@surething/cockpit 1.0.241 → 1.0.242
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next-prod/BUILD_ID +1 -1
- package/.next-prod/app-path-routes-manifest.json +5 -5
- package/.next-prod/build-manifest.json +2 -2
- package/.next-prod/prerender-manifest.json +3 -3
- package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_global-error.html +1 -1
- package/.next-prod/server/app/_global-error.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_not-found.html +2 -2
- package/.next-prod/server/app/_not-found.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/project/page.js +1 -1
- package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app-paths-manifest.json +5 -5
- package/.next-prod/server/chunks/304.js +3 -3
- package/.next-prod/server/chunks/9658.js +3 -3
- package/.next-prod/server/middleware-build-manifest.js +1 -1
- package/.next-prod/server/pages/404.html +2 -2
- package/.next-prod/server/pages/500.html +1 -1
- package/.next-prod/server/server-reference-manifest.json +1 -1
- package/.next-prod/static/chunks/{5408-e785cb62df051a22.js → 5408-f9fd9ece18d916dc.js} +1 -1
- package/.next-prod/trace +13 -13
- package/.next-prod/trace-build +1 -1
- package/dist/{chunk-TRQ4S2LT.mjs → chunk-53DHIXIY.mjs} +1 -1
- package/dist/{chunk-44DBCDDK.mjs → chunk-PTHQK26K.mjs} +46 -14
- package/dist/{chunk-JDX7Z54G.mjs → chunk-RBT65EBM.mjs} +1 -1
- package/dist/httpApi.mjs +2 -2
- package/dist/scheduledTasks.mjs +2 -2
- package/dist/{server-UDKNFSZE.mjs → server-XWLYHEMD.mjs} +2 -2
- package/dist/wsServer.mjs +4 -4
- package/package.json +1 -1
- /package/.next-prod/static/{x_Nlb9WAVX__4ygoUBUWt → YsWseNHOrhvA60UWaNkzK}/_buildManifest.js +0 -0
- /package/.next-prod/static/{x_Nlb9WAVX__4ygoUBUWt → YsWseNHOrhvA60UWaNkzK}/_ssgManifest.js +0 -0
|
@@ -22,4 +22,4 @@ Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[N,m,k,r,e,O,Y,q,
|
|
|
22
22
|
Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=Y(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e+`
|
|
23
23
|
Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,N,m,k,r,e,O,Y,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await i.t4.runPromise(tN(e,r,t,W.current).pipe(Q.tapError(e=>Q.sync(()=>console.error("Failed to delete command:",e))),Q.orElse(()=>Q.void)))},[e,r,q]),ec=(0,s.useCallback)((t,n,s)=>{var o;let a=tO(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=m);let d={id:(o=a.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...l};if(c(e=>[...e,d]),w(d.id),setTimeout(G,100),s){let t=S&&S.length>0?[...S]:z.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,d.id):t.push(d.id),L(t),r&&i.t4.runFork(tk(e,r,t,W.current).pipe(Q.orElse(()=>Q.void)))}if(r){let n=a.toHistory(d);i.t4.runFork(ty(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},W.current).pipe(Q.tapError(e=>Q.sync(()=>console.error(`Failed to save ${t} item:`,e))),Q.orElse(()=>Q.void)))}},[G,e,r,S]),ed=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(c(e=>e.filter(e=>e.id!==t)),w(e=>e===t?null:e),u(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=tO(n._type);e?.onClose?.(n)}r&&i.t4.runFork(tN(e,r,t,W.current).pipe(Q.tapError(e=>Q.sync(()=>console.error("Failed to delete plugin item:",e))),Q.orElse(()=>Q.void)))},[l,e,r]);A.current=ec,D.current=eo;let eu=(0,s.useCallback)((t,n)=>{let s,o,a,l;r&&i.t4.runFork((s=e,o=r,a=t,l={sleeping:n},tb("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:s,tabId:o,id:a,fields:l,sourceId:W.current})})).pipe(Q.orElse(()=>Q.void)))},[e,r]),em=(0,s.useCallback)(e=>{u(t=>new Set(t).add(e)),eu(e,!0)},[eu]),ex=(0,s.useCallback)(e=>{u(t=>{let r=new Set(t);return r.delete(e),r}),eu(e,!1)},[eu]),eh=(0,s.useCallback)(async t=>{L(t),r&&await i.t4.runPromise(tk(e,r,t,W.current).pipe(Q.orElse(()=>Q.void)))},[e,r]),ef=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!S||0===S.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(S.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,l,S]);z.current=ef,(0,s.useEffect)(()=>{$.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ep=async()=>{y(await i.t4.runPromise(tj(e,r).pipe(Q.tapError(e=>Q.sync(()=>console.error("Failed to load env:",e))),Q.orElseSucceed(()=>({})))))},eg=async()=>{C(await i.t4.runPromise(tw().pipe(Q.tapError(e=>Q.sync(()=>console.error("Failed to load aliases:",e))),Q.orElseSucceed(()=>({})))))},eb=async()=>{if(!r)return;let t=await i.t4.runPromise(tg(`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(r)}`).pipe(Q.map(e=>e.order||[])).pipe(Q.orElseSucceed(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await X(0),e.current||await et(e)})(),ep(),eg(),eb(),()=>{e.current=!0}},[X,et]),(0,s.useEffect)(()=>()=>{null!==M.current&&cancelAnimationFrame(M.current)},[]),(0,s.useEffect)(()=>()=>{r7()},[]),{commands:o,pluginItems:l,sleepingBubbles:d,consoleItems:ef,currentCwd:m,selectedCommandId:j,setSelectedCommandId:w,customEnv:k,setCustomEnv:y,aliases:N,setAliases:C,isLoadingHistory:h,hasMoreHistory:p,currentPage:b,scrollRef:_,commandHistoryRef:$,ptySizeRef:R,executeCommandRef:D,executeCommand:eo,interruptCommand:ea,rerunCommand:el,deleteCommand:ei,addPluginItem:ec,closePluginItem:ed,handleBubbleSleep:em,handleBubbleWake:ex,loadHistory:X,scrollToBottom:G,saveBubbleOrder:eh,sendStdin:r3,resizePty:r6,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:Z}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[W,_]=(0,s.useState)(null),[H,O]=(0,s.useState)(0),[q,V]=(0,s.useState)(0),[U,K]=(0,s.useState)(!0),[J,Z]=(0,s.useState)(!1),[Y,G]=(0,s.useState)(!1),[X,ee]=(0,s.useState)(!1),[et,er]=(0,s.useState)(!1),en=(0,s.useRef)(null),es=(0,s.useRef)(null),eo=(0,s.useRef)(null),ea=(0,s.useRef)(!1),el=(0,s.useRef)(null),ei=(0,s.useRef)(null),ec=(0,s.useRef)([]);(0,s.useEffect)(()=>{ec.current=d},[d]);let ed=(0,s.useCallback)(()=>{let e=u.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[u]),eu=(0,s.useCallback)(()=>{let e=u.current;return!e||e.scrollTop<50},[u]),em=(0,s.useCallback)(()=>{ee(!eu()),er(!ed())},[ed,eu]),ex=(0,s.useCallback)(()=>{es.current?.scrollIntoView({behavior:"smooth"})},[]),eh=async()=>{let t=await i.t4.runPromiseExit(tg(`/api/project-settings?cwd=${encodeURIComponent(e)}`));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&K(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>eh())},[]);let ef=(0,s.useCallback)(()=>{ea.current=!0},[]),ep=(0,s.useCallback)((e,t)=>{if(!ea.current)return void e.preventDefault();ea.current=!1,el.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:var(--card);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),eg=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ei.current=t},[]),eb=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ev=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ej=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ew=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=el.current,r=ei.current;if(el.current=null,ei.current=null,!t||!r||t===r)return;let n=ec.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let a=[...n];a[s]=r,a[o]=t,T(a)},[T]),ek=(0,s.useCallback)(e=>{_(t=>t===e?null:e)},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),m&&ek(m))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[m,ek]),(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=new ResizeObserver(([e])=>{V(e.contentRect.height)});return t.observe(e),V(e.clientHeight),()=>t.disconnect()},[u]),(0,s.useEffect)(()=>{let e=u.current;if(e)return W?O(e.clientHeight):(e.style.overflow="",O(0)),()=>{e&&(e.style.overflow="")}},[W,u]),(0,s.useEffect)(()=>{let e=u.current;if(!e||!W||!H)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${W}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[W,H,u]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&j(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[j]);let ey=q>0?Math.floor((q-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:en,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:u,onScroll:em,className:`console-scroll-root flex-1 overflow-y-auto ${W?"":"py-4 px-4"}`,children:0===d.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-4 text-sm",children:[(0,n.jsx)("p",{className:"text-muted-foreground",children:c("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:nr.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3",children:[(0,n.jsx)("span",{className:"w-16 flex-shrink-0 text-foreground font-medium",children:c(e.label)}),(0,n.jsxs)("span",{className:"flex-1 flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"flex flex-wrap gap-1",children:e.triggers.map(e=>(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-xs font-mono text-muted-foreground",children:e},e))}),e.notes?.map(e=>(0,n.jsx)("span",{className:"text-xs leading-snug text-muted-foreground/70",children:c(e)},e))]})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>j("zsh"),title:c("console.launchZsh"),className:"self-start flex items-center gap-2 px-4 py-2 rounded-lg border border-input bg-background text-sm text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 transition-all",children:[(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),"New PTY"]})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:es}),$&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>R(B+1),disabled:F,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors disabled:opacity-50",children:F?c("console.loadingMore"):c("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:W?"flex flex-col gap-3":U?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:d.map(t=>{let s={draggable:!0,onDragStart:e=>ep(e,t.data.id),onDragOver:e=>eg(e,t.data.id),onDragEnter:eb,onDragLeave:ev,onDrop:ej,onDragEnd:ew};if("command"===t.type){let o=t.data;return(0,n.jsx)("div",{"data-bubble-id":o.id,className:"group/cmd rounded-lg transition-shadow",...s,children:(0,n.jsx)(tP,{commandId:o.id,tabId:r,projectCwd:e,command:o.command,output:o.output,exitCode:o.exitCode,isRunning:o.isRunning,selected:m===o.id,onSelect:()=>{x(o.id)},onInterrupt:o.isRunning?()=>h(o.id):void 0,onStdin:o.isRunning?e=>f(o.id,e):void 0,onDelete:()=>{o.isRunning&&o.pid&&r9(o.pid),p(o.id)},onRerun:()=>g(o.id),timestamp:o.timestamp,usePty:o.usePty,subscribePtyOutput:o.usePty?D:void 0,subscribePtyReset:o.usePty?A:void 0,subscribePtyRefresh:o.usePty?z:void 0,onPtyResize:(e,t)=>{b.current.set(o.id,{cols:e,rows:t}),v(o.id,e,t)},onToggleMaximize:()=>ek(o.id),maximized:W===o.id,expandedHeight:H,bubbleContentHeight:ey,onTitleMouseDown:ef})},o.id)}let o=tO(t.type);if(!o)return null;let a=o.Component,l=t.data;return(0,n.jsx)("div",{"data-bubble-id":l.id,className:"rounded-lg transition-shadow",...s,children:(0,n.jsx)(a,{item:l,selected:m===l.id,maximized:W===l.id,expandedHeight:H,bubbleContentHeight:ey,timestamp:l.timestamp,onSelect:()=>{x(l.id)},onClose:()=>k(l.id),onToggleMaximize:()=>ek(l.id),onTitleMouseDown:ef,extra:{addBrowserItem:(e,t)=>w("browser",e,t),initialSleeping:y.has(l.id),onSleep:N,onWake:C,projectCwd:e,tabId:r}})},l.id)})}),(0,n.jsx)("div",{ref:eo})]})}),!W&&d.length>0&&(0,n.jsx)(rq,{showTop:X,showBottom:et,onScrollTop:ex,onScrollBottom:S}),(0,n.jsx)(rO,{cwd:e,currentCwd:L,commandHistoryRef:M,gridLayout:U,onGridLayoutChange:t=>{K(t);i.t4.runFork(tv("/api/project-settings",{cwd:e,settings:{gridLayout:t}}).pipe(Q.tapError(e=>Q.sync(()=>console.error("Failed to save project settings:",e))),Q.orElse(()=>Q.void)))},onExecute:j,onAddPluginItem:w,onShowEnvManager:()=>Z(!0),onOpenZsh:()=>j("zsh"),onOpenNote:l}),J&&(0,n.jsx)(tR,{cwd:e,tabId:r,onClose:()=>Z(!1),onSave:e=>E(e)}),Y&&(0,n.jsx)(tF,{onClose:()=>G(!1),onSave:e=>P(e)})]})}var ns=r(83897),no=r(65992),na=r(89039),nl=r(76412),ni=r(24058),nc=r(98307),nd=r(65153);function nu({cwd:e,sessionId:t,onOpenProjectSessions:r,onOpenSessionBrowser:a,onOpenSettings:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["Session: ",t.slice(0,8),"..."]}),e&&(0,n.jsx)("button",{onClick:r,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),t&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t}`;navigator.clipboard.writeText(e).then(()=>{d(!0),setTimeout(()=>d(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-500 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:c?i("chat.copiedCommandTooltip"):i("chat.copyCommandTooltip",{sessionId:t}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:i("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function nm({tokenUsage:e,rateLimitInfo:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>l(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let i=t?.status==="rejected"?"text-red-500":t?.status==="allowed_warning"?"text-yellow-500":"text-muted-foreground",c=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,d=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-a;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},u=e=>e?e.replace(/_/g," "):"";return(0,n.jsx)("div",{className:"px-4 py-1.5 border-t border-border bg-secondary",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&c&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${i}`,title:[t.rateLimitType&&`Type: ${u(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${d(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:c}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${d(t.resetsAt)}`]})]}),t&&!c&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5",title:[t.rateLimitType&&u(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${d(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:d(t.resetsAt)})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsxs)("span",{children:[r("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens).toLocaleString()})]})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[r("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}function nx({isOpen:e,onClose:t,messages:r,onSelectMessage:s}){let{t:a}=(0,o.Bd)();if((0,j.E)(t,e),!e)return null;let l=r.filter(e=>"user"===e.role),i=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-lg max-h-[70vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:a("userMessages.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===l.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:a("userMessages.noMessages")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:l.map((e,r)=>{let o,a,l,i=(o=e.id.match(/^user-(\d+)/))?parseInt(o[1],10):null,c=i?(a=new Date(i),l=new Date,a.toDateString()===l.toDateString()?a.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):a.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})):"";return(0,n.jsx)("button",{onClick:()=>{s(e.id),t()},className:"w-full px-4 py-3 text-left hover:bg-accent transition-colors",children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[r+1,"."]}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("p",{className:"text-sm text-foreground break-words",children:function(e,t=50){let r=e.replace(/\s+/g," ").trim();return r.length<=t?r:r.slice(0,t)+"..."}(e.content)})}),c&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:c})]})},e.id)})})})]})});return(0,n.jsx)(m.ZL,{children:i})}var nh=r(67589),nf=r(20917),np=r(73395);function ng({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-full max-h-[90vh] object-contain rounded-lg",onClick:e=>e.stopPropagation()}),(0,n.jsx)("button",{onClick:t,className:"absolute -top-3 -right-3 w-8 h-8 bg-card text-foreground hover:text-foreground rounded-full shadow-lg flex items-center justify-center transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})});return(0,n.jsx)(m.ZL,{children:s})}function nb({images:e,onRemove:t,disabled:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 bg-secondary border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:a("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:a("imagePreview.deleteImage"),children:"✕"})]},e.id))}),l&&(0,n.jsx)(ng,{image:l,onClose:()=>i(null)})]})}var nv=r(93777),nj=r(88371);let nw=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,engine:a,onShowGitStatus:l,onShowComments:d,onShowUserMessages:u,onOpenNote:m,onCreateScheduledTask:x}){let{t:f}=(0,o.Bd)(),[p,g]=(0,s.useState)(""),[b,v]=(0,s.useState)(0),[j,w]=(0,s.useState)([]),[y,N]=(0,s.useState)([]),[C,S]=(0,s.useState)([]),[L,M]=(0,s.useState)(!1),[E,P]=(0,s.useState)(0),[T,$]=(0,s.useState)(!1),R=(0,s.useRef)(null),B=(0,s.useRef)(null),F=(0,s.useCallback)(()=>{let e=R.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{F()},[p,F]),(0,s.useEffect)(()=>{i.t4.runPromiseExit((0,c.M5)()).then(e=>{"Success"===e._tag?N(e.value):console.error("Failed to load commands:",e.cause)})},[]);let I=(0,s.useCallback)(async()=>{let e=await i.t4.runPromiseExit((0,c.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;S((Array.isArray(t)?t:[]).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint})))}else console.error("Failed to load skills:",e.cause)},[]);(0,s.useEffect)(()=>(I(),(0,nj.U)(I)),[I]);let D=(0,s.useMemo)(()=>{let e=0===b?0:p.lastIndexOf("\n",b-1)+1,t=p.indexOf("\n",b),r=-1===t?p.length:t;return{text:p.slice(e,r),start:e,end:r}},[p,b]),A=(0,s.useMemo)(()=>{let e=D.text.match(/^\s*([/@])([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[D.text]),z=(0,s.useMemo)(()=>a&&"claude"!==a&&"claude2"!==a?[]:[{name:"/plan",description:"Enable plan mode (read-only). /plan <task> to plan a task; /plan off to disable.",source:"builtin",argumentHint:"[task|off]"}],[a]),W=(0,s.useMemo)(()=>{if(!A)return[];let{verb:e}=A,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return[...z.filter(t),...y.filter(t),...C.filter(t)]},[A,z,y,C]),_=!T&&!!A&&W.length>0,H=(0,s.useRef)(p);(0,s.useLayoutEffect)(()=>{H.current!==p&&(queueMicrotask(()=>P(0)),T&&queueMicrotask(()=>$(!1)),H.current=p)},[p,T]),(0,s.useLayoutEffect)(()=>{if(_&&B.current){let e=B.current.children[E];e&&e.scrollIntoView({block:"nearest"})}},[E,_]);let O=(0,s.useCallback)(()=>{let r=p.trim();(r||j.length>0)&&!t&&(e(r,j.length>0?j:void 0),g(""),w([]),R.current&&(R.current.style.height="auto"))},[p,j,t,e]),q=(0,s.useCallback)(e=>{let t=A?.marker??"/",r=`${t}${e.name.slice(1)} `,n=p.slice(0,D.start),s=n+r+p.slice(D.end),o=n.length+r.length;g(s),v(o),requestAnimationFrame(()=>{let e=R.current;e&&(e.focus(),e.setSelectionRange(o,o))})},[p,D,A]),V=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing){if(_&&W.length>0){if("ArrowDown"===e.key){e.preventDefault(),P(e=>(e+1)%W.length);return}if("ArrowUp"===e.key){e.preventDefault(),P(e=>(e-1+W.length)%W.length);return}if("Enter"===e.key){e.preventDefault(),q(W[E]);return}if("Escape"===e.key){e.preventDefault(),$(!0);return}if("Tab"===e.key){e.preventDefault(),q(W[E]);return}}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),O())}},[_,W,E,q,O]),U=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(f("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};w(e=>[...e,s])},s.readAsDataURL(r)}}},[f]),K=(0,s.useCallback)(e=>{w(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nb,{images:j,onRemove:K,disabled:t}),_&&W.length>0&&(0,n.jsx)("div",{ref:B,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64 overflow-y-auto bg-card border border-border rounded-lg shadow-lg",children:W.map((e,t)=>{let r=t>0?W[t-1]:null,s="skill"===e.source&&(!r||"skill"!==r.source),o="skill"!==e.source&&0===t;return(0,n.jsxs)("div",{children:[o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),s&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),(0,n.jsxs)("div",{onClick:()=>q(e),className:`px-4 py-2 cursor-pointer ${t===E?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:(A?.marker??"/")+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?f(`commands.${e.name.slice(1)}`,{defaultValue:e.description}):e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return f("common.builtin");case"skill":return"Skill"}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.name)})}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[(0,n.jsx)("button",{onClick:async()=>{if(!r)return;let e=await i.t4.runPromiseExit((0,h.Iz)(r,["."]));"Success"===e._tag?((0,k.oR)(f("toast.stagedAllFiles"),"success"),window.dispatchEvent(new CustomEvent("git-status-changed"))):(console.error("Error staging files:",e.cause),(0,k.oR)(f("toast.stageFailed"),"error"))},className:"p-2 text-green-11 hover:text-green-10 hover:bg-green-9/10 active:bg-green-9/20 active:scale-95 rounded-lg transition-all",title:f("chat.stageAll"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),l&&(0,n.jsx)("button",{onClick:l,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:f("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),d&&(0,n.jsx)("button",{onClick:d,className:"p-2 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95 rounded-lg transition-all",title:f("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),u&&(0,n.jsx)("button",{onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:f("chat.userMessages"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),m&&(0,n.jsx)("button",{onClick:m,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:f("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),x&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>M(!L),className:`p-2 rounded-lg transition-all ${L?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95"}`,title:f("chat.scheduledTasks"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]})}),L&&(0,n.jsx)(nv.E,{onClose:()=>M(!1),onCreate:x})]}),(0,n.jsx)("textarea",{ref:R,value:p,onChange:e=>{g(e.target.value),v(e.target.selectionStart??e.target.value.length)},onSelect:e=>v(e.currentTarget.selectionStart??0),onKeyDown:V,onPaste:U,placeholder:t?f("chat.placeholderDisabled"):f("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground placeholder-slate-9"})]})]})});var nk=r(95942);function ny({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[d,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(!1),g=(0,s.useRef)(null),b=(0,s.useRef)(null),[v,j]=(0,s.useState)({top:0,left:0}),w=(0,m.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{b.current&&!b.current.contains(e.target)&&g.current&&!g.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let k=(0,s.useCallback)(async()=>{u(!0),h(null);let e=await i.t4.runPromiseExit((0,c.qD)(()=>p(!0)));if(p(!1),"Failure"===e._tag)h("Connection error");else{let t=e.value;switch(t._tag){case"ok":l(t.models);break;case"not-installed":case"error":h(t.message);break;case"not-running":h("Ollama is not running")}}u(!1)},[]),y=e?e.replace(/:latest$/,""):"Select model",N=r?(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{ref:b,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[200px] max-h-[300px] overflow-y-auto",style:{top:v.top,left:v.left},children:d||f?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),f?"Starting Ollama...":"Loading models..."]}):x?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-400",children:x}):0===a.length?(0,n.jsxs)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No models found. Run ",(0,n.jsx)("code",{className:"bg-secondary px-1 rounded",children:"ollama pull <model>"})]}):a.map(r=>{var s;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center justify-between gap-2 px-3 py-1.5 text-xs hover:bg-brand/10 transition-colors ${r.name===e?"text-brand":"text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:r.parameter_size||((s=r.size)<1e9?`${(s/1e6).toFixed(0)}M`:`${(s/1e9).toFixed(1)}G`)})]},r.name)})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:g,onClick:()=>{if(!r){if(g.current){let e=g.current.getBoundingClientRect(),t=w?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;j({top:e.bottom+4-n,left:e.left-r})}k()}o(e=>!e)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded bg-violet-500/15 text-violet-400 hover:bg-violet-500/25 transition-colors",title:"Switch Ollama model",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-violet-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate max-w-[120px]",children:y}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),N]})}let nN=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function nC({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null),y=(0,s.useRef)(null),[N,C]=(0,s.useState)({top:0,left:0}),S=(0,m.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{k.current&&!k.current.contains(e.target)&&w.current&&!w.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let L=(0,s.useCallback)(async()=>{p(!0),j(null);let r=await i.t4.runPromiseExit((0,c.td)());if("Failure"===r._tag){j("Failed to load settings"),p(!1);return}let n=r.value;l(n?.engines?.deepseek?.apiKey||""),u(""),h(!1);let s=n?.engines?.deepseek?.model;!e&&s&&nN.some(e=>e.value===s)&&t(s),p(!1)},[e,t]),M=(0,s.useCallback)(async e=>{let t=await i.t4.runPromiseExit((0,c.td)()),r=("Success"===t._tag?t.value:{}).engines||{},n={...r,deepseek:{...r.deepseek||{},...e}};if("Failure"===(await i.t4.runPromiseExit((0,c.em)({engines:n})))._tag)throw Error("Failed to save settings")},[]),E=async()=>{let e=d.trim();if(e){b(!0),j(null);try{await M({apiKey:e}),l(e),u(""),h(!1)}catch(e){j(e instanceof Error?e.message:"Save failed")}finally{b(!1)}}},P=async()=>{b(!0),j(null);try{await M({apiKey:""}),l(""),u(""),h(!1)}catch(e){j(e instanceof Error?e.message:"Clear failed")}finally{b(!1)}},T=async e=>{t(e);try{await M({model:e})}catch{}},$=!!a,R=$?e||"deepseek-v4-flash":"Set API key",B=$?"text-sky-400":"text-amber-400",F=r?(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{ref:k,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-2 min-w-[280px]",style:{top:N.top,left:N.left},children:f?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"API Key"}),$&&!x?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:a?a.length<=8?a.replace(/./g,"•"):`${a.slice(0,3)}${"•".repeat(Math.max(4,a.length-7))}${a.slice(-4)}`:""}),(0,n.jsx)("button",{onClick:()=>{h(!0),u(""),setTimeout(()=>y.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-accent text-foreground transition-colors",disabled:g,children:"Edit"}),(0,n.jsx)("button",{onClick:P,className:"text-[11px] px-2 py-1 rounded text-red-400 hover:bg-red-500/10 transition-colors",disabled:g,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:y,type:"password",value:d,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&E()},placeholder:"sk-...",className:"flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:border-sky-500 focus:outline-none font-mono",autoFocus:!0}),(0,n.jsx)("button",{onClick:E,disabled:g||!d.trim(),className:"text-[11px] px-2 py-1 rounded bg-sky-500/20 hover:bg-sky-500/30 text-sky-300 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:g?"Saving...":"Save"}),$&&(0,n.jsx)("button",{onClick:()=>{h(!1),u("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),v&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-400",children:v})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Model"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:nN.map(t=>{let r=(e||"deepseek-v4-flash")===t.value;return(0,n.jsxs)("button",{onClick:()=>T(t.value),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?"bg-sky-500/15 text-sky-300":"text-foreground hover:bg-accent"}`,children:[(0,n.jsx)("span",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${r?"border-sky-400":"border-muted-foreground"}`,children:r&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-sky-400"})}),(0,n.jsx)("span",{children:t.label})]},t.value)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:w,onClick:()=>{if(!r){if(w.current){let e=w.current.getBoundingClientRect(),t=S?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;C({top:e.bottom+4-n,left:e.left-r})}L()}o(e=>!e)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded bg-sky-500/15 hover:bg-sky-500/25 transition-colors",title:"Configure DeepSeek",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-sky-500 flex-shrink-0"}),(0,n.jsx)("span",{className:`truncate max-w-[160px] ${B}`,children:R}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-sky-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),F]})}var nS=r(46456);function nL(e){if(0===e.length)return"";let t=[e9.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===en.Un),n=e.filter(e=>e.filePath!==en.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";t.push(`[${r+1}] ${e.filePath}${n}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(e9.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function nM({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),c=(0,et.r)(),[d,u]=(0,s.useState)([]),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),y=(0,s.useCallback)(async()=>{if(!r)return;f(!0);let e=await i.t4.runPromiseExit((0,nS.$)(r));"Success"===e._tag?u(e.value.comments??[]):console.error("Failed to load comments:",e.cause),f(!1)},[r]);(0,s.useEffect)(()=>{e&&y()},[e,y]);let N=async e=>{let t=await i.t4.runPromiseExit((0,nS.Tu)(r,e));"Success"===t._tag?(u(t=>t.filter(t=>t.id!==e)),(0,en.Cm)()):console.error("Failed to delete comment:",t.cause)},C=async e=>{g(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await i.t4.runPromiseExit((0,x.K9)(r,e.filePath));if("Success"!==n._tag||!n.value.ok)throw Error("Failed to read file");t=(n.value.data?.content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=nL([n]);await navigator.clipboard.writeText(s),(0,k.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{g(null)}},S=async()=>{if(0!==d.length){v(!0);try{let e=await (0,en.$3)(r),t=nL(e);await navigator.clipboard.writeText(t),(0,k.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{v(!1)}}},L=async()=>{if(0!==d.length&&c&&!c.isLoading&&!j){w(!0);try{let e=(await (0,en.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,en.Gw)(e,"");c.sendMessage(n),await (0,en.RP)(r),u([]),t()}catch(e){console.error("Failed to send comments to AI:",e)}finally{w(!1)}}},M=d.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let E=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-xl flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:l("comments.allComments")}),d.length>0&&(0,n.jsx)("button",{onClick:S,disabled:b,className:"p-1 rounded hover:bg-accent text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:b?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:h?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:l("common.loading")}):0===d.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:l("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(M).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===en.Un?l("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",l("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-accent/50 cursor-pointer group",onClick:()=>a?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand font-mono",children:[l("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",l("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:l("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),C(e)},disabled:p===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground transition-opacity disabled:opacity-50",title:l("common.copy"),children:p===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),N(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground hover:text-red-9 transition-opacity",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border bg-secondary flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:l("comments.totalComments",{count:d.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[c&&(0,n.jsx)("button",{onClick:L,disabled:0===d.length||c.isLoading||j,className:"px-3 py-1.5 text-sm bg-brand text-brand-foreground rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",title:c.isLoading?l("comments.aiResponding"):l("comments.sendToAI"),children:j?l("comments.submitting"):l("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===d.length||await (0,en.RP)(r)&&u([])},disabled:0===d.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:l("comments.clearAll")})]})]})]})});return(0,n.jsx)(m.ZL,{children:E})}function nE({tabId:e,initialCwd:t,initialSessionId:r,engine:u,ollamaModel:m,onOllamaModelChange:x,deepseekModel:h,onDeepseekModelChange:f,chatMode:p,onChatModeChange:g,planMode:b,onPlanModeChange:v,hideHeader:j,hideSidebar:w,isActive:y=!0,refreshSignal:N,onLoadingChange:C,onSessionIdChange:S,onTitleChange:L,onShowGitStatus:M,onOpenNote:E,onCreateScheduledTask:P,onOpenSession:T,onContentSearch:$,onShowFileDiff:R,onOpenSessionBrowser:B,onOpenSettings:F}){let{t:I}=(0,o.Bd)(),D=(0,ns.nH)(),[A,z]=(0,s.useState)([]),[W,_]=(0,s.useState)(null),[H,O]=(0,s.useState)(!1),[q,V]=(0,s.useState)(!1),[U,K]=(0,s.useState)(!1),[J,Q]=(0,s.useState)(!1),[Z,Y]=(0,s.useState)(null),[G,X]=(0,s.useState)("sdk"),ee=p??G,et=(0,s.useCallback)(e=>{X(e),g?.(e)},[g]),[er,en]=(0,s.useState)(!1),es=b??er,eo=(0,s.useCallback)(e=>{en(e),v?.(e)},[v]),ea=!u||"claude"===u||"claude2"===u,el=(0,s.useRef)(null),ei=(0,s.useCallback)(e=>{el.current?.write(e)},[]),ec=(0,s.useCallback)(e=>{W&&fetch("/api/chat/pty-input",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:W,data:e})}).catch(()=>{})},[W]),ed=(0,s.useRef)(!1),eu=(0,s.useRef)(null),em=(0,s.useRef)(null),ex=(0,s.useCallback)(async e=>{if(!t)return;let r=await i.t4.runPromiseExit((0,c.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?L?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,L]),eh=(0,s.useRef)(null),{isLoading:ef,tokenUsage:ep,rateLimitInfo:eg,apiRetryInfo:eb,ptyNotice:ev,handleSend:ej,handleStop:ew}=(0,nf.e)(A,z,{sessionId:W,cwd:t,engine:u,chatMode:ee,planMode:es,ollamaModel:m,deepseekModel:h,onSessionId:_,onFetchTitle:ex,onPtyOutput:ei,onRunComplete:()=>eh.current?.()}),ek=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(ea&&"sdk"===ee){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(eo(!1),(0,k.oR)(I("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(eo(!0),(0,k.oR)(I("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(eo(!0),ej(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void ej(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await i.t4.runPromiseExit((0,c.JC)({command:s,cwd:t}));if("Success"===a._tag){let e=a.value,t=[e.stdout,e.stderr].filter(Boolean).join("\n")||"(no output)",n=I("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
|
|
24
24
|
|
|
25
|
-
${o}`),ej(n,r)}else ej(I("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}ej(e,r)},[ej,t,I,ea,ee,eo]),ey=(0,s.useCallback)(()=>{eo(!1),ej(I("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[ej,eo,I]),[eN,eC]=(0,s.useState)(!1),eS=(0,s.useRef)(!1);(0,s.useEffect)(()=>{eS.current=eN},[eN]);let{isLoadingHistory:eL,isLoadingMore:eM,hasMoreHistory:eE,loadMoreHistory:eP,loadHistoryByCwdAndSessionId:eT,loadedSessionId:e$}=(0,nh.m)(A,z,W,{cwd:t,initialSessionId:r,onSessionId:_,onTitleChange:L,onTokenUsage:Y,liveRunningRef:eS}),eR=e$||W,eB=y&&!ef&&!!eR;(0,nd.u)(eR,z,eB,u,{onRunningChange:e=>{eS.current=e,eC(e)},onComplete:()=>{t&&eR&&eT(t,eR,!0)}}),(0,s.useEffect)(()=>{eB||eC(!1)},[eB]),(0,s.useEffect)(()=>{eh.current=()=>{t&&eR&&eT(t,eR,!0)}},[t,eR,eT]);let eF=(0,s.useRef)(y);(0,s.useEffect)(()=>{y&&!eF.current&&W&&t&&!ef&&!eN&&eT(t,W,!0,10),eF.current=y},[y,W,t,ef,eN,eT]);let eI=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!N||N.nonce===eI.current)return;eI.current=N.nonce;let e=W||e$;!t||!e||N.sessionId!==W&&N.sessionId!==e$||ef||eN||eT(t,e,!0,10,void 0,!0)},[N,W,e$,t,ef,eN,eT]),(0,s.useEffect)(()=>{"pty"===ee&&ef&&!ed.current&&el.current?.clear(),ed.current=ef},[ef,ee]);let eD=ep||Z;(0,s.useEffect)(()=>{W&&S?.(W)},[W,S]);let eA=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(C?.(ef),eA.current&&!ef&&t&&W){let e;for(let t=A.length-1;t>=0;t--)if("user"===A[t].role&&A[t].content){e=A[t].content.slice(0,100);break}(0,a.F)(l.n.SessionComplete,{cwd:t,sessionId:W,lastUserMessage:e})}eA.current=ef},[ef,C,t]),(0,s.useEffect)(()=>{y&&D?.setIsLoading(ef)},[ef,y,D]),(0,s.useEffect)(()=>{if(e&&D)return D.registerChat(e=>{em.current?.(e)},e),()=>{D.unregisterChat(e)}},[e,D]),(0,s.useEffect)(()=>{e&&y&&D&&D.setActiveTab(e)},[e,y,D]),(0,s.useEffect)(()=>{em.current=ek},[ek]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&H&&(ef||eN)&&ew()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[H,ef,eN,ew]);let ez=(0,s.useCallback)(async e=>{let r=e$??W;if(!t||!r)return;let n=await i.t4.runPromiseExit((0,c.Zr)(r,{cwd:t,fromMessageUuid:e}));if("Success"===n._tag&&n.value.newSessionId){let e=n.value.newSessionId;T?T(e,"Fork"):(0,a.F)(l.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===n._tag&&console.error("Fork failed:",n.cause)},[t,e$,W,T]),eW=(0,s.useCallback)(()=>{K(!0)},[]),e_=(0,s.useCallback)(()=>{Q(!0)},[]),eH=(0,s.useMemo)(()=>{if(P&&t&&e&&W)return r=>{P({...r,cwd:t,tabId:e,sessionId:W,engine:u,..."ollama"===u&&m&&{model:m},..."deepseek"===u&&h&&{model:h}})}},[P,t,e,W,u,m,h]);return(0,n.jsxs)("div",{className:`flex ${j&&w?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1),children:[!j&&(0,n.jsx)(nu,{cwd:t,sessionId:W,onOpenProjectSessions:()=>V(!0),onOpenSessionBrowser:B,onOpenSettings:F}),ea&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:I("chat.executionMode",{defaultValue:"Execution mode"})}),(0,n.jsxs)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":"chatmode-toggle",children:[(0,n.jsx)("button",{type:"button","data-testid":"chatmode-sdk",onClick:()=>et("sdk"),className:`px-2 py-0.5 ${"sdk"===ee?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-accent"}`,children:"Claude Agent SDK"}),(0,n.jsx)("button",{type:"button","data-testid":"chatmode-pty",onClick:()=>et("pty"),className:`px-2 py-0.5 ${"pty"===ee?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-accent"}`,title:I("chat.ptyModeHint",{defaultValue:"Subscription-billing mode: driven by the interactive claude CLI"}),children:"Claude Code CLI"})]}),"sdk"===ee&&(0,n.jsxs)("label",{className:"flex items-center gap-1.5 ml-2 pl-3 border-l border-border text-xs cursor-pointer select-none",title:I("chat.planModeHint",{defaultValue:"Plan mode: read-only exploration that produces a plan without editing. Uncheck and resend to implement."}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:es,onChange:e=>eo(e.target.checked),className:"accent-brand"}),(0,n.jsxs)("span",{className:"flex items-center gap-1 text-foreground",children:[(0,n.jsx)(nc.A,{className:"w-3.5 h-3.5"}),I("chat.planMode",{defaultValue:"Plan mode"})]}),(0,n.jsx)("span",{className:"text-muted-foreground",children:I("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"})})]})]}),"ollama"===u&&x&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(ny,{currentModel:m,onModelChange:x})}),"deepseek"===u&&f&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(nC,{currentModel:h,onModelChange:f})}),eL?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:I("sessions.loadingHistory")})}):(0,n.jsx)(np.M,{ref:eu,messages:A,isLoading:ef||eN,cwd:t,sessionId:W,engine:u,apiRetryInfo:eb,ptyNotice:ev,hasMoreHistory:eE,isLoadingMore:eM,onLoadMore:eP,onFork:ez,isActive:y,onContentSearch:$,onShowFileDiff:R,onApprovePlan:ey}),eD&&(0,n.jsx)(nm,{tokenUsage:eD,rateLimitInfo:eg}),(0,n.jsx)(nw,{onSend:ek,disabled:ef||eN,cwd:t,engine:u,onShowGitStatus:M,onShowComments:t?eW:void 0,onShowUserMessages:e_,onOpenNote:E,onCreateScheduledTask:eH}),(0,n.jsx)(nk.ri,{ref:el,visible:ea&&"pty"===ee,running:ef,onInput:ec})]}),!j&&t&&(0,n.jsx)(d,{isOpen:q,onClose:()=>V(!1),cwd:t}),t&&(0,n.jsx)(nM,{isOpen:U,onClose:()=>K(!1),cwd:t}),(0,n.jsx)(nx,{isOpen:J,onClose:()=>Q(!1),messages:A,onSelectMessage:e=>{eu.current?.scrollToMessage(e)}})]})}function nP({tabId:e,cwd:t,sessionId:r,engine:o,ollamaModel:a,onOllamaModelChange:l,deepseekModel:i,onDeepseekModelChange:c,chatMode:d,onChatModeChange:u,planMode:m,onPlanModeChange:x,isActive:h,refreshSignal:f,onStateChange:p,onShowGitStatus:g,onOpenNote:b,onCreateScheduledTask:v,onOpenSession:j,onContentSearch:w,onShowFileDiff:k}){let y=(0,s.useCallback)(t=>{p(e,{isLoading:t})},[e,p]),N=(0,s.useCallback)(t=>{p(e,{sessionId:t})},[e,p]),C=(0,s.useCallback)(t=>{p(e,{title:t})},[e,p]),S=(0,s.useCallback)(t=>{l?.(e,t)},[e,l]),L=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),M=(0,s.useCallback)(t=>{u?.(e,t)},[e,u]),E=(0,s.useCallback)(t=>{x?.(e,t)},[e,x]);return(0,n.jsx)(nE,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,ollamaModel:a,onOllamaModelChange:S,deepseekModel:i,onDeepseekModelChange:L,chatMode:d,onChatModeChange:M,planMode:m,onPlanModeChange:E,hideHeader:!0,hideSidebar:!0,isActive:h,refreshSignal:f,onLoadingChange:y,onSessionIdChange:N,onTitleChange:C,onShowGitStatus:g,onOpenNote:b,onCreateScheduledTask:v,onOpenSession:j,onContentSearch:w,onShowFileDiff:k})}var nT=r(3292),n$=r(23121),nR=r(88292),nB=r(76900),nF=r(96472);function nI({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[a,c]=(0,s.useState)("agent"),{tabs:u,activeTabId:x,activeTab:h,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,closeTab:b,switchTab:v,handleSelectSession:j,handleNewTab:w,handleNewClaude2Tab:k,handleNewCodexTab:y,handleNewKimiTab:N,handleNewOllamaTab:C,handleNewDeepseekTab:S,handleOpenSession:L,updateTabState:M,updateTabOllamaModel:E,updateTabDeepseekModel:P,updateTabChatMode:T,updateTabPlanMode:$,handleTabDragStart:R,handleTabDragOver:B,handleTabDrop:F,handleTabDragEnd:D}=(0,na.useTabState)({initialCwd:e,initialSessionId:t,activeView:a}),{isPinned:A,pinSession:z,unpinSession:W}=(0,nT.P)(),{createTask:_}=(0,n$.n)(),H=(0,s.useCallback)(e=>{let t=u.find(t=>t.id===e);return!!t?.sessionId&&A(t.sessionId)},[u,A]),O=(0,s.useCallback)(t=>{let r=u.find(e=>e.id===t);r?.sessionId&&(A(r.sessionId)?W(r.sessionId):z(r.sessionId,r.cwd||e||"",r.title))},[u,A,z,W,e]),[q,V]=(0,s.useState)(!1),[U,K]=(0,s.useState)(!1),[J,Z]=(0,s.useState)(!1),[Y,G]=(0,s.useState)(null),[X,ee]=(0,s.useState)(!1),[et,er]=(0,s.useState)("tree"),[en,es]=(0,s.useState)(0),[eo,ea]=(0,s.useState)(null),[el,ei]=(0,s.useState)(0),[ec,ed]=(0,s.useState)(null),[eu,em]=(0,s.useState)(null);(0,s.useEffect)(()=>{e&&i.t4.runPromiseExit((0,nB.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&c(t.activeView)}})},[e]);let[ex,eh]=(0,s.useState)(!1),ef=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(ef.current=a,c("console"),eh(!0)):(eh(!1),ef.current&&"console"!==ef.current&&c(ef.current),ef.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[a]);let ep=(0,s.useCallback)(t=>{c(t),e&&(i.t4.runFork((0,nB.Yn)({cwd:e,settings:{activeView:t}}).pipe(Q.orElse(()=>Q.void))),i.t4.runFork(Q.flatMap(nR.d,r=>r.publish(l.n.ViewChange,{cwd:e,view:t}))))},[e]),eg=(0,s.useCallback)(async()=>{if(!e)return;let t=await i.t4.runPromiseExit((0,nB.b2)(e));if("Success"===t._tag){let r=t.value;if(ee(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&G(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eg())},[eg]);let eb=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"git"===e.type)&&eg()},[eg]);(0,I.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eb,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),ep("agent")):"2"===e.key?(e.preventDefault(),ep("explorer")):"3"===e.key?(e.preventDefault(),ep("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){j(r),n&&ep("agent");let t=u.find(e=>e.sessionId===r);t&&em(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(i.t4.runFork((0,nF.KJ)(e,r,"normal").pipe(Q.orElse(()=>Q.void))),i.t4.runFork((0,nF.M2)(r).pipe(Q.orElse(()=>Q.void))))}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[j,ep,e,u]);let ev=(0,s.useCallback)(()=>{er("status"),es(e=>e+1),ep("explorer")},[ep]),ej=(0,s.useCallback)(e=>{ea(e),ei(e=>e+1),ep("explorer")},[ep]),ew=(0,s.useCallback)((e,t)=>{ed({toolCalls:e,cwd:t}),ep("explorer")},[ep]);(0,s.useEffect)(()=>{ed(null)},[en,el]);let ek=(0,s.useCallback)(()=>{e&&i.t4.runFork(Q.flatMap(nR.d,t=>t.publish(l.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(ns.k_,{children:(0,n.jsx)(ts.fY,{activeView:a,onViewChange:ep,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(nl.TabManagerTopBar,{initialCwd:e,activeTab:h,isGitRepo:X,currentBranch:Y,onOpenWorktree:()=>K(!0),onOpenAliasManager:()=>Z(!0),onBranchSwitched:eg}),ex&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),r("console.screenshotting")]}),e?(0,n.jsxs)(ts.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(ni.TabBar,{tabs:u,activeTabId:x,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,isPinned:H,onTogglePin:O,onSwitchTab:v,onCloseTab:b,onNewTab:w,onNewClaude2Tab:k,onNewCodexTab:y,onNewKimiTab:N,onNewOllamaTab:C,onNewDeepseekTab:S,onOpenProjectSessions:()=>V(!0),onDragStart:R,onDragOver:B,onDrop:F,onDragEnd:D}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===x?"block":"hidden"}`,children:(0,n.jsx)(nP,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:E,deepseekModel:e.deepseekModel,onDeepseekModelChange:P,chatMode:e.chatMode,onChatModeChange:T,planMode:e.planMode,onPlanModeChange:$,isActive:e.id===x&&"agent"===a,refreshSignal:eu,onStateChange:M,onShowGitStatus:ev,onContentSearch:ej,onShowFileDiff:ew,onOpenNote:ek,onCreateScheduledTask:_,onOpenSession:L})},e.id))})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsxs)(m.a9,{children:[(0,n.jsx)(to,{onClose:()=>ep("agent"),cwd:e,initialTab:et,tabSwitchTrigger:en,initialSearchQuery:eo,searchQueryTrigger:el}),ec&&(0,n.jsx)("div",{className:"absolute inset-0 z-20",children:(0,n.jsx)(no.e$,{toolCalls:ec.toolCalls,cwd:ec.cwd,onClose:()=>ed(null)})})]})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsx)(nn,{cwd:e,tabId:"default",onOpenNote:ek})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(ni.TabBar,{tabs:u,activeTabId:x,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,isPinned:H,onTogglePin:O,onSwitchTab:v,onCloseTab:b,onNewTab:w,onNewClaude2Tab:k,onNewCodexTab:y,onNewKimiTab:N,onNewDeepseekTab:S,onDragStart:R,onDragOver:B,onDrop:F,onDragEnd:D}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===x?"block":"hidden"}`,children:(0,n.jsx)(nP,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:E,deepseekModel:e.deepseekModel,onDeepseekModelChange:P,chatMode:e.chatMode,onChatModeChange:T,planMode:e.planMode,onPlanModeChange:$,isActive:e.id===x,refreshSignal:eu,onStateChange:M,onCreateScheduledTask:_,onOpenSession:L})},e.id))})]})]}),e&&(0,n.jsx)(d,{isOpen:q,onClose:()=>V(!1),cwd:e,onSelectSession:j}),e&&X&&(0,n.jsx)(ta,{isOpen:U,onClose:()=>K(!1),cwd:e}),J&&(0,n.jsx)(tF,{onClose:()=>Z(!1),onSave:()=>Z(!1)})]})})})}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>x});var n=r(95155),s=r(12115),o=r(79114),a=r(3238),l=r(34075),i=r(12786),c=r(53853),d=r(86957),u=r(49433),m=r(76900);function x({isOpen:e,onClose:t}){let{t:r,i18n:h}=(0,o.Bd)(),{theme:f,setTheme:p}=(0,a.D)(),g=(0,c.G)(),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.M5)()).then(e=>{"Success"===e._tag&&e.value.language&&y(e.value.language)})},[e]);let N=(0,s.useCallback)(e=>{y(e),d.t4.runFork((0,m.DZ)({language:e}).pipe(u.orElse(()=>u.void)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;h.changeLanguage(t)},[h]),C=g?"installed":"not-installed",S=g?.version??null;if((0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.Wr)()).then(e=>{"Success"===e._tag&&e.value.version&&w(e.value.version)})},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&v(e.value.path)})},[e]),!e)return null;let L=[{value:"system",label:r("settings.themeSystem"),icon:"\uD83D\uDCBB"},{value:"light",label:r("settings.themeLight"),icon:"☀️"},{value:"dark",label:r("settings.themeDark"),icon:"\uD83C\uDF19"}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("settings.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.theme")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:L.map(e=>(0,n.jsxs)("button",{onClick:()=>p(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${f===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.language")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{value:"auto",label:r("settings.languageAuto"),icon:"\uD83C\uDF10"},{value:"en",label:"English",icon:"\uD83C\uDDFA\uD83C\uDDF8"},{value:"zh",label:"中文",icon:"\uD83C\uDDE8\uD83C\uDDF3"}].map(e=>(0,n.jsxs)("button",{onClick:()=>N(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${k===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.browserExtension")}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${"installed"===C?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===C&&`${r("settings.extensionInstalled")}${S?` (v${S})`:""}`,"not-installed"===C&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==C&&(0,n.jsxs)("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-md p-2 space-y-1",children:[(0,n.jsx)("p",{className:"font-medium text-foreground",children:r("settings.installSteps")}),(0,n.jsxs)("p",{children:[r("settings.step1")," ",(0,n.jsx)("code",{className:"px-1 py-0.5 bg-muted rounded text-foreground",children:"chrome://extensions"})]}),(0,n.jsx)("p",{children:r("settings.step2")}),(0,n.jsx)("p",{children:r("settings.step3")}),(0,i.L)()&&(0,n.jsx)("p",{dangerouslySetInnerHTML:{__html:r("settings.step4mac")}})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>{let e=b||"chrome-extension";navigator.clipboard.writeText(e),(0,l.oR)(r("toast.copiedName",{name:e}))},className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:r("settings.copyExtensionPath")}),"installed"===C&&(0,n.jsx)("button",{onClick:()=>{g?.id&&window.chrome?.runtime?.sendMessage&&(window.chrome.runtime.sendMessage(g.id,{type:"reload"}),(0,l.oR)(r("toast.pluginReloading")))},className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-muted transition-colors",children:r("settings.reloadExtension")})]}),b&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:b})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.about")}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground space-y-1",children:[(0,n.jsxs)("p",{children:["Cockpit",j?` v${j}`:""]}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},23121:(e,t,r)=>{r.d(t,{n:()=>m});var n=r(12115),s=r(95045),o=r(75346),a=r(49433),l=r(86957),i=r(82680);let c=(e,t,r)=>a.tryPromise({try:async()=>{let n=await fetch(e,{method:t,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:r=>new i.uV({message:`${t} ${e} failed`,cause:r})}),d="SCHEDULED_TASKS_CHANGED";function u(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:d},"*")}catch{}})}function m(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useCallback)(()=>{let e;l.t4.runPromise((e="/api/scheduled-tasks",a.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new i.uV({message:`fetch ${e} failed`,cause:t})})).pipe(a.match({onSuccess:e=>{t(e.tasks??[]),s(e.unreadCount??0)},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{o()},[o]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===d&&o()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[o]);let m=(0,n.useCallback)(async e=>{let t=await l.t4.runPromiseExit(c("/api/scheduled-tasks","POST",e));if("Success"!==t._tag)return null;let r=t.value;return r.task?(o(),u(),r.task):null},[o]),x=(0,n.useCallback)(async(e,t,r)=>{await l.t4.runPromise(c("/api/scheduled-tasks","PATCH",{id:e,action:t,fields:r}).pipe(a.asVoid).pipe(a.orElse(()=>a.void))),o(),u()},[o]),h=(0,n.useCallback)(e=>x(e,"pause"),[x]),f=(0,n.useCallback)(e=>x(e,"resume"),[x]),p=(0,n.useCallback)(async e=>{await l.t4.runPromise(c("/api/scheduled-tasks","DELETE",{id:e}).pipe(a.asVoid).pipe(a.orElse(()=>a.void))),o(),u()},[o]),g=(0,n.useCallback)((e,t)=>x(e,"update",t),[x]),b=(0,n.useCallback)(e=>x(e,"trigger"),[x]),v=(0,n.useCallback)(e=>x(e,"markRead"),[x]);return{tasks:e,unreadCount:r,reload:o,createTask:m,pauseTask:h,resumeTask:f,triggerTask:b,deleteTask:p,updateTask:g,markRead:v,markAllRead:(0,n.useCallback)(()=>x("_","markAllRead"),[x]),reorderTasks:(0,n.useCallback)(e=>x("_","reorder",{orderedIds:e}),[x])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>d});var n=r(95155),s=r(12115),o=r(94287),a=r(64428),l=r(79114);function i({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function c({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:l,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),m=(0,s.useRef)(null),x=(0,s.useRef)(null),[h,f]=(0,s.useState)({top:0,right:0}),p=(0,a.F2)();(0,s.useEffect)(()=>{if(!d)return;let e=e=>{x.current&&!x.current.contains(e.target)&&m.current&&!m.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let g=n=>{u(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?l?.():"deepseek"===n?i?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:m,onClick:()=>{if(!d&&m.current){let e=m.current.getBoundingClientRect(),t=p?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;f({top:e.bottom+4-n,right:s-(e.right-r)})}u(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"New tab",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),d&&(0,n.jsx)(a.ZL,{children:(0,n.jsxs)("div",{ref:x,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:h.top,right:h.right},children:[(0,n.jsxs)("button",{onClick:()=>g("claude"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}),"Claude Code"]}),(0,n.jsxs)("button",{onClick:()=>g("claude2"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-orange-500 flex-shrink-0"}),"Claude 2"]}),(0,n.jsxs)("button",{onClick:()=>g("codex"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 flex-shrink-0"}),"Codex"]}),(0,n.jsxs)("button",{onClick:()=>g("deepseek"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"}),"DeepSeek"]}),(0,n.jsxs)("button",{onClick:()=>g("kimi"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500 flex-shrink-0"}),"Kimi"]}),(0,n.jsxs)("button",{onClick:()=>g("ollama"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-violet-500 flex-shrink-0"}),"Ollama"]})]})})]})}function d({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:a,isPinned:u,onTogglePin:m,onSwitchTab:x,onCloseTab:h,onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j,onOpenProjectSessions:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C}){let{t:S}=(0,l.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((l,c)=>(0,n.jsx)(o.m,{content:l.title,delay:200,className:"flex-1 min-w-16 max-w-32",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>k(c),onDragOver:e=>y(e,c),onDrop:()=>N(c),onDragEnd:C,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg border-t-[1.5px] transition-colors ${l.id===t?"border-brand bg-slate-4 text-foreground font-medium":"border-transparent text-muted-foreground hover:bg-secondary/50"} ${s===c?"opacity-50":""} ${a===c?"border-l-2 border-brand":""}`,onClick:()=>x(l.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(i,{number:c+1,isActive:l.id===t}),l.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!l.isLoading&&r.has(l.id)&&l.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),m&&u?.(l.id)&&!l.isLoading&&!(r.has(l.id)&&l.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m(l.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:S("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),m&&!u?.(l.id)&&!l.isLoading&&!(r.has(l.id)&&l.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m(l.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:S("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:l.title}),"claude2"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-orange-500/15 text-orange-400 font-medium leading-relaxed",children:"C2"}),"codex"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-emerald-500/15 text-emerald-400 font-medium leading-relaxed",children:"CX"}),"kimi"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-blue-500/15 text-blue-400 font-medium leading-relaxed",children:"KM"}),"ollama"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-violet-500/15 text-violet-400 font-medium leading-relaxed",children:"OL"}),"deepseek"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-sky-500/15 text-sky-400 font-medium leading-relaxed",children:"DS"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(l.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:S("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},l.id)),(0,n.jsx)(c,{onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j}),w&&(0,n.jsx)("button",{onClick:w,className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:S("sessions.projectSessions"),"aria-label":S("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})})]})})}},26520:(e,t,r)=>{r.d(t,{Workspace:()=>q});var n=r(95155),s=r(12115),o=r(79114),a=r(42701),l=r(76288),i=r(83678),c=r(21484),d=r(86957),u=r(62111),m=r(83448);let x={"claude-opus-4-6":{label:"Opus 4.6",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"},"claude-opus-4-5-20251101":{label:"Opus 4.5",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#fb923c"},"claude-sonnet-4-6":{label:"Sonnet 4.6",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#3b82f6"},"claude-sonnet-4-5-20250929":{label:"Sonnet 4.5",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#60a5fa"},"claude-haiku-4-5-20251001":{label:"Haiku 4.5",input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}},h={label:"",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#94a3b8"};function f(e){if(x[e])return x[e];let t=e.toLowerCase();return t.includes("opus")?{...h,input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"}:t.includes("haiku")?{...h,input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}:h}function p(e){let t=x[e];return t?t.label:e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function g(e){return(x[e]??f(e)).color}function b(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function v(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function j({data:e,height:t=200,formatValue:r=b}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),[l,i]=(0,s.useState)(null),c=(0,s.useRef)([]),d=(0,s.useCallback)(()=>{let n=o.current,s=a.current;if(!n||!s)return;let l=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*l,n.height=t*l,n.style.width=`${i}px`,n.style.height=`${t}px`;let d=n.getContext("2d");d.scale(l,l),d.clearRect(0,0,i,t);let{labels:u,datasets:m}=e;if(0===u.length)return;let x=i-50-12,h=t-8-28,f=function(e){if(e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),r=e/t;return r<=1?t:r<=2?2*t:r<=5?5*t:10*t}(Math.max(1,...u.map((e,t)=>m.reduce((e,r)=>e+r.data[t],0))));d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="10px ui-monospace, monospace",d.textAlign="right",d.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;d.fillText(r(t),44,s),d.strokeStyle=(p="--border",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),d.lineWidth=.5,d.beginPath(),d.moveTo(50,s),d.lineTo(50+x,s),d.stroke()}let g=x/u.length,b=Math.max(4,Math.min(.6*g,32)),v=[];u.forEach((e,t)=>{let r=50+t*g+(g-b)/2,s=0;m.forEach(n=>{var o,a,l,i,c,u;let m=n.data[t];if(m<=0)return;let x=m/f*h,p=8+h-s-x;d.fillStyle=n.color,o=d,a=r,l=p,i=b,u=2,(c=x)<1||(u=Math.min(u,c/2,i/2),o.beginPath(),o.moveTo(a+u,l),o.lineTo(a+i-u,l),o.quadraticCurveTo(a+i,l,a+i,l+u),o.lineTo(a+i,l+c-u),o.quadraticCurveTo(a+i,l+c,a+i-u,l+c),o.lineTo(a+u,l+c),o.quadraticCurveTo(a,l+c,a,l+c-u),o.lineTo(a,l+u),o.quadraticCurveTo(a,l,a+u,l),o.fill()),v.push({x:r,y:p,w:b,h:x,label:e,value:m,dataset:n.label,color:n.color}),s+=x}),d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="9px ui-monospace, monospace",d.textAlign="center",d.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&d.fillText(e,r+b/2,8+h+6)}),c.current=v},[e,t,r]);(0,s.useEffect)(()=>{d();let e=new ResizeObserver(()=>d());return a.current&&e.observe(a.current),()=>e.disconnect()},[d]);let u=(0,s.useCallback)(e=>{let t=o.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,s=e.clientY-t.top,a=c.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);a?i({x:e.clientX-t.left,y:a.y-4,content:`${a.dataset}: ${r(a.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:a,className:"relative w-full text-muted-foreground",children:[(0,n.jsx)("canvas",{ref:o,className:"w-full",style:{height:t},onMouseMove:u,onMouseLeave:()=>i(null)}),l&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lg border border-border whitespace-nowrap z-10",style:{left:l.x,top:l.y,transform:"translate(-50%, -100%)"},children:l.content})]})}function w({hourCounts:e}){let{t}=(0,o.Bd)(),r=Math.max(1,...Object.values(e)),s=Array.from({length:24},(e,t)=>t);return(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:t("tokenStats.activeHours")}),(0,n.jsx)("div",{className:"flex gap-[2px] items-end h-16",children:s.map(s=>{let o=e[String(s)]||0,a=o/r;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:s,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*a)}px`,backgroundColor:a>0?`rgba(59, 130, 246, ${.2+.8*a})`:"var(--muted)"}}),s%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:s})]},s)})})]})}function k({isOpen:e,onClose:t}){var r;let a,l,{t:i}=(0,o.Bd)(),[c,x]=(0,s.useState)(null),[h,N]=(0,s.useState)(!0),[C,S]=(0,s.useState)("day"),[L,M]=(0,s.useState)("tokens"),[E,P]=(0,s.useState)("claude");(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>N(!0)),d.t4.runPromiseExit((0,m.Cr)(E)).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>x(t))}queueMicrotask(()=>N(!1))}))},[e,E]);let T=(0,s.useMemo)(()=>c?.modelUsage?Object.entries(c.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:p(e),color:g(e),usage:t,cost:(r=f(e),t.inputTokens/1e6*r.input+t.outputTokens/1e6*r.output+t.cacheReadInputTokens/1e6*r.cacheRead+t.cacheCreationInputTokens/1e6*r.cacheWrite),totalTokens:t.inputTokens+t.outputTokens+t.cacheReadInputTokens+t.cacheCreationInputTokens}}).sort((e,t)=>t.cost-e.cost):[],[c]),$=(0,s.useMemo)(()=>T.reduce((e,t)=>e+t.cost,0),[T]),R=(0,s.useMemo)(()=>T.map(e=>e.id),[T]),B=(0,s.useMemo)(()=>{let e={};for(let t of T)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[T]),{activityChart:F,tokenChart:I,costChart:D}=(0,s.useMemo)(()=>{let e=c?.dailyActivity||[],t=c?.dailyModelTokens||[];if("day"===C){let r=e.slice(-60),n=t.slice(-60),s={labels:r.map(e=>e.date.slice(5)),datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messageCount),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:"#22c55e"}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:R.map(e=>({label:p(e),data:n.map(t=>t.tokensByModel[e]||0),color:g(e)}))},costChart:{labels:o,datasets:R.map(e=>({label:p(e),data:n.map(t=>(t.tokensByModel[e]||0)*(B[e]||0)),color:g(e)}))}}}if("week"===C){let r=function(e,t){let r=new Map;for(let t of e){let e=new Date(t.date),n=new Date(e);n.setDate(e.getDate()-e.getDay());let s=n.toISOString().slice(0,10),o=s.slice(5);r.has(s)||r.set(s,{label:o,messages:0,sessions:0,tools:0,tokensByModel:{}});let a=r.get(s);a.messages+=t.messageCount,a.sessions+=t.sessionCount,a.tools+=t.toolCallCount}for(let e of t){let t=new Date(e.date),n=new Date(t);n.setDate(t.getDate()-t.getDay());let s=n.toISOString().slice(0,10);r.has(s)||r.set(s,{label:s.slice(5),messages:0,sessions:0,tools:0,tokensByModel:{}});let o=r.get(s);for(let[t,r]of Object.entries(e.tokensByModel))o.tokensByModel[t]=(o.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:R.map(e=>({label:p(e),data:r.map(t=>t.tokensByModel[e]||0),color:g(e)}))},costChart:{labels:n,datasets:R.map(e=>({label:p(e),data:r.map(t=>(t.tokensByModel[e]||0)*(B[e]||0)),color:g(e)}))}}}let r=function(e,t){let r=new Map;for(let t of e){let e=t.date.slice(0,7);r.has(e)||r.set(e,{label:e,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(e);n.messages+=t.messageCount,n.sessions+=t.sessionCount,n.tools+=t.toolCallCount}for(let e of t){let t=e.date.slice(0,7);r.has(t)||r.set(t,{label:t,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(t);for(let[t,r]of Object.entries(e.tokensByModel))n.tokensByModel[t]=(n.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:R.map(e=>({label:p(e),data:r.map(t=>t.tokensByModel[e]||0),color:g(e)}))},costChart:{labels:n,datasets:R.map(e=>({label:p(e),data:r.map(t=>(t.tokensByModel[e]||0)*(B[e]||0)),color:g(e)}))}}},[c,C,R,B,i]);if((0,u.E)(t,e),!e)return null;let A=[{key:"day",label:i("tokenStats.day")},{key:"week",label:i("tokenStats.week")},{key:"month",label:i("tokenStats.month")}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-xl w-full max-w-4xl mx-4 max-h-[90vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("tokenStats.title")}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:["claude","claude2"].map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${E===e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{x(null),P(e)},children:"claude"===e?"Claude":"Claude 2"},e))}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:A.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${C===e.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>S(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:h?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(y,{label:i("tokenStats.totalSessions"),value:String(c.totalSessions??0)}),(0,n.jsx)(y,{label:i("tokenStats.totalMessages"),value:b(c.totalMessages??0)}),(0,n.jsx)(y,{label:i("tokenStats.equivalentApiCost"),value:v($),highlight:!0}),(0,n.jsx)(y,{label:i("tokenStats.longestSession"),value:c.longestSession?(a=Math.floor((r=c.longestSession.duration)/36e5),l=Math.floor(r%36e5/6e4),a>0?`${a}h ${l}m`:`${l}m`):"-"}),(0,n.jsx)(y,{label:i("tokenStats.firstUse"),value:c.firstSessionDate?c.firstSessionDate.slice(0,10):"-"})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.activityTrend")}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-[10px]",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#3b82f6"}}),i("tokenStats.messages")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#22c55e"}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(j,{data:F,height:180})})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.byModel")}),(0,n.jsxs)("div",{className:"flex bg-muted rounded-md p-0.5",children:[(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"tokens"===L?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>M("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===L?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>M("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:T.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:e.color}}),e.label]},e.id))})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(j,{data:"tokens"===L?I:D,height:180,formatValue:"tokens"===L?b:v})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("tokenStats.modelCostDetail")}),(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"bg-muted/50 text-muted-foreground",children:[(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium",children:i("tokenStats.model")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Input"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Output"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Read"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Write"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.share")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.equivalentCost")})]})}),(0,n.jsxs)("tbody",{children:[T.map(e=>(0,n.jsxs)("tr",{className:"border-t border-border",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.label]})}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:$>0?`${(e.cost/$*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:v(e.cost)})]},e.id)),(0,n.jsxs)("tr",{className:"border-t-2 border-border bg-muted/30",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-medium text-foreground",children:i("tokenStats.total")}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(T.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(T.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(T.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(T.reduce((e,t)=>e+t.usage.cacheCreationInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:"100%"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-bold text-foreground",children:v($)})]})]})]})})]}),c.hourCounts&&Object.keys(c.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(w,{hourCounts:c.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function y({label:e,value:t,highlight:r}){return(0,n.jsxs)("div",{className:"bg-muted/30 rounded-lg px-3 py-2.5",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground",children:e}),(0,n.jsx)("div",{className:`text-sm font-semibold mt-0.5 ${r?"text-brand":"text-foreground"}`,children:t})]})}var N=r(60865),C=r(34075),S=r(5135),L=r(38408),M=r(49433),E=r(82680);let P=(e,t)=>M.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok){let e;try{e=(await r.json()).error}catch{}throw Error(e||`HTTP ${r.status}`)}return await r.json()},catch:r=>new E.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})});function T({skillId:e,onClose:t}){let[r,o]=(0,s.useState)(null),[a,l]=(0,s.useState)(!0),[i,c]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return l(!0),d.t4.runPromiseExit(P(`/api/skills/content?id=${encodeURIComponent(e)}`)).then(e=>{t||("Success"===e._tag?o(e.value):console.error("Failed to load skill content",e.cause),l(!1))}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),(0,u.k)(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let m=(0,s.useCallback)(async()=>{if(r?.path)try{await navigator.clipboard.writeText(r.path),(0,C.oR)("Path copied","success")}catch{(0,C.oR)("Failed to copy","error")}},[r]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-[70%] h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:r?.name?`/${r.name}`:"Skill Preview"}),(0,n.jsx)("button",{onClick:m,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),r?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:r.path})]}),(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>c("preview"),className:`px-3 py-1 transition-colors ${"preview"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Preview"}),(0,n.jsx)("button",{onClick:()=>c("source"),className:`px-3 py-1 transition-colors ${"source"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Source"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors flex-shrink-0",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),a?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Loading..."}):r&&r.valid?"preview"===i?(0,n.jsx)(S.M,{content:r.content,filePath:r.path,cwd:r.path.slice(0,Math.max(0,r.path.lastIndexOf("/"))),embedded:!0,onClose:t}):(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsx)(L.XO,{content:r.content,filePath:r.path,className:"min-h-full"})}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"File cannot be read."})]})]})}var $=r(88371);function R({isOpen:e,onClose:t}){let[r,o]=(0,s.useState)([]),[a,l]=(0,s.useState)(!1),[i,c]=(0,s.useState)(""),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(null),j=(0,s.useCallback)(async()=>{l(!0);let e=await d.t4.runPromiseExit(P("/api/skills"));"Success"===e._tag?o(e.value):console.error("Failed to load skills",e.cause),l(!1)},[]);(0,s.useEffect)(()=>{e&&(j(),setTimeout(()=>{v.current?.focus(),v.current?.select()},100))},[e,j]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!g){if(u){m(!1),h("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,u,g]);let w=(0,s.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):r},[r,i]),k=(0,s.useCallback)(async()=>{let e=x.trim();if(!e)return;p(!0);let t=await d.t4.runPromiseExit(P("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}));if("Success"===t._tag)(0,C.oR)("Skill added","success"),h(""),m(!1),await j(),(0,$.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:"Failed to add skill";(0,C.oR)(n,"error")}p(!1)},[x,j]),y=(0,s.useCallback)(async e=>{"Success"===(await d.t4.runPromiseExit(P(`/api/skills/${encodeURIComponent(e)}`,{method:"DELETE"})))._tag?(o(t=>t.filter(t=>t.id!==e)),(0,$.k)()):(0,C.oR)("Failed to delete","error")},[]),N=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,C.oR)("Path copied","success")}catch{(0,C.oR)("Failed to copy","error")}},[]);return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-7xl h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:"Skills"}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:v,type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Search skills...",className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),i&&(0,n.jsx)("button",{onClick:()=>{c(""),v.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:"Clear",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("button",{onClick:()=>m(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:"Add Skill",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Add Skill"]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:a?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:"Loading..."}):0===w.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:0===r.length?'No skills yet. Click "Add Skill" to add one.':"No skills match your search."}):(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:w.map(e=>(0,n.jsx)(B,{skill:e,onPreview:()=>b(e.id),onDelete:()=>y(e.id),onCopyPath:()=>N(e.path)},e.id))})})]})]}),u&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:()=>{f||(m(!1),h(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:"Add Skill"}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:"Absolute path to SKILL.md"}),(0,n.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"!==e.key||f||k()},placeholder:"/Users/you/.../skills/foo/SKILL.md",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{m(!1),h("")},disabled:f,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",children:"Cancel"}),(0,n.jsx)("button",{onClick:k,disabled:f||!x.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:f?"Adding...":"Add"})]})]})]}),g&&(0,n.jsx)(T,{skillId:g,onClose:()=>b(null)})]}):null}function B({skill:e,onPreview:t,onDelete:r,onCopyPath:o}){let[a,l]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`group flex flex-col h-full border border-border rounded-lg p-3 bg-secondary hover:border-brand hover:shadow-md transition-all ${e.valid?"":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)("div",{className:"w-9 h-9 flex-shrink-0 flex items-center justify-center rounded-md bg-brand/10 text-brand text-lg",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})})}),(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground truncate flex-1 min-w-0",title:`/${e.name}`,children:["/",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"flex-shrink-0 text-xs px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:"Invalid"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Preview",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})}),a?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{l(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:"Confirm"}),(0,n.jsx)("button",{onClick:()=>l(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:"Cancel"})]}):(0,n.jsx)("button",{onClick:()=>l(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:"Delete",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M1 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})]})]}),(0,n.jsxs)("div",{className:"font-mono text-xs text-muted-foreground mt-2 break-all",children:[e.path,(0,n.jsx)("button",{onClick:o,className:"inline-flex align-middle ml-1 p-0.5 hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mt-2 pt-2 border-t border-border/60 break-words whitespace-pre-wrap",children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:"No description"})}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-1 truncate",title:e.argumentHint,children:e.argumentHint})]})}var F=r(47650);let I=[],D=[];function A(){D.forEach(e=>e())}function z(e){I=I.filter(t=>t.id!==e),A()}function W({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return D.push(t),()=>{D=D.filter(e=>e!==t)}},[]),I}();return 0===t.length?null:(0,F.createPortal)((0,n.jsx)("div",{className:"fixed bottom-4 left-4 z-[100] flex flex-col gap-2 pointer-events-none",children:t.map(t=>(0,n.jsx)(_,{item:t,onNavigate:e,onRemove:z},t.id))}),document.body)}function _({item:e,onNavigate:t,onRemove:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),c=(0,s.useRef)(void 0),d=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(c.current=setTimeout(d,5e3),()=>clearTimeout(c.current)),[d]);let u=(0,s.useCallback)(()=>{clearTimeout(c.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),m=(0,s.useCallback)(()=>{clearTimeout(c.current)},[]),x=(0,s.useCallback)(()=>{c.current=setTimeout(d,2e3)},[d]);return(0,n.jsxs)("div",{className:`pointer-events-auto bg-card border border-border rounded-lg shadow-lg px-3 py-2.5 min-w-[260px] max-w-[340px] cursor-pointer hover:bg-accent transition-all ${l?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:l?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:m,onMouseLeave:x,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-green-9 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:e.projectName}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:a("common.done")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"ml-auto p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.message&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-1 ml-6",children:e.message})]})}var H=r(77725);let O=M.tryPromise({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new E.uV({message:"fetch /api/projects failed",cause:e})});function q({initialCwd:e,initialSessionId:t}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)(0),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,P]=(0,s.useState)(null),[T,$]=(0,s.useState)(!1),[B,F]=(0,s.useState)(!1),[D,z]=(0,s.useState)(new Set),_=(0,s.useRef)(new Map),V=(0,s.useRef)(new Map),U=(0,s.useRef)(new Map),K=(0,s.useRef)(null),J=(0,H.Z)(O,[]);(0,s.useEffect)(()=>{if("success"===J.status){let e=J.data;m([...e.projects||[]]),h(e.activeIndex||0),p(e.collapsed||!1),F(!0)}else"error"===J.status&&(console.error("Failed to load projects:",J.error),F(!0))},[J]);let Q=(0,s.useCallback)(async(e,t,n)=>{let s,{Effect:o}=await r.e(9012).then(r.bind(r,49012)),{BrowserRuntime:a}=await r.e(7562).then(r.bind(r,47562)),l=await a.runPromise((s={projects:e,activeIndex:t,collapsed:n},M.tryPromise({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(s)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new E.uV({message:"save /api/projects failed",cause:e})})).pipe(o.either));"Left"===l._tag&&console.error("Failed to save projects:",l.left)},[]);(0,s.useEffect)(()=>{let e=u[x]?.cwd;e&&z(t=>t.has(e)?t:new Set(t).add(e))},[x,u]),(0,s.useEffect)(()=>{for(let[e,t]of _.current.entries()){let r=u[x]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r},"*")}},[x,u]);let Z=(0,s.useCallback)((e,t)=>{let r=new URL(window.location.href);r.searchParams.set("cwd",e),t?r.searchParams.set("sessionId",t):r.searchParams.delete("sessionId"),window.history.replaceState({},"",r.toString());let n=e.split("/").filter(Boolean).pop();document.title=n?`Cockpit - ${n}`:"Cockpit"},[]),Y=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!B||Y.current||!e)return;Y.current=!0,t&&(V.current.set(e,{sessionId:t}),U.current.set(e,t));let r=u.findIndex(t=>t.cwd===e);if(r>=0)r!==x&&(h(r),Q(u,r,f));else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),Q(t,r,f)}Z(e,t)},[B,e,t,u,x,f,Q,Z]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r}=e.data;U.current.set(t,r);let n=u[x];n?.cwd===t&&Z(t,r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:r,sessionId:n,lastUserMessage:s}=e.data,o=u[x];if(o?.cwd!==r){var t;let e;t={projectName:r.split("/").pop()||r,message:s,cwd:r,sessionId:n},e=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,I=[...I,{...t,id:e}],A()}}if(e.data?.type==="OPEN_TOKEN_STATS"&&y(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&(P(e.data.cwd),S(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){K.current=x;let t=e.data.cwd,r=u.findIndex(e=>e.cwd===t);r>=0&&r!==x&&h(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==K.current&&K.current!==x&&h(K.current),K.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r}=e.data,n=r||"";U.current.set(t,n);let s=u.findIndex(e=>e.cwd===t);if(s>=0){if(n){let e=_.current.get(t);e?.contentWindow&&e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:n},"*")}s!==x&&(h(s),Q(u,s,f))}else{let e=[...u,{cwd:t}],r=e.length-1;m(e),h(r),Q(e,r,f),n&&V.current.set(t,{sessionId:n})}Z(t,n)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[u,x,f,Z,Q]),(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&!e.altKey){if(!e.shiftKey&&("p"===e.key||"f"===e.key||"s"===e.key))return void e.preventDefault();e.ctrlKey&&!e.metaKey&&"Minus"===e.code&&e.preventDefault()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let G=(0,s.useCallback)(e=>{h(e),Q(u,e,f);let t=u[e];if(t?.cwd){let e=U.current.get(t.cwd);Z(t.cwd,e)}},[u,f,Q,Z]),X=(0,s.useCallback)(e=>{let t=u.filter((t,r)=>r!==e),r=x;e<x?r=x-1:e===x&&r>=t.length&&(r=Math.max(0,t.length-1)),m(t),h(r),Q(t,r,f)},[u,x,f,Q]),ee=(0,s.useCallback)(e=>{let t=u[x],r=e.findIndex(e=>e.cwd===t?.cwd);m(e),h(r>=0?r:0),Q(e,r>=0?r:0,f)},[u,x,f,Q]),et=(0,s.useCallback)(()=>{let e=!f;p(e),Q(u,x,e)},[u,x,f,Q]),er=(0,s.useCallback)((e,t)=>{U.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=_.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),h(r),Q(u,r,f)}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),Q(r,n,f),V.current.set(e,{sessionId:t,switchToAgent:!0})}Z(e,t),b(!1)},[u,f,Q,Z]),en=(0,s.useCallback)((e,t)=>{U.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=_.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),r!==x&&(h(r),Q(u,r,f))}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),Q(r,n,f),V.current.set(e,{sessionId:t,switchToAgent:!0})}Z(e,t)},[u,x,f,Q,Z]),es=(0,s.useCallback)(e=>{let t=V.current.get(e);if(t){let r=_.current.get(e);r?.contentWindow&&r.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t.sessionId,switchToAgent:t.switchToAgent},"*"),V.current.delete(e)}},[]);return B?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(a.ProjectSidebar,{projects:u,activeIndex:x,collapsed:f,currentCwd:u[x]?.cwd,onSelectProject:G,onRemoveProject:X,onReorderProjects:ee,onToggleCollapse:et,onOpenSessionBrowser:()=>b(!0),onOpenSettings:()=>j(!0),onOpenNote:e=>{P(e??null),S(!0)},onOpenSkills:()=>$(!0),onSwitchProject:en,onAddProject:e=>{let t=u.findIndex(t=>t.cwd===e);if(t>=0)h(t),Q(u,t,f);else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),Q(t,r,f)}}}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===u.length?(0,n.jsx)(l.EmptyState,{onSelectSession:er}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:u.map((e,t)=>D.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?_.current.set(e.cwd,t):_.current.delete(e.cwd)},src:`/project?cwd=${encodeURIComponent(e.cwd)}`,onLoad:()=>es(e.cwd),className:`absolute inset-0 w-full h-full border-0 ${t===x?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd))})}),(0,n.jsx)(i.SessionBrowser,{isOpen:g,onClose:()=>b(!1),onSelectSession:er,onAddProject:e=>{let t=u.findIndex(t=>t.cwd===e);if(t>=0)h(t),Q(u,t,f);else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),Q(t,r,f)}b(!1)}}),(0,n.jsx)(c.SettingsModal,{isOpen:v,onClose:()=>j(!1)}),(0,n.jsx)(k,{isOpen:w,onClose:()=>y(!1)}),(0,n.jsx)(N.NoteModal,{isOpen:C,onClose:()=>{S(!1),P(null)},projectCwd:L,projectName:L?L.split("/").pop():null}),(0,n.jsx)(R,{isOpen:T,onClose:()=>$(!1)}),(0,n.jsx)(W,{onNavigate:en})]}):(0,n.jsx)("div",{className:"h-screen flex items-center justify-center bg-card",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:d("workspace.loadingText")})]})})}},41474:(e,t,r)=>{r.d(t,{F:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)(()=>"u"<typeof document||"visible"===document.visibilityState);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}},42701:(e,t,r)=>{r.d(t,{ProjectSidebar:()=>k});var n=r(95155),s=r(12115),o=r(79114),a=r(2228),l=r(86957),i=r(53213),c=r(83448);function d({isOpen:e,onClose:t,onSwitchProject:r}){let{t:a}=(0,o.Bd)(),[i,u]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useCallback)(async()=>{x(!0),f(null);let e=await l.t4.runPromiseExit((0,c.z2)());"Success"===e._tag?u([...e.value]):f(a("sessions.loadSessionsFailed")),x(!1)},[a]);(0,s.useEffect)(()=>{e&&(v(),setTimeout(()=>{b.current?.focus(),b.current?.select()},100))},[e,v]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let j=i.filter(e=>{if(!p)return!0;let t=p.toLowerCase();return void 0!==e.searchText?e.searchText.includes(t):e.cwd.toLowerCase().includes(t)||(e.title?.toLowerCase().includes(t)??!1)||(e.lastUserMessage?.toLowerCase().includes(t)??!1)||(e.firstMessages?.some(e=>e.toLowerCase().includes(t))??!1)||(e.lastMessages?.some(e=>e.toLowerCase().includes(t))??!1)});return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-7xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:a("sessions.recentSessions")})}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:b,type:"text",placeholder:a("sessions.searchSessions"),value:p,onChange:e=>g(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),p&&(0,n.jsx)("button",{onClick:()=>{g(""),b.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:a("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:a("sessions.loadingSessions")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:h})}),!m&&!h&&0===j.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:p?a("sessions.noMatchingSessions"):a("sessions.noSessions")})}),!m&&!h&&j.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:j.map(e=>{let s;return(0,n.jsxs)("div",{onClick:()=>{r(e.cwd,e.sessionId),t()},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${"loading"===e.status?"bg-orange-9 animate-pulse":"unread"===e.status?"bg-red-500":"bg-muted-foreground/30"}`}),e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate flex-1",title:e.cwd,children:(s=e.cwd).split("/").pop()||s}),"loading"===e.status&&(0,n.jsx)("span",{className:"text-[10px] text-orange-11 flex-shrink-0",children:a("sessions.running")}),"unread"===e.status&&(0,n.jsx)("span",{className:"text-[10px] text-red-500 flex-shrink-0",children:a("sessions.done")})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.lastActive).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(e.firstMessages?.length??0)>0||(e.lastMessages?.length??0)>0?(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[e.firstMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),(e.lastMessages?.length??0)>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]}):e.lastUserMessage||e.title?(0,n.jsxs)("div",{className:"text-xs text-foreground truncate",title:e.lastUserMessage||e.title,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e.lastUserMessage||e.title]}):null]},`${e.cwd}-${e.sessionId}`)})})]})]})]}):null}function u({currentCwd:e,onSwitchProject:t,collapsed:r,sessions:a}){let{t:c}=(0,o.Bd)(),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(0),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)({}),y=(0,s.useCallback)((e,t)=>{let r=t.currentTarget.getBoundingClientRect(),n=r.top;n+260>window.innerHeight&&(n=Math.max(8,window.innerHeight-260-8)),j({session:e,top:n,left:r.right+8}),k(t=>e.cwd in t?t:(l.t4.runPromiseExit((0,i.ue)(e.cwd)).then(t=>{"Success"===t._tag&&k(r=>({...r,[e.cwd]:t.value.branch}))}),{...t,[e.cwd]:null}))},[]),N=(0,s.useCallback)(()=>j(null),[]);(0,s.useEffect)(()=>{m||j(null)},[m]),(0,s.useEffect)(()=>{if(!m)return;let e=e=>{b.current&&!b.current.contains(e.target)&&x(!1)},t=()=>{x(!1)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[m]);let C=(0,s.useCallback)(e=>{t(e.cwd,e.sessionId),x(!1),j(null)},[t]),S=a.filter(e=>"loading"===e.status).length,L=a.filter(e=>"unread"===e.status).length,M=(0,s.useCallback)(e=>{let t=Math.floor((p-e)/6e4);if(t<1)return c("common.justNow");if(t<60)return c("common.minutesAgo",{count:t});let r=Math.floor(t/60);return r<24?c("common.hoursAgo",{count:r}):c("common.daysAgo",{count:Math.floor(r/24)})},[c,p]),E=e=>e.split("/").pop()||e;return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsxs)("button",{onClick:()=>{g(Date.now()),x(!m)},className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"w-full justify-center":"w-full"}`,title:c("sessions.recentSessions"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),!r&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:c("sessions.recentSessions")}),S>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-orange-9 animate-pulse ${r?"absolute -top-1 -right-1":""}`,children:S}),L>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${r&&!S?"absolute -top-1 -right-1":""}`,children:L})]}),m&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:c("sessions.recentSessions")}),S>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-orange-11",children:["(",c("sessions.runningCount",{count:S}),")"]}),L>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-red-500",children:["(",c("sessions.unreadCount",{count:L}),")"]}),(0,n.jsx)("button",{onClick:()=>{g(Date.now()),x(!1),j(null),f(!0)},className:"ml-auto p-1 -mr-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:c("sessions.searchRecentSessions"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15"})})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:c("sessions.noSessions")}):a.map((t,r)=>(0,n.jsxs)("button",{onClick:()=>C(t),onMouseEnter:e=>y(t,e),onMouseLeave:N,className:`w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 ${r!==a.length-1?"border-b border-border/50":""} ${e===t.cwd?"bg-accent/50":""}`,children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${"loading"===t.status?"bg-orange-9 animate-pulse":"unread"===t.status?"bg-red-500":"bg-muted-foreground/30"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:E(t.cwd)}),"loading"===t.status&&(0,n.jsx)("span",{className:"text-xs text-orange-11 flex-shrink-0",children:c("sessions.running")}),"unread"===t.status&&(0,n.jsx)("span",{className:"text-xs text-red-500 flex-shrink-0",children:c("sessions.done")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:M(t.lastActive)})]}),(t.lastUserMessage||t.title)&&(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:t.lastUserMessage||t.title})]})]},`${t.cwd}-${t.sessionId}`))})]}),v&&(0,n.jsxs)("div",{className:"fixed z-[60] w-72 max-h-[260px] overflow-y-auto bg-popover border border-border rounded-lg shadow-lg p-3 pointer-events-none",style:{top:v.top,left:v.left},children:[(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate",children:E(v.session.cwd)}),w[v.session.cwd]&&(0,n.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-normal min-w-0",children:[(0,n.jsxs)("svg",{className:"w-3 h-3 flex-shrink-0 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2.5"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2.5"}),(0,n.jsx)("circle",{cx:"18",cy:"7",r:"2.5"}),(0,n.jsx)("path",{strokeLinecap:"round",d:"M6 8.5v7M8.5 6.5h4.5a3 3 0 013 3v0"})]}),(0,n.jsx)("span",{className:"truncate",children:w[v.session.cwd]})]}),(v.session.firstMessages?.length??0)>0||(v.session.lastMessages?.length??0)>0?(0,n.jsxs)("div",{className:"space-y-0.5 text-xs border-t border-border/50 mt-2 pt-2",children:[v.session.firstMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground/90 truncate",children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`f-${t}`)),(v.session.lastMessages?.length??0)>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),v.session.lastMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground/90 truncate",children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`l-${t}`))]}):v.session.lastUserMessage||v.session.title?(0,n.jsx)("div",{className:"text-xs text-foreground/90 border-t border-border/50 mt-2 pt-2 line-clamp-3 break-words",children:v.session.lastUserMessage||v.session.title}):null]}),(0,n.jsx)(d,{isOpen:h,onClose:()=>f(!1),onSwitchProject:t})]})}function m({collapsed:e,pinnedSessions:t,onSwitchProject:r,onUnpin:a,onUpdateTitle:l,onReorder:i}){let{t:c}=(0,o.Bd)(),[d,u]=(0,s.useState)(!1),x=(0,s.useRef)(null),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{x.current&&!x.current.contains(e.target)&&(u(!1),f(null))},t=()=>{u(!1),f(null)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[d]),(0,s.useEffect)(()=>{h&&(b.current?.focus(),b.current?.select())},[h]);let y=(0,s.useCallback)(e=>{h||(r(e.cwd,e.sessionId),u(!1))},[r,h]),N=(0,s.useCallback)((e,t)=>{t.stopPropagation(),f(e.sessionId),g(e.customTitle||"")},[]),C=(0,s.useCallback)(()=>{h&&p.trim()&&l(h,p.trim()),f(null)},[h,p,l]),S=(0,s.useCallback)(e=>{j(e)},[]),L=(0,s.useCallback)((e,t)=>{e.preventDefault(),k(t)},[]),M=(0,s.useCallback)(e=>{if(null===v||v===e){j(null),k(null);return}let r=[...t],[n]=r.splice(v,1);r.splice(e,0,n),i(r),j(null),k(null)},[v,t,i]),E=(0,s.useCallback)(()=>{j(null),k(null)},[]);return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>u(!d),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:c("sessions.pinnedSessions"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:c("sessions.pinnedSessions")}),e&&t.length>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-accent",children:t.length})]}),d&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 max-h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:c("sessions.pinnedSessions")})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:c("sessions.noPinnedSessions")}):t.map((e,r)=>{let s;return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>S(r),onDragOver:e=>L(e,r),onDrop:()=>M(r),onDragEnd:E,onClick:()=>y(e),className:`group w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 cursor-pointer ${r!==t.length-1?"border-b border-border/50":""} ${v===r?"opacity-50":""} ${w===r?"border-t-2 border-brand":""}`,children:[(0,n.jsx)("span",{className:"mt-1.5 text-muted-foreground/30 flex-shrink-0 cursor-grab",children:(0,n.jsxs)("svg",{className:"w-3 h-3",viewBox:"0 0 10 16",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"3",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"14",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"14",r:"1.5"})]})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",title:e.cwd,children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:(s=e.cwd).split("/").pop()||s})}),h===e.sessionId?(0,n.jsx)("input",{ref:b,type:"text",value:p,onChange:e=>g(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||("Enter"===e.key&&C(),"Escape"===e.key&&f(null))},onBlur:C,onClick:e=>e.stopPropagation(),className:"w-full text-xs px-1 py-0.5 border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring mt-0.5"}):(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:e.customTitle||e.sessionId.slice(0,8)})]}),h!==e.sessionId&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity mt-0.5",children:[(0,n.jsx)("button",{onClick:t=>N(e,t),className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:c("sessions.editTitle"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),a(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:c("sessions.remove"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},e.sessionId)})})]})]})}var x=r(93777);function h(e,t){if("once"===e.type)return t("scheduledTasks.onceType",{minutes:e.delayMinutes});if("interval"===e.type){let r=t("scheduledTasks.everyNMinutes",{minutes:e.intervalMinutes});return e.activeFrom&&e.activeTo?`${r} (${e.activeFrom}-${e.activeTo})`:r}return"cron"===e.type?e.cron||"cron":e.type}function f(e){return e.unread?"bg-red-500":e.completed?"bg-muted-foreground":e.paused?"bg-yellow-500":"error"===e.lastResult?"bg-red-500":"bg-green-500"}function p({collapsed:e,tasks:t,unreadCount:r,onSwitchProject:a,onPause:l,onResume:i,onTrigger:c,onDelete:d,onMarkRead:u,onUpdateTask:m,onReorder:g}){let{t:b}=(0,o.Bd)(),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),y=(0,s.useRef)(null),N=t.filter(e=>!e.completed),C=N.filter(e=>!e.paused).length,S=t.filter(e=>e.completed),[L,M]=(0,s.useState)(null),[E,P]=(0,s.useState)(null),T=(0,s.useCallback)(e=>{M(e)},[]),$=(0,s.useCallback)((e,t)=>{e.preventDefault(),P(t)},[]),R=(0,s.useCallback)(e=>{if(null===L||L===e){M(null),P(null);return}let t=[...N],[r]=t.splice(L,1);t.splice(e,0,r),g([...t,...S].map(e=>e.id)),M(null),P(null)},[L,N,S,g]),B=(0,s.useCallback)(()=>{M(null),P(null)},[]),[,F]=(0,s.useState)(0);return(0,s.useEffect)(()=>{if(!v)return;let e=setInterval(()=>F(e=>e+1),1e4);return()=>clearInterval(e)},[v]),(0,s.useEffect)(()=>{if(!v)return;let e=e=>{y.current&&!y.current.contains(e.target)&&j(!1)},t=()=>j(!1);return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[v]),(0,n.jsxs)("div",{className:"relative",ref:y,children:[(0,n.jsxs)("button",{onClick:()=>j(!v),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:b("scheduledTasks.title"),children:[(0,n.jsxs)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:b("scheduledTasks.title")}),r>0?(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${e?"absolute -top-1 -right-1":""}`,children:r}):e&&t.length>0?(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-accent",children:t.length}):null]}),v&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-96 max-h-[500px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:b("scheduledTasks.title")}),N.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[b("scheduledTasks.activeCount",{running:C}),N.length-C>0?` \xb7 ${b("scheduledTasks.pausedCount",{paused:N.length-C})}`:""]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:b("scheduledTasks.noScheduledTasks")}):(0,n.jsxs)(n.Fragment,{children:[N.map((e,t)=>{var r;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>T(t),onDragOver:e=>$(e,t),onDrop:()=>R(t),onDragEnd:B,className:`group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 cursor-pointer ${e.unread?"bg-brand/5":""} ${L===t?"opacity-50":""} ${E===t?"border-t-2 border-brand":""}`,onClick:()=>{a(e.cwd,e.sessionId),e.unread&&u(e.id),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${f(e)}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground font-mono",children:(r=e.cwd).split("/").pop()||r}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"\xb7"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:e.completed?b("scheduledTasks.completed"):e.paused?b("scheduledTasks.paused"):b("common.running")})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5",title:e.message,children:e.message}),(0,n.jsxs)("div",{className:"flex items-center gap-3 mt-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{children:h(e,b)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{children:e.paused?b("scheduledTasks.paused"):function(e,t){if(!e)return"-";let r=e-Date.now();if(r<=0)return t("scheduledTasks.aboutToTrigger");if(r<6e4)return t("scheduledTasks.secondsLater",{count:Math.ceil(r/1e3)});if(r<36e5)return t("scheduledTasks.minutesLater",{count:Math.ceil(r/6e4)});if(r<864e5){let e=Math.floor(r/36e5),n=Math.ceil(r%36e5/6e4);return n>0?t("scheduledTasks.hoursMinutesLater",{h:e,m:n}):t("scheduledTasks.hoursLater",{h:e})}return new Date(e).toLocaleDateString("zh-CN",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(e.nextFireTime,b)}),e.lastFiredAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsxs)("span",{children:[b("scheduledTasks.lastResult"),": ","success"===e.lastResult?"✓":"✗"]})]})]})]}),(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),c(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-brand",title:b("scheduledTasks.runNow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{d:"M8 5v14l11-7z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),k(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:b("common.edit"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-500",title:b("scheduledTasks.resume"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"})})}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),l(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-yellow-500",title:b("scheduledTasks.pause"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 9v6m4-6v6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]})},e.id)}),S.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-muted/30 border-b border-border/50",children:b("scheduledTasks.completedCount",{count:S.length})}),S.map(e=>(0,n.jsx)("div",{className:"group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 opacity-60 cursor-pointer",onClick:()=>{a(e.cwd,e.sessionId),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${f(e)}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:e.message}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground mt-0.5",children:[h(e,b)," \xb7 ","success"===e.lastResult?b("scheduledTasks.success"):b("scheduledTasks.failure")]})]}),(0,n.jsx)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]})},e.id))]})]})})]}),w&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/30",onClick:()=>k(null)}),(0,n.jsx)("div",{className:"relative",children:(0,n.jsx)(x.E,{onClose:()=>k(null),onCreate:()=>{},editTask:{id:w.id,message:w.message,type:w.type,delayMinutes:w.delayMinutes,intervalMinutes:w.intervalMinutes,activeFrom:w.activeFrom,activeTo:w.activeTo,cron:w.cron},onUpdate:(e,t)=>{m(e,t),k(null)}})})]})]})}var g=r(3292),b=r(23121),v=r(34075),j=r(2111),w=r(76900);function k({projects:e,activeIndex:t,collapsed:r,currentCwd:i,onSelectProject:c,onRemoveProject:d,onReorderProjects:x,onToggleCollapse:h,onOpenSessionBrowser:f,onOpenSettings:y,onOpenNote:N,onOpenSkills:C,onSwitchProject:S,onAddProject:L}){let{t:M,i18n:E}=(0,o.Bd)(),{latest:P,hasUpdate:T}=function(){let[e,t]=(0,s.useState)(),[r,n]=(0,s.useState)();(0,s.useEffect)(()=>{let e=!1;l.t4.runPromiseExit((0,w.Wr)()).then(r=>{!e&&"Success"===r._tag&&r.value.version&&t(r.value.version)});let r=new AbortController,s=setTimeout(()=>r.abort(),3e3);return fetch("https://registry.npmjs.org/@surething/cockpit/latest",{signal:r.signal}).then(e=>e.ok?e.json():null).then(t=>{if(e)return;let r=t?.version;"string"==typeof r&&n(r)}).catch(()=>{}).finally(()=>clearTimeout(s)),()=>{e=!0,r.abort(),clearTimeout(s)}},[]);let o=!!e&&!!r&&function(e,t){let r=e=>e.replace(/^v/,"").split("-")[0].split(".").map(e=>parseInt(e,10)||0),n=r(e),s=r(t),o=Math.max(n.length,s.length);for(let e=0;e<o;e++){let t=n[e]??0,r=s[e]??0;if(t!==r)return t-r}return 0}(r,e)>0;return{current:e,latest:r,hasUpdate:o}}(),[$,R]=(0,s.useState)(!1),B=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!$)return;let e=e=>{B.current?.contains(e.target)||R(!1)},t=()=>R(!1);return document.addEventListener("mousedown",e,!0),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e,!0),window.removeEventListener("blur",t)}},[$]);let F=(0,s.useCallback)(()=>{navigator.clipboard.writeText("cockpit update"),(0,v.oR)(M("workspace.upgradeCommandCopied")),R(!1)},[M]),{pinnedSessions:I,unpinSession:D,updateTitle:A,reorder:z}=(0,g.P)(),{tasks:W,unreadCount:_,reload:H,pauseTask:O,resumeTask:q,triggerTask:V,deleteTask:U,updateTask:K,markRead:J,reorderTasks:Q}=(0,b.n)(),[Z,Y]=(0,s.useState)(null),[G,X]=(0,s.useState)(null),[ee,et]=(0,s.useState)([]),er=(0,s.useRef)(ee);(0,s.useEffect)(()=>{er.current=ee});let en=(0,s.useRef)(H);(0,s.useEffect)(()=>{en.current=H});let es=(0,s.useCallback)(e=>{try{if("task-fired"===e.type)return void en.current();let{data:t}=e;if(!t)return;et(t.sessions||[])}catch{}},[]);(0,j.h)({url:"/ws/global-state",onMessage:es});let eo=new Set(ee.filter(e=>"loading"===e.status).map(e=>e.cwd)),ea=new Set(ee.filter(e=>"unread"===e.status).map(e=>e.cwd)),el=(0,s.useCallback)(e=>{Y(e)},[]),ei=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==Z&&Z!==t&&X(t)},[Z]),ec=(0,s.useCallback)(t=>{if(null!==Z&&Z!==t){let r=[...e],[n]=r.splice(Z,1);r.splice(t,0,n),x(r)}Y(null),X(null)},[Z,e,x]),ed=(0,s.useCallback)(()=>{Y(null),X(null)},[]);return(0,n.jsxs)("div",{className:`h-full bg-card border-r border-border flex flex-col transition-all duration-200 ${r?"w-12":"w-56"}`,children:[(0,n.jsxs)("div",{className:"group p-2 border-b border-border relative",children:[(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:f,title:M("workspace.openProject"),children:[(0,n.jsxs)("svg",{className:"w-5 h-5 flex-shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.openProject")})]}),r?(0,n.jsx)("button",{className:"absolute inset-0 m-2 flex items-center justify-center px-2 py-2 rounded-lg bg-accent text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:h,title:M("workspace.expandSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0 rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}):(0,n.jsx)("button",{className:"absolute top-1/2 -translate-y-1/2 right-2 p-2 rounded-lg bg-accent text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:h,title:M("workspace.collapseSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:e.map((e,s)=>{var o;let l;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>el(s),onDragOver:e=>ei(e,s),onDrop:()=>ec(s),onDragEnd:ed,className:`${G===s?"border-t-2 border-brand":""} ${Z===s?"opacity-50":""}`,children:(0,n.jsx)(a.ProjectItem,{index:s,name:(l=(o=e.cwd).split("/").filter(Boolean))[l.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:ea.has(e.cwd),isLoading:eo.has(e.cwd),onClick:()=>c(s),onRemove:()=>d(s),onOpenNote:()=>N(e.cwd)})},e.cwd)})}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(u,{currentCwd:i,onSwitchProject:S,collapsed:r,sessions:ee}),(0,n.jsx)(m,{collapsed:r,pinnedSessions:I,onSwitchProject:S,onUnpin:D,onUpdateTitle:A,onReorder:z}),(0,n.jsx)(p,{collapsed:r,tasks:W,unreadCount:_,onSwitchProject:S,onPause:O,onResume:q,onTrigger:V,onDelete:U,onMarkRead:J,onUpdateTask:K,onReorder:Q}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:()=>N(),title:M("workspace.notes"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.notes")})]}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:C,title:M("workspace.skills"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.skills")})]}),(0,n.jsxs)("div",{className:`relative flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:y,title:M("workspace.settings"),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),r&&T&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500",title:P?M("workspace.updateAvailable",{version:P}):void 0})]}),!r&&(0,n.jsx)("span",{className:"flex-1 text-sm",children:M("workspace.settings")}),!r&&T&&P&&(0,n.jsxs)("div",{ref:B,className:"relative -mr-2",children:[(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),R(e=>!e)},className:"px-1.5 py-0.5 rounded text-xs font-mono font-medium text-brand hover:bg-brand/10 transition-colors",title:M("workspace.updateAvailable",{version:P}),"aria-label":M("workspace.updateAvailable",{version:P}),children:["v",P]}),$&&(0,n.jsxs)("div",{className:"absolute left-full bottom-full ml-2 mb-1 w-56 rounded-lg border border-border bg-popover shadow-lg p-2 z-50",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2 px-1",children:M("workspace.updateAvailable",{version:P})}),(0,n.jsxs)("button",{type:"button",onClick:F,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left hover:bg-accent transition-colors",children:[(0,n.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]}),(0,n.jsx)("span",{className:"flex-1",children:M("workspace.copyUpgradeCommand")})]}),(0,n.jsxs)("a",{href:`https://opencockpit.dev/${E.language?.startsWith("zh")?"zh":"en"}/changelog/`,target:"_blank",rel:"noopener",onClick:()=>R(!1),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-accent transition-colors",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("span",{className:"flex-1",children:M("workspace.viewChangelog")}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]}),!r&&(0,n.jsx)("a",{href:`https://opencockpit.dev/${E.language?.startsWith("zh")?"zh":"en"}/docs/get-started/quickstart/`,target:"_blank",rel:"noopener",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",onClick:e=>e.stopPropagation(),title:M("workspace.help"),"aria-label":M("workspace.help"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]})})]})]})]})}},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>c});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(86957),i=r(76900);function c({children:e}){return(0,s.useEffect)(()=>{l.t4.runPromiseExit((0,i.M5)()).then(e=>{var t;let r="auto"!==(t=("Success"===e._tag?e.value.language:"auto")||"auto")&&t?t:navigator.language.startsWith("zh")?"zh":"en";a.A.language!==r&&a.A.changeLanguage(r)})},[]),(0,s.useEffect)(()=>{let e=e=>(function(e){for(let t of document.querySelectorAll("iframe"))try{t.contentWindow?.postMessage({type:"cockpit:language-change",lang:e},"*")}catch{}})(e);return a.A.on("languageChanged",e),()=>{a.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&a.A.language!==e.data.lang&&a.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:a.A,children:e})}},53213:(e,t,r)=>{r.d(t,{Bj:()=>c,CM:()=>v,FK:()=>b,Iz:()=>x,MB:()=>j,Ub:()=>f,X0:()=>h,Zi:()=>d,lv:()=>m,oh:()=>g,r4:()=>l,ue:()=>i,w2:()=>p,yy:()=>u});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok){let e;try{e=(await t.json()).error}catch{}throw Error(e||`HTTP ${t.status}`)}return await t.json()},catch:t=>new s.uV({message:`fetch ${e} failed`,cause:t})}),a=(e,t)=>n.tryPromise({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),l=e=>o(`/api/git/branches?cwd=${encodeURIComponent(e)}`).pipe(n.flatMap(t=>"Failed to get branches"===t.error?n.fail(new s.m_({resource:"git-repo",id:e})):n.succeed(t))),i=e=>o(`/api/git/current-branch?cwd=${encodeURIComponent(e)}`),c=(e,t,r,n)=>o(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${r}${"number"==typeof n?`&offset=${n}`:""}`),d=(e,t,r)=>o(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=(e,t,r)=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),m=e=>o(`/api/git/status?cwd=${encodeURIComponent(e)}`),x=(e,t)=>a("/api/git/stage",{cwd:e,files:t}),h=(e,t)=>a("/api/git/unstage",{cwd:e,files:t}),f=(e,t,r)=>a("/api/git/discard",{cwd:e,files:t,isUntracked:r}),p=(e,t,r)=>{let n=new URLSearchParams({cwd:e,file:t,type:r});return o(`/api/git/diff?${n}`)},g=e=>o(`/api/git/diff?${e.toString()}`),b=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),v=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await t.json().catch(()=>null);if(!t.ok)throw Error(r?.error||`HTTP ${t.status}`);return r},catch:e=>new s.uV({message:"POST /api/git/worktree failed",cause:e})}),j=e=>o(`/api/projectGraph/search?${e.toString()}`)},53853:(e,t,r)=>{r.d(t,{G:()=>u,f:()=>m});var n=r(12115);function s(){if("u"<typeof document)return null;let e=document.querySelector('meta[name="cockpit-bridge"]');if(!e)return null;let t=e.dataset.id,r=e.dataset.version;return t?{id:t,version:r||"unknown"}:null}let o=null,a=new Set;function l(){a.forEach(e=>e())}function i(e){a.add(e);let t=s();return t&&!o&&(o=t,Promise.resolve().then(l)),()=>{a.delete(e)}}function c(){return o}function d(){return null}if("u">typeof document&&(o=s()),"u">typeof MutationObserver&&"u">typeof document){let e=new MutationObserver(()=>{let e=s();e&&(!o||e.id!==o.id||e.version!==o.version)&&(o=e,l())}),t=document.head||document.documentElement;t&&e.observe(t,{childList:!0})}function u(){return(0,n.useSyncExternalStore)(i,c,d)}function m(){return o??s()}},60865:(e,t,r)=>{r.d(t,{NoteModal:()=>es});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(13439),i=r(58940),c=r(43561),d=r(5989),u=r(76065),m=r(43203),x=r(6268),h=r(48434),f=r(82159),p=r(44695);let g={todo:"doing",doing:"done",done:"todo"},b={todo:"false",doing:"mixed",done:"true"},v=/^\s*(\[([ x/])?\])\s$/,j=p.L.extend({addAttributes:()=>({status:{default:"todo",keepOnSplit:!1,parseHTML:e=>(function(e){let t=e.getAttribute("data-status");if("todo"===t||"doing"===t||"done"===t)return t;let r=e.getAttribute("data-checked");return""===r||"true"===r?"done":"todo"})(e),renderHTML:e=>({"data-status":e.status,"data-checked":"done"===e.status?"true":"false"})}}),addStorage:()=>({markdown:{serialize(e,t){var r;e.write(`${"done"===(r=t.attrs.status)?"[x]":"doing"===r?"[/]":"[ ]"} `),e.renderContent(t)}}}),addInputRules(){return[(0,f.tG)({find:v,type:this.type,getAttributes:e=>{let t=e[e.length-1];return{status:"x"===t?"done":"/"===t?"doing":"todo"}}})]},renderHTML({HTMLAttributes:e}){return["li",(0,f.KV)(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},addNodeView(){return({node:e,getPos:t,editor:r})=>{let n=document.createElement("li");n.setAttribute("data-type",this.name);let s=document.createElement("label");s.classList.add("task-marker"),s.contentEditable="false";let o=document.createElement("span");o.classList.add("task-marker-box"),o.setAttribute("role","checkbox"),s.appendChild(o);let a=document.createElement("div");n.append(s,a);let l=e=>{let t=e.attrs.status??"todo";n.dataset.status=t,n.dataset.checked="done"===t?"true":"false",o.setAttribute("aria-checked",b[t])};return l(e),s.addEventListener("mousedown",e=>e.preventDefault()),s.addEventListener("click",e=>{if(e.preventDefault(),!r.isEditable||"function"!=typeof t)return;let n=t();"number"==typeof n&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=e.doc.nodeAt(n);if(!t)return!1;let r=t.attrs.status??"todo";return e.setNodeMarkup(n,void 0,{...t.attrs,status:g[r]}),!0}).run()}),{dom:n,contentDOM:a,update:t=>t.type===e.type&&(l(t),!0)}}}});var w=r(59265),k=r(26932),y=r(27050),N=r(52740),C=r(76865),S=r(63197);let L=new C.hs("headingFold");function M(e){let t=e.attrs.foldState;return"folded"===t||"children"===t?t:"expanded"}function E(e){let t=[],r=[];return e.forEach((e,n)=>{let s=n+e.nodeSize;if("heading"===e.type.name){let o=e.attrs.level;for(;r.length&&r[r.length-1].level>=o;)r.pop();let a=M(e),l=r.some(e=>"folded"===e.state),i=["note-heading"];"expanded"!==a&&i.push("is-collapsed"),l&&i.push("note-folded-hidden"),t.push(S.NZ.node(n,s,{class:i.join(" ")})),t.push(S.NZ.widget(n+1,(e,t)=>{let r;return(r=document.createElement("span")).className="note-fold-toggle",r.contentEditable="false",r.setAttribute("data-fold-state",a),r.addEventListener("mousedown",r=>{r.preventDefault(),r.stopPropagation();let n=t();if(null==n)return;let s=n-1,o=e.state.doc.nodeAt(s);o&&"heading"===o.type.name&&e.dispatch(e.state.tr.setNodeMarkup(s,void 0,{...o.attrs,foldState:"expanded"===M(o)?"folded":"expanded"}))}),r},{side:-1,key:`fold-${n}-${a}`})),r.push({level:o,state:a})}else r.some(e=>"folded"===e.state||"children"===e.state)&&t.push(S.NZ.node(n,s,{class:"note-folded-hidden"}))}),S.zF.create(e,t)}let P=N.A.extend({addAttributes(){return{...this.parent?.(),foldState:{default:"expanded",keepOnSplit:!1,parseHTML:e=>"true"===e.getAttribute("data-collapsed")?"folded":"expanded",renderHTML:e=>e.foldState&&"expanded"!==e.foldState?{"data-collapsed":"true"}:{}}}},addKeyboardShortcuts(){let e=this.name;return{Tab:()=>{var t;let r,n,s,{state:o}=this.editor,{$from:a}=o.selection;if(a.parent.type.name!==e)return!1;let l=a.before(a.depth),i=o.doc.nodeAt(l);if(!i||i.type.name!==e)return!1;let c=i.attrs.level,d=(t=o.doc,n=[],s=!1,t.forEach((t,r)=>{if(r===l){s=!0;return}if(s&&t.type.name===e){if(t.attrs.level<=c){s=!1;return}n.push(r)}}),n),u=d.length>0,m=M(i),x=null;return u?"expanded"===m?r="folded":(r="folded"===m?"children":"expanded",x="expanded"):r="expanded"===m?"folded":"expanded",this.editor.chain().command(({tr:t})=>{if(t.setNodeMarkup(l,void 0,{...i.attrs,foldState:r}),x)for(let r of d){let n=t.doc.nodeAt(r);n&&n.type.name===e&&t.setNodeMarkup(r,void 0,{...n.attrs,foldState:x})}return!0}).run()}}},addStorage:()=>({markdown:{serialize(e,t){e.write(e.repeat("#",t.attrs.level)+" "),e.renderInline(t,!1),"expanded"!==M(t)&&e.write(" \x3c!-- fold --\x3e"),e.closeBlock(t)},parse:{updateDOM(e){e.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach(e=>{let t=e.lastChild;for(;t&&3===t.nodeType&&!(t.textContent||"").trim();){let r=t.previousSibling;e.removeChild(t),t=r}if(t&&8===t.nodeType&&/^\s*fold\s*$/.test(t.textContent||"")){let r=t.previousSibling;e.removeChild(t),r&&3===r.nodeType&&(r.textContent=(r.textContent||"").replace(/\s+$/,"")),e.setAttribute("data-collapsed","true")}})}}}}),addProseMirrorPlugins:()=>[new C.k_({key:L,state:{init:(e,{doc:t})=>E(t),apply:(e,t)=>e.docChanged?E(e.doc):t},props:{decorations:e=>L.getState(e)}})]});function T(e){let t=[];return e.forEach((e,r)=>t.push({node:e,start:r,end:r+e.nodeSize})),t}function $(e,t){return"heading"===e.type.name&&e.attrs.level<=t}function R(e){for(let t=e.depth;t>0;t--){let r=e.node(t).type.name;if("listItem"===r||"taskItem"===r)return t}return -1}function B(e,t,r,n,s){let o=t.slice(r,n),a=t.slice(n,s);e.replaceWith(r,s,a.content.append(o.content))}function F(e,t){let r=Math.max(0,Math.min(t,e.doc.content.size));e.setSelection(C.U3.near(e.doc.resolve(r)))}let I=new Set(["paragraph","bulletList","orderedList","taskList"]);function D(e,t,r){let{doc:n,selection:s}=e,o=s.$from,a=o.before(1),l=T(n),i=l.findIndex(e=>e.start===a);if(i<0)return!1;let c=i;for(;c>0&&I.has(l[c-1].node.type.name);)c--;let d=i;for(;d<l.length-1&&I.has(l[d+1].node.type.name);)d++;let u=[],m=-1,x="paragraph"===l[i].node.type.name?-1:o.index(1);for(let e=c;e<=d;e++){let t=l[e].node;if("paragraph"===t.type.name)e===i&&(m=u.length),u.push({kind:"paragraph",node:t});else{let r=t.type.name,n=0;t.forEach(t=>{e===i&&n===x&&(m=u.length),u.push({kind:r,node:t}),n++})}}if(m<0)return!1;let h=m+(r>0?1:-1);if(h<0||h>=u.length)return!1;if(t){let r,n,s,a=u[m];u[m]=u[h],u[h]=a;let i=function(e,t){let r=[],n=0;for(;n<e.length;){if("paragraph"===e[n].kind){r.push(e[n].node),n++;continue}let s=e[n].kind,o=[];for(;n<e.length&&e[n].kind===s;)o.push(e[n].node),n++;r.push(t.schema.nodes[s].create(null,o))}return y.FK.from(r)}(u,e),x=l[c].start,f=l[d].end,p=e.tr;p.replaceWith(x,f,i);let g=(r=0,n=0,s=-1,i.forEach(e=>{if(!(s>=0))if("paragraph"===e.type.name)r===h&&(s=n+1),r++,n+=e.nodeSize;else{let t=n+1;e.forEach(e=>{s>=0||(r===h&&(s=t+2),r++,t+=e.nodeSize)}),n+=e.nodeSize}}),s);F(p,g>=0?x+g+o.parentOffset:x),t(p.scrollIntoView())}return!0}function A(e,t,r){let n=e.selection.$from;if(1===n.depth&&"heading"===n.parent.type.name)return function(e,t,r){let{doc:n,selection:s}=e,o=s.$from.before(1),a=T(n),l=a.findIndex(e=>e.start===o);if(l<0)return!1;let i=a[l].node.attrs.level,c=l+1;for(;c<a.length&&!$(a[c].node,i);)c++;let d=a[l].start,u=a[c-1].end;if(r>0){if(c>=a.length)return!1;let r=a[c].node.attrs.level,o=c+1;for(;o<a.length&&!$(a[o].node,r);)o++;let l=a[o-1].end;if(t){let r=e.tr,o=n.slice(u,l).content.size;B(r,n,d,u,l),F(r,d+o+(s.from-d)),t(r.scrollIntoView())}return!0}if(0===l)return!1;let m=l-1;for(;m>=0&&!$(a[m].node,i);)m--;if(m<0||a[m].node.attrs.level<i)return!1;let x=a[m].start;if(t){let r=e.tr;B(r,n,x,d,u),F(r,x+(s.from-d)),t(r.scrollIntoView())}return!0}(e,t,r);let s=R(n);if(s>0){let o=n.node(s-1),a=n.index(s-1);return(r>0?a<o.childCount-1:a>0)?function(e,t,r,n){let{doc:s,selection:o}=e,a=o.$from,l=a.node(n),i=a.node(n-1),c=a.index(n-1),d=a.before(n),u=d+l.nodeSize;if(r>0){if(c>=i.childCount-1)return!1;let r=u+i.child(c+1).nodeSize;if(t){let n=e.tr,a=s.slice(u,r).content.size;B(n,s,d,u,r),F(n,d+a+(o.from-d)),t(n.scrollIntoView())}return!0}if(c<=0)return!1;let m=d-i.child(c-1).nodeSize;if(t){let r=e.tr;B(r,s,m,d,u),F(r,m+(o.from-d)),t(r.scrollIntoView())}return!0}(e,t,r,s):2===s&&D(e,t,r)}let o=n.depth>=1?n.node(n.depth-1).type.name:"doc";return"paragraph"===n.parent.type.name&&"doc"===o&&D(e,t,r)}function z(e,t){let{state:r}=e,n=r.selection.$from,s=n.parent.type.name;if("doc"===(n.depth>=1?n.node(n.depth-1).type.name:"doc")&&("heading"===s||"paragraph"===s)){let r=(("heading"===s?n.parent.attrs.level-1:3)+(t>0?1:-1)+4)%4;return 3===r?e.chain().setParagraph().run():e.chain().setHeading({level:r+1}).run()}let o=R(n);if(o>0){let r=n.node(o).type.name;return t<0?e.commands.liftListItem(r):e.commands.sinkListItem(r)}return!1}function W(e,t){let{state:r}=e,n=r.selection;if(!n.empty)return!1;let s=n.$from,o=t>0?1:-1;for(let t=s.depth;t>0;t--)if("taskItem"===s.node(t).type.name){let n=s.before(t),a=r.doc.nodeAt(n);if(!a)return!1;let l=a.attrs.status??"todo",i=(("doing"===l?2:"done"===l?3:1)+o+4)%4;if(0===i)return e.chain().toggleTaskList().run();let c=2===i?"doing":3===i?"done":"todo";return e.chain().command(({tr:e})=>{let t=e.doc.nodeAt(n);return!!t&&(e.setNodeMarkup(n,void 0,{...t.attrs,status:c}),!0)}).run()}if("paragraph"!==s.parent.type.name)return!1;let a=s.depth>=1?s.node(s.depth-1).type.name:"doc";return("doc"===a||"listItem"===a)&&(1==(0+o+4)%4?e.chain().toggleTaskList().run():e.chain().toggleTaskList().command(({tr:e})=>(function(e,t){let r=e.selection.$from;for(let n=r.depth;n>0;n--)if("taskItem"===r.node(n).type.name){let s=r.before(n),o=e.doc.nodeAt(s);o&&e.setNodeMarkup(s,void 0,{...o.attrs,status:t});break}return!0})(e,"done")).run())}let _=f.YY.create({name:"noteOrgKeymap",addKeyboardShortcuts(){return{"Alt-ArrowUp":()=>this.editor.commands.command(({state:e,dispatch:t})=>A(e,t,-1)),"Alt-ArrowDown":()=>this.editor.commands.command(({state:e,dispatch:t})=>A(e,t,1)),"Alt-ArrowLeft":()=>z(this.editor,-1),"Alt-ArrowRight":()=>z(this.editor,1),"Shift-ArrowRight":()=>W(this.editor,1),"Shift-ArrowLeft":()=>W(this.editor,-1)}}});function H(e){return e.storage.markdown.getMarkdown()}function O(){return[{label:a.A.t("slashCommands.heading1"),icon:"H1",description:a.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:a.A.t("slashCommands.heading2"),icon:"H2",description:a.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:a.A.t("slashCommands.heading3"),icon:"H3",description:a.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:a.A.t("slashCommands.bulletList"),icon:"•",description:a.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:a.A.t("slashCommands.orderedList"),icon:"1.",description:a.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:a.A.t("slashCommands.taskList"),icon:"☑",description:a.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:a.A.t("slashCommands.blockquote"),icon:"❝",description:a.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:a.A.t("slashCommands.codeBlock"),icon:"<>",description:a.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:a.A.t("slashCommands.table"),icon:"▦",description:a.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:a.A.t("slashCommands.horizontalRule"),icon:"──",description:a.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:a.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:a.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function q({editor:e,query:t,position:r,onClose:o}){let[a,l]=(0,s.useState)(0),i=(0,s.useRef)(null),c=O().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>l(0))},[t]);let d=r=>{e.chain().focus().deleteRange({from:e.state.selection.from-t.length-1,to:e.state.selection.from}).run(),r.action(e),o()};return((0,s.useEffect)(()=>{let e=e=>{"ArrowDown"===e.key?(e.preventDefault(),l(e=>(e+1)%c.length)):"ArrowUp"===e.key?(e.preventDefault(),l(e=>(e-1+c.length)%c.length)):"Enter"===e.key?(e.preventDefault(),c[a]&&d(c[a])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,a,o]),0===c.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lg py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:c.map((e,t)=>(0,n.jsxs)("button",{className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors ${t===a?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"}`,onClick:()=>d(e),onMouseEnter:()=>l(t),children:[(0,n.jsx)("span",{className:"w-6 text-center text-xs font-mono flex-shrink-0",children:e.icon}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium",children:e.label}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:e.description})]})]},e.label))})}O();var V=r(76043),U=r(86957),K=r(49433),J=r(34075),Q=r(76900);let Z=/^\s*[-*+]\s+(?:\\?\[ \\?\]|\\?\[[xX/]\\?\])\s*$/,Y=/^\s*(```|~~~)/;function G(e){return e.classList.contains("task-list-item")}let X=/^\s*\[\/\]\s?/,ee=f.YY.create({name:"markdownTaskListFix",addStorage:()=>({markdown:{parse:{updateDOM(e){var t;for(let r of Array.from(e.querySelectorAll("li"))){if(G(r))continue;let e=r.parentElement;e&&"UL"===e.tagName&&(t=r.textContent||"",/^\s*\[\/\]/.test(t)&&(!function(e){let t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=t.nextNode();for(;r&&!(r.nodeValue&&""!==r.nodeValue.trim());)r=t.nextNode();r&&r.nodeValue&&(r.nodeValue=r.nodeValue.replace(X,""))}(r),r.classList.add("task-list-item"),r.setAttribute("data-type","taskItem"),r.setAttribute("data-status","doing"),e.classList.add("contains-task-list")))}!function(e){for(let t of Array.from(e.querySelectorAll("ul.contains-task-list"))){let e=Array.from(t.children).filter(e=>"LI"===e.tagName);if(0===e.length)continue;let r=function(e){let t=[];for(let r of e){let e=t[t.length-1];e&&e.isTask===r.isTask?e.items.push(r):t.push({isTask:r.isTask,items:[r]})}return t}(e.map(e=>({isTask:G(e),el:e})));if(r.length<=1){r[0]?.isTask&&t.setAttribute("data-type","taskList");continue}let n=t.ownerDocument,s=n.createDocumentFragment();for(let e of r){let t=n.createElement("ul");for(let{el:r}of(e.isTask&&(t.setAttribute("class","contains-task-list"),t.setAttribute("data-type","taskList")),e.items))t.appendChild(r);s.appendChild(t)}t.replaceWith(s)}}(e)}}}})});var et=r(8242);let er=new Set(["taskItem","listItem"]),en=f.YY.create({name:"dropShellCleanup",addProseMirrorPlugins:()=>[new C.k_({key:new C.hs("dropShellCleanup"),appendTransaction(e,t,r){let n=[];if(e.forEach((t,r)=>{let s;if("drop"!==t.getMeta("uiEvent")||!t.docChanged)return;let o=(s=[],t.steps.forEach((e,r)=>{e instanceof et.Ln&&(0!==e.slice.size||e.from>=e.to||s.push(t.mapping.slice(r+1).map(e.from)))}),s);for(let t=r+1;t<e.length;t++)o=o.map(r=>e[t].mapping.map(r));n.push(...o)}),0===n.length)return null;let s=r.tr,o=!1;for(let e of n){let t=function(e,t){if(t<0||t>e.content.size)return null;let r=e.resolve(t);for(let e=r.depth;e>0;e--){var n;if(n=r.node(e),!er.has(n.type.name)||1!==n.childCount||null===n.firstChild||!n.firstChild.isTextblock||0!==n.firstChild.content.size)continue;let t=e;for(;t>1&&1===r.node(t-1).childCount;)t--;return{from:r.before(t),to:r.after(t)}}return null}(s.doc,s.mapping.map(e));if(t)try{s.delete(t.from,t.to),o=!0}catch{}}return o?s:null}})]});function es({isOpen:e,onClose:t,projectCwd:r,projectName:f}){let{t:p}=(0,o.Bd)(),[g,b]=(0,s.useState)(!0),[v,N]=(0,s.useState)(!1),C=(0,s.useRef)(null),S=(0,s.useRef)(!1),L=(0,s.useRef)(void 0),[M,E]=(0,s.useState)(null),T=(0,s.useRef)(null),$=(0,s.useCallback)(async e=>{let t=function(e){if(!e)return e;let t=e.split("\n"),r=[],n=!1;for(let e of t){if(Y.test(e)){n=!n,r.push(e);continue}if(n){r.push(e);continue}Z.test(e)||r.push(e)}let s=[],o=0,a=!1;for(let e of r){if(Y.test(e)){a=!a,s.push(e),o=0;continue}if(!a&&""===e.trim()){if((o+=1)>=2)continue;s.push(e);continue}o=0,s.push(e)}return s.join("\n")}(e);N(!0);let n=await U.t4.runPromiseExit((0,Q.Cq)(r,t,L.current).pipe(K.tapError(e=>K.sync(()=>console.error("Failed to save note:",e)))));if("Success"===n._tag){let e=n.value;e.conflict?(F.current?.commands.setContent(e.content,{emitUpdate:!1}),L.current=e.mtime,S.current=!1,(0,J.oR)(p("editor.conflictReloaded"),"info")):(L.current=e.mtime,S.current=!1)}N(!1)},[r,p]),R=(0,s.useCallback)(e=>{S.current=!0,C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{$(e)},5e3)},[$]),B=(0,l.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:!1}),P.configure({levels:[1,2,3]}),_,c.A.configure({placeholder:()=>a.A.t("editor.placeholder")}),d.XI.configure({resizable:!0}),u.H,m.n,x.A,h._,w.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),j.configure({nested:!0}),ee,en,k.o.configure({html:!0,transformCopiedText:!1,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},clipboardTextSerializer:e=>e.content.textBetween(0,e.content.size,"\n").replace(/\n+$/,""),transformCopied:e=>{let t=e=>!!e&&e.isTextblock&&0===e.content.size,r=e.content,{openStart:n,openEnd:s}=e;for(;r.childCount>1&&t(r.lastChild);)r=r.cut(0,r.size-r.lastChild.nodeSize),s=0;for(;r.childCount>1&&t(r.firstChild);)r=r.cut(r.firstChild.nodeSize),n=0;return new y.Ji(r,n,s)},handleClick:(e,t,r)=>{if(r.metaKey||r.ctrlKey){let r=e.state.doc.resolve(t).marks().find(e=>"link"===e.type.name)?.attrs;if(r?.href)return window.open(r.href,"_blank","noopener,noreferrer"),!0}return!1},handleKeyDown:(e,t)=>{if("Backspace"===t.key&&F.current){let e=F.current;if(e.isActive("codeBlock")){let{$from:t}=e.state.selection,r=t.node(t.depth);if("codeBlock"===r.type.name&&""===r.textContent)return e.chain().focus().toggleCodeBlock().run(),!0}}return"/"!==t.key||M||setTimeout(()=>{if(!F.current)return;let{from:e}=F.current.state.selection;if("/"===F.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){T.current=e;let t=F.current.view.coordsAtPos(e);E({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(R(H(e)),null!==T.current){let{from:t}=e.state.selection;if(t<T.current)E(null),T.current=null;else{let r=e.state.doc.textBetween(T.current,t,"\n");r.includes(" ")||r.includes("\n")?(E(null),T.current=null):E(e=>e?{...e,query:r}:null)}}}}),F=(0,s.useRef)(null);(0,s.useEffect)(()=>{F.current=B},[B]),(0,s.useEffect)(()=>{e&&B&&(b(!0),E(null),T.current=null,U.t4.runPromiseExit((0,Q.zF)(r)).then(e=>{"Success"===e._tag?(B.commands.setContent(e.value.content||"",{emitUpdate:!1}),L.current=e.value.mtime,C.current&&(clearTimeout(C.current),C.current=null),S.current=!1):console.error("Failed to load note:",e.cause),b(!1)}))},[e,B,r]);let I=(0,s.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null),S.current&&B&&$(H(B)),E(null),T.current=null,t()},[B,$,t]);return((0,s.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(M?(E(null),T.current=null):I())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,I,M]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:I}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:f?p("editor.noteTitle",{name:f}):p("editor.noteUntitled")}),v&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:p("editor.saving")})]}),(0,n.jsx)("button",{onClick:I,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(V.NoteToolbar,{editor:B}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:g?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:p("common.loading")})}):(0,n.jsx)(l.$Z,{editor:B})})]}),M&&B&&(0,n.jsx)(q,{editor:B,query:M.query,position:M.position,onClose:()=>{E(null),T.current=null}})]}):null}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>d,fY:()=>c,gT:()=>u});var n=r(95155),s=r(12115);let o=["agent","explorer","console"],a={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},l=(0,s.createContext)(null);function i(){let e=(0,s.useContext)(l);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function c({activeView:e,onViewChange:t,children:r}){let a=(0,s.useRef)(null),i=(0,s.useRef)(!1),d=(0,s.useRef)(0),[u,m]=(0,s.useState)(0),[x,h]=(0,s.useState)(!1),f=o.indexOf(e),p=o.length-1;(0,s.useEffect)(()=>{d.current=0,queueMicrotask(()=>m(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){let r=e.target;if("IFRAME"===r.tagName||function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth>e.clientWidth)return!0;e=e.parentElement}return!1}(r))return;e.preventDefault(),e.stopPropagation(),i.current&&(i.current=!1);let n=window.innerWidth,s=d.current-6*e.deltaX;!(f>0)&&s>0&&(s=0),!(f<p)&&s<0&&(s=0),d.current=s=Math.max(-n,Math.min(n,s)),m(s),h(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{let e=d.current,r=.12*n;h(!1),i.current=!0;let s=f;e<-r&&f<p?s=f+1:e>r&&f>0&&(s=f-1),d.current=0,m(0),s!==f&&t(o[s]),setTimeout(()=>{i.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[f,p,t]);let[g,b]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>b(!0))},[]);let v={activeView:e,onViewChange:t,dragOffset:(()=>{if(!g)return 0;let e=window.innerWidth;return e?u/e:0})(),isDragging:g&&x};return(0,n.jsx)(l.Provider,{value:v,children:r})}function d({children:e}){let t,r,{activeView:a,dragOffset:l,isDragging:c}=i(),u=(0,s.useRef)(null),m=(0,s.useRef)(null),x=o.indexOf(a),h=o.length;return(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{0!==e.scrollLeft&&(e.scrollLeft=0)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,n.jsx)("div",{ref:u,className:"flex-1 overflow-hidden relative",style:{overscrollBehaviorX:"none"},children:(0,n.jsx)("div",{ref:m,className:c?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*o.length}%`,transform:(t=l/h*100,r=-(100/h*x)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function u(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:l}=i(),c=(0,s.useRef)(null),d=(0,s.useRef)([]),[u,m]=(0,s.useState)({left:0,width:0}),x=o.indexOf(e),h=()=>{if(!c.current||0===d.current.length)return{left:0,width:0};let e=c.current.getBoundingClientRect(),t=d.current.filter(Boolean);if(t.length!==o.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(o.length-1,x-n)),a=Math.floor(s),l=Math.ceil(s),i=s-a,u=t[a],m=t[l];if(!u||!m)return{left:0,width:0};let h=u.getBoundingClientRect(),f=m.getBoundingClientRect();return{left:h.left+(f.left-h.left)*i-e.left,width:h.width+(f.width-h.width)*i}};(0,s.useEffect)(()=>{queueMicrotask(()=>m(h()))},[x,r]),(0,s.useEffect)(()=>{let e=()=>{m(h())};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[x,r]);let f=Number.isFinite(r)?r:0,p=Math.round(Math.max(0,Math.min(o.length-1,x-f)));return(0,n.jsxs)("div",{ref:c,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{d.current[r]=e},onClick:()=>t(e),className:`px-4 py-1 text-sm font-medium transition-colors ${p===r?"text-brand":"text-muted-foreground hover:text-foreground"}`,children:a[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${l?"":"transition-all duration-100 ease-out"}`,style:{left:u.left,width:u.width}})]})}},76043:(e,t,r)=>{r.d(t,{NoteToolbar:()=>l});var n=r(95155),s=r(12115),o=r(79114);function a({editor:e,onClose:t,position:r}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)(()=>e.getAttributes("link").href||""),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.current?.focus()},[]);let u=()=>{let r=i.trim();if(r){let t=r.match(/^https?:\/\//)?r:`https://${r}`;e.chain().focus().extendMarkRange("link").setLink({href:t}).run()}else e.chain().focus().extendMarkRange("link").unsetLink().run();t()},m=r?{top:r.top,left:r.left}:{};return(0,n.jsxs)("div",{className:`${r?"fixed":"absolute top-full left-0 mt-1"} z-[60] bg-popover border border-border rounded-lg shadow-lg p-2 flex items-center gap-2`,style:m,children:[(0,n.jsx)("input",{ref:d,type:"text",value:i,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u()):"Escape"===e.key&&(e.preventDefault(),t())},placeholder:l("editor.linkPlaceholder"),className:"bg-background border border-border rounded px-2 py-1 text-sm w-64 outline-none focus:border-brand"}),(0,n.jsx)("button",{onClick:u,className:"p-1 rounded text-sm font-medium text-brand hover:bg-brand/10 transition-colors",title:l("editor.confirmLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})}),e.isActive("link")&&(0,n.jsx)("button",{onClick:()=>{e.chain().focus().extendMarkRange("link").unsetLink().run(),t()},className:"p-1 rounded text-sm font-medium text-red-500 hover:bg-red-500/10 transition-colors",title:l("editor.removeLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})}function l({editor:e}){let{t}=(0,o.Bd)(),[r,i]=(0,s.useState)(!1),c=(0,s.useRef)(null),[,d]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>d(e=>e+1);return e.on("selectionUpdate",t),e.on("transaction",t),()=>{e.off("selectionUpdate",t),e.off("transaction",t)}},[e]),(0,s.useEffect)(()=>{let e=()=>i(!0);return window.addEventListener("tiptap-insert-link",e),()=>window.removeEventListener("tiptap-insert-link",e)},[]),!e)return null;let u=e=>`p-1.5 rounded text-xs font-medium transition-colors ${e?"bg-brand/15 text-brand":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,m="w-px h-5 bg-border mx-0.5",x=e.isActive("table");return(0,n.jsxs)("div",{className:"flex items-center gap-0.5 px-4 py-1.5 border-b border-border flex-shrink-0 flex-wrap",children:[(0,n.jsx)("button",{className:u(e.isActive("heading",{level:1})),onClick:()=>e.chain().focus().toggleHeading({level:1}).run(),title:t("editor.heading1"),children:"H1"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:2})),onClick:()=>e.chain().focus().toggleHeading({level:2}).run(),title:t("editor.heading2"),children:"H2"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:3})),onClick:()=>e.chain().focus().toggleHeading({level:3}).run(),title:t("editor.heading3"),children:"H3"}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("bold")),onClick:()=>e.chain().focus().toggleBold().run(),title:t("editor.bold"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"})})}),(0,n.jsx)("button",{className:u(e.isActive("italic")),onClick:()=>e.chain().focus().toggleItalic().run(),title:t("editor.italic"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z"})})}),(0,n.jsx)("button",{className:u(e.isActive("strike")),onClick:()=>e.chain().focus().toggleStrike().run(),title:t("editor.strikethrough"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("code")),onClick:()=>e.chain().focus().toggleCode().run(),title:t("editor.inlineCode"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"})})}),(0,n.jsx)("div",{className:m}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{ref:c,className:u(e.isActive("link")),onClick:()=>i(!r),title:t("editor.link"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})})}),r&&(0,n.jsx)(a,{editor:e,onClose:()=>i(!1),position:null})]}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("bulletList")),onClick:()=>e.chain().focus().toggleBulletList().run(),title:t("editor.bulletList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z"})})}),(0,n.jsx)("button",{className:u(e.isActive("orderedList")),onClick:()=>e.chain().focus().toggleOrderedList().run(),title:t("editor.orderedList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("taskList")),onClick:()=>e.chain().focus().toggleTaskList().run(),title:t("editor.taskList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14zM17.99 9l-1.41-1.42-6.59 6.59-2.58-2.57-1.42 1.41 4 3.99z"})})}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("blockquote")),onClick:()=>e.chain().focus().toggleBlockquote().run(),title:t("editor.blockquote"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"})})}),(0,n.jsx)("button",{className:u(e.isActive("codeBlock")),onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.codeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H4V5h16v14zm-7.5-4.5L15 12l-2.5-2.5L11 11l1.5 1.5L11 14l1.5 1.5zM9.5 14.5L7 12l2.5-2.5L11 11 9.5 12.5 11 14l-1.5.5z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:t("editor.table"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-9 15H4v-4h7v4zm0-6H4V7h7v4zm9 6h-7v-4h7v4zm0-6h-7V7h7v4z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().setHorizontalRule().run(),title:t("editor.horizontalRule"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 11h16v2H4z"})})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowBefore().run(),title:t("editor.insertRowAbove"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zM11 17H4v-2h7v2zm0-4H4v-2h7v2zm9 4h-7v-2h7v2zm0-4h-7v-2h7v2z"}),(0,n.jsx)("path",{d:"M14 1h-4v2H8v2h2v2h4V5h2V3h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowAfter().run(),title:t("editor.insertRowBelow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v10h20V6c0-1.1-.9-2-2-2zM11 12H4v-2h7v2zm0-4H4V6h7v2zm9 4h-7v-2h7v2zm0-4h-7V6h7v2z"}),(0,n.jsx)("path",{d:"M14 19h-4v2H8v2h2v-2h4v2h2v-2h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnBefore().run(),title:t("editor.insertColumnLeft"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 11H10v-2h7v2zm0-4H10V9h7v2z"}),(0,n.jsx)("path",{d:"M1 14v-4h2V8h2v2h-2v4h2v2H3v-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnAfter().run(),title:t("editor.insertColumnRight"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M4 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h10V4H4zm7 11H4v-2h7v2zm0-4H4V9h7v2z"}),(0,n.jsx)("path",{d:"M18 4v20h2c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-2z"}),(0,n.jsx)("path",{d:"M21 14v-4h2V8h2v2h-2v4h2v2h-2v-2z",opacity:".6"})]})}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-500 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteRow().run(),title:t("editor.deleteRow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zm-8 8H4v-2h8v2z"}),(0,n.jsx)("path",{d:"M15 13l-1.41 1.41L15.17 16l-1.58 1.59L15 19l1.59-1.59L18.17 19l1.42-1.41L18 16l1.59-1.59L18.17 13 16.59 14.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-500 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteColumn().run(),title:t("editor.deleteColumn"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 7H10V9h7v2z"}),(0,n.jsx)("path",{d:"M13 16l-1.41 1.41L13.17 19l-1.58 1.59L13 22l1.59-1.59L16.17 22l1.42-1.41L16 19l1.59-1.59L16.17 16l-1.58 1.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-500 hover:bg-red-500/10",onClick:()=>e.chain().focus().deleteTable().run(),title:t("editor.deleteTable"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]}),e.isActive("codeBlock")&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-500 hover:bg-red-500/10",onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.deleteCodeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})]})}},76288:(e,t,r)=>{r.d(t,{EmptyState:()=>i});var n=r(95155),s=r(12115),o=r(79114),a=r(86957),l=r(76900);function i({onSelectSession:e}){let{t}=(0,o.Bd)(),[r,c]=(0,s.useState)([]),[d,u]=(0,s.useState)({}),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useCallback)(async()=>{x(!0),f(null),u({});let e=await a.t4.runPromiseExit((0,l.H7)());"Success"===e._tag?c(e.value):f("Failed to load projects"),x(!1)},[]),j=(0,s.useCallback)(async e=>{u(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await a.t4.runPromiseExit((0,l.QW)(e));"Success"===t._tag?u(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):u(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),w=(0,s.useCallback)(e=>{let t=d[e];t?.isExpanded?u(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?u(t=>({...t,[e]:{...t[e],isExpanded:!0}})):j(e)},[d,j]);return(0,s.useEffect)(()=>{v(),setTimeout(()=>{b.current?.focus()},100)},[v]),(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-card",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-lg font-medium text-foreground",children:t("workspace.selectProject")}),(0,n.jsx)("input",{ref:b,type:"text",placeholder:t("workspace.searchProjectPath"),value:p,onChange:e=>g(e.target.value),className:"px-3 py-1.5 text-sm border border-border rounded-lg bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:t("workspace.loadingProjects")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-red-500",children:h})}),!m&&!h&&0===r.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:t("workspace.projectNotFound")})}),!m&&!h&&(0,n.jsx)("div",{className:"space-y-2",children:r.filter(e=>e.fullPath.toLowerCase().includes(p.toLowerCase())).map(r=>{let s=d[r.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>w(r.encodedPath),className:"w-full flex items-center gap-3 p-3 hover:bg-accent transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-4 h-4 text-muted-foreground transition-transform ${s.isExpanded?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("svg",{className:"w-5 h-5 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground truncate",children:r.name}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:r.fullPath})]}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground bg-secondary px-2 py-0.5 rounded",children:t("workspace.sessions",{count:r.sessionCount})})]}),s.isExpanded&&(0,n.jsxs)("div",{className:"border-t border-border bg-secondary/30",children:[s.isLoading&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:t("workspace.loadingSessions")})]}),s.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-500",children:s.error}),!s.isLoading&&!s.error&&0===s.sessions.length&&(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:t("workspace.noSessions")}),!s.isLoading&&!s.error&&s.sessions.map(t=>(0,n.jsxs)("button",{onClick:()=>{e(r.fullPath,(t.path.split("/").pop()||"").replace(".jsonl",""))},className:"w-full flex items-start gap-3 p-3 hover:bg-accent transition-colors text-left border-t border-border first:border-t-0",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground mt-0.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:t.title}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),t.firstMessages.length>0&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-1 truncate",children:t.firstMessages[0]})]})]},t.path))]})]},r.encodedPath)})})]})]})}},76412:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>p});var n=r(95155),s=r(12115),o=r(63728),a=r(82032),l=r(34075),i=r(79114),c=r(95045),d=r(75346),u=r(49433),m=r(86957),x=r(53213),h=r(76900);function f({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,i.Bd)(),[a,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)([]),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),k=(0,s.useRef)(null),y=(0,s.useRef)(null),N=(0,s.useCallback)(async()=>{g(!0);let t=await m.t4.runPromiseExit((0,x.r4)(e));if("Success"===t._tag){let e=t.value,r=e.local??[];u([...r,...(e.remote??[]).filter(e=>!r.includes(e.replace(/^origin\//,"")))])}else(0,l.oR)(o("toast.loadBranchFailed"),"error");g(!1)},[e,o]),C=(0,s.useCallback)(()=>{c(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{c(!1)},[]);(0,s.useEffect)(()=>{if(!a)return;let e=e=>{k.current&&!k.current.contains(e.target)&&S()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a,S]),(0,s.useEffect)(()=>{a&&setTimeout(()=>y.current?.focus(),50)},[a]);let L=async t=>{v(!0);let n=await m.t4.runPromiseExit((0,h.Kl)({action:"checkout",cwd:e,path:e,branch:t}));if("Success"===n._tag){let e=t.replace(/^origin\//,"");(0,l.oR)(o("toast.switchedToBranch",{branch:e}),"success"),S(),r()}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:o("toast.switchBranchFailed");(0,l.oR)(r,"error")}v(!1)},M=d.filter(e=>e!==t&&e.toLowerCase().includes(j.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsx)("button",{onClick:a?S:C,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:o("git.switchBranch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),a&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lg z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:y,type:"text",value:j,onChange:e=>w(e.target.value),placeholder:o("git.searchBranch"),className:"w-full px-2.5 py-1.5 text-sm bg-muted rounded border-none outline-none placeholder:text-muted-foreground",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:p?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===M.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):M.map(e=>(0,n.jsx)("button",{onClick:()=>L(e),disabled:b,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function p({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:x,onOpenAliasManager:g,onBranchSwitched:b}){let{t:v}=(0,i.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6 cursor-pointer",title:v("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,l.oR)(v("toast.copiedPageUrl"),"success")})}}),e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,l.oR)(v("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v("tabManagerTopBar.copyDirPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}):(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"})]}),r&&e&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:x,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"Git Worktrees",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 17h8m0 0l-4-4m4 4l-4 4M3 7v6a4 4 0 004 4h5"})}),(0,n.jsx)("span",{className:"text-sm",children:s||"main"})]}),(0,n.jsx)(f,{cwd:e,currentBranch:s,onSwitched:()=>b?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(o.gT,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(a.ReviewDropdown,{cwd:e}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.refreshProject"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&m.t4.runFork((0,h.em)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.583 2.213L12 7.393 6.417 2.213 1 6.17v11.66l5.417 3.957L12 16.607l5.583 5.18L23 17.83V6.17l-5.417-3.957zM6.417 17.83L3 15.33V8.67l3.417-2.5v11.66zm11.166 0V6.17L21 8.67v6.66l-3.417 2.5z"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&m.t4.runFork((0,h.Q1)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openInCursor"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4.5 2L20.5 12L4.5 22V2Z"})})}),t?.sessionId&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t.sessionId}`;navigator.clipboard.writeText(e).then(()=>{(0,l.oR)(v("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("chat.copyCommandTooltip",{sessionId:t.sessionId}),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:g,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.aliasesGlobal"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12h-6m-4 0a8 8 0 1116 0 8 8 0 01-16 0zm4 0h.01"})})}),(0,n.jsx)("button",{onClick:()=>(0,c.F)(d.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.tokenStats"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,n.jsx)("button",{onClick:()=>window.open("https://surething.io?from=cockpit","_blank"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}},76900:(e,t,r)=>{r.d(t,{Cq:()=>x,D0:()=>p,DZ:()=>i,H7:()=>h,It:()=>b,Kl:()=>k,M5:()=>l,Or:()=>d,Q1:()=>j,QW:()=>f,Wr:()=>c,Yn:()=>g,b2:()=>w,em:()=>v,zF:()=>m});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:r=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})}),a=(e,t)=>o(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),l=()=>o("/api/settings"),i=e=>o("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>o("/api/version"),d=()=>o("/api/extension/version"),u=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",m=e=>o(u(e)),x=(e,t,r)=>n.tryPromise({try:async()=>{let n=u(e),s=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,baseMtime:r})});if(409===s.status){let e=await s.json();return{conflict:!0,content:e.content??"",mtime:e.mtime}}if(!s.ok)throw Error(`HTTP ${s.status}`);return{conflict:!1,mtime:(await s.json()).mtime}},catch:t=>new s.uV({message:`POST ${u(e)} failed`,cause:t})}),h=()=>o("/api/sessions/projects"),f=e=>o(`/api/sessions/projects/${encodeURIComponent(e)}`),p=e=>o(`/api/project-settings?cwd=${encodeURIComponent(e)}`),g=e=>a("/api/project-settings",e),b=()=>o("/api/pick-folder"),v=e=>a("/api/open-vscode",{cwd:e}),j=e=>a("/api/open-cursor",{cwd:e}),w=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),k=e=>a("/api/git/worktree",e)},83678:(e,t,r)=>{r.d(t,{SessionBrowser:()=>d});var n=r(95155),s=r(12115),o=r(79114),a=r(95045),l=r(75346),i=r(86957),c=r(76900);function d({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)({}),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(""),C=(0,s.useRef)(null),S=(0,s.useCallback)(async()=>{j(!0),k(null),b({});let e=await i.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?p(e.value):k("Failed to load projects"),j(!1)},[]),L=(0,s.useCallback)(async e=>{b(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await i.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?b(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):b(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),M=(0,s.useCallback)(e=>{let t=g[e];t?.isExpanded?b(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?b(t=>({...t,[e]:{...t[e],isExpanded:!0}})):L(e)},[g,L]);(0,s.useEffect)(()=>{e&&(S(),setTimeout(()=>{C.current?.focus(),C.current?.select()},100))},[e,S]);let E=(0,s.useCallback)(async()=>{if(x)return;h(!0);let e=await i.t4.runPromiseExit((0,c.It)());"Success"===e._tag&&e.value.folder&&u&&(u(e.value.folder),t()),h(!1)},[x,u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-7xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:m("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:C,type:"text",placeholder:m("workspace.searchProjectPath"),value:y,onChange:e=>N(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),y&&(0,n.jsx)("button",{onClick:()=>{N(""),C.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:m("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),u&&(0,n.jsxs)("button",{onClick:E,disabled:x,className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",title:m("sessions.openFolder"),children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),x?m("sessions.selectingFolder"):m("sessions.openFolder")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[v&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:m("workspace.loadingProjects")})]})}),w&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:w})}),!v&&!w&&0===f.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:m("workspace.projectNotFound")})}),!v&&!w&&f.filter(e=>e.fullPath.toLowerCase().includes(y.toLowerCase())).map(e=>{let t=g[e.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"mb-3",children:[(0,n.jsxs)("button",{onClick:()=>M(e.encodedPath),className:"w-full flex items-center gap-2 p-2 rounded hover:bg-accent transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-3 h-3 text-muted-foreground transition-transform ${t.isExpanded?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("span",{className:"flex-1 text-xs font-medium text-foreground truncate",title:e.fullPath,children:e.fullPath}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.sessionCount,")"]})]}),t.isExpanded&&(0,n.jsxs)("div",{className:"ml-6 mt-2",children:[t.isLoading&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-3 w-3",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:m("sessions.loadingSessions")})]}),t.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-11",children:t.error}),!t.isLoading&&!t.error&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:t.sessions.map(t=>(0,n.jsxs)("div",{onClick:()=>{var n;let s;return n=e.fullPath,s=(t.path.split("/").pop()||"").replace(".jsonl",""),void(r?r(n,s):(0,a.F)(l.n.OpenProject,{cwd:n,sessionId:s}))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[t.engine&&"claude"!==t.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===t.engine?"bg-orange-500/15 text-orange-11":"ollama"===t.engine?"bg-blue-500/15 text-blue-11":"codex"===t.engine?"bg-green-500/15 text-green-11":"kimi"===t.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:t.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:t.title,children:t.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[t.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path))})]})]},e.encodedPath)})]})]})]}):null}},84310:(e,t,r)=>{r.d(t,{Providers:()=>u});var n=r(95155),s=r(47617),o=r(3238),a=r(34075),l=r(12115),i=r(47650);function c(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return e;t=t.parentElement}return null}function d(){let[e,t]=(0,l.useState)(null),r=(0,l.useRef)(null);r.current=e;let s=(0,l.useRef)(null),o=(0,l.useRef)(null),[a,d]=(0,l.useState)({left:0,top:0}),[u,m]=(0,l.useState)(!1);return((0,l.useEffect)(()=>m(!0),[]),(0,l.useEffect)(()=>{let e=()=>{s.current&&(clearTimeout(s.current),s.current=null)},n=n=>{let o=c(n.target);if(!o){e(),r.current&&t(null);return}if(r.current&&r.current.text===o)return void t({text:o,x:n.clientX,y:n.clientY});e();let a=n.clientX,l=n.clientY;s.current=setTimeout(()=>{t({text:o,x:a,y:l}),s.current=null},300)},o=n=>{if(!r.current)return;let s=c(n.target);if(!s){e(),t(null);return}t({text:s,x:n.clientX,y:n.clientY})},a=()=>{e(),r.current&&t(null)};return document.addEventListener("mouseover",n,!0),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("mousedown",a),()=>{document.removeEventListener("mouseover",n,!0),document.removeEventListener("mousemove",o),document.removeEventListener("mouseleave",a),document.removeEventListener("mousedown",a),e()}},[]),(0,l.useLayoutEffect)(()=>{if(!e||!o.current)return;let t=o.current.getBoundingClientRect(),r=window.innerWidth,n=window.innerHeight,s=e.x+12,a=e.y+16;s+t.width>r-8&&(s=r-t.width-8),s<8&&(s=8),a+t.height>n-8&&(a=e.y-t.height-8),d({left:s,top:a})},[e]),u&&e)?(0,i.createPortal)((0,n.jsx)("div",{ref:o,className:"fixed z-[9999] px-2 py-1 bg-popover text-popover-foreground text-xs font-mono rounded shadow-lg border border-brand whitespace-nowrap pointer-events-none max-w-[80vw] overflow-hidden text-ellipsis",style:{left:a.left,top:a.top},children:e.text}),document.body):null}function u({children:e}){return(0,n.jsx)(s.I18nProvider,{children:(0,n.jsx)(o.N,{children:(0,n.jsxs)(a.tE,{children:[e,(0,n.jsx)(d,{})]})})})}},88371:(e,t,r)=>{r.d(t,{U:()=>o,k:()=>s});let n="cockpit-skills";function s(){let e="u"<typeof BroadcastChannel?null:new BroadcastChannel(n);if(e)try{e.postMessage({type:"changed"})}finally{e.close()}}function o(e){if("u"<typeof BroadcastChannel)return()=>{};let t=new BroadcastChannel(n),r=t=>{t.data?.type==="changed"&&e()};return t.addEventListener("message",r),()=>{t.removeEventListener("message",r),t.close()}}},89039:(e,t,r)=>{r.d(t,{useTabState:()=>u});var n=r(12115),s=r(41474),o=r(2111),a=r(95045),l=r(75346),i=r(49433),c=r(86957),d=r(96472);function u({initialCwd:e,initialSessionId:t,activeView:r}){let m=(0,n.useRef)(!1),x=(0,n.useRef)(!0),h=(0,n.useRef)(r);(0,n.useEffect)(()=>{h.current=r},[r]);let f=(0,s.F)(),p=(0,n.useRef)(f);(0,n.useEffect)(()=>{p.current=f},[f]);let[g,b]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),[v,j]=(0,n.useState)(g[0]?.id??""),[w,k]=(0,n.useState)(new Set),y=(0,n.useRef)(g);(0,n.useEffect)(()=>{y.current=g},[g]);let N=(0,n.useRef)(v);(0,n.useEffect)(()=>{N.current=v},[v]);let C=(0,n.useRef)(new Set),S=(0,n.useCallback)((t,r)=>{e&&t&&c.t4.runFork((0,d.KJ)(e,t,r).pipe(i.catchAll(()=>i.void)))},[e]),[L,M]=(0,n.useState)(null),[E,P]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||m.current||(m.current=!0,(async()=>{let r=await c.t4.runPromise((0,d.n8)(e).pipe(i.catchAll(()=>i.succeed(null))));if(r){let n=r.sessions||[],s=r.activeSessionId,o=r.engines||{},a=r.ollamaModels||{},l=r.deepseekModels||{},i=r.chatModes||{},c=r.planModes||{},d=[...n];if(t&&!d.includes(t)&&(d=[t,...d]),d.length>0){let r=d.map((t,r)=>({id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:o[t]||void 0,ollamaModel:a[t]||void 0,deepseekModel:l[t]||void 0,chatMode:i[t]||void 0,planMode:c[t]||void 0})),n=t||s,u=n?d.indexOf(n):-1;u<0&&(u=0);let m=r[u].id;b(r),j(m),setTimeout(()=>{x.current=!1},0)}else x.current=!1}else x.current=!1})())},[e,t]),(0,n.useEffect)(()=>{if(x.current||!e)return;let t=g.map(e=>e.sessionId).filter(e=>!!e),r=g.find(e=>e.id===v),n=r?.sessionId,s={},o={},a={},l={},u={};for(let e of g)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(o[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(a[e.sessionId]=e.deepseekModel),e.sessionId&&(l[e.sessionId]="pty"===e.chatMode?"pty":"sdk",u[e.sessionId]=!!e.planMode);let m=[...C.current];c.t4.runFork((0,d.ej)({cwd:e,sessions:t,activeSessionId:n,engines:s,ollamaModels:o,deepseekModels:a,chatModes:l,planModes:u,...m.length?{closedSessionIds:m}:{}}).pipe(i.tap(()=>i.sync(()=>{for(let e of m)C.current.delete(e)})),i.tapError(e=>i.sync(()=>console.error("Failed to save sessions:",e))),i.catchAll(()=>i.void)))},[g,v,e]),(0,n.useEffect)(()=>{if(x.current||!e)return;let t=g.find(e=>e.id===v);t?.sessionId&&(0,a.F)(l.n.SessionChange,{cwd:e,sessionId:t.sessionId})},[v,g,e]);let T=(0,n.useCallback)(t=>{e&&c.t4.runPromise((0,d.n8)(e).pipe(i.catchAll(()=>i.succeed(null)))).then(r=>{if(!r)return;let n=r.sessions||[],s=r.engines||{},o=r.ollamaModels||{},a=r.deepseekModels||{},l=r.chatModes||{},i=r.planModes||{},c=y.current,d=new Set(t),u=c.filter(e=>!e.sessionId||!d.has(e.sessionId)),m=new Set(u.map(e=>e.sessionId).filter(Boolean)),x=n.filter(e=>!m.has(e));if(u.length===c.length&&0===x.length)return;let h=[...u,...x.map((t,r)=>({id:`tab-${Date.now()}-sync-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:s[t]||void 0,ollamaModel:o[t]||void 0,deepseekModel:a[t]||void 0,chatMode:l[t]||void 0,planMode:i[t]||void 0}))];0===h.length&&(h=[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),b(h),h.some(e=>e.id===N.current)||j(h[h.length-1].id)})},[e]);(0,o.h)({url:"/ws/global-state",enabled:!!e,onMessage:t=>{x.current||!e||"project-state-changed"===t.type&&t.cwd===e&&T(t.closedSessionIds??[])}});let $=(0,n.useCallback)((e,t,r,n,s,o,a=!1)=>{let l={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:n,ollamaModel:s,deepseekModel:o};b(e=>{if(a)return[...e,l];let t=e.findIndex(e=>e.id===v);if(-1===t)return[...e,l];let r=[...e];return r.splice(t+1,0,l),r}),j(l.id)},[v]),R=(0,n.useCallback)(t=>{let r=y.current.find(e=>e.id===t);r?.sessionId&&C.current.add(r.sessionId),b(r=>{let n=r.filter(e=>e.id!==t);if(t===v&&n.length>0&&j(n[n.length-1].id),0===n.length){let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};return j(t.id),[t]}return n})},[v,e]),B=(0,n.useCallback)((t,r)=>{let n=g.find(e=>e.sessionId===t);n?j(n.id):$(e,t,r,void 0,void 0,void 0,!0)},[g,e,$]),F=(0,n.useCallback)(()=>{$(e,void 0,void 0,void 0,void 0,void 0,!0)},[e,$]),I=(0,n.useCallback)(()=>{$(e,void 0,"New Claude 2 Chat","claude2",void 0,void 0,!0)},[e,$]),D=(0,n.useCallback)(()=>{$(e,void 0,"New Codex Chat","codex",void 0,void 0,!0)},[e,$]),A=(0,n.useCallback)(()=>{$(e,void 0,"New Kimi Chat","kimi",void 0,void 0,!0)},[e,$]),z=(0,n.useCallback)(t=>{$(e,void 0,t?`New Ollama (${t})`:"New Ollama Chat","ollama",t,void 0,!0)},[e,$]),W=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),_=(0,n.useCallback)(()=>{$(e,void 0,"New DeepSeek Chat","deepseek",void 0,"deepseek-v4-flash",!0)},[e,$]),H=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),O=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,chatMode:t}:r))},[]),q=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,planMode:t}:r))},[]),V=(0,n.useCallback)((t,r)=>{$(e,t,r)},[e,$]),U=(0,n.useCallback)((e,t)=>{b(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!h.current||"agent"===h.current;if(e===v&&r&&p.current){let e=n.sessionId||t.sessionId;e&&S(e,"normal")}else k(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[v,S]);(0,n.useEffect)(()=>{(!r||"agent"===r)&&f&&k(e=>{if(!e.has(v))return e;let t=new Set(e);t.delete(v);let r=y.current.find(e=>e.id===v);return r?.sessionId&&(S(r.sessionId,"normal"),c.t4.runFork((0,d.M2)(r.sessionId).pipe(i.catchAll(()=>i.void)))),t})},[r,v,f,S]);let K=(0,n.useCallback)(e=>{j(e),k(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=y.current.find(t=>t.id===e);return n?.sessionId&&(S(n.sessionId,"normal"),c.t4.runFork((0,d.M2)(n.sessionId).pipe(i.catchAll(()=>i.void)))),r})},[S]),J=(0,n.useCallback)(e=>{M(e)},[]),Q=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==L&&L!==t&&P(t)},[L]),Z=(0,n.useCallback)(e=>{null!==L&&L!==e&&b(t=>{let r=[...t],[n]=r.splice(L,1);return r.splice(e,0,n),r}),M(null),P(null)},[L]),Y=(0,n.useCallback)(()=>{M(null),P(null)},[]),G=g.find(e=>e.id===v);return{tabs:g,activeTabId:v,activeTab:G,unreadTabs:w,dragTabIndex:L,dragOverTabIndex:E,addTab:$,closeTab:R,switchTab:K,handleSelectSession:B,handleNewTab:F,handleNewClaude2Tab:I,handleNewCodexTab:D,handleNewKimiTab:A,handleNewOllamaTab:z,handleNewDeepseekTab:_,handleOpenSession:V,updateTabState:U,updateTabOllamaModel:W,updateTabDeepseekModel:H,updateTabChatMode:O,updateTabPlanMode:q,handleTabDragStart:J,handleTabDragOver:Q,handleTabDrop:Z,handleTabDragEnd:Y}}},93777:(e,t,r)=>{r.d(t,{E:()=>c});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(12786);let i={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120}],cron:[{labelKey:"scheduledTasks.daily9am",value:"0 9 * * *"},{labelKey:"scheduledTasks.daily6pm",value:"0 18 * * *"},{labelKey:"scheduledTasks.weeklyMon9am",value:"0 9 * * 1"},{labelKey:"scheduledTasks.monthly1st9am",value:"0 9 1 * *"}]};function c({onClose:e,onCreate:t,editTask:r,onUpdate:d}){let{t:u}=(0,o.Bd)(),m=!!r,[x,h]=(0,s.useState)(r?.type||"once"),[f,p]=(0,s.useState)(r?.message||""),[g,b]=(0,s.useState)(r?String(r.delayMinutes||r.intervalMinutes||""):""),[v,j]=(0,s.useState)(r?.cron||""),[w,k]=(0,s.useState)(r?.activeFrom||"09:00"),[y,N]=(0,s.useState)(r?.activeTo||"18:00"),[C,S]=(0,s.useState)(!!(r?.activeFrom&&r?.activeTo)),[L,M]=(0,s.useState)(null),E=(0,s.useRef)(null),P=(0,s.useRef)(null);(0,s.useEffect)(()=>{P.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{E.current&&!E.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let T=(0,s.useCallback)(()=>{if(!f.trim())return;let n=null;if("once"===x){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"once",delayMinutes:e}}else if("interval"===x){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"interval",intervalMinutes:e,...C?{activeFrom:w,activeTo:y}:{}}}else if("cron"===x){let e=L||v.trim();if(!e)return;n={message:f.trim(),type:"cron",cron:e}}n&&(m&&r&&d?d(r.id,n):t(n),e())},[f,x,L,g,v,C,w,y,t,e,m,r,d]);return(0,n.jsxs)("div",{ref:E,className:`w-[28rem] max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lg z-50 ${m?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&T()},children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:m?u("scheduledTasks.editTask"):u("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4 max-h-[min(52rem,calc(100vh-3rem))] overflow-y-auto",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.sendMessage")}),(0,n.jsx)("textarea",{ref:P,value:f,onChange:e=>p(e.target.value),placeholder:u("scheduledTasks.messagePlaceholder"),rows:5,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-y min-h-[6rem]"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{h(e),M(null),b(""),j("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${x===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?u("scheduledTasks.once"):"interval"===e?u("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:i[x].map(e=>(0,n.jsx)("button",{onClick:()=>{M(e.value),"cron"===x?j(String(e.value)):b(String(e.value))},className:`px-2 py-1 text-xs rounded border transition-colors ${L===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:u(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===x?u("scheduledTasks.customCron"):u("scheduledTasks.customMinutes")}),"cron"===x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:v,onChange:e=>{j(e.target.value),M(null)},placeholder:u("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),v.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=a.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,l,i]=r,c={0:t("cron.dowSun"),1:t("cron.dowMon"),2:t("cron.dowTue"),3:t("cron.dowWed"),4:t("cron.dowThu"),5:t("cron.dowFri"),6:t("cron.dowSat")},d={1:`1${t("cron.monthPrefix")}`,2:`2${t("cron.monthPrefix")}`,3:`3${t("cron.monthPrefix")}`,4:`4${t("cron.monthPrefix")}`,5:`5${t("cron.monthPrefix")}`,6:`6${t("cron.monthPrefix")}`,7:`7${t("cron.monthPrefix")}`,8:`8${t("cron.monthPrefix")}`,9:`9${t("cron.monthPrefix")}`,10:`10${t("cron.monthPrefix")}`,11:`11${t("cron.monthPrefix")}`,12:`12${t("cron.monthPrefix")}`};try{let e="";if(n.includes("/")||s.includes("/")){if("*"===s&&n.includes("/"))return t("cron.everyNMinutes",{n:n.split("/")[1]});if("0"===n&&s.includes("/"))return t("cron.everyNHours",{n:s.split("/")[1]});return null}let r=parseInt(s,10),a=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(a)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:a}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}`;let u=[];if("*"!==l){let e=l.split(",").map(e=>d[e]||`${e}${t("cron.monthPrefix")}`);u.push(e.join(", "))}if("*"!==o)if(o.includes("-")){let[e,r]=o.split("-");u.push(t("cron.dayRange",{a:e,b:r}))}else o.includes(",")?u.push(o.split(",").map(e=>`${e}${t("cron.dayOfMonth")}`).join(", ")):u.push(`${o}${t("cron.dayOfMonth")}`);if("*"!==i)if("1-5"===i)u.push(t("cron.weekdays"));else if("0,6"===i||"6,0"===i)u.push(t("cron.weekends"));else{let e=i.split(",").map(e=>{if(e.includes("-")){let[r,n]=e.split("-");return t("cron.weekdayRange",{a:c[r]||r,b:c[n]||n})}return`${t("cron.weekdayPrefix")}${c[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===l&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}(v.trim())||(0,n.jsx)("span",{className:"text-destructive",children:u("scheduledTasks.cronFormat")})})]}):(0,n.jsx)("input",{type:"number",value:g,onChange:e=>{b(e.target.value),M(null)},placeholder:u("scheduledTasks.minutesPlaceholder"),min:1,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]}),"interval"===x&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:C,onChange:e=>S(e.target.checked),className:"rounded border-border"}),u("scheduledTasks.limitTimeRange")]}),C&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:w,onChange:e=>k(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:y,onChange:e=>N(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]})]}),(0,n.jsx)("button",{onClick:T,disabled:!(f.trim()&&("once"===x||"interval"===x?!!(L||g&&parseInt(g,10)>0):"cron"===x&&!!(L||v.trim()))),className:"w-full py-1.5 text-sm font-medium rounded bg-brand text-white hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:m?u("scheduledTasks.saveBtn",{modKey:(0,l.Mu)()}):u("scheduledTasks.createBtn",{modKey:(0,l.Mu)()})})]})]})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}),a=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"saveProjectState failed",cause:e})}),l=(e,t,r)=>n.tryPromise({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})}}]);
|
|
25
|
+
${o}`),ej(n,r)}else ej(I("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}ej(e,r)},[ej,t,I,ea,ee,eo]),ey=(0,s.useCallback)(()=>{eo(!1),ej(I("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[ej,eo,I]),[eN,eC]=(0,s.useState)(!1),eS=(0,s.useRef)(!1);(0,s.useEffect)(()=>{eS.current=eN},[eN]);let{isLoadingHistory:eL,isLoadingMore:eM,hasMoreHistory:eE,loadMoreHistory:eP,loadHistoryByCwdAndSessionId:eT,loadedSessionId:e$}=(0,nh.m)(A,z,W,{cwd:t,initialSessionId:r,onSessionId:_,onTitleChange:L,onTokenUsage:Y,liveRunningRef:eS}),eR=e$||W,eB=y&&!ef&&!!eR;(0,nd.u)(eR,z,eB,u,{onRunningChange:e=>{eS.current=e,eC(e)},onComplete:()=>{t&&eR&&eT(t,eR,!0)}}),(0,s.useEffect)(()=>{eB||eC(!1)},[eB]),(0,s.useEffect)(()=>{eh.current=()=>{t&&eR&&eT(t,eR,!0)}},[t,eR,eT]);let eF=(0,s.useRef)(y);(0,s.useEffect)(()=>{y&&!eF.current&&W&&t&&!ef&&!eN&&eT(t,W,!0,10),eF.current=y},[y,W,t,ef,eN,eT]);let eI=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!N||N.nonce===eI.current)return;eI.current=N.nonce;let e=W||e$;!t||!e||N.sessionId!==W&&N.sessionId!==e$||ef||eN||eT(t,e,!0,10,void 0,!0)},[N,W,e$,t,ef,eN,eT]),(0,s.useEffect)(()=>{"pty"===ee&&ef&&!ed.current&&el.current?.clear(),ed.current=ef},[ef,ee]);let eD=ep||Z;(0,s.useEffect)(()=>{W&&S?.(W)},[W,S]);let eA=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(C?.(ef),eA.current&&!ef&&t&&W){let e;for(let t=A.length-1;t>=0;t--)if("user"===A[t].role&&A[t].content){e=A[t].content.slice(0,100);break}(0,a.F)(l.n.SessionComplete,{cwd:t,sessionId:W,lastUserMessage:e})}eA.current=ef},[ef,C,t]),(0,s.useEffect)(()=>{y&&D?.setIsLoading(ef)},[ef,y,D]),(0,s.useEffect)(()=>{if(e&&D)return D.registerChat(e=>{em.current?.(e)},e),()=>{D.unregisterChat(e)}},[e,D]),(0,s.useEffect)(()=>{e&&y&&D&&D.setActiveTab(e)},[e,y,D]),(0,s.useEffect)(()=>{em.current=ek},[ek]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&H&&(ef||eN)&&ew()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[H,ef,eN,ew]);let ez=(0,s.useCallback)(async e=>{let r=e$??W;if(!t||!r)return;let n=await i.t4.runPromiseExit((0,c.Zr)(r,{cwd:t,fromMessageUuid:e}));if("Success"===n._tag&&n.value.newSessionId){let e=n.value.newSessionId;T?T(e,"Fork"):(0,a.F)(l.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===n._tag&&console.error("Fork failed:",n.cause)},[t,e$,W,T]),eW=(0,s.useCallback)(()=>{K(!0)},[]),e_=(0,s.useCallback)(()=>{Q(!0)},[]),eH=(0,s.useMemo)(()=>{if(P&&t&&e&&W)return r=>{P({...r,cwd:t,tabId:e,sessionId:W,engine:u,..."ollama"===u&&m&&{model:m},..."deepseek"===u&&h&&{model:h}})}},[P,t,e,W,u,m,h]);return(0,n.jsxs)("div",{className:`flex ${j&&w?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>O(!0),onMouseLeave:()=>O(!1),children:[!j&&(0,n.jsx)(nu,{cwd:t,sessionId:W,onOpenProjectSessions:()=>V(!0),onOpenSessionBrowser:B,onOpenSettings:F}),ea&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card/50",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:I("chat.executionMode",{defaultValue:"Execution mode"})}),(0,n.jsxs)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":"chatmode-toggle",children:[(0,n.jsx)("button",{type:"button","data-testid":"chatmode-sdk",onClick:()=>et("sdk"),className:`px-2 py-0.5 ${"sdk"===ee?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-accent"}`,children:"Claude Agent SDK"}),(0,n.jsx)("button",{type:"button","data-testid":"chatmode-pty",onClick:()=>et("pty"),className:`px-2 py-0.5 ${"pty"===ee?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-accent"}`,title:I("chat.ptyModeHint",{defaultValue:"Subscription-billing mode: driven by the interactive claude CLI"}),children:"Claude Code CLI"})]}),"sdk"===ee&&(0,n.jsxs)("label",{className:"flex items-center gap-1.5 ml-2 pl-3 border-l border-border text-xs cursor-pointer select-none",title:I("chat.planModeHint",{defaultValue:"Plan mode: read-only exploration that produces a plan without editing. Uncheck and resend to implement."}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:es,onChange:e=>eo(e.target.checked),className:"accent-brand"}),(0,n.jsxs)("span",{className:"flex items-center gap-1 text-foreground",children:[(0,n.jsx)(nc.A,{className:"w-3.5 h-3.5"}),I("chat.planMode",{defaultValue:"Plan mode"})]}),(0,n.jsx)("span",{className:"text-muted-foreground",children:I("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"})})]})]}),"ollama"===u&&x&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(ny,{currentModel:m,onModelChange:x})}),"deepseek"===u&&f&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(nC,{currentModel:h,onModelChange:f})}),eL?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:I("sessions.loadingHistory")})}):(0,n.jsx)(np.M,{ref:eu,messages:A,isLoading:ef||eN,cwd:t,sessionId:W,engine:u,apiRetryInfo:eb,ptyNotice:ev,hasMoreHistory:eE,isLoadingMore:eM,onLoadMore:eP,onFork:ez,isActive:y,onContentSearch:$,onShowFileDiff:R,onApprovePlan:ey}),eD&&(0,n.jsx)(nm,{tokenUsage:eD,rateLimitInfo:eg}),(0,n.jsx)(nw,{onSend:ek,disabled:ef||eN,cwd:t,engine:u,onShowGitStatus:M,onShowComments:t?eW:void 0,onShowUserMessages:e_,onOpenNote:E,onCreateScheduledTask:eH}),(0,n.jsx)(nk.ri,{ref:el,visible:ea&&"pty"===ee,running:ef,onInput:ec})]}),!j&&t&&(0,n.jsx)(d,{isOpen:q,onClose:()=>V(!1),cwd:t}),t&&(0,n.jsx)(nM,{isOpen:U,onClose:()=>K(!1),cwd:t}),(0,n.jsx)(nx,{isOpen:J,onClose:()=>Q(!1),messages:A,onSelectMessage:e=>{eu.current?.scrollToMessage(e)}})]})}function nP({tabId:e,cwd:t,sessionId:r,engine:o,ollamaModel:a,onOllamaModelChange:l,deepseekModel:i,onDeepseekModelChange:c,chatMode:d,onChatModeChange:u,planMode:m,onPlanModeChange:x,isActive:h,refreshSignal:f,onStateChange:p,onShowGitStatus:g,onOpenNote:b,onCreateScheduledTask:v,onOpenSession:j,onContentSearch:w,onShowFileDiff:k}){let y=(0,s.useCallback)(t=>{p(e,{isLoading:t})},[e,p]),N=(0,s.useCallback)(t=>{p(e,{sessionId:t})},[e,p]),C=(0,s.useCallback)(t=>{p(e,{title:t})},[e,p]),S=(0,s.useCallback)(t=>{l?.(e,t)},[e,l]),L=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),M=(0,s.useCallback)(t=>{u?.(e,t)},[e,u]),E=(0,s.useCallback)(t=>{x?.(e,t)},[e,x]);return(0,n.jsx)(nE,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,ollamaModel:a,onOllamaModelChange:S,deepseekModel:i,onDeepseekModelChange:L,chatMode:d,onChatModeChange:M,planMode:m,onPlanModeChange:E,hideHeader:!0,hideSidebar:!0,isActive:h,refreshSignal:f,onLoadingChange:y,onSessionIdChange:N,onTitleChange:C,onShowGitStatus:g,onOpenNote:b,onCreateScheduledTask:v,onOpenSession:j,onContentSearch:w,onShowFileDiff:k})}var nT=r(3292),n$=r(23121),nR=r(88292),nB=r(76900),nF=r(96472);function nI({initialCwd:e,initialSessionId:t,initialView:r}){let{t:a}=(0,o.Bd)(),[c,u]=(0,s.useState)(r??"agent"),{tabs:x,activeTabId:h,activeTab:f,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,closeTab:v,switchTab:j,handleSelectSession:w,handleNewTab:k,handleNewClaude2Tab:y,handleNewCodexTab:N,handleNewKimiTab:C,handleNewOllamaTab:S,handleNewDeepseekTab:L,handleOpenSession:M,updateTabState:E,updateTabOllamaModel:P,updateTabDeepseekModel:T,updateTabChatMode:$,updateTabPlanMode:R,handleTabDragStart:B,handleTabDragOver:F,handleTabDrop:D,handleTabDragEnd:A}=(0,na.useTabState)({initialCwd:e,initialSessionId:t,activeView:c}),{isPinned:z,pinSession:W,unpinSession:_}=(0,nT.P)(),{createTask:H}=(0,n$.n)(),O=(0,s.useCallback)(e=>{let t=x.find(t=>t.id===e);return!!t?.sessionId&&z(t.sessionId)},[x,z]),q=(0,s.useCallback)(t=>{let r=x.find(e=>e.id===t);r?.sessionId&&(z(r.sessionId)?_(r.sessionId):W(r.sessionId,r.cwd||e||"",r.title))},[x,z,W,_,e]),[V,U]=(0,s.useState)(!1),[K,J]=(0,s.useState)(!1),[Z,Y]=(0,s.useState)(!1),[G,X]=(0,s.useState)(null),[ee,et]=(0,s.useState)(!1),[er,en]=(0,s.useState)("tree"),[es,eo]=(0,s.useState)(0),[ea,el]=(0,s.useState)(null),[ei,ec]=(0,s.useState)(0),[ed,eu]=(0,s.useState)(null),[em,ex]=(0,s.useState)(null);(0,s.useEffect)(()=>{e&&!r&&i.t4.runPromiseExit((0,nB.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&u(t.activeView)}})},[e,r]);let[eh,ef]=(0,s.useState)(!1),ep=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(ep.current=c,u("console"),ef(!0)):(ef(!1),ep.current&&"console"!==ep.current&&u(ep.current),ep.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[c]);let eg=(0,s.useCallback)(t=>{u(t),e&&(i.t4.runFork((0,nB.Yn)({cwd:e,settings:{activeView:t}}).pipe(Q.orElse(()=>Q.void))),i.t4.runFork(Q.flatMap(nR.d,r=>r.publish(l.n.ViewChange,{cwd:e,view:t}))))},[e]),eb=(0,s.useCallback)(async()=>{if(!e)return;let t=await i.t4.runPromiseExit((0,nB.b2)(e));if("Success"===t._tag){let r=t.value;if(et(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&X(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eb())},[eb]);let ev=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"git"===e.type)&&eb()},[eb]);(0,I.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:ev,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),eg("agent")):"2"===e.key?(e.preventDefault(),eg("explorer")):"3"===e.key?(e.preventDefault(),eg("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){w(r),n&&eg("agent");let t=x.find(e=>e.sessionId===r);t&&ex(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(i.t4.runFork((0,nF.KJ)(e,r,"normal").pipe(Q.orElse(()=>Q.void))),i.t4.runFork((0,nF.M2)(r).pipe(Q.orElse(()=>Q.void))))}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[w,eg,e,x]);let ej=(0,s.useCallback)(()=>{en("status"),eo(e=>e+1),eg("explorer")},[eg]),ew=(0,s.useCallback)(e=>{el(e),ec(e=>e+1),eg("explorer")},[eg]),ek=(0,s.useCallback)((e,t)=>{eu({toolCalls:e,cwd:t}),eg("explorer")},[eg]);(0,s.useEffect)(()=>{eu(null)},[es,ei]);let ey=(0,s.useCallback)(()=>{e&&i.t4.runFork(Q.flatMap(nR.d,t=>t.publish(l.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(ns.k_,{children:(0,n.jsx)(ts.fY,{activeView:c,onViewChange:eg,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(nl.TabManagerTopBar,{initialCwd:e,activeTab:f,isGitRepo:ee,currentBranch:G,onOpenWorktree:()=>J(!0),onOpenAliasManager:()=>Y(!0),onBranchSwitched:eb}),eh&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),a("console.screenshotting")]}),e?(0,n.jsxs)(ts.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(ni.TabBar,{tabs:x,activeTabId:h,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,isPinned:O,onTogglePin:q,onSwitchTab:j,onCloseTab:v,onNewTab:k,onNewClaude2Tab:y,onNewCodexTab:N,onNewKimiTab:C,onNewOllamaTab:S,onNewDeepseekTab:L,onOpenProjectSessions:()=>U(!0),onDragStart:B,onDragOver:F,onDrop:D,onDragEnd:A}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:x.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===h?"block":"hidden"}`,children:(0,n.jsx)(nP,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:P,deepseekModel:e.deepseekModel,onDeepseekModelChange:T,chatMode:e.chatMode,onChatModeChange:$,planMode:e.planMode,onPlanModeChange:R,isActive:e.id===h&&"agent"===c,refreshSignal:em,onStateChange:E,onShowGitStatus:ej,onContentSearch:ew,onShowFileDiff:ek,onOpenNote:ey,onCreateScheduledTask:H,onOpenSession:M})},e.id))})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsxs)(m.a9,{children:[(0,n.jsx)(to,{onClose:()=>eg("agent"),cwd:e,initialTab:er,tabSwitchTrigger:es,initialSearchQuery:ea,searchQueryTrigger:ei}),ed&&(0,n.jsx)("div",{className:"absolute inset-0 z-20",children:(0,n.jsx)(no.e$,{toolCalls:ed.toolCalls,cwd:ed.cwd,onClose:()=>eu(null)})})]})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsx)(nn,{cwd:e,tabId:"default",onOpenNote:ey})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(ni.TabBar,{tabs:x,activeTabId:h,unreadTabs:p,dragTabIndex:g,dragOverTabIndex:b,isPinned:O,onTogglePin:q,onSwitchTab:j,onCloseTab:v,onNewTab:k,onNewClaude2Tab:y,onNewCodexTab:N,onNewKimiTab:C,onNewDeepseekTab:L,onDragStart:B,onDragOver:F,onDrop:D,onDragEnd:A}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:x.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===h?"block":"hidden"}`,children:(0,n.jsx)(nP,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:P,deepseekModel:e.deepseekModel,onDeepseekModelChange:T,chatMode:e.chatMode,onChatModeChange:$,planMode:e.planMode,onPlanModeChange:R,isActive:e.id===h,refreshSignal:em,onStateChange:E,onCreateScheduledTask:H,onOpenSession:M})},e.id))})]})]}),e&&(0,n.jsx)(d,{isOpen:V,onClose:()=>U(!1),cwd:e,onSelectSession:w}),e&&ee&&(0,n.jsx)(ta,{isOpen:K,onClose:()=>J(!1),cwd:e}),Z&&(0,n.jsx)(tF,{onClose:()=>Y(!1),onSave:()=>Y(!1)})]})})})}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>x});var n=r(95155),s=r(12115),o=r(79114),a=r(3238),l=r(34075),i=r(12786),c=r(53853),d=r(86957),u=r(49433),m=r(76900);function x({isOpen:e,onClose:t}){let{t:r,i18n:h}=(0,o.Bd)(),{theme:f,setTheme:p}=(0,a.D)(),g=(0,c.G)(),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.M5)()).then(e=>{"Success"===e._tag&&e.value.language&&y(e.value.language)})},[e]);let N=(0,s.useCallback)(e=>{y(e),d.t4.runFork((0,m.DZ)({language:e}).pipe(u.orElse(()=>u.void)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;h.changeLanguage(t)},[h]),C=g?"installed":"not-installed",S=g?.version??null;if((0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.Wr)()).then(e=>{"Success"===e._tag&&e.value.version&&w(e.value.version)})},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&v(e.value.path)})},[e]),!e)return null;let L=[{value:"system",label:r("settings.themeSystem"),icon:"\uD83D\uDCBB"},{value:"light",label:r("settings.themeLight"),icon:"☀️"},{value:"dark",label:r("settings.themeDark"),icon:"\uD83C\uDF19"}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-md mx-4 overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("settings.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.theme")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:L.map(e=>(0,n.jsxs)("button",{onClick:()=>p(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${f===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.language")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{value:"auto",label:r("settings.languageAuto"),icon:"\uD83C\uDF10"},{value:"en",label:"English",icon:"\uD83C\uDDFA\uD83C\uDDF8"},{value:"zh",label:"中文",icon:"\uD83C\uDDE8\uD83C\uDDF3"}].map(e=>(0,n.jsxs)("button",{onClick:()=>N(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${k===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.browserExtension")}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${"installed"===C?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===C&&`${r("settings.extensionInstalled")}${S?` (v${S})`:""}`,"not-installed"===C&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==C&&(0,n.jsxs)("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-md p-2 space-y-1",children:[(0,n.jsx)("p",{className:"font-medium text-foreground",children:r("settings.installSteps")}),(0,n.jsxs)("p",{children:[r("settings.step1")," ",(0,n.jsx)("code",{className:"px-1 py-0.5 bg-muted rounded text-foreground",children:"chrome://extensions"})]}),(0,n.jsx)("p",{children:r("settings.step2")}),(0,n.jsx)("p",{children:r("settings.step3")}),(0,i.L)()&&(0,n.jsx)("p",{dangerouslySetInnerHTML:{__html:r("settings.step4mac")}})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>{let e=b||"chrome-extension";navigator.clipboard.writeText(e),(0,l.oR)(r("toast.copiedName",{name:e}))},className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:r("settings.copyExtensionPath")}),"installed"===C&&(0,n.jsx)("button",{onClick:()=>{g?.id&&window.chrome?.runtime?.sendMessage&&(window.chrome.runtime.sendMessage(g.id,{type:"reload"}),(0,l.oR)(r("toast.pluginReloading")))},className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-muted transition-colors",children:r("settings.reloadExtension")})]}),b&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:b})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.about")}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground space-y-1",children:[(0,n.jsxs)("p",{children:["Cockpit",j?` v${j}`:""]}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},23121:(e,t,r)=>{r.d(t,{n:()=>m});var n=r(12115),s=r(95045),o=r(75346),a=r(49433),l=r(86957),i=r(82680);let c=(e,t,r)=>a.tryPromise({try:async()=>{let n=await fetch(e,{method:t,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:r=>new i.uV({message:`${t} ${e} failed`,cause:r})}),d="SCHEDULED_TASKS_CHANGED";function u(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:d},"*")}catch{}})}function m(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useCallback)(()=>{let e;l.t4.runPromise((e="/api/scheduled-tasks",a.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new i.uV({message:`fetch ${e} failed`,cause:t})})).pipe(a.match({onSuccess:e=>{t(e.tasks??[]),s(e.unreadCount??0)},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{o()},[o]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===d&&o()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[o]);let m=(0,n.useCallback)(async e=>{let t=await l.t4.runPromiseExit(c("/api/scheduled-tasks","POST",e));if("Success"!==t._tag)return null;let r=t.value;return r.task?(o(),u(),r.task):null},[o]),x=(0,n.useCallback)(async(e,t,r)=>{await l.t4.runPromise(c("/api/scheduled-tasks","PATCH",{id:e,action:t,fields:r}).pipe(a.asVoid).pipe(a.orElse(()=>a.void))),o(),u()},[o]),h=(0,n.useCallback)(e=>x(e,"pause"),[x]),f=(0,n.useCallback)(e=>x(e,"resume"),[x]),p=(0,n.useCallback)(async e=>{await l.t4.runPromise(c("/api/scheduled-tasks","DELETE",{id:e}).pipe(a.asVoid).pipe(a.orElse(()=>a.void))),o(),u()},[o]),g=(0,n.useCallback)((e,t)=>x(e,"update",t),[x]),b=(0,n.useCallback)(e=>x(e,"trigger"),[x]),v=(0,n.useCallback)(e=>x(e,"markRead"),[x]);return{tasks:e,unreadCount:r,reload:o,createTask:m,pauseTask:h,resumeTask:f,triggerTask:b,deleteTask:p,updateTask:g,markRead:v,markAllRead:(0,n.useCallback)(()=>x("_","markAllRead"),[x]),reorderTasks:(0,n.useCallback)(e=>x("_","reorder",{orderedIds:e}),[x])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>d});var n=r(95155),s=r(12115),o=r(94287),a=r(64428),l=r(79114);function i({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function c({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:l,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),m=(0,s.useRef)(null),x=(0,s.useRef)(null),[h,f]=(0,s.useState)({top:0,right:0}),p=(0,a.F2)();(0,s.useEffect)(()=>{if(!d)return;let e=e=>{x.current&&!x.current.contains(e.target)&&m.current&&!m.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let g=n=>{u(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?l?.():"deepseek"===n?i?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:m,onClick:()=>{if(!d&&m.current){let e=m.current.getBoundingClientRect(),t=p?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;f({top:e.bottom+4-n,right:s-(e.right-r)})}u(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"New tab",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),d&&(0,n.jsx)(a.ZL,{children:(0,n.jsxs)("div",{ref:x,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:h.top,right:h.right},children:[(0,n.jsxs)("button",{onClick:()=>g("claude"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}),"Claude Code"]}),(0,n.jsxs)("button",{onClick:()=>g("claude2"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-orange-500 flex-shrink-0"}),"Claude 2"]}),(0,n.jsxs)("button",{onClick:()=>g("codex"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 flex-shrink-0"}),"Codex"]}),(0,n.jsxs)("button",{onClick:()=>g("deepseek"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"}),"DeepSeek"]}),(0,n.jsxs)("button",{onClick:()=>g("kimi"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-blue-500 flex-shrink-0"}),"Kimi"]}),(0,n.jsxs)("button",{onClick:()=>g("ollama"),className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-violet-500 flex-shrink-0"}),"Ollama"]})]})})]})}function d({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:a,isPinned:u,onTogglePin:m,onSwitchTab:x,onCloseTab:h,onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j,onOpenProjectSessions:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C}){let{t:S}=(0,l.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((l,c)=>(0,n.jsx)(o.m,{content:l.title,delay:200,className:"flex-1 min-w-16 max-w-32",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>k(c),onDragOver:e=>y(e,c),onDrop:()=>N(c),onDragEnd:C,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg border-t-[1.5px] transition-colors ${l.id===t?"border-brand bg-slate-4 text-foreground font-medium":"border-transparent text-muted-foreground hover:bg-secondary/50"} ${s===c?"opacity-50":""} ${a===c?"border-l-2 border-brand":""}`,onClick:()=>x(l.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(i,{number:c+1,isActive:l.id===t}),l.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!l.isLoading&&r.has(l.id)&&l.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),m&&u?.(l.id)&&!l.isLoading&&!(r.has(l.id)&&l.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m(l.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:S("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),m&&!u?.(l.id)&&!l.isLoading&&!(r.has(l.id)&&l.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m(l.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:S("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:l.title}),"claude2"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-orange-500/15 text-orange-400 font-medium leading-relaxed",children:"C2"}),"codex"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-emerald-500/15 text-emerald-400 font-medium leading-relaxed",children:"CX"}),"kimi"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-blue-500/15 text-blue-400 font-medium leading-relaxed",children:"KM"}),"ollama"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-violet-500/15 text-violet-400 font-medium leading-relaxed",children:"OL"}),"deepseek"===l.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-sky-500/15 text-sky-400 font-medium leading-relaxed",children:"DS"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(l.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:S("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},l.id)),(0,n.jsx)(c,{onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j}),w&&(0,n.jsx)("button",{onClick:w,className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:S("sessions.projectSessions"),"aria-label":S("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})})]})})}},26520:(e,t,r)=>{r.d(t,{Workspace:()=>q});var n=r(95155),s=r(12115),o=r(79114),a=r(42701),l=r(76288),i=r(83678),c=r(21484),d=r(86957),u=r(62111),m=r(83448);let x={"claude-opus-4-6":{label:"Opus 4.6",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"},"claude-opus-4-5-20251101":{label:"Opus 4.5",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#fb923c"},"claude-sonnet-4-6":{label:"Sonnet 4.6",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#3b82f6"},"claude-sonnet-4-5-20250929":{label:"Sonnet 4.5",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#60a5fa"},"claude-haiku-4-5-20251001":{label:"Haiku 4.5",input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}},h={label:"",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#94a3b8"};function f(e){if(x[e])return x[e];let t=e.toLowerCase();return t.includes("opus")?{...h,input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"}:t.includes("haiku")?{...h,input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}:h}function p(e){let t=x[e];return t?t.label:e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function g(e){return(x[e]??f(e)).color}function b(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function v(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function j({data:e,height:t=200,formatValue:r=b}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),[l,i]=(0,s.useState)(null),c=(0,s.useRef)([]),d=(0,s.useCallback)(()=>{let n=o.current,s=a.current;if(!n||!s)return;let l=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*l,n.height=t*l,n.style.width=`${i}px`,n.style.height=`${t}px`;let d=n.getContext("2d");d.scale(l,l),d.clearRect(0,0,i,t);let{labels:u,datasets:m}=e;if(0===u.length)return;let x=i-50-12,h=t-8-28,f=function(e){if(e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),r=e/t;return r<=1?t:r<=2?2*t:r<=5?5*t:10*t}(Math.max(1,...u.map((e,t)=>m.reduce((e,r)=>e+r.data[t],0))));d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="10px ui-monospace, monospace",d.textAlign="right",d.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;d.fillText(r(t),44,s),d.strokeStyle=(p="--border",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),d.lineWidth=.5,d.beginPath(),d.moveTo(50,s),d.lineTo(50+x,s),d.stroke()}let g=x/u.length,b=Math.max(4,Math.min(.6*g,32)),v=[];u.forEach((e,t)=>{let r=50+t*g+(g-b)/2,s=0;m.forEach(n=>{var o,a,l,i,c,u;let m=n.data[t];if(m<=0)return;let x=m/f*h,p=8+h-s-x;d.fillStyle=n.color,o=d,a=r,l=p,i=b,u=2,(c=x)<1||(u=Math.min(u,c/2,i/2),o.beginPath(),o.moveTo(a+u,l),o.lineTo(a+i-u,l),o.quadraticCurveTo(a+i,l,a+i,l+u),o.lineTo(a+i,l+c-u),o.quadraticCurveTo(a+i,l+c,a+i-u,l+c),o.lineTo(a+u,l+c),o.quadraticCurveTo(a,l+c,a,l+c-u),o.lineTo(a,l+u),o.quadraticCurveTo(a,l,a+u,l),o.fill()),v.push({x:r,y:p,w:b,h:x,label:e,value:m,dataset:n.label,color:n.color}),s+=x}),d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="9px ui-monospace, monospace",d.textAlign="center",d.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&d.fillText(e,r+b/2,8+h+6)}),c.current=v},[e,t,r]);(0,s.useEffect)(()=>{d();let e=new ResizeObserver(()=>d());return a.current&&e.observe(a.current),()=>e.disconnect()},[d]);let u=(0,s.useCallback)(e=>{let t=o.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,s=e.clientY-t.top,a=c.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);a?i({x:e.clientX-t.left,y:a.y-4,content:`${a.dataset}: ${r(a.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:a,className:"relative w-full text-muted-foreground",children:[(0,n.jsx)("canvas",{ref:o,className:"w-full",style:{height:t},onMouseMove:u,onMouseLeave:()=>i(null)}),l&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lg border border-border whitespace-nowrap z-10",style:{left:l.x,top:l.y,transform:"translate(-50%, -100%)"},children:l.content})]})}function w({hourCounts:e}){let{t}=(0,o.Bd)(),r=Math.max(1,...Object.values(e)),s=Array.from({length:24},(e,t)=>t);return(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:t("tokenStats.activeHours")}),(0,n.jsx)("div",{className:"flex gap-[2px] items-end h-16",children:s.map(s=>{let o=e[String(s)]||0,a=o/r;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:s,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*a)}px`,backgroundColor:a>0?`rgba(59, 130, 246, ${.2+.8*a})`:"var(--muted)"}}),s%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:s})]},s)})})]})}function k({isOpen:e,onClose:t}){var r;let a,l,{t:i}=(0,o.Bd)(),[c,x]=(0,s.useState)(null),[h,N]=(0,s.useState)(!0),[C,S]=(0,s.useState)("day"),[L,M]=(0,s.useState)("tokens"),[E,P]=(0,s.useState)("claude");(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>N(!0)),d.t4.runPromiseExit((0,m.Cr)(E)).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>x(t))}queueMicrotask(()=>N(!1))}))},[e,E]);let T=(0,s.useMemo)(()=>c?.modelUsage?Object.entries(c.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:p(e),color:g(e),usage:t,cost:(r=f(e),t.inputTokens/1e6*r.input+t.outputTokens/1e6*r.output+t.cacheReadInputTokens/1e6*r.cacheRead+t.cacheCreationInputTokens/1e6*r.cacheWrite),totalTokens:t.inputTokens+t.outputTokens+t.cacheReadInputTokens+t.cacheCreationInputTokens}}).sort((e,t)=>t.cost-e.cost):[],[c]),$=(0,s.useMemo)(()=>T.reduce((e,t)=>e+t.cost,0),[T]),R=(0,s.useMemo)(()=>T.map(e=>e.id),[T]),B=(0,s.useMemo)(()=>{let e={};for(let t of T)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[T]),{activityChart:F,tokenChart:I,costChart:D}=(0,s.useMemo)(()=>{let e=c?.dailyActivity||[],t=c?.dailyModelTokens||[];if("day"===C){let r=e.slice(-60),n=t.slice(-60),s={labels:r.map(e=>e.date.slice(5)),datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messageCount),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:"#22c55e"}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:R.map(e=>({label:p(e),data:n.map(t=>t.tokensByModel[e]||0),color:g(e)}))},costChart:{labels:o,datasets:R.map(e=>({label:p(e),data:n.map(t=>(t.tokensByModel[e]||0)*(B[e]||0)),color:g(e)}))}}}if("week"===C){let r=function(e,t){let r=new Map;for(let t of e){let e=new Date(t.date),n=new Date(e);n.setDate(e.getDate()-e.getDay());let s=n.toISOString().slice(0,10),o=s.slice(5);r.has(s)||r.set(s,{label:o,messages:0,sessions:0,tools:0,tokensByModel:{}});let a=r.get(s);a.messages+=t.messageCount,a.sessions+=t.sessionCount,a.tools+=t.toolCallCount}for(let e of t){let t=new Date(e.date),n=new Date(t);n.setDate(t.getDate()-t.getDay());let s=n.toISOString().slice(0,10);r.has(s)||r.set(s,{label:s.slice(5),messages:0,sessions:0,tools:0,tokensByModel:{}});let o=r.get(s);for(let[t,r]of Object.entries(e.tokensByModel))o.tokensByModel[t]=(o.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:R.map(e=>({label:p(e),data:r.map(t=>t.tokensByModel[e]||0),color:g(e)}))},costChart:{labels:n,datasets:R.map(e=>({label:p(e),data:r.map(t=>(t.tokensByModel[e]||0)*(B[e]||0)),color:g(e)}))}}}let r=function(e,t){let r=new Map;for(let t of e){let e=t.date.slice(0,7);r.has(e)||r.set(e,{label:e,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(e);n.messages+=t.messageCount,n.sessions+=t.sessionCount,n.tools+=t.toolCallCount}for(let e of t){let t=e.date.slice(0,7);r.has(t)||r.set(t,{label:t,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(t);for(let[t,r]of Object.entries(e.tokensByModel))n.tokensByModel[t]=(n.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:R.map(e=>({label:p(e),data:r.map(t=>t.tokensByModel[e]||0),color:g(e)}))},costChart:{labels:n,datasets:R.map(e=>({label:p(e),data:r.map(t=>(t.tokensByModel[e]||0)*(B[e]||0)),color:g(e)}))}}},[c,C,R,B,i]);if((0,u.E)(t,e),!e)return null;let A=[{key:"day",label:i("tokenStats.day")},{key:"week",label:i("tokenStats.week")},{key:"month",label:i("tokenStats.month")}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-xl w-full max-w-4xl mx-4 max-h-[90vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("tokenStats.title")}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:["claude","claude2"].map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${E===e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{x(null),P(e)},children:"claude"===e?"Claude":"Claude 2"},e))}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:A.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${C===e.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>S(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:h?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(y,{label:i("tokenStats.totalSessions"),value:String(c.totalSessions??0)}),(0,n.jsx)(y,{label:i("tokenStats.totalMessages"),value:b(c.totalMessages??0)}),(0,n.jsx)(y,{label:i("tokenStats.equivalentApiCost"),value:v($),highlight:!0}),(0,n.jsx)(y,{label:i("tokenStats.longestSession"),value:c.longestSession?(a=Math.floor((r=c.longestSession.duration)/36e5),l=Math.floor(r%36e5/6e4),a>0?`${a}h ${l}m`:`${l}m`):"-"}),(0,n.jsx)(y,{label:i("tokenStats.firstUse"),value:c.firstSessionDate?c.firstSessionDate.slice(0,10):"-"})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.activityTrend")}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-[10px]",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#3b82f6"}}),i("tokenStats.messages")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:"#22c55e"}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(j,{data:F,height:180})})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.byModel")}),(0,n.jsxs)("div",{className:"flex bg-muted rounded-md p-0.5",children:[(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"tokens"===L?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>M("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===L?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>M("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:T.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:e.color}}),e.label]},e.id))})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(j,{data:"tokens"===L?I:D,height:180,formatValue:"tokens"===L?b:v})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("tokenStats.modelCostDetail")}),(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"bg-muted/50 text-muted-foreground",children:[(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium",children:i("tokenStats.model")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Input"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Output"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Read"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Write"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.share")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.equivalentCost")})]})}),(0,n.jsxs)("tbody",{children:[T.map(e=>(0,n.jsxs)("tr",{className:"border-t border-border",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.label]})}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:$>0?`${(e.cost/$*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:v(e.cost)})]},e.id)),(0,n.jsxs)("tr",{className:"border-t-2 border-border bg-muted/30",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-medium text-foreground",children:i("tokenStats.total")}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(T.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(T.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(T.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:b(T.reduce((e,t)=>e+t.usage.cacheCreationInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:"100%"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-bold text-foreground",children:v($)})]})]})]})})]}),c.hourCounts&&Object.keys(c.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(w,{hourCounts:c.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function y({label:e,value:t,highlight:r}){return(0,n.jsxs)("div",{className:"bg-muted/30 rounded-lg px-3 py-2.5",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground",children:e}),(0,n.jsx)("div",{className:`text-sm font-semibold mt-0.5 ${r?"text-brand":"text-foreground"}`,children:t})]})}var N=r(60865),C=r(34075),S=r(5135),L=r(38408),M=r(49433),E=r(82680);let P=(e,t)=>M.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok){let e;try{e=(await r.json()).error}catch{}throw Error(e||`HTTP ${r.status}`)}return await r.json()},catch:r=>new E.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})});function T({skillId:e,onClose:t}){let[r,o]=(0,s.useState)(null),[a,l]=(0,s.useState)(!0),[i,c]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return l(!0),d.t4.runPromiseExit(P(`/api/skills/content?id=${encodeURIComponent(e)}`)).then(e=>{t||("Success"===e._tag?o(e.value):console.error("Failed to load skill content",e.cause),l(!1))}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),(0,u.k)(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let m=(0,s.useCallback)(async()=>{if(r?.path)try{await navigator.clipboard.writeText(r.path),(0,C.oR)("Path copied","success")}catch{(0,C.oR)("Failed to copy","error")}},[r]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-[70%] h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:r?.name?`/${r.name}`:"Skill Preview"}),(0,n.jsx)("button",{onClick:m,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),r?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:r.path})]}),(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>c("preview"),className:`px-3 py-1 transition-colors ${"preview"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Preview"}),(0,n.jsx)("button",{onClick:()=>c("source"),className:`px-3 py-1 transition-colors ${"source"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Source"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors flex-shrink-0",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),a?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"Loading..."}):r&&r.valid?"preview"===i?(0,n.jsx)(S.M,{content:r.content,filePath:r.path,cwd:r.path.slice(0,Math.max(0,r.path.lastIndexOf("/"))),embedded:!0,onClose:t}):(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsx)(L.XO,{content:r.content,filePath:r.path,className:"min-h-full"})}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"File cannot be read."})]})]})}var $=r(88371);function R({isOpen:e,onClose:t}){let[r,o]=(0,s.useState)([]),[a,l]=(0,s.useState)(!1),[i,c]=(0,s.useState)(""),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(null),j=(0,s.useCallback)(async()=>{l(!0);let e=await d.t4.runPromiseExit(P("/api/skills"));"Success"===e._tag?o(e.value):console.error("Failed to load skills",e.cause),l(!1)},[]);(0,s.useEffect)(()=>{e&&(j(),setTimeout(()=>{v.current?.focus(),v.current?.select()},100))},[e,j]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!g){if(u){m(!1),h("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,u,g]);let w=(0,s.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):r},[r,i]),k=(0,s.useCallback)(async()=>{let e=x.trim();if(!e)return;p(!0);let t=await d.t4.runPromiseExit(P("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}));if("Success"===t._tag)(0,C.oR)("Skill added","success"),h(""),m(!1),await j(),(0,$.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:"Failed to add skill";(0,C.oR)(n,"error")}p(!1)},[x,j]),y=(0,s.useCallback)(async e=>{"Success"===(await d.t4.runPromiseExit(P(`/api/skills/${encodeURIComponent(e)}`,{method:"DELETE"})))._tag?(o(t=>t.filter(t=>t.id!==e)),(0,$.k)()):(0,C.oR)("Failed to delete","error")},[]),N=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,C.oR)("Path copied","success")}catch{(0,C.oR)("Failed to copy","error")}},[]);return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-7xl h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:"Skills"}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:v,type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Search skills...",className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),i&&(0,n.jsx)("button",{onClick:()=>{c(""),v.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:"Clear",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("button",{onClick:()=>m(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:"Add Skill",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Add Skill"]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",title:"Close",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:a?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:"Loading..."}):0===w.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:0===r.length?'No skills yet. Click "Add Skill" to add one.':"No skills match your search."}):(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:w.map(e=>(0,n.jsx)(B,{skill:e,onPreview:()=>b(e.id),onDelete:()=>y(e.id),onCopyPath:()=>N(e.path)},e.id))})})]})]}),u&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:()=>{f||(m(!1),h(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:"Add Skill"}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:"Absolute path to SKILL.md"}),(0,n.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"!==e.key||f||k()},placeholder:"/Users/you/.../skills/foo/SKILL.md",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{m(!1),h("")},disabled:f,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",children:"Cancel"}),(0,n.jsx)("button",{onClick:k,disabled:f||!x.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:f?"Adding...":"Add"})]})]})]}),g&&(0,n.jsx)(T,{skillId:g,onClose:()=>b(null)})]}):null}function B({skill:e,onPreview:t,onDelete:r,onCopyPath:o}){let[a,l]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`group flex flex-col h-full border border-border rounded-lg p-3 bg-secondary hover:border-brand hover:shadow-md transition-all ${e.valid?"":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,n.jsx)("div",{className:"w-9 h-9 flex-shrink-0 flex items-center justify-center rounded-md bg-brand/10 text-brand text-lg",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})})}),(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground truncate flex-1 min-w-0",title:`/${e.name}`,children:["/",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"flex-shrink-0 text-xs px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:"Invalid"}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Preview",children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})}),a?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{l(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:"Confirm"}),(0,n.jsx)("button",{onClick:()=>l(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:"Cancel"})]}):(0,n.jsx)("button",{onClick:()=>l(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:"Delete",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M1 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})]})]}),(0,n.jsxs)("div",{className:"font-mono text-xs text-muted-foreground mt-2 break-all",children:[e.path,(0,n.jsx)("button",{onClick:o,className:"inline-flex align-middle ml-1 p-0.5 hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mt-2 pt-2 border-t border-border/60 break-words whitespace-pre-wrap",children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:"No description"})}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-1 truncate",title:e.argumentHint,children:e.argumentHint})]})}var F=r(47650);let I=[],D=[];function A(){D.forEach(e=>e())}function z(e){I=I.filter(t=>t.id!==e),A()}function W({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return D.push(t),()=>{D=D.filter(e=>e!==t)}},[]),I}();return 0===t.length?null:(0,F.createPortal)((0,n.jsx)("div",{className:"fixed bottom-4 left-4 z-[100] flex flex-col gap-2 pointer-events-none",children:t.map(t=>(0,n.jsx)(_,{item:t,onNavigate:e,onRemove:z},t.id))}),document.body)}function _({item:e,onNavigate:t,onRemove:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),c=(0,s.useRef)(void 0),d=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(c.current=setTimeout(d,5e3),()=>clearTimeout(c.current)),[d]);let u=(0,s.useCallback)(()=>{clearTimeout(c.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),m=(0,s.useCallback)(()=>{clearTimeout(c.current)},[]),x=(0,s.useCallback)(()=>{c.current=setTimeout(d,2e3)},[d]);return(0,n.jsxs)("div",{className:`pointer-events-auto bg-card border border-border rounded-lg shadow-lg px-3 py-2.5 min-w-[260px] max-w-[340px] cursor-pointer hover:bg-accent transition-all ${l?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:l?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:m,onMouseLeave:x,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-green-9 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:e.projectName}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:a("common.done")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"ml-auto p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.message&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-1 ml-6",children:e.message})]})}var H=r(77725);let O=M.tryPromise({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new E.uV({message:"fetch /api/projects failed",cause:e})});function q({initialCwd:e,initialSessionId:t}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)(0),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,P]=(0,s.useState)(null),[T,$]=(0,s.useState)(!1),[B,F]=(0,s.useState)(!1),[D,z]=(0,s.useState)(new Set),_=(0,s.useRef)(new Map),V=(0,s.useRef)(new Map),U=(0,s.useRef)(new Map),K=(0,s.useRef)(null),J=(0,H.Z)(O,[]);(0,s.useEffect)(()=>{if("success"===J.status){let e=J.data;m([...e.projects||[]]),h(e.activeIndex||0),p(e.collapsed||!1),F(!0)}else"error"===J.status&&(console.error("Failed to load projects:",J.error),F(!0))},[J]);let Q=(0,s.useCallback)(async(e,t,n)=>{let s,{Effect:o}=await r.e(9012).then(r.bind(r,49012)),{BrowserRuntime:a}=await r.e(7562).then(r.bind(r,47562)),l=await a.runPromise((s={projects:e,activeIndex:t,collapsed:n},M.tryPromise({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(s)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new E.uV({message:"save /api/projects failed",cause:e})})).pipe(o.either));"Left"===l._tag&&console.error("Failed to save projects:",l.left)},[]);(0,s.useEffect)(()=>{let e=u[x]?.cwd;e&&z(t=>t.has(e)?t:new Set(t).add(e))},[x,u]),(0,s.useEffect)(()=>{for(let[e,t]of _.current.entries()){let r=u[x]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r},"*")}},[x,u]);let Z=(0,s.useCallback)((e,t)=>{let r=new URL(window.location.href);r.searchParams.set("cwd",e),t?r.searchParams.set("sessionId",t):r.searchParams.delete("sessionId"),window.history.replaceState({},"",r.toString());let n=e.split("/").filter(Boolean).pop();document.title=n?`Cockpit - ${n}`:"Cockpit"},[]),Y=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!B||Y.current||!e)return;Y.current=!0,t&&(V.current.set(e,{sessionId:t}),U.current.set(e,t));let r=u.findIndex(t=>t.cwd===e);if(r>=0)r!==x&&(h(r),Q(u,r,f));else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),Q(t,r,f)}Z(e,t)},[B,e,t,u,x,f,Q,Z]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r}=e.data;U.current.set(t,r);let n=u[x];n?.cwd===t&&Z(t,r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:r,sessionId:n,lastUserMessage:s}=e.data,o=u[x];if(o?.cwd!==r){var t;let e;t={projectName:r.split("/").pop()||r,message:s,cwd:r,sessionId:n},e=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,I=[...I,{...t,id:e}],A()}}if(e.data?.type==="OPEN_TOKEN_STATS"&&y(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&(P(e.data.cwd),S(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){K.current=x;let t=e.data.cwd,r=u.findIndex(e=>e.cwd===t);r>=0&&r!==x&&h(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==K.current&&K.current!==x&&h(K.current),K.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r}=e.data,n=r||"";U.current.set(t,n);let s=u.findIndex(e=>e.cwd===t);if(s>=0){if(n){let e=_.current.get(t);e?.contentWindow&&e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:n},"*")}s!==x&&(h(s),Q(u,s,f))}else{let e=[...u,{cwd:t}],r=e.length-1;m(e),h(r),Q(e,r,f),n&&V.current.set(t,{sessionId:n})}Z(t,n)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[u,x,f,Z,Q]),(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&!e.altKey){if(!e.shiftKey&&("p"===e.key||"f"===e.key||"s"===e.key))return void e.preventDefault();e.ctrlKey&&!e.metaKey&&"Minus"===e.code&&e.preventDefault()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let G=(0,s.useCallback)(e=>{h(e),Q(u,e,f);let t=u[e];if(t?.cwd){let e=U.current.get(t.cwd);Z(t.cwd,e)}},[u,f,Q,Z]),X=(0,s.useCallback)(e=>{let t=u.filter((t,r)=>r!==e),r=x;e<x?r=x-1:e===x&&r>=t.length&&(r=Math.max(0,t.length-1)),m(t),h(r),Q(t,r,f)},[u,x,f,Q]),ee=(0,s.useCallback)(e=>{let t=u[x],r=e.findIndex(e=>e.cwd===t?.cwd);m(e),h(r>=0?r:0),Q(e,r>=0?r:0,f)},[u,x,f,Q]),et=(0,s.useCallback)(()=>{let e=!f;p(e),Q(u,x,e)},[u,x,f,Q]),er=(0,s.useCallback)((e,t)=>{U.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=_.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),h(r),Q(u,r,f)}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),Q(r,n,f),V.current.set(e,{sessionId:t,switchToAgent:!0})}Z(e,t),b(!1)},[u,f,Q,Z]),en=(0,s.useCallback)((e,t)=>{U.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=_.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),r!==x&&(h(r),Q(u,r,f))}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),Q(r,n,f),V.current.set(e,{sessionId:t,switchToAgent:!0})}Z(e,t)},[u,x,f,Q,Z]);return B?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(a.ProjectSidebar,{projects:u,activeIndex:x,collapsed:f,currentCwd:u[x]?.cwd,onSelectProject:G,onRemoveProject:X,onReorderProjects:ee,onToggleCollapse:et,onOpenSessionBrowser:()=>b(!0),onOpenSettings:()=>j(!0),onOpenNote:e=>{P(e??null),S(!0)},onOpenSkills:()=>$(!0),onSwitchProject:en,onAddProject:e=>{let t=u.findIndex(t=>t.cwd===e);if(t>=0)h(t),Q(u,t,f);else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),Q(t,r,f)}}}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===u.length?(0,n.jsx)(l.EmptyState,{onSelectSession:er}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:u.map((e,t)=>{let r,s;return D.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?_.current.set(e.cwd,t):_.current.delete(e.cwd)},src:(r=`/project?cwd=${encodeURIComponent(e.cwd)}`,s=V.current.get(e.cwd),s?.sessionId&&(r+=`&sessionId=${encodeURIComponent(s.sessionId)}`,s.switchToAgent&&(r+="&view=agent")),r),className:`absolute inset-0 w-full h-full border-0 ${t===x?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd)})})}),(0,n.jsx)(i.SessionBrowser,{isOpen:g,onClose:()=>b(!1),onSelectSession:er,onAddProject:e=>{let t=u.findIndex(t=>t.cwd===e);if(t>=0)h(t),Q(u,t,f);else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),Q(t,r,f)}b(!1)}}),(0,n.jsx)(c.SettingsModal,{isOpen:v,onClose:()=>j(!1)}),(0,n.jsx)(k,{isOpen:w,onClose:()=>y(!1)}),(0,n.jsx)(N.NoteModal,{isOpen:C,onClose:()=>{S(!1),P(null)},projectCwd:L,projectName:L?L.split("/").pop():null}),(0,n.jsx)(R,{isOpen:T,onClose:()=>$(!1)}),(0,n.jsx)(W,{onNavigate:en})]}):(0,n.jsx)("div",{className:"h-screen flex items-center justify-center bg-card",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:d("workspace.loadingText")})]})})}},41474:(e,t,r)=>{r.d(t,{F:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)(()=>"u"<typeof document||"visible"===document.visibilityState);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}},42701:(e,t,r)=>{r.d(t,{ProjectSidebar:()=>k});var n=r(95155),s=r(12115),o=r(79114),a=r(2228),l=r(86957),i=r(53213),c=r(83448);function d({isOpen:e,onClose:t,onSwitchProject:r}){let{t:a}=(0,o.Bd)(),[i,u]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useCallback)(async()=>{x(!0),f(null);let e=await l.t4.runPromiseExit((0,c.z2)());"Success"===e._tag?u([...e.value]):f(a("sessions.loadSessionsFailed")),x(!1)},[a]);(0,s.useEffect)(()=>{e&&(v(),setTimeout(()=>{b.current?.focus(),b.current?.select()},100))},[e,v]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let j=i.filter(e=>{if(!p)return!0;let t=p.toLowerCase();return void 0!==e.searchText?e.searchText.includes(t):e.cwd.toLowerCase().includes(t)||(e.title?.toLowerCase().includes(t)??!1)||(e.lastUserMessage?.toLowerCase().includes(t)??!1)||(e.firstMessages?.some(e=>e.toLowerCase().includes(t))??!1)||(e.lastMessages?.some(e=>e.toLowerCase().includes(t))??!1)});return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-7xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:a("sessions.recentSessions")})}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:b,type:"text",placeholder:a("sessions.searchSessions"),value:p,onChange:e=>g(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),p&&(0,n.jsx)("button",{onClick:()=>{g(""),b.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:a("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:a("sessions.loadingSessions")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:h})}),!m&&!h&&0===j.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:p?a("sessions.noMatchingSessions"):a("sessions.noSessions")})}),!m&&!h&&j.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:j.map(e=>{let s;return(0,n.jsxs)("div",{onClick:()=>{r(e.cwd,e.sessionId),t()},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${"loading"===e.status?"bg-orange-9 animate-pulse":"unread"===e.status?"bg-red-500":"bg-muted-foreground/30"}`}),e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate flex-1",title:e.cwd,children:(s=e.cwd).split("/").pop()||s}),"loading"===e.status&&(0,n.jsx)("span",{className:"text-[10px] text-orange-11 flex-shrink-0",children:a("sessions.running")}),"unread"===e.status&&(0,n.jsx)("span",{className:"text-[10px] text-red-500 flex-shrink-0",children:a("sessions.done")})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.lastActive).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(e.firstMessages?.length??0)>0||(e.lastMessages?.length??0)>0?(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[e.firstMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),(e.lastMessages?.length??0)>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]}):e.lastUserMessage||e.title?(0,n.jsxs)("div",{className:"text-xs text-foreground truncate",title:e.lastUserMessage||e.title,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e.lastUserMessage||e.title]}):null]},`${e.cwd}-${e.sessionId}`)})})]})]})]}):null}function u({currentCwd:e,onSwitchProject:t,collapsed:r,sessions:a}){let{t:c}=(0,o.Bd)(),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(0),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)({}),y=(0,s.useCallback)((e,t)=>{let r=t.currentTarget.getBoundingClientRect(),n=r.top;n+260>window.innerHeight&&(n=Math.max(8,window.innerHeight-260-8)),j({session:e,top:n,left:r.right+8}),k(t=>e.cwd in t?t:(l.t4.runPromiseExit((0,i.ue)(e.cwd)).then(t=>{"Success"===t._tag&&k(r=>({...r,[e.cwd]:t.value.branch}))}),{...t,[e.cwd]:null}))},[]),N=(0,s.useCallback)(()=>j(null),[]);(0,s.useEffect)(()=>{m||j(null)},[m]),(0,s.useEffect)(()=>{if(!m)return;let e=e=>{b.current&&!b.current.contains(e.target)&&x(!1)},t=()=>{x(!1)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[m]);let C=(0,s.useCallback)(e=>{t(e.cwd,e.sessionId),x(!1),j(null)},[t]),S=a.filter(e=>"loading"===e.status).length,L=a.filter(e=>"unread"===e.status).length,M=(0,s.useCallback)(e=>{let t=Math.floor((p-e)/6e4);if(t<1)return c("common.justNow");if(t<60)return c("common.minutesAgo",{count:t});let r=Math.floor(t/60);return r<24?c("common.hoursAgo",{count:r}):c("common.daysAgo",{count:Math.floor(r/24)})},[c,p]),E=e=>e.split("/").pop()||e;return(0,n.jsxs)("div",{className:"relative",ref:b,children:[(0,n.jsxs)("button",{onClick:()=>{g(Date.now()),x(!m)},className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"w-full justify-center":"w-full"}`,title:c("sessions.recentSessions"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),!r&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:c("sessions.recentSessions")}),S>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-orange-9 animate-pulse ${r?"absolute -top-1 -right-1":""}`,children:S}),L>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${r&&!S?"absolute -top-1 -right-1":""}`,children:L})]}),m&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:c("sessions.recentSessions")}),S>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-orange-11",children:["(",c("sessions.runningCount",{count:S}),")"]}),L>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-red-500",children:["(",c("sessions.unreadCount",{count:L}),")"]}),(0,n.jsx)("button",{onClick:()=>{g(Date.now()),x(!1),j(null),f(!0)},className:"ml-auto p-1 -mr-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:c("sessions.searchRecentSessions"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15"})})})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:c("sessions.noSessions")}):a.map((t,r)=>(0,n.jsxs)("button",{onClick:()=>C(t),onMouseEnter:e=>y(t,e),onMouseLeave:N,className:`w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 ${r!==a.length-1?"border-b border-border/50":""} ${e===t.cwd?"bg-accent/50":""}`,children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${"loading"===t.status?"bg-orange-9 animate-pulse":"unread"===t.status?"bg-red-500":"bg-muted-foreground/30"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:E(t.cwd)}),"loading"===t.status&&(0,n.jsx)("span",{className:"text-xs text-orange-11 flex-shrink-0",children:c("sessions.running")}),"unread"===t.status&&(0,n.jsx)("span",{className:"text-xs text-red-500 flex-shrink-0",children:c("sessions.done")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:M(t.lastActive)})]}),(t.lastUserMessage||t.title)&&(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:t.lastUserMessage||t.title})]})]},`${t.cwd}-${t.sessionId}`))})]}),v&&(0,n.jsxs)("div",{className:"fixed z-[60] w-72 max-h-[260px] overflow-y-auto bg-popover border border-border rounded-lg shadow-lg p-3 pointer-events-none",style:{top:v.top,left:v.left},children:[(0,n.jsx)("div",{className:"text-xs font-medium text-foreground truncate",children:E(v.session.cwd)}),w[v.session.cwd]&&(0,n.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-normal min-w-0",children:[(0,n.jsxs)("svg",{className:"w-3 h-3 flex-shrink-0 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2.5"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2.5"}),(0,n.jsx)("circle",{cx:"18",cy:"7",r:"2.5"}),(0,n.jsx)("path",{strokeLinecap:"round",d:"M6 8.5v7M8.5 6.5h4.5a3 3 0 013 3v0"})]}),(0,n.jsx)("span",{className:"truncate",children:w[v.session.cwd]})]}),(v.session.firstMessages?.length??0)>0||(v.session.lastMessages?.length??0)>0?(0,n.jsxs)("div",{className:"space-y-0.5 text-xs border-t border-border/50 mt-2 pt-2",children:[v.session.firstMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground/90 truncate",children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`f-${t}`)),(v.session.lastMessages?.length??0)>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),v.session.lastMessages?.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground/90 truncate",children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`l-${t}`))]}):v.session.lastUserMessage||v.session.title?(0,n.jsx)("div",{className:"text-xs text-foreground/90 border-t border-border/50 mt-2 pt-2 line-clamp-3 break-words",children:v.session.lastUserMessage||v.session.title}):null]}),(0,n.jsx)(d,{isOpen:h,onClose:()=>f(!1),onSwitchProject:t})]})}function m({collapsed:e,pinnedSessions:t,onSwitchProject:r,onUnpin:a,onUpdateTitle:l,onReorder:i}){let{t:c}=(0,o.Bd)(),[d,u]=(0,s.useState)(!1),x=(0,s.useRef)(null),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{x.current&&!x.current.contains(e.target)&&(u(!1),f(null))},t=()=>{u(!1),f(null)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[d]),(0,s.useEffect)(()=>{h&&(b.current?.focus(),b.current?.select())},[h]);let y=(0,s.useCallback)(e=>{h||(r(e.cwd,e.sessionId),u(!1))},[r,h]),N=(0,s.useCallback)((e,t)=>{t.stopPropagation(),f(e.sessionId),g(e.customTitle||"")},[]),C=(0,s.useCallback)(()=>{h&&p.trim()&&l(h,p.trim()),f(null)},[h,p,l]),S=(0,s.useCallback)(e=>{j(e)},[]),L=(0,s.useCallback)((e,t)=>{e.preventDefault(),k(t)},[]),M=(0,s.useCallback)(e=>{if(null===v||v===e){j(null),k(null);return}let r=[...t],[n]=r.splice(v,1);r.splice(e,0,n),i(r),j(null),k(null)},[v,t,i]),E=(0,s.useCallback)(()=>{j(null),k(null)},[]);return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>u(!d),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:c("sessions.pinnedSessions"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:c("sessions.pinnedSessions")}),e&&t.length>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-accent",children:t.length})]}),d&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 max-h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:c("sessions.pinnedSessions")})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:c("sessions.noPinnedSessions")}):t.map((e,r)=>{let s;return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>S(r),onDragOver:e=>L(e,r),onDrop:()=>M(r),onDragEnd:E,onClick:()=>y(e),className:`group w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 cursor-pointer ${r!==t.length-1?"border-b border-border/50":""} ${v===r?"opacity-50":""} ${w===r?"border-t-2 border-brand":""}`,children:[(0,n.jsx)("span",{className:"mt-1.5 text-muted-foreground/30 flex-shrink-0 cursor-grab",children:(0,n.jsxs)("svg",{className:"w-3 h-3",viewBox:"0 0 10 16",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"3",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"14",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"14",r:"1.5"})]})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",title:e.cwd,children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:(s=e.cwd).split("/").pop()||s})}),h===e.sessionId?(0,n.jsx)("input",{ref:b,type:"text",value:p,onChange:e=>g(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||("Enter"===e.key&&C(),"Escape"===e.key&&f(null))},onBlur:C,onClick:e=>e.stopPropagation(),className:"w-full text-xs px-1 py-0.5 border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring mt-0.5"}):(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:e.customTitle||e.sessionId.slice(0,8)})]}),h!==e.sessionId&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity mt-0.5",children:[(0,n.jsx)("button",{onClick:t=>N(e,t),className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:c("sessions.editTitle"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),a(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:c("sessions.remove"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},e.sessionId)})})]})]})}var x=r(93777);function h(e,t){if("once"===e.type)return t("scheduledTasks.onceType",{minutes:e.delayMinutes});if("interval"===e.type){let r=t("scheduledTasks.everyNMinutes",{minutes:e.intervalMinutes});return e.activeFrom&&e.activeTo?`${r} (${e.activeFrom}-${e.activeTo})`:r}return"cron"===e.type?e.cron||"cron":e.type}function f(e){return e.unread?"bg-red-500":e.completed?"bg-muted-foreground":e.paused?"bg-yellow-500":"error"===e.lastResult?"bg-red-500":"bg-green-500"}function p({collapsed:e,tasks:t,unreadCount:r,onSwitchProject:a,onPause:l,onResume:i,onTrigger:c,onDelete:d,onMarkRead:u,onUpdateTask:m,onReorder:g}){let{t:b}=(0,o.Bd)(),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),y=(0,s.useRef)(null),N=t.filter(e=>!e.completed),C=N.filter(e=>!e.paused).length,S=t.filter(e=>e.completed),[L,M]=(0,s.useState)(null),[E,P]=(0,s.useState)(null),T=(0,s.useCallback)(e=>{M(e)},[]),$=(0,s.useCallback)((e,t)=>{e.preventDefault(),P(t)},[]),R=(0,s.useCallback)(e=>{if(null===L||L===e){M(null),P(null);return}let t=[...N],[r]=t.splice(L,1);t.splice(e,0,r),g([...t,...S].map(e=>e.id)),M(null),P(null)},[L,N,S,g]),B=(0,s.useCallback)(()=>{M(null),P(null)},[]),[,F]=(0,s.useState)(0);return(0,s.useEffect)(()=>{if(!v)return;let e=setInterval(()=>F(e=>e+1),1e4);return()=>clearInterval(e)},[v]),(0,s.useEffect)(()=>{if(!v)return;let e=e=>{y.current&&!y.current.contains(e.target)&&j(!1)},t=()=>j(!1);return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[v]),(0,n.jsxs)("div",{className:"relative",ref:y,children:[(0,n.jsxs)("button",{onClick:()=>j(!v),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:b("scheduledTasks.title"),children:[(0,n.jsxs)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:b("scheduledTasks.title")}),r>0?(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${e?"absolute -top-1 -right-1":""}`,children:r}):e&&t.length>0?(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-accent",children:t.length}):null]}),v&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-96 max-h-[500px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:b("scheduledTasks.title")}),N.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[b("scheduledTasks.activeCount",{running:C}),N.length-C>0?` \xb7 ${b("scheduledTasks.pausedCount",{paused:N.length-C})}`:""]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:b("scheduledTasks.noScheduledTasks")}):(0,n.jsxs)(n.Fragment,{children:[N.map((e,t)=>{var r;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>T(t),onDragOver:e=>$(e,t),onDrop:()=>R(t),onDragEnd:B,className:`group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 cursor-pointer ${e.unread?"bg-brand/5":""} ${L===t?"opacity-50":""} ${E===t?"border-t-2 border-brand":""}`,onClick:()=>{a(e.cwd,e.sessionId),e.unread&&u(e.id),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${f(e)}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground font-mono",children:(r=e.cwd).split("/").pop()||r}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"\xb7"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:e.completed?b("scheduledTasks.completed"):e.paused?b("scheduledTasks.paused"):b("common.running")})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5",title:e.message,children:e.message}),(0,n.jsxs)("div",{className:"flex items-center gap-3 mt-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{children:h(e,b)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{children:e.paused?b("scheduledTasks.paused"):function(e,t){if(!e)return"-";let r=e-Date.now();if(r<=0)return t("scheduledTasks.aboutToTrigger");if(r<6e4)return t("scheduledTasks.secondsLater",{count:Math.ceil(r/1e3)});if(r<36e5)return t("scheduledTasks.minutesLater",{count:Math.ceil(r/6e4)});if(r<864e5){let e=Math.floor(r/36e5),n=Math.ceil(r%36e5/6e4);return n>0?t("scheduledTasks.hoursMinutesLater",{h:e,m:n}):t("scheduledTasks.hoursLater",{h:e})}return new Date(e).toLocaleDateString("zh-CN",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(e.nextFireTime,b)}),e.lastFiredAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsxs)("span",{children:[b("scheduledTasks.lastResult"),": ","success"===e.lastResult?"✓":"✗"]})]})]})]}),(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),c(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-brand",title:b("scheduledTasks.runNow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{d:"M8 5v14l11-7z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),k(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:b("common.edit"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-500",title:b("scheduledTasks.resume"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"})})}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),l(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-yellow-500",title:b("scheduledTasks.pause"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 9v6m4-6v6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]})},e.id)}),S.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-muted/30 border-b border-border/50",children:b("scheduledTasks.completedCount",{count:S.length})}),S.map(e=>(0,n.jsx)("div",{className:"group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 opacity-60 cursor-pointer",onClick:()=>{a(e.cwd,e.sessionId),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${f(e)}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:e.message}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground mt-0.5",children:[h(e,b)," \xb7 ","success"===e.lastResult?b("scheduledTasks.success"):b("scheduledTasks.failure")]})]}),(0,n.jsx)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]})},e.id))]})]})})]}),w&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/30",onClick:()=>k(null)}),(0,n.jsx)("div",{className:"relative",children:(0,n.jsx)(x.E,{onClose:()=>k(null),onCreate:()=>{},editTask:{id:w.id,message:w.message,type:w.type,delayMinutes:w.delayMinutes,intervalMinutes:w.intervalMinutes,activeFrom:w.activeFrom,activeTo:w.activeTo,cron:w.cron},onUpdate:(e,t)=>{m(e,t),k(null)}})})]})]})}var g=r(3292),b=r(23121),v=r(34075),j=r(2111),w=r(76900);function k({projects:e,activeIndex:t,collapsed:r,currentCwd:i,onSelectProject:c,onRemoveProject:d,onReorderProjects:x,onToggleCollapse:h,onOpenSessionBrowser:f,onOpenSettings:y,onOpenNote:N,onOpenSkills:C,onSwitchProject:S,onAddProject:L}){let{t:M,i18n:E}=(0,o.Bd)(),{latest:P,hasUpdate:T}=function(){let[e,t]=(0,s.useState)(),[r,n]=(0,s.useState)();(0,s.useEffect)(()=>{let e=!1;l.t4.runPromiseExit((0,w.Wr)()).then(r=>{!e&&"Success"===r._tag&&r.value.version&&t(r.value.version)});let r=new AbortController,s=setTimeout(()=>r.abort(),3e3);return fetch("https://registry.npmjs.org/@surething/cockpit/latest",{signal:r.signal}).then(e=>e.ok?e.json():null).then(t=>{if(e)return;let r=t?.version;"string"==typeof r&&n(r)}).catch(()=>{}).finally(()=>clearTimeout(s)),()=>{e=!0,r.abort(),clearTimeout(s)}},[]);let o=!!e&&!!r&&function(e,t){let r=e=>e.replace(/^v/,"").split("-")[0].split(".").map(e=>parseInt(e,10)||0),n=r(e),s=r(t),o=Math.max(n.length,s.length);for(let e=0;e<o;e++){let t=n[e]??0,r=s[e]??0;if(t!==r)return t-r}return 0}(r,e)>0;return{current:e,latest:r,hasUpdate:o}}(),[$,R]=(0,s.useState)(!1),B=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!$)return;let e=e=>{B.current?.contains(e.target)||R(!1)},t=()=>R(!1);return document.addEventListener("mousedown",e,!0),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e,!0),window.removeEventListener("blur",t)}},[$]);let F=(0,s.useCallback)(()=>{navigator.clipboard.writeText("cockpit update"),(0,v.oR)(M("workspace.upgradeCommandCopied")),R(!1)},[M]),{pinnedSessions:I,unpinSession:D,updateTitle:A,reorder:z}=(0,g.P)(),{tasks:W,unreadCount:_,reload:H,pauseTask:O,resumeTask:q,triggerTask:V,deleteTask:U,updateTask:K,markRead:J,reorderTasks:Q}=(0,b.n)(),[Z,Y]=(0,s.useState)(null),[G,X]=(0,s.useState)(null),[ee,et]=(0,s.useState)([]),er=(0,s.useRef)(ee);(0,s.useEffect)(()=>{er.current=ee});let en=(0,s.useRef)(H);(0,s.useEffect)(()=>{en.current=H});let es=(0,s.useCallback)(e=>{try{if("task-fired"===e.type)return void en.current();let{data:t}=e;if(!t)return;et(t.sessions||[])}catch{}},[]);(0,j.h)({url:"/ws/global-state",onMessage:es});let eo=new Set(ee.filter(e=>"loading"===e.status).map(e=>e.cwd)),ea=new Set(ee.filter(e=>"unread"===e.status).map(e=>e.cwd)),el=(0,s.useCallback)(e=>{Y(e)},[]),ei=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==Z&&Z!==t&&X(t)},[Z]),ec=(0,s.useCallback)(t=>{if(null!==Z&&Z!==t){let r=[...e],[n]=r.splice(Z,1);r.splice(t,0,n),x(r)}Y(null),X(null)},[Z,e,x]),ed=(0,s.useCallback)(()=>{Y(null),X(null)},[]);return(0,n.jsxs)("div",{className:`h-full bg-card border-r border-border flex flex-col transition-all duration-200 ${r?"w-12":"w-56"}`,children:[(0,n.jsxs)("div",{className:"group p-2 border-b border-border relative",children:[(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:f,title:M("workspace.openProject"),children:[(0,n.jsxs)("svg",{className:"w-5 h-5 flex-shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.openProject")})]}),r?(0,n.jsx)("button",{className:"absolute inset-0 m-2 flex items-center justify-center px-2 py-2 rounded-lg bg-accent text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:h,title:M("workspace.expandSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0 rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}):(0,n.jsx)("button",{className:"absolute top-1/2 -translate-y-1/2 right-2 p-2 rounded-lg bg-accent text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:h,title:M("workspace.collapseSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:e.map((e,s)=>{var o;let l;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>el(s),onDragOver:e=>ei(e,s),onDrop:()=>ec(s),onDragEnd:ed,className:`${G===s?"border-t-2 border-brand":""} ${Z===s?"opacity-50":""}`,children:(0,n.jsx)(a.ProjectItem,{index:s,name:(l=(o=e.cwd).split("/").filter(Boolean))[l.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:ea.has(e.cwd),isLoading:eo.has(e.cwd),onClick:()=>c(s),onRemove:()=>d(s),onOpenNote:()=>N(e.cwd)})},e.cwd)})}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(u,{currentCwd:i,onSwitchProject:S,collapsed:r,sessions:ee}),(0,n.jsx)(m,{collapsed:r,pinnedSessions:I,onSwitchProject:S,onUnpin:D,onUpdateTitle:A,onReorder:z}),(0,n.jsx)(p,{collapsed:r,tasks:W,unreadCount:_,onSwitchProject:S,onPause:O,onResume:q,onTrigger:V,onDelete:U,onMarkRead:J,onUpdateTask:K,onReorder:Q}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:()=>N(),title:M("workspace.notes"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.notes")})]}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:C,title:M("workspace.skills"),children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:M("workspace.skills")})]}),(0,n.jsxs)("div",{className:`relative flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"justify-center":""}`,onClick:y,title:M("workspace.settings"),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),r&&T&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500",title:P?M("workspace.updateAvailable",{version:P}):void 0})]}),!r&&(0,n.jsx)("span",{className:"flex-1 text-sm",children:M("workspace.settings")}),!r&&T&&P&&(0,n.jsxs)("div",{ref:B,className:"relative -mr-2",children:[(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),R(e=>!e)},className:"px-1.5 py-0.5 rounded text-xs font-mono font-medium text-brand hover:bg-brand/10 transition-colors",title:M("workspace.updateAvailable",{version:P}),"aria-label":M("workspace.updateAvailable",{version:P}),children:["v",P]}),$&&(0,n.jsxs)("div",{className:"absolute left-full bottom-full ml-2 mb-1 w-56 rounded-lg border border-border bg-popover shadow-lg p-2 z-50",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2 px-1",children:M("workspace.updateAvailable",{version:P})}),(0,n.jsxs)("button",{type:"button",onClick:F,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left hover:bg-accent transition-colors",children:[(0,n.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]}),(0,n.jsx)("span",{className:"flex-1",children:M("workspace.copyUpgradeCommand")})]}),(0,n.jsxs)("a",{href:`https://opencockpit.dev/${E.language?.startsWith("zh")?"zh":"en"}/changelog/`,target:"_blank",rel:"noopener",onClick:()=>R(!1),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-accent transition-colors",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("span",{className:"flex-1",children:M("workspace.viewChangelog")}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]}),!r&&(0,n.jsx)("a",{href:`https://opencockpit.dev/${E.language?.startsWith("zh")?"zh":"en"}/docs/get-started/quickstart/`,target:"_blank",rel:"noopener",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",onClick:e=>e.stopPropagation(),title:M("workspace.help"),"aria-label":M("workspace.help"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]})})]})]})]})}},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>c});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(86957),i=r(76900);function c({children:e}){return(0,s.useEffect)(()=>{l.t4.runPromiseExit((0,i.M5)()).then(e=>{var t;let r="auto"!==(t=("Success"===e._tag?e.value.language:"auto")||"auto")&&t?t:navigator.language.startsWith("zh")?"zh":"en";a.A.language!==r&&a.A.changeLanguage(r)})},[]),(0,s.useEffect)(()=>{let e=e=>(function(e){for(let t of document.querySelectorAll("iframe"))try{t.contentWindow?.postMessage({type:"cockpit:language-change",lang:e},"*")}catch{}})(e);return a.A.on("languageChanged",e),()=>{a.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&a.A.language!==e.data.lang&&a.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:a.A,children:e})}},53213:(e,t,r)=>{r.d(t,{Bj:()=>c,CM:()=>v,FK:()=>b,Iz:()=>x,MB:()=>j,Ub:()=>f,X0:()=>h,Zi:()=>d,lv:()=>m,oh:()=>g,r4:()=>l,ue:()=>i,w2:()=>p,yy:()=>u});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok){let e;try{e=(await t.json()).error}catch{}throw Error(e||`HTTP ${t.status}`)}return await t.json()},catch:t=>new s.uV({message:`fetch ${e} failed`,cause:t})}),a=(e,t)=>n.tryPromise({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),l=e=>o(`/api/git/branches?cwd=${encodeURIComponent(e)}`).pipe(n.flatMap(t=>"Failed to get branches"===t.error?n.fail(new s.m_({resource:"git-repo",id:e})):n.succeed(t))),i=e=>o(`/api/git/current-branch?cwd=${encodeURIComponent(e)}`),c=(e,t,r,n)=>o(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${r}${"number"==typeof n?`&offset=${n}`:""}`),d=(e,t,r)=>o(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=(e,t,r)=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),m=e=>o(`/api/git/status?cwd=${encodeURIComponent(e)}`),x=(e,t)=>a("/api/git/stage",{cwd:e,files:t}),h=(e,t)=>a("/api/git/unstage",{cwd:e,files:t}),f=(e,t,r)=>a("/api/git/discard",{cwd:e,files:t,isUntracked:r}),p=(e,t,r)=>{let n=new URLSearchParams({cwd:e,file:t,type:r});return o(`/api/git/diff?${n}`)},g=e=>o(`/api/git/diff?${e.toString()}`),b=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),v=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await t.json().catch(()=>null);if(!t.ok)throw Error(r?.error||`HTTP ${t.status}`);return r},catch:e=>new s.uV({message:"POST /api/git/worktree failed",cause:e})}),j=e=>o(`/api/projectGraph/search?${e.toString()}`)},53853:(e,t,r)=>{r.d(t,{G:()=>u,f:()=>m});var n=r(12115);function s(){if("u"<typeof document)return null;let e=document.querySelector('meta[name="cockpit-bridge"]');if(!e)return null;let t=e.dataset.id,r=e.dataset.version;return t?{id:t,version:r||"unknown"}:null}let o=null,a=new Set;function l(){a.forEach(e=>e())}function i(e){a.add(e);let t=s();return t&&!o&&(o=t,Promise.resolve().then(l)),()=>{a.delete(e)}}function c(){return o}function d(){return null}if("u">typeof document&&(o=s()),"u">typeof MutationObserver&&"u">typeof document){let e=new MutationObserver(()=>{let e=s();e&&(!o||e.id!==o.id||e.version!==o.version)&&(o=e,l())}),t=document.head||document.documentElement;t&&e.observe(t,{childList:!0})}function u(){return(0,n.useSyncExternalStore)(i,c,d)}function m(){return o??s()}},60865:(e,t,r)=>{r.d(t,{NoteModal:()=>es});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(13439),i=r(58940),c=r(43561),d=r(5989),u=r(76065),m=r(43203),x=r(6268),h=r(48434),f=r(82159),p=r(44695);let g={todo:"doing",doing:"done",done:"todo"},b={todo:"false",doing:"mixed",done:"true"},v=/^\s*(\[([ x/])?\])\s$/,j=p.L.extend({addAttributes:()=>({status:{default:"todo",keepOnSplit:!1,parseHTML:e=>(function(e){let t=e.getAttribute("data-status");if("todo"===t||"doing"===t||"done"===t)return t;let r=e.getAttribute("data-checked");return""===r||"true"===r?"done":"todo"})(e),renderHTML:e=>({"data-status":e.status,"data-checked":"done"===e.status?"true":"false"})}}),addStorage:()=>({markdown:{serialize(e,t){var r;e.write(`${"done"===(r=t.attrs.status)?"[x]":"doing"===r?"[/]":"[ ]"} `),e.renderContent(t)}}}),addInputRules(){return[(0,f.tG)({find:v,type:this.type,getAttributes:e=>{let t=e[e.length-1];return{status:"x"===t?"done":"/"===t?"doing":"todo"}}})]},renderHTML({HTMLAttributes:e}){return["li",(0,f.KV)(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},addNodeView(){return({node:e,getPos:t,editor:r})=>{let n=document.createElement("li");n.setAttribute("data-type",this.name);let s=document.createElement("label");s.classList.add("task-marker"),s.contentEditable="false";let o=document.createElement("span");o.classList.add("task-marker-box"),o.setAttribute("role","checkbox"),s.appendChild(o);let a=document.createElement("div");n.append(s,a);let l=e=>{let t=e.attrs.status??"todo";n.dataset.status=t,n.dataset.checked="done"===t?"true":"false",o.setAttribute("aria-checked",b[t])};return l(e),s.addEventListener("mousedown",e=>e.preventDefault()),s.addEventListener("click",e=>{if(e.preventDefault(),!r.isEditable||"function"!=typeof t)return;let n=t();"number"==typeof n&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=e.doc.nodeAt(n);if(!t)return!1;let r=t.attrs.status??"todo";return e.setNodeMarkup(n,void 0,{...t.attrs,status:g[r]}),!0}).run()}),{dom:n,contentDOM:a,update:t=>t.type===e.type&&(l(t),!0)}}}});var w=r(59265),k=r(26932),y=r(27050),N=r(52740),C=r(76865),S=r(63197);let L=new C.hs("headingFold");function M(e){let t=e.attrs.foldState;return"folded"===t||"children"===t?t:"expanded"}function E(e){let t=[],r=[];return e.forEach((e,n)=>{let s=n+e.nodeSize;if("heading"===e.type.name){let o=e.attrs.level;for(;r.length&&r[r.length-1].level>=o;)r.pop();let a=M(e),l=r.some(e=>"folded"===e.state),i=["note-heading"];"expanded"!==a&&i.push("is-collapsed"),l&&i.push("note-folded-hidden"),t.push(S.NZ.node(n,s,{class:i.join(" ")})),t.push(S.NZ.widget(n+1,(e,t)=>{let r;return(r=document.createElement("span")).className="note-fold-toggle",r.contentEditable="false",r.setAttribute("data-fold-state",a),r.addEventListener("mousedown",r=>{r.preventDefault(),r.stopPropagation();let n=t();if(null==n)return;let s=n-1,o=e.state.doc.nodeAt(s);o&&"heading"===o.type.name&&e.dispatch(e.state.tr.setNodeMarkup(s,void 0,{...o.attrs,foldState:"expanded"===M(o)?"folded":"expanded"}))}),r},{side:-1,key:`fold-${n}-${a}`})),r.push({level:o,state:a})}else r.some(e=>"folded"===e.state||"children"===e.state)&&t.push(S.NZ.node(n,s,{class:"note-folded-hidden"}))}),S.zF.create(e,t)}let P=N.A.extend({addAttributes(){return{...this.parent?.(),foldState:{default:"expanded",keepOnSplit:!1,parseHTML:e=>"true"===e.getAttribute("data-collapsed")?"folded":"expanded",renderHTML:e=>e.foldState&&"expanded"!==e.foldState?{"data-collapsed":"true"}:{}}}},addKeyboardShortcuts(){let e=this.name;return{Tab:()=>{var t;let r,n,s,{state:o}=this.editor,{$from:a}=o.selection;if(a.parent.type.name!==e)return!1;let l=a.before(a.depth),i=o.doc.nodeAt(l);if(!i||i.type.name!==e)return!1;let c=i.attrs.level,d=(t=o.doc,n=[],s=!1,t.forEach((t,r)=>{if(r===l){s=!0;return}if(s&&t.type.name===e){if(t.attrs.level<=c){s=!1;return}n.push(r)}}),n),u=d.length>0,m=M(i),x=null;return u?"expanded"===m?r="folded":(r="folded"===m?"children":"expanded",x="expanded"):r="expanded"===m?"folded":"expanded",this.editor.chain().command(({tr:t})=>{if(t.setNodeMarkup(l,void 0,{...i.attrs,foldState:r}),x)for(let r of d){let n=t.doc.nodeAt(r);n&&n.type.name===e&&t.setNodeMarkup(r,void 0,{...n.attrs,foldState:x})}return!0}).run()}}},addStorage:()=>({markdown:{serialize(e,t){e.write(e.repeat("#",t.attrs.level)+" "),e.renderInline(t,!1),"expanded"!==M(t)&&e.write(" \x3c!-- fold --\x3e"),e.closeBlock(t)},parse:{updateDOM(e){e.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach(e=>{let t=e.lastChild;for(;t&&3===t.nodeType&&!(t.textContent||"").trim();){let r=t.previousSibling;e.removeChild(t),t=r}if(t&&8===t.nodeType&&/^\s*fold\s*$/.test(t.textContent||"")){let r=t.previousSibling;e.removeChild(t),r&&3===r.nodeType&&(r.textContent=(r.textContent||"").replace(/\s+$/,"")),e.setAttribute("data-collapsed","true")}})}}}}),addProseMirrorPlugins:()=>[new C.k_({key:L,state:{init:(e,{doc:t})=>E(t),apply:(e,t)=>e.docChanged?E(e.doc):t},props:{decorations:e=>L.getState(e)}})]});function T(e){let t=[];return e.forEach((e,r)=>t.push({node:e,start:r,end:r+e.nodeSize})),t}function $(e,t){return"heading"===e.type.name&&e.attrs.level<=t}function R(e){for(let t=e.depth;t>0;t--){let r=e.node(t).type.name;if("listItem"===r||"taskItem"===r)return t}return -1}function B(e,t,r,n,s){let o=t.slice(r,n),a=t.slice(n,s);e.replaceWith(r,s,a.content.append(o.content))}function F(e,t){let r=Math.max(0,Math.min(t,e.doc.content.size));e.setSelection(C.U3.near(e.doc.resolve(r)))}let I=new Set(["paragraph","bulletList","orderedList","taskList"]);function D(e,t,r){let{doc:n,selection:s}=e,o=s.$from,a=o.before(1),l=T(n),i=l.findIndex(e=>e.start===a);if(i<0)return!1;let c=i;for(;c>0&&I.has(l[c-1].node.type.name);)c--;let d=i;for(;d<l.length-1&&I.has(l[d+1].node.type.name);)d++;let u=[],m=-1,x="paragraph"===l[i].node.type.name?-1:o.index(1);for(let e=c;e<=d;e++){let t=l[e].node;if("paragraph"===t.type.name)e===i&&(m=u.length),u.push({kind:"paragraph",node:t});else{let r=t.type.name,n=0;t.forEach(t=>{e===i&&n===x&&(m=u.length),u.push({kind:r,node:t}),n++})}}if(m<0)return!1;let h=m+(r>0?1:-1);if(h<0||h>=u.length)return!1;if(t){let r,n,s,a=u[m];u[m]=u[h],u[h]=a;let i=function(e,t){let r=[],n=0;for(;n<e.length;){if("paragraph"===e[n].kind){r.push(e[n].node),n++;continue}let s=e[n].kind,o=[];for(;n<e.length&&e[n].kind===s;)o.push(e[n].node),n++;r.push(t.schema.nodes[s].create(null,o))}return y.FK.from(r)}(u,e),x=l[c].start,f=l[d].end,p=e.tr;p.replaceWith(x,f,i);let g=(r=0,n=0,s=-1,i.forEach(e=>{if(!(s>=0))if("paragraph"===e.type.name)r===h&&(s=n+1),r++,n+=e.nodeSize;else{let t=n+1;e.forEach(e=>{s>=0||(r===h&&(s=t+2),r++,t+=e.nodeSize)}),n+=e.nodeSize}}),s);F(p,g>=0?x+g+o.parentOffset:x),t(p.scrollIntoView())}return!0}function A(e,t,r){let n=e.selection.$from;if(1===n.depth&&"heading"===n.parent.type.name)return function(e,t,r){let{doc:n,selection:s}=e,o=s.$from.before(1),a=T(n),l=a.findIndex(e=>e.start===o);if(l<0)return!1;let i=a[l].node.attrs.level,c=l+1;for(;c<a.length&&!$(a[c].node,i);)c++;let d=a[l].start,u=a[c-1].end;if(r>0){if(c>=a.length)return!1;let r=a[c].node.attrs.level,o=c+1;for(;o<a.length&&!$(a[o].node,r);)o++;let l=a[o-1].end;if(t){let r=e.tr,o=n.slice(u,l).content.size;B(r,n,d,u,l),F(r,d+o+(s.from-d)),t(r.scrollIntoView())}return!0}if(0===l)return!1;let m=l-1;for(;m>=0&&!$(a[m].node,i);)m--;if(m<0||a[m].node.attrs.level<i)return!1;let x=a[m].start;if(t){let r=e.tr;B(r,n,x,d,u),F(r,x+(s.from-d)),t(r.scrollIntoView())}return!0}(e,t,r);let s=R(n);if(s>0){let o=n.node(s-1),a=n.index(s-1);return(r>0?a<o.childCount-1:a>0)?function(e,t,r,n){let{doc:s,selection:o}=e,a=o.$from,l=a.node(n),i=a.node(n-1),c=a.index(n-1),d=a.before(n),u=d+l.nodeSize;if(r>0){if(c>=i.childCount-1)return!1;let r=u+i.child(c+1).nodeSize;if(t){let n=e.tr,a=s.slice(u,r).content.size;B(n,s,d,u,r),F(n,d+a+(o.from-d)),t(n.scrollIntoView())}return!0}if(c<=0)return!1;let m=d-i.child(c-1).nodeSize;if(t){let r=e.tr;B(r,s,m,d,u),F(r,m+(o.from-d)),t(r.scrollIntoView())}return!0}(e,t,r,s):2===s&&D(e,t,r)}let o=n.depth>=1?n.node(n.depth-1).type.name:"doc";return"paragraph"===n.parent.type.name&&"doc"===o&&D(e,t,r)}function z(e,t){let{state:r}=e,n=r.selection.$from,s=n.parent.type.name;if("doc"===(n.depth>=1?n.node(n.depth-1).type.name:"doc")&&("heading"===s||"paragraph"===s)){let r=(("heading"===s?n.parent.attrs.level-1:3)+(t>0?1:-1)+4)%4;return 3===r?e.chain().setParagraph().run():e.chain().setHeading({level:r+1}).run()}let o=R(n);if(o>0){let r=n.node(o).type.name;return t<0?e.commands.liftListItem(r):e.commands.sinkListItem(r)}return!1}function W(e,t){let{state:r}=e,n=r.selection;if(!n.empty)return!1;let s=n.$from,o=t>0?1:-1;for(let t=s.depth;t>0;t--)if("taskItem"===s.node(t).type.name){let n=s.before(t),a=r.doc.nodeAt(n);if(!a)return!1;let l=a.attrs.status??"todo",i=(("doing"===l?2:"done"===l?3:1)+o+4)%4;if(0===i)return e.chain().toggleTaskList().run();let c=2===i?"doing":3===i?"done":"todo";return e.chain().command(({tr:e})=>{let t=e.doc.nodeAt(n);return!!t&&(e.setNodeMarkup(n,void 0,{...t.attrs,status:c}),!0)}).run()}if("paragraph"!==s.parent.type.name)return!1;let a=s.depth>=1?s.node(s.depth-1).type.name:"doc";return("doc"===a||"listItem"===a)&&(1==(0+o+4)%4?e.chain().toggleTaskList().run():e.chain().toggleTaskList().command(({tr:e})=>(function(e,t){let r=e.selection.$from;for(let n=r.depth;n>0;n--)if("taskItem"===r.node(n).type.name){let s=r.before(n),o=e.doc.nodeAt(s);o&&e.setNodeMarkup(s,void 0,{...o.attrs,status:t});break}return!0})(e,"done")).run())}let _=f.YY.create({name:"noteOrgKeymap",addKeyboardShortcuts(){return{"Alt-ArrowUp":()=>this.editor.commands.command(({state:e,dispatch:t})=>A(e,t,-1)),"Alt-ArrowDown":()=>this.editor.commands.command(({state:e,dispatch:t})=>A(e,t,1)),"Alt-ArrowLeft":()=>z(this.editor,-1),"Alt-ArrowRight":()=>z(this.editor,1),"Shift-ArrowRight":()=>W(this.editor,1),"Shift-ArrowLeft":()=>W(this.editor,-1)}}});function H(e){return e.storage.markdown.getMarkdown()}function O(){return[{label:a.A.t("slashCommands.heading1"),icon:"H1",description:a.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:a.A.t("slashCommands.heading2"),icon:"H2",description:a.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:a.A.t("slashCommands.heading3"),icon:"H3",description:a.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:a.A.t("slashCommands.bulletList"),icon:"•",description:a.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:a.A.t("slashCommands.orderedList"),icon:"1.",description:a.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:a.A.t("slashCommands.taskList"),icon:"☑",description:a.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:a.A.t("slashCommands.blockquote"),icon:"❝",description:a.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:a.A.t("slashCommands.codeBlock"),icon:"<>",description:a.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:a.A.t("slashCommands.table"),icon:"▦",description:a.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:a.A.t("slashCommands.horizontalRule"),icon:"──",description:a.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:a.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:a.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function q({editor:e,query:t,position:r,onClose:o}){let[a,l]=(0,s.useState)(0),i=(0,s.useRef)(null),c=O().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>l(0))},[t]);let d=r=>{e.chain().focus().deleteRange({from:e.state.selection.from-t.length-1,to:e.state.selection.from}).run(),r.action(e),o()};return((0,s.useEffect)(()=>{let e=e=>{"ArrowDown"===e.key?(e.preventDefault(),l(e=>(e+1)%c.length)):"ArrowUp"===e.key?(e.preventDefault(),l(e=>(e-1+c.length)%c.length)):"Enter"===e.key?(e.preventDefault(),c[a]&&d(c[a])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,a,o]),0===c.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lg py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:c.map((e,t)=>(0,n.jsxs)("button",{className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors ${t===a?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"}`,onClick:()=>d(e),onMouseEnter:()=>l(t),children:[(0,n.jsx)("span",{className:"w-6 text-center text-xs font-mono flex-shrink-0",children:e.icon}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium",children:e.label}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:e.description})]})]},e.label))})}O();var V=r(76043),U=r(86957),K=r(49433),J=r(34075),Q=r(76900);let Z=/^\s*[-*+]\s+(?:\\?\[ \\?\]|\\?\[[xX/]\\?\])\s*$/,Y=/^\s*(```|~~~)/;function G(e){return e.classList.contains("task-list-item")}let X=/^\s*\[\/\]\s?/,ee=f.YY.create({name:"markdownTaskListFix",addStorage:()=>({markdown:{parse:{updateDOM(e){var t;for(let r of Array.from(e.querySelectorAll("li"))){if(G(r))continue;let e=r.parentElement;e&&"UL"===e.tagName&&(t=r.textContent||"",/^\s*\[\/\]/.test(t)&&(!function(e){let t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=t.nextNode();for(;r&&!(r.nodeValue&&""!==r.nodeValue.trim());)r=t.nextNode();r&&r.nodeValue&&(r.nodeValue=r.nodeValue.replace(X,""))}(r),r.classList.add("task-list-item"),r.setAttribute("data-type","taskItem"),r.setAttribute("data-status","doing"),e.classList.add("contains-task-list")))}!function(e){for(let t of Array.from(e.querySelectorAll("ul.contains-task-list"))){let e=Array.from(t.children).filter(e=>"LI"===e.tagName);if(0===e.length)continue;let r=function(e){let t=[];for(let r of e){let e=t[t.length-1];e&&e.isTask===r.isTask?e.items.push(r):t.push({isTask:r.isTask,items:[r]})}return t}(e.map(e=>({isTask:G(e),el:e})));if(r.length<=1){r[0]?.isTask&&t.setAttribute("data-type","taskList");continue}let n=t.ownerDocument,s=n.createDocumentFragment();for(let e of r){let t=n.createElement("ul");for(let{el:r}of(e.isTask&&(t.setAttribute("class","contains-task-list"),t.setAttribute("data-type","taskList")),e.items))t.appendChild(r);s.appendChild(t)}t.replaceWith(s)}}(e)}}}})});var et=r(8242);let er=new Set(["taskItem","listItem"]),en=f.YY.create({name:"dropShellCleanup",addProseMirrorPlugins:()=>[new C.k_({key:new C.hs("dropShellCleanup"),appendTransaction(e,t,r){let n=[];if(e.forEach((t,r)=>{let s;if("drop"!==t.getMeta("uiEvent")||!t.docChanged)return;let o=(s=[],t.steps.forEach((e,r)=>{e instanceof et.Ln&&(0!==e.slice.size||e.from>=e.to||s.push(t.mapping.slice(r+1).map(e.from)))}),s);for(let t=r+1;t<e.length;t++)o=o.map(r=>e[t].mapping.map(r));n.push(...o)}),0===n.length)return null;let s=r.tr,o=!1;for(let e of n){let t=function(e,t){if(t<0||t>e.content.size)return null;let r=e.resolve(t);for(let e=r.depth;e>0;e--){var n;if(n=r.node(e),!er.has(n.type.name)||1!==n.childCount||null===n.firstChild||!n.firstChild.isTextblock||0!==n.firstChild.content.size)continue;let t=e;for(;t>1&&1===r.node(t-1).childCount;)t--;return{from:r.before(t),to:r.after(t)}}return null}(s.doc,s.mapping.map(e));if(t)try{s.delete(t.from,t.to),o=!0}catch{}}return o?s:null}})]});function es({isOpen:e,onClose:t,projectCwd:r,projectName:f}){let{t:p}=(0,o.Bd)(),[g,b]=(0,s.useState)(!0),[v,N]=(0,s.useState)(!1),C=(0,s.useRef)(null),S=(0,s.useRef)(!1),L=(0,s.useRef)(void 0),[M,E]=(0,s.useState)(null),T=(0,s.useRef)(null),$=(0,s.useCallback)(async e=>{let t=function(e){if(!e)return e;let t=e.split("\n"),r=[],n=!1;for(let e of t){if(Y.test(e)){n=!n,r.push(e);continue}if(n){r.push(e);continue}Z.test(e)||r.push(e)}let s=[],o=0,a=!1;for(let e of r){if(Y.test(e)){a=!a,s.push(e),o=0;continue}if(!a&&""===e.trim()){if((o+=1)>=2)continue;s.push(e);continue}o=0,s.push(e)}return s.join("\n")}(e);N(!0);let n=await U.t4.runPromiseExit((0,Q.Cq)(r,t,L.current).pipe(K.tapError(e=>K.sync(()=>console.error("Failed to save note:",e)))));if("Success"===n._tag){let e=n.value;e.conflict?(F.current?.commands.setContent(e.content,{emitUpdate:!1}),L.current=e.mtime,S.current=!1,(0,J.oR)(p("editor.conflictReloaded"),"info")):(L.current=e.mtime,S.current=!1)}N(!1)},[r,p]),R=(0,s.useCallback)(e=>{S.current=!0,C.current&&clearTimeout(C.current),C.current=setTimeout(()=>{$(e)},5e3)},[$]),B=(0,l.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:!1}),P.configure({levels:[1,2,3]}),_,c.A.configure({placeholder:()=>a.A.t("editor.placeholder")}),d.XI.configure({resizable:!0}),u.H,m.n,x.A,h._,w.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),j.configure({nested:!0}),ee,en,k.o.configure({html:!0,transformCopiedText:!1,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},clipboardTextSerializer:e=>e.content.textBetween(0,e.content.size,"\n").replace(/\n+$/,""),transformCopied:e=>{let t=e=>!!e&&e.isTextblock&&0===e.content.size,r=e.content,{openStart:n,openEnd:s}=e;for(;r.childCount>1&&t(r.lastChild);)r=r.cut(0,r.size-r.lastChild.nodeSize),s=0;for(;r.childCount>1&&t(r.firstChild);)r=r.cut(r.firstChild.nodeSize),n=0;return new y.Ji(r,n,s)},handleClick:(e,t,r)=>{if(r.metaKey||r.ctrlKey){let r=e.state.doc.resolve(t).marks().find(e=>"link"===e.type.name)?.attrs;if(r?.href)return window.open(r.href,"_blank","noopener,noreferrer"),!0}return!1},handleKeyDown:(e,t)=>{if("Backspace"===t.key&&F.current){let e=F.current;if(e.isActive("codeBlock")){let{$from:t}=e.state.selection,r=t.node(t.depth);if("codeBlock"===r.type.name&&""===r.textContent)return e.chain().focus().toggleCodeBlock().run(),!0}}return"/"!==t.key||M||setTimeout(()=>{if(!F.current)return;let{from:e}=F.current.state.selection;if("/"===F.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){T.current=e;let t=F.current.view.coordsAtPos(e);E({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(R(H(e)),null!==T.current){let{from:t}=e.state.selection;if(t<T.current)E(null),T.current=null;else{let r=e.state.doc.textBetween(T.current,t,"\n");r.includes(" ")||r.includes("\n")?(E(null),T.current=null):E(e=>e?{...e,query:r}:null)}}}}),F=(0,s.useRef)(null);(0,s.useEffect)(()=>{F.current=B},[B]),(0,s.useEffect)(()=>{e&&B&&(b(!0),E(null),T.current=null,U.t4.runPromiseExit((0,Q.zF)(r)).then(e=>{"Success"===e._tag?(B.commands.setContent(e.value.content||"",{emitUpdate:!1}),L.current=e.value.mtime,C.current&&(clearTimeout(C.current),C.current=null),S.current=!1):console.error("Failed to load note:",e.cause),b(!1)}))},[e,B,r]);let I=(0,s.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null),S.current&&B&&$(H(B)),E(null),T.current=null,t()},[B,$,t]);return((0,s.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(M?(E(null),T.current=null):I())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,I,M]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:I}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] mx-4 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:f?p("editor.noteTitle",{name:f}):p("editor.noteUntitled")}),v&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:p("editor.saving")})]}),(0,n.jsx)("button",{onClick:I,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(V.NoteToolbar,{editor:B}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:g?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:p("common.loading")})}):(0,n.jsx)(l.$Z,{editor:B})})]}),M&&B&&(0,n.jsx)(q,{editor:B,query:M.query,position:M.position,onClose:()=>{E(null),T.current=null}})]}):null}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>d,fY:()=>c,gT:()=>u});var n=r(95155),s=r(12115);let o=["agent","explorer","console"],a={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},l=(0,s.createContext)(null);function i(){let e=(0,s.useContext)(l);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function c({activeView:e,onViewChange:t,children:r}){let a=(0,s.useRef)(null),i=(0,s.useRef)(!1),d=(0,s.useRef)(0),[u,m]=(0,s.useState)(0),[x,h]=(0,s.useState)(!1),f=o.indexOf(e),p=o.length-1;(0,s.useEffect)(()=>{d.current=0,queueMicrotask(()=>m(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){let r=e.target;if("IFRAME"===r.tagName||function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth>e.clientWidth)return!0;e=e.parentElement}return!1}(r))return;e.preventDefault(),e.stopPropagation(),i.current&&(i.current=!1);let n=window.innerWidth,s=d.current-6*e.deltaX;!(f>0)&&s>0&&(s=0),!(f<p)&&s<0&&(s=0),d.current=s=Math.max(-n,Math.min(n,s)),m(s),h(!0),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{let e=d.current,r=.12*n;h(!1),i.current=!0;let s=f;e<-r&&f<p?s=f+1:e>r&&f>0&&(s=f-1),d.current=0,m(0),s!==f&&t(o[s]),setTimeout(()=>{i.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[f,p,t]);let[g,b]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>b(!0))},[]);let v={activeView:e,onViewChange:t,dragOffset:(()=>{if(!g)return 0;let e=window.innerWidth;return e?u/e:0})(),isDragging:g&&x};return(0,n.jsx)(l.Provider,{value:v,children:r})}function d({children:e}){let t,r,{activeView:a,dragOffset:l,isDragging:c}=i(),u=(0,s.useRef)(null),m=(0,s.useRef)(null),x=o.indexOf(a),h=o.length;return(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{0!==e.scrollLeft&&(e.scrollLeft=0)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,n.jsx)("div",{ref:u,className:"flex-1 overflow-hidden relative",style:{overscrollBehaviorX:"none"},children:(0,n.jsx)("div",{ref:m,className:c?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*o.length}%`,transform:(t=l/h*100,r=-(100/h*x)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function u(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:l}=i(),c=(0,s.useRef)(null),d=(0,s.useRef)([]),[u,m]=(0,s.useState)({left:0,width:0}),x=o.indexOf(e),h=()=>{if(!c.current||0===d.current.length)return{left:0,width:0};let e=c.current.getBoundingClientRect(),t=d.current.filter(Boolean);if(t.length!==o.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(o.length-1,x-n)),a=Math.floor(s),l=Math.ceil(s),i=s-a,u=t[a],m=t[l];if(!u||!m)return{left:0,width:0};let h=u.getBoundingClientRect(),f=m.getBoundingClientRect();return{left:h.left+(f.left-h.left)*i-e.left,width:h.width+(f.width-h.width)*i}};(0,s.useEffect)(()=>{queueMicrotask(()=>m(h()))},[x,r]),(0,s.useEffect)(()=>{let e=()=>{m(h())};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[x,r]);let f=Number.isFinite(r)?r:0,p=Math.round(Math.max(0,Math.min(o.length-1,x-f)));return(0,n.jsxs)("div",{ref:c,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{d.current[r]=e},onClick:()=>t(e),className:`px-4 py-1 text-sm font-medium transition-colors ${p===r?"text-brand":"text-muted-foreground hover:text-foreground"}`,children:a[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${l?"":"transition-all duration-100 ease-out"}`,style:{left:u.left,width:u.width}})]})}},76043:(e,t,r)=>{r.d(t,{NoteToolbar:()=>l});var n=r(95155),s=r(12115),o=r(79114);function a({editor:e,onClose:t,position:r}){let{t:l}=(0,o.Bd)(),[i,c]=(0,s.useState)(()=>e.getAttributes("link").href||""),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.current?.focus()},[]);let u=()=>{let r=i.trim();if(r){let t=r.match(/^https?:\/\//)?r:`https://${r}`;e.chain().focus().extendMarkRange("link").setLink({href:t}).run()}else e.chain().focus().extendMarkRange("link").unsetLink().run();t()},m=r?{top:r.top,left:r.left}:{};return(0,n.jsxs)("div",{className:`${r?"fixed":"absolute top-full left-0 mt-1"} z-[60] bg-popover border border-border rounded-lg shadow-lg p-2 flex items-center gap-2`,style:m,children:[(0,n.jsx)("input",{ref:d,type:"text",value:i,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u()):"Escape"===e.key&&(e.preventDefault(),t())},placeholder:l("editor.linkPlaceholder"),className:"bg-background border border-border rounded px-2 py-1 text-sm w-64 outline-none focus:border-brand"}),(0,n.jsx)("button",{onClick:u,className:"p-1 rounded text-sm font-medium text-brand hover:bg-brand/10 transition-colors",title:l("editor.confirmLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})}),e.isActive("link")&&(0,n.jsx)("button",{onClick:()=>{e.chain().focus().extendMarkRange("link").unsetLink().run(),t()},className:"p-1 rounded text-sm font-medium text-red-500 hover:bg-red-500/10 transition-colors",title:l("editor.removeLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})}function l({editor:e}){let{t}=(0,o.Bd)(),[r,i]=(0,s.useState)(!1),c=(0,s.useRef)(null),[,d]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>d(e=>e+1);return e.on("selectionUpdate",t),e.on("transaction",t),()=>{e.off("selectionUpdate",t),e.off("transaction",t)}},[e]),(0,s.useEffect)(()=>{let e=()=>i(!0);return window.addEventListener("tiptap-insert-link",e),()=>window.removeEventListener("tiptap-insert-link",e)},[]),!e)return null;let u=e=>`p-1.5 rounded text-xs font-medium transition-colors ${e?"bg-brand/15 text-brand":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,m="w-px h-5 bg-border mx-0.5",x=e.isActive("table");return(0,n.jsxs)("div",{className:"flex items-center gap-0.5 px-4 py-1.5 border-b border-border flex-shrink-0 flex-wrap",children:[(0,n.jsx)("button",{className:u(e.isActive("heading",{level:1})),onClick:()=>e.chain().focus().toggleHeading({level:1}).run(),title:t("editor.heading1"),children:"H1"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:2})),onClick:()=>e.chain().focus().toggleHeading({level:2}).run(),title:t("editor.heading2"),children:"H2"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:3})),onClick:()=>e.chain().focus().toggleHeading({level:3}).run(),title:t("editor.heading3"),children:"H3"}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("bold")),onClick:()=>e.chain().focus().toggleBold().run(),title:t("editor.bold"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"})})}),(0,n.jsx)("button",{className:u(e.isActive("italic")),onClick:()=>e.chain().focus().toggleItalic().run(),title:t("editor.italic"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z"})})}),(0,n.jsx)("button",{className:u(e.isActive("strike")),onClick:()=>e.chain().focus().toggleStrike().run(),title:t("editor.strikethrough"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("code")),onClick:()=>e.chain().focus().toggleCode().run(),title:t("editor.inlineCode"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"})})}),(0,n.jsx)("div",{className:m}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{ref:c,className:u(e.isActive("link")),onClick:()=>i(!r),title:t("editor.link"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})})}),r&&(0,n.jsx)(a,{editor:e,onClose:()=>i(!1),position:null})]}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("bulletList")),onClick:()=>e.chain().focus().toggleBulletList().run(),title:t("editor.bulletList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z"})})}),(0,n.jsx)("button",{className:u(e.isActive("orderedList")),onClick:()=>e.chain().focus().toggleOrderedList().run(),title:t("editor.orderedList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("taskList")),onClick:()=>e.chain().focus().toggleTaskList().run(),title:t("editor.taskList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14zM17.99 9l-1.41-1.42-6.59 6.59-2.58-2.57-1.42 1.41 4 3.99z"})})}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("blockquote")),onClick:()=>e.chain().focus().toggleBlockquote().run(),title:t("editor.blockquote"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"})})}),(0,n.jsx)("button",{className:u(e.isActive("codeBlock")),onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.codeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H4V5h16v14zm-7.5-4.5L15 12l-2.5-2.5L11 11l1.5 1.5L11 14l1.5 1.5zM9.5 14.5L7 12l2.5-2.5L11 11 9.5 12.5 11 14l-1.5.5z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:t("editor.table"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-9 15H4v-4h7v4zm0-6H4V7h7v4zm9 6h-7v-4h7v4zm0-6h-7V7h7v4z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().setHorizontalRule().run(),title:t("editor.horizontalRule"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 11h16v2H4z"})})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowBefore().run(),title:t("editor.insertRowAbove"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zM11 17H4v-2h7v2zm0-4H4v-2h7v2zm9 4h-7v-2h7v2zm0-4h-7v-2h7v2z"}),(0,n.jsx)("path",{d:"M14 1h-4v2H8v2h2v2h4V5h2V3h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowAfter().run(),title:t("editor.insertRowBelow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v10h20V6c0-1.1-.9-2-2-2zM11 12H4v-2h7v2zm0-4H4V6h7v2zm9 4h-7v-2h7v2zm0-4h-7V6h7v2z"}),(0,n.jsx)("path",{d:"M14 19h-4v2H8v2h2v-2h4v2h2v-2h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnBefore().run(),title:t("editor.insertColumnLeft"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 11H10v-2h7v2zm0-4H10V9h7v2z"}),(0,n.jsx)("path",{d:"M1 14v-4h2V8h2v2h-2v4h2v2H3v-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnAfter().run(),title:t("editor.insertColumnRight"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M4 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h10V4H4zm7 11H4v-2h7v2zm0-4H4V9h7v2z"}),(0,n.jsx)("path",{d:"M18 4v20h2c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-2z"}),(0,n.jsx)("path",{d:"M21 14v-4h2V8h2v2h-2v4h2v2h-2v-2z",opacity:".6"})]})}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-500 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteRow().run(),title:t("editor.deleteRow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zm-8 8H4v-2h8v2z"}),(0,n.jsx)("path",{d:"M15 13l-1.41 1.41L15.17 16l-1.58 1.59L15 19l1.59-1.59L18.17 19l1.42-1.41L18 16l1.59-1.59L18.17 13 16.59 14.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-500 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteColumn().run(),title:t("editor.deleteColumn"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 7H10V9h7v2z"}),(0,n.jsx)("path",{d:"M13 16l-1.41 1.41L13.17 19l-1.58 1.59L13 22l1.59-1.59L16.17 22l1.42-1.41L16 19l1.59-1.59L16.17 16l-1.58 1.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-500 hover:bg-red-500/10",onClick:()=>e.chain().focus().deleteTable().run(),title:t("editor.deleteTable"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]}),e.isActive("codeBlock")&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-500 hover:bg-red-500/10",onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.deleteCodeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})]})}},76288:(e,t,r)=>{r.d(t,{EmptyState:()=>i});var n=r(95155),s=r(12115),o=r(79114),a=r(86957),l=r(76900);function i({onSelectSession:e}){let{t}=(0,o.Bd)(),[r,c]=(0,s.useState)([]),[d,u]=(0,s.useState)({}),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useCallback)(async()=>{x(!0),f(null),u({});let e=await a.t4.runPromiseExit((0,l.H7)());"Success"===e._tag?c(e.value):f("Failed to load projects"),x(!1)},[]),j=(0,s.useCallback)(async e=>{u(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await a.t4.runPromiseExit((0,l.QW)(e));"Success"===t._tag?u(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):u(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),w=(0,s.useCallback)(e=>{let t=d[e];t?.isExpanded?u(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?u(t=>({...t,[e]:{...t[e],isExpanded:!0}})):j(e)},[d,j]);return(0,s.useEffect)(()=>{v(),setTimeout(()=>{b.current?.focus()},100)},[v]),(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-card",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-lg font-medium text-foreground",children:t("workspace.selectProject")}),(0,n.jsx)("input",{ref:b,type:"text",placeholder:t("workspace.searchProjectPath"),value:p,onChange:e=>g(e.target.value),className:"px-3 py-1.5 text-sm border border-border rounded-lg bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:t("workspace.loadingProjects")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-red-500",children:h})}),!m&&!h&&0===r.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:t("workspace.projectNotFound")})}),!m&&!h&&(0,n.jsx)("div",{className:"space-y-2",children:r.filter(e=>e.fullPath.toLowerCase().includes(p.toLowerCase())).map(r=>{let s=d[r.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>w(r.encodedPath),className:"w-full flex items-center gap-3 p-3 hover:bg-accent transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-4 h-4 text-muted-foreground transition-transform ${s.isExpanded?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("svg",{className:"w-5 h-5 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground truncate",children:r.name}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:r.fullPath})]}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground bg-secondary px-2 py-0.5 rounded",children:t("workspace.sessions",{count:r.sessionCount})})]}),s.isExpanded&&(0,n.jsxs)("div",{className:"border-t border-border bg-secondary/30",children:[s.isLoading&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:t("workspace.loadingSessions")})]}),s.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-500",children:s.error}),!s.isLoading&&!s.error&&0===s.sessions.length&&(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:t("workspace.noSessions")}),!s.isLoading&&!s.error&&s.sessions.map(t=>(0,n.jsxs)("button",{onClick:()=>{e(r.fullPath,(t.path.split("/").pop()||"").replace(".jsonl",""))},className:"w-full flex items-start gap-3 p-3 hover:bg-accent transition-colors text-left border-t border-border first:border-t-0",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground mt-0.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:t.title}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),t.firstMessages.length>0&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-1 truncate",children:t.firstMessages[0]})]})]},t.path))]})]},r.encodedPath)})})]})]})}},76412:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>p});var n=r(95155),s=r(12115),o=r(63728),a=r(82032),l=r(34075),i=r(79114),c=r(95045),d=r(75346),u=r(49433),m=r(86957),x=r(53213),h=r(76900);function f({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,i.Bd)(),[a,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)([]),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),k=(0,s.useRef)(null),y=(0,s.useRef)(null),N=(0,s.useCallback)(async()=>{g(!0);let t=await m.t4.runPromiseExit((0,x.r4)(e));if("Success"===t._tag){let e=t.value,r=e.local??[];u([...r,...(e.remote??[]).filter(e=>!r.includes(e.replace(/^origin\//,"")))])}else(0,l.oR)(o("toast.loadBranchFailed"),"error");g(!1)},[e,o]),C=(0,s.useCallback)(()=>{c(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{c(!1)},[]);(0,s.useEffect)(()=>{if(!a)return;let e=e=>{k.current&&!k.current.contains(e.target)&&S()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a,S]),(0,s.useEffect)(()=>{a&&setTimeout(()=>y.current?.focus(),50)},[a]);let L=async t=>{v(!0);let n=await m.t4.runPromiseExit((0,h.Kl)({action:"checkout",cwd:e,path:e,branch:t}));if("Success"===n._tag){let e=t.replace(/^origin\//,"");(0,l.oR)(o("toast.switchedToBranch",{branch:e}),"success"),S(),r()}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:o("toast.switchBranchFailed");(0,l.oR)(r,"error")}v(!1)},M=d.filter(e=>e!==t&&e.toLowerCase().includes(j.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsx)("button",{onClick:a?S:C,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:o("git.switchBranch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),a&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lg z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:y,type:"text",value:j,onChange:e=>w(e.target.value),placeholder:o("git.searchBranch"),className:"w-full px-2.5 py-1.5 text-sm bg-muted rounded border-none outline-none placeholder:text-muted-foreground",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:p?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===M.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):M.map(e=>(0,n.jsx)("button",{onClick:()=>L(e),disabled:b,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function p({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:x,onOpenAliasManager:g,onBranchSwitched:b}){let{t:v}=(0,i.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6 cursor-pointer",title:v("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,l.oR)(v("toast.copiedPageUrl"),"success")})}}),e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help",title:`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,l.oR)(v("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:v("tabManagerTopBar.copyDirPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}):(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"})]}),r&&e&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:x,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:"Git Worktrees",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 17h8m0 0l-4-4m4 4l-4 4M3 7v6a4 4 0 004 4h5"})}),(0,n.jsx)("span",{className:"text-sm",children:s||"main"})]}),(0,n.jsx)(f,{cwd:e,currentBranch:s,onSwitched:()=>b?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(o.gT,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(a.ReviewDropdown,{cwd:e}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.refreshProject"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&m.t4.runFork((0,h.em)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.583 2.213L12 7.393 6.417 2.213 1 6.17v11.66l5.417 3.957L12 16.607l5.583 5.18L23 17.83V6.17l-5.417-3.957zM6.417 17.83L3 15.33V8.67l3.417-2.5v11.66zm11.166 0V6.17L21 8.67v6.66l-3.417 2.5z"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&m.t4.runFork((0,h.Q1)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openInCursor"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4.5 2L20.5 12L4.5 22V2Z"})})}),t?.sessionId&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t.sessionId}`;navigator.clipboard.writeText(e).then(()=>{(0,l.oR)(v("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("chat.copyCommandTooltip",{sessionId:t.sessionId}),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:g,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.aliasesGlobal"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12h-6m-4 0a8 8 0 1116 0 8 8 0 01-16 0zm4 0h.01"})})}),(0,n.jsx)("button",{onClick:()=>(0,c.F)(d.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.tokenStats"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,n.jsx)("button",{onClick:()=>window.open("https://surething.io?from=cockpit","_blank"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:v("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}},76900:(e,t,r)=>{r.d(t,{Cq:()=>x,D0:()=>p,DZ:()=>i,H7:()=>h,It:()=>b,Kl:()=>k,M5:()=>l,Or:()=>d,Q1:()=>j,QW:()=>f,Wr:()=>c,Yn:()=>g,b2:()=>w,em:()=>v,zF:()=>m});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:r=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})}),a=(e,t)=>o(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),l=()=>o("/api/settings"),i=e=>o("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>o("/api/version"),d=()=>o("/api/extension/version"),u=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",m=e=>o(u(e)),x=(e,t,r)=>n.tryPromise({try:async()=>{let n=u(e),s=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,baseMtime:r})});if(409===s.status){let e=await s.json();return{conflict:!0,content:e.content??"",mtime:e.mtime}}if(!s.ok)throw Error(`HTTP ${s.status}`);return{conflict:!1,mtime:(await s.json()).mtime}},catch:t=>new s.uV({message:`POST ${u(e)} failed`,cause:t})}),h=()=>o("/api/sessions/projects"),f=e=>o(`/api/sessions/projects/${encodeURIComponent(e)}`),p=e=>o(`/api/project-settings?cwd=${encodeURIComponent(e)}`),g=e=>a("/api/project-settings",e),b=()=>o("/api/pick-folder"),v=e=>a("/api/open-vscode",{cwd:e}),j=e=>a("/api/open-cursor",{cwd:e}),w=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),k=e=>a("/api/git/worktree",e)},83678:(e,t,r)=>{r.d(t,{SessionBrowser:()=>d});var n=r(95155),s=r(12115),o=r(79114),a=r(95045),l=r(75346),i=r(86957),c=r(76900);function d({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)({}),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(""),C=(0,s.useRef)(null),S=(0,s.useCallback)(async()=>{j(!0),k(null),b({});let e=await i.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?p(e.value):k("Failed to load projects"),j(!1)},[]),L=(0,s.useCallback)(async e=>{b(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await i.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?b(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):b(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),M=(0,s.useCallback)(e=>{let t=g[e];t?.isExpanded?b(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?b(t=>({...t,[e]:{...t[e],isExpanded:!0}})):L(e)},[g,L]);(0,s.useEffect)(()=>{e&&(S(),setTimeout(()=>{C.current?.focus(),C.current?.select()},100))},[e,S]);let E=(0,s.useCallback)(async()=>{if(x)return;h(!0);let e=await i.t4.runPromiseExit((0,c.It)());"Success"===e._tag&&e.value.folder&&u&&(u(e.value.folder),t()),h(!1)},[x,u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-7xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:m("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:C,type:"text",placeholder:m("workspace.searchProjectPath"),value:y,onChange:e=>N(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),y&&(0,n.jsx)("button",{onClick:()=>{N(""),C.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:m("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),u&&(0,n.jsxs)("button",{onClick:E,disabled:x,className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",title:m("sessions.openFolder"),children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),x?m("sessions.selectingFolder"):m("sessions.openFolder")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[v&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:m("workspace.loadingProjects")})]})}),w&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:w})}),!v&&!w&&0===f.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:m("workspace.projectNotFound")})}),!v&&!w&&f.filter(e=>e.fullPath.toLowerCase().includes(y.toLowerCase())).map(e=>{let t=g[e.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"mb-3",children:[(0,n.jsxs)("button",{onClick:()=>M(e.encodedPath),className:"w-full flex items-center gap-2 p-2 rounded hover:bg-accent transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-3 h-3 text-muted-foreground transition-transform ${t.isExpanded?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("span",{className:"flex-1 text-xs font-medium text-foreground truncate",title:e.fullPath,children:e.fullPath}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.sessionCount,")"]})]}),t.isExpanded&&(0,n.jsxs)("div",{className:"ml-6 mt-2",children:[t.isLoading&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-3 w-3",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:m("sessions.loadingSessions")})]}),t.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-11",children:t.error}),!t.isLoading&&!t.error&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:t.sessions.map(t=>(0,n.jsxs)("div",{onClick:()=>{var n;let s;return n=e.fullPath,s=(t.path.split("/").pop()||"").replace(".jsonl",""),void(r?r(n,s):(0,a.F)(l.n.OpenProject,{cwd:n,sessionId:s}))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[t.engine&&"claude"!==t.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===t.engine?"bg-orange-500/15 text-orange-11":"ollama"===t.engine?"bg-blue-500/15 text-blue-11":"codex"===t.engine?"bg-green-500/15 text-green-11":"kimi"===t.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:t.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:t.title,children:t.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[t.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path))})]})]},e.encodedPath)})]})]})]}):null}},84310:(e,t,r)=>{r.d(t,{Providers:()=>u});var n=r(95155),s=r(47617),o=r(3238),a=r(34075),l=r(12115),i=r(47650);function c(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return e;t=t.parentElement}return null}function d(){let[e,t]=(0,l.useState)(null),r=(0,l.useRef)(null);r.current=e;let s=(0,l.useRef)(null),o=(0,l.useRef)(null),[a,d]=(0,l.useState)({left:0,top:0}),[u,m]=(0,l.useState)(!1);return((0,l.useEffect)(()=>m(!0),[]),(0,l.useEffect)(()=>{let e=()=>{s.current&&(clearTimeout(s.current),s.current=null)},n=n=>{let o=c(n.target);if(!o){e(),r.current&&t(null);return}if(r.current&&r.current.text===o)return void t({text:o,x:n.clientX,y:n.clientY});e();let a=n.clientX,l=n.clientY;s.current=setTimeout(()=>{t({text:o,x:a,y:l}),s.current=null},300)},o=n=>{if(!r.current)return;let s=c(n.target);if(!s){e(),t(null);return}t({text:s,x:n.clientX,y:n.clientY})},a=()=>{e(),r.current&&t(null)};return document.addEventListener("mouseover",n,!0),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("mousedown",a),()=>{document.removeEventListener("mouseover",n,!0),document.removeEventListener("mousemove",o),document.removeEventListener("mouseleave",a),document.removeEventListener("mousedown",a),e()}},[]),(0,l.useLayoutEffect)(()=>{if(!e||!o.current)return;let t=o.current.getBoundingClientRect(),r=window.innerWidth,n=window.innerHeight,s=e.x+12,a=e.y+16;s+t.width>r-8&&(s=r-t.width-8),s<8&&(s=8),a+t.height>n-8&&(a=e.y-t.height-8),d({left:s,top:a})},[e]),u&&e)?(0,i.createPortal)((0,n.jsx)("div",{ref:o,className:"fixed z-[9999] px-2 py-1 bg-popover text-popover-foreground text-xs font-mono rounded shadow-lg border border-brand whitespace-nowrap pointer-events-none max-w-[80vw] overflow-hidden text-ellipsis",style:{left:a.left,top:a.top},children:e.text}),document.body):null}function u({children:e}){return(0,n.jsx)(s.I18nProvider,{children:(0,n.jsx)(o.N,{children:(0,n.jsxs)(a.tE,{children:[e,(0,n.jsx)(d,{})]})})})}},88371:(e,t,r)=>{r.d(t,{U:()=>o,k:()=>s});let n="cockpit-skills";function s(){let e="u"<typeof BroadcastChannel?null:new BroadcastChannel(n);if(e)try{e.postMessage({type:"changed"})}finally{e.close()}}function o(e){if("u"<typeof BroadcastChannel)return()=>{};let t=new BroadcastChannel(n),r=t=>{t.data?.type==="changed"&&e()};return t.addEventListener("message",r),()=>{t.removeEventListener("message",r),t.close()}}},89039:(e,t,r)=>{r.d(t,{useTabState:()=>u});var n=r(12115),s=r(41474),o=r(2111),a=r(95045),l=r(75346),i=r(49433),c=r(86957),d=r(96472);function u({initialCwd:e,initialSessionId:t,activeView:r}){let m=(0,n.useRef)(!1),x=(0,n.useRef)(!0),h=(0,n.useRef)(r);(0,n.useEffect)(()=>{h.current=r},[r]);let f=(0,s.F)(),p=(0,n.useRef)(f);(0,n.useEffect)(()=>{p.current=f},[f]);let[g,b]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:t?`Session ${t.slice(0,6)}...`:"New Chat"}]),[v,j]=(0,n.useState)(g[0]?.id??""),[w,k]=(0,n.useState)(new Set),y=(0,n.useRef)(g);(0,n.useEffect)(()=>{y.current=g},[g]);let N=(0,n.useRef)(v);(0,n.useEffect)(()=>{N.current=v},[v]);let C=(0,n.useRef)(new Set),S=(0,n.useCallback)((t,r)=>{e&&t&&c.t4.runFork((0,d.KJ)(e,t,r).pipe(i.catchAll(()=>i.void)))},[e]),[L,M]=(0,n.useState)(null),[E,P]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||m.current||(m.current=!0,(async()=>{let r=await c.t4.runPromise((0,d.n8)(e).pipe(i.catchAll(()=>i.succeed(null))));if(r){let n=r.sessions||[],s=r.activeSessionId,o=r.engines||{},a=r.ollamaModels||{},l=r.deepseekModels||{},i=r.chatModes||{},c=r.planModes||{},d=[...n];if(t&&!d.includes(t)&&(d=[t,...d]),d.length>0){let r=d.map((t,r)=>({id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:o[t]||void 0,ollamaModel:a[t]||void 0,deepseekModel:l[t]||void 0,chatMode:i[t]||void 0,planMode:c[t]||void 0})),n=t||s,u=n?d.indexOf(n):-1;u<0&&(u=0);let m=r[u].id;b(r),j(m),setTimeout(()=>{x.current=!1},0)}else x.current=!1}else x.current=!1})())},[e,t]),(0,n.useEffect)(()=>{if(x.current||!e)return;let t=g.map(e=>e.sessionId).filter(e=>!!e),r=g.find(e=>e.id===v),n=r?.sessionId,s={},o={},a={},l={},u={};for(let e of g)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(o[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(a[e.sessionId]=e.deepseekModel),e.sessionId&&(l[e.sessionId]="pty"===e.chatMode?"pty":"sdk",u[e.sessionId]=!!e.planMode);let m=[...C.current];c.t4.runFork((0,d.ej)({cwd:e,sessions:t,activeSessionId:n,engines:s,ollamaModels:o,deepseekModels:a,chatModes:l,planModes:u,...m.length?{closedSessionIds:m}:{}}).pipe(i.tap(()=>i.sync(()=>{for(let e of m)C.current.delete(e)})),i.tapError(e=>i.sync(()=>console.error("Failed to save sessions:",e))),i.catchAll(()=>i.void)))},[g,v,e]),(0,n.useEffect)(()=>{if(x.current||!e)return;let t=g.find(e=>e.id===v);t?.sessionId&&(0,a.F)(l.n.SessionChange,{cwd:e,sessionId:t.sessionId})},[v,g,e]);let T=(0,n.useCallback)(t=>{e&&c.t4.runPromise((0,d.n8)(e).pipe(i.catchAll(()=>i.succeed(null)))).then(r=>{if(!r)return;let n=r.sessions||[],s=r.engines||{},o=r.ollamaModels||{},a=r.deepseekModels||{},l=r.chatModes||{},i=r.planModes||{},c=y.current,d=new Set(t),u=c.filter(e=>!e.sessionId||!d.has(e.sessionId)),m=new Set(u.map(e=>e.sessionId).filter(Boolean)),x=n.filter(e=>!m.has(e));if(u.length===c.length&&0===x.length)return;let h=[...u,...x.map((t,r)=>({id:`tab-${Date.now()}-sync-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:s[t]||void 0,ollamaModel:o[t]||void 0,deepseekModel:a[t]||void 0,chatMode:l[t]||void 0,planMode:i[t]||void 0}))];0===h.length&&(h=[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),b(h),h.some(e=>e.id===N.current)||j(h[h.length-1].id)})},[e]);(0,o.h)({url:"/ws/global-state",enabled:!!e,onMessage:t=>{x.current||!e||"project-state-changed"===t.type&&t.cwd===e&&T(t.closedSessionIds??[])}});let $=(0,n.useCallback)((e,t,r,n,s,o,a=!1)=>{let l={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:n,ollamaModel:s,deepseekModel:o};b(e=>{if(a)return[...e,l];let t=e.findIndex(e=>e.id===v);if(-1===t)return[...e,l];let r=[...e];return r.splice(t+1,0,l),r}),j(l.id)},[v]),R=(0,n.useCallback)(t=>{let r=y.current.find(e=>e.id===t);r?.sessionId&&C.current.add(r.sessionId),b(r=>{let n=r.filter(e=>e.id!==t);if(t===v&&n.length>0&&j(n[n.length-1].id),0===n.length){let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};return j(t.id),[t]}return n})},[v,e]),B=(0,n.useCallback)((t,r)=>{let n=g.find(e=>e.sessionId===t);n?j(n.id):$(e,t,r,void 0,void 0,void 0,!0)},[g,e,$]),F=(0,n.useCallback)(()=>{$(e,void 0,void 0,void 0,void 0,void 0,!0)},[e,$]),I=(0,n.useCallback)(()=>{$(e,void 0,"New Claude 2 Chat","claude2",void 0,void 0,!0)},[e,$]),D=(0,n.useCallback)(()=>{$(e,void 0,"New Codex Chat","codex",void 0,void 0,!0)},[e,$]),A=(0,n.useCallback)(()=>{$(e,void 0,"New Kimi Chat","kimi",void 0,void 0,!0)},[e,$]),z=(0,n.useCallback)(t=>{$(e,void 0,t?`New Ollama (${t})`:"New Ollama Chat","ollama",t,void 0,!0)},[e,$]),W=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),_=(0,n.useCallback)(()=>{$(e,void 0,"New DeepSeek Chat","deepseek",void 0,"deepseek-v4-flash",!0)},[e,$]),H=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),O=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,chatMode:t}:r))},[]),q=(0,n.useCallback)((e,t)=>{b(r=>r.map(r=>r.id===e?{...r,planMode:t}:r))},[]),V=(0,n.useCallback)((t,r)=>{$(e,t,r)},[e,$]),U=(0,n.useCallback)((e,t)=>{b(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!h.current||"agent"===h.current;if(e===v&&r&&p.current){let e=n.sessionId||t.sessionId;e&&S(e,"normal")}else k(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[v,S]);(0,n.useEffect)(()=>{(!r||"agent"===r)&&f&&k(e=>{if(!e.has(v))return e;let t=new Set(e);t.delete(v);let r=y.current.find(e=>e.id===v);return r?.sessionId&&(S(r.sessionId,"normal"),c.t4.runFork((0,d.M2)(r.sessionId).pipe(i.catchAll(()=>i.void)))),t})},[r,v,f,S]);let K=(0,n.useCallback)(e=>{j(e),k(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=y.current.find(t=>t.id===e);return n?.sessionId&&(S(n.sessionId,"normal"),c.t4.runFork((0,d.M2)(n.sessionId).pipe(i.catchAll(()=>i.void)))),r})},[S]),J=(0,n.useCallback)(e=>{M(e)},[]),Q=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==L&&L!==t&&P(t)},[L]),Z=(0,n.useCallback)(e=>{null!==L&&L!==e&&b(t=>{let r=[...t],[n]=r.splice(L,1);return r.splice(e,0,n),r}),M(null),P(null)},[L]),Y=(0,n.useCallback)(()=>{M(null),P(null)},[]),G=g.find(e=>e.id===v);return{tabs:g,activeTabId:v,activeTab:G,unreadTabs:w,dragTabIndex:L,dragOverTabIndex:E,addTab:$,closeTab:R,switchTab:K,handleSelectSession:B,handleNewTab:F,handleNewClaude2Tab:I,handleNewCodexTab:D,handleNewKimiTab:A,handleNewOllamaTab:z,handleNewDeepseekTab:_,handleOpenSession:V,updateTabState:U,updateTabOllamaModel:W,updateTabDeepseekModel:H,updateTabChatMode:O,updateTabPlanMode:q,handleTabDragStart:J,handleTabDragOver:Q,handleTabDrop:Z,handleTabDragEnd:Y}}},93777:(e,t,r)=>{r.d(t,{E:()=>c});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(12786);let i={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120}],cron:[{labelKey:"scheduledTasks.daily9am",value:"0 9 * * *"},{labelKey:"scheduledTasks.daily6pm",value:"0 18 * * *"},{labelKey:"scheduledTasks.weeklyMon9am",value:"0 9 * * 1"},{labelKey:"scheduledTasks.monthly1st9am",value:"0 9 1 * *"}]};function c({onClose:e,onCreate:t,editTask:r,onUpdate:d}){let{t:u}=(0,o.Bd)(),m=!!r,[x,h]=(0,s.useState)(r?.type||"once"),[f,p]=(0,s.useState)(r?.message||""),[g,b]=(0,s.useState)(r?String(r.delayMinutes||r.intervalMinutes||""):""),[v,j]=(0,s.useState)(r?.cron||""),[w,k]=(0,s.useState)(r?.activeFrom||"09:00"),[y,N]=(0,s.useState)(r?.activeTo||"18:00"),[C,S]=(0,s.useState)(!!(r?.activeFrom&&r?.activeTo)),[L,M]=(0,s.useState)(null),E=(0,s.useRef)(null),P=(0,s.useRef)(null);(0,s.useEffect)(()=>{P.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{E.current&&!E.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let T=(0,s.useCallback)(()=>{if(!f.trim())return;let n=null;if("once"===x){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"once",delayMinutes:e}}else if("interval"===x){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"interval",intervalMinutes:e,...C?{activeFrom:w,activeTo:y}:{}}}else if("cron"===x){let e=L||v.trim();if(!e)return;n={message:f.trim(),type:"cron",cron:e}}n&&(m&&r&&d?d(r.id,n):t(n),e())},[f,x,L,g,v,C,w,y,t,e,m,r,d]);return(0,n.jsxs)("div",{ref:E,className:`w-[28rem] max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lg z-50 ${m?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&T()},children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:m?u("scheduledTasks.editTask"):u("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4 max-h-[min(52rem,calc(100vh-3rem))] overflow-y-auto",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.sendMessage")}),(0,n.jsx)("textarea",{ref:P,value:f,onChange:e=>p(e.target.value),placeholder:u("scheduledTasks.messagePlaceholder"),rows:5,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-y min-h-[6rem]"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{h(e),M(null),b(""),j("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${x===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?u("scheduledTasks.once"):"interval"===e?u("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:i[x].map(e=>(0,n.jsx)("button",{onClick:()=>{M(e.value),"cron"===x?j(String(e.value)):b(String(e.value))},className:`px-2 py-1 text-xs rounded border transition-colors ${L===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:u(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===x?u("scheduledTasks.customCron"):u("scheduledTasks.customMinutes")}),"cron"===x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:v,onChange:e=>{j(e.target.value),M(null)},placeholder:u("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),v.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=a.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,l,i]=r,c={0:t("cron.dowSun"),1:t("cron.dowMon"),2:t("cron.dowTue"),3:t("cron.dowWed"),4:t("cron.dowThu"),5:t("cron.dowFri"),6:t("cron.dowSat")},d={1:`1${t("cron.monthPrefix")}`,2:`2${t("cron.monthPrefix")}`,3:`3${t("cron.monthPrefix")}`,4:`4${t("cron.monthPrefix")}`,5:`5${t("cron.monthPrefix")}`,6:`6${t("cron.monthPrefix")}`,7:`7${t("cron.monthPrefix")}`,8:`8${t("cron.monthPrefix")}`,9:`9${t("cron.monthPrefix")}`,10:`10${t("cron.monthPrefix")}`,11:`11${t("cron.monthPrefix")}`,12:`12${t("cron.monthPrefix")}`};try{let e="";if(n.includes("/")||s.includes("/")){if("*"===s&&n.includes("/"))return t("cron.everyNMinutes",{n:n.split("/")[1]});if("0"===n&&s.includes("/"))return t("cron.everyNHours",{n:s.split("/")[1]});return null}let r=parseInt(s,10),a=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(a)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:a}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}`;let u=[];if("*"!==l){let e=l.split(",").map(e=>d[e]||`${e}${t("cron.monthPrefix")}`);u.push(e.join(", "))}if("*"!==o)if(o.includes("-")){let[e,r]=o.split("-");u.push(t("cron.dayRange",{a:e,b:r}))}else o.includes(",")?u.push(o.split(",").map(e=>`${e}${t("cron.dayOfMonth")}`).join(", ")):u.push(`${o}${t("cron.dayOfMonth")}`);if("*"!==i)if("1-5"===i)u.push(t("cron.weekdays"));else if("0,6"===i||"6,0"===i)u.push(t("cron.weekends"));else{let e=i.split(",").map(e=>{if(e.includes("-")){let[r,n]=e.split("-");return t("cron.weekdayRange",{a:c[r]||r,b:c[n]||n})}return`${t("cron.weekdayPrefix")}${c[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===l&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}(v.trim())||(0,n.jsx)("span",{className:"text-destructive",children:u("scheduledTasks.cronFormat")})})]}):(0,n.jsx)("input",{type:"number",value:g,onChange:e=>{b(e.target.value),M(null)},placeholder:u("scheduledTasks.minutesPlaceholder"),min:1,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]}),"interval"===x&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:C,onChange:e=>S(e.target.checked),className:"rounded border-border"}),u("scheduledTasks.limitTimeRange")]}),C&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:w,onChange:e=>k(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:y,onChange:e=>N(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]})]}),(0,n.jsx)("button",{onClick:T,disabled:!(f.trim()&&("once"===x||"interval"===x?!!(L||g&&parseInt(g,10)>0):"cron"===x&&!!(L||v.trim()))),className:"w-full py-1.5 text-sm font-medium rounded bg-brand text-white hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:m?u("scheduledTasks.saveBtn",{modKey:(0,l.Mu)()}):u("scheduledTasks.createBtn",{modKey:(0,l.Mu)()})})]})]})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}),a=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"saveProjectState failed",cause:e})}),l=(e,t,r)=>n.tryPromise({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})}}]);
|