@surething/cockpit 1.0.281 → 1.0.282

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +7 -7
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/cockpit-build.json +2 -2
  5. package/.next-prod/prerender-manifest.json +3 -3
  6. package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
  7. package/.next-prod/server/app/_global-error.html +1 -1
  8. package/.next-prod/server/app/_global-error.rsc +1 -1
  9. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  10. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/.next-prod/server/app/_not-found.html +2 -2
  14. package/.next-prod/server/app/_not-found.rsc +4 -4
  15. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +4 -4
  16. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +4 -4
  17. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  18. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  19. package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
  20. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  21. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  22. package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
  23. package/.next-prod/server/app-paths-manifest.json +7 -7
  24. package/.next-prod/server/chunks/2493.js +2 -2
  25. package/.next-prod/server/chunks/5591.js +3 -3
  26. package/.next-prod/server/chunks/7438.js +2 -2
  27. package/.next-prod/server/middleware-build-manifest.js +1 -1
  28. package/.next-prod/server/pages/404.html +2 -2
  29. package/.next-prod/server/pages/500.html +1 -1
  30. package/.next-prod/server/server-reference-manifest.json +1 -1
  31. package/.next-prod/static/chunks/{72550-9aedd46bd54f0be7.js → 72550-456b4a8d1b8a0122.js} +2 -2
  32. package/.next-prod/static/chunks/app/{layout-22f49ab92f208f15.js → layout-6641747151f1495e.js} +1 -1
  33. package/.next-prod/static/css/bc059ebeb7cf61ba.css +1 -0
  34. package/.next-prod/trace +15 -15
  35. package/.next-prod/trace-build +1 -1
  36. package/dist/{chunk-N6CFCP2N.mjs → chunk-UIW3QM6E.mjs} +1 -1
  37. package/dist/{chunk-3LSLUAN6.mjs → chunk-YDI26AYY.mjs} +6 -2
  38. package/dist/httpApi.mjs +2 -2
  39. package/dist/scheduledTasks.mjs +1 -1
  40. package/dist/wsServer.mjs +2 -2
  41. package/package.json +3 -3
  42. package/.next-prod/static/css/e33280be1b23649f.css +0 -1
  43. /package/.next-prod/static/{COnpPKy0RckqiixR3j42H → CzzbCJuWzqFF_23NMp7ya}/_buildManifest.js +0 -0
  44. /package/.next-prod/static/{COnpPKy0RckqiixR3j42H → CzzbCJuWzqFF_23NMp7ya}/_ssgManifest.js +0 -0
@@ -7,7 +7,7 @@ ${t}`;function M({collapsed:e,pinnedSessions:t,sessionNumbers:r,currentCwd:a,onS
7
7
  ${e.sessionId}`]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0 group-hover:hidden",children:e.completed?v("scheduledTasks.completed"):e.paused?v("scheduledTasks.paused"):v("common.running")}),V===e.id?(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),U(null),p(e.id)},className:"px-2 py-0.5 text-[10px] rounded bg-red-9 text-white hover:bg-red-10",children:v("common.confirm")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),U(null)},className:"px-2 py-0.5 text-[10px] rounded border border-border text-muted-foreground hover:text-foreground",children:v("common.cancel")})]}):(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.taskFile&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),W(e.taskFile)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:v("common.preview"),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)("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"})]})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),X(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:v(e.taskFile?"common.copyPath":"common.copy"),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)("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"})]})}),(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:v("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(),N.current=t.currentTarget,y(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:v("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.completed?null:e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-11",title:v("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(),i(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-amber-11",title:v("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(),U(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:v("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"})})})]})]}),(0,n.jsx)("div",{className:"text-xs text-foreground line-clamp-3 mb-1 whitespace-pre-wrap break-words","data-tooltip":(0,P.Q_)(e),children:(0,P.Q_)(e)}),(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"truncate",children:function(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}(e,v)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{className:"flex-shrink-0",children:e.completed?"success"===e.lastResult?v("scheduledTasks.success"):v("scheduledTasks.failure"):e.paused?v("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,v)}),!e.completed&&e.lastFiredAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsxs)("span",{className:"flex-shrink-0",children:[v("scheduledTasks.lastResult"),": ","success"===e.lastResult?"✓":"✗"]})]})]})]},e.id)})})]},e)})})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:J?(0,n.jsx)(F,{task:J,onOpenSession:()=>et(J)},J.id):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:v("scheduledTasks.selectTaskHint")})})]})})]})]}),I&&null!==z&&(0,n.jsx)(T.x,{filePath:I,content:z,cwd:I.slice(0,Math.max(0,I.lastIndexOf("/"))),onClose:Z,zClassName:"z-[80]"}),k&&(0,n.jsx)("div",{ref:C,className:"fixed z-[100]",style:{top:S?.top??0,left:S?.left??0,visibility:S?"visible":"hidden"},children:(0,n.jsx)($.E,{onClose:R,onCreate:()=>{},editTask:{id:k.id,message:k.message,taskFile:k.taskFile,type:k.type,delayMinutes:k.delayMinutes,intervalMinutes:k.intervalMinutes,activeFrom:k.activeFrom,activeTo:k.activeTo,cron:k.cron},onUpdate:(e,t)=>{b(e,t),R()}})})]})}var W=r(42804),z=r(39872),O=r(2111),_=r(94720);function q({collapsed:e,currentCwd:t,projectOrder:r,onFocusTerminal:a}){let{t:l}=(0,o.Bd)(),{terminals:i,refresh:d}=function(){let[e,t]=(0,s.useState)([]),r=(0,s.useRef)(null),n=(0,s.useCallback)(()=>{m.t4.runPromiseExit((0,_.D5)()).then(e=>{"Success"===e._tag&&t(e.value)})},[]),o=(0,s.useCallback)(()=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{r.current=null,n()},150)},[n]);return(0,s.useEffect)(()=>(n(),()=>{r.current&&clearTimeout(r.current)}),[n]),(0,O.h)({url:"/ws/global-state",onMessage:e=>{("running-terminals-changed"===e.type||"console-delta"===e.type&&"rename"===e.op)&&o()}}),{terminals:e,refresh:n}}(),[c,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(()=>Date.now()),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(()=>new Set),w=(0,s.useRef)(new Map),k=(0,s.useMemo)(()=>{let e=new Map;for(let t of i){let r=e.get(t.projectCwd);r?r.push(t):e.set(t.projectCwd,[t])}let n=e=>{if(e===t)return -1;let n=r.indexOf(e);return n>=0?n:Number.MAX_SAFE_INTEGER};return[...e.entries()].sort(([e],[t])=>n(e)-n(t)||e.localeCompare(t)).map(([e,t])=>({cwd:e,number:r.indexOf(e)+1,items:[...t].sort((e,t)=>e.timestamp.localeCompare(t.timestamp))}))},[i,t,r]),y=(0,s.useMemo)(()=>k.flatMap(e=>e.items),[k]),N=(0,s.useCallback)(()=>{u(!1),b(null)},[]),C=(0,s.useCallback)(()=>{d(),h(Date.now()),u(!0)},[d]);(0,s.useEffect)(()=>{if(!c)return;let e=setInterval(()=>h(Date.now()),1e3);return()=>clearInterval(e)},[c]),(0,s.useEffect)(()=>{let e=new Set(i.map(e=>e.commandId));for(let[t,r]of(j(t=>{let r=new Set([...t].filter(t=>e.has(t)));return r.size===t.size?t:r}),w.current))e.has(t)||(clearTimeout(r),w.current.delete(t))},[i]),(0,s.useEffect)(()=>{let e=w.current;return()=>{for(let t of e.values())clearTimeout(t)}},[]);let S=(0,s.useCallback)(e=>{N(),a(e.projectCwd,e.commandId)},[N,a]),M=(0,s.useCallback)(e=>{b(null),j(t=>new Set(t).add(e.commandId));let t=()=>{w.current.delete(e.commandId),j(t=>{let r=new Set(t);return r.delete(e.commandId),r}),(0,E.oR)(l("runningTerminals.stopFailed"),"error")};m.t4.runPromiseExit((0,_.px)(e.commandId)).then(r=>{"Success"!==r._tag?t():r.value.interrupted?w.current.set(e.commandId,setTimeout(t,3e3)):d()})},[d,l]);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{if("Escape"===e.key){e.preventDefault(),g?b(null):N();return}if(0===y.length)return;let t=y.findIndex(e=>e.commandId===f);if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();let r="ArrowDown"===e.key?1:-1,n=t<0?r>0?0:y.length-1:(t+r+y.length)%y.length;p(y[n].commandId),b(null);return}let r=t>=0?y[t]:null;r&&("Enter"===e.key?(e.preventDefault(),g===r.commandId?M(r):S(r)):("Delete"===e.key||"Backspace"===e.key)&&(e.preventDefault(),v.has(r.commandId)||b(r.commandId)))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[c,y,f,g,v,N,S,M]);let L=e=>{var t,r;let s,o,a,i,d=v.has(e.commandId),c=g===e.commandId,u=(t=e.cwd,r=e.projectCwd,t&&t!==r?t.startsWith(r+"/")?t.slice(r.length+1):t:""),m=e.title||e.command.split("\n")[0];return(0,n.jsxs)("div",{"data-running-terminal":e.commandId,onClick:()=>{d||S(e)},onMouseEnter:()=>p(e.commandId),title:`${e.command}
8
8
  pid ${e.pid}`,className:`group rounded-md px-3 py-2 transition-colors ${d?"opacity-50 cursor-default":"cursor-pointer"} ${!d&&f===e.commandId?"bg-hover":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0 font-mono text-[10px] px-1 rounded bg-muted text-muted-foreground",children:e.shortId}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm font-mono text-foreground",children:m}),e.usePty&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-foreground-subtle",children:"PTY"}),(0,n.jsx)("span",{className:"flex-shrink-0 text-xs tabular-nums text-muted-foreground",children:(o=Math.floor((s=Math.max(0,Math.floor((x-new Date(e.timestamp).getTime())/1e3)))/86400),a=Math.floor(s%86400/3600),i=Math.floor(s%3600/60),o>0?`${o}d ${a}h`:a>0?`${a}h ${i}m`:i>0?`${i}m`:`${s}s`)}),d?(0,n.jsx)("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:l("runningTerminals.stopping")}):c?null:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),b(e.commandId)},className:"flex-shrink-0 px-1.5 py-0.5 text-xs rounded text-muted-foreground hover:text-destructive hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",children:l("runningTerminals.stop")})]}),(u||e.title)&&!c&&(0,n.jsxs)("div",{className:"mt-0.5 pl-9 text-xs text-muted-foreground truncate font-mono",children:[e.title?e.command.split("\n")[0]:u,e.title&&u?` \xb7 ${u}`:""]}),c&&(0,n.jsxs)("div",{className:"mt-1.5 flex items-center justify-end gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:l("runningTerminals.confirmStop")}),(0,n.jsx)("button",{onClick:()=>b(null),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:()=>M(e),className:"px-2 py-0.5 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:l("runningTerminals.stop")})]})]},e.commandId)},P=i.length;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:C,className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${e?"w-full justify-center":"w-full"}`,title:e?l("runningTerminals.title"):void 0,"data-testid":"running-terminals-entry",children:[(0,n.jsx)(W.A,{className:"w-5 h-5 flex-shrink-0"}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:l("runningTerminals.title")}),P>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border ${e?"absolute -top-1 -right-1":""}`,children:P})]}),c&&(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-scrim",onClick:N}),(0,n.jsxs)("div",{className:"relative w-[min(calc(100vw-2rem),max(42rem,60vw))] max-w-6xl h-[70vh] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden","data-testid":"running-terminals-board",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 items-center gap-3 min-w-0",children:(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:l("runningTerminals.title")})}),(0,n.jsx)("button",{onClick:N,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover 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===P?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:l("runningTerminals.empty")}):(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:k.map(e=>{var r;return(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center gap-1.5",children:[e.number>0&&(0,n.jsx)(z.B,{number:e.number,isActive:e.cwd===t}),(0,n.jsx)("span",{className:"truncate",title:e.cwd,children:(r=e.cwd).split(/[\\/]/).filter(Boolean).pop()||r}),e.cwd===t&&(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["\xb7 ",l("runningTerminals.currentProject")]})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(L)})]},e.cwd)})})}),(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-1.5 border-t border-border text-xs text-muted-foreground","data-testid":"running-terminals-status",children:[(0,n.jsx)("span",{className:"tabular-nums",children:l("runningTerminals.status",{count:P,projects:k.length})}),P>0&&(0,n.jsx)("span",{className:"truncate text-foreground-subtle",children:l("runningTerminals.keys")})]})]})]})]})}var V=r(3292),U=r(76900),K=r(72363),Q=r(94852),G=r(60285);let J=e=>"unread"===e?0:"loading"===e?1:2;function Y({className:e=""}){return(0,n.jsxs)("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("rect",{x:"4",y:"14",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("path",{d:"M17 3v8"}),(0,n.jsx)("path",{d:"M13 7h8"})]})}function Z({item:e,active:t,onClick:r,className:s=""}){return(0,n.jsx)("button",{type:"button",onClick:r,className:`h-8 w-8 rounded-md border bg-transparent text-muted-foreground hover:text-brand hover:border-brand/70 active:scale-95 transition-all flex items-center justify-center ${t?"border-brand/80 text-brand":"border-border/70"} ${s}`,title:`${e.title}
9
9
  ${e.path}`,children:e.icon?(0,n.jsx)("span",{className:"text-base leading-none",children:e.icon}):(0,n.jsx)(Q.A,{className:"w-4 h-4"})})}function X({collapsed:e,previews:t,activePath:r,onOpenApps:a,onShowPreview:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(null),u=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{u.current?.contains(e.target)||c(null)};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[d]);let m=t.length>4,x=m?t.slice(0,3):t.slice(0,4),h=m?t.slice(3):[],f=(0,n.jsxs)("button",{type:"button",onClick:()=>{a(),c(null)},className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:i("htmlApps.title"),children:[(0,n.jsx)("span",{className:"h-7 w-7 flex-shrink-0 rounded-md border border-border/70 bg-transparent flex items-center justify-center",children:(0,n.jsx)(Y,{className:"w-4 h-4"})}),(0,n.jsx)("span",{className:"min-w-0 flex-1",children:(0,n.jsx)("span",{className:"block text-xs font-medium truncate",children:i("htmlApps.title")})})]},"html-apps-list"),p=e=>{l(e),c(null)},g=e=>(0,n.jsxs)("div",{className:"max-h-[19.75rem] overflow-y-auto p-1.5 space-y-1",children:[f,e.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>p(e),className:`w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left hover:bg-hover transition-colors ${r===e.path?"text-brand":"text-muted-foreground hover:text-foreground"}`,title:e.path,children:[(0,n.jsx)("span",{className:"h-7 w-7 flex-shrink-0 rounded-md border border-border/70 bg-transparent flex items-center justify-center",children:e.icon?(0,n.jsx)("span",{className:"text-base leading-none",children:e.icon}):(0,n.jsx)(Q.A,{className:"w-4 h-4"})}),(0,n.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"block text-xs font-medium truncate",children:e.title}),(0,n.jsx)("span",{className:"block text-[10px] font-mono text-muted-foreground truncate",children:e.path})]})]},e.path))]});return e?(0,n.jsxs)("div",{ref:u,className:"relative p-2 border-t border-border",children:[(0,n.jsx)("button",{type:"button",onClick:()=>c(e=>"collapsed"===e?null:"collapsed"),className:`w-full h-8 rounded-md border bg-transparent text-muted-foreground hover:text-brand hover:border-brand/70 transition-colors flex items-center justify-center ${r?"border-brand/80 text-brand":"border-border/70"}`,title:i("htmlApps.title"),children:(0,n.jsx)(Y,{className:"w-4 h-4"})}),"collapsed"===d&&(0,n.jsx)("div",{className:"absolute left-full bottom-0 ml-2 w-64 rounded-lg border border-border bg-card shadow-lv3 z-50",children:g(t)})]}):(0,n.jsx)("div",{ref:u,className:"p-2 border-t border-border",children:(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-1.5",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"h-8 w-8 rounded-md border border-border/70 bg-transparent text-muted-foreground hover:text-brand hover:border-brand/70 active:scale-95 transition-all flex items-center justify-center",title:i("htmlApps.title"),children:(0,n.jsx)(Y,{className:"w-4 h-4"})}),x.map(e=>(0,n.jsx)(Z,{item:e,active:r===e.path,onClick:()=>p(e)},e.path)),m&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{type:"button",onClick:()=>c(e=>"more"===e?null:"more"),className:"h-8 w-8 rounded-md border border-border/70 bg-transparent text-muted-foreground hover:text-brand hover:border-brand/70 transition-colors flex items-center justify-center",title:i("common.loadMore"),children:(0,n.jsx)(G.A,{className:"w-4 h-4"})}),"more"===d&&(0,n.jsx)("div",{className:"absolute left-0 bottom-full mb-2 w-64 rounded-lg border border-border bg-card shadow-lv3 z-50",children:g(h)})]})]})})}function ee({projects:e,activeIndex:t,collapsed:r,currentCwd:d,onSelectProject:c,onRemoveProject:u,onReorderProjects:x,onToggleCollapse:h,onOpenSessionBrowser:f,onOpenSettings:p,onOpenNote:g,onOpenSkills:b,onOpenBots:v,onOpenApps:j,htmlAppPreviews:w,activeHtmlAppPreviewPath:k,onShowHtmlAppPreview:y,onSwitchProject:C,onFocusTerminal:S,onResolveSessionNumbers:L,sessionOrders:$,sessionNumbers:T}){let R,I,{t:F,i18n:B}=(0,o.Bd)(),D=(0,s.useMemo)(()=>e.map(e=>e.cwd),[e]),{latest:A,hasUpdate:W}=function(){let[e,t]=(0,s.useState)(),[r,n]=(0,s.useState)();(0,s.useEffect)(()=>{let e=!1;m.t4.runPromiseExit((0,U.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,a]=(0,s.useState)(!1);(0,s.useEffect)(()=>{a(!0===window.__COCKPIT_FORCE_UPDATE__)},[]);let l=!!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:o?r??"999.0.0":r,hasUpdate:!!o||l}}(),[z,_]=(0,s.useState)(!1),Q=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!z)return;let e=e=>{Q.current?.contains(e.target)||_(!1)},t=()=>_(!1);return document.addEventListener("mousedown",e,!0),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e,!0),window.removeEventListener("blur",t)}},[z]);let G=(0,s.useCallback)(()=>{navigator.clipboard.writeText("cockpit update"),(0,E.oR)(F("workspace.upgradeCommandCopied")),_(!1)},[F]),{isUpdating:Y,start:Z}=(R=(0,s.useSyncExternalStore)(K.N4,K.fX,K.fX),I=(0,s.useCallback)(()=>{(0,K._I)()},[]),{isUpdating:R.visible&&"done"!==R.stage&&"failed"!==R.stage,start:I}),et=(0,s.useCallback)(()=>{_(!1),Z()},[Z]),{pinnedSessions:er,unpinSession:en,updateTitle:es,reorder:eo}=(0,V.P)(),{tasks:ea,unreadCount:el,reload:ei,pauseTask:ed,resumeTask:ec,triggerTask:eu,deleteTask:em,updateTask:ex,markRead:eh}=(0,P.nS)(),[ef,ep]=(0,s.useState)(null),[eg,eb]=(0,s.useState)(null),[ev,ej]=(0,s.useState)([]),ew=(0,s.useRef)(ev);(0,s.useEffect)(()=>{ew.current=ev});let ek=(0,s.useRef)(ei);(0,s.useEffect)(()=>{ek.current=ei});let ey=(0,s.useCallback)(e=>{try{if("task-fired"===e.type)return void ek.current();let{data:t}=e;if(!t)return;ej(t.sessions||[])}catch{}},[]);(0,O.h)({url:"/ws/global-state",onMessage:ey});let eN=new Set(ev.filter(e=>"loading"===e.status).map(e=>e.cwd)),eC=new Set(ev.filter(e=>"unread"===e.status).map(e=>e.cwd)),eS=(0,s.useMemo)(()=>{let t=new Map;for(let r of e){let e=$[r.cwd]??[],n=ev.filter(e=>e.cwd===r.cwd).map(t=>({session:t,position:e.indexOf(t.sessionId)})).filter(({session:e,position:t})=>t>=0||"loading"===e.status||"unread"===e.status).sort((e,t)=>{let r=J(e.session.status)-J(t.session.status);return 0!==r?r:t.session.lastActive-e.session.lastActive}),s=n.find(({session:e})=>2===J(e.status)),o=n.filter(({session:e})=>2>J(e.status)||e===s?.session).slice(0,3).sort((e,t)=>e.position<0?t.position<0?0:1:t.position<0?-1:e.position-t.position).map(({session:e,position:t})=>({sessionId:e.sessionId,label:t>=0?String(t+1):"\xb7",status:"loading"===e.status?"loading":"unread"===e.status?"unread":"normal",...e.bot?{bot:e.bot}:{}}));o.length>0&&t.set(r.cwd,o)}return t},[e,ev,$]),eM=(0,s.useCallback)(e=>{ep(e)},[]),eL=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==ef&&ef!==t&&eb(t)},[ef]),eE=(0,s.useCallback)(t=>{if(null!==ef&&ef!==t){let r=[...e],[n]=r.splice(ef,1);r.splice(t,0,n),x(r)}ep(null),eb(null)},[ef,e,x]),eP=(0,s.useCallback)(()=>{ep(null),eb(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-hover transition-colors ${r?"justify-center":""}`,onClick:f,title:r?F("workspace.openProject"):void 0,children:[(0,n.jsx)("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)("path",{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"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:F("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-popover shadow-lv1 text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:h,title:F("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-popover shadow-lv1 text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:h,title:F("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 a;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>eM(s),onDragOver:e=>eL(e,s),onDrop:()=>eE(s),onDragEnd:eP,className:`${eg===s?"border-t-2 border-brand":""} ${ef===s?"opacity-50":""}`,children:(0,n.jsx)(i.ProjectItem,{index:s,name:(a=(o=e.cwd).split("/").filter(Boolean))[a.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:eC.has(e.cwd),isLoading:eN.has(e.cwd),sessionBadges:eS.get(e.cwd),onClick:()=>c(s),onSelectSession:t=>C(e.cwd,t),onRemove:()=>u(s),onOpenNote:()=>g(e.cwd)})},e.cwd)})}),(0,n.jsx)(X,{collapsed:r,previews:w,activePath:k,onOpenApps:j,onShowPreview:y}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(N,{currentCwd:d,onSwitchProject:C,onResolveSessionNumbers:L,collapsed:r,sessions:ev}),(0,n.jsx)(M,{collapsed:r,pinnedSessions:er,sessionNumbers:T,currentCwd:d,onSwitchProject:C,onUnpin:en,onUpdateTitle:es,onReorder:eo}),(0,n.jsx)(H,{collapsed:r,tasks:ea,unreadCount:el,sessionNumbers:T,onSwitchProject:C,onPause:ed,onResume:ec,onTrigger:eu,onDelete:em,onMarkRead:eh,onUpdateTask:ex}),(0,n.jsx)(q,{collapsed:r,currentCwd:d,projectOrder:D,onFocusTerminal:S}),(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-hover transition-colors ${r?"justify-center":""}`,onClick:()=>g(),title:r?F("workspace.notes"):void 0,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:F("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-hover transition-colors ${r?"justify-center":""}`,onClick:b,title:r?F("workspace.skills"):void 0,children:[(0,n.jsx)(a.A,{className:"w-5 h-5 flex-shrink-0"}),!r&&(0,n.jsx)("span",{className:"text-sm",children:F("workspace.skills")})]}),(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-hover transition-colors ${r?"justify-center":""}`,onClick:v,title:r?F("workspace.bots"):void 0,children:[(0,n.jsx)(l.A,{className:"w-5 h-5 flex-shrink-0"}),!r&&(0,n.jsx)("span",{className:"text-sm",children:F("workspace.bots")})]}),(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-hover transition-colors ${r?"justify-center":""}`,onClick:p,title:F("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&&W&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500",title:A?F("workspace.updateAvailable",{version:A}):void 0})]}),!r&&(0,n.jsx)("span",{className:"flex-1 text-sm",children:F("workspace.settings")}),!r&&W&&A&&(0,n.jsxs)("div",{ref:Q,className:"relative -mr-2",children:[(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),_(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:F("workspace.updateAvailable",{version:A}),"aria-label":F("workspace.updateAvailable",{version:A}),children:["v",A]}),z&&(0,n.jsxs)("div",{className:"absolute left-full bottom-full ml-2 mb-1 w-56 rounded-lg border border-border bg-popover shadow-lv2 p-2 z-50",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2 px-1",children:F("workspace.updateAvailable",{version:A})}),(0,n.jsxs)("button",{type:"button",onClick:et,disabled:Y,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left\n hover:bg-hover transition-colors disabled:opacity-60 disabled:cursor-default",children:[Y?(0,n.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0 animate-spin",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-8v4a4 4 0 00-4 4H4z"})]}):(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:"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)("span",{className:"flex-1",children:Y?F("workspace.updating"):F("workspace.updateNow")})]}),(0,n.jsxs)("button",{type:"button",onClick:G,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left hover:bg-hover 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:F("workspace.copyUpgradeCommand")})]}),(0,n.jsxs)("a",{href:`https://opencockpit.dev/${B.language?.startsWith("zh")?"zh":"en"}/changelog/`,target:"_blank",rel:"noopener",onClick:()=>_(!1),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-hover 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:F("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/${B.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-hover transition-colors",onClick:e=>e.stopPropagation(),title:F("workspace.help"),"aria-label":F("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})]})})]})]})]})}},7578:(e,t,r)=>{r.d(t,{S:()=>a,l:()=>l});var n=r(95155),s=r(68287),o=r(16147);function a(e){return"loading"===e||"unread"===e?e:"normal"}function l({projectNumber:e,sessionNumber:t,coordinate:r,status:a="normal",statusLabel:i,bot:d,className:c=""}){if(r){let[n,s]=r.split(".");e??=n,t??=s}if(null==e&&null==t&&"normal"!==a&&(t="\xb7"),null==e&&null==t)return null;let u=[e,t].filter(e=>null!=e).join(".");return(0,n.jsxs)("span",{className:`inline-flex items-center gap-1 font-mono text-[9px] font-medium leading-none tabular-nums flex-shrink-0 ${c}`,"aria-label":i?`${u} \xb7 ${i}`:u,children:[null!=e&&(0,n.jsx)("span",{className:`flex h-4 w-4 items-center justify-center border rounded-[4px] ${(0,s.ci)("normal",!1)}`,children:e}),null!=t&&(0,n.jsx)(o.w,{wash:(0,s.JQ)(a,!1),ring:(0,s.QV)(a),bot:d,title:i,children:t})]})}},12786:(e,t,r)=>{r.d(t,{L:()=>s,Mu:()=>o});var n=r(41463);function s(){return!("u"<typeof navigator)&&(/Mac|iPhone|iPad/.test(navigator.platform||"")||navigator.userAgentData?.platform==="macOS")}function o(){return s()?"⌘":"Ctrl+"}n.platform,n.platform,n.platform},16147:(e,t,r)=>{r.d(t,{w:()=>o});var n=r(95155);let s="font-mono text-[9px] font-medium leading-none tabular-nums transition-colors";function o({children:e,wash:t,ring:r="",bot:a,className:l="",tooltip:i,title:d,role:c,ariaLabel:u,ariaHidden:m}){let x={title:d,role:c,"aria-label":u,"aria-hidden":m?"true":void 0,"data-tooltip":i??(a?`@${a}`:void 0)};return a?(0,n.jsx)("span",{className:`relative -m-0.5 flex h-5 w-5 flex-shrink-0 items-center justify-center ${r} ${l}`,...x,children:(0,n.jsx)("span",{className:`session-number-bot flex h-full w-full items-center justify-center ${s} ${t}`,children:(0,n.jsx)("span",{className:"translate-y-[1.5px]",children:e})})}):(0,n.jsx)("span",{className:`flex h-4 w-4 flex-shrink-0 items-center justify-center rounded-full border ${s} ${r} ${t} ${l}`,...x,children:e})}},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),d=r(53853),c=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.DP)(),g=(0,d.G)(),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&c.t4.runPromiseExit((0,m.M5)()).then(e=>{"Success"===e._tag&&e.value.language&&C(e.value.language)})},[e]);let S=(0,s.useCallback)(e=>{C(e),c.t4.runFork((0,m.DZ)({language:e}).pipe(u.NWQ(()=>u.rIH)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;h.changeLanguage(t)},[h]),M=g?"installed":"not-installed",L=g?.version??null;if((0,s.useEffect)(()=>{e&&c.t4.runPromiseExit((0,m.Wr)()).then(e=>{"Success"===e._tag&&(e.value.version&&w(e.value.version),e.value.agents&&y(e.value.agents))})},[e]),(0,s.useEffect)(()=>{e&&c.t4.runPromiseExit((0,m.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&v(e.value.path)})},[e]),!e)return null;let E=[{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-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-2xl 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-hover 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:E.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:()=>S(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${N===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"===M?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===M&&`${r("settings.extensionInstalled")}${L?` (v${L})`:""}`,"not-installed"===M&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==M&&(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"===M&&(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}`:""]}),(k?.claude||k?.codex)&&(0,n.jsx)("p",{className:"text-muted-foreground/60",children:[k.claude&&`Claude Code ${k.claude}`,k.codex&&`Codex ${k.codex}`,r("settings.agentsBundled")].filter(Boolean).join(" \xb7 ")}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},23121:(e,t,r)=>{r.d(t,{P_:()=>m,Q_:()=>x,nS:()=>p});var n=r(12115),s=r(95045),o=r(75346),a=r(49433),l=r(69809),i=r(34075),d=r(86957),c=r(82680);let u=(e,t,r)=>a.$mh({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 c.uV({message:`${t} ${e} failed`,cause:r})});function m(e){return e.split("/").pop()||e}function x(e){return e.resolvedPrompt||e.message||e.taskFile||""}let h="SCHEDULED_TASKS_CHANGED";function f(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:h},"*")}catch{}})}function p(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useCallback)(()=>{let e;d.t4.runPromise((e="/api/scheduled-tasks",a.$mh({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new c.uV({message:`fetch ${e} failed`,cause:t})})).pipe(a.YWq({onSuccess:e=>{t(e.tasks??[]),s(e.unreadCount??0)},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{o()},[o]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===h&&o()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[o]);let m=(0,n.useCallback)(async e=>{let t=await d.t4.runPromiseExit(u("/api/scheduled-tasks","POST",{language:l.A.language,...e}));if("Success"!==t._tag)return null;let r=t.value;return r.task?(o(),f(),r.task):null},[o]),x=(0,n.useCallback)(async e=>{await d.t4.runPromise(u("/api/scheduled-tasks","PATCH",e).pipe(a.NLW).pipe(a.NWQ(()=>a.rIH))),o(),f()},[o]),p=(0,n.useCallback)(e=>x({id:e,action:"pause"}),[x]),g=(0,n.useCallback)(e=>x({id:e,action:"resume"}),[x]),b=(0,n.useCallback)(async e=>{await d.t4.runPromise(u("/api/scheduled-tasks","DELETE",{id:e}).pipe(a.NLW).pipe(a.as(!0),a.DM4(()=>!1)))||(0,i.oR)(l.A.t("scheduledTasks.deleteFailed"),"error"),o(),f()},[o]),v=(0,n.useCallback)((e,t)=>x({id:e,action:"update",fields:{...t,language:l.A.language}}),[x]),j=(0,n.useCallback)(e=>x({id:e,action:"trigger"}),[x]),w=(0,n.useCallback)(e=>x({id:e,action:"markRead"}),[x]);return{tasks:e,unreadCount:r,reload:o,createTask:m,pauseTask:p,resumeTask:g,triggerTask:j,deleteTask:b,updateTask:v,markRead:w,markAllRead:(0,n.useCallback)(()=>x({action:"markAllRead"}),[x]),reorderTasks:(0,n.useCallback)(e=>x({action:"reorder",fields:{orderedIds:e}}),[x])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>h});var n=r(95155),s=r(12115),o=r(68287),a=r(16147),l=r(57125),i=r(92689),d=r(94287),c=r(64428),u=r(79114);function m({number:e,status:t,statusLabel:r,isActive:s,pinned:l,bot:i}){let d="normal"!==t?(0,o.JQ)(t,s):l?"border-transparent bg-amber-9 text-black/80":s?"border-transparent bg-brand/25 text-brand":"border-transparent bg-muted-foreground/25 text-foreground/75";return(0,n.jsx)(a.w,{wash:d,ring:(0,o.QV)(t),bot:i,role:"normal"!==t?"status":void 0,ariaLabel:i?[r,`Bot session: @${i}`].filter(Boolean).join(" \xb7 "):r,ariaHidden:"normal"===t&&!i,children:e})}function x({onNewTab:e,onNewCodexTab:t,onNewKimiTab:r,onNewGlmTab:o,onNewOllamaTab:a,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),m=(0,s.useRef)(null),h=(0,s.useRef)(null),[f,p]=(0,s.useState)({top:0,right:0}),g=(0,c.F2)();return(0,s.useEffect)(()=>{if(!d)return;let e=e=>{h.current&&!h.current.contains(e.target)&&m.current&&!m.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:m,onClick:()=>{if(!d&&m.current){let e=m.current.getBoundingClientRect(),t=g?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;p({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-hover 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)(c.ZL,{children:(0,n.jsx)("div",{ref:h,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lv2 py-1 min-w-[140px]",style:{top:f.top,right:f.right},children:l.CX.map(s=>(0,n.jsxs)("button",{onClick:()=>{u(!1),"codex"===s?t?.():"kimi"===s?r?.():"glm"===s?o?.():"ollama"===s?a?.():"deepseek"===s?i?.():e()},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)(l.eV,{engine:s,className:"h-3.5 w-3.5"}),l.H[s]]},s))})})]})}function h({tabs:e,selectedTabId:t,unreadTabs:r,globalLoadingTabs:s,dragTabIndex:o,dragOverTabIndex:a,isPinned:l,onSwitchTab:c,onCloseTab:f,onCloseAllTabs:p,onNewTab:g,onNewCodexTab:b,onNewKimiTab:v,onNewGlmTab:j,onNewOllamaTab:w,onNewDeepseekTab:k,onOpenProjectSessions:y,onDragStart:N,onDragOver:C,onDrop:S,onDragEnd:M,sideBySide:L,onToggleSideBySide:E}){let{t:P}=(0,u.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((e,u)=>{let x=e.id===t,h=l?.(e.id)??!1,p=e.isLoading||s.has(e.id)?"loading":r.has(e.id)&&!x?"unread":"normal";return(0,n.jsx)(d.m,{content:e.title,delay:200,className:"flex-1 min-w-16 max-w-[260px]",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>N(u),onDragOver:e=>C(e,u),onDrop:()=>S(u),onDragEnd:M,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 ${x?"border-brand bg-slate-4 text-foreground font-medium":"border-transparent text-muted-foreground hover:bg-secondary/50"} ${o===u?"opacity-50":""} ${a===u?"border-l-2 border-brand":""}`,onClick:()=>c(e.id),children:[(0,n.jsx)("div",{className:"h-4 w-4 -translate-x-1 flex-shrink-0",children:(0,n.jsx)(m,{number:u+1,status:p,statusLabel:"loading"===p?P("sessions.running"):"unread"===p?P("sessions.done"):void 0,isActive:x,pinned:h,bot:e.bot})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.title}),(0,n.jsxs)("span",{className:"relative ml-1 h-4 w-4 translate-x-1 shrink-0",children:[(0,n.jsx)("span",{className:"absolute inset-0 inline-flex items-center justify-center transition-opacity group-hover:opacity-0 group-focus-within:opacity-0",children:(0,n.jsx)(i.S,{engine:e.engine,size:"sm"})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),f(e.id)},className:"absolute inset-0 flex items-center justify-center rounded opacity-0 transition-opacity hover:bg-muted group-hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","data-tooltip":P("tabBar.closeTab"),"aria-label":P("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"h-3 w-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"})})})]})]})},e.id)}),(0,n.jsx)(x,{onNewTab:g,onNewCodexTab:b,onNewKimiTab:v,onNewGlmTab:j,onNewOllamaTab:w,onNewDeepseekTab:k}),p&&(0,n.jsx)("button",{onClick:p,className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-destructive hover:bg-hover rounded transition-colors",title:P("tabBar.closeAll"),"aria-label":P("tabBar.closeAll"),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:"M6 18L18 6M6 6l12 12"})})}),y&&(0,n.jsx)("button",{onClick:y,className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:P("sessions.projectSessions"),"aria-label":P("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"})})}),E&&(0,n.jsx)("button",{onClick:E,className:"flex-shrink-0 p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:L?P("chat.singlePane"):P("chat.splitPane"),"aria-label":L?P("chat.singlePane"):P("chat.splitPane"),"aria-pressed":L,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:"3",y:"4",width:"18",height:"16",rx:"2",strokeWidth:2}),!L&&(0,n.jsx)("path",{strokeWidth:2,d:"M12 4v16"})]})})]})})}},27068:(e,t,r)=>{r.d(t,{Providers:()=>g});var n=r(95155),s=r(47617),o=r(3238),a=r(34075),l=r(12115),i=r(47650);function d(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return e;t=t.parentElement}return null}function c(){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,c]=(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=d(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=d(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),c({left:s,top:a})},[e]),u&&e)?(0,i.createPortal)((0,n.jsx)("div",{ref:o,className:"fixed z-[9999] max-w-[min(80vw,64rem)] px-2 py-1 bg-tooltip text-tooltip-foreground text-xs font-mono rounded shadow-lv3 border border-line-1 whitespace-pre-wrap break-words pointer-events-none",style:{left:a.left,top:a.top},children:e.text}),document.body):null}var u=r(79114),m=r(72363),x=r(2111);let h=new Set(["preparing","installing","repairing","rolling-back","restarting"]);function f(){return(0,n.jsxs)("svg",{className:"h-4 w-4 flex-shrink-0 animate-spin text-brand",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-8v4a4 4 0 00-4 4H4z"})]})}function p(){let{t:e}=(0,u.Bd)(),t=(0,l.useSyncExternalStore)(m.N4,m.fX,m.fX),[r,s]=(0,l.useState)(()=>Date.now()),o=(0,l.useRef)(!1),{stale:i}=function(){let[e,t]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let r=window.__COCKPIT_BUILD_ID__;if(!r)return;let n=!1,s=async()=>{if(!n&&!e)try{let e=await fetch("/api/health",{cache:"no-store",signal:AbortSignal.timeout(3e3)});if(!e.ok)return;let s=await e.json();if(!s.buildId)return;n||s.buildId===r||t(!0)}catch{}},o=(0,x.D)(s);return()=>{n=!0,o()}},[e]),{stale:e}}(),[d,c]=(0,l.useState)(!1),[p,g]=(0,l.useState)(!1);(0,l.useEffect)(()=>{g(window.self===window.top)},[]),(0,l.useEffect)(()=>{p&&!o.current&&(o.current=!0,(0,m.$2)())},[p]);let b=t.visible&&h.has(t.stage);(0,l.useEffect)(()=>{if(!b)return;s(Date.now());let e=window.setInterval(()=>s(Date.now()),1e3);return()=>window.clearInterval(e)},[b]);let v=(0,l.useCallback)(()=>{navigator.clipboard.writeText(t.fixCommand),(0,a.oR)(e("workspace.updateCardFixCopied"))},[t.fixCommand,e]),j=!t.visible&&i&&!d;if(!p||!t.visible&&!j)return null;let w=t.startedAt?Math.max(0,Math.round((r-t.startedAt)/1e3)):0,k=t.baselineMs?Math.round(t.baselineMs/1e3):null,y=j||"done"===t.stage,N=j||!h.has(t.stage),C=y&&!t.upToDate,S=j?e("workspace.serverRestarted"):(()=>{switch(t.stage){case"preparing":return e("workspace.updateCardPreparing");case"installing":return e("workspace.updateCardInstalling");case"repairing":return e("workspace.updateCardRepairing");case"rolling-back":return e("workspace.updateCardRollingBack");case"restarting":return e("workspace.updateCardRestarting");case"done":if(!t.installedVersion)return e("workspace.updateComplete");return t.upToDate?e("workspace.updateCardUpToDate",{version:t.installedVersion}):e("workspace.updateCardDone",{version:t.installedVersion});case"failed":return e("workspace.updateFailed")}})();return(0,n.jsx)("div",{className:"fixed top-4 right-4 z-[110] w-80 rounded-lg border border-border\n bg-background/95 p-3 shadow-lv2 backdrop-blur",role:"status","aria-live":"polite",children:(0,n.jsxs)("div",{className:"flex items-start gap-2.5",children:[b?(0,n.jsx)(f,{}):y?(0,n.jsx)("svg",{className:"h-4 w-4 flex-shrink-0 text-brand",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:"h-4 w-4 flex-shrink-0 text-destructive",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v4m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm text-foreground",children:S}),b&&(0,n.jsxs)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:[e("workspace.updateCardElapsed",{seconds:w}),null!==k&&(0,n.jsxs)(n.Fragment,{children:[" \xb7 ",e("workspace.updateCardBaseline",{seconds:k})]})]}),b&&!t.live&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground/80",children:e("workspace.updateCardNoLiveStatus")}),b&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateRestartNote")}),!j&&"failed"===t.stage&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"mt-1 break-words text-[11px] leading-snug text-muted-foreground",children:t.error}),t.rolledBack&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateCardRolledBack")}),(0,n.jsx)("div",{className:"mt-2 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateCardManualHint")}),(0,n.jsx)("code",{className:"mt-1 block break-all rounded bg-hover px-2 py-1.5 text-[11px]\n leading-snug text-foreground",children:t.fixCommand}),(0,n.jsx)("button",{type:"button",onClick:v,className:"mt-1.5 w-full rounded-md border border-border px-2.5 py-1.5 text-xs\n text-foreground transition-colors hover:bg-hover",children:e("workspace.updateCardCopyFix")}),t.logPath&&(0,n.jsx)("div",{className:"mt-1.5 break-all text-[11px] leading-snug text-muted-foreground/80",children:e("workspace.updateCardLogHint",{path:t.logPath})})]}),C&&(0,n.jsx)("button",{type:"button",onClick:()=>window.location.reload(),className:"mt-2 w-full rounded-md bg-primary px-2.5 py-1.5 text-xs\n text-primary-foreground transition-opacity hover:opacity-90",children:e("workspace.reloadNow")})]}),N&&(0,n.jsx)("button",{type:"button",onClick:()=>{c(!0),j||(0,m.fZ)()},"aria-label":e("common.close"),className:"-mr-1 -mt-1 rounded p-1 text-muted-foreground transition-colors hover:bg-hover",children:(0,n.jsx)("svg",{className:"h-3.5 w-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"})})})]})})}function g({children:e}){return(0,l.useEffect)(()=>{let e=e=>{e.preventDefault()};return document.addEventListener("contextmenu",e),()=>document.removeEventListener("contextmenu",e)},[]),(0,n.jsx)(s.I18nProvider,{children:(0,n.jsx)(o.NP,{children:(0,n.jsxs)(a.tE,{children:[e,(0,n.jsx)(c,{}),(0,n.jsx)(p,{})]})})})}},39872:(e,t,r)=>{r.d(t,{B:()=>o});var n=r(95155),s=r(68287);function o({number:e,status:t="normal",isActive:r=!1}){return(0,n.jsx)("span",{className:`flex h-[18px] w-[18px] flex-shrink-0 items-center justify-center rounded-[4px] border font-mono text-[10px] font-medium leading-none tabular-nums transition-colors ${(0,s.ci)(t,r)}`,"aria-hidden":"true",children:e})}},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}},45720:(e,t,r)=>{r.d(t,{X:()=>n});function n(e,t){switch(e){case"codex":return`codex resume ${t}`;case"kimi":case"glm":case"deepseek":case"ollama":return`${e} ${t}`;default:return`claude -r ${t}`}}},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>d});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(86957),i=r(76900);function d({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})}},52153:(e,t,r)=>{r.d(t,{SessionBrowser:()=>g});var n=r(95155),s=r(12115),o=r(79114),a=r(66109),l=r(95045),i=r(75346),d=r(86957),c=r(76900),u=r(64702);let m=(e,t)=>e.endsWith(t)?e:e+t,x=(0,s.memo)(function({entry:e,index:t,highlighted:r,top:s,onEnter:o,onPick:a,onHover:l}){return(0,n.jsxs)("div",{role:"option","aria-selected":r,onClick:()=>o(e.path),onDoubleClick:()=>a(e.path),onMouseMove:()=>l(t),style:{position:"absolute",top:s,left:0,right:0,height:30},className:`flex items-center gap-2 px-3 text-xs cursor-pointer select-none ${r?"bg-hover text-foreground":"text-foreground"} ${e.hidden?"opacity-60":""}`,children:[(0,n.jsx)("svg",{className:"w-4 h-4 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:"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 truncate",children:e.name}),e.git&&(0,n.jsx)("span",{className:"shrink-0 text-[10px] text-muted-foreground border border-border rounded px-1",children:"git"})]})});function h({onPick:e}){let t,r,a,{t:l}=(0,o.Bd)(),[i,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(-1),N=(0,s.useRef)(null),C=(0,s.useRef)(null),S=(0,s.useRef)(0),M=p?.sep??"/",{base:L,prefix:E}=(t="\\"===M?Math.max(i.lastIndexOf("/"),i.lastIndexOf("\\")):i.lastIndexOf("/"),r=i.slice(0,t+1),a=i.slice(t+1),""===r&&"~"===a?{base:"~",prefix:""}:{base:r,prefix:a});(0,s.useEffect)(()=>{let e=++S.current;d.t4.runPromiseExit((0,c.fz)("")).then(t=>{"Success"===t._tag&&e===S.current&&(g(t.value),v(m(t.value.path,t.value.sep)),f(m(t.value.path,t.value.sep)))}),N.current?.focus()},[]),(0,s.useEffect)(()=>{if(null===b||L===b)return;let e=setTimeout(()=>{let e=++S.current;d.t4.runPromiseExit((0,c.fz)(L)).then(t=>{"Success"===t._tag&&e===S.current&&(g(t.value),v(L))})},60);return()=>clearTimeout(e)},[L,b]);let P=b!==L,$=(0,s.useMemo)(()=>{if(!p)return[];let e=E.toLowerCase(),t=p.dirs.filter(t=>j||!t.hidden||e.startsWith("."));return e?[...t.filter(t=>t.name.toLowerCase().startsWith(e)),...t.filter(t=>!t.name.toLowerCase().startsWith(e)&&t.name.toLowerCase().includes(e))]:t},[p,E,j]);(0,s.useEffect)(()=>{y(E&&$.length>0?0:-1)},[E,$]);let T=(0,s.useMemo)(()=>!p||p.error||P?null:E?$.find(e=>e.name.toLowerCase()===E.toLowerCase())?.path??null:p.path,[p,E,$,P]),R=(0,s.useCallback)(e=>{f(m(e,M)),N.current?.focus()},[M]),I=(0,u.Te)({count:$.length,getScrollElement:()=>C.current,estimateSize:()=>30,overscan:8});(0,s.useEffect)(()=>{k>=0&&I.scrollToIndex(k)},[k,I]);let F=p?.error&&!P?l(`folderPicker.${p.error}`):null;return(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col gap-2 p-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:N,type:"text",value:i,onChange:e=>f(e.target.value),onKeyDown:t=>{if("Enter"===t.key&&(t.metaKey||t.ctrlKey))t.preventDefault(),T&&e(T);else if("ArrowDown"===t.key)t.preventDefault(),y(e=>Math.min(e+1,$.length-1));else if("ArrowUp"===t.key)t.preventDefault(),y(e=>Math.max(e-1,0));else if("Tab"===t.key||"Enter"===t.key){let e=$[k];e?(t.preventDefault(),R(e.path)):"Tab"===t.key&&t.preventDefault()}},placeholder:l("folderPicker.placeholder"),spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"flex-1 min-w-0 px-2.5 py-1.5 text-xs font-mono border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>T&&e(T),disabled:!T,"data-tooltip":T??void 0,className:"shrink-0 px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:l("folderPicker.open")})]}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 min-h-6 overflow-x-auto text-xs text-muted-foreground whitespace-nowrap",children:p?.segments.map((e,t)=>(0,n.jsxs)("span",{className:"flex items-center",children:[t>1&&(0,n.jsx)("span",{className:"px-0.5 text-foreground-subtle",children:"›"}),(0,n.jsx)("button",{onClick:()=>R(e.path),className:"px-1 py-0.5 rounded hover:bg-hover hover:text-foreground transition-colors",children:e.name})]},e.path))}),(0,n.jsx)("div",{ref:C,role:"listbox",className:`flex-1 min-h-0 overflow-y-auto border border-border rounded transition-opacity ${P?"opacity-60":""}`,children:F?(0,n.jsx)("div",{className:"p-3 text-xs text-red-11",children:F}):p&&0===$.length?(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:l(E?"folderPicker.noMatch":"folderPicker.empty")}):(0,n.jsx)("div",{style:{height:I.getTotalSize(),position:"relative"},children:I.getVirtualItems().map(t=>(0,n.jsx)(x,{entry:$[t.index],index:t.index,highlighted:t.index===k,top:t.start,onEnter:R,onPick:e,onHover:y},$[t.index].path))})}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[p&&(0,n.jsx)("button",{onClick:()=>R(p.home),className:"px-2 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:"~"}),p?.roots.map(e=>(0,n.jsx)("button",{onClick:()=>R(e),className:"px-2 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors font-mono",children:e},e))]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 text-muted-foreground cursor-pointer select-none",children:[(0,n.jsx)("input",{type:"checkbox",checked:j,onChange:e=>w(e.target.checked)}),l("folderPicker.showHidden")]}),(0,n.jsx)("span",{className:"hidden md:inline text-foreground-subtle",children:l("folderPicker.hint")})]})]})}var f=r(7578),p=r(92689);function g({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u,sessionNumbers:m={},projectNumbers:x={}}){let{t:b}=(0,o.Bd)(),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)({}),[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(null),[E,P]=(0,s.useState)(""),$=(0,s.useRef)(null),T=(0,s.useCallback)(async()=>{S(!0),L(null),N({});let e=await d.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?k(e.value):L("Failed to load projects"),S(!1)},[]),R=(0,s.useCallback)(async e=>{N(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await d.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?N(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):N(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),I=(0,s.useCallback)(e=>{let t=y[e];t?.isExpanded?N(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?N(t=>({...t,[e]:{...t[e],isExpanded:!0}})):R(e)},[y,R]);(0,s.useEffect)(()=>{e&&(j(!1),T(),setTimeout(()=>{$.current?.focus(),$.current?.select()},100))},[e,T]);let F=(0,s.useCallback)(e=>{u?.(e),t()},[u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&(v?j(!1):t())};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,v,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-scrim",onClick:t}),(0,n.jsxs)("div",{className:v?"relative w-full max-w-[min(42rem,calc((100vw_-_28rem)*0.9))] h-[min(70vh,36rem)] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden":a.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[v?(0,n.jsxs)("button",{onClick:()=>j(!1),className:"flex items-center gap-1 text-sm font-medium text-foreground hover:text-brand transition-colors",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:"M15 19l-7-7 7-7"})}),b("folderPicker.title")]}):(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:b("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[!v&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:$,type:"text",placeholder:b("workspace.searchProjectPath"),value:E,onChange:e=>P(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),E&&(0,n.jsx)("button",{onClick:()=>{P(""),$.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:b("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&&!v&&(0,n.jsxs)("button",{onClick:()=>j(!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-hover transition-colors",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"})}),b("sessions.openFolder")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover 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"})})})]})]}),v?(0,n.jsx)(h,{onPick:F}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[C&&(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:b("workspace.loadingProjects")})]})}),M&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:M})}),!C&&!M&&0===w.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:b("workspace.projectNotFound")})}),!C&&!M&&w.filter(e=>e.fullPath.toLowerCase().includes(E.toLowerCase())).map(e=>{let t=y[e.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null},s=x[e.fullPath];return(0,n.jsxs)("div",{className:"mb-3",children:[(0,n.jsxs)("button",{onClick:()=>I(e.encodedPath),className:"w-full flex items-center gap-2 p-2 rounded hover:bg-hover 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"})}),s&&(0,n.jsx)(f.l,{projectNumber:s}),(0,n.jsx)("span",{className:"flex-1 text-xs font-medium text-foreground truncate","data-tooltip":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:b("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:a.jL,children:t.sessions.map(t=>{let s=t.path.split("/").pop()||"",o=t.sessionId||s.replace(".jsonl",""),a=m[`${e.fullPath}
10
- ${o}`],[d,c]=a?.split(".")??[];return(0,n.jsxs)("div",{onClick:()=>{var n;let s,o;return n=e.fullPath,s=t.path.split("/").pop()||"",o=t.sessionId||s.replace(".jsonl",""),void(r?r(n,o):(0,l.F)(i.n.OpenProject,{cwd:n,sessionId:o}))},className:"p-3 rounded border border-border hover:border-brand hover:shadow-lv2 cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(p.S,{engine:t.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate","data-tooltip":t.title,children:t.title}),a&&(0,n.jsx)(f.l,{projectNumber:d,sessionNumber:c,bot:t.bot,className:"ml-auto"})]}),(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","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-foreground-subtle text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path)})})]})]},e.encodedPath)})]})]})]}):null}},53213:(e,t,r)=>{r.d(t,{Bj:()=>d,CM:()=>v,FK:()=>b,Iz:()=>x,MB:()=>j,Ub:()=>f,X0:()=>h,Zi:()=>c,lv:()=>m,oh:()=>g,r4:()=>l,ue:()=>i,w2:()=>p,yy:()=>u});var n=r(49433),s=r(82680);let o=e=>n.$mh({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.$mh({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.qIB(t=>"Failed to get branches"===t.error?n.fJG(new s.m_({resource:"git-repo",id:e})):n.PyW(t))),i=e=>o(`/api/git/current-branch?cwd=${encodeURIComponent(e)}`),d=(e,t,r,n)=>o(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${r}${"number"==typeof n?`&offset=${n}`:""}`),c=(e,t,r)=>o(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=(e,t,r,n="worktree")=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}&mode=${n}${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,n)=>{let s=new URLSearchParams({cwd:e,file:t,type:r});return n&&s.set("oldPath",n),o(`/api/git/diff?${s}`)},g=e=>o(`/api/git/diff?${e.toString()}`),b=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),v=e=>n.$mh({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()}`)},53317:(e,t,r)=>{function n(e){return e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/(\d)-(?=\d)/g,"$1.").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function s(e){return e.split("-").map((e,t)=>0===t?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)).join("-")}r.d(t,{J:()=>n,U:()=>s})},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 d(){return o}function c(){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,d,c)}function m(){return o??s()}},54356:(e,t,r)=>{r.d(t,{useTabState:()=>v});var n=r(12115),s=r(41474),o=r(2111),a=r(95045),l=r(75346),i=r(49433),d=r(86957),c=r(96472),u=r(82680);let m=e=>`cockpit:active-tab:${e}`;var x=r(83448);function h(e,t,r,n,s){let o=new Set(t.map(e=>e.id)),a=new Set([...e].filter(e=>o.has(e))),l=new Map;for(let e of r){if(e.cwd!==n)continue;let t="codex"===e.engine?g(e.sessionId):e.sessionId;l.set(t,e.status??"normal")}for(let e of t){if(!e.sessionId)continue;let t=l.get(e.sessionId);void 0!==t&&(t===s?a.add(e.id):a.delete(e.id))}return a}function f(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}let p=/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:\.jsonl)?$/i;function g(e){let t=e.match(p);return t?.[1]??e}function b(e,t,r){let n=new Set(t.map(e=>e.id)),s=new Set(e.filter(e=>n.has(e))),o=[],a=[];for(let l of e){if(n.has(l)&&!a.includes(l)){a.push(l);continue}let e=new Set([...a,...s]),i=[...t].reverse().find(t=>!e.has(t.id));if(i){a.push(i.id),s.add(i.id);continue}let d={id:`tab-${Date.now()}-pane${o.length}`,cwd:r,title:"New Chat"};o.push(d),a.push(d.id)}return{panes:a,created:o}}function v({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:p}){let j=(0,n.useRef)(!1),w=(0,n.useRef)(!0),[k,y]=(0,n.useState)(!1),N=(0,n.useCallback)(()=>{w.current=!1,y(!0)},[]),C=(0,n.useRef)(p);(0,n.useEffect)(()=>{C.current=p},[p]);let S=(0,s.F)(),M=(0,n.useRef)(S);(0,n.useEffect)(()=>{M.current=S},[S]);let[L,E]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:t?`Session ${t.slice(0,6)}...`:"New Chat"}]),[P,$]=(0,n.useState)(()=>[L[0]?.id??""]),[T,R]=(0,n.useState)(0),I=(0,n.useRef)(T);(0,n.useEffect)(()=>{I.current=T},[T]);let F=(0,n.useRef)(P);(0,n.useEffect)(()=>{F.current=P},[P]);let B=P[T]??P[0]??"",D=(0,n.useCallback)(e=>{$(t=>{let r=t.indexOf(e);if(-1!==r)return r!==I.current&&R(r),t;let n=[...t];return n[I.current]=e,n})},[]),[A,H]=(0,n.useState)(new Set),[W,z]=(0,n.useState)(new Set),O=(0,n.useRef)(L);(0,n.useEffect)(()=>{O.current=L},[L]);let _=(0,n.useRef)([]),q=(0,n.useRef)(B);(0,n.useEffect)(()=>{q.current=B},[B]);let V=(0,n.useRef)(null),U=(0,n.useRef)(new Set),K=(0,n.useCallback)((t,r)=>{e&&t&&d.t4.runFork((0,c.KJ)(e,t,r).pipe(i.h9N(()=>i.rIH)))},[e]),Q=(0,n.useCallback)(t=>{e&&(z(r=>{let n=h(r,O.current,t,e,"loading");return f(r,n)?r:n}),H(r=>{let n=h(r,O.current,t,e,"unread");return f(r,n)?r:n}))},[e]);(0,n.useEffect)(()=>{k&&Q(_.current)},[k,L,Q]);let[G,J]=(0,n.useState)(null),[Y,Z]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||j.current||(j.current=!0,(async()=>{let n=d.t4.runSync(i.SvU({try:()=>{let t=window.sessionStorage.getItem(m(e));if(!t)return null;let r=JSON.parse(t);return"blank"===r.kind?{kind:"blank"}:"session"===r.kind&&"string"==typeof r.sessionId&&r.sessionId?{kind:"session",sessionId:r.sessionId}:null},catch:e=>new u.uV({message:"load active tab target failed",cause:e})}).pipe(i.h9N(()=>i.PyW(null)))),s=await d.t4.runPromise((0,c.n8)(e).pipe(i.h9N(()=>i.PyW(null))));if(s){let o=s.engines||{},a={};for(let[e,t]of Object.entries(o))a["codex"===t?g(e):e]=t;let l=[];for(let e of s.sessions||[]){let t="codex"===o[e]?g(e):e;l.includes(t)||l.push(t)}let i=s.activeSessionId&&"codex"===o[s.activeSessionId]?g(s.activeSessionId):s.activeSessionId,d=s.ollamaModels||{},c=s.deepseekModels||{},u=s.kimiModels||{},m=s.glmModels||{},x=s.claudeModels||{},h=s.claudeEfforts||{},f=s.claudeFastModes||{},p=s.claudeThinkings||{},v=s.codexModels||{},j=s.codexReasoningEfforts||{},w=s.planModes||{},k=s.noHistories||{},y=s.outputStyles||{},C=n?.kind==="session"?n.sessionId:void 0,S=[...l];if(t&&!S.includes(t)&&(S=[t,...S]),C&&!S.includes(C)&&(S=[C,...S]),S.length>0){let l=O.current,M=S.map((t,r)=>{let n=l.find(e=>e.sessionId===t);return{id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:a[t]||n?.engine||void 0,ollamaModel:d[t]||n?.ollamaModel||void 0,deepseekModel:c[t]||n?.deepseekModel||void 0,kimiModel:u[t]||n?.kimiModel||void 0,glmModel:m[t]||n?.glmModel||void 0,claudeModel:x[t]||n?.claudeModel||void 0,claudeEffort:h[t]||n?.claudeEffort||void 0,claudeFastMode:f[t]??n?.claudeFastMode,claudeThinking:p[t]??n?.claudeThinking,codexModel:v[t]||n?.codexModel||void 0,codexReasoningEffort:j[t]||n?.codexReasoningEffort||void 0,planMode:w[t]??n?.planMode,noHistory:k[t]??n?.noHistory,outputStyle:y[t]??n?.outputStyle}}),L=C||t||i,P=L?S.indexOf(L):-1;P<0&&(P=0);let T=n?.kind!=="blank"&&(n||t||!r&&null!==i)?void 0:{id:`tab-${Date.now()}-blank`,cwd:e,title:"New Chat"},I=T?[...M,T]:M,F=T?.id??M[P].id,B=s.paneSessionIds;if(Array.isArray(B)&&B.length>1){let{panes:t,created:r}=b(B.slice(0,2).map(e=>{let t=e&&"codex"===o[e]?g(e):e;return t&&M.find(e=>e.sessionId===t)?.id||""}),I,e),n=t.indexOf(F);-1===n&&(t[0]=F,n=0);let s=t[0]===t[1];E([...I,...r]),$(s?[t[0]]:t),R(s?0:n)}else E(I),D(F);setTimeout(N,0)}else N()}else N()})())},[e,t,r,N]),(0,n.useEffect)(()=>{var t;let r,n,s,o;if(!k||!e)return;let a=L.map(e=>e.sessionId).filter(e=>!!e),l=L.find(e=>e.id===B),i=l?.sessionId??null,u={},m={},x={},h={},f={},p={},g={},b={},v={},j={},w={},y={},N={},C={};for(let e of L)e.sessionId&&e.engine&&(u[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(m[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(x[e.sessionId]=e.deepseekModel),e.sessionId&&e.kimiModel&&(h[e.sessionId]=e.kimiModel),e.sessionId&&e.glmModel&&(f[e.sessionId]=e.glmModel),e.sessionId&&e.claudeModel&&(p[e.sessionId]=e.claudeModel),e.sessionId&&e.claudeEffort&&(g[e.sessionId]=e.claudeEffort),e.sessionId&&e.codexModel&&(j[e.sessionId]=e.codexModel),e.sessionId&&e.codexReasoningEffort&&(w[e.sessionId]=e.codexReasoningEffort),e.sessionId&&(void 0!==e.planMode&&(y[e.sessionId]=e.planMode),void 0!==e.noHistory&&(N[e.sessionId]=e.noHistory),void 0!==e.outputStyle&&(C[e.sessionId]=e.outputStyle),void 0!==e.claudeFastMode&&(b[e.sessionId]=e.claudeFastMode),void 0!==e.claudeThinking&&(v[e.sessionId]=e.claudeThinking));let S=[...U.current],M={cwd:e,sessions:a,activeSessionId:i,paneSessionIds:P.map(e=>L.find(t=>t.id===e)?.sessionId??null),engines:u,ollamaModels:m,deepseekModels:x,kimiModels:h,glmModels:f,claudeModels:p,claudeEfforts:g,claudeFastModes:b,claudeThinkings:v,codexModels:j,codexReasoningEfforts:w,planModes:y,noHistories:N,outputStyles:C,...S.length?{closedSessionIds:S}:{}};V.current||(t=async e=>{let t=await d.t4.runPromiseExit((0,c.ej)(e));if("Success"===t._tag)for(let t of e.closedSessionIds??[])U.current.delete(t);else console.error("Failed to save sessions:",t.cause)},n=!1,s=Promise.resolve(),o=async()=>{if(!n){n=!0;try{for(;void 0!==r;){let e=r;r=void 0;try{await t(e)}catch{}}}finally{n=!1}}},V.current={enqueue(e){r=e,n||(s=o())},whenIdle:()=>s}),V.current.enqueue(M)},[L,B,P,e,k]),(0,n.useLayoutEffect)(()=>{if(w.current||!e)return;let t=L.find(e=>e.id===B)?.sessionId,r=t?{kind:"session",sessionId:t}:{kind:"blank"};d.t4.runSync(i.SvU({try:()=>window.sessionStorage.setItem(m(e),JSON.stringify(r)),catch:e=>new u.uV({message:"save active tab target failed",cause:e})}).pipe(i.h9N(()=>i.rIH))),(0,a.F)(l.n.SessionChange,{cwd:e,sessionId:t??null})},[B,L,e,k]);let X=(0,n.useCallback)(t=>{e&&d.t4.runPromise((0,c.n8)(e).pipe(i.h9N(()=>i.PyW(null)))).then(r=>{if(!r)return;let n=r.engines||{},s={};for(let[e,t]of Object.entries(n))s["codex"===t?g(e):e]=t;let o=[];for(let e of r.sessions||[]){let t="codex"===n[e]?g(e):e;o.includes(t)||o.push(t)}let a=r.ollamaModels||{},l=r.deepseekModels||{},i=r.kimiModels||{},d=r.glmModels||{},c=r.claudeModels||{},u=r.claudeEfforts||{},m=r.claudeFastModes||{},x=r.claudeThinkings||{},h=r.codexModels||{},f=r.codexReasoningEfforts||{},p=r.planModes||{},v=r.noHistories||{},j=r.outputStyles||{},w=O.current,k=new Set(t),y=w.filter(e=>!e.sessionId||!k.has(e.sessionId)),N=new Set(y.map(e=>e.sessionId).filter(Boolean)),C=o.filter(e=>!N.has(e));if(y.length===w.length&&0===C.length)return;let S=[...y,...C.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:a[t]||void 0,deepseekModel:l[t]||void 0,kimiModel:i[t]||void 0,glmModel:d[t]||void 0,claudeModel:c[t]||void 0,claudeEffort:u[t]||void 0,claudeFastMode:m[t]??void 0,claudeThinking:x[t]??void 0,codexModel:h[t]||void 0,codexReasoningEffort:f[t]||void 0,planMode:p[t]||void 0,noHistory:v[t]||void 0,outputStyle:j[t]||void 0}))];0===S.length&&(S=[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]);let{panes:M,created:L}=b(F.current,S,e);L.length&&(S=[...S,...L]),E(S),$(M)})},[e]),ee=(0,n.useCallback)(t=>{if(e){if("global-state"===t.type&&Array.isArray(t.data?.sessions)){_.current=t.data.sessions,w.current||Q(t.data.sessions);return}w.current||"project-state-changed"!==t.type||t.cwd!==e||X(t.closedSessionIds??[])}},[e,X,Q]);(0,o.h)({url:"/ws/global-state",enabled:!!e,onMessage:ee});let et=(0,n.useCallback)((e,t,r,n)=>{let{engine:s,ollamaModel:o,deepseekModel:a,kimiModel:l,glmModel:i,claudeModel:d,claudeEffort:c,claudeFastMode:u,claudeThinking:m,codexModel:x,codexReasoningEffort:h,planMode:f,noHistory:p,outputStyle:g,appendToEnd:b=!1}=n??{},v={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:s,ollamaModel:o,deepseekModel:a,kimiModel:l,glmModel:i,claudeModel:d,claudeEffort:c,claudeFastMode:u,claudeThinking:m,codexModel:x,codexReasoningEffort:h,planMode:f,noHistory:p,outputStyle:g};return E(e=>{if(b)return[...e,v];let t=e.findIndex(e=>e.id===B);if(-1===t)return[...e,v];let r=[...e];return r.splice(t+1,0,v),r}),D(v.id),v.id},[B]),er=(0,n.useCallback)(t=>{let r=O.current.find(e=>e.id===t);r?.sessionId&&U.current.add(r.sessionId);let n=O.current.filter(e=>e.id!==t),{panes:s,created:o}=b(F.current,n,e);E([...n,...o]),$(s)},[e]),en=(0,n.useCallback)(()=>{R(0),O.current.forEach(e=>{e.sessionId&&U.current.add(e.sessionId)});let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};D(t.id),E([t])},[e]),es=(0,n.useCallback)((t,r)=>{let n=L.find(e=>e.sessionId===t);n?D(n.id):e?d.t4.runPromise((0,c.n8)(e).pipe(i.h9N(()=>i.PyW(null)))).then(n=>{let s=O.current.find(e=>e.sessionId===t);s?D(s.id):et(e,t,r,{engine:n?.engines?.[t],ollamaModel:n?.ollamaModels?.[t],deepseekModel:n?.deepseekModels?.[t],kimiModel:n?.kimiModels?.[t],glmModel:n?.glmModels?.[t],claudeModel:n?.claudeModels?.[t],claudeEffort:n?.claudeEfforts?.[t],claudeFastMode:n?.claudeFastModes?.[t],claudeThinking:n?.claudeThinkings?.[t],codexModel:n?.codexModels?.[t],codexReasoningEffort:n?.codexReasoningEfforts?.[t],planMode:n?.planModes?.[t],noHistory:n?.noHistories?.[t],outputStyle:n?.outputStyles?.[t],appendToEnd:!0})}):et(e,t,r,{appendToEnd:!0})},[L,e,et]),eo=(0,n.useCallback)(()=>{et(e,void 0,void 0,{appendToEnd:!0})},[e,et]),ea=(0,n.useCallback)(()=>{et(e,void 0,"New Codex Chat",{engine:"codex",appendToEnd:!0})},[e,et]),el=(0,n.useCallback)(()=>{et(e,void 0,"New Kimi Chat",{engine:"kimi",kimiModel:"k3",appendToEnd:!0})},[e,et]),ei=(0,n.useCallback)(()=>{et(e,void 0,"New GLM Chat",{engine:"glm",glmModel:"glm-5.3",appendToEnd:!0})},[e,et]),ed=(0,n.useRef)(void 0),ec=(0,n.useCallback)(()=>{let t=et(e,void 0,"New Ollama Chat",{engine:"ollama",ollamaModel:ed.current,appendToEnd:!0});d.t4.runPromise((0,x.Vm)()).then(e=>{e&&(ed.current=e,E(r=>r.map(r=>r.id!==t||r.ollamaModel?r:{...r,ollamaModel:e})))})},[e,et]),eu=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e&&r.engine!==t?{...r,engine:t}:r))},[]),em=(0,n.useCallback)((e,t)=>{ed.current=t,E(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),ex=(0,n.useCallback)(()=>{et(e,void 0,"New DeepSeek Chat",{engine:"deepseek",deepseekModel:"deepseek-v4-flash",appendToEnd:!0})},[e,et]),eh=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),ef=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,kimiModel:t}:r))},[]),ep=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,glmModel:t}:r))},[]),eg=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,claudeModel:t}:r))},[]),eb=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,claudeEffort:t}:r))},[]),ev=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,claudeFastMode:t}:r))},[]),ej=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,claudeThinking:t}:r))},[]),ew=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,codexModel:t}:r))},[]),ek=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,codexReasoningEffort:t}:r))},[]),ey=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,planMode:t}:r))},[]),eN=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,noHistory:t}:r))},[]),eC=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,outputStyle:t}:r))},[]),eS=(0,n.useCallback)((t,r)=>{let n=O.current.find(e=>e.id===q.current);et(e,t,r,{engine:n?.engine,ollamaModel:n?.ollamaModel,deepseekModel:n?.deepseekModel,kimiModel:n?.kimiModel,glmModel:n?.glmModel,claudeModel:n?.claudeModel,claudeEffort:n?.claudeEffort,claudeFastMode:n?.claudeFastMode,claudeThinking:n?.claudeThinking,codexModel:n?.codexModel,codexReasoningEffort:n?.codexReasoningEffort})},[e,et]),eM=(0,n.useCallback)((e,t)=>{E(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!C.current||"agent"===C.current;if(e===B&&r&&M.current){let e=n.sessionId||t.sessionId;e&&K(e,"normal")}else H(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[B,K]);(0,n.useEffect)(()=>{(!p||"agent"===p)&&S&&H(e=>{if(!e.has(B))return e;let t=new Set(e);t.delete(B);let r=O.current.find(e=>e.id===B);return r?.sessionId&&(K(r.sessionId,"normal"),d.t4.runFork((0,c.M2)(r.sessionId).pipe(i.h9N(()=>i.rIH)))),t})},[p,B,S,K]);let eL=(0,n.useCallback)(()=>{let t=F.current;if(t.length>1){$([t[I.current]]),R(0);return}let r=O.current,n=r.findIndex(e=>e.id===t[0]),s=r[n+1]??r[n-1];if(s){$([t[0],s.id]),R(0);return}let o={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};E(e=>[...e,o]),$([t[0],o.id]),R(1)},[e]),eE=(0,n.useCallback)(e=>{let t=F.current;t.length<2||($(t.filter((t,r)=>r!==e)),R(0))},[]),eP=(0,n.useCallback)(e=>{R(e)},[]),e$=(0,n.useCallback)(e=>{D(e),H(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=O.current.find(t=>t.id===e);return n?.sessionId&&(K(n.sessionId,"normal"),d.t4.runFork((0,c.M2)(n.sessionId).pipe(i.h9N(()=>i.rIH)))),r})},[K]),eT=(0,n.useCallback)(e=>{J(e)},[]),eR=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==G&&G!==t&&Z(t)},[G]),eI=(0,n.useCallback)(e=>{null!==G&&G!==e&&E(t=>{let r=[...t],[n]=r.splice(G,1);return r.splice(e,0,n),r}),J(null),Z(null)},[G]),eF=(0,n.useCallback)(()=>{J(null),Z(null)},[]),eB=L.find(e=>e.id===B);return{tabs:L,activeTabId:B,activeTab:eB,paneTabIds:P,activePane:T,unreadTabs:A,globalLoadingTabs:W,pageVisible:S,dragTabIndex:G,dragOverTabIndex:Y,addTab:et,toggleSideBySide:eL,focusPane:eP,closePane:eE,closeTab:er,closeAllTabs:en,switchTab:e$,handleSelectSession:es,handleNewTab:eo,handleNewCodexTab:ea,handleNewKimiTab:el,handleNewGlmTab:ei,handleNewOllamaTab:ec,handleNewDeepseekTab:ex,handleOpenSession:eS,updateTabState:eM,updateTabEngine:eu,updateTabOllamaModel:em,updateTabDeepseekModel:eh,updateTabKimiModel:ef,updateTabGlmModel:ep,updateTabClaudeModel:eg,updateTabClaudeEffort:eb,updateTabClaudeFastMode:ev,updateTabClaudeThinking:ej,updateTabCodexModel:ew,updateTabCodexReasoningEffort:ek,updateTabPlanMode:ey,updateTabNoHistory:eN,updateTabOutputStyle:eC,handleTabDragStart:eT,handleTabDragOver:eR,handleTabDrop:eI,handleTabDragEnd:eF}}},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),d=r(43561),c=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 M=new C.hs("headingFold");function L(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=L(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"===L(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 d=i.attrs.level,c=(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<=d){s=!1;return}n.push(r)}}),n),u=c.length>0,m=L(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 c){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"!==L(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:M,state:{init:(e,{doc:t})=>E(t),apply:(e,t)=>e.docChanged?E(e.doc):t},props:{decorations:e=>M.getState(e)}})]});function $(e){let t=[];return e.forEach((e,r)=>t.push({node:e,start:r,end:r+e.nodeSize})),t}function T(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 I(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 B=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=$(n),i=l.findIndex(e=>e.start===a);if(i<0)return!1;let d=i;for(;d>0&&B.has(l[d-1].node.type.name);)d--;let c=i;for(;c<l.length-1&&B.has(l[c+1].node.type.name);)c++;let u=[],m=-1,x="paragraph"===l[i].node.type.name?-1:o.index(1);for(let e=d;e<=c;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[d].start,f=l[c].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=$(n),l=a.findIndex(e=>e.start===o);if(l<0)return!1;let i=a[l].node.attrs.level,d=l+1;for(;d<a.length&&!T(a[d].node,i);)d++;let c=a[l].start,u=a[d-1].end;if(r>0){if(d>=a.length)return!1;let r=a[d].node.attrs.level,o=d+1;for(;o<a.length&&!T(a[o].node,r);)o++;let l=a[o-1].end;if(t){let r=e.tr,o=n.slice(u,l).content.size;I(r,n,c,u,l),F(r,c+o+(s.from-c)),t(r.scrollIntoView())}return!0}if(0===l)return!1;let m=l-1;for(;m>=0&&!T(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;I(r,n,x,c,u),F(r,x+(s.from-c)),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),d=a.index(n-1),c=a.before(n),u=c+l.nodeSize;if(r>0){if(d>=i.childCount-1)return!1;let r=u+i.child(d+1).nodeSize;if(t){let n=e.tr,a=s.slice(u,r).content.size;I(n,s,c,u,r),F(n,c+a+(o.from-c)),t(n.scrollIntoView())}return!0}if(d<=0)return!1;let m=c-i.child(d-1).nodeSize;if(t){let r=e.tr;I(r,s,m,c,u),F(r,m+(o.from-c)),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 H(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 d=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:d}),!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 z=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":()=>H(this.editor,-1),"Alt-ArrowRight":()=>H(this.editor,1),"Shift-ArrowRight":()=>W(this.editor,1),"Shift-ArrowLeft":()=>W(this.editor,-1)}}});function O(e){return e.storage.markdown.getMarkdown()}function _(){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),d=_().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>l(0))},[t]);let c=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)%d.length)):"ArrowUp"===e.key?(e.preventDefault(),l(e=>(e-1+d.length)%d.length)):"Enter"===e.key?(e.preventDefault(),d[a]&&c(d[a])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,a,o]),0===d.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lv2 py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:d.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-hover hover:text-foreground"}`,onClick:()=>c(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))})}_();var V=r(76043),U=r(86957),K=r(49433),Q=r(34075),G=r(76900);let J=/^\s*[-*+]\s+(?:\\?\[ \\?\]|\\?\[[xX/]\\?\])\s*$/,Y=/^\s*(```|~~~)/;function Z(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(Z(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:Z(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),M=(0,s.useRef)(void 0),[L,E]=(0,s.useState)(null),$=(0,s.useRef)(null),T=(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}J.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,G.Cq)(r,t,M.current).pipe(K.sFT(e=>K.OH5(()=>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}),M.current=e.mtime,S.current=!1,(0,Q.oR)(p("editor.conflictReloaded"),"info")):(M.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(()=>{T(e)},5e3)},[T]),I=(0,l.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:!1,link:!1}),P.configure({levels:[1,2,3]}),z,d.A.configure({placeholder:()=>a.A.t("editor.placeholder")}),c.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||L||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")){$.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(O(e)),null!==$.current){let{from:t}=e.state.selection;if(t<$.current)E(null),$.current=null;else{let r=e.state.doc.textBetween($.current,t,"\n");r.includes(" ")||r.includes("\n")?(E(null),$.current=null):E(e=>e?{...e,query:r}:null)}}}}),F=(0,s.useRef)(null);(0,s.useEffect)(()=>{F.current=I},[I]),(0,s.useEffect)(()=>{e&&I&&(b(!0),E(null),$.current=null,U.t4.runPromiseExit((0,G.zF)(r)).then(e=>{"Success"===e._tag?(I.commands.setContent(e.value.content||"",{emitUpdate:!1}),M.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,I,r]);let B=(0,s.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null),S.current&&I&&T(O(I)),E(null),$.current=null,t()},[I,T,t]);return((0,s.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(L?(E(null),$.current=null):B())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,B,L]),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-scrim",onClick:B}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 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:B,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover 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:I}),(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:I})})]}),L&&I&&(0,n.jsx)(q,{editor:I,query:L.query,position:L.position,onClose:()=>{E(null),$.current=null}})]}):null}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>c,fY:()=>d,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 d({activeView:e,onViewChange:t,children:r,onOverscroll:a}){let i=(0,s.useRef)(null),c=(0,s.useRef)(!1),u=(0,s.useRef)(0),m=(0,s.useRef)(0),x=(0,s.useRef)(null),h=(0,s.useRef)(null),f=(0,s.useRef)(0),p=(0,s.useRef)(a);(0,s.useEffect)(()=>{p.current=a},[a]);let[g,b]=(0,s.useState)(0),[v,j]=(0,s.useState)(!1),w=o.indexOf(e),k=o.length-1;(0,s.useEffect)(()=>{u.current=0,m.current=0,h.current=null,queueMicrotask(()=>b(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){var r,n,s;let a=e.target;if("IFRAME"===a.tagName)return;let l=performance.now(),d=(r=f.current,n=h.current,s=()=>(function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth-e.clientWidth>1)return!0;e=e.parentElement}return!1})(a),null!==n&&l-r<=180?n:s()?"inner":"switcher");if(h.current=d,f.current=l,"inner"===d)return;e.preventDefault(),e.stopPropagation(),c.current&&(c.current=!1);let g=window.innerWidth,v=u.current-6*e.deltaX,y=w>0,N=w<k,C=!1;!y&&v>0&&(m.current+=v,x.current=a,v=0,C=!0),!N&&v<0&&(m.current+=v,x.current=a,v=0,C=!0),C&&p.current?.({offset:m.current,phase:"move",triggered:!1,target:a}),u.current=v=Math.max(-g,Math.min(g,v)),b(v),j(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{let e=u.current,r=m.current,n=x.current;m.current=0,x.current=null;let s=.12*g;j(!1),c.current=!0;let a=w;e<-s&&w<k?a=w+1:e>s&&w>0&&(a=w-1),u.current=0,b(0),a!==w&&t(o[a]),a===w&&0!==r&&p.current?.({offset:r,phase:"release",triggered:Math.abs(r)>.2*g,target:n}),setTimeout(()=>{c.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[w,k,t]);let[y,N]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>N(!0))},[]);let C={activeView:e,onViewChange:t,dragOffset:(()=>{if(!y)return 0;let e=window.innerWidth;return e?g/e:0})(),isDragging:y&&v};return(0,n.jsx)(l.Provider,{value:C,children:r})}function c({children:e}){let t,r,{activeView:a,dragOffset:l,isDragging:d}=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:d?"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(),d=(0,s.useRef)(null),c=(0,s.useRef)([]),[u,m]=(0,s.useState)({left:0,width:0}),x=o.indexOf(e),h=()=>{if(!d.current||0===c.current.length)return{left:0,width:0};let e=d.current.getBoundingClientRect(),t=c.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:d,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{c.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}})]})}},66109:(e,t,r)=>{r.d(t,{aO:()=>n,iG:()=>s,jL:()=>o});let n="relative w-full max-w-[calc((100vw_-_28rem)*0.9)] h-[90vh] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden",s="relative w-full max-w-[calc((100vw_-_14rem)*0.9)] h-[90vh] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden",o="grid grid-cols-[repeat(auto-fill,minmax(320px,1fr))] gap-3"},68287:(e,t,r)=>{function n(e){return"loading"===e?"relative session-number-running":""}function s(e,t){return"loading"===e||"unread"===e?"border-transparent bg-orange-11/15 text-orange-11":t?"border-transparent bg-brand/15 text-brand":"border-transparent bg-muted-foreground/15 text-muted-foreground"}function o(e,t){return[n(e),s(e,t)].filter(Boolean).join(" ")}r.d(t,{JQ:()=>s,QV:()=>n,ci:()=>o})},72363:(e,t,r)=>{r.d(t,{$2:()=>j,N4:()=>c,_I:()=>v,fX:()=>u,fZ:()=>m});let n="cockpit update",s={visible:!1,stage:"preparing",startedAt:0,baselineMs:null,installedVersion:null,upToDate:!1,error:null,rolledBack:!1,fixCommand:n,logPath:null,live:!1},o="cockpit:update-seen-at",a=s,l=new Set,i=!1;function d(e){a={...a,...e},l.forEach(e=>e())}function c(e){return l.add(e),()=>l.delete(e)}function u(){return a}function m(){try{window.localStorage.setItem(o,String(Date.now()))}catch{}d({visible:!1})}let x=e=>new Promise(t=>setTimeout(t,e));async function h(){try{let e=await fetch("/api/health",{cache:"no-store",signal:AbortSignal.timeout(2e3)});if(!e.ok)return null;let t=await e.json();return{pid:"number"==typeof t.pid?t.pid:null,version:t.version??null}}catch{return null}}async function f(){try{let e=await fetch("/api/update-state",{cache:"no-store",signal:AbortSignal.timeout(2e3)});if(!e.ok)return{state:null,logPath:null};let t=await e.json();return{state:t.state??null,logPath:t.logPath??null}}catch{return{state:null,logPath:null}}}async function p(e){try{let t=await fetch(`http://127.0.0.1:${e}/`,{cache:"no-store",signal:AbortSignal.timeout(1500)});if(!t.ok)return null;return await t.json()}catch{return null}}function g(e){switch(e){case"installing":return"installing";case"repairing":return"repairing";case"rolling-back":return"rolling-back";case"restarting":case"done":return"restarting";default:return"preparing"}}function b(e,t={}){d({stage:"failed",error:e,...t})}async function v(){if(!i){i=!0,d({...s,visible:!0,stage:"preparing",startedAt:Date.now()});try{let e=await f();d({baselineMs:e.state?.installMs??e.state?.prevInstallMs??null,logPath:e.logPath});let t=await h(),r=t?.pid??null,s=t?.version??null,o=await fetch("/api/update",{method:"POST"});if(!o.ok){let e=await o.json().catch(()=>({}));b(e.error??`HTTP ${o.status}`);return}let l=await o.json().catch(()=>({})),i=l.statusPort??null;d({logPath:l.logPath??a.logPath});let c=0,u=null!==i,m=Date.now()+3e5;for(;Date.now()<m;){if(await x(1e3),u&&null!==i){let e=await p(i);if(e){if(c=0,d({live:!0}),"failed"===e.phase)return void b(e.error??"install failed",{rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n,live:!0});d({stage:g(e.phase),installedVersion:e.installed??a.installedVersion,baselineMs:a.baselineMs??e.prevInstallMs??null})}else++c>=3&&(u=!1,d({live:!1}))}let e=await h();if(e?.pid!=null&&(null===r||e.pid!==r)){let{state:t}=await f();if(t?.phase==="failed")return void b(t.error??"update failed",{rolledBack:!0===t.rolledBack,fixCommand:t.fixCommand??n});let r=e.version??a.installedVersion;d({stage:"done",installedVersion:r,upToDate:null!==r&&r===s});return}}b("timeout")}catch(e){b(e instanceof Error?e.message:String(e))}finally{i=!1}}}async function j(){if(i||a.visible)return;let{state:e,logPath:t}=await f();if(!e?.phase||"done"===e.phase)return;let r=e.startedAt??0,l=e.installMs??e.prevInstallMs??null;if("failed"===e.phase){let a=0;try{a=Number(window.localStorage.getItem(o))||0}catch{}if((e.finishedAt??0)<=a)return;d({...s,visible:!0,stage:"failed",startedAt:r,baselineMs:l,error:e.error??"unknown error",rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n,logPath:t});return}if(!(!r||Date.now()-r>6e5)){i=!0,d({...s,visible:!0,stage:g(e.phase),startedAt:r,baselineMs:l,logPath:t});try{let e=r+3e5;for(;Date.now()<e;){await x(1e3);let{state:e}=await f();if(e?.phase){if("failed"===e.phase)return void b(e.error??"install failed",{rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n});if("done"===e.phase)return void d({stage:"done",installedVersion:e.installed??null,upToDate:!0===e.unchanged});d({stage:g(e.phase)})}}b("timeout")}finally{i=!1}}}},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,d]=(0,s.useState)(()=>e.getAttributes("link").href||""),c=(0,s.useRef)(null);(0,s.useEffect)(()=>{c.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-lv2 p-2 flex items-center gap-2`,style:m,children:[(0,n.jsx)("input",{ref:c,type:"text",value:i,onChange:e=>d(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-11 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),d=(0,s.useRef)(null),[,c]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>c(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-hover"}`,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:d,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-11 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-11 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-11 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-11 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:()=>o});var n=r(95155),s=r(79114);function o({onBrowseProjects:e}){let{t}=(0,s.Bd)();return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-5 bg-card",children:[(0,n.jsx)("svg",{className:"w-14 h-14 text-muted-foreground/40",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"})}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:t("workspace.selectProject")}),(0,n.jsxs)("button",{onClick:e,className:"flex items-center gap-2 px-4 py-2 text-sm rounded-lg bg-primary text-primary-foreground hover:opacity-90 transition-opacity",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"})}),t("workspace.openProject")]})]})}},76412:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>v});var n=r(95155),s=r(12115),o=r(63728),a=r(82032),l=r(34075),i=r(79114),d=r(95045),c=r(75346),u=r(49433),m=r(86957),x=r(53213),h=r(45720),f=r(76900);function p({className:e}){return(0,n.jsxs)("svg",{className:e,fill:"none",viewBox:"0 0 100 100","aria-hidden":"true",children:[(0,n.jsx)("path",{fill:"#0065A9",d:"M96.461 10.796 75.857.876a6.23 6.23 0 0 0-7.107 1.207l-67.451 61.5a4.167 4.167 0 0 0 .004 6.162l5.51 5.009a4.167 4.167 0 0 0 5.32.236l81.228-61.62c2.725-2.067 6.639-.124 6.639 3.297v-.24a6.25 6.25 0 0 0-3.539-5.63Z"}),(0,n.jsx)("path",{fill:"#007ACC",d:"m96.461 89.204-20.604 9.92a6.229 6.229 0 0 1-7.107-1.207l-67.451-61.5a4.167 4.167 0 0 1 .004-6.162l5.51-5.009a4.167 4.167 0 0 1 5.32-.236l81.228 61.62c2.725 2.067 6.639.124 6.639-3.297v.24a6.25 6.25 0 0 0-3.539 5.63Z"}),(0,n.jsx)("path",{fill:"#1F9CF0",d:"M75.858 99.126a6.232 6.232 0 0 1-7.108-1.21c2.306 2.307 6.25.674 6.25-2.588V4.672c0-3.262-3.944-4.895-6.25-2.589a6.232 6.232 0 0 1 7.108-1.21l20.6 9.908A6.25 6.25 0 0 1 100 16.413v67.174a6.25 6.25 0 0 1-3.541 5.633l-20.601 9.906Z"})]})}function g({className:e}){return(0,n.jsx)("svg",{className:e,viewBox:"0 0 466.73 532.09",fill:"currentColor","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M457.43,125.94L244.42,2.96c-6.84-3.95-15.28-3.95-22.12,0L9.3,125.94c-5.75,3.32-9.3,9.46-9.3,16.11v247.99c0,6.65,3.55,12.79,9.3,16.11l213.01,122.98c6.84,3.95,15.28,3.95,22.12,0l213.01-122.98c5.75-3.32,9.3-9.46,9.3-16.11v-247.99c0-6.65-3.55-12.79-9.3-16.11h-.01ZM444.05,151.99l-205.63,356.16c-1.39,2.4-5.06,1.42-5.06-1.36v-233.21c0-4.66-2.49-8.97-6.53-11.31L24.87,145.67c-2.4-1.39-1.42-5.06,1.36-5.06h411.26c5.84,0,9.49,6.33,6.57,11.39h-.01Z"})})}function b({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,i.Bd)(),[a,d]=(0,s.useState)(!1),[c,u]=(0,s.useState)([]),[h,p]=(0,s.useState)(!1),[g,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()=>{p(!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");p(!1)},[e,o]),C=(0,s.useCallback)(()=>{d(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{d(!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 M=async t=>{v(!0);let n=await m.t4.runPromiseExit((0,f.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)},L=c.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-hover 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-lv2 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",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:h?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===L.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):L.map(e=>(0,n.jsx)("button",{onClick:()=>M(e),disabled:g,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-hover transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function v({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:x,onOpenAliasManager:j,onBranchSwitched:w}){let{t:k}=(0,i.Bd)(),y=t?.sessionId?(0,h.X)(t.engine,t.sessionId):null;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:k("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,l.oR)(k("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","data-tooltip":`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,l.oR)(k("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:k("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-hover 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)(b,{cwd:e,currentBranch:s,onSwitched:()=>w?.()})]})]}),(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-hover rounded-lg transition-colors",title:k("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,f.em)(t.cwd).pipe(u.NWQ(()=>u.rIH)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)(p,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&m.t4.runFork((0,f.Q1)(t.cwd).pipe(u.NWQ(()=>u.rIH)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openInCursor"),children:(0,n.jsx)(g,{className:"w-4 h-4"})}),y&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(y).then(()=>{(0,l.oR)(k("toast.copiedCommand",{command:y}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("chat.copyCommandTooltip",{command:y}),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:j,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("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,d.F)(c.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("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-hover rounded-lg transition-colors",title:k("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,Kl:()=>k,M5:()=>l,Or:()=>c,Q1:()=>j,QW:()=>f,Wr:()=>d,Yn:()=>g,b2:()=>w,em:()=>v,fz:()=>b,zF:()=>m});var n=r(49433),s=r(82680);let o=(e,t)=>n.$mh({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)}),d=()=>o("/api/version"),c=()=>o("/api/extension/version"),u=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",m=e=>o(u(e)),x=(e,t,r)=>n.$mh({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=e=>o(`/api/fs/dirs?path=${encodeURIComponent(e)}`),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)},84204:(e,t,r)=>{r.d(t,{Workspace:()=>em});var n=r(95155),s=r(12115),o=r(79114),a=r(4426),l=r(76288),i=r(52153),d=r(21484),c=r(34075),u=r(66109),m=r(61878),x=r(33210),h=r(51914),f=r(94852),p=r(67635),g=r(60241),b=r(42804),v=r(22164),j=r(20986),w=r(68459),k=r(86957),y=r(34582),N=r(85269),C=r(63563),S=r(63040);function M({isOpen:e,htmlAppPreviews:t,activeHtmlAppPreviewPath:r,onShowHtmlAppPreview:a,onMinimizeHtmlAppPreview:l,onCloseHtmlAppPreview:i,onClose:d,onOpenApp:w}){let{t:E,i18n:P}=(0,o.Bd)(),[$,T]=(0,s.useState)([]),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)(""),[D,A]=(0,s.useState)(!1),[H,W]=(0,s.useState)(""),[z,O]=(0,s.useState)(!1),[_,q]=(0,s.useState)({}),V=(0,s.useRef)(null),U=(0,s.useCallback)(async()=>{I(!0);let e=await k.t4.runPromiseExit((0,S.mi)());"Success"===e._tag?T(e.value):console.error("Failed to load html apps",e.cause),I(!1)},[]);(0,s.useEffect)(()=>{e&&(U(),setTimeout(()=>{V.current?.focus(),V.current?.select()},100))},[e,U]);let K=(0,s.useCallback)(()=>{A(!1),d()},[d]);(0,s.useEffect)(()=>{if(!e&&!r)return;let t=e=>{if("Escape"===e.key){if(r)return void i(r);if(D){A(!1),W("");return}K()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,r,K,i,D]);let Q=(0,s.useMemo)(()=>{let e=F.trim().toLowerCase();return e?$.filter(t=>t.name.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):$},[$,F]),G=(0,s.useMemo)(()=>$.filter(e=>!e.builtin).length,[$]),J=F.trim().length>0,Y=P.resolvedLanguage?.startsWith("zh")?"https://opencockpit.dev/zh/docs/agent/html-apps/":"https://opencockpit.dev/en/docs/agent/html-apps/",Z=(0,s.useCallback)(async()=>{let e=H.trim();if(!e)return;O(!0);let t=await k.t4.runPromiseExit((0,S.ot)(e));if("Success"===t._tag)t.value.alreadyExists?(0,c.oR)(E("htmlApps.alreadyAdded"),"info"):((0,c.oR)(E("htmlApps.added"),"success"),(0,C.N)()),W(""),A(!1),await U();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:E("htmlApps.addFailed");(0,c.oR)(n,"error")}O(!1)},[H,U,E]),X=(0,s.useCallback)(async e=>{"Success"===(await k.t4.runPromiseExit((0,S.m3)(e)))._tag?(T(t=>t.filter(t=>t.id!==e)),(0,C.N)()):(0,c.oR)(E("common.deleteFailed"),"error")},[E]),ee=(0,s.useCallback)(e=>{w?w(e):window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:e}})),K()},[K,w]),et=(0,s.useCallback)(e=>{w?w(e):window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:e}})),l()},[l,w]),er=(0,s.useCallback)(e=>{let t=(0,y.Xe)(e);window.open((0,y.PB)(t,window.location.origin),"_blank")},[]),en=(0,s.useCallback)(e=>{q(t=>({...t,[e]:(t[e]||0)+1}))},[]),es=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,c.oR)(E("common.copiedPath"),"success")}catch{(0,c.oR)(E("common.copyFailed"),"error")}},[E]);return(0,n.jsxs)(n.Fragment,{children:[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-scrim",onClick:K}),(0,n.jsxs)("div",{className:u.aO,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:E("htmlApps.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(m.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-foreground-subtle pointer-events-none"}),(0,n.jsx)("input",{ref:V,type:"text",value:F,onChange:e=>B(e.target.value),placeholder:E("htmlApps.searchPlaceholder"),className:"pl-7 pr-6 py-1 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),F&&(0,n.jsx)("button",{onClick:()=>{B(""),V.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:E("fileBrowser.clear"),children:(0,n.jsx)(x.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("button",{onClick:()=>A(!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-hover transition-colors",title:E("htmlApps.addHtmlApp"),children:[(0,n.jsx)(h.A,{className:"w-4 h-4"})," ",E("htmlApps.add")]}),(0,n.jsx)("button",{onClick:K,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:E("common.close"),children:(0,n.jsx)(x.A,{className:"w-5 h-5"})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:R?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:E("common.loading")}):(0,n.jsxs)(n.Fragment,{children:[Q.length>0&&(0,n.jsx)("div",{className:u.jL,children:Q.map(e=>(0,n.jsx)(L,{app:e,onOpenConsole:()=>ee(e.path),onOpenExternal:()=>er(e.path),onPreview:()=>{a({path:e.path,title:e.title,icon:e.icon}),K()},onDelete:()=>X(e.id),onCopyPath:()=>es(e.path)},e.id))}),0===Q.length&&J&&(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:E("htmlApps.emptyNoMatch")}),!J&&0===G&&(0,n.jsxs)("div",{className:`text-center text-muted-foreground py-8 text-sm space-y-2${Q.length>0?" mt-4 border-t border-border/60":""}`,children:[(0,n.jsx)("p",{children:E("htmlApps.emptyNoApps")}),(0,n.jsxs)("p",{children:[E("htmlApps.emptyCreatePrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/html"})," ",E("htmlApps.emptyCreateSuffix")]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("button",{type:"button",onClick:()=>A(!0),className:"text-brand hover:underline",children:E("htmlApps.addExisting")})," \xb7 ",(0,n.jsx)("a",{href:Y,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline",children:E("htmlApps.viewDocs")})]})]})]})})]})]}),e&&D&&(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-scrim",onClick:()=>{z||(A(!1),W(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:E("htmlApps.addHtmlApp")}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:E("htmlApps.pathLabel")}),(0,n.jsx)("input",{type:"text",value:H,onChange:e=>W(e.target.value),onKeyDown:e=>{"Enter"!==e.key||z||Z()},placeholder:"/Users/you/.../report.html",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground 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:()=>{A(!1),W("")},disabled:z,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors disabled:opacity-50",children:E("common.cancel")}),(0,n.jsx)("button",{onClick:Z,disabled:z||!H.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:z?E("htmlApps.adding"):E("htmlApps.add")})]})]})]}),t.map(e=>{let t=r===e.path;return(0,n.jsx)("div",{className:t?"fixed inset-0 z-[60] flex items-center justify-center bg-scrim p-0 md:p-4":"hidden",onClick:l,children:(0,n.jsxs)("div",{className:"bg-card shadow-lv3 border border-brand/30 w-full h-full md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.icon?(0,n.jsx)("span",{className:"text-base leading-none flex-shrink-0",children:e.icon}):(0,n.jsx)(f.A,{className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate max-w-[35%]","data-tooltip":e.title,children:e.title}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground flex-shrink-0","aria-hidden":"true",children:"-"}),(0,n.jsx)("span",{className:"font-mono text-sm text-muted-foreground truncate min-w-0","data-tooltip":e.path,children:e.path}),(0,n.jsx)("button",{onClick:()=>es(e.path),className:"text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("common.copyPath"),"aria-label":E("common.copyPath"),children:(0,n.jsx)(p.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("button",{onClick:l,className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("common.minimize"),children:(0,n.jsx)(g.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>et(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("common.openInConsole"),children:(0,n.jsx)(b.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>er(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("browser.openInNewWindow"),children:(0,n.jsx)(v.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>en(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("common.refresh"),children:(0,n.jsx)(j.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>i(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)(x.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,n.jsx)(N.O,{filePath:e.path,reloadKey:_[e.path]||0})})]})},e.path)})]})}function L({app:e,onOpenConsole:t,onOpenExternal:r,onPreview:a,onDelete:l,onCopyPath:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`group flex flex-col h-full border border-border rounded-lg p-3 hover:border-brand hover:shadow-lv2 transition-all cursor-pointer ${e.valid?"":"opacity-60"}`,onClick:()=>e.valid&&a(),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)(v.A,{className:"w-5 h-5"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground truncate","data-tooltip":e.title,children:e.title}),(0,n.jsxs)("div",{className:"font-mono text-[11px] text-muted-foreground truncate","data-tooltip":`/${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:d("htmlApps.invalid")}),e.builtin&&(0,n.jsx)("span",{className:"flex-shrink-0 text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:d("htmlApps.builtin")}),(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",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:d("common.openInConsole"),children:(0,n.jsx)(b.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:r,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:d("browser.openInNewWindow"),children:(0,n.jsx)(v.A,{className:"w-4 h-4"})}),e.builtin?null:c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{u(!1),l()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:d("common.confirm")}),(0,n.jsx)("button",{onClick:()=>u(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:d("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>u(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:d("common.delete"),children:(0,n.jsx)(w.A,{className:"w-4 h-4"})})]})]}),(0,n.jsxs)("div",{className:"font-mono text-xs text-muted-foreground mt-2 break-all",children:[e.path,(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i()},className:"inline-flex align-middle ml-1 p-0.5 hover:text-foreground hover:bg-hover rounded transition-colors",title:d("common.copyPath"),children:(0,n.jsx)(p.A,{className:"w-3.5 h-3.5"})})]}),(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:d("htmlApps.noDescription")})})]})}var E=r(3238),P=r(62111),$=r(83448),T=r(53317);let R={"claude-fable-5-1":{input:10,output:50,cacheRead:.25,cacheWrite:12.5},"claude-mythos-5-1":{input:10,output:50,cacheRead:.25,cacheWrite:12.5},"claude-fable-5":{input:10,output:50,cacheRead:1,cacheWrite:12.5},"claude-mythos-5":{input:10,output:50,cacheRead:1,cacheWrite:12.5},"claude-opus-5-5":{input:4,output:20,cacheRead:.2,cacheWrite:5},"claude-opus-5":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-8":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-7":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-6":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-5":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-sonnet-5-5":{input:2,output:10,cacheRead:.2,cacheWrite:2.5},"claude-sonnet-5":{input:2,output:10,cacheRead:.2,cacheWrite:2.5},"claude-sonnet-4-6":{input:3,output:15,cacheRead:.3,cacheWrite:3.75},"claude-sonnet-4-5":{input:3,output:15,cacheRead:.3,cacheWrite:3.75},"claude-haiku-4-5":{input:1,output:5,cacheRead:.1,cacheWrite:1.25}},I={input:3,output:15,cacheRead:.3,cacheWrite:3.75},F={light:["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#4a3aa7","#e34948"],dark:["#3987e5","#d95926","#199e70","#c98500","#d55181","#008300","#9085e9","#e66767"]},B={light:{messages:"#2a78d6",toolCalls:"#1baf7a",messagesRgb:"42, 120, 214"},dark:{messages:"#3987e5",toolCalls:"#199e70",messagesRgb:"57, 135, 229"}};function D(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 A(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function H({data:e,height:t=200,formatValue:r=D}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),[l,i]=(0,s.useState)(null),d=(0,s.useRef)([]),c=(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 c=n.getContext("2d");c.scale(l,l),c.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))));c.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",c.font="10px ui-monospace, monospace",c.textAlign="right",c.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;c.fillText(r(t),44,s),c.strokeStyle=(p="--line-2",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),c.lineWidth=.5,c.beginPath(),c.moveTo(50,s),c.lineTo(50+x,s),c.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,d,u;let m=n.data[t];if(m<=0)return;let x=Math.max(1,m/f*h),p=8+h-s-x;c.fillStyle=n.color,o=c,a=r,l=p,i=b,u=2,(d=x)<1||(u=Math.min(u,d/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+d-u),o.quadraticCurveTo(a+i,l+d,a+i-u,l+d),o.lineTo(a+u,l+d),o.quadraticCurveTo(a,l+d,a,l+d-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}),c.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",c.font="9px ui-monospace, monospace",c.textAlign="center",c.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&c.fillText(e,r+b/2,8+h+6)}),d.current=v},[e,t,r]);(0,s.useEffect)(()=>{c();let e=new ResizeObserver(()=>c());return a.current&&e.observe(a.current),()=>e.disconnect()},[c]);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=d.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-lv2 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)(),{resolvedTheme:r}=(0,E.DP)(),s=B[r],a=Math.max(1,...Object.values(e)),l=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:l.map(r=>{let o=e[String(r)]||0,l=o/a;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:r,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*l)}px`,backgroundColor:l>0?`rgba(${s.messagesRgb}, ${.2+.8*l})`:"var(--muted)"}}),r%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:r})]},r)})})]})}function z({isOpen:e,onClose:t}){var r;let a,l,{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(!0),[x,h]=(0,s.useState)("day"),[f,p]=(0,s.useState)("tokens"),[g,b]=(0,s.useState)(null),{resolvedTheme:v}=(0,E.DP)();(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>m(!0)),k.t4.runPromiseExit((0,$.Cr)()).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>c(t))}queueMicrotask(()=>m(!1))}))},[e]);let j=(0,s.useMemo)(()=>{var e;let t,r,n=Object.keys(d?.modelUsage||{}).filter(e=>!e.startsWith("<")),s=new Map;for(let e of d?.dailyModelTokens||[])for(let[t,r]of Object.entries(e.tokensByModel)){let n=s.get(t);r>0&&(!n||e.date<n)&&s.set(t,e.date)}return e=[...n].sort((e,t)=>(s.get(e)??"￿").localeCompare(s.get(t)??"￿")||e.localeCompare(t)),t=F[v],r={},e.forEach((e,n)=>{r[e]=t[n%t.length]}),r},[d,v]),w=(0,s.useMemo)(()=>d?.modelUsage?Object.entries(d.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:(0,T.J)(e),color:j[e],usage:t,cost:(r=function(e){let t=e.replace(/-\d{8}$/,""),r=R[t];if(r)return r;let n=t.toLowerCase();return n.includes("fable")||n.includes("mythos")?{input:10,output:50,cacheRead:1,cacheWrite:12.5}:n.includes("opus")?{input:5,output:25,cacheRead:.5,cacheWrite:6.25}:n.includes("haiku")?{input:1,output:5,cacheRead:.1,cacheWrite:1.25}:I}(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):[],[d,j]),y=(0,s.useMemo)(()=>w.reduce((e,t)=>e+t.cost,0),[w]),N=(0,s.useMemo)(()=>w.map(e=>e.id),[w]),C=(0,s.useMemo)(()=>{let e={};for(let t of w)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[w]),{activityChart:S,tokenChart:M,costChart:L}=(0,s.useMemo)(()=>{let e=d?.dailyActivity||[],t=d?.dailyModelTokens||[];if("day"===x){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:B[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:B[v].toolCalls}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:n.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:o,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:n.map(t=>(t.tokensByModel[e]||0)*(C[e]||0)),color:j[e]}))}}}if("week"===x){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:B[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:B[v].toolCalls}]};return{activityChart:s,tokenChart:{labels:n,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:r.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:n,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:r.map(t=>(t.tokensByModel[e]||0)*(C[e]||0)),color:j[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:B[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:B[v].toolCalls}]};return{activityChart:s,tokenChart:{labels:n,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:r.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:n,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:r.map(t=>(t.tokensByModel[e]||0)*(C[e]||0)),color:j[e]}))}}},[d,x,N,C,j,i]),_=g&&j[g]?g:null,q=(0,s.useMemo)(()=>{let e="tokens"===f?M:L;return _?{...e,datasets:e.datasets.filter(e=>e.id===_)}:e},[M,L,f,_]);if((0,P.E)(t,e),!e)return null;let V=[{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-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-lv3 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:V.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${x===e.key?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>h(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover 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:u?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):d?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(O,{label:i("tokenStats.totalSessions"),value:String(d.totalSessions??0)}),(0,n.jsx)(O,{label:i("tokenStats.totalMessages"),value:D(d.totalMessages??0)}),(0,n.jsx)(O,{label:i("tokenStats.equivalentApiCost"),value:A(y),highlight:!0}),(0,n.jsx)(O,{label:i("tokenStats.longestSession"),value:d.longestSession?(a=Math.floor((r=d.longestSession.duration)/36e5),l=Math.floor(r%36e5/6e4),a>0?`${a}h ${l}m`:`${l}m`):"-"}),(0,n.jsx)(O,{label:i("tokenStats.firstUse"),value:d.firstSessionDate?d.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:B[v].messages}}),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:B[v].toolCalls}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(H,{data:S,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"===f?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>p("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===f?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>p("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:w.map(e=>(0,n.jsxs)("button",{onClick:()=>b(_===e.id?null:e.id),className:`flex items-center gap-1 rounded-sm transition-opacity hover:opacity-100 ${_&&_!==e.id?"opacity-40":""}`,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)(H,{data:q,height:180,formatValue:"tokens"===f?D:A})})]}),(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:[w.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:D(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:y>0?`${(e.cost/y*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:A(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:D(w.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(w.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(w.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(w.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:A(y)})]})]})]})})]}),d.hourCounts&&Object.keys(d.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(W,{hourCounts:d.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function O({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 _=r(60865),q=r(52252),V=r(48764),U=r(58250),K=r(5135),Q=r(38408);function G({skillId:e,onClose:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(null),[i,d]=(0,s.useState)(!0),[u,m]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return d(!0),k.t4.runPromiseExit((0,V.Bz)(e)).then(e=>{t||("Success"===e._tag?l(e.value):console.error("Failed to load skill content",e.cause),d(!1))}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),(0,P.k)(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let x=(0,s.useCallback)(async()=>{if(a?.path)try{await navigator.clipboard.writeText(a.path),(0,c.oR)(r("common.copiedPath"),"success")}catch{(0,c.oR)(r("common.copyFailed"),"error")}},[a,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-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 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:a?.name?`/${a.name}`:r("skills.previewTitle")}),(0,n.jsx)("button",{onClick:x,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:r("skills.copyPath"),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"})]})})]}),a?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:a.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:()=>m("preview"),className:`px-3 py-1 transition-colors ${"preview"===u?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:r("common.preview")}),(0,n.jsx)("button",{onClick:()=>m("source"),className:`px-3 py-1 transition-colors ${"source"===u?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:r("skills.source")})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors flex-shrink-0",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"})})})]}),i?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:r("common.loading")}):a&&a.valid?"preview"===u?(0,n.jsx)(K.M,{content:a.content,filePath:a.path,cwd:a.path.slice(0,Math.max(0,a.path.lastIndexOf("/"))),embedded:!0,onClose:t}):(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsx)(Q.XO,{content:a.content,filePath:a.path,className:"min-h-full"})}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:r("skills.cannotRead")})]})]})}function J({isOpen:e,onClose:t}){let{t:r,i18n:a}=(0,o.Bd)(),[l,i]=(0,s.useState)([]),[d,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(""),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(null),N=(0,s.useRef)(null),C=(0,s.useCallback)(async()=>{m(!0);let e=await k.t4.runPromiseExit((0,V.Hy)());"Success"===e._tag?i(e.value):console.error("Failed to load skills",e.cause),m(!1)},[]);(0,s.useEffect)(()=>{e&&(C(),setTimeout(()=>{N.current?.focus(),N.current?.select()},100))},[e,C]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!w){if(f){p(!1),b("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,f,w]);let S=(0,s.useMemo)(()=>{let e=x.trim().toLowerCase();return e?l.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):l},[l,x]),M=a.resolvedLanguage?.startsWith("zh")?"https://opencockpit.dev/zh/docs/agent/skills/":"https://opencockpit.dev/en/docs/agent/skills/",L=(0,s.useCallback)(async()=>{let e=g.trim();if(!e)return;j(!0);let t=await k.t4.runPromiseExit((0,V.L5)(e));if("Success"===t._tag)(0,c.oR)(t.value.alreadyExists?r("skills.alreadyAdded"):r("skills.added"),t.value.alreadyExists?"info":"success"),b(""),p(!1),await C(),t.value.alreadyExists||(0,U.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause,s=n instanceof Error?n.message:r("skills.addFailed");(0,c.oR)(s,"error")}j(!1)},[g,C,r]),E=(0,s.useCallback)(async e=>{"Success"===(await k.t4.runPromiseExit((0,V.hp)(e)))._tag?(i(t=>t.filter(t=>t.id!==e)),(0,U.k)()):(0,c.oR)(r("common.deleteFailed"),"error")},[r]),P=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,c.oR)(r("common.copiedPath"),"success")}catch{(0,c.oR)(r("common.copyFailed"),"error")}},[r]);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-scrim",onClick:t}),(0,n.jsxs)("div",{className:u.aO,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:r("skills.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:N,type:"text",value:x,onChange:e=>h(e.target.value),placeholder:r("skills.searchPlaceholder"),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),x&&(0,n.jsx)("button",{onClick:()=>{h(""),N.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:r("skills.clearSearch"),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:()=>p(!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-hover transition-colors",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"})}),r("skills.addSkill")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded 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"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:d?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:r("common.loading")}):0===S.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm space-y-2",children:0===l.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{children:r("skills.emptyNoSkills")}),(0,n.jsxs)("p",{children:[r("skills.emptyIntroPrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/skillify"})," ",r("skills.emptyIntroSuffix")]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("button",{type:"button",onClick:()=>p(!0),className:"text-brand hover:underline",children:r("skills.addSkill")})," \xb7 ",(0,n.jsx)("a",{href:M,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline",children:r("skills.viewDocs")})]})]}):r("skills.emptyNoMatch")}):(0,n.jsx)("div",{className:u.jL,children:S.map(e=>(0,n.jsx)(Y,{skill:e,onPreview:()=>y(e.id),onDelete:()=>E(e.id),onCopyPath:()=>P(e.path)},e.id))})})]})]}),f&&(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-scrim",onClick:()=>{v||(p(!1),b(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:r("skills.addSkill")}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:r("skills.pathLabel")}),(0,n.jsx)("input",{type:"text",value:g,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"!==e.key||v||L()},placeholder:r("skills.pathPlaceholder"),autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground 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:()=>{p(!1),b("")},disabled:v,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors disabled:opacity-50",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:L,disabled:v||!g.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:v?r("skills.adding"):r("skills.add")})]})]})]}),w&&(0,n.jsx)(G,{skillId:w,onClose:()=>y(null)})]}):null}function Y({skill:e,onPreview:t,onDelete:r,onCopyPath:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(!1);return(0,n.jsxs)("div",{onClick:e.valid?t:void 0,role:e.valid?"button":void 0,tabIndex:e.valid?0:void 0,onKeyDown:r=>{e.valid&&("Enter"===r.key||" "===r.key)&&(r.preventDefault(),t())},className:`group flex flex-col h-56 border border-border rounded-lg p-3 hover:border-brand hover:shadow-lv2 transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${e.valid?"cursor-pointer":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 flex-shrink-0",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)(q.A,{className:"w-5 h-5"})}),(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground truncate flex-1 min-w-0","data-tooltip":`/${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:l("skills.invalid")}),(0,n.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",children:i?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:l("common.confirm")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(!1)},className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:l("common.cancel")})]}):(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(!0)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",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 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})})]}),(0,n.jsxs)("div",{className:"font-mono text-xs text-muted-foreground mt-2 flex-shrink-0 break-all line-clamp-2","data-tooltip":e.path,children:[e.path,(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),a()},className:"inline-flex align-middle ml-1 p-0.5 hover:text-foreground hover:bg-hover rounded transition-colors",title:l("skills.copyPath"),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 line-clamp-4","data-tooltip":e.description||void 0,children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:l("skills.noDescription")})}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-auto pt-1 truncate flex-shrink-0","data-tooltip":e.argumentHint,children:e.argumentHint})]})}var Z=r(1767),X=r(47650),ee=r(7578);let et=[],er=[];function en(){er.forEach(e=>e())}function es(e){et=et.filter(t=>t.id!==e),en()}function eo({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return er.push(t),()=>{er=er.filter(e=>e!==t)}},[]),et}();return 0===t.length?null:(0,X.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)(ea,{item:t,onNavigate:e,onRemove:es},t.id))}),document.body)}function ea({item:e,onNavigate:t,onRemove:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),d=(0,s.useRef)(void 0),c=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(d.current=setTimeout(c,5e3),()=>clearTimeout(d.current)),[c]);let u=(0,s.useCallback)(()=>{clearTimeout(d.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),m=(0,s.useCallback)(()=>{clearTimeout(d.current)},[]),x=(0,s.useCallback)(()=>{d.current=setTimeout(c,2e3)},[c]);return(0,n.jsxs)("div",{className:`group pointer-events-auto relative bg-popover border border-border rounded-lg shadow-lv3 px-3 py-3 min-h-[84px] min-w-[260px] max-w-[340px] cursor-pointer 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.jsx)("div",{className:"pointer-events-none absolute inset-0 rounded-lg bg-hover opacity-0 group-hover:opacity-100 transition-opacity"}),(0,n.jsxs)("div",{className:"relative flex items-start 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)(ee.l,{projectNumber:e.projectNumber,sessionNumber:e.sessionNumber,className:"ml-auto"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:"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:"relative text-xs text-muted-foreground line-clamp-2 break-words mt-1 ml-6",children:e.message})]})}var el=r(77725),ei=r(49433),ed=r(82680);let ec=ei.$mh({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new ed.uV({message:"fetch /api/projects failed",cause:e})});var eu=r(96472);function em({initialCwd:e,initialSessionId:t,initialBlank:r}){let{t:c}=(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),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),[E,P]=(0,s.useState)(!1),[$,T]=(0,s.useState)(!1),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)(null),[H,W]=(0,s.useState)({}),[O,q]=(0,s.useState)({}),[V,U]=(0,s.useState)(!1),[K,Q]=(0,s.useState)(new Set),G=(0,s.useRef)(new Map),Y=(0,s.useRef)(new Map),X=(0,s.useRef)(new Map),ee=(0,s.useRef)(null),er=(0,el.Z)(ec,[]);(0,s.useEffect)(()=>{if("success"===er.status){let e=er.data;m([...e.projects||[]]),h(e.activeIndex||0),p(e.collapsed||!1),U(!0)}else"error"===er.status&&(console.error("Failed to load projects:",er.error),U(!0))},[er]);let es=(0,s.useCallback)(async(e,t,r)=>{let n,s=await k.t4.runPromise((n={projects:e,activeIndex:t,collapsed:r},ei.$mh({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new ed.uV({message:"save /api/projects failed",cause:e})})).pipe(ei.gPK));"Left"===s._tag&&console.error("Failed to save projects:",s.left)},[]),ea=(0,s.useCallback)((e,t)=>{var r,n;let s=u[x]?.cwd,o=(r=s?{cwd:s,sessionId:X.current.get(s)}:void 0,n={cwd:e,sessionId:t},r?.cwd&&r.sessionId&&(r.cwd!==n.cwd||n.sessionId&&r.sessionId!==n.sessionId)?{cwd:r.cwd,sessionId:r.sessionId}:null);o&&k.t4.runFork((0,eu.T$)(o.cwd,o.sessionId).pipe(ei.h9N(()=>ei.rIH)))},[u,x]);(0,s.useEffect)(()=>{let e=u[x]?.cwd;e&&Q(t=>t.has(e)?t:new Set(t).add(e))},[x,u]),(0,s.useEffect)(()=>{for(let[e,t]of G.current.entries()){let r=u[x]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r,projectNumber:u.findIndex(t=>t.cwd===e)+1},"*")}},[x,u]);let ex=(0,s.useCallback)(e=>{let t=u[x]?.cwd,r=t?G.current.get(t):null,n=r?.contentWindow;if(!n)return;let s=n.document.createEvent("CustomEvent");s.initCustomEvent("console-open-browser",!1,!1,{url:e}),n.dispatchEvent(s)},[x,u]),eh=(0,s.useCallback)(e=>{B(t=>t.some(t=>t.path===e.path)?t:[...t,e]),A(e.path)},[]),ef=(0,s.useCallback)(()=>{A(null)},[]),ep=(0,s.useCallback)(e=>{B(t=>t.filter(t=>t.path!==e)),A(t=>t===e?null:t)},[]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type!=="SESSION_NUMBERS")return;let t=e.data.cwd;if("string"!=typeof t||!Array.isArray(e.data.sessionIds))return;let r=e.data.sessionIds.map(e=>"string"==typeof e?e:null);q(e=>{let n=e[t];return n&&n.length===r.length&&n.every((e,t)=>e===r[t])?e:{...e,[t]:r}})};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let eg=(0,s.useMemo)(()=>{let e={};return u.forEach((t,r)=>{(O[t.cwd]??[]).forEach((n,s)=>{n&&(e[`${t.cwd}
10
+ ${o}`],[d,c]=a?.split(".")??[];return(0,n.jsxs)("div",{onClick:()=>{var n;let s,o;return n=e.fullPath,s=t.path.split("/").pop()||"",o=t.sessionId||s.replace(".jsonl",""),void(r?r(n,o):(0,l.F)(i.n.OpenProject,{cwd:n,sessionId:o}))},className:"p-3 rounded border border-border hover:border-brand hover:shadow-lv2 cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(p.S,{engine:t.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate","data-tooltip":t.title,children:t.title}),a&&(0,n.jsx)(f.l,{projectNumber:d,sessionNumber:c,bot:t.bot,className:"ml-auto"})]}),(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","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-foreground-subtle text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path)})})]})]},e.encodedPath)})]})]})]}):null}},53213:(e,t,r)=>{r.d(t,{Bj:()=>d,CM:()=>v,FK:()=>b,Iz:()=>x,MB:()=>j,Ub:()=>f,X0:()=>h,Zi:()=>c,lv:()=>m,oh:()=>g,r4:()=>l,ue:()=>i,w2:()=>p,yy:()=>u});var n=r(49433),s=r(82680);let o=e=>n.$mh({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.$mh({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.qIB(t=>"Failed to get branches"===t.error?n.fJG(new s.m_({resource:"git-repo",id:e})):n.PyW(t))),i=e=>o(`/api/git/current-branch?cwd=${encodeURIComponent(e)}`),d=(e,t,r,n)=>o(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${r}${"number"==typeof n?`&offset=${n}`:""}`),c=(e,t,r)=>o(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=(e,t,r,n="worktree")=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}&mode=${n}${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,n)=>{let s=new URLSearchParams({cwd:e,file:t,type:r});return n&&s.set("oldPath",n),o(`/api/git/diff?${s}`)},g=e=>o(`/api/git/diff?${e.toString()}`),b=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),v=e=>n.$mh({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()}`)},53317:(e,t,r)=>{function n(e){return e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/(\d)-(?=\d)/g,"$1.").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function s(e){return e.split("-").map((e,t)=>0===t?e.toUpperCase():e.charAt(0).toUpperCase()+e.slice(1)).join("-")}r.d(t,{J:()=>n,U:()=>s})},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 d(){return o}function c(){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,d,c)}function m(){return o??s()}},54356:(e,t,r)=>{r.d(t,{useTabState:()=>v});var n=r(12115),s=r(41474),o=r(2111),a=r(95045),l=r(75346),i=r(49433),d=r(86957),c=r(96472),u=r(82680);let m=e=>`cockpit:active-tab:${e}`;var x=r(83448);function h(e,t,r,n,s){let o=new Set(t.map(e=>e.id)),a=new Set([...e].filter(e=>o.has(e))),l=new Map;for(let e of r){if(e.cwd!==n)continue;let t="codex"===e.engine?g(e.sessionId):e.sessionId;l.set(t,e.status??"normal")}for(let e of t){if(!e.sessionId)continue;let t=l.get(e.sessionId);void 0!==t&&(t===s?a.add(e.id):a.delete(e.id))}return a}function f(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}let p=/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:\.jsonl)?$/i;function g(e){let t=e.match(p);return t?.[1]??e}function b(e,t,r){let n=new Set(t.map(e=>e.id)),s=new Set(e.filter(e=>n.has(e))),o=[],a=[];for(let l of e){if(n.has(l)&&!a.includes(l)){a.push(l);continue}let e=new Set([...a,...s]),i=[...t].reverse().find(t=>!e.has(t.id));if(i){a.push(i.id),s.add(i.id);continue}let d={id:`tab-${Date.now()}-pane${o.length}`,cwd:r,title:"New Chat"};o.push(d),a.push(d.id)}return{panes:a,created:o}}function v({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:p}){let j=(0,n.useRef)(!1),w=(0,n.useRef)(!0),[k,y]=(0,n.useState)(!1),N=(0,n.useCallback)(()=>{w.current=!1,y(!0)},[]),C=(0,n.useRef)(p);(0,n.useEffect)(()=>{C.current=p},[p]);let S=(0,s.F)(),M=(0,n.useRef)(S);(0,n.useEffect)(()=>{M.current=S},[S]);let[L,E]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:t?`Session ${t.slice(0,6)}...`:"New Chat"}]),[P,$]=(0,n.useState)(()=>[L[0]?.id??""]),[T,R]=(0,n.useState)(0),I=(0,n.useRef)(T);(0,n.useEffect)(()=>{I.current=T},[T]);let F=(0,n.useRef)(P);(0,n.useEffect)(()=>{F.current=P},[P]);let B=P[T]??P[0]??"",D=(0,n.useCallback)(e=>{$(t=>{let r=t.indexOf(e);if(-1!==r)return r!==I.current&&R(r),t;let n=[...t];return n[I.current]=e,n})},[]),[A,H]=(0,n.useState)(new Set),[W,z]=(0,n.useState)(new Set),O=(0,n.useRef)(L);(0,n.useEffect)(()=>{O.current=L},[L]);let _=(0,n.useRef)([]),q=(0,n.useRef)(B);(0,n.useEffect)(()=>{q.current=B},[B]);let V=(0,n.useRef)(null),U=(0,n.useRef)(new Set),K=(0,n.useCallback)((t,r)=>{e&&t&&d.t4.runFork((0,c.KJ)(e,t,r).pipe(i.h9N(()=>i.rIH)))},[e]),Q=(0,n.useCallback)(t=>{e&&(z(r=>{let n=h(r,O.current,t,e,"loading");return f(r,n)?r:n}),H(r=>{let n=h(r,O.current,t,e,"unread");return f(r,n)?r:n}))},[e]);(0,n.useEffect)(()=>{k&&Q(_.current)},[k,L,Q]);let[G,J]=(0,n.useState)(null),[Y,Z]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||j.current||(j.current=!0,(async()=>{let n=d.t4.runSync(i.SvU({try:()=>{let t=window.sessionStorage.getItem(m(e));if(!t)return null;let r=JSON.parse(t);return"blank"===r.kind?{kind:"blank"}:"session"===r.kind&&"string"==typeof r.sessionId&&r.sessionId?{kind:"session",sessionId:r.sessionId}:null},catch:e=>new u.uV({message:"load active tab target failed",cause:e})}).pipe(i.h9N(()=>i.PyW(null)))),s=await d.t4.runPromise((0,c.n8)(e).pipe(i.h9N(()=>i.PyW(null))));if(s){let o=s.engines||{},a={};for(let[e,t]of Object.entries(o))a["codex"===t?g(e):e]=t;let l=[];for(let e of s.sessions||[]){let t="codex"===o[e]?g(e):e;l.includes(t)||l.push(t)}let i=s.activeSessionId&&"codex"===o[s.activeSessionId]?g(s.activeSessionId):s.activeSessionId,d=s.ollamaModels||{},c=s.deepseekModels||{},u=s.kimiModels||{},m=s.glmModels||{},x=s.claudeModels||{},h=s.claudeEfforts||{},f=s.claudeFastModes||{},p=s.claudeThinkings||{},v=s.codexModels||{},j=s.codexReasoningEfforts||{},w=s.planModes||{},k=s.noHistories||{},y=s.outputStyles||{},C=n?.kind==="session"?n.sessionId:void 0,S=[...l];if(t&&!S.includes(t)&&(S=[t,...S]),C&&!S.includes(C)&&(S=[C,...S]),S.length>0){let l=O.current,M=S.map((t,r)=>{let n=l.find(e=>e.sessionId===t);return{id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:a[t]||n?.engine||void 0,ollamaModel:d[t]||n?.ollamaModel||void 0,deepseekModel:c[t]||n?.deepseekModel||void 0,kimiModel:u[t]||n?.kimiModel||void 0,glmModel:m[t]||n?.glmModel||void 0,claudeModel:x[t]||n?.claudeModel||void 0,claudeEffort:h[t]||n?.claudeEffort||void 0,claudeFastMode:f[t]??n?.claudeFastMode,claudeThinking:p[t]??n?.claudeThinking,codexModel:v[t]||n?.codexModel||void 0,codexReasoningEffort:j[t]||n?.codexReasoningEffort||void 0,planMode:w[t]??n?.planMode,noHistory:k[t]??n?.noHistory,outputStyle:y[t]??n?.outputStyle}}),L=C||t||i,P=L?S.indexOf(L):-1;P<0&&(P=0);let T=n?.kind!=="blank"&&(n||t||!r&&null!==i)?void 0:{id:`tab-${Date.now()}-blank`,cwd:e,title:"New Chat"},I=T?[...M,T]:M,F=T?.id??M[P].id,B=s.paneSessionIds;if(Array.isArray(B)&&B.length>1){let{panes:t,created:r}=b(B.slice(0,2).map(e=>{let t=e&&"codex"===o[e]?g(e):e;return t&&M.find(e=>e.sessionId===t)?.id||""}),I,e),n=t.indexOf(F);-1===n&&(t[0]=F,n=0);let s=t[0]===t[1];E([...I,...r]),$(s?[t[0]]:t),R(s?0:n)}else E(I),D(F);setTimeout(N,0)}else N()}else N()})())},[e,t,r,N]),(0,n.useEffect)(()=>{var t;let r,n,s,o;if(!k||!e)return;let a=L.map(e=>e.sessionId).filter(e=>!!e),l=L.find(e=>e.id===B),i=l?.sessionId??null,u={},m={},x={},h={},f={},p={},g={},b={},v={},j={},w={},y={},N={},C={};for(let e of L)e.sessionId&&e.engine&&(u[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(m[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(x[e.sessionId]=e.deepseekModel),e.sessionId&&e.kimiModel&&(h[e.sessionId]=e.kimiModel),e.sessionId&&e.glmModel&&(f[e.sessionId]=e.glmModel),e.sessionId&&e.claudeModel&&(p[e.sessionId]=e.claudeModel),e.sessionId&&e.claudeEffort&&(g[e.sessionId]=e.claudeEffort),e.sessionId&&e.codexModel&&(j[e.sessionId]=e.codexModel),e.sessionId&&e.codexReasoningEffort&&(w[e.sessionId]=e.codexReasoningEffort),e.sessionId&&(void 0!==e.planMode&&(y[e.sessionId]=e.planMode),void 0!==e.noHistory&&(N[e.sessionId]=e.noHistory),void 0!==e.outputStyle&&(C[e.sessionId]=e.outputStyle),void 0!==e.claudeFastMode&&(b[e.sessionId]=e.claudeFastMode),void 0!==e.claudeThinking&&(v[e.sessionId]=e.claudeThinking));let S=[...U.current],M={cwd:e,sessions:a,activeSessionId:i,paneSessionIds:P.map(e=>L.find(t=>t.id===e)?.sessionId??null),engines:u,ollamaModels:m,deepseekModels:x,kimiModels:h,glmModels:f,claudeModels:p,claudeEfforts:g,claudeFastModes:b,claudeThinkings:v,codexModels:j,codexReasoningEfforts:w,planModes:y,noHistories:N,outputStyles:C,...S.length?{closedSessionIds:S}:{}};V.current||(t=async e=>{let t=await d.t4.runPromiseExit((0,c.ej)(e));if("Success"===t._tag)for(let t of e.closedSessionIds??[])U.current.delete(t);else console.error("Failed to save sessions:",t.cause)},n=!1,s=Promise.resolve(),o=async()=>{if(!n){n=!0;try{for(;void 0!==r;){let e=r;r=void 0;try{await t(e)}catch{}}}finally{n=!1}}},V.current={enqueue(e){r=e,n||(s=o())},whenIdle:()=>s}),V.current.enqueue(M)},[L,B,P,e,k]),(0,n.useLayoutEffect)(()=>{if(w.current||!e)return;let t=L.find(e=>e.id===B)?.sessionId,r=t?{kind:"session",sessionId:t}:{kind:"blank"};d.t4.runSync(i.SvU({try:()=>window.sessionStorage.setItem(m(e),JSON.stringify(r)),catch:e=>new u.uV({message:"save active tab target failed",cause:e})}).pipe(i.h9N(()=>i.rIH))),(0,a.F)(l.n.SessionChange,{cwd:e,sessionId:t??null})},[B,L,e,k]);let X=(0,n.useCallback)(t=>{e&&d.t4.runPromise((0,c.n8)(e).pipe(i.h9N(()=>i.PyW(null)))).then(r=>{if(!r)return;let n=r.engines||{},s={};for(let[e,t]of Object.entries(n))s["codex"===t?g(e):e]=t;let o=[];for(let e of r.sessions||[]){let t="codex"===n[e]?g(e):e;o.includes(t)||o.push(t)}let a=r.ollamaModels||{},l=r.deepseekModels||{},i=r.kimiModels||{},d=r.glmModels||{},c=r.claudeModels||{},u=r.claudeEfforts||{},m=r.claudeFastModes||{},x=r.claudeThinkings||{},h=r.codexModels||{},f=r.codexReasoningEfforts||{},p=r.planModes||{},v=r.noHistories||{},j=r.outputStyles||{},w=O.current,k=new Set(t),y=w.filter(e=>!e.sessionId||!k.has(e.sessionId)),N=new Set(y.map(e=>e.sessionId).filter(Boolean)),C=o.filter(e=>!N.has(e));if(y.length===w.length&&0===C.length)return;let S=[...y,...C.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:a[t]||void 0,deepseekModel:l[t]||void 0,kimiModel:i[t]||void 0,glmModel:d[t]||void 0,claudeModel:c[t]||void 0,claudeEffort:u[t]||void 0,claudeFastMode:m[t]??void 0,claudeThinking:x[t]??void 0,codexModel:h[t]||void 0,codexReasoningEffort:f[t]||void 0,planMode:p[t]||void 0,noHistory:v[t]||void 0,outputStyle:j[t]||void 0}))];0===S.length&&(S=[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]);let{panes:M,created:L}=b(F.current,S,e);L.length&&(S=[...S,...L]),E(S),$(M)})},[e]),ee=(0,n.useCallback)(t=>{if(e){if("global-state"===t.type&&Array.isArray(t.data?.sessions)){_.current=t.data.sessions,w.current||Q(t.data.sessions);return}w.current||"project-state-changed"!==t.type||t.cwd!==e||X(t.closedSessionIds??[])}},[e,X,Q]);(0,o.h)({url:"/ws/global-state",enabled:!!e,onMessage:ee});let et=(0,n.useCallback)((e,t,r,n)=>{let{engine:s,ollamaModel:o,deepseekModel:a,kimiModel:l,glmModel:i,claudeModel:d,claudeEffort:c,claudeFastMode:u,claudeThinking:m,codexModel:x,codexReasoningEffort:h,planMode:f,noHistory:p,outputStyle:g,appendToEnd:b=!1}=n??{},v={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:s,ollamaModel:o,deepseekModel:a,kimiModel:l,glmModel:i,claudeModel:d,claudeEffort:c,claudeFastMode:u,claudeThinking:m,codexModel:x,codexReasoningEffort:h,planMode:f,noHistory:p,outputStyle:g};return E(e=>{if(b)return[...e,v];let t=e.findIndex(e=>e.id===B);if(-1===t)return[...e,v];let r=[...e];return r.splice(t+1,0,v),r}),D(v.id),v.id},[B]),er=(0,n.useCallback)(t=>{let r=O.current.find(e=>e.id===t);r?.sessionId&&U.current.add(r.sessionId);let n=O.current.filter(e=>e.id!==t),{panes:s,created:o}=b(F.current,n,e);E([...n,...o]),$(s)},[e]),en=(0,n.useCallback)(()=>{R(0),O.current.forEach(e=>{e.sessionId&&U.current.add(e.sessionId)});let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};D(t.id),E([t])},[e]),es=(0,n.useCallback)((t,r)=>{let n=L.find(e=>e.sessionId===t);n?D(n.id):e?d.t4.runPromise((0,c.n8)(e).pipe(i.h9N(()=>i.PyW(null)))).then(n=>{let s=O.current.find(e=>e.sessionId===t);s?D(s.id):et(e,t,r,{engine:n?.engines?.[t],ollamaModel:n?.ollamaModels?.[t],deepseekModel:n?.deepseekModels?.[t],kimiModel:n?.kimiModels?.[t],glmModel:n?.glmModels?.[t],claudeModel:n?.claudeModels?.[t],claudeEffort:n?.claudeEfforts?.[t],claudeFastMode:n?.claudeFastModes?.[t],claudeThinking:n?.claudeThinkings?.[t],codexModel:n?.codexModels?.[t],codexReasoningEffort:n?.codexReasoningEfforts?.[t],planMode:n?.planModes?.[t],noHistory:n?.noHistories?.[t],outputStyle:n?.outputStyles?.[t],appendToEnd:!0})}):et(e,t,r,{appendToEnd:!0})},[L,e,et]),eo=(0,n.useCallback)(()=>{et(e,void 0,void 0,{appendToEnd:!0})},[e,et]),ea=(0,n.useCallback)(()=>{et(e,void 0,"New Codex Chat",{engine:"codex",appendToEnd:!0})},[e,et]),el=(0,n.useCallback)(()=>{et(e,void 0,"New Kimi Chat",{engine:"kimi",kimiModel:"k3",appendToEnd:!0})},[e,et]),ei=(0,n.useCallback)(()=>{et(e,void 0,"New GLM Chat",{engine:"glm",glmModel:"glm-5.3",appendToEnd:!0})},[e,et]),ed=(0,n.useRef)(void 0),ec=(0,n.useCallback)(()=>{let t=et(e,void 0,"New Ollama Chat",{engine:"ollama",ollamaModel:ed.current,appendToEnd:!0});d.t4.runPromise((0,x.Vm)()).then(e=>{e&&(ed.current=e,E(r=>r.map(r=>r.id!==t||r.ollamaModel?r:{...r,ollamaModel:e})))})},[e,et]),eu=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e&&r.engine!==t?{...r,engine:t}:r))},[]),em=(0,n.useCallback)((e,t)=>{ed.current=t,E(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),ex=(0,n.useCallback)(()=>{et(e,void 0,"New DeepSeek Chat",{engine:"deepseek",deepseekModel:"deepseek-v4-flash",appendToEnd:!0})},[e,et]),eh=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),ef=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,kimiModel:t}:r))},[]),ep=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,glmModel:t}:r))},[]),eg=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,claudeModel:t}:r))},[]),eb=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,claudeEffort:t}:r))},[]),ev=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,claudeFastMode:t}:r))},[]),ej=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,claudeThinking:t}:r))},[]),ew=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,codexModel:t}:r))},[]),ek=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,codexReasoningEffort:t}:r))},[]),ey=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,planMode:t}:r))},[]),eN=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,noHistory:t}:r))},[]),eC=(0,n.useCallback)((e,t)=>{E(r=>r.map(r=>r.id===e?{...r,outputStyle:t}:r))},[]),eS=(0,n.useCallback)((t,r)=>{let n=O.current.find(e=>e.id===q.current);et(e,t,r,{engine:n?.engine,ollamaModel:n?.ollamaModel,deepseekModel:n?.deepseekModel,kimiModel:n?.kimiModel,glmModel:n?.glmModel,claudeModel:n?.claudeModel,claudeEffort:n?.claudeEffort,claudeFastMode:n?.claudeFastMode,claudeThinking:n?.claudeThinking,codexModel:n?.codexModel,codexReasoningEffort:n?.codexReasoningEffort})},[e,et]),eM=(0,n.useCallback)((e,t)=>{E(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!C.current||"agent"===C.current;if(e===B&&r&&M.current){let e=n.sessionId||t.sessionId;e&&K(e,"normal")}else H(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[B,K]);(0,n.useEffect)(()=>{(!p||"agent"===p)&&S&&H(e=>{if(!e.has(B))return e;let t=new Set(e);t.delete(B);let r=O.current.find(e=>e.id===B);return r?.sessionId&&(K(r.sessionId,"normal"),d.t4.runFork((0,c.M2)(r.sessionId).pipe(i.h9N(()=>i.rIH)))),t})},[p,B,S,K]);let eL=(0,n.useCallback)(()=>{let t=F.current;if(t.length>1){$([t[I.current]]),R(0);return}let r=O.current,n=r.findIndex(e=>e.id===t[0]),s=r[n+1]??r[n-1];if(s){$([t[0],s.id]),R(0);return}let o={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};E(e=>[...e,o]),$([t[0],o.id]),R(1)},[e]),eE=(0,n.useCallback)(e=>{let t=F.current;t.length<2||($(t.filter((t,r)=>r!==e)),R(0))},[]),eP=(0,n.useCallback)(e=>{R(e)},[]),e$=(0,n.useCallback)(e=>{D(e),H(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=O.current.find(t=>t.id===e);return n?.sessionId&&(K(n.sessionId,"normal"),d.t4.runFork((0,c.M2)(n.sessionId).pipe(i.h9N(()=>i.rIH)))),r})},[K]),eT=(0,n.useCallback)(e=>{J(e)},[]),eR=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==G&&G!==t&&Z(t)},[G]),eI=(0,n.useCallback)(e=>{null!==G&&G!==e&&E(t=>{let r=[...t],[n]=r.splice(G,1);return r.splice(e,0,n),r}),J(null),Z(null)},[G]),eF=(0,n.useCallback)(()=>{J(null),Z(null)},[]),eB=L.find(e=>e.id===B);return{tabs:L,activeTabId:B,activeTab:eB,paneTabIds:P,activePane:T,unreadTabs:A,globalLoadingTabs:W,pageVisible:S,dragTabIndex:G,dragOverTabIndex:Y,addTab:et,toggleSideBySide:eL,focusPane:eP,closePane:eE,closeTab:er,closeAllTabs:en,switchTab:e$,handleSelectSession:es,handleNewTab:eo,handleNewCodexTab:ea,handleNewKimiTab:el,handleNewGlmTab:ei,handleNewOllamaTab:ec,handleNewDeepseekTab:ex,handleOpenSession:eS,updateTabState:eM,updateTabEngine:eu,updateTabOllamaModel:em,updateTabDeepseekModel:eh,updateTabKimiModel:ef,updateTabGlmModel:ep,updateTabClaudeModel:eg,updateTabClaudeEffort:eb,updateTabClaudeFastMode:ev,updateTabClaudeThinking:ej,updateTabCodexModel:ew,updateTabCodexReasoningEffort:ek,updateTabPlanMode:ey,updateTabNoHistory:eN,updateTabOutputStyle:eC,handleTabDragStart:eT,handleTabDragOver:eR,handleTabDrop:eI,handleTabDragEnd:eF}}},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),d=r(43561),c=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 M=new C.hs("headingFold");function L(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=L(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"===L(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 d=i.attrs.level,c=(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<=d){s=!1;return}n.push(r)}}),n),u=c.length>0,m=L(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 c){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"!==L(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:M,state:{init:(e,{doc:t})=>E(t),apply:(e,t)=>e.docChanged?E(e.doc):t},props:{decorations:e=>M.getState(e)}})]});function $(e){let t=[];return e.forEach((e,r)=>t.push({node:e,start:r,end:r+e.nodeSize})),t}function T(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 I(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 B=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=$(n),i=l.findIndex(e=>e.start===a);if(i<0)return!1;let d=i;for(;d>0&&B.has(l[d-1].node.type.name);)d--;let c=i;for(;c<l.length-1&&B.has(l[c+1].node.type.name);)c++;let u=[],m=-1,x="paragraph"===l[i].node.type.name?-1:o.index(1);for(let e=d;e<=c;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[d].start,f=l[c].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=$(n),l=a.findIndex(e=>e.start===o);if(l<0)return!1;let i=a[l].node.attrs.level,d=l+1;for(;d<a.length&&!T(a[d].node,i);)d++;let c=a[l].start,u=a[d-1].end;if(r>0){if(d>=a.length)return!1;let r=a[d].node.attrs.level,o=d+1;for(;o<a.length&&!T(a[o].node,r);)o++;let l=a[o-1].end;if(t){let r=e.tr,o=n.slice(u,l).content.size;I(r,n,c,u,l),F(r,c+o+(s.from-c)),t(r.scrollIntoView())}return!0}if(0===l)return!1;let m=l-1;for(;m>=0&&!T(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;I(r,n,x,c,u),F(r,x+(s.from-c)),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),d=a.index(n-1),c=a.before(n),u=c+l.nodeSize;if(r>0){if(d>=i.childCount-1)return!1;let r=u+i.child(d+1).nodeSize;if(t){let n=e.tr,a=s.slice(u,r).content.size;I(n,s,c,u,r),F(n,c+a+(o.from-c)),t(n.scrollIntoView())}return!0}if(d<=0)return!1;let m=c-i.child(d-1).nodeSize;if(t){let r=e.tr;I(r,s,m,c,u),F(r,m+(o.from-c)),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 H(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 d=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:d}),!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 z=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":()=>H(this.editor,-1),"Alt-ArrowRight":()=>H(this.editor,1),"Shift-ArrowRight":()=>W(this.editor,1),"Shift-ArrowLeft":()=>W(this.editor,-1)}}});function O(e){return e.storage.markdown.getMarkdown()}function _(){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),d=_().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>l(0))},[t]);let c=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)%d.length)):"ArrowUp"===e.key?(e.preventDefault(),l(e=>(e-1+d.length)%d.length)):"Enter"===e.key?(e.preventDefault(),d[a]&&c(d[a])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,a,o]),0===d.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lv2 py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:d.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-hover hover:text-foreground"}`,onClick:()=>c(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))})}_();var V=r(76043),U=r(86957),K=r(49433),Q=r(34075),G=r(76900);let J=/^\s*[-*+]\s+(?:\\?\[ \\?\]|\\?\[[xX/]\\?\])\s*$/,Y=/^\s*(```|~~~)/;function Z(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(Z(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:Z(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),M=(0,s.useRef)(void 0),[L,E]=(0,s.useState)(null),$=(0,s.useRef)(null),T=(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}J.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,G.Cq)(r,t,M.current).pipe(K.sFT(e=>K.OH5(()=>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}),M.current=e.mtime,S.current=!1,(0,Q.oR)(p("editor.conflictReloaded"),"info")):(M.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(()=>{T(e)},5e3)},[T]),I=(0,l.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:!1,link:!1}),P.configure({levels:[1,2,3]}),z,d.A.configure({placeholder:()=>a.A.t("editor.placeholder")}),c.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||L||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")){$.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(O(e)),null!==$.current){let{from:t}=e.state.selection;if(t<$.current)E(null),$.current=null;else{let r=e.state.doc.textBetween($.current,t,"\n");r.includes(" ")||r.includes("\n")?(E(null),$.current=null):E(e=>e?{...e,query:r}:null)}}}}),F=(0,s.useRef)(null);(0,s.useEffect)(()=>{F.current=I},[I]),(0,s.useEffect)(()=>{e&&I&&(b(!0),E(null),$.current=null,U.t4.runPromiseExit((0,G.zF)(r)).then(e=>{"Success"===e._tag?(I.commands.setContent(e.value.content||"",{emitUpdate:!1}),M.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,I,r]);let B=(0,s.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null),S.current&&I&&T(O(I)),E(null),$.current=null,t()},[I,T,t]);return((0,s.useEffect)(()=>()=>{C.current&&clearTimeout(C.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(L?(E(null),$.current=null):B())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,B,L]),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-scrim",onClick:B}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 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:B,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover 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:I}),(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:I})})]}),L&&I&&(0,n.jsx)(q,{editor:I,query:L.query,position:L.position,onClose:()=>{E(null),$.current=null}})]}):null}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>c,fY:()=>d,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 d({activeView:e,onViewChange:t,children:r,onOverscroll:a}){let i=(0,s.useRef)(null),c=(0,s.useRef)(!1),u=(0,s.useRef)(0),m=(0,s.useRef)(0),x=(0,s.useRef)(null),h=(0,s.useRef)(null),f=(0,s.useRef)(0),p=(0,s.useRef)(a);(0,s.useEffect)(()=>{p.current=a},[a]);let[g,b]=(0,s.useState)(0),[v,j]=(0,s.useState)(!1),w=o.indexOf(e),k=o.length-1;(0,s.useEffect)(()=>{u.current=0,m.current=0,h.current=null,queueMicrotask(()=>b(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){var r,n,s;let a=e.target;if("IFRAME"===a.tagName)return;let l=performance.now(),d=(r=f.current,n=h.current,s=()=>(function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth-e.clientWidth>1)return!0;e=e.parentElement}return!1})(a),null!==n&&l-r<=180?n:s()?"inner":"switcher");if(h.current=d,f.current=l,"inner"===d)return;e.preventDefault(),e.stopPropagation(),c.current&&(c.current=!1);let g=window.innerWidth,v=u.current-6*e.deltaX,y=w>0,N=w<k,C=!1;!y&&v>0&&(m.current+=v,x.current=a,v=0,C=!0),!N&&v<0&&(m.current+=v,x.current=a,v=0,C=!0),C&&p.current?.({offset:m.current,phase:"move",triggered:!1,target:a}),u.current=v=Math.max(-g,Math.min(g,v)),b(v),j(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{let e=u.current,r=m.current,n=x.current;m.current=0,x.current=null;let s=.12*g;j(!1),c.current=!0;let a=w;e<-s&&w<k?a=w+1:e>s&&w>0&&(a=w-1),u.current=0,b(0),a!==w&&t(o[a]),a===w&&0!==r&&p.current?.({offset:r,phase:"release",triggered:Math.abs(r)>.2*g,target:n}),setTimeout(()=>{c.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[w,k,t]);let[y,N]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>N(!0))},[]);let C={activeView:e,onViewChange:t,dragOffset:(()=>{if(!y)return 0;let e=window.innerWidth;return e?g/e:0})(),isDragging:y&&v};return(0,n.jsx)(l.Provider,{value:C,children:r})}function c({children:e}){let t,r,{activeView:a,dragOffset:l,isDragging:d}=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:d?"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(),d=(0,s.useRef)(null),c=(0,s.useRef)([]),[u,m]=(0,s.useState)({left:0,width:0}),x=o.indexOf(e),h=()=>{if(!d.current||0===c.current.length)return{left:0,width:0};let e=d.current.getBoundingClientRect(),t=c.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:d,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{c.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}})]})}},66109:(e,t,r)=>{r.d(t,{aO:()=>n,iG:()=>s,jL:()=>o});let n="relative w-full max-w-[calc((100vw_-_28rem)*0.9)] h-[90vh] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden",s="relative w-full max-w-[calc((100vw_-_14rem)*0.9)] h-[90vh] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden",o="grid grid-cols-[repeat(auto-fill,minmax(320px,1fr))] gap-3"},68287:(e,t,r)=>{function n(e){return"loading"===e?"relative session-number-running":""}function s(e,t){return"loading"===e||"unread"===e?"border-transparent bg-orange-11/15 text-orange-11":t?"border-transparent bg-brand/15 text-brand":"border-transparent bg-muted-foreground/15 text-muted-foreground"}function o(e,t){return[n(e),s(e,t)].filter(Boolean).join(" ")}r.d(t,{JQ:()=>s,QV:()=>n,ci:()=>o})},72363:(e,t,r)=>{r.d(t,{$2:()=>j,N4:()=>c,_I:()=>v,fX:()=>u,fZ:()=>m});let n="cockpit update",s={visible:!1,stage:"preparing",startedAt:0,baselineMs:null,installedVersion:null,upToDate:!1,error:null,rolledBack:!1,fixCommand:n,logPath:null,live:!1},o="cockpit:update-seen-at",a=s,l=new Set,i=!1;function d(e){a={...a,...e},l.forEach(e=>e())}function c(e){return l.add(e),()=>l.delete(e)}function u(){return a}function m(){try{window.localStorage.setItem(o,String(Date.now()))}catch{}d({visible:!1})}let x=e=>new Promise(t=>setTimeout(t,e));async function h(){try{let e=await fetch("/api/health",{cache:"no-store",signal:AbortSignal.timeout(2e3)});if(!e.ok)return null;let t=await e.json();return{pid:"number"==typeof t.pid?t.pid:null,version:t.version??null}}catch{return null}}async function f(){try{let e=await fetch("/api/update-state",{cache:"no-store",signal:AbortSignal.timeout(2e3)});if(!e.ok)return{state:null,logPath:null};let t=await e.json();return{state:t.state??null,logPath:t.logPath??null}}catch{return{state:null,logPath:null}}}async function p(e){try{let t=await fetch(`http://127.0.0.1:${e}/`,{cache:"no-store",signal:AbortSignal.timeout(1500)});if(!t.ok)return null;return await t.json()}catch{return null}}function g(e){switch(e){case"installing":return"installing";case"repairing":return"repairing";case"rolling-back":return"rolling-back";case"restarting":case"done":return"restarting";default:return"preparing"}}function b(e,t={}){d({stage:"failed",error:e,...t})}async function v(){if(!i){i=!0,d({...s,visible:!0,stage:"preparing",startedAt:Date.now()});try{let e=await f();d({baselineMs:e.state?.installMs??e.state?.prevInstallMs??null,logPath:e.logPath});let t=await h(),r=t?.pid??null,s=t?.version??null,o=await fetch("/api/update",{method:"POST"});if(!o.ok){let e=await o.json().catch(()=>({}));b(e.error??`HTTP ${o.status}`);return}let l=await o.json().catch(()=>({})),i=l.statusPort??null;d({logPath:l.logPath??a.logPath});let c=0,u=null!==i,m=Date.now()+3e5;for(;Date.now()<m;){if(await x(1e3),u&&null!==i){let e=await p(i);if(e){if(c=0,d({live:!0}),"failed"===e.phase)return void b(e.error??"install failed",{rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n,live:!0});d({stage:g(e.phase),installedVersion:e.installed??a.installedVersion,baselineMs:a.baselineMs??e.prevInstallMs??null})}else++c>=3&&(u=!1,d({live:!1}))}let e=await h();if(e?.pid!=null&&(null===r||e.pid!==r)){let{state:t}=await f();if(t?.phase==="failed")return void b(t.error??"update failed",{rolledBack:!0===t.rolledBack,fixCommand:t.fixCommand??n});let r=e.version??a.installedVersion;d({stage:"done",installedVersion:r,upToDate:null!==r&&r===s});return}}b("timeout")}catch(e){b(e instanceof Error?e.message:String(e))}finally{i=!1}}}async function j(){if(i||a.visible)return;let{state:e,logPath:t}=await f();if(!e?.phase||"done"===e.phase)return;let r=e.startedAt??0,l=e.installMs??e.prevInstallMs??null;if("failed"===e.phase){let a=0;try{a=Number(window.localStorage.getItem(o))||0}catch{}if((e.finishedAt??0)<=a)return;d({...s,visible:!0,stage:"failed",startedAt:r,baselineMs:l,error:e.error??"unknown error",rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n,logPath:t});return}if(!(!r||Date.now()-r>6e5)){i=!0,d({...s,visible:!0,stage:g(e.phase),startedAt:r,baselineMs:l,logPath:t});try{let e=r+3e5;for(;Date.now()<e;){await x(1e3);let{state:e}=await f();if(e?.phase){if("failed"===e.phase)return void b(e.error??"install failed",{rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n});if("done"===e.phase)return void d({stage:"done",installedVersion:e.installed??null,upToDate:!0===e.unchanged});d({stage:g(e.phase)})}}b("timeout")}finally{i=!1}}}},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,d]=(0,s.useState)(()=>e.getAttributes("link").href||""),c=(0,s.useRef)(null);(0,s.useEffect)(()=>{c.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-lv2 p-2 flex items-center gap-2`,style:m,children:[(0,n.jsx)("input",{ref:c,type:"text",value:i,onChange:e=>d(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-11 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),d=(0,s.useRef)(null),[,c]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>c(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-hover"}`,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:d,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-11 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-11 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-11 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-11 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:()=>o});var n=r(95155),s=r(79114);function o({onBrowseProjects:e}){let{t}=(0,s.Bd)();return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-5 bg-card",children:[(0,n.jsx)("svg",{className:"w-14 h-14 text-muted-foreground/40",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"})}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:t("workspace.selectProject")}),(0,n.jsxs)("button",{onClick:e,className:"flex items-center gap-2 px-4 py-2 text-sm rounded-lg bg-primary text-primary-foreground hover:opacity-90 transition-opacity",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"})}),t("workspace.openProject")]})]})}},76412:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>v});var n=r(95155),s=r(12115),o=r(63728),a=r(82032),l=r(34075),i=r(79114),d=r(95045),c=r(75346),u=r(49433),m=r(86957),x=r(53213),h=r(45720),f=r(76900);function p({className:e}){return(0,n.jsxs)("svg",{className:e,fill:"none",viewBox:"0 0 100 100","aria-hidden":"true",children:[(0,n.jsx)("path",{fill:"#0065A9",d:"M96.461 10.796 75.857.876a6.23 6.23 0 0 0-7.107 1.207l-67.451 61.5a4.167 4.167 0 0 0 .004 6.162l5.51 5.009a4.167 4.167 0 0 0 5.32.236l81.228-61.62c2.725-2.067 6.639-.124 6.639 3.297v-.24a6.25 6.25 0 0 0-3.539-5.63Z"}),(0,n.jsx)("path",{fill:"#007ACC",d:"m96.461 89.204-20.604 9.92a6.229 6.229 0 0 1-7.107-1.207l-67.451-61.5a4.167 4.167 0 0 1 .004-6.162l5.51-5.009a4.167 4.167 0 0 1 5.32-.236l81.228 61.62c2.725 2.067 6.639.124 6.639-3.297v.24a6.25 6.25 0 0 0-3.539 5.63Z"}),(0,n.jsx)("path",{fill:"#1F9CF0",d:"M75.858 99.126a6.232 6.232 0 0 1-7.108-1.21c2.306 2.307 6.25.674 6.25-2.588V4.672c0-3.262-3.944-4.895-6.25-2.589a6.232 6.232 0 0 1 7.108-1.21l20.6 9.908A6.25 6.25 0 0 1 100 16.413v67.174a6.25 6.25 0 0 1-3.541 5.633l-20.601 9.906Z"})]})}function g({className:e}){return(0,n.jsx)("svg",{className:e,viewBox:"0 0 466.73 532.09",fill:"currentColor","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M457.43,125.94L244.42,2.96c-6.84-3.95-15.28-3.95-22.12,0L9.3,125.94c-5.75,3.32-9.3,9.46-9.3,16.11v247.99c0,6.65,3.55,12.79,9.3,16.11l213.01,122.98c6.84,3.95,15.28,3.95,22.12,0l213.01-122.98c5.75-3.32,9.3-9.46,9.3-16.11v-247.99c0-6.65-3.55-12.79-9.3-16.11h-.01ZM444.05,151.99l-205.63,356.16c-1.39,2.4-5.06,1.42-5.06-1.36v-233.21c0-4.66-2.49-8.97-6.53-11.31L24.87,145.67c-2.4-1.39-1.42-5.06,1.36-5.06h411.26c5.84,0,9.49,6.33,6.57,11.39h-.01Z"})})}function b({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,i.Bd)(),[a,d]=(0,s.useState)(!1),[c,u]=(0,s.useState)([]),[h,p]=(0,s.useState)(!1),[g,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()=>{p(!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");p(!1)},[e,o]),C=(0,s.useCallback)(()=>{d(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{d(!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 M=async t=>{v(!0);let n=await m.t4.runPromiseExit((0,f.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)},L=c.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-hover 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-lv2 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",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:h?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===L.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):L.map(e=>(0,n.jsx)("button",{onClick:()=>M(e),disabled:g,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-hover transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function v({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:x,onOpenAliasManager:j,onBranchSwitched:w}){let{t:k}=(0,i.Bd)(),y=t?.sessionId?(0,h.X)(t.engine,t.sessionId):null;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:k("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,l.oR)(k("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","data-tooltip":`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,l.oR)(k("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:k("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-hover 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)(b,{cwd:e,currentBranch:s,onSwitched:()=>w?.()})]})]}),(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-hover rounded-lg transition-colors",title:k("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,f.em)(t.cwd).pipe(u.NWQ(()=>u.rIH)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)(p,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&m.t4.runFork((0,f.Q1)(t.cwd).pipe(u.NWQ(()=>u.rIH)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openInCursor"),children:(0,n.jsx)(g,{className:"w-4 h-4"})}),y&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(y).then(()=>{(0,l.oR)(k("toast.copiedCommand",{command:y}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("chat.copyCommandTooltip",{command:y}),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:j,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("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,d.F)(c.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("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-hover rounded-lg transition-colors",title:k("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,Kl:()=>k,M5:()=>l,Or:()=>c,Q1:()=>j,QW:()=>f,Wr:()=>d,Yn:()=>g,b2:()=>w,em:()=>v,fz:()=>b,zF:()=>m});var n=r(49433),s=r(82680);let o=(e,t)=>n.$mh({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)}),d=()=>o("/api/version"),c=()=>o("/api/extension/version"),u=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",m=e=>o(u(e)),x=(e,t,r)=>n.$mh({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=e=>o(`/api/fs/dirs?path=${encodeURIComponent(e)}`),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)},84204:(e,t,r)=>{r.d(t,{Workspace:()=>em});var n=r(95155),s=r(12115),o=r(79114),a=r(4426),l=r(76288),i=r(52153),d=r(21484),c=r(34075),u=r(66109),m=r(61878),x=r(33210),h=r(51914),f=r(94852),p=r(67635),g=r(60241),b=r(42804),v=r(22164),j=r(20986),w=r(68459),k=r(86957),y=r(34582),N=r(85269),C=r(63563),S=r(63040);function M({isOpen:e,htmlAppPreviews:t,activeHtmlAppPreviewPath:r,onShowHtmlAppPreview:a,onMinimizeHtmlAppPreview:l,onCloseHtmlAppPreview:i,onClose:d,onOpenApp:w}){let{t:E,i18n:P}=(0,o.Bd)(),[$,T]=(0,s.useState)([]),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)(""),[D,A]=(0,s.useState)(!1),[H,W]=(0,s.useState)(""),[z,O]=(0,s.useState)(!1),[_,q]=(0,s.useState)({}),V=(0,s.useRef)(null),U=(0,s.useCallback)(async()=>{I(!0);let e=await k.t4.runPromiseExit((0,S.mi)());"Success"===e._tag?T(e.value):console.error("Failed to load html apps",e.cause),I(!1)},[]);(0,s.useEffect)(()=>{e&&(U(),setTimeout(()=>{V.current?.focus(),V.current?.select()},100))},[e,U]);let K=(0,s.useCallback)(()=>{A(!1),d()},[d]);(0,s.useEffect)(()=>{if(!e&&!r)return;let t=e=>{if("Escape"===e.key){if(r)return void i(r);if(D){A(!1),W("");return}K()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,r,K,i,D]);let Q=(0,s.useMemo)(()=>{let e=F.trim().toLowerCase();return e?$.filter(t=>t.name.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):$},[$,F]),G=(0,s.useMemo)(()=>$.filter(e=>!e.builtin).length,[$]),J=F.trim().length>0,Y=P.resolvedLanguage?.startsWith("zh")?"https://opencockpit.dev/zh/docs/agent/html-apps/":"https://opencockpit.dev/en/docs/agent/html-apps/",Z=(0,s.useCallback)(async()=>{let e=H.trim();if(!e)return;O(!0);let t=await k.t4.runPromiseExit((0,S.ot)(e));if("Success"===t._tag)t.value.alreadyExists?(0,c.oR)(E("htmlApps.alreadyAdded"),"info"):((0,c.oR)(E("htmlApps.added"),"success"),(0,C.N)()),W(""),A(!1),await U();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:E("htmlApps.addFailed");(0,c.oR)(n,"error")}O(!1)},[H,U,E]),X=(0,s.useCallback)(async e=>{"Success"===(await k.t4.runPromiseExit((0,S.m3)(e)))._tag?(T(t=>t.filter(t=>t.id!==e)),(0,C.N)()):(0,c.oR)(E("common.deleteFailed"),"error")},[E]),ee=(0,s.useCallback)(e=>{w?w(e):window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:e}})),K()},[K,w]),et=(0,s.useCallback)(e=>{w?w(e):window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:e}})),l()},[l,w]),er=(0,s.useCallback)(e=>{let t=(0,y.Xe)(e);window.open((0,y.PB)(t,window.location.origin),"_blank")},[]),en=(0,s.useCallback)(e=>{q(t=>({...t,[e]:(t[e]||0)+1}))},[]),es=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,c.oR)(E("common.copiedPath"),"success")}catch{(0,c.oR)(E("common.copyFailed"),"error")}},[E]);return(0,n.jsxs)(n.Fragment,{children:[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-scrim",onClick:K}),(0,n.jsxs)("div",{className:u.aO,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:E("htmlApps.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(m.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-foreground-subtle pointer-events-none"}),(0,n.jsx)("input",{ref:V,type:"text",value:F,onChange:e=>B(e.target.value),placeholder:E("htmlApps.searchPlaceholder"),className:"pl-7 pr-6 py-1 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),F&&(0,n.jsx)("button",{onClick:()=>{B(""),V.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:E("fileBrowser.clear"),children:(0,n.jsx)(x.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("button",{onClick:()=>A(!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-hover transition-colors",title:E("htmlApps.addHtmlApp"),children:[(0,n.jsx)(h.A,{className:"w-4 h-4"})," ",E("htmlApps.add")]}),(0,n.jsx)("button",{onClick:K,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:E("common.close"),children:(0,n.jsx)(x.A,{className:"w-5 h-5"})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:R?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:E("common.loading")}):(0,n.jsxs)(n.Fragment,{children:[Q.length>0&&(0,n.jsx)("div",{className:u.jL,children:Q.map(e=>(0,n.jsx)(L,{app:e,onOpenConsole:()=>ee(e.path),onOpenExternal:()=>er(e.path),onPreview:()=>{a({path:e.path,title:e.title,icon:e.icon}),K()},onDelete:()=>X(e.id),onCopyPath:()=>es(e.path)},e.id))}),0===Q.length&&J&&(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:E("htmlApps.emptyNoMatch")}),!J&&0===G&&(0,n.jsxs)("div",{className:`text-center text-muted-foreground py-8 text-sm space-y-2${Q.length>0?" mt-4 border-t border-border/60":""}`,children:[(0,n.jsx)("p",{children:E("htmlApps.emptyNoApps")}),(0,n.jsxs)("p",{children:[E("htmlApps.emptyCreatePrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/html"})," ",E("htmlApps.emptyCreateSuffix")]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("button",{type:"button",onClick:()=>A(!0),className:"text-brand hover:underline",children:E("htmlApps.addExisting")})," \xb7 ",(0,n.jsx)("a",{href:Y,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline",children:E("htmlApps.viewDocs")})]})]})]})})]})]}),e&&D&&(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-scrim",onClick:()=>{z||(A(!1),W(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:E("htmlApps.addHtmlApp")}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:E("htmlApps.pathLabel")}),(0,n.jsx)("input",{type:"text",value:H,onChange:e=>W(e.target.value),onKeyDown:e=>{"Enter"!==e.key||z||Z()},placeholder:"/Users/you/.../report.html",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground 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:()=>{A(!1),W("")},disabled:z,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors disabled:opacity-50",children:E("common.cancel")}),(0,n.jsx)("button",{onClick:Z,disabled:z||!H.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:z?E("htmlApps.adding"):E("htmlApps.add")})]})]})]}),t.map(e=>{let t=r===e.path;return(0,n.jsx)("div",{className:t?"fixed inset-0 z-[60] flex items-center justify-center bg-scrim p-0 md:p-4":"hidden",onClick:l,children:(0,n.jsxs)("div",{className:"bg-card shadow-lv3 border border-brand/30 w-full h-full md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.icon?(0,n.jsx)("span",{className:"text-base leading-none flex-shrink-0",children:e.icon}):(0,n.jsx)(f.A,{className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate max-w-[35%]","data-tooltip":e.title,children:e.title}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground flex-shrink-0","aria-hidden":"true",children:"-"}),(0,n.jsx)("span",{className:"font-mono text-sm text-muted-foreground truncate min-w-0","data-tooltip":e.path,children:e.path}),(0,n.jsx)("button",{onClick:()=>es(e.path),className:"text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("common.copyPath"),"aria-label":E("common.copyPath"),children:(0,n.jsx)(p.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("button",{onClick:l,className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("common.minimize"),children:(0,n.jsx)(g.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>et(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("common.openInConsole"),children:(0,n.jsx)(b.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>er(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("browser.openInNewWindow"),children:(0,n.jsx)(v.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>en(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:E("common.refresh"),children:(0,n.jsx)(j.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>i(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)(x.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,n.jsx)(N.O,{filePath:e.path,reloadKey:_[e.path]||0})})]})},e.path)})]})}function L({app:e,onOpenConsole:t,onOpenExternal:r,onPreview:a,onDelete:l,onCopyPath:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`group flex flex-col h-full border border-border rounded-lg p-3 hover:border-brand hover:shadow-lv2 transition-all cursor-pointer ${e.valid?"":"opacity-60"}`,onClick:()=>e.valid&&a(),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)(v.A,{className:"w-5 h-5"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground truncate","data-tooltip":e.title,children:e.title}),(0,n.jsxs)("div",{className:"font-mono text-[11px] text-muted-foreground truncate","data-tooltip":`/${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:d("htmlApps.invalid")}),e.builtin&&(0,n.jsx)("span",{className:"flex-shrink-0 text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:d("htmlApps.builtin")}),(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",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:d("common.openInConsole"),children:(0,n.jsx)(b.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:r,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:d("browser.openInNewWindow"),children:(0,n.jsx)(v.A,{className:"w-4 h-4"})}),e.builtin?null:c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{u(!1),l()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:d("common.confirm")}),(0,n.jsx)("button",{onClick:()=>u(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:d("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>u(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:d("common.delete"),children:(0,n.jsx)(w.A,{className:"w-4 h-4"})})]})]}),(0,n.jsxs)("div",{className:"font-mono text-xs text-muted-foreground mt-2 break-all",children:[e.path,(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),i()},className:"inline-flex align-middle ml-1 p-0.5 hover:text-foreground hover:bg-hover rounded transition-colors",title:d("common.copyPath"),children:(0,n.jsx)(p.A,{className:"w-3.5 h-3.5"})})]}),(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:d("htmlApps.noDescription")})})]})}var E=r(3238),P=r(62111),$=r(83448),T=r(53317);let R={"claude-fable-5-1":{input:10,output:50,cacheRead:.25,cacheWrite:12.5},"claude-mythos-5-1":{input:10,output:50,cacheRead:.25,cacheWrite:12.5},"claude-fable-5":{input:10,output:50,cacheRead:1,cacheWrite:12.5},"claude-mythos-5":{input:10,output:50,cacheRead:1,cacheWrite:12.5},"claude-opus-5-5":{input:4,output:20,cacheRead:.2,cacheWrite:5},"claude-opus-5":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-8":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-7":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-6":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-5":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-sonnet-5-5":{input:2,output:10,cacheRead:.2,cacheWrite:2.5},"claude-sonnet-5":{input:2,output:10,cacheRead:.2,cacheWrite:2.5},"claude-sonnet-4-6":{input:3,output:15,cacheRead:.3,cacheWrite:3.75},"claude-sonnet-4-5":{input:3,output:15,cacheRead:.3,cacheWrite:3.75},"claude-haiku-5-5":{input:.1,output:.5,cacheRead:.01,cacheWrite:.125},"claude-haiku-4-5":{input:1,output:5,cacheRead:.1,cacheWrite:1.25}},I={input:3,output:15,cacheRead:.3,cacheWrite:3.75},F={light:["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#4a3aa7","#e34948"],dark:["#3987e5","#d95926","#199e70","#c98500","#d55181","#008300","#9085e9","#e66767"]},B={light:{messages:"#2a78d6",toolCalls:"#1baf7a",messagesRgb:"42, 120, 214"},dark:{messages:"#3987e5",toolCalls:"#199e70",messagesRgb:"57, 135, 229"}};function D(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 A(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function H({data:e,height:t=200,formatValue:r=D}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),[l,i]=(0,s.useState)(null),d=(0,s.useRef)([]),c=(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 c=n.getContext("2d");c.scale(l,l),c.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))));c.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",c.font="10px ui-monospace, monospace",c.textAlign="right",c.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;c.fillText(r(t),44,s),c.strokeStyle=(p="--line-2",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),c.lineWidth=.5,c.beginPath(),c.moveTo(50,s),c.lineTo(50+x,s),c.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,d,u;let m=n.data[t];if(m<=0)return;let x=Math.max(1,m/f*h),p=8+h-s-x;c.fillStyle=n.color,o=c,a=r,l=p,i=b,u=2,(d=x)<1||(u=Math.min(u,d/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+d-u),o.quadraticCurveTo(a+i,l+d,a+i-u,l+d),o.lineTo(a+u,l+d),o.quadraticCurveTo(a,l+d,a,l+d-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}),c.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",c.font="9px ui-monospace, monospace",c.textAlign="center",c.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&c.fillText(e,r+b/2,8+h+6)}),d.current=v},[e,t,r]);(0,s.useEffect)(()=>{c();let e=new ResizeObserver(()=>c());return a.current&&e.observe(a.current),()=>e.disconnect()},[c]);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=d.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-lv2 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)(),{resolvedTheme:r}=(0,E.DP)(),s=B[r],a=Math.max(1,...Object.values(e)),l=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:l.map(r=>{let o=e[String(r)]||0,l=o/a;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:r,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*l)}px`,backgroundColor:l>0?`rgba(${s.messagesRgb}, ${.2+.8*l})`:"var(--muted)"}}),r%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:r})]},r)})})]})}function z({isOpen:e,onClose:t}){var r;let a,l,{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(!0),[x,h]=(0,s.useState)("day"),[f,p]=(0,s.useState)("tokens"),[g,b]=(0,s.useState)(null),{resolvedTheme:v}=(0,E.DP)();(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>m(!0)),k.t4.runPromiseExit((0,$.Cr)()).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>c(t))}queueMicrotask(()=>m(!1))}))},[e]);let j=(0,s.useMemo)(()=>{var e;let t,r,n=Object.keys(d?.modelUsage||{}).filter(e=>!e.startsWith("<")),s=new Map;for(let e of d?.dailyModelTokens||[])for(let[t,r]of Object.entries(e.tokensByModel)){let n=s.get(t);r>0&&(!n||e.date<n)&&s.set(t,e.date)}return e=[...n].sort((e,t)=>(s.get(e)??"￿").localeCompare(s.get(t)??"￿")||e.localeCompare(t)),t=F[v],r={},e.forEach((e,n)=>{r[e]=t[n%t.length]}),r},[d,v]),w=(0,s.useMemo)(()=>d?.modelUsage?Object.entries(d.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:(0,T.J)(e),color:j[e],usage:t,cost:(r=function(e){let t=e.replace(/-\d{8}$/,""),r=R[t];if(r)return r;let n=t.toLowerCase();return n.includes("fable")||n.includes("mythos")?{input:10,output:50,cacheRead:1,cacheWrite:12.5}:n.includes("opus")?{input:5,output:25,cacheRead:.5,cacheWrite:6.25}:n.includes("haiku")?{input:1,output:5,cacheRead:.1,cacheWrite:1.25}:I}(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):[],[d,j]),y=(0,s.useMemo)(()=>w.reduce((e,t)=>e+t.cost,0),[w]),N=(0,s.useMemo)(()=>w.map(e=>e.id),[w]),C=(0,s.useMemo)(()=>{let e={};for(let t of w)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[w]),{activityChart:S,tokenChart:M,costChart:L}=(0,s.useMemo)(()=>{let e=d?.dailyActivity||[],t=d?.dailyModelTokens||[];if("day"===x){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:B[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:B[v].toolCalls}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:n.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:o,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:n.map(t=>(t.tokensByModel[e]||0)*(C[e]||0)),color:j[e]}))}}}if("week"===x){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:B[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:B[v].toolCalls}]};return{activityChart:s,tokenChart:{labels:n,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:r.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:n,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:r.map(t=>(t.tokensByModel[e]||0)*(C[e]||0)),color:j[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:B[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:B[v].toolCalls}]};return{activityChart:s,tokenChart:{labels:n,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:r.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:n,datasets:N.map(e=>({id:e,label:(0,T.J)(e),data:r.map(t=>(t.tokensByModel[e]||0)*(C[e]||0)),color:j[e]}))}}},[d,x,N,C,j,i]),_=g&&j[g]?g:null,q=(0,s.useMemo)(()=>{let e="tokens"===f?M:L;return _?{...e,datasets:e.datasets.filter(e=>e.id===_)}:e},[M,L,f,_]);if((0,P.E)(t,e),!e)return null;let V=[{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-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-lv3 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:V.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${x===e.key?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>h(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover 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:u?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):d?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(O,{label:i("tokenStats.totalSessions"),value:String(d.totalSessions??0)}),(0,n.jsx)(O,{label:i("tokenStats.totalMessages"),value:D(d.totalMessages??0)}),(0,n.jsx)(O,{label:i("tokenStats.equivalentApiCost"),value:A(y),highlight:!0}),(0,n.jsx)(O,{label:i("tokenStats.longestSession"),value:d.longestSession?(a=Math.floor((r=d.longestSession.duration)/36e5),l=Math.floor(r%36e5/6e4),a>0?`${a}h ${l}m`:`${l}m`):"-"}),(0,n.jsx)(O,{label:i("tokenStats.firstUse"),value:d.firstSessionDate?d.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:B[v].messages}}),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:B[v].toolCalls}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(H,{data:S,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"===f?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>p("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===f?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>p("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:w.map(e=>(0,n.jsxs)("button",{onClick:()=>b(_===e.id?null:e.id),className:`flex items-center gap-1 rounded-sm transition-opacity hover:opacity-100 ${_&&_!==e.id?"opacity-40":""}`,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)(H,{data:q,height:180,formatValue:"tokens"===f?D:A})})]}),(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:[w.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:D(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:y>0?`${(e.cost/y*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:A(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:D(w.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(w.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(w.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:D(w.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:A(y)})]})]})]})})]}),d.hourCounts&&Object.keys(d.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(W,{hourCounts:d.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function O({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 _=r(60865),q=r(52252),V=r(48764),U=r(58250),K=r(5135),Q=r(38408);function G({skillId:e,onClose:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(null),[i,d]=(0,s.useState)(!0),[u,m]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return d(!0),k.t4.runPromiseExit((0,V.Bz)(e)).then(e=>{t||("Success"===e._tag?l(e.value):console.error("Failed to load skill content",e.cause),d(!1))}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),(0,P.k)(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let x=(0,s.useCallback)(async()=>{if(a?.path)try{await navigator.clipboard.writeText(a.path),(0,c.oR)(r("common.copiedPath"),"success")}catch{(0,c.oR)(r("common.copyFailed"),"error")}},[a,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-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 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:a?.name?`/${a.name}`:r("skills.previewTitle")}),(0,n.jsx)("button",{onClick:x,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:r("skills.copyPath"),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"})]})})]}),a?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:a.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:()=>m("preview"),className:`px-3 py-1 transition-colors ${"preview"===u?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:r("common.preview")}),(0,n.jsx)("button",{onClick:()=>m("source"),className:`px-3 py-1 transition-colors ${"source"===u?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:r("skills.source")})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors flex-shrink-0",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"})})})]}),i?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:r("common.loading")}):a&&a.valid?"preview"===u?(0,n.jsx)(K.M,{content:a.content,filePath:a.path,cwd:a.path.slice(0,Math.max(0,a.path.lastIndexOf("/"))),embedded:!0,onClose:t}):(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsx)(Q.XO,{content:a.content,filePath:a.path,className:"min-h-full"})}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:r("skills.cannotRead")})]})]})}function J({isOpen:e,onClose:t}){let{t:r,i18n:a}=(0,o.Bd)(),[l,i]=(0,s.useState)([]),[d,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(""),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(null),N=(0,s.useRef)(null),C=(0,s.useCallback)(async()=>{m(!0);let e=await k.t4.runPromiseExit((0,V.Hy)());"Success"===e._tag?i(e.value):console.error("Failed to load skills",e.cause),m(!1)},[]);(0,s.useEffect)(()=>{e&&(C(),setTimeout(()=>{N.current?.focus(),N.current?.select()},100))},[e,C]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!w){if(f){p(!1),b("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,f,w]);let S=(0,s.useMemo)(()=>{let e=x.trim().toLowerCase();return e?l.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):l},[l,x]),M=a.resolvedLanguage?.startsWith("zh")?"https://opencockpit.dev/zh/docs/agent/skills/":"https://opencockpit.dev/en/docs/agent/skills/",L=(0,s.useCallback)(async()=>{let e=g.trim();if(!e)return;j(!0);let t=await k.t4.runPromiseExit((0,V.L5)(e));if("Success"===t._tag)(0,c.oR)(t.value.alreadyExists?r("skills.alreadyAdded"):r("skills.added"),t.value.alreadyExists?"info":"success"),b(""),p(!1),await C(),t.value.alreadyExists||(0,U.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause,s=n instanceof Error?n.message:r("skills.addFailed");(0,c.oR)(s,"error")}j(!1)},[g,C,r]),E=(0,s.useCallback)(async e=>{"Success"===(await k.t4.runPromiseExit((0,V.hp)(e)))._tag?(i(t=>t.filter(t=>t.id!==e)),(0,U.k)()):(0,c.oR)(r("common.deleteFailed"),"error")},[r]),P=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,c.oR)(r("common.copiedPath"),"success")}catch{(0,c.oR)(r("common.copyFailed"),"error")}},[r]);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-scrim",onClick:t}),(0,n.jsxs)("div",{className:u.aO,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:r("skills.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:N,type:"text",value:x,onChange:e=>h(e.target.value),placeholder:r("skills.searchPlaceholder"),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),x&&(0,n.jsx)("button",{onClick:()=>{h(""),N.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:r("skills.clearSearch"),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:()=>p(!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-hover transition-colors",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"})}),r("skills.addSkill")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded 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"})})})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:d?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:r("common.loading")}):0===S.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm space-y-2",children:0===l.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{children:r("skills.emptyNoSkills")}),(0,n.jsxs)("p",{children:[r("skills.emptyIntroPrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/skillify"})," ",r("skills.emptyIntroSuffix")]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("button",{type:"button",onClick:()=>p(!0),className:"text-brand hover:underline",children:r("skills.addSkill")})," \xb7 ",(0,n.jsx)("a",{href:M,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline",children:r("skills.viewDocs")})]})]}):r("skills.emptyNoMatch")}):(0,n.jsx)("div",{className:u.jL,children:S.map(e=>(0,n.jsx)(Y,{skill:e,onPreview:()=>y(e.id),onDelete:()=>E(e.id),onCopyPath:()=>P(e.path)},e.id))})})]})]}),f&&(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-scrim",onClick:()=>{v||(p(!1),b(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:r("skills.addSkill")}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:r("skills.pathLabel")}),(0,n.jsx)("input",{type:"text",value:g,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"!==e.key||v||L()},placeholder:r("skills.pathPlaceholder"),autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground 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:()=>{p(!1),b("")},disabled:v,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors disabled:opacity-50",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:L,disabled:v||!g.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:v?r("skills.adding"):r("skills.add")})]})]})]}),w&&(0,n.jsx)(G,{skillId:w,onClose:()=>y(null)})]}):null}function Y({skill:e,onPreview:t,onDelete:r,onCopyPath:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(!1);return(0,n.jsxs)("div",{onClick:e.valid?t:void 0,role:e.valid?"button":void 0,tabIndex:e.valid?0:void 0,onKeyDown:r=>{e.valid&&("Enter"===r.key||" "===r.key)&&(r.preventDefault(),t())},className:`group flex flex-col h-56 border border-border rounded-lg p-3 hover:border-brand hover:shadow-lv2 transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-ring ${e.valid?"cursor-pointer":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 flex-shrink-0",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)(q.A,{className:"w-5 h-5"})}),(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground truncate flex-1 min-w-0","data-tooltip":`/${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:l("skills.invalid")}),(0,n.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",children:i?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:l("common.confirm")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(!1)},className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:l("common.cancel")})]}):(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d(!0)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",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 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})})]}),(0,n.jsxs)("div",{className:"font-mono text-xs text-muted-foreground mt-2 flex-shrink-0 break-all line-clamp-2","data-tooltip":e.path,children:[e.path,(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),a()},className:"inline-flex align-middle ml-1 p-0.5 hover:text-foreground hover:bg-hover rounded transition-colors",title:l("skills.copyPath"),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 line-clamp-4","data-tooltip":e.description||void 0,children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:l("skills.noDescription")})}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-auto pt-1 truncate flex-shrink-0","data-tooltip":e.argumentHint,children:e.argumentHint})]})}var Z=r(1767),X=r(47650),ee=r(7578);let et=[],er=[];function en(){er.forEach(e=>e())}function es(e){et=et.filter(t=>t.id!==e),en()}function eo({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return er.push(t),()=>{er=er.filter(e=>e!==t)}},[]),et}();return 0===t.length?null:(0,X.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)(ea,{item:t,onNavigate:e,onRemove:es},t.id))}),document.body)}function ea({item:e,onNavigate:t,onRemove:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),d=(0,s.useRef)(void 0),c=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(d.current=setTimeout(c,5e3),()=>clearTimeout(d.current)),[c]);let u=(0,s.useCallback)(()=>{clearTimeout(d.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),m=(0,s.useCallback)(()=>{clearTimeout(d.current)},[]),x=(0,s.useCallback)(()=>{d.current=setTimeout(c,2e3)},[c]);return(0,n.jsxs)("div",{className:`group pointer-events-auto relative bg-popover border border-border rounded-lg shadow-lv3 px-3 py-3 min-h-[84px] min-w-[260px] max-w-[340px] cursor-pointer 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.jsx)("div",{className:"pointer-events-none absolute inset-0 rounded-lg bg-hover opacity-0 group-hover:opacity-100 transition-opacity"}),(0,n.jsxs)("div",{className:"relative flex items-start 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)(ee.l,{projectNumber:e.projectNumber,sessionNumber:e.sessionNumber,className:"ml-auto"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:"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:"relative text-xs text-muted-foreground line-clamp-2 break-words mt-1 ml-6",children:e.message})]})}var el=r(77725),ei=r(49433),ed=r(82680);let ec=ei.$mh({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new ed.uV({message:"fetch /api/projects failed",cause:e})});var eu=r(96472);function em({initialCwd:e,initialSessionId:t,initialBlank:r}){let{t:c}=(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),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),[E,P]=(0,s.useState)(!1),[$,T]=(0,s.useState)(!1),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)(null),[H,W]=(0,s.useState)({}),[O,q]=(0,s.useState)({}),[V,U]=(0,s.useState)(!1),[K,Q]=(0,s.useState)(new Set),G=(0,s.useRef)(new Map),Y=(0,s.useRef)(new Map),X=(0,s.useRef)(new Map),ee=(0,s.useRef)(null),er=(0,el.Z)(ec,[]);(0,s.useEffect)(()=>{if("success"===er.status){let e=er.data;m([...e.projects||[]]),h(e.activeIndex||0),p(e.collapsed||!1),U(!0)}else"error"===er.status&&(console.error("Failed to load projects:",er.error),U(!0))},[er]);let es=(0,s.useCallback)(async(e,t,r)=>{let n,s=await k.t4.runPromise((n={projects:e,activeIndex:t,collapsed:r},ei.$mh({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new ed.uV({message:"save /api/projects failed",cause:e})})).pipe(ei.gPK));"Left"===s._tag&&console.error("Failed to save projects:",s.left)},[]),ea=(0,s.useCallback)((e,t)=>{var r,n;let s=u[x]?.cwd,o=(r=s?{cwd:s,sessionId:X.current.get(s)}:void 0,n={cwd:e,sessionId:t},r?.cwd&&r.sessionId&&(r.cwd!==n.cwd||n.sessionId&&r.sessionId!==n.sessionId)?{cwd:r.cwd,sessionId:r.sessionId}:null);o&&k.t4.runFork((0,eu.T$)(o.cwd,o.sessionId).pipe(ei.h9N(()=>ei.rIH)))},[u,x]);(0,s.useEffect)(()=>{let e=u[x]?.cwd;e&&Q(t=>t.has(e)?t:new Set(t).add(e))},[x,u]),(0,s.useEffect)(()=>{for(let[e,t]of G.current.entries()){let r=u[x]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r,projectNumber:u.findIndex(t=>t.cwd===e)+1},"*")}},[x,u]);let ex=(0,s.useCallback)(e=>{let t=u[x]?.cwd,r=t?G.current.get(t):null,n=r?.contentWindow;if(!n)return;let s=n.document.createEvent("CustomEvent");s.initCustomEvent("console-open-browser",!1,!1,{url:e}),n.dispatchEvent(s)},[x,u]),eh=(0,s.useCallback)(e=>{B(t=>t.some(t=>t.path===e.path)?t:[...t,e]),A(e.path)},[]),ef=(0,s.useCallback)(()=>{A(null)},[]),ep=(0,s.useCallback)(e=>{B(t=>t.filter(t=>t.path!==e)),A(t=>t===e?null:t)},[]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type!=="SESSION_NUMBERS")return;let t=e.data.cwd;if("string"!=typeof t||!Array.isArray(e.data.sessionIds))return;let r=e.data.sessionIds.map(e=>"string"==typeof e?e:null);q(e=>{let n=e[t];return n&&n.length===r.length&&n.every((e,t)=>e===r[t])?e:{...e,[t]:r}})};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let eg=(0,s.useMemo)(()=>{let e={};return u.forEach((t,r)=>{(O[t.cwd]??[]).forEach((n,s)=>{n&&(e[`${t.cwd}
11
11
  ${n}`]=`${r+1}.${s+1}`)})}),e},[u,O]),eb=(0,s.useCallback)(()=>{let e=crypto.randomUUID(),t=new Map(u.map((e,t)=>[e.cwd,t+1])),r=[...G.current.values()];return 0===r.length?Promise.resolve({}):new Promise(n=>{let s={},o=new Set(r.map(e=>e.contentWindow).filter(Boolean)),a=()=>{window.removeEventListener("message",l),clearTimeout(i),W(s),n(s)},l=r=>{if(r.data?.type!=="SESSION_NUMBERS"||r.data?.requestId!==e||!o.delete(r.source))return;let n=t.get(r.data.cwd);n&&Array.isArray(r.data.sessionIds)&&r.data.sessionIds.forEach((e,t)=>{"string"==typeof e&&(s[`${r.data.cwd}
12
12
  ${e}`]=`${n}.${t+1}`)}),0===o.size&&a()};window.addEventListener("message",l);let i=window.setTimeout(a,300);r.forEach(t=>t.contentWindow?.postMessage({type:"GET_SESSION_NUMBERS",requestId:e},"*"))})},[u]),ev=Object.fromEntries(u.map((e,t)=>[e.cwd,t+1]));(0,s.useEffect)(()=>{g&&eb()},[g,eb]);let ej=(0,s.useCallback)((e,t,r=!1)=>{let n=new URL(window.location.href);n.searchParams.set("cwd",e),t?n.searchParams.set("sessionId",t):n.searchParams.delete("sessionId"),r?n.searchParams.set("newChat","1"):n.searchParams.delete("newChat"),window.history.replaceState({},"",n.toString());let s=e.split("/").filter(Boolean).pop();document.title=s||"Cockpit"},[]),ew=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!V||ew.current||!e)return;ew.current=!0,t?(Y.current.set(e,{sessionId:t}),X.current.set(e,t)):r&&(Y.current.set(e,{blank:!0}),X.current.set(e,null));let n=u.findIndex(t=>t.cwd===e);if(n>=0)n!==x&&(h(n),es(u,n,f));else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),es(t,r,f)}ej(e,t,r)},[V,e,t,r,u,x,f,es,ej]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="GET_PROJECT_NUMBER"){let t=u.findIndex(t=>t.cwd===e.data.cwd);t>=0&&e.source&&"postMessage"in e.source&&e.source.postMessage({type:"PROJECT_NUMBER",projectNumber:t+1},"*");return}if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&"sessionId"in e.data){let{cwd:t,sessionId:r}=e.data;"string"==typeof r&&r?X.current.set(t,r):X.current.set(t,null);let n=u[x];n?.cwd===t&&ej(t,"string"==typeof r?r:void 0,null===r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r,lastUserMessage:n}=e.data,s=u[x];if(s?.cwd!==t){let e=t.split("/").pop()||t;eb().then(s=>{let o,[a,l]=s[`${t}
13
13
  ${r}`]?.split(".")??[],i=u.findIndex(e=>e.cwd===t);o=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,et=[...et,{projectName:e,message:n,cwd:t,sessionId:r,projectNumber:a??(i>=0?i+1:void 0),sessionNumber:l,id:o}],en()})}}if(e.data?.type==="OPEN_TOKEN_STATS"&&y(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&(L(e.data.cwd),C(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){ee.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!==ee.current&&ee.current!==x&&h(ee.current),ee.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r,switchToAgent:n,file:s}=e.data,o=r||"";ea(t,o||void 0),X.current.set(t,o);let a=u.findIndex(e=>e.cwd===t);if(a>=0){if(o){let e=G.current.get(t);e?.contentWindow?e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:o,...n?{switchToAgent:!0}:{}},"*"):Y.current.set(t,{sessionId:o,...n?{switchToAgent:!0}:{}})}if(s){let e=G.current.get(t);e?.contentWindow?e.contentWindow.postMessage({type:"OPEN_FILE",path:s},"*"):Y.current.set(t,{...Y.current.get(t),file:s})}a!==x&&(h(a),es(u,a,f))}else{let e=[...u,{cwd:t}],r=e.length-1;m(e),h(r),es(e,r,f),(o||s)&&Y.current.set(t,{...o?{sessionId:o}:{},...n?{switchToAgent:!0}:{},...s?{file:s}:{}})}ej(t,o)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[u,x,f,ej,es,eb,ea]),(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 ek=(0,s.useCallback)(e=>{let t=u[e];if(t&&(e!==x&&ea(t.cwd,X.current.get(t.cwd)),h(e),es(u,e,f),t?.cwd)){let e=X.current.get(t.cwd);ej(t.cwd,e??void 0,null===e)}},[u,x,f,es,ej,ea]),ey=(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),es(t,r,f)},[u,x,f,es]),eN=(0,s.useCallback)(e=>{let t=u[x],r=e.findIndex(e=>e.cwd===t?.cwd);m(e),h(r>=0?r:0),es(e,r>=0?r:0,f)},[u,x,f,es]),eC=(0,s.useCallback)(()=>{let e=!f;p(e),es(u,x,e)},[u,x,f,es]),eS=(0,s.useCallback)((e,t)=>{ea(e,t),X.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=G.current.get(e);n?.contentWindow?n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"):Y.current.set(e,{sessionId:t,switchToAgent:!0}),h(r),es(u,r,f)}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),Y.current.set(e,{sessionId:t,switchToAgent:!0})}ej(e,t),b(!1)},[u,f,es,ej,ea]),eM=(0,s.useCallback)((e,t)=>{ea(e,t),X.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=G.current.get(e);n?.contentWindow?n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"):Y.current.set(e,{sessionId:t,switchToAgent:!0}),r!==x&&(h(r),es(u,r,f))}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),Y.current.set(e,{sessionId:t,switchToAgent:!0})}ej(e,t)},[u,x,f,es,ej,ea]),eL=(0,s.useCallback)((e,t)=>{let r=X.current.get(e)??void 0;ea(e,r);let n=u.findIndex(t=>t.cwd===e);if(n>=0){let r=G.current.get(e);r?.contentWindow?r.contentWindow.postMessage({type:"FOCUS_CONSOLE_BUBBLE",commandId:t},"*"):Y.current.set(e,{...Y.current.get(e),bubble:t}),n!==x&&(h(n),es(u,n,f))}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),Y.current.set(e,{bubble:t})}ej(e,r)},[u,x,f,es,ej,ea]);return V?(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:ek,onRemoveProject:ey,onReorderProjects:eN,onToggleCollapse:eC,onOpenSessionBrowser:()=>b(!0),onOpenSettings:()=>j(!0),onOpenNote:e=>{L(e??null),C(!0)},onOpenSkills:()=>P(!0),onOpenBots:()=>T(!0),onOpenApps:()=>I(!0),htmlAppPreviews:F,activeHtmlAppPreviewPath:D,onShowHtmlAppPreview:eh,onSwitchProject:eM,onFocusTerminal:eL,onResolveSessionNumbers:eb,sessionOrders:O,sessionNumbers:eg}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===u.length?(0,n.jsx)(l.EmptyState,{onBrowseProjects:()=>b(!0)}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:u.map((e,t)=>{var r;let s,o,a;return K.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?G.current.set(e.cwd,t):G.current.delete(e.cwd)},src:(s=Y.current.get(e.cwd),r=e.cwd,o=`/project?cwd=${encodeURIComponent(r)}`,s?.sessionId?o+=`&sessionId=${encodeURIComponent(s.sessionId)}`:s?.blank&&(o+="&newChat=1"),s?.file?o+=`&file=${encodeURIComponent(s.file)}`:s?.bubble&&(o+=`&bubble=${encodeURIComponent(s.bubble)}`),(a=s?.file?"explorer":s?.bubble?"console":s?.sessionId&&s.switchToAgent?"agent":null)&&(o+=`&view=${a}`),o),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:eS,sessionNumbers:H,projectNumbers:ev,onAddProject:e=>{let t=u.findIndex(t=>t.cwd===e);if(ea(e,t>=0?X.current.get(e):void 0),t>=0)h(t),es(u,t,f);else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),es(t,r,f)}b(!1)}}),(0,n.jsx)(d.SettingsModal,{isOpen:v,onClose:()=>j(!1)}),(0,n.jsx)(z,{isOpen:w,onClose:()=>y(!1)}),(0,n.jsx)(_.NoteModal,{isOpen:N,onClose:()=>{C(!1),L(null)},projectCwd:S,projectName:S?S.split("/").pop():null}),(0,n.jsx)(J,{isOpen:E,onClose:()=>P(!1)}),(0,n.jsx)(Z.BotsModal,{isOpen:$,onClose:()=>T(!1)}),(0,n.jsx)(M,{isOpen:R,htmlAppPreviews:F,activeHtmlAppPreviewPath:D,onShowHtmlAppPreview:eh,onMinimizeHtmlAppPreview:ef,onCloseHtmlAppPreview:ep,onClose:()=>I(!1),onOpenApp:ex}),(0,n.jsx)(eo,{onNavigate:eM})]}):(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:c("workspace.loadingText")})]})})}},92689:(e,t,r)=>{r.d(t,{S:()=>o});var n=r(95155),s=r(57125);function o({engine:e,tooltip:t,size:r="md"}){let a=e||"claude";return(0,s.ch)(a)?(0,n.jsx)("span",{className:"shrink-0 inline-flex items-center","data-tooltip":t??s.H[a],children:(0,n.jsx)(s.eV,{engine:a,className:"sm"===r?"h-3 w-3":"h-3.5 w-3.5"})}):(0,n.jsx)("span",{className:"shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded bg-muted text-muted-foreground","data-tooltip":t??a,children:a})}},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),i=r(96625);let d={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:u}){let{t:m}=(0,o.Bd)(),x=!!r,[h,f]=(0,s.useState)(r?.type||"once"),[p,g]=(0,s.useState)(r?.message||""),[b,v]=(0,s.useState)(r?.taskFile?"file":"message"),[j,w]=(0,s.useState)(r?.taskFile||""),[k,y]=(0,s.useState)(r?String(r.delayMinutes||r.intervalMinutes||""):""),[N,C]=(0,s.useState)(r?.cron||""),[S,M]=(0,s.useState)(r?.activeFrom||"09:00"),[L,E]=(0,s.useState)(r?.activeTo||"18:00"),[P,$]=(0,s.useState)(!!(r?.activeFrom&&r?.activeTo)),[T,R]=(0,s.useState)(null),I=(0,s.useRef)(null),F=(0,s.useRef)(null),B=(0,i.n)({value:p,onChange:g,textareaRef:F});(0,s.useEffect)(()=>{F.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{I.current&&!I.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let D=(0,s.useCallback)(()=>{let n="file"===b,s=n?{message:"",taskFile:j.trim()}:{message:p.trim(),taskFile:""};if(n?!s.taskFile:!s.message)return;let o=null;if("once"===h){let e=T||parseInt(k,10);if(!e||e<=0)return;o={...s,type:"once",delayMinutes:e}}else if("interval"===h){let e=T||parseInt(k,10);if(!e||e<=0)return;o={...s,type:"interval",intervalMinutes:e,...P?{activeFrom:S,activeTo:L}:{}}}else if("cron"===h){let e=T||N.trim();if(!e)return;o={...s,type:"cron",cron:e}}o&&(x&&r&&u?u(r.id,o):t(o),e())},[p,b,j,h,T,k,N,P,S,L,t,e,x,r,u]);return(0,n.jsxs)("div",{ref:I,className:`w-[28rem] max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 ${x?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&D()},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:x?m("scheduledTasks.editTask"):m("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)("div",{className:"flex gap-1 mb-1.5",children:["message","file"].map(e=>(0,n.jsx)("button",{onClick:()=>v(e),className:`px-2 py-1 text-xs rounded transition-colors ${b===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"message"===e?m("scheduledTasks.sendMessage"):m("scheduledTasks.taskFile")},e))}),"message"===b?(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("textarea",{ref:F,value:p,onChange:e=>{g(e.target.value),B.trackCaret(e.target)},onSelect:e=>B.trackCaret(e.currentTarget),onKeyDown:e=>{B.handleKeyDown(e)},placeholder:m("scheduledTasks.messagePlaceholder"),rows:5,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-y min-h-[6rem]"}),(0,n.jsx)(i.V,{ac:B,className:"absolute top-full left-0 right-0 mt-1 max-h-48 z-10"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:j,onChange:e=>w(e.target.value),placeholder:m("scheduledTasks.taskFilePlaceholder"),className:"w-full px-2 py-1.5 text-sm font-mono border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:m("scheduledTasks.taskFileHint")})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:m("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{f(e),R(null),y(""),C("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${h===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?m("scheduledTasks.once"):"interval"===e?m("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:m("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:d[h].map(e=>(0,n.jsx)("button",{onClick:()=>{R(e.value),"cron"===h?C(String(e.value)):y(String(e.value))},className:`px-2 py-1 text-xs rounded border transition-colors ${T===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:m(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===h?m("scheduledTasks.customCron"):m("scheduledTasks.customMinutes")}),"cron"===h?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:N,onChange:e=>{C(e.target.value),R(null)},placeholder:m("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),N.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,d={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")},c={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=>c[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:d[r]||r,b:d[n]||n})}return`${t("cron.weekdayPrefix")}${d[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}}(N.trim())||(0,n.jsx)("span",{className:"text-destructive",children:m("scheduledTasks.cronFormat")})})]}):(0,n.jsx)("input",{type:"number",value:k,onChange:e=>{y(e.target.value),R(null)},placeholder:m("scheduledTasks.minutesPlaceholder"),min:1,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]}),"interval"===h&&(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:P,onChange:e=>$(e.target.checked),className:"rounded border-border"}),m("scheduledTasks.limitTimeRange")]}),P&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:S,onChange:e=>M(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:m("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:L,onChange:e=>E(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:D,disabled:!(("file"===b?!!j.trim():!!p.trim())&&("once"===h||"interval"===h?!!(T||k&&parseInt(k,10)>0):"cron"===h&&!!(T||N.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:x?m("scheduledTasks.saveBtn",{modKey:(0,l.Mu)()}):m("scheduledTasks.createBtn",{modKey:(0,l.Mu)()})})]})]})}},94720:(e,t,r)=>{r.d(t,{AJ:()=>g,Cb:()=>E,D0:()=>C,D5:()=>P,DN:()=>m,Jn:()=>c,MR:()=>x,Ok:()=>k,QF:()=>d,SN:()=>b,UV:()=>L,Vv:()=>j,Yj:()=>M,Yn:()=>S,bv:()=>v,cm:()=>h,cv:()=>w,jO:()=>y,px:()=>$,tp:()=>N,uc:()=>p,y8:()=>f});var n=r(49433),s=r(82680);let o=e=>n.$mh({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new s.uV({message:`fetch ${e} failed`,cause:t})}),a=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:r=>new s.uV({message:`${t.method} ${e} failed`,cause:r})}),l=(e,t)=>a(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i=(e,t)=>n.$mh({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}`);return await r.json()},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),d=(e,t)=>n.JkU(function*(){let r=new URLSearchParams({cwd:e});t&&r.set("tabId",t);let n=yield*o(`/api/terminal/env?${r}`);return{env:n.env||{},home:n.home||""}}),c=()=>o("/api/terminal/aliases").pipe(n.TjK(e=>e.aliases||{})),u=(e,t)=>`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}`,m=(e,t)=>o(u(e,t)).pipe(n.TjK(e=>e.order||[])),x=(e,t)=>o(u(e,t)).pipe(n.TjK(e=>e.titles||{})),h=(e,t,r,n)=>l("/api/terminal/bubble-order",{cwd:e,tabId:t,order:r,sourceId:n}),f=(e,t,r,n)=>l("/api/terminal/bubble-order",{cwd:e,tabId:t,titles:{[r]:n}}),p=(e,t,r,n=100)=>o(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&page=${r}&pageSize=${n}`),g=(e,t,r,n)=>l("/api/terminal/history",{cwd:e,tabId:t,entry:r,sourceId:n}),b=(e,t,r,n)=>a(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&commandId=${encodeURIComponent(r)}${n?`&sourceId=${encodeURIComponent(n)}`:""}`,{method:"DELETE"}),v=(e,t,r,n,s)=>a("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:t,id:r,fields:n,sourceId:s})}),j=e=>l("/api/terminal/env",e),w=e=>l("/api/terminal/aliases",{aliases:e}),k=e=>l("/api/terminal/register",e),y=e=>l("/api/terminal/unregister",e),N=e=>n.$mh({try:async()=>{let t=await fetch("/api/terminal/autocomplete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"POST /api/terminal/autocomplete failed",cause:e})}),C=e=>o(`/api/project-settings?cwd=${encodeURIComponent(e)}`),S=e=>l("/api/project-settings",e),M=()=>o("/api/services/config?scope=global"),L=e=>o(`/api/services/config?cwd=${encodeURIComponent(e)}`),E=e=>i("/api/services/config",e),P=()=>o("/api/terminal/running"),$=e=>i("/api/terminal/running",{commandId:e})},95608:(e,t,r)=>{r.d(t,{TabManager:()=>oe});var n=r(95155),s=r(12115),o=r(79114);let a=(0,s.createContext)(null);function l({value:e,children:t}){return(0,n.jsx)(a.Provider,{value:e,children:t})}var i=r(66109),d=r(95045),c=r(75346),u=r(86957),m=r(83448),x=r(92689),h=r(7578);function f({isOpen:e,onClose:t,cwd:r,onSelectSession:a,projectNumber:l,openSessionIds:p=[]}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)([]),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(""),S=(0,s.useRef)(null),M=(0,s.useCallback)(async()=>{let e;if(!r)return;w(!0),y(null);let t=(e=r.replace(/[^a-zA-Z0-9]/g,"-")).length<=200?e:`${e.slice(0,200)}-${function(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r)|0;return Math.abs(t).toString(36)}(r)}`,n=await u.t4.runPromiseExit((0,m.QW)(t));"Success"===n._tag?v(n.value):y("Failed to load sessions"),w(!1)},[r]);(0,s.useEffect)(()=>{e&&(M(),setTimeout(()=>{S.current?.focus(),S.current?.select()},100))},[e,M]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let L=b.filter(e=>{if(!N)return!0;let t=N.toLowerCase();return void 0!==e.searchText?e.searchText.includes(t):e.title.toLowerCase().includes(t)||e.firstMessages.some(e=>e.toLowerCase().includes(t))||e.lastMessages.some(e=>e.toLowerCase().includes(t))});return 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-scrim",onClick:t}),(0,n.jsxs)("div",{className:i.iG,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:g("sessions.sessionList")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate","data-tooltip":r,children:r})]}),(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:S,type:"text",placeholder:g("sessions.searchSessions"),value:N,onChange:e=>C(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),N&&(0,n.jsx)("button",{onClick:()=>{C(""),S.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:g("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-foreground-subtle hover:text-foreground hover:bg-hover 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:[j&&(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:g("sessions.loadingSessions")})]})}),k&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:k})}),!j&&!k&&0===L.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:g(N?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!j&&!k&&L.length>0&&(0,n.jsx)("div",{className:i.jL,children:L.map(e=>{let s=e.path.split("/").pop()||"",o=e.sessionId||s.replace(".jsonl",""),i=p.indexOf(o);return(0,n.jsxs)("div",{onClick:()=>{let n,s;return n=e.path.split("/").pop()||"",s=e.sessionId||n.replace(".jsonl",""),void(a?(a(s,e.title),t()):(0,d.F)(c.n.OpenProject,{cwd:r,sessionId:s}))},className:"p-3 rounded border border-border hover:border-brand hover:shadow-lv2 cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(x.S,{engine:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate","data-tooltip":e.title,children:e.title}),l&&i>=0&&(0,n.jsx)(h.l,{projectNumber:l,sessionNumber:i+1,bot:e.bot,className:"ml-auto"})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.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:[e.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`first-${t}`)),e.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-foreground-subtle text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`last-${t}`))]})]},e.path)})})]})]})]}):null}var p=r(47650),g=r(72312),b=r(64428),v=r(60938),j=r(51145),w=r(53213),k=r(45619),y=r(24602),N=r(5135),C=r(30133),S=r(48661),M=r(88780),L=r(20080);let E=(e,t,r)=>`/api/git/blob?cwd=${encodeURIComponent(e)}&rev=${encodeURIComponent(t)}&file=${encodeURIComponent(r)}`;function P({cwd:e,filePath:t,oldRev:r,newRev:s,newNode:o}){return(0,n.jsx)(L.K,{filePath:t,oldSrc:r?E(e,r,t):null,newSrc:s?E(e,s,t):null,newNode:o})}var $=r(94287),T=r(34075);let R=(0,s.memo)(function({cwd:e,filePath:t,onLocateInTree:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",title:t,children:t}),(0,n.jsx)($.m,{content:s("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,T.oR)(s("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",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"})})})}),r&&(0,n.jsx)($.m,{content:s("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),r(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",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",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})})]})});var I=r(82292),F=r(47215),B=r(56045);function D({preview:e,onClose:t,search:r,preRef:s}){return(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:e.filePath}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",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:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(B._,{search:r}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-secondary",children:(0,n.jsx)("pre",{ref:s,className:"whitespace-pre-wrap break-words font-mono text-foreground",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,F.xb)(e.content)})})]})})}var A=r(48347),H=r(62111);function W({isOpen:e,onClose:t,commit:r,cwd:a,embedded:l=!1,initialFilePath:i,onContentSearch:d,onLocateInTree:c}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(null),[L,E]=(0,s.useState)(null),[$,T]=(0,s.useState)(!1),[z,O]=(0,s.useState)(!1),[_,q]=(0,s.useState)(null),[V,U]=(0,s.useState)(null),[K,Q]=(0,s.useState)(null),G=(0,s.useCallback)(()=>Q(null),[]),J=(0,s.useCallback)(()=>q(null),[]),[Y,Z]=(0,s.useState)("compact"),[X,ee]=(0,s.useState)("unified"),et=(0,s.useRef)(null),er=(0,B.o)(et),en=(0,A.r)(),es=r?.shortHash,eo=(0,s.useCallback)(e=>{es&&en?.sendMessage(m("explain.commitFileMessage",{hash:es,path:e}))},[en,m,es]);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&_){e.preventDefault(),er.open();return}if("Escape"===e.key){if(er.isVisible)return void er.close();if(V)return void U(null);if(K)return void Q(null);if(_)return void q(null);(0,H.k)(),t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,V,K,_,er]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{h([]),p([]),j(null),E(null),T(!0)}),u.t4.runPromiseExit((0,w.Zi)(a,r.hash)).then(e=>{if("Success"===e._tag){let t=e.value.files??[];h(t);let n=(0,M.Do)(t);if(p(n),b(new Set((0,M.Sz)(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{j(e),u.t4.runPromiseExit((0,w.Zi)(a,r.hash,e.path)).then(e=>{"Success"===e._tag?E(e.value):console.error(e.cause)})},0)}}else console.error(e.cause);T(!1)}))},[e,r,a,i]);let ea=(0,s.useCallback)(e=>{r&&(j(e),O(!0),u.t4.runPromiseExit((0,w.Zi)(a,r.hash,e.path)).then(e=>{"Success"===e._tag?E(e.value):console.error(e.cause),O(!1)}))},[a,r]),el=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ei=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,a,l;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${a}:${l}`:`${e.getFullYear()}-${s}-${o} ${a}:${l}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]),ed=L?.filePath,ec=(0,s.useMemo)(()=>ed?(0,n.jsx)(R,{cwd:a,filePath:ed,onLocateInTree:c}):null,[a,ed,c]);if(!e||!r)return null;let eu=!!L&&(!0===L.isImage||(0,I.u)(L.filePath)),em=(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-2",children:r.subject}),r.body&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground whitespace-pre-wrap mb-3 max-h-32 overflow-y-auto border-l-2 border-border pl-3",children:r.body}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:m("commitDetail.hash")}),(0,n.jsx)("span",{className:"font-mono bg-accent px-1.5 py-0.5 rounded",children:r.hash})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:m("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:m("commitDetail.date")}),(0,n.jsx)("span",{children:ei}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:m("commitDetail.files")}),(0,n.jsx)("span",{children:m("commitDetail.nChanges",{count:x.length})})]}),!eu&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,n.jsx)(C.y,{value:Y,onChange:Z}),(0,n.jsx)(S.q,{value:X,onChange:ee})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto overflow-x-hidden",children:$?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:m("commitDetail.loadingFiles")}):(0,n.jsx)(M.VO,{files:f,selectedPath:v?.path||null,expandedPaths:g,onSelect:e=>e.file&&ea(e.file),onToggle:el,cwd:a,showChanges:!0,showChangeClass:!0,emptyMessage:m("commitDetail.noFileChanges"),className:"py-1",onExplain:en&&es?eo:void 0,explainDisabled:en?.isLoading})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:z?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:m("commitDetail.loadingDiff")}):L?eu?(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1 border-b border-border bg-accent",children:ec}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(P,{cwd:a,filePath:L.filePath,oldRev:L.oldRev??(L.isNew?null:`${r.hash}^1`),newRev:L.newRev??(L.isDeleted?null:r.hash)})})]}):"unified"===X?(0,n.jsx)(k.xU,{oldContent:L.oldContent,newContent:L.newContent,filePath:L.filePath,cwd:a,enableComments:!0,compact:"compact"===Y,headerLeading:ec,onPreview:L.isDeleted?void 0:(0,F.aR)(L.filePath)?()=>U({content:L.newContent,filePath:L.filePath}):(0,F.e$)(L.filePath)?()=>Q({content:L.newContent,filePath:L.filePath}):L.filePath.endsWith(".json")?()=>q({content:L.newContent,filePath:L.filePath}):void 0,previewLabel:L.filePath.endsWith(".json")?m("common.readable"):m("common.preview"),onContentSearch:d}):(0,n.jsx)(k.xZ,{oldContent:L.oldContent,newContent:L.newContent,filePath:L.filePath,isNew:L.isNew,isDeleted:L.isDeleted,cwd:a,enableComments:!0,compact:"compact"===Y,headerLeading:ec,onPreview:L.isDeleted?void 0:(0,F.aR)(L.filePath)?()=>U({content:L.newContent,filePath:L.filePath}):(0,F.e$)(L.filePath)?()=>Q({content:L.newContent,filePath:L.filePath}):L.filePath.endsWith(".json")?()=>q({content:L.newContent,filePath:L.filePath}):void 0,previewLabel:L.filePath.endsWith(".json")?m("common.readable"):m("common.preview"),onContentSearch:d}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:m("commitDetail.selectFileToView")})})]})]}),ex=_&&(0,n.jsx)(D,{preview:_,onClose:J,search:er,preRef:et}),eh=V&&(0,n.jsx)(y.N,{filePath:V.filePath,content:V.content,cwd:a,onClose:()=>U(null)}),ef=K&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:G,children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(N.M,{content:K.content,filePath:K.filePath,cwd:a,onClose:G})})});return l?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:m("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"})})}),em,ex,eh,ef]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card w-full h-full 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",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:m("commitDetail.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover 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"})})})]}),em,ex,eh,ef]})})}var z=r(64702),O=r(70188),_=r(14575);let q={M:{text:"text-amber-11",bg:"bg-amber-9/20"},A:{text:"text-green-11",bg:"bg-green-9/20"},D:{text:"text-red-11",bg:"bg-red-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},V=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:a,onToggle:l,onContextMenu:i,renderActions:d}){let{node:c,level:u,gitStatus:m,hasChangedChildren:x}=e,h=m?q[m]:null,f=(0,s.useCallback)(()=>{c.isDirectory?l(c.path):a(c.path)},[c.isDirectory,c.path,a,l]),p=(0,s.useCallback)(e=>{i(e,c.path,c.isDirectory)},[c.path,c.isDirectory,i]),g=!c.isDirectory&&(".env"===c.name||c.name.startsWith(".env.")),b=m?h.text:x?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!c.isDirectory?"text-brand":"text-foreground";return(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 cursor-pointer hover:bg-hover ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[c.isDirectory?o?(0,n.jsxs)("svg",{className:"w-4 h-4 flex-shrink-0 text-muted-foreground animate-spin",viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):(0,n.jsx)("svg",{className:`w-4 h-4 flex-shrink-0 text-muted-foreground transition-transform ${r?"rotate-90":""}`,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M6 4 L10 8 L6 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)(_.o,{name:c.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":c.isSymlink&&c.symlinkTarget?`${c.path} → ${c.symlinkTarget}`:c.path,children:c.name}),c.isSymlink&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:"→"}),m&&(0,n.jsx)("span",{className:`text-xs font-mono px-1 rounded ${h.text} ${h.bg} flex-shrink-0`,children:m}),c.isDirectory&&x&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),d?.(c)]})});function U({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:a=null,loadingDirs:l,onSelect:i,onToggle:d,cwd:c,shouldScrollToSelected:u=!1,onScrolledToSelected:m,className:x,renderActions:h,onCreateFile:f,onDelete:p,onRefresh:g,onCopyFile:b,onPaste:v,onExplain:j,explainDisabled:w}){let k=(0,s.useRef)(null),{contextMenu:y,showContextMenu:N,hideContextMenu:C}=(0,O.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let a=[];for(let l of t){if(null!==n&&!n.has(l.path))continue;let t=s?.get(l.path),i=l.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(l.path,s):void 0;a.push({node:l,level:o,gitStatus:t,hasChangedChildren:i}),l.isDirectory&&l.children&&r.has(l.path)&&a.push(...e(l.children,r,n,s,o+1))}return a})(e,r,o,a),[e,r,o,a]),M=(0,z.Te)({count:S.length,getScrollElement:()=>k.current,estimateSize:()=>26,overscan:10}),L=(0,s.useRef)(m);return(L.current=m,(0,s.useEffect)(()=>{if(u&&t&&S.length>0){let e=S.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{M.scrollToIndex(e,{align:"center"}),L.current?.()},150);return()=>clearTimeout(t)}}},[u,t,S,M]),0===S.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:k,className:x||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${M.getTotalSize()}px`,width:"100%",position:"relative"},children:M.getVirtualItems().map(e=>{let s=S[e.index];return(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},children:(0,n.jsx)(V,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:l?.has(s.node.path),onSelect:i,onToggle:d,onContextMenu:N,renderActions:h})},s.node.path)})}),y&&(0,n.jsx)(O.ft,{x:y.x,y:y.y,path:y.path,cwd:c,isDirectory:y.isDirectory,onClose:C,onCreateFile:f,onDelete:p,onRefresh:g,onCopyFile:b,onPaste:v,onExplain:j,explainDisabled:w})]})}var K=r(38408),Q=r(32041),G=r(14341),J=r(42804),Y=r(22164),Z=r(34582),X=r(86304),ee=r(43595),et=r(88403),er=r(85269),en=r(79968);function es({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),a=o>=0?e.slice(0,o+1):"",l=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],a="",l=!1;for(let s=0;s<e.length;s++){let i=t+s,d=r.has(i);d!==l&&a&&(o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-${s}`):(0,n.jsx)("span",{children:a},`${t}-${s}`)),a=""),l=d,a+=e[s]}return a&&o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-end`):(0,n.jsx)("span",{children:a},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[a&&i(a,0,"text-muted-foreground"),i(l,a.length,"text-foreground")]})}function eo({files:e,fileIndex:t,recentFiles:r,onSelectFile:a,onClose:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(""),[u,m]=(0,s.useState)(0),x=(0,s.useRef)(null),h=(0,s.useRef)(null),f=(0,s.useMemo)(()=>{let r,n;return t??(r=[],(n=e=>{for(let t of e)t.isDirectory&&t.children?n(t.children):t.isDirectory||r.push(t.path)})(e),r)},[t,e]),p=(0,s.useMemo)(()=>{if(!d.trim()){let e=new Set(r);return[...r.map(e=>({path:e,score:0,matchedIndices:[]})),...f.filter(t=>!e.has(t)).slice(0,50).map(e=>({path:e,score:0,matchedIndices:[]}))]}let e=[];for(let t of f){let n=function(e,t){let r=e.toLowerCase(),n=t.toLowerCase(),s=[],o=0,a=0,l=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),l===i-1&&(a+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(a+=10),i>e.lastIndexOf("/")&&(a+=3),e[i]===t[o]&&(a+=1),l=i,o++);return o<n.length?null:(a-=.1*e.length,{path:e,score:a,matchedIndices:s})}(t,d.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[d,f,r]),g=(0,s.useCallback)(e=>{c(e),m(0)},[]);(0,s.useEffect)(()=>{x.current?.focus()},[]),(0,s.useEffect)(()=>{if(h.current){let e=h.current.children[u];e?.scrollIntoView({block:"nearest"})}},[u]);let v=(0,s.useCallback)(e=>{a(e),l()},[a,l]),j=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing)switch(e.key){case"ArrowDown":e.preventDefault(),m(e=>Math.min(e+1,p.length-1));break;case"ArrowUp":e.preventDefault(),m(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),p[u]&&v(p[u].path);break;case"Escape":e.preventDefault(),l()}},[p,u,v,l]);return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:l,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-lv3 overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref:x,value:d,onChange:e=>g(e.target.value),onKeyDown:j,placeholder:i("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none",autoComplete:"off",autoCorrect:"off",spellCheck:"false"}),(0,n.jsx)("kbd",{className:"text-[10px] text-muted-foreground px-1.5 py-0.5 rounded border border-border bg-secondary",children:"ESC"})]}),(0,n.jsx)("div",{ref:h,className:"flex-1 overflow-y-auto py-1",children:0===p.length?(0,n.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:i("quickFileOpen.noMatch")}):p.map((e,t)=>(0,n.jsxs)("div",{className:`px-3 py-1.5 flex items-center gap-2 cursor-pointer transition-colors ${t===u?"bg-brand/15 text-foreground":"hover:bg-hover text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(_.o,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(es,{path:e.path,matchedIndices:e.matchedIndices}),!d.trim()&&r.includes(e.path)&&(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground px-1.5 py-0.5 rounded bg-secondary flex-shrink-0",children:i("quickFileOpen.recent")})]},e.path))}),(0,n.jsxs)("div",{className:"px-3 py-1.5 border-t border-border flex items-center gap-3 text-[10px] text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"↑↓"})," ",i("quickFileOpen.selectHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Enter"})," ",i("quickFileOpen.openHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Esc"})," ",i("quickFileOpen.closeHint")]})]})]})})})}var ea=r(2111),el=r(41474),ei=r(61878),ed=r(33210),ec=r(48368),eu=r(91958),em=r(45916),ex=r(31794),eh=r(69048),ef=r(97567),ep=r(68806),eg=r(52475);function eb({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(ec.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(em.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(ex.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(eh.A,{className:s});case"class":return(0,n.jsx)(ef.A,{className:s});case"interface":return(0,n.jsx)(ep.A,{className:s});default:return(0,n.jsx)(eg.A,{className:s})}}var ev=r(49433),ej=r(82680);let ew=new Map,ek=new Map;async function ey(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){ew.clear(),ek.clear();return}let t=`${e}::`;for(let e of ew.keys())e.startsWith(t)&&ew.delete(e);for(let e of ek.keys())e.startsWith(t)&&ek.delete(e)}(e);else{let e=ew.get(n);if(e)return e;let t=ek.get(n);if(t)return t}let s=ev.$mh({try:async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);let a=await o.json();return ew.set(n,a),a},catch:e=>new ej.uV({message:"fetchFileFunctions failed",cause:e})}),o=u.t4.runPromiseExit(s).then(e=>{if("Success"===e._tag)return e.value;let t="Fail"===e.cause._tag?e.cause.error:null,r=t?.cause;if(r instanceof Error)throw r;throw Error(t?.message??"fetchFileFunctions failed")}).finally(()=>ek.delete(n));return ek.set(n,o),o}function eN(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let a=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),ey(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?a(e,t,!1):n({state:"idle"})},[e,t,a]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&a(e,t,!0)},[e,t,a])}}function eC({cwd:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(null);(0,s.useEffect)(()=>{a(null)},[e]);let l=(0,s.useCallback)(t=>{t?.type==="graphProgress"&&t.data&&t.data.cwd===e&&a(t.data)},[e]);(0,ea.h)({url:`/ws/watch?cwd=${encodeURIComponent(e)}`,onMessage:l});let i=(0,s.useRef)("");if(r?.currentFile&&(i.current=r.currentFile),!r)return(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:t("blockViewer.fileMode.loading","Loading…")});let d=t(`blockViewer.buildProgress.${r.phase}`,eS[r.phase]),c=Math.max(0,Math.min(100,Math.round(r.percent)));return(0,n.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 px-8",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline justify-between text-xs text-muted-foreground",children:[(0,n.jsx)("span",{children:d}),(0,n.jsx)("span",{className:"tabular-nums",children:"parsing"===r.phase&&r.filesTotal>0?`${r.filesDone} / ${r.filesTotal}`:`${c}%`})]}),(0,n.jsx)("div",{className:"h-1 w-full overflow-hidden rounded-full bg-muted",children:(0,n.jsx)("div",{className:"h-full rounded-full bg-primary transition-[width] duration-150 ease-linear",style:{width:`${c}%`}})}),(0,n.jsx)("div",{className:"h-4 truncate text-left font-mono text-[11px] leading-4 text-muted-foreground/70",dir:"rtl",title:"done"===r.phase?"":i.current,children:"done"===r.phase?"":i.current})]})})}let eS={listing:"Listing files…",contexts:"Reading project config…",parsing:"Parsing files",resolving:"Resolving imports…",edges:"Building call graph…",done:"Finishing up…"};var eM=r(1058),eL=r(90717),eE=r(3238),eP=r(17196);function e$({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-card flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsx)("div",{className:"flex items-center text-xs text-muted-foreground font-mono min-w-0",children:(0,n.jsx)("span",{className:"truncate",children:0===e.length?s("blockViewer.history.title"):`${s("blockViewer.history.title")} \xb7 ${e.length}/15`})}),e.length>0&&(0,n.jsx)($.m,{content:s("blockViewer.history.clear"),children:(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",children:(0,n.jsx)(ed.A,{className:"w-3 h-3"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:s("blockViewer.history.empty")}):e.map((e,r)=>{var s;let o;return(0,n.jsx)($.m,{content:`${e.qname} \xb7 ${e.filePath}`,children:(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(eb,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]})},`${e.filePath}::${e.qname}::${r}`)})})]})}function eT(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}let eR=new Set(["function","class","method"]);function eI(e){return eR.has(e.kind)}function eF({functions:e,counts:t,totalLines:r,currentQname:a,onSelect:l,notIndexed:i,onRebuild:d}){let{t:c}=(0,o.Bd)(),u=(0,s.useMemo)(()=>e.filter(eI),[e]);return(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-card flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground font-mono truncate",children:[c("blockViewer.toc.title"),u.length>0&&` \xb7 ${u.length}`,null!=r&&` \xb7 ${r} ${c("common.lines")}`]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===u.length?i?(0,n.jsxs)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/80 leading-relaxed flex flex-col gap-2",children:[(0,n.jsx)("span",{className:"italic",children:c("blockViewer.toc.notIndexed")}),d&&(0,n.jsx)("button",{type:"button",onClick:d,className:"self-start px-2 py-1 rounded border border-border bg-secondary/60 hover:bg-secondary text-[10px] text-foreground transition-colors",children:c("blockViewer.refresh")})]}):(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:c("blockViewer.toc.empty")}):u.map(e=>{let r=a===e.qualifiedName,s=t?.get(e.qualifiedName),o=s?[s.in>0&&["in",s.in,"text-amber-11/80"],s.out>0&&["out",s.out,"text-green-11/80"],s.self>0&&["self",s.self,"text-muted-foreground/60"]].filter(Boolean):[];return(0,n.jsx)($.m,{content:`${e.qualifiedName} \xb7 L${e.startLine}`,children:(0,n.jsxs)("button",{onClick:()=>l(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-start gap-1.5 min-w-0 ${r?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(eb,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0 mt-0.5"}),(0,n.jsxs)("span",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:`flex-1 min-w-0 text-xs font-mono truncate ${r?"font-semibold text-brand":""}`,children:e.name}),(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground/50 tabular-nums",children:e.endLine-e.startLine+1})]}),o.length>0&&(0,n.jsx)("span",{className:"block text-[10px] font-mono truncate",children:o.map(([e,t,r],s)=>(0,n.jsxs)("span",{className:r,children:[s>0&&(0,n.jsx)("span",{className:"text-muted-foreground/30",children:" \xb7 "}),e," ",t]},e))})]})]})},e.qualifiedName)})})]})}var eB=r(27570),eD=r(96035);function eA({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,rowOf:a,onCommentClick:l}){let i=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=i.get(n.endLine);e?e.push(n):i.set(n.endLine,[n])}return 0===i.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(i.entries()).map(([e,r])=>{let i=a?a(e):e-t,d=r[0],c=r.length-1;return(0,n.jsx)($.m,{content:1===r.length?d.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>l(d,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-lv1 transition-colors",style:{top:`${o+i*s+s/2-8}px`},children:[(0,n.jsx)(eD.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]})},e)})})}function eH(e,t){for(let r=0;r<e.blocks.length;r++){let n=e.blocks[r];if(t>=n.startLine&&t<=n.endLine)return e.prefix[r]+(t-n.startLine)}return null}function eW({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let a,l=(0,s.useRef)(null),i=(0,s.useMemo)(()=>(function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[0];for(let e of t){let t=Math.max(0,e.endLine-e.startLine+1);r.push(r[r.length-1]+t)}return{blocks:t,prefix:r,total:r[r.length-1]}})(t),[t]),d=(0,s.useMemo)(()=>{if(i.total<=0||0===e.size)return[];let t=[];for(let r of e){let e=i.blocks.find(e=>r>=e.startLine&&r<=e.endLine);e&&t.push({line:r,qname:e.qname})}t.sort((e,t)=>e.line-t.line);let r=[],n=null;for(let e of t)n&&e.line===n.end+1&&e.qname===n.qname?n.end=e.line:(n&&r.push(n),n={start:e.line,end:e.line,qname:e.qname});return n&&r.push(n),r},[e,i]);if(i.total<=0)return null;let c=(e,t)=>{let r=eH(i,e),n=eH(i,t);return null===r||null===n?null:{top:r/i.total*100,heightPct:(n-r+1)/i.total*100}};return(0,n.jsxs)("div",{ref:l,onClick:e=>{let t=l.current;if(!t)return;let r=t.getBoundingClientRect();if(r.height<=0)return;let n=function(e,t){if(e.total<=0)return null;let r=Math.max(0,Math.min(e.total-1,t));for(let t=0;t<e.blocks.length;t++){let n=e.prefix[t],s=e.prefix[t+1];if(r>=n&&r<s){let s=e.blocks[t];return{qname:s.qname,line:s.startLine+Math.round(r-n)}}}return null}(i,(e.clientY-r.top)/r.height*i.total);if(!n)return;let s=n.line,a=d.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(a)return void o(a.qname,s);if(d.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=eH(i,s);if(null!==t){let r=null,n=1/0;for(let e of d){let s=eH(i,e.start),o=eH(i,e.end);if(null===s||null===o)continue;let a=t<s?s-t:t>o?t-o:0;a<n&&(r=e,n=a)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let c=i.blocks.find(e=>e.qname===n.qname);c&&o(c.qname,c.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[d.map(e=>{let t=c(e.start,e.end);return t?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${t.top}%`,height:`${t.heightPct}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`):null}),r&&r.end>=r.start&&((a=c(r.start,r.end))?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${a.top}%`,height:`${Math.max(1.2,a.heightPct)}%`}}):null)]})}var ez=r(19502),eO=r(89109),e_=r(7320),eq=r(37614);function eV(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eU(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}let eK="flex-shrink-0 h-4 leading-4 px-1.5 rounded text-[10px] text-brand hover:bg-brand/10 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent";function eQ({symbol:e,fileSource:t,hasChange:r,onHighlighted:a,comments:l,onCommentClick:i,addedLines:d,upstream:c,downstream:u,fold:m,onExpandGap:x}){let{resolvedTheme:h}=(0,eE.DP)(),{t:f}=(0,o.Bd)(),p=(0,A.r)(),g=(c?.length??0)+(u?.length??0)>0,b=(0,s.useMemo)(()=>(0,eP.sQ)(e.filePath),[e.filePath]),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!t)return void j(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,eP.kS)()).codeToTokens(n,{lang:b,theme:"dark"===h?"github-dark":"github-light"});r||(j(s.tokens.map(e=>(0,eP.b8)(e))),k(null))}catch(e){r||k(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,b,h]);let y=(0,s.useMemo)(()=>{if(!v)return null;let t=t=>{let r=v[t-e.startLine]??"",n=d?.has(t)?" bg-green-9/15":"";return`<div class="flex${n}" style="min-width:max-content" data-line="${t}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${t}</span><span class="whitespace-pre">${r}</span></div>`};return m?m.segments.map(e=>{if("gap"===e.kind){var r;let t,n,s;return r=e.startLine,n=eU(f("diffViewer.gap.hidden",{count:t=e.endLine-r+1})),s=eU(f("diffViewer.gap.expandAll",{count:t})),`<div class="flex items-center cursor-pointer select-none hover:bg-hover" style="min-width:max-content;height:${eY}px" data-fold-gap="${r}" title="${s}"><span class="select-none pr-3 text-muted-foreground/40" style="min-width:3.2rem;text-align:right">⋯</span><span class="text-[10px] text-muted-foreground/60 whitespace-pre">${n}</span></div>`}let n="";for(let r=e.startLine;r<=e.endLine;r++)n+=t(r);return n}).join(""):v.map((r,n)=>t(e.startLine+n)).join("")},[v,m,d,e.startLine,f]);(0,s.useEffect)(()=>{(null!==v||null!==w)&&a(e.qualifiedName)},[v,w,e.qualifiedName,a]);let N=(0,s.useCallback)(t=>{if(!x)return;let r=t.target,n=r?.closest?.("[data-fold-gap]");if(!n)return;let s=Number(n.getAttribute("data-fold-gap"));Number.isFinite(s)&&x(e.qualifiedName,s)},[x,e.qualifiedName]);return(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border text-xs",children:[(0,n.jsx)(eb,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),!e.qualifiedName.startsWith("__code_")&&(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:["unknown"!==e.kind&&`${e.kind} \xb7 `,e.endLine-e.startLine+1," ",f("common.lines")]}),p&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>p.sendMessage(f("explain.symbolMessage",{name:e.name,path:e.filePath,lines:`${e.startLine}-${e.endLine}`})),disabled:p.isLoading,title:p.isLoading?f("comments.aiResponding"):void 0,className:eK,children:f("explain.action")}),g&&(0,n.jsx)("button",{onClick:()=>p.sendMessage(f("deps.symbolMessage",{name:e.name,path:e.filePath,lines:`${e.startLine}-${e.endLine}`,...function(e,t,r){let n=e=>{switch(e.kind){case"cross":case"self":return`${e.external.name} (${e.external.filePath})`;case"method":return`${e.receiverName}.${e.methodName}()`;case"ext":return null}},s=e=>{let t=e.map(n).filter(e=>null!==e);return t.length?t.join(", "):r},o=new Map;for(let e of t){if("ext"!==e.kind)continue;let t=o.get(e.packageSpec);t?t.push(e.name):o.set(e.packageSpec,[e.name])}let a=[...o].map(([e,t])=>`${e} (${t.join(", ")})`);return{callers:s(e),callees:s(t),externals:a.length?a.join("; "):r}}(c??[],u??[],f("deps.none"))})),disabled:p.isLoading,title:p.isLoading?f("comments.aiResponding"):void 0,className:eK,children:f("deps.action")})]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${eY}px`},onClick:N,children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),w&&(0,n.jsx)("span",{className:"text-red-11",children:w}),y&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:y}})]}),l&&l.length>0&&i&&(0,n.jsx)(eA,{comments:l,startLine:e.startLine,endLine:e.endLine,lineHeight:eY,bodyTopOffset:eZ+eX,rowOf:m?.rowOf,onCommentClick:i})]})}function eG({side:e,pin:t,accent:r,onClick:s}){let o,a,l,i,d,c,u,m=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="ext",l="text-muted-foreground/60",i=t.name,d=t.packageSpec,c="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="method",l="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,d=null,c="method (unresolved)",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",a="self",l="text-muted-foreground/70",i=t.external.name,d=null,c="same-file",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",a=e,l="in"===e?"text-amber-11":"text-green-11",i=t.external.name,d=eV(t.external.filePath),c="in"===e?"caller":"callee",u=t.external.filePath);let x=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${x} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors block`,"data-tooltip":`${c} \xb7 ${i}${u?" \xb7 "+u:""}`,children:(0,n.jsxs)("span",{className:"block h-[26px] leading-[13px] overflow-hidden",children:[(0,n.jsx)("span",{className:`${l} float-left mr-1.5 text-[9px] uppercase tracking-wider font-semibold`,children:a}),(d||m>1)&&(0,n.jsxs)("span",{className:"float-right clear-both ml-1.5 max-w-[60%] truncate text-muted-foreground/70",children:[d,m>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60",children:[d?" ":"","\xb7",m,"\xd7"]})]}),(0,n.jsx)("span",{className:"font-medium break-all",children:i})]})})}let eJ="w-44 @min-[900px]:w-52 @min-[1100px]:w-60 @min-[1400px]:w-72 @min-[1800px]:w-80 @min-[2400px]:w-96",eY=18,eZ=29,eX=8;function e0(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function e1(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function e2(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function e5({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:a,onHighlighted:l,comments:i,onCommentClick:d,accentQnames:c,addedLines:u,fold:m,onExpandGap:x}){let h=function(e,t,r){if(0===e.length)return[];let n=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});n.sort((e,t)=>e.line-t.line||e.i-t.i);let s=Array(e.length).fill(0),o=-1/0;for(let{i:e,line:a}of n){let n=Math.max(eZ+eX+(r?r.rowOf(a):a-t.startLine)*eY,o);s[e]=n,o=n+34}return s}(o,e,m);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:`${eJ} flex-shrink-0 flex flex-col gap-1 pt-1`,children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(eG,{side:"in",pin:t,accent:e1(t,c),onClick:()=>a(t,e)},e0("in",t)))}),(0,n.jsx)(eQ,{symbol:e,fileSource:t,hasChange:r,onHighlighted:l,comments:i,onCommentClick:d,addedLines:u,upstream:s,downstream:o,fold:m,onExpandGap:x}),(0,n.jsx)("div",{className:`${eJ} flex-shrink-0 relative`,children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${h[r]}px`},children:(0,n.jsx)(eG,{side:"out",pin:t,accent:e1(t,c),onClick:()=>a(t,e)})},e0("out",t)))})]})}function e4({cwd:e,onSelect:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(""),[d,c]=(0,s.useState)({files:[],symbols:[]}),[m,x]=(0,s.useState)(0),[h,f]=(0,s.useState)(!1),p=(0,s.useMemo)(()=>[...d.files,...d.symbols],[d]);(0,s.useEffect)(()=>{let t=l.trim();if(!t)return void c({files:[],symbols:[]});f(!0);let r=setTimeout(async()=>{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await u.t4.runPromiseExit((0,w.MB)(r));"Success"===n._tag&&(c(n.value),x(0)),f(!1)},120);return()=>clearTimeout(r)},[l,e]);let g=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==p.length){if("ArrowDown"===e.key)e.preventDefault(),x(e=>Math.min(e+1,p.length-1));else if("ArrowUp"===e.key)e.preventDefault(),x(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=p[m];r&&t(r)}}},[p,m,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-lv3 overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(ei.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),onKeyDown:g,placeholder:a("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),h&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(ed.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===p.length&&l&&!h&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("blockViewer.search.noResults","No matches")}),(0,n.jsx)(e3,{label:a("blockViewer.search.files","Files"),hits:d.files,startIdx:0,activeIdx:m,onSelect:t,setActive:x}),(0,n.jsx)(e3,{label:a("blockViewer.search.symbols","Symbols"),hits:d.symbols,startIdx:d.files.length,activeIdx:m,onSelect:t,setActive:x})]})]})})}function e3({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:a}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let l=r+t,i=l===s;return(0,n.jsxs)("button",{onMouseEnter:()=>a(l),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.type?(0,n.jsx)(ec.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(eb,{kind:e.target.kind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function e6({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:a,enableComments:l=!1,onContentSearch:i,onFocalChange:d,qnameFilter:c,qnameFilterFile:m,accentQnames:x,accentFile:h,addedLines:f,addedLinesFile:p,compact:g=!1,headerExtraLeft:b,headerExtraRight:j}){let{t:w}=(0,o.Bd)(),[k,y]=(0,s.useState)("toc"),[N,C]=(0,s.useState)(null),S=N??t??null;(0,s.useEffect)(()=>{C(null)},[t]),(0,s.useEffect)(()=>{d?.(S)},[S,d]);let{state:M,refresh:L}=eN(e,S),[E,P]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!S)return void P(null);let t=!1;return P(null),(async()=>{let r=new URLSearchParams({cwd:e,path:S}),n=await u.t4.runPromiseExit((0,v.eA)(r));t||("Success"===n._tag?P({content:n.value.content,mtimeMs:n.value.mtimeMs}):console.error("[BlockViewer] failed to load file source for",S,n.cause))})(),()=>{t=!0}},[e,S]);let $=(0,s.useMemo)(()=>E?E.content.split("\n").length:null,[E]),T=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!E||"ready"!==M.state)return;let e=M.data.mtimeMs;!e||E.mtimeMs<=e||T.current!==E.mtimeMs&&(T.current=E.mtimeMs,L())},[E,M,L]);let[R,I]=(0,s.useState)([]),[F,B]=(0,s.useState)(!1),[D,H]=(0,s.useState)(null),W=(0,s.useRef)(0),z=(0,s.useRef)(0),[O,_]=(0,s.useState)(()=>new Set),q="ready"===M.state?M.data.filePath:null;(0,s.useEffect)(()=>{_(new Set)},[q]);let V=(0,s.useCallback)(e=>{_(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),B(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let U=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;W.current+=1,H({filePath:e,qname:"__imports__",nonce:W.current});return}let r=e2(t),n=e2(e.external);I(e=>eT(eT(e,r),n)),C(n.filePath),W.current+=1,H({filePath:n.filePath,qname:n.qname,nonce:W.current})},[]),K=(0,s.useCallback)(e=>{C(e.filePath),W.current+=1,H({filePath:e.filePath,qname:e.qname,nonce:W.current})},[]),Q=(0,s.useCallback)(e=>{B(!1),C(e.target.filePath),"symbol"===e.type&&(W.current+=1,H({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.startLine,nonce:W.current}))},[]),G=(0,s.useCallback)((e,t)=>{S&&(W.current+=1,H({filePath:S,qname:e,line:t,nonce:W.current}))},[S]),[J,Y]=(0,s.useState)(()=>new Set),Z=(0,s.useCallback)((e,t)=>{Y(r=>{let n=new Set(r);return n.add(`${S}#${e}#${t}`),n})},[S]),[X,ee]=(0,s.useState)(null),[et,er]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!X)return;let e=null,t=()=>{e=null;let t=X.getBoundingClientRect();if(t.height<=0)return;let r=X.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let a=Number(r),l=Number(o);if(!Number.isFinite(a)||!Number.isFinite(l))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let d=Math.max(0,t.top-i.top),c=Math.min(i.height,t.bottom-i.top),u=l-a+1,m=Math.floor(d/i.height*u),x=Math.ceil(c/i.height*u)-1,h=a+Math.max(0,m),f=a+Math.min(u-1,Math.max(0,x));h<n&&(n=h),f>s&&(s=f)}),n===1/0||s===-1/0?er(null):er(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),X.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(X);let s=new MutationObserver(r);return s.observe(X,{childList:!0,subtree:!0}),()=>{X.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[X]);let en=(0,s.useMemo)(()=>{if("ready"!==M.state||!et)return null;let e=M.data.functions;if(0===e.length)return null;let t=(et.start+et.end)/2;for(let r of e)if(r.startLine<=t&&t<=r.endLine)return r.qualifiedName;let r=null;for(let t of e)t.startLine<=et.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[M,et]),es=l&&!!e&&!!S,eo=(0,A.r)(),{comments:ea,addComment:el,updateComment:ei,deleteComment:ed,refresh:ec}=(0,eM._)({cwd:e,filePath:S??""}),[eu,em]=(0,s.useState)(null),{toolbarRef:ex,bumpRef:eh,clearToolbar:ef}=(0,eB.L)({enabled:es,container:eu,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,r=t?.closest("[data-line]");if(!r||!eu||!eu.contains(r))return null;let n=r.getAttribute("data-line");if(!n)return null;let s=parseInt(n,10);return Number.isFinite(s)?{start:s,end:s}:null},buildLineSnapshot:({start:e,end:t})=>{let r=E?.content;return r?r.split("\n").slice(e-1,t).join("\n"):""}}),[ep,eg]=(0,s.useState)(null),[eb,ev]=(0,s.useState)(null),[ej,ew]=(0,s.useState)(null),ek=(0,s.useCallback)(()=>{let e=ex.current;e&&(eg({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),ef())},[ef,ex]),ey=(0,s.useCallback)(()=>{let e=ex.current;e&&(ev({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),ef())},[ef,ex]),eS=(0,s.useCallback)(()=>{let e=ex.current;e&&eo&&S&&(ef(),(0,eL.Ff)(eo.sendMessage,{filePath:S,startLine:e.range.start,endLine:e.range.end,codeContent:e.lineSnapshot},w("explain.selectionMessage")))},[eo,S,ef,ex,w]),eE=(0,s.useCallback)(()=>{let e=ex.current;if(!e||!i)return;let t=e.selectedText.trim();ef(),t&&i(t)},[i,ef,ex]),eP=(0,s.useCallback)(async e=>{ep&&(await el(ep.range.start,ep.range.end,e,ep.selectedText),eg(null))},[ep,el]),eR=(0,s.useCallback)(async(t,r)=>{if(eo&&e&&S)try{let n=(await (0,eL.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));n.push({filePath:S,startLine:t.range.start,endLine:t.range.end,codeContent:t.lineSnapshot});let s=(0,eL.Gw)(n,r);eo.sendMessage(s),await (0,eL.RP)(e),ec()}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[eo,e,S,ec]),eI=(0,s.useCallback)(e=>{eb&&eR(eb,e)},[eb,eR]),eD=(0,s.useCallback)(e=>{ep&&eR(ep,e)},[ep,eR]),eA=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ew({comment:e,x:t.clientX,y:t.clientY}),ef(),eg(null),ev(null)},[ef]);if((0,s.useEffect)(()=>{if(!D||z.current>=D.nonce||"ready"!==M.state||!E||M.data.filePath!==D.filePath)return;let e=Math.max(1,new Set((m===M.data.filePath&&c?M.data.functions.filter(e=>c.has(e.qualifiedName)):M.data.functions).map(e=>e.qualifiedName)).size);if(O.size<e)return;z.current=D.nonce;let t=null,r=requestAnimationFrame(()=>{let e=D.qname.indexOf(">"),r=e>=0?D.qname.slice(0,e):D.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof D.line){let e=n.querySelector(`[data-line="${D.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"instant",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"instant",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[D,M,E,O,c,m]),!S)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e9,{focalFile:null,fileCount:null,onSwitchToCode:a,onSearch:()=>B(!0),onRefresh:L,refreshDisabled:!0,extraLeft:b,extraRight:j}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:w("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:w("blockViewer.empty.hint","or press ⌘K to search.")})]}),F&&(0,n.jsx)(e4,{cwd:e,onSelect:Q,onClose:()=>B(!1)})]});if("idle"===M.state||"loading"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e9,{focalFile:S,fileCount:null,onSwitchToCode:a,onSearch:()=>B(!0),onRefresh:L,refreshDisabled:!0,extraLeft:b,extraRight:j}),(0,n.jsx)(eC,{cwd:e})]});if("notFound"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e9,{focalFile:S,fileCount:null,onSwitchToCode:a,onSearch:()=>B(!0),onRefresh:L,extraLeft:b,extraRight:j}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:w("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),F&&(0,n.jsx)(e4,{cwd:e,onSelect:Q,onClose:()=>B(!1)})]});if("error"===M.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e9,{focalFile:S,fileCount:null,onSwitchToCode:a,onSearch:()=>B(!0),onRefresh:L,extraLeft:b,extraRight:j}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:M.message}),(0,n.jsx)("button",{onClick:L,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:w("blockViewer.retry","Retry")})]})]});let eH=M.data,eU=eH.functions;if(0===eU.length&&E){let e=Math.max(1,$??1);eU=[{filePath:eH.filePath,qualifiedName:"__file__",name:eV(eH.filePath),kind:"unknown",startLine:1,endLine:e}]}let eK=m&&m===eH.filePath,eQ=h&&h===eH.filePath,eG=p&&p===eH.filePath;eK&&c&&(eU=eU.filter(e=>c.has(e.qualifiedName)));let eY=eQ?x:void 0,eZ=eG?f:void 0,eX=new Map;if(g&&eZ)for(let e of eU)eX.set(e.qualifiedName,function(e,t,r,n,s=ez.aj){if(t<e)return null;let o=[];for(let n of r)n>=e&&n<=t&&o.push(n);o.sort((e,t)=>e-t);let a=[];for(let r of o){let n=Math.max(e,r-s),o=Math.min(t,r+s),l=a[a.length-1];l&&n<=l.endLine+1?o>l.endLine&&(l.endLine=o):a.push({startLine:n,endLine:o})}let l=[],i=e;for(let e of a)e.startLine>i&&l.push({startLine:i,endLine:e.startLine-1}),i=e.endLine+1;i<=t&&l.push({startLine:i,endLine:t});let d=[],c=[];for(let e of l)e.endLine-e.startLine+1<2||n(e.startLine)?c.push(e):d.push(e);if(0===d.length)return null;a=function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[];for(let e of t){let t=r[r.length-1];t&&e.startLine<=t.endLine+1?e.endLine>t.endLine&&(t.endLine=e.endLine):r.push({...e})}return r}([...a,...c]);let u=[];for(let e of[...a.map(e=>({kind:"lines",...e})),...d.map(e=>({kind:"gap",...e}))].sort((e,t)=>e.startLine-t.startLine))u.push(e);let m=[],x=0;for(let e of u)m.push(x),x+="gap"===e.kind?1:e.endLine-e.startLine+1;let h=x;return{segments:u,visibleRuns:a,hiddenCount:d.reduce((e,t)=>e+(t.endLine-t.startLine+1),0),rowOf:t=>{for(let e=0;e<u.length;e++){let r=u[e];if(t<r.startLine)break;if(t<=r.endLine)return"gap"===r.kind?m[e]:m[e]+(t-r.startLine)}return t<e?0:Math.max(0,h-1)}}}(e.startLine,e.endLine,eZ,t=>J.has(`${eH.filePath}#${e.qualifiedName}#${t}`)));let e0=e8(eH.upstreamCalls),e1=e8(eH.downstreamCalls),e3=new Map(eU.map(e=>[e.qualifiedName,e])),e7=new Map,te=new Map;for(let e of eH.intraCalls){let t=e3.get(e.to),r=e3.get(e.from);if(t){let r=e7.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):e7.set(e.from,[n])}if(r){let t=te.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):te.set(e.to,[n])}}let tt=new Map;for(let e of eH.externalCalls??[]){let t=tt.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):tt.set(e.focalQname,[r])}let tr=new Map;for(let e of eH.methodCalls??[]){let t=tr.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):tr.set(e.focalQname,[r])}let tn=new Map;for(let e of eU){let t=e.qualifiedName,r={in:e0.get(t)?.length??0,out:e1.get(t)?.length??0,self:(te.get(t)?.length??0)+(e7.get(t)?.length??0)};(r.in||r.out||r.self)&&tn.set(t,r)}let ts=r.has(eH.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(e9,{focalFile:S,fileCount:eH.fileCount,functionCount:eH.functions.length,upstreamCount:eH.upstreamCalls.length,downstreamCount:eH.downstreamCalls.length,onSwitchToCode:a,onSearch:()=>B(!0),onRefresh:L,extraLeft:b,extraRight:j}),(0,n.jsxs)("div",{ref:em,className:"@container flex-1 relative min-h-0 flex",children:[(0,n.jsxs)("div",{className:`${eJ} flex-shrink-0 border-r border-border flex flex-col`,children:[(0,n.jsx)("div",{className:"flex-shrink-0 flex border-b border-border",children:[["toc",w("blockViewer.tabs.toc")],["history",w("blockViewer.tabs.history")]].map(([e,t])=>(0,n.jsx)("button",{onClick:()=>y(e),className:`flex-1 px-2 py-1.5 text-xs font-medium transition-colors ${k===e?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground"}`,children:t},e))}),(0,n.jsx)("div",{className:"toc"===k?"flex-1 min-h-0 flex flex-col":"hidden",children:(0,n.jsx)(eF,{functions:eU,counts:tn,totalLines:$,currentQname:en,onSelect:G,notIndexed:eH.notIndexed,onRebuild:L})}),(0,n.jsx)("div",{className:"history"===k?"flex-1 min-h-0 flex flex-col":"hidden",children:(0,n.jsx)(e$,{entries:R,onSelect:K,onClear:()=>I([])})})]}),(0,n.jsx)("div",{ref:ee,className:"@container flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eU.map(e=>{let t,r,s,o,a,l;return(0,n.jsx)(e5,{symbol:e,fileSource:E?.content??null,hasChange:ts,upstream:(t=e0.get(e.qualifiedName),r=te.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=e1.get(e.qualifiedName),o=e7.get(e.qualifiedName),a=tr.get(e.qualifiedName),l=tt.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...a??[],...l??[]]),onPinClick:U,onHighlighted:V,comments:es?ea:void 0,onCommentClick:es?eA:void 0,accentQnames:eY,addedLines:eZ,fold:eX.get(e.qualifiedName),onExpandGap:Z},`${e.qualifiedName}#${e.startLine}`)})})}),es&&eu&&(0,n.jsx)(eO.fS,{floatingToolbarRef:ex,bumpRef:eh,container:eu,onAddComment:ek,onSendToAI:ey,onSearch:i?eE:void 0,onExplain:eo&&S?eS:void 0,isChatLoading:eo?.isLoading}),es&&ep&&(0,n.jsx)(e_.t,{x:ep.x,y:ep.y,range:ep.range,filePath:S??void 0,lineSnapshot:ep.lineSnapshot,container:eu,onSubmit:eP,onSendToAI:eo&&S?eD:void 0,onClose:()=>eg(null),isChatLoading:eo?.isLoading}),es&&eb&&S&&(0,n.jsx)(e_.G,{x:eb.x,y:eb.y,range:eb.range,filePath:S,lineSnapshot:eb.lineSnapshot,container:eu,onSubmit:eI,onClose:()=>ev(null),isChatLoading:eo?.isLoading}),es&&ej&&(0,n.jsx)(eq.t,{x:ej.x,y:ej.y,comment:ej.comment,container:eu,onClose:()=>ew(null),onUpdateComment:ei,onDeleteComment:ed}),eZ&&eZ.size>0&&eU.length>0&&(0,n.jsx)(eW,{addedLines:eZ,blockRanges:eU.flatMap(e=>{let t=eX.get(e.qualifiedName);return t?t.visibleRuns.map(t=>({qname:e.qualifiedName,startLine:t.startLine,endLine:t.endLine})):[{qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine}]}),viewportRange:et,onJumpToLine:G}),F&&(0,n.jsx)(e4,{cwd:e,onSelect:Q,onClose:()=>B(!1)})]})]})}function e8(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function e9({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:a,onSwitchToCode:l,onSearch:i,onRefresh:d,refreshDisabled:c,extraLeft:u,extraRight:m}){let{t:x}=(0,o.Bd)(),h={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:a??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof a&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",a," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(h)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[m&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:m(h)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":x("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(ei.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:d,disabled:c,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":x("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(eu.A,{className:"w-3 h-3"})}),l&&(0,n.jsx)("button",{onClick:l,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:x("common.code","Code")})]})]})}var e7=r(22576);function te(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function tt(e){return e.replace(/\s+/g," ").trim()}function tr(e,t){return e?`${e}>${t}`:t}function tn(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function ts(e,t,r,n,s=[],o){return{qualifiedName:tr(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:te(tt(e.text)),children:s,params:o}}function to(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}let ta={theorem:"function",def:"function",abbrev:"function",example:"function",instance:"const",structure:"class",inductive:"type",axiom:"const",opaque:"const",constant:"const"};function tl(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";case"lean":return"lean";default:return null}}var ti=r(14066);let td="/tree-sitter",tc=null,tu=new Map;async function tm(e){let t,r=await (!(t=tu.get(e))&&(t=(async()=>(await (!tc&&(tc=ti.iX.init({locateFile:e=>`${td}/${e}`})),tc),ti.TM.load(`${td}/tree-sitter-${e}.wasm`)))(),tu.set(e,t)),t),n=new ti.iX;return n.setLanguage(r),n}function tx(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function th(e){return!tx(e)&&"__file__"!==e.qualifiedName}async function tf(e,t){if(!e)return[];let r=tl(t);if(!r)return null;let n=(await tm(r)).parse(e);if(!n)return null;try{return function(e,t){var r;let n,s,o=[],a=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type||"import"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,contentHash:te(tt(t.map(e=>e.text).join("\n"))),children:[]}}(e);if(a&&o.push(a),"lean"===t)o.push(...function(e){let t=[],r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s)continue;switch(s.type){case"namespace":r.push(s.childForFieldName("name")?.text??null);continue;case"section":r.push(null);continue;case"end":r.pop();continue}let o=null;if("declaration"===s.type)for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t&&t.type in ta){o=t;break}}else s.type in ta&&(o=s);if(!o)continue;let a=o.childForFieldName("name")?.text??o.type,l=r.filter(e=>null!==e);t.push({qualifiedName:[...l,a].join("."),name:a,kind:ta[o.type],startLine:s.startPosition.row+1,endLine:function(e){let t=e.endPosition.row+1,r=e.text.replace(/\s+$/,""),n=e.text.slice(r.length);if(!n)return t;let s=n.split("\n").length-1;return Math.max(e.startPosition.row+1,t-s)}(s),contentHash:te(tt(s.text)),children:[]})}return t}(e));else for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);r&&o.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[ts(t,tn(t),"function",r,[],to(t))];case"class_declaration":case"abstract_class_declaration":{let e=tn(t),n=tr(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(ts(s,tn(s),"method",t,[],to(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(ts(s,tn(s),"method",t,[],to(e)))}}}return r}(t.childForFieldName("body"),n);return[ts(t,e,"class",r,s)]}case"interface_declaration":return[ts(t,tn(t),"interface",r)];case"type_alias_declaration":return[ts(t,tn(t),"type",r)];case"enum_declaration":return[ts(t,tn(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),a=s.childForFieldName("value");if(!o)continue;let l=o.text,i=a&&("arrow_function"===a.type||"function_expression"===a.type),d=i&&a?to(a):void 0;if(r.push(ts(e,l,i?"function":"const",t,[],d)),a&&"object"===a.type&&!i){let e=t?`${t}>${l}`:l;for(let t=0;t<a.namedChildCount;t++){let n=a.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(ts(n,t.text,"method",e,[],to(s)))}else if("method_definition"===n.type){let t=tn(n);t&&r.push(ts(n,t,"method",e,[],to(n)))}}}}}return r}(t,r);case"class_definition":{let e=tn(t),n=tr(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(ts(o,tn(o),"method",r,[],to(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...ts(t,tn(t),"method",r,[],to(t)),startLine:o.startPosition.row+1,contentHash:te(tt(o.text))});else if(t?.type==="class_definition"){let s=tn(t),a=tr(r,s),l=e(t.childForFieldName("body"),a);n.push({...ts(t,s,"class",r,l),startLine:o.startPosition.row+1,contentHash:te(tt(o.text))})}}else if("class_definition"===o.type){let t=tn(o),s=tr(r,t),a=e(o.childForFieldName("body"),s);n.push(ts(o,t,"class",r,a))}}}return n}(t.childForFieldName("body"),n);return[ts(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:te(tt(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:tr(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:te(tt(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,a=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&a.push(t)}}if(0===a.length||!o)return[];let l=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=l?`${l} ${o}`:o;return a.map((e,r)=>ts(e,a.length>1?`${i} #${r+1}`:i,"function",t,[],to(e)))}(t,r)),e}default:return[]}}(r,void 0,!1))}return!function(e,t){let r=new Map;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);n&&n.type.endsWith("comment")&&r.set(n.endPosition.row+1,n)}if(0===r.size)return;let n=new Set;for(let e of t)for(let t=e.startLine;t<=e.endLine;t++)n.add(t);for(let e of t){if("unknown"===e.kind)continue;let t=e.startLine;for(;;){let e=r.get(t-1);if(!e)break;let s=e.startPosition.row+1,o=!1;for(let e=s;e<=t-1;e++)if(n.has(e)){o=!0;break}if(o)break;t=s}if(t!==e.startLine){for(let r=t;r<e.startLine;r++)n.add(r);e.startLine=t}}}(e,o),o.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],a=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,contentHash:te(tt(s)),children:[]})},l=-1;for(let e=1;e<=n;e++)s[e]?l>=0&&(a(l,e-1),l=-1):l<0&&(l=e);return l>=0&&a(l,n),o}(e,o)),r=o,n=new Map,(s=e=>{for(let t of e){let e=(n.get(t.qualifiedName)??0)+1;n.set(t.qualifiedName,e),e>1&&(t.qualifiedName=`${t.qualifiedName}#${e}`),s(t.children)}})(r),o}(n.rootNode,r)}finally{n.delete()}}async function tp(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of(0,e7.X)(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!tl(r))return{addedLines:o};let[a,l]=await Promise.all([tf(n?"":e,r),tf(s?"":t,r)]),i=l??[],d=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}((a??[]).filter(th),i.filter(th)),c=new Set;for(let e of d)"deleted"!==e.changeKind&&c.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(tx(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(i,o))c.add(e);return{changedQnames:c,addedLines:o}}function tg({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:a=!1,isDeleted:l=!1,changedFiles:i,fileGitStatusMap:d,enableComments:c=!1,compact:u=!0,onContentSearch:m,onSwitchToCode:x,headerExtraLeft:h,headerExtraRight:f}){let[p,g]=(0,s.useState)(t);(0,s.useEffect)(()=>{g(t)},[t]);let[b,v]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return v(null),(async()=>{try{let s=await tb(p,t,r,o,a,l,i,d,e);if(n||!s)return;let c=await tp(s.oldContent,s.newContent,p,s.isNew,s.isDeleted);if(n)return;v(c)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[p,t,r,o,a,l,i,d,e]),(0,n.jsx)(e6,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:c,qnameFilter:u?b?.changedQnames:void 0,qnameFilterFile:p,accentQnames:b?.changedQnames,accentFile:p,addedLines:b?.addedLines,addedLinesFile:p,compact:u,onFocalChange:e=>e&&g(e),onContentSearch:m,onSwitchToCode:x,headerExtraLeft:h,headerExtraRight:f})}async function tb(e,t,r,n,s,o,a,l,i){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!a.has(e))return null;let d=l?.get(e);if(!d)return null;let c=new URLSearchParams({cwd:i,file:e,type:d}),m=await u.t4.runPromiseExit((0,w.oh)(c));if("Success"!==m._tag)return null;let x=m.value;return{oldContent:x.oldContent,newContent:x.newContent,isNew:x.isNew??!1,isDeleted:x.isDeleted??!1}}var tv=r(50860);let tj=(e,t,r)=>`/api/git/blob?cwd=${encodeURIComponent(e)}&rev=${encodeURIComponent(t)}&file=${encodeURIComponent(r)}`;function tw({cwd:e,selected:t,diff:r,showMarkdownPreview:a,setShowMarkdownPreview:l,changedFiles:i,fileGitStatusMap:d,onContentSearch:c,locateInTree:u,setJsonPreview:m,onTokenHover:x,onTokenHoverLeave:h,onTokenHoverCancel:f}){let{t:p}=(0,o.Bd)(),g="unstaged"===t.type?{onTokenHover:x,onTokenHoverLeave:h,onTokenHoverCancel:f}:{},[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)("file"),[M,E]=(0,s.useState)("compact"),[P,R]=(0,s.useState)("unified"),B=t.file.path,D=t.file.oldPath||B,A=(0,I.u)(B),H=B.startsWith("/")?B:e?`${e.replace(/\/$/,"")}/${B}`:B,{state:W}=eN(e,B),z=(0,s.useMemo)(()=>{if("ready"===W.state)return W.data.functions.filter(eI).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[W]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[A||"map"!==j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:B}),(0,n.jsx)($.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${B}`),(0,T.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",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)($.m,{content:p("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(B)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",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",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${"staged"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?p("fileBrowser.staged"):p("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!A&&(0,n.jsx)(C.y,{value:M,onChange:E}),!A&&"file"===j&&(0,n.jsx)(S.q,{value:P,onChange:R}),!A&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),w(e)},className:`px-2 py-0.5 text-xs transition-colors ${j===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:A?(0,n.jsx)(L.K,{filePath:B,oldSrc:r.isNew?null:tj(e,"staged"===t.type?"HEAD":":0","staged"===t.type?D:B),newSrc:r.isDeleted||"staged"!==t.type?null:tj(e,":0",B),newNode:r.isDeleted||"staged"===t.type?void 0:(0,n.jsx)(tv.I,{cwd:e,path:B,className:"flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:B})}):"unified"===P?(0,n.jsx)(k.xU,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,cwd:e,enableComments:!0,compact:"compact"===M,onPreview:!r.isDeleted&&(0,F.e$)(B)?()=>l(!0):!r.isDeleted&&(0,F.aR)(B)?()=>v(!0):!r.isDeleted&&B.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:B.endsWith(".json")?p("common.readable"):p("common.preview"),onContentSearch:c,...g}):(0,n.jsx)(k.xZ,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===M,symbols:z,onPreview:!r.isDeleted&&(0,F.e$)(B)?()=>l(!0):!r.isDeleted&&(0,F.aR)(B)?()=>v(!0):!r.isDeleted&&B.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:B.endsWith(".json")?p("common.readable"):p("common.preview"),onContentSearch:c,...g})})]}):(0,n.jsx)(tg,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:d,enableComments:!0,compact:"compact"===M,onContentSearch:c,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=d.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,T.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",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:"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)($.m,{content:p("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3 h-3",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)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?p("fileBrowser.staged"):p("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(C.y,{value:M,onChange:E}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),w(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${j===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})]})}),a&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:()=>l(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(N.M,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>l(!1)})})}),b&&(0,n.jsx)(y.N,{filePath:H,content:r.newContent,cwd:e,onClose:()=>v(!1)})]})}function tk({branches:e,selectedBranch:t,onSelect:r,isLoading:a,pinnedBranches:l=[]}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(""),x=(0,s.useRef)(null),h=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{d&&h.current&&h.current.focus()},[d]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=l.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],w=e=>{r(e),c(!1),m("")};return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>c(!d),disabled:a,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground 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"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-foreground-subtle transition-transform ${d?"rotate-180":""}`,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"})})]}),d&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lv2 max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:h,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>w(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand 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"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-popover sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>w(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand 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"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-popover sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>w(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand 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"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}let ty=96/72;function tN({cwd:e,path:t,refreshKey:o}){let a=(0,s.useRef)(null),[l,i]=(0,s.useState)({kind:"loading"}),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(0),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(0),[g,b]=(0,s.useState)({kind:"auto"}),[v,j]=(0,s.useState)(1),[w,k]=(0,s.useState)(!0);(0,s.useEffect)(()=>{let n=!1;i({kind:"loading"}),c(null),m(0),h(null),j(1);let s=null;return(async()=>{try{let a=await Promise.all([r.e(52084),r.e(49304)]).then(r.bind(r,66898));a.GlobalWorkerOptions.workerSrc="/pdfjs/pdf.worker.min.mjs";let l=`/api/files/read?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}&v=${encodeURIComponent(String(o??""))}`;s=a.getDocument({url:l});let d=await s.promise;if(n)return;let u=await Promise.all(Array.from({length:d.numPages},(e,t)=>d.getPage(t+1).then(e=>{let t=e.getViewport({scale:1});return{w:t.width,h:t.height}})));if(n)return;c(d),m(d.numPages),h(u),i({kind:"ready"})}catch(e){n||i({kind:"error",message:e instanceof Error?e.message:"Failed to load PDF"})}})(),()=>{n=!0;try{s?.destroy()}catch{}}},[e,t,o]),(0,s.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>p(Math.max(0,e.clientWidth-32));t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[]);let y=(0,s.useMemo)(()=>x?.length?Math.max(...x.map(e=>e.w)):0,[x]),N=Math.min(y>0&&f>0?f/y:ty,ty),C="auto"===g.kind?N:g.factor*ty,S=Math.round(C/ty*100),M=(0,s.useMemo)(()=>x?x.map(e=>e.h*C+16):[],[x,C]),L=y*C,E=(0,s.useRef)(1);E.current=N/ty;let P=(0,s.useRef)(M);P.current=M;let $=(0,z.Te)({count:u,getScrollElement:()=>a.current,estimateSize:e=>P.current[e]??0,overscan:2});(0,s.useEffect)(()=>{M.length>0&&$.measure()},[M,$]);let T=(0,s.useCallback)(()=>{let e=a.current;if(!e||0===u)return;let t=e.scrollTop,r=$.getVirtualItems().find(e=>e.end>t);j((r?r.index:u-1)+1)},[$,u]),R=(0,s.useCallback)(e=>{b(t=>({kind:"fixed",factor:Math.min(4,Math.max(.25,("auto"===t.kind?E.current:t.factor)*e))}))},[]),I=(0,s.useCallback)(()=>R(1.2),[R]),F=(0,s.useCallback)(()=>R(.8333333333333334),[R]),B=(0,s.useCallback)(()=>b({kind:"auto"}),[]),D=(0,s.useCallback)(()=>k(e=>!e),[]),A=(0,s.useCallback)(e=>{$.scrollToIndex(e,{align:"start"}),j(e+1)},[$]),H=$.getVirtualItems(),W=$.getTotalSize(),O=(0,s.useMemo)(()=>(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border text-muted-foreground text-xs select-none",children:[(0,n.jsx)("button",{onClick:D,className:`px-1.5 py-0.5 rounded hover:bg-hover transition-colors ${w?"text-foreground":""}`,title:w?"Hide thumbnails":"Show thumbnails","aria-label":"Toggle thumbnails",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),(0,n.jsx)("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),(0,n.jsx)("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]})}),(0,n.jsx)("span",{className:"tabular-nums",children:u>0?`${v} / ${u}`:"—"}),(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:F,className:"px-1.5 py-0.5 rounded hover:bg-hover transition-colors",title:"Zoom out","aria-label":"Zoom out",children:"−"}),(0,n.jsxs)("button",{onClick:B,className:`px-1.5 py-0.5 rounded hover:bg-hover transition-colors tabular-nums min-w-[3.5rem] ${"auto"===g.kind?"":"text-foreground"}`,title:"Reset to automatic zoom",children:[S,"%"]}),(0,n.jsx)("button",{onClick:I,className:"px-1.5 py-0.5 rounded hover:bg-hover transition-colors",title:"Zoom in","aria-label":"Zoom in",children:"+"})]})]}),[u,v,S,g.kind,I,F,B,w,D]);return"error"===l.kind?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-secondary",children:[O,(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:l.message})})]}):(0,n.jsxs)("div",{className:"h-full flex flex-col bg-secondary",children:[O,(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[w&&d&&x&&(0,n.jsx)(tC,{doc:d,numPages:u,sizes:x,maxPageW:y,currentPage:v,onSelect:A}),(0,n.jsx)("div",{ref:a,onScroll:T,className:"flex-1 overflow-auto px-4 py-4",children:"loading"!==l.kind&&d&&x&&!(L<=0)?(0,n.jsx)("div",{style:{height:W,width:Math.max(L,f),position:"relative"},children:H.map(e=>(0,n.jsx)("div",{"data-index":e.index,className:"absolute left-0 top-0 w-full flex justify-center",style:{transform:`translateY(${e.start}px)`,paddingBottom:16},children:(0,n.jsx)(tS,{doc:d,pageNumber:e.index+1,scale:C,width:x[e.index].w*C,height:x[e.index].h*C})},e.key))}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})})})]})]})}function tC({doc:e,numPages:t,sizes:r,maxPageW:o,currentPage:a,onSelect:l}){let i=(0,s.useRef)(null),d=o>0?100/o:0,c=(0,s.useMemo)(()=>r.map(e=>e.h*d+18+12),[r,d]),u=(0,s.useRef)(c);u.current=c;let m=(0,z.Te)({count:t,getScrollElement:()=>i.current,estimateSize:e=>u.current[e]??0,overscan:3});(0,s.useEffect)(()=>{c.length>0&&m.measure()},[c,m]),(0,s.useEffect)(()=>{t>0&&m.scrollToIndex(a-1,{align:"auto"})},[a]);let x=m.getVirtualItems();return(0,n.jsx)("div",{ref:i,className:"shrink-0 overflow-auto border-r border-border py-2",style:{width:132},children:(0,n.jsx)("div",{style:{height:m.getTotalSize(),width:"100%",position:"relative"},children:x.map(t=>{let s=a===t.index+1;return(0,n.jsxs)("div",{className:"absolute left-0 top-0 w-full flex flex-col items-center",style:{transform:`translateY(${t.start}px)`,paddingBottom:12},children:[(0,n.jsx)("button",{onClick:()=>l(t.index),className:`rounded-sm overflow-hidden transition-shadow ${s?"ring-2 ring-brand":"ring-1 ring-border hover:ring-muted-foreground"}`,title:`Page ${t.index+1}`,"aria-label":`Go to page ${t.index+1}`,children:(0,n.jsx)(tS,{doc:e,pageNumber:t.index+1,scale:d,width:r[t.index].w*d,height:r[t.index].h*d})}),(0,n.jsx)("span",{className:`mt-0.5 text-[11px] tabular-nums leading-none ${s?"text-foreground font-medium":"text-muted-foreground"}`,style:{height:18},children:t.index+1})]},t.key)})})})}function tS({doc:e,pageNumber:t,scale:r,width:o,height:a}){let l=(0,s.useRef)(null);return(0,s.useEffect)(()=>{let n=!1,s=null;return(async()=>{let o=await e.getPage(t);if(n)return;let a=l.current;if(!a)return;let i=Math.min(window.devicePixelRatio||1,2),d=o.getViewport({scale:r*i});a.width=Math.floor(d.width),a.height=Math.floor(d.height),a.style.width=`${a.width/i}px`,a.style.height=`${a.height/i}px`,s=o.render({canvas:a,viewport:d});try{await s.promise}catch{}})(),()=>{n=!0;try{s?.cancel()}catch{}}},[e,t,r]),(0,n.jsx)("div",{className:"bg-white shadow-lv2",style:{width:o,height:a},children:(0,n.jsx)("canvas",{ref:l,className:"block"})})}var tM=r(69809);function tL(e){let t=e.split(".").pop()?.toLowerCase();return t?["ts","tsx","js","jsx","mjs","cjs"].includes(t)?"typescript":["py","pyi"].includes(t)?"python":null:null}let tE=(e,t)=>ev.$mh({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}`);return await r.json()},catch:t=>new ej.uV({message:`${e} failed`,cause:t})});function tP(e){return e.replace(/^\([^)]+\)\s*/,"")}function t$(e){let t=tP(e),r=t.match(/^(?:function|const|let|var|class|interface|type|enum|async function)\s+([a-zA-Z_$][\w$]*)/);if(r)return r[1];let n=e.match(/\([^)]+\)\s+(?:[\w$]+\.)*([a-zA-Z_$][\w$]*)/);if(n)return n[1];let s=t.match(/([a-zA-Z_$][\w$]*)/);return s?s[1]:t.split(/[(\s:]/)[0]}let tT=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:a,container:l,onMouseEnter:i,onMouseLeave:d,onFindReferences:c,onSearch:u,onExplain:m,explainDisabled:x},h){let{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null);(0,s.useImperativeHandle)(h,()=>p.current,[]);let g=l.getBoundingClientRect(),b=r-g.left,v=a-g.top,j=(0,s.useMemo)(()=>tP(e),[e]),w=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,a=0,l=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=l.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},a++));let l=t[0];/^["']/.test(l)?s.push((0,n.jsx)("span",{className:"text-green-11",children:l},a++)):/^\d+$/.test(l)?s.push((0,n.jsx)("span",{className:"text-orange-11",children:l},a++)):r.test(l)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-violet-11",children:l},a++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:l},a++)),o=t.index+l.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},a++)),s})(j),[j]);return(0,s.useEffect)(()=>{if(!p.current)return;let e=p.current,t=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=a-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,a,l]),(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-lv3 px-3 py-2 pointer-events-none",style:{left:b,top:v},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:w}),t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap",children:t})]}),(c||u||m)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1.5"}),(0,n.jsxs)("div",{className:"flex items-center gap-3 pointer-events-auto",onMouseEnter:i,onMouseLeave:d,children:[c&&(0,n.jsx)("button",{onClick:c,className:"text-[11px] text-brand hover:underline cursor-pointer",children:f("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(t$(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:f("hoverTooltip.search")}),m&&(0,n.jsx)("button",{onClick:()=>m(t$(e)),disabled:x,title:x?f("comments.aiResponding"):void 0,className:"text-[11px] text-brand hover:underline cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:no-underline",children:f("explain.action")})]})]})]})});function tR({references:e,loading:t,onSelect:r,onClose:a}){let{t:l}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,eP.kS)();if(t!==a.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let a=(0,eP.sQ)(r.file);if("text"!==a)try{let e=n.codeToTokens(r.lineText,{lang:a,theme:s}),l=(0,eP.b8)(e.tokens[0]||[]);l&&o.set(t,l)}catch{}}t===a.current&&r(o)})()},[e,n]),t}(e),d=[],c=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=c.get(r.file);void 0===n&&(n=d.length,c.set(r.file,n),d.push({file:r.file,items:[]})),d[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-card flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[l("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-hover text-muted-foreground",children:(0,n.jsx)(ed.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.notFound")}):d.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-hover flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function tI({results:e,loading:t,totalMatches:r,onSelect:a,onClose:l,scope:i,onScopeChange:d,selectedPath:c}){let{t:u}=(0,o.Bd)(),m=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,eP.kS)(),o=new Map;for(let t of e){let e=(0,eP.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let a=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),l=(0,eP.b8)(t.tokens[0]||[]);l&&o.set(a,l)}catch{}}}t===a.current&&r(o)})()},[e,n]),t}(e),x="selected"===i?e.filter(e=>e.path===c):e,h=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsxs)("div",{className:"border-t border-border bg-card flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground truncate",children:[u("searchResults.title")," ",!t&&u("searchResults.nMatches",{count:"selected"===i?h:r})]}),(0,n.jsxs)("div",{className:"flex items-center rounded border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>d("selected"),className:`px-2 py-0.5 ${"selected"===i?"bg-brand/15 text-brand":"text-muted-foreground hover:bg-hover"}`,children:u("searchResults.scopeSelected")}),(0,n.jsx)("button",{onClick:()=>d("all"),className:`px-2 py-0.5 border-l border-border ${"all"===i?"bg-brand/15 text-brand":"text-muted-foreground hover:bg-hover"}`,children:u("searchResults.scopeAll")})]})]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-hover text-muted-foreground flex-shrink-0",children:(0,n.jsx)(ed.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:u("searchResults.searching")}):0===x.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:u("searchResults.noResults")}):x.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=m.get(s);return(0,n.jsxs)("button",{onClick:()=>a(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-hover flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}var tF=r(63728);let tB=s.memo(function({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:a,initialSearchQuery:l,searchQueryTrigger:i,fileOpenRequest:d}){var c;let m,x,h,f,y,L,E,$,H,z,_,q,V,{t:es}=(0,o.Bd)(),ei=(0,A.r)(),ed=(0,s.useCallback)(e=>{ei?.sendMessage(es("explain.fileMessage",{path:e}))},[ei,es]),ec=(0,s.useCallback)(e=>{ei?.sendMessage(es("explain.stagedFileMessage",{path:e}))},[ei,es]),eu=(0,s.useCallback)(e=>{ei?.sendMessage(es("explain.unstagedFileMessage",{path:e}))},[ei,es]),em=(0,X.P)(),ex=(0,ee.U)(),eh=(0,et.Q)(),{activeView:ef,onViewChange:ep}=(0,tF.R8)(),[eg,eb]=(0,s.useState)(r),[ew,ek]=(0,s.useState)("code"),ey=(0,s.useRef)(null),eN=(0,s.useRef)(!1),[eC,eS]=(0,s.useState)(null),[eM,eL]=(0,s.useState)(null),[eE,eP]=(0,s.useState)(!1),e$=(0,s.useRef)(1),eT=(0,s.useRef)(null),[eR,eI]=(0,s.useState)(null),eF=(0,s.useRef)(null),[eB,eD]=(0,s.useState)({isDirty:!1,isSaving:!1}),[eA,eH]=(0,s.useState)(!1),[eW,ez]=(0,s.useState)(null),[eO,e_]=(0,s.useState)(null),[eq,eV]=(0,s.useState)("compact"),[eU,eK]=(0,s.useState)("unified"),[eQ,eG]=(0,s.useState)("full"),[eJ,eY]=(0,s.useState)("unified"),[eZ,eX]=(0,s.useState)(320),e0=(0,s.useRef)(null),e1=(0,s.useCallback)(e=>{"mouse"===e.pointerType&&0===e.button&&(e.preventDefault(),e0.current={startX:e.clientX,startWidth:eZ},e.currentTarget.setPointerCapture(e.pointerId))},[eZ]),e2=(0,s.useCallback)(e=>{let t=e0.current;t&&eX(Math.min(480,Math.max(320,t.startWidth+(e.clientX-t.startX))))},[]),e5=(0,s.useCallback)(e=>{e0.current&&(e0.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},[]),e4=(0,s.useRef)(null),e3=(0,B.o)(e4),e8=(0,s.useRef)(null),e9=(0,B.o)(e8),e7=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);let o=await u.t4.runPromiseExit(tE("/api/lsp/definition",{cwd:e,filePath:t,line:n,column:s}));return(r(!1),"Success"===o._tag)?o.value.definitions??[]:(console.error("[useLSP] definition error:",o.cause),[])},[e]),loading:t}}(t),te=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),a=(0,s.useRef)(0),l=(0,s.useRef)(!1),i=(0,s.useRef)(null),d=(0,s.useRef)({x:0,y:0}),c=(0,s.useCallback)(e=>{i.current=e},[]);(0,s.useEffect)(()=>{let e=e=>{d.current.x=e.clientX,d.current.y=e.clientY};return document.addEventListener("mousemove",e),()=>document.removeEventListener("mousemove",e)},[]);let m=(0,s.useRef)(!1),x=(0,s.useRef)(null),h=(0,s.useCallback)(()=>{let e=i.current;e&&m.current&&(e.style.pointerEvents="none"),m.current=!1,x.current&&(i.current?.removeEventListener("mouseleave",x.current),x.current=null)},[]),f=(0,s.useCallback)(()=>{let e=i.current;if(!e||m.current)return;m.current=!0,l.current=!0,e.style.pointerEvents="auto";let t=()=>{l.current=!1,h(),a.current++,r(null)};x.current=t,e.addEventListener("mouseleave",t)},[h]),p=(0,s.useCallback)((t,s,l,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let d=++a.current;n.current=setTimeout(async()=>{let n=await u.t4.runPromiseExit(tE("/api/lsp/hover",{cwd:e,filePath:t,line:s,column:l}));if(d!==a.current||"Success"!==n._tag)return;let o=n.value.hover;o&&o.displayString&&r({...o,x:i.x,y:i.y,filePath:t,line:s,column:l})},300)},[e]),g=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),a.current++,o.current=setTimeout(function(){if(l.current)return;let e=i.current;if(e){let t=e.getBoundingClientRect(),{x:r,y:n}=d.current;if(r>=t.left&&r<=t.right&&n>=t.top&&n<=t.bottom)return void f()}r(null)},150)},[f]),b=(0,s.useCallback)(()=>{l.current=!0,o.current&&clearTimeout(o.current)},[]),v=(0,s.useCallback)(()=>{l.current=!1,a.current++,r(null)},[]),j=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),l.current=!1,h(),a.current++,r(null)},[h]);return(0,s.useEffect)(()=>{t||h()},[t,h]),{hoverInfo:t,onTokenMouseEnter:p,onTokenMouseLeave:g,onCardMouseEnter:b,onCardMouseLeave:v,clearHover:j,setTooltipEl:c}}(t),tt=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(!1);return{references:t,loading:n,visible:a,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),l(!0);let a=await u.t4.runPromiseExit(tE("/api/lsp/references",{cwd:e,filePath:t,line:n,column:s}));"Success"===a._tag?r(a.value.references??[]):(console.error("[useLSP] references error:",a.cause),r([])),o(!1)},[e]),closeReferences:(0,s.useCallback)(()=>{l(!1),r([])},[])}}(t),tr=(m=(0,s.useRef)([]),x=(0,s.useRef)([]),h=(0,s.useCallback)(e=>{m.current.push(e),m.current.length>50&&(m.current=m.current.slice(-50)),x.current=[]},[]),f=(0,s.useCallback)(e=>{if(0===m.current.length)return null;let t=m.current.pop();return x.current.push(e),x.current.length>50&&(x.current=x.current.slice(-50)),t},[]),y=(0,s.useCallback)(e=>{if(0===x.current.length)return null;let t=x.current.pop();return m.current.push(e),m.current.length>50&&(m.current=m.current.slice(-50)),t},[]),{push:h,goBack:f,goForward:y,canGoBack:(0,s.useCallback)(()=>m.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>x.current.length>0,[])}),tn=(0,el.F)(),ts=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[a,l]=(0,s.useState)(new Set),[i,d]=(0,s.useState)([]),[c,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(new Set),[g,b]=(0,s.useState)(null),[w,k]=(0,s.useState)(""),[y,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(null),[M,L]=(0,s.useState)(!0),[E,P]=(0,s.useState)(!1),[$,T]=(0,s.useState)(null),R=(0,s.useRef)(null),[F,B]=(0,s.useState)(!1),[D,A]=(0,s.useState)(null),[H,W]=(0,s.useState)("center"),[z,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(null),[V,U]=(0,s.useState)(!1),[K,Q]=(0,s.useState)([]),[G,J]=(0,s.useState)(!1),[Y,Z]=(0,s.useState)(null),[X,ee]=(0,s.useState)(null),[et,er]=(0,s.useState)(!0),[en,es]=(0,s.useState)(!1),[eo,ea]=(0,s.useState)(!1),el=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),ei=(0,s.useMemo)(()=>(0,I.v3)(el),[el]),ed=(0,s.useMemo)(()=>new Set((0,I.tW)(ei)),[ei]),ec=(0,s.useMemo)(()=>w?n?(0,I.KH)(n,w,y):(0,I.q3)(t,w,y):null,[t,n,w,y]);(0,s.useEffect)(()=>{if(!ec||0===ec.size)return void b(null);let e=new Set;if(n){let t=new Set(n);for(let r of ec)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&ec.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}b(e)},[ec,t,n]);let eu=g??f,em=(0,s.useRef)(null),ex=(0,s.useCallback)(t=>{em.current&&clearTimeout(em.current),em.current=setTimeout(()=>{u.t4.runFork((0,v.Ft)(e,Array.from(t)).pipe(ev.sFT(e=>ev.OH5(()=>console.error("Error saving expanded paths:",e))),ev.NWQ(()=>ev.rIH)))},500)},[e]),eh=(0,s.useCallback)(async()=>{L(!0),T(null),await u.t4.runPromise((0,v.mP)(e).pipe(ev.YWq({onSuccess:e=>{e.error?T(e.error):(r(e.files??[]),e.expandedPaths&&Array.isArray(e.expandedPaths)&&p(new Set(e.expandedPaths)))},onFailure:e=>{console.error("Error loading files:",e),T("Failed to load files")}}))),L(!1)},[e]),ef=(0,s.useCallback)(()=>{u.t4.runPromise((0,v.DZ)(e).pipe(ev.YWq({onSuccess:e=>{e.paths&&o(e.paths)},onFailure:e=>{console.error("Error loading file index:",e)}})))},[e]),ep=(0,s.useCallback)(async t=>{l(e=>new Set([...e,t])),await u.t4.runPromise((0,v.gZ)(e,t).pipe(ev.YWq({onSuccess:e=>{e.children&&r(r=>{if(!t){let t=new Map(r.map(e=>[e.path,e]));return e.children.map(e=>{let r=t.get(e.path);return r?.children&&e.isDirectory?{...e,children:r.children}:e})}let n=structuredClone(r),s=(0,I.MB)(n,t);return s&&(s.children=e.children),n})},onFailure:e=>{console.error("Error loading directory:",e)}}))),l(e=>{let r=new Set(e);return r.delete(t),r})},[e]),eg=(0,s.useRef)(a);eg.current=a,(0,s.useEffect)(()=>{for(let e of g??f){let r=(0,I.MB)(t,e);r&&r.isDirectory&&!r.children&&!eg.current.has(e)&&ep(e)}},[t,f,g,ep]);let eb=(0,s.useCallback)(async()=>{await u.t4.runPromise((0,v.r9)(e).pipe(ev.YWq({onSuccess:e=>d(e.files??[]),onFailure:e=>console.error("Error loading recent files:",e)})))},[e]),ej=(0,s.useCallback)(async t=>{d(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)}),await u.t4.runPromise((0,v.YW)(e,t).pipe(ev.sFT(e=>ev.OH5(()=>console.error("Error adding to recent files:",e))),ev.NWQ(()=>ev.rIH)))},[e]),ew=(0,s.useCallback)((t,r,n,s)=>{d(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),u.t4.runFork((0,v.YW)(e,t,{scrollLine:r,cursorLine:n,cursorCol:s}).pipe(ev.NWQ(()=>ev.rIH)))},[e]),ek=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),ey=(0,s.useCallback)(async t=>{let r=t||c;r&&(J(!0),Z(null),await u.t4.runPromise((0,v.eE)(e,r).pipe(ev.YWq({onSuccess:e=>{e.error?Z(e.error):Q(e.blame??[])},onFailure:e=>{console.error("Error loading blame:",e),Z("Failed to load blame info")}}))),J(!1))},[e,c]),eN=(0,s.useCallback)(async t=>{P(!0),h(null),U(!1),Q([]),Z(null),ee(null);let r=ev.JkU(function*(){let r=yield*(0,v.r6)(e,t);if(!r.ok)return{type:"error",message:r.data?.error||"Failed to stat file"};let n=r.data??{};if(!n.exists)return{type:"error",message:"File not found"};if("dir"===n.kind)return{type:"error",message:"Path is a directory"};switch(n.category){case"image":return{type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}};case"pdf":return{type:"pdf",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}};case"binary":return{type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs};case"too-large":return{type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs};default:{let r=yield*(0,j.K)(e,t);if(409===r.status)return{type:"binary",message:r.data?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs};if(!r.ok)return{type:"error",message:r.data?.error||"Failed to load file"};let s=r.data??{};return{type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}}}}});await u.t4.runPromise(r.pipe(ev.YWq({onSuccess:e=>h(e),onFailure:e=>{console.error("Error loading file content:",e),h({type:"error",message:"Failed to load file"})}}))),ej(t),ey(t),P(!1)},[e,ej,ey]),eC=(0,s.useCallback)(()=>{V?U(!1):(U(!0),0===K.length&&ey())},[V,K.length,ey]),eS=(0,s.useCallback)((e,t)=>{if(!e)return;if(m(e),A(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(A(t.scrollLine),W("start"),O(t.cursorLine??null),q(t.cursorCol??null)):(W("center"),O(null),q(null))}else W("center"),O(null),q(null);eN(e);let r=e.split("/");if(r.length>1){let e=[];for(let t=1;t<r.length;t++)e.push(r.slice(0,t).join("/"));p(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ex(r),n?r:t})}},[eN,ex,i]),eM=(0,s.useCallback)(e=>{if(g)b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!f.has(e);if(p(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ex(r),r}),r){let r=(0,I.MB)(t,e);r&&r.isDirectory&&!r.children&&ep(e)}}},[g,ex,f,t,ep]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:a,expandedPaths:f,setExpandedPaths:p,searchTreeExpandedPaths:g,setSearchTreeExpandedPaths:b,effectiveExpandedPaths:eu,searchQuery:w,setSearchQuery:k,searchExactMatch:y,setSearchDirExact:N,matchedPaths:ec,creatingItem:C,setCreatingItem:S,isLoadingFiles:M,fileError:$,searchInputRef:R,shouldScrollToSelected:F,setShouldScrollToSelected:B,targetLineNumber:D,setTargetLineNumber:A,targetScrollAlign:H,setTargetScrollAlign:W,initialCursorLine:z,initialCursorCol:_,setInitialCursorLine:O,setInitialCursorCol:q,selectedPath:c,setSelectedPath:m,fileContent:x,setFileContent:h,isLoadingContent:E,recentFiles:i,recentFilePaths:el,setRecentFiles:d,recentFilesTree:ei,recentTreeDirPaths:ed,showBlame:V,setShowBlame:U,blameLines:K,isLoadingBlame:G,blameError:Y,blameSelectedCommit:X,setBlameSelectedCommit:ee,previewMarkdown:et,setPreviewMarkdown:er,previewHtml:en,setPreviewHtml:es,showEditor:eo,setShowEditor:ea,saveExpandedPaths:ex,loadFiles:eh,loadFileIndex:ef,loadDirectory:ep,loadRecentFiles:eb,addToRecentFiles:ej,updateRecentFilePosition:ew,getRecentFilePosition:ek,loadFileContent:eN,loadBlame:ey,handleToggleBlame:eC,handleSelectFile:eS,handleToggle:eM}}({cwd:t});c=ts.selectedPath,L=(0,s.useRef)(null),(0,s.useEffect)(()=>{c&&c!==L.current&&tL(c)&&(L.current=c,u.t4.runFork(tE("/api/lsp/warmup",{cwd:t,filePath:c}).pipe(ev.NLW).pipe(ev.NWQ(()=>ev.rIH))))},[t,c]);let to=(0,s.useMemo)(()=>{let e=ts.fileContent,t=ts.selectedPath;return e&&"text"===e.type&&"string"==typeof e.content&&t&&(0,F.Hz)(t)?(0,F.xb)(e.content,F.cG):null},[ts.fileContent,ts.selectedPath]),[ta,tl]=(0,s.useState)({version:0,collapsed:!1});(0,s.useEffect)(()=>{tl(e=>e.collapsed?{version:e.version+1,collapsed:!1}:e)},[ts.selectedPath]);let ti=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(null),[m,x]=(0,s.useState)(new Set),[h,f]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[p,g]=(0,s.useState)(null),b=(0,s.useRef)(null),v=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){a([]),g(null);return}if(n.length<2)return void c(tM.A.t("fileBrowser.searchMinChars"));i(!0),c(null);let s=new URLSearchParams({cwd:e,q:r,caseSensitive:String(h.caseSensitive),wholeWord:String(h.wholeWord),regex:String(h.regex),fileType:h.fileType}),o=ev.$mh({try:async()=>{let e=await fetch(`/api/files/search?${s}`),t=await e.json();if(t.error)throw Error(t.error);return t},catch:e=>new ej.uV({message:"content search failed",cause:e})});await u.t4.runPromise(o.pipe(ev.YWq({onSuccess:e=>{a(e.results),g({totalFiles:e.totalFiles,totalMatches:e.totalMatches,truncated:e.truncated}),x(new Set(e.results.map(e=>e.path))),e.results.length>0&&t?.()},onFailure:e=>{c(e.cause instanceof Error?e.cause.message:"Search failed"),a([])}}))),i(!1)},[e,h,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:l,searchError:d,searchExpandedPaths:m,searchOptions:h,setSearchOptions:f,searchStats:p,contentSearchInputRef:b,performContentSearch:v,handleSearchToggle:(0,s.useCallback)(e=>{x(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>eH(!0)}),td=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),[m,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)(new Set),[j,k]=(0,s.useState)([]),[y,N]=(0,s.useState)([]),C=(0,s.useMemo)(()=>{let e=new Set((0,M.Sz)(j));for(let t of p)e.delete(t);return e},[j,p]),S=(0,s.useMemo)(()=>{let e=new Set((0,M.Sz)(y));for(let t of b)e.delete(t);return e},[y,b]),[L,E]=(0,s.useState)(!1),[P,$]=(0,s.useState)(0),R=(0,s.useCallback)(async()=>{a(!0),i(null),await u.t4.runPromise((0,w.lv)(e).pipe(ev.YWq({onSuccess:e=>{n(e);let t=(0,M.Do)(e.staged),r=(0,M.Do)(e.unstaged);k(t),N(r)},onFailure:e=>{i(e.cause instanceof Error?e.cause.message:"Unknown error")}}))),a(!1)},[e]),I=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),F=(0,s.useCallback)(e=>{v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),B=(0,s.useCallback)((e,r)=>{c({file:e,type:r}),t(e.path)},[t]),D=(0,s.useCallback)(async(e,t,r,n)=>{let s=await u.t4.runPromiseExit(e);"Success"===s._tag?(await R(),(0,T.oR)(t,"success")):(console.error(r,s.cause),(0,T.oR)(n,"error"))},[R]),A=(0,s.useCallback)(t=>D((0,w.Iz)(e,[t]),tM.A.t("toast.staged"),"Error staging file:",tM.A.t("toast.stageFailed")),[e,D]),H=(0,s.useCallback)(t=>D((0,w.X0)(e,[t]),tM.A.t("toast.unstaged"),"Error unstaging file:",tM.A.t("toast.unstageFailed")),[e,D]),W=(0,s.useCallback)(async t=>{0!==t.length&&await D((0,w.Iz)(e,t),tM.A.t("toast.stagedNFiles",{count:t.length}),"Error staging files:",tM.A.t("toast.stageFailed"))},[e,D]),z=(0,s.useCallback)(async t=>{0!==t.length&&await D((0,w.X0)(e,t),tM.A.t("toast.unstagedNFiles",{count:t.length}),"Error unstaging files:",tM.A.t("toast.unstageFailed"))},[e,D]),O=(0,s.useCallback)(async t=>{if(0===t.length)return;let r=t.filter(e=>"untracked"===e.status).map(e=>e.path),n=t.filter(e=>"untracked"!==e.status).map(e=>e.path),s=ev.JkU(function*(){r.length>0&&(yield*(0,w.Ub)(e,r,!0)),n.length>0&&(yield*(0,w.Ub)(e,n,!1))});await D(s,tM.A.t("toast.discardedNFiles",{count:t.length}),"Error discarding files:",tM.A.t("toast.discardFailed"))},[e,D]),_=(0,s.useCallback)(async()=>{r?.unstaged.length&&await D((0,w.Iz)(e,r.unstaged.map(e=>e.path)),tM.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"Error staging all files:",tM.A.t("toast.stageFailed"))},[e,r,D]),q=(0,s.useCallback)(async()=>{r?.staged.length&&await D((0,w.X0)(e,r.staged.map(e=>e.path)),tM.A.t("toast.unstagedNFiles",{count:r.staged.length}),"Error unstaging all files:",tM.A.t("toast.unstageFailed"))},[e,r,D]),V=(0,s.useCallback)(async t=>{let r="untracked"===t.status;await D((0,w.Ub)(e,[t.path],r),r?tM.A.t("toast.deletedFile"):tM.A.t("toast.discardedChanges"),"Error discarding file:",tM.A.t("toast.discardFailed"))},[e,D]),U=(0,s.useCallback)(async()=>{if(!r?.unstaged.length||!await (0,T.lJ)(tM.A.t("git.discardAllConfirm",{count:r.unstaged.length}),{danger:!0}))return;let t=r.unstaged.filter(e=>"untracked"===e.status).map(e=>e.path),n=r.unstaged.filter(e=>"untracked"!==e.status).map(e=>e.path),s=r.unstaged.length,o=ev.JkU(function*(){n.length>0&&(yield*(0,w.Ub)(e,n,!1)),t.length>0&&(yield*(0,w.Ub)(e,t,!0))});await D(o,tM.A.t("toast.discardedNFiles",{count:s}),"Error discarding all:",tM.A.t("toast.discardFailed"))},[e,r,D]);return(0,s.useEffect)(()=>{d?(f(!0),u.t4.runPromiseExit((0,w.w2)(e,d.file.path,d.type)).then(e=>{"Success"===e._tag?x(e.value):console.error("Error fetching diff:",e.cause),f(!1)})):x(null)},[d,e,P]),{status:r,setStatus:n,statusLoading:o,statusError:l,statusSelectedFile:d,statusDiff:m,statusDiffLoading:h,stagedExpandedPaths:C,unstagedExpandedPaths:S,stagedTree:j,setStagedTree:k,unstagedTree:y,setUnstagedTree:N,showStatusDiffPreview:L,setShowStatusDiffPreview:E,fetchStatus:R,handleStagedToggle:I,handleUnstagedToggle:F,handleStatusFileSelect:B,handleStage:A,handleUnstage:H,handleStageFiles:W,handleUnstageFiles:z,handleDiscardFiles:O,handleStageAll:_,handleUnstageAll:q,handleDiscardFile:V,handleDiscardAll:U,refreshDiff:(0,s.useCallback)(()=>$(e=>e+1),[])}}({cwd:t,addToRecentFiles:ts.addToRecentFiles}),tc=(0,s.useMemo)(()=>{let e=new Set;if(td.status){for(let t of td.status.staged)e.add(t.path);for(let t of td.status.unstaged)e.add(t.path)}return e},[td.status]),tu=(0,s.useMemo)(()=>{let e=new Map;if(td.status){for(let t of td.status.staged)e.set(t.path,"staged");for(let t of td.status.unstaged)e.set(t.path,"unstaged")}return e},[td.status]),tm=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(""),[l,i]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[m,x]=(0,s.useState)([]),[h,f]=(0,s.useState)([]),[p,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)(null),[j,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)(!1),[P,$]=(0,s.useState)(!0),[T,R]=(0,s.useState)(!1),[F,B]=(0,s.useState)(!1),[D,A]=(0,s.useState)(null),H=(0,s.useRef)(null),[W,z]=(0,s.useState)(null),[O,_]=(0,s.useState)(!1),[q,V]=(0,s.useState)(""),[U,K]=(0,s.useState)(""),[Q,G]=(0,s.useState)([]),[J,Y]=(0,s.useState)([]),[Z,X]=(0,s.useState)(new Set),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)(!1),[ei,ed]=(0,s.useState)("worktree"),ec=(0,s.useRef)(O);ec.current=O;let eu=(0,s.useRef)(ei);eu.current=ei;let em=(0,s.useRef)(U);em.current=U;let ex=(0,s.useRef)(ee);ex.current=ee;let eh=(0,s.useCallback)(()=>{N(!0),A(null),u.t4.runPromise((0,w.r4)(e).pipe(ev.YWq({onSuccess:e=>{e.local&&e.current?(n(e),a(e.current),e.upstream&&V(e.upstream)):(A(tM.A.t("git.cannotGetBranches")),n(null))},onFailure:e=>{console.error(e),"NotFoundError"===e._tag?A(tM.A.t("git.notGitRepo")):A(tM.A.t("git.getBranchesFailed")),n(null)}}))).finally(()=>N(!1))},[e]),ef=(0,s.useCallback)(t=>{S(!0),c(null),x([]),f([]),v(null),k(null),$(!0),u.t4.runPromise((0,w.Bj)(e,t,I.B_).pipe(ev.YWq({onSuccess:e=>{let t=e.commits||[];i(t),$(t.length>=I.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>S(!1))},[e]),ep=(0,s.useCallback)(()=>{if(L||!P||!o)return;E(!0);let t=l.length;u.t4.runPromise((0,w.Bj)(e,o,I.B_,t).pipe(ev.YWq({onSuccess:e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),$(t.length>=I.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>E(!1))},[e,o,l.length,L,P]),eg=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&ep()},[ep]),eb=(0,s.useCallback)(t=>{c(t),v(null),k(null),R(!0),u.t4.runPromise((0,w.Zi)(e,t.hash).pipe(ev.YWq({onSuccess:e=>{let t=e.files||[];x(t);let r=(0,M.Do)(t);f(r),g(new Set((0,M.Sz)(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>R(!1))},[e]),ej=(0,s.useCallback)(r=>{d&&(v(r),t(r.path),B(!0),u.t4.runPromise((0,w.Zi)(e,d.hash,r.path).pipe(ev.YWq({onSuccess:e=>k(e),onFailure:e=>{console.error(e)}}))).finally(()=>B(!1)))},[e,d,t]),ew=(0,s.useCallback)(e=>{g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ek=(0,s.useCallback)((t,r)=>{eo(!0),et(null),en(null),u.t4.runPromise((0,w.yy)(e,t,void 0,r??eu.current).pipe(ev.YWq({onSuccess:e=>{let t=e.files||[];G(t);let r=(0,M.Do)(t);Y(r),X(new Set((0,M.Sz)(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>eo(!1))},[e]),ey=(0,s.useCallback)(r=>{et(r),t(r.path),el(!0),u.t4.runPromise((0,w.yy)(e,U,r.path,eu.current).pipe(ev.YWq({onSuccess:e=>en(e),onFailure:e=>{console.error(e)}}))).finally(()=>el(!1))},[e,U,t]),eN=(0,s.useCallback)(()=>{if(!ec.current||"worktree"!==eu.current)return;let t=em.current;if(!t)return;u.t4.runPromise((0,w.yy)(e,t,void 0,"worktree").pipe(ev.YWq({onSuccess:e=>{let t=e.files||[];G(t);let r=(0,M.Do)(t);Y(r),X(e=>{let t=new Set(e);for(let n of(0,M.Sz)(r))e.has(n)||t.add(n);return t})},onFailure:e=>console.error(e)})));let r=ex.current;r&&u.t4.runPromise((0,w.yy)(e,t,r.path,"worktree").pipe(ev.YWq({onSuccess:e=>en(e),onFailure:e=>console.error(e)})))},[e]),eC=(0,s.useCallback)(e=>{if(eu.current===e)return;eu.current=e,ed(e);let t=em.current;ec.current&&t&&ek(t,e)},[ek]),eS=(0,s.useCallback)(e=>{X(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eM=(0,s.useCallback)(e=>{if(_(e),e){let e="origin/main";K(e),ek(e)}else G([]),Y([]),et(null),en(null),K("")},[q,ek]);return{branches:r,selectedBranch:o,setSelectedBranch:a,commits:l,setCommits:i,selectedCommit:d,setSelectedCommit:c,historyFiles:m,historyFileTree:h,historyExpandedPaths:p,historySelectedFile:b,historyFileDiff:j,isLoadingBranches:y,isLoadingCommits:C,isLoadingMore:L,hasMoreCommits:P,setHasMoreCommits:$,isLoadingHistoryFiles:T,isLoadingHistoryDiff:F,historyError:D,commitListRef:H,tooltipPos:W,loadBranches:eh,loadCommits:ef,loadMoreCommits:ep,handleCommitListScroll:eg,handleSelectCommit:eb,handleSelectHistoryFile:ej,handleHistoryToggle:ew,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{z({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{z(null)},[]),compareMode:O,toggleCompareMode:eM,compareBaseBranch:U,setCompareBaseBranch:K,upstreamBranch:q,compareFiles:Q,compareFileTree:J,compareExpandedPaths:Z,compareSelectedFile:ee,compareFileDiff:er,isLoadingCompareFiles:es,isLoadingCompareDiff:ea,handleSelectCompareFile:ey,handleCompareToggle:eS,loadCompareFiles:ek,compareDiffMode:ei,setCompareDiffMode:eC,refreshCompare:eN}}({cwd:t,addToRecentFiles:ts.addToRecentFiles}),tx=tm.compareFileDiff,th=tx?.filePath??"",tf=(0,s.useMemo)(()=>{if(!tx||tx.isDeleted)return;let e={content:tx.newContent,filePath:tx.filePath};return(0,F.e$)(tx.filePath)?()=>e_(e):tx.filePath.endsWith(".json")?()=>ez(e):void 0},[tx]),tp=(0,s.useCallback)(()=>e_(null),[]),tb=(0,s.useCallback)(()=>ez(null),[]);(0,s.useEffect)(()=>{e_(null)},[tx]);let tj=(0,s.useMemo)(()=>{let e=0,t=0;for(let r of tm.compareFiles)e+=r.additions,t+=r.deletions;return{additions:e,deletions:t}},[tm.compareFiles]),ty=(0,s.useCallback)(e=>{ei?.sendMessage(es("worktree"===tm.compareDiffMode?"explain.compareFileWorktreeMessage":"explain.compareFileMessage",{base:tm.compareBaseBranch,path:e}))},[ei,es,tm.compareBaseBranch,tm.compareDiffMode]),tC=(0,s.useRef)(!1),tS=(0,s.useCallback)(e=>{ts.setFileContent(t=>t?.type==="text"?{...t,content:e}:t),ts.showEditor||(tC.current=!0,ts.setShowEditor(!0))},[ts]);(0,s.useEffect)(()=>{ts.showEditor&&tC.current&&(eF.current?.markDirty(),tC.current=!1)},[ts.showEditor]);let tP=(0,s.useCallback)(e=>{ts.setShowEditor(!0)},[ts]),t$=(0,s.useCallback)(async()=>{if(!ts.fileContent||"text"!==ts.fileContent.type||!ts.fileContent.content)return;let e=await u.t4.runPromiseExit((0,v.OJ)({cwd:t,path:ts.selectedPath,content:ts.fileContent.content}));try{if("Failure"===e._tag||!e.value.ok)throw Error("Failed to save file");let t=e.value.data?.mtime;t&&ts.setFileContent(e=>e?.type==="text"?{...e,mtime:t}:e),(0,T.oR)(es("toast.savedSuccess"),"success")}catch{(0,T.oR)(es("toast.saveFailed"),"error")}},[t,ts]),tB=(0,s.useCallback)(()=>{if(!ts.selectedPath)return;let e=e$.current,t=eT.current;e>0&&ts.updateRecentFilePosition(ts.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[ts]),tD=(0,s.useCallback)(async(e,t)=>{let r=e!==ts.selectedPath;if(r&&ts.showEditor){if(eB.isDirty&&(!await (0,T.lJ)(es("fileBrowser.saveBeforeSwitch"),{confirmText:es("fileBrowser.saveAndSwitch"),cancelText:es("common.cancel")})||(await eF.current?.save(),eF.current?.isDirty)))return;ts.setShowEditor(!1)}r&&tB(),ts.handleSelectFile(e,t)},[ts,tB,eB.isDirty,es]),tA=(0,s.useMemo)(()=>{let e=ti.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,I.v3)(r),s=new Set((0,I.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[ti.contentSearchResults]),[tH,tW]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{tW(tA.expandDirs)},[tA.expandDirs]);let tz=(0,s.useCallback)(e=>{tW(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),tO=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=tA.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[tA.matchMap]),t_=eA&&ti.contentSearchResults.length>0,[tq,tV]=(0,s.useState)("selected");(0,s.useEffect)(()=>{tV("selected")},[ti.contentSearchResults]);let tU=!!ts.selectedPath&&null!==tL(ts.selectedPath),[tK,tQ]=(0,s.useState)(!1),tG=(0,s.useCallback)(async(e,r)=>{if(!ts.selectedPath||!tU)return;let n=await e7.goToDefinition(ts.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",a=s.file.startsWith(o)?s.file.slice(o.length):s.file;tr.push({filePath:ts.selectedPath,lineNumber:e$.current}),a===ts.selectedPath?ts.setTargetLineNumber(s.line):tD(a,s.line)},[ts,t,tU,e7,tr]),tJ=(0,s.useCallback)((e,t,r,n,s)=>{e&&null!==tL(e)&&(tQ(t),te.onTokenMouseEnter(e,r,n,s))},[te]),tY=(0,s.useCallback)((e,t,r)=>{tU&&tJ(ts.selectedPath,!1,e,t,r)},[ts.selectedPath,tU,tJ]),tZ=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;ts.selectedPath&&tr.push({filePath:ts.selectedPath,lineNumber:e$.current}),n===ts.selectedPath?ts.setTargetLineNumber(e.line):tD(n,e.line)},[ts,t,tr]),tX=(0,s.useMemo)(()=>{if(!td.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":case"untracked":return"A";case"deleted":return"D";case"renamed":return"R"}};for(let r of td.status.staged)e.set(r.path,t(r.status));for(let r of td.status.unstaged)e.set(r.path,t(r.status));return e},[td.status]),t0=(0,s.useMemo)(()=>{if(!td.status)return null;let e=new Map;for(let t of td.status.staged)"renamed"===t.status&&t.oldPath&&e.set(t.path,t.oldPath);return e},[td.status]),t1=(0,s.useCallback)(e=>{eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)},[ti.setContentSearchQuery,ti.performContentSearch]),t2=function({cwd:e,selectedPath:t,gitStatusMap:r,renameOldPaths:n,isText:o,refreshKey:a}){let l=t?r?.get(t):void 0,i=o&&("M"===l||"R"===l),[d,c]=(0,s.useState)(null),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(()=>new Set),p=(0,s.useRef)(new Set),g=i&&!!t&&h.has(t);return(0,s.useEffect)(()=>{!t||p.current.has(t)||!r||o&&(p.current.add(t),i&&f(e=>new Set(e).add(t)))},[t,r,o,i]),(0,s.useEffect)(()=>{if(!g||!t)return void c(null);let r=!1;return x(!0),u.t4.runPromiseExit((0,w.w2)(e,t,"worktree",n?.get(t)).pipe(ev.fRP("explorer.treeFileDiff"))).then(e=>{r||("Success"===e._tag?c(e.value):(console.error("Error fetching tree file diff:",e.cause),c(null)),x(!1))}),()=>{r=!0}},[g,t,e,a,n]),{canDiff:i,showDiff:g,toggleDiff:(0,s.useCallback)(()=>{t&&f(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},[t]),diff:d,isLoadingDiff:m}}({cwd:t,selectedPath:ts.selectedPath,gitStatusMap:tX,renameOldPaths:t0,isText:ts.fileContent?.type==="text",refreshKey:ts.fileContent?.mtime}),t5="tree"===eg&&t2.showDiff;(0,s.useEffect)(()=>{eS(ey.current)},[]),(0,s.useEffect)(()=>{eb(r)},[r,a]),(0,s.useEffect)(()=>{l&&(eb("search"),ti.setContentSearchQuery(l),ti.performContentSearch(l))},[i]);let t4=(0,s.useCallback)(e=>{eb(e),ts.setBlameSelectedCommit(null),"history"===e&&tm.selectedBranch&&tm.loadCommits(tm.selectedBranch)},[ts,tm.selectedBranch,tm.loadCommits]),t3=(0,s.useCallback)(()=>{if(!ts.selectedPath)return;let e={filePath:ts.selectedPath,lineNumber:e$.current},t=tr.goBack(e);t&&(t.filePath===ts.selectedPath?ts.setTargetLineNumber(t.lineNumber):tD(t.filePath,t.lineNumber))},[ts,tr]),t6=(0,s.useCallback)(()=>{if(!ts.selectedPath)return;let e={filePath:ts.selectedPath,lineNumber:e$.current},t=tr.goForward(e);t&&(t.filePath===ts.selectedPath?ts.setTargetLineNumber(t.lineNumber):tD(t.filePath,t.lineNumber))},[ts,tr]),t8=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;"Success"===(await u.t4.runPromiseExit((0,v.__)({cwd:t,path:e})))._tag?(0,T.oR)(es("toast.copiedName",{name:r}),"success"):(0,T.oR)(es("toast.copyFailed"),"error")},[t,es]),t9=(0,s.useCallback)(async e=>{let r=await u.t4.runPromiseExit((0,v.dt)());if("Success"!==r._tag||!r.value.path)return void(0,T.oR)(es("toast.noFileToPaste"),"info");let n=r.value.path,s=await u.t4.runPromiseExit((0,v.Nn)({cwd:t,targetDir:e,sourceAbsPath:n}));if("Success"===s._tag)(0,T.oR)(es("toast.pastedFile",{name:s.value.newName}),"success"),ts.loadDirectory(e),ts.loadFileIndex();else{let e="Fail"===s.cause._tag?s.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:es("toast.pasteFailed");(0,T.oR)(r,"error")}},[t,ts,es]),t7=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===ef;if(t.ctrlKey&&!t.metaKey&&"Minus"===t.code){if(t.preventDefault(),!r)return;t.shiftKey?t6():t3();return}if((t.metaKey||t.ctrlKey)&&"p"===t.key&&!t.shiftKey&&!t.altKey){t.preventDefault(),r?eP(e=>!e):(ep("explorer"),eP(!0));return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===eg||"recent"===eg)&&ts.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),t8(ts.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===eg||"recent"===eg)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),t9((0,I.S7)(ts.selectedPath,ts.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(eW){t.preventDefault(),e9.open();return}if(ts.previewMarkdown&&ts.selectedPath&&(0,F.Hz)(ts.selectedPath)){t.preventDefault(),e3.open();return}}if(r&&"Escape"===t.key){if(eE)return void eP(!1);if(e9.isVisible)return void e9.close();if(e3.isVisible)return void e3.close();if(eO)return void e_(null);if(eW)return void ez(null);let t=Date.now();if(t-t7.current<3e3)return;t7.current=t,tt.visible?tt.closeReferences():eA?eH(!1):ts.blameSelectedCommit?ts.setBlameSelectedCommit(null):ts.showBlame?ts.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,ts.showBlame,ts.blameSelectedCommit,ts,eE,tt.visible,tt.closeReferences,eA,t3,t6,e3,eW,eO,e9,eg,t8,t9,ef,ep]),(0,s.useEffect)(()=>{ts.loadFiles(),ts.loadFileIndex(),ts.loadRecentFiles(),td.fetchStatus(),tm.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{td.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[td.fetchStatus]);let re=(0,s.useRef)(tn);(0,s.useEffect)(()=>{tn&&!re.current&&(ts.loadFiles(),ts.loadFileIndex(),ts.loadRecentFiles(),td.fetchStatus(),tm.loadBranches()),re.current=tn},[tn]),(0,s.useEffect)(()=>{tm.selectedBranch&&tm.loadCommits(tm.selectedBranch)},[tm.selectedBranch,tm.loadCommits]);let rt=(0,s.useRef)(eg),rr=(0,s.useRef)(!1);(0,s.useEffect)(()=>{let e=rt.current;if(rt.current=eg,"tree"===eg&&rr.current){rr.current=!1;return}if(("tree"===eg||"recent"===eg)&&ts.recentFiles.length>0){let t=ts.recentFiles[0].path;ts.selectedPath&&("status"!==e&&"history"!==e||ts.selectedPath===t)||(ts.setShouldScrollToSelected(!0),tD(t))}},[eg,ts.recentFiles,ts.selectedPath,tD,ts]);let rn=(0,s.useRef)(tm.selectedBranch);rn.current=tm.selectedBranch;let rs=(0,s.useRef)(ts.selectedPath);rs.current=ts.selectedPath;let ro=(0,s.useRef)(ts.fileContent?.type);ro.current=ts.fileContent?.type;let ra=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!Array.isArray(r))return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(u.t4.runPromise((0,v.mP)(t)).then(e=>{e.error||ts.setFiles(t=>(0,I.HR)(e.files??[],t))}).catch(()=>{})),o.push(u.t4.runPromise((0,v.DZ)(t)).then(e=>{e.paths&&ts.setFileIndex(e.paths)}).catch(()=>{})),o.push(u.t4.runPromise((0,v.r9)(t)).then(e=>{ts.setRecentFiles(e.files??[])}).catch(()=>{}))),n||s){o.push(u.t4.runPromise((0,w.lv)(t)).then(e=>{td.setStatus(e);let t=(0,M.Do)(e.staged),r=(0,M.Do)(e.unstaged);td.setStagedTree(t),td.setUnstagedTree(r)}).catch(()=>{})),td.refreshDiff(),tm.refreshCompare(),n&&tm.loadBranches();let e=rn.current;e&&o.push(u.t4.runPromise((0,w.Bj)(t,e,I.B_)).then(e=>{let t=e.commits??[];tm.setCommits(t),tm.setHasMoreCommits(t.length>=I.B_)}).catch(()=>{}))}let a=rs.current,l=ro.current;a&&"text"===l&&o.push(u.t4.runPromise((0,j.K)(t,a)).then(e=>{let t=e.ok?e.data:null;t&&"string"==typeof t.content&&ts.setFileContent({type:"text",content:t.content,size:t.size,mtime:t.mtimeMs,...t.isSymlink?{isSymlink:!0,symlinkTarget:t.symlinkTarget}:{}})}).catch(()=>{})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,ea.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:ra,enabled:tn});let rl=(0,s.useCallback)(e=>{tD(e),ts.setShouldScrollToSelected(!0),eb("tree")},[ts,tD]),ri=(0,s.useRef)(tD);(0,s.useEffect)(()=>{ri.current=tD},[tD]);let rd=(0,s.useRef)(null),{setPreviewMarkdown:rc,setShouldScrollToSelected:ru}=ts;(0,s.useEffect)(()=>{!d||ts.isLoadingFiles||rd.current!==d.nonce&&(rd.current=d.nonce,rr.current=!0,ek("code"),eb("tree"),null!=d.lineNumber&&rc(!1),ri.current(d.path,d.lineNumber),ru(!0))},[d,ts.isLoadingFiles,rc,ru]);let rm=(0,s.useCallback)(({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,T.oR)(es("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:es("common.copyAbsPath"),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:"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(),rl(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:es("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",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)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),[t,rl,es]),rx=(0,s.useCallback)(({focalFile:e})=>"tree"===eg&&t2.canDiff&&e===ts.selectedPath?(0,n.jsxs)(n.Fragment,{children:[t2.showDiff&&(0,n.jsx)(C.y,{value:eQ,onChange:eG}),(0,n.jsx)("button",{onClick:t2.toggleDiff,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${t2.showDiff?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,title:t2.showDiff?es("fileBrowser.exitDiff"):es("fileBrowser.viewDiff"),children:es("common.diff")})]}):null,[eg,t2.canDiff,t2.showDiff,t2.toggleDiff,ts.selectedPath,eQ,es]),[rh,rf]=(0,s.useState)(null),rp=(0,s.useCallback)((e,t)=>{ts.setPreviewMarkdown(!0),rl(e),rf(t),t&&setTimeout(()=>rf(null),400)},[ts,rl]);return(0,n.jsxs)(O.SU,{container:eC,children:[(0,n.jsxs)("div",{ref:ey,className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:eZ},children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>t4("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===eg?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:es("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>t4("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===eg?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:es("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>t4("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===eg?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:es("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>t4("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===eg?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:es("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>t4("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===eg?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:es("fileBrowser.historyTab")})]}),"tree"===eg&&(0,n.jsxs)("div",{className:"p-2 border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:ts.searchInputRef,type:"text",value:ts.searchQuery,onChange:e=>ts.setSearchQuery(e.target.value),placeholder:es("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),ts.searchQuery&&(0,n.jsx)("button",{onClick:()=>{ts.setSearchQuery(""),ts.searchInputRef.current?.focus()},className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:es("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:()=>ts.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${ts.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:ts.searchExactMatch?es("fileBrowser.exactMatchOn"):es("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>ts.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:es("fileBrowser.refreshTree"),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:"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:()=>ts.searchTreeExpandedPaths?ts.setSearchTreeExpandedPaths(new Set):ts.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:es("fileBrowser.collapseAll"),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:"M20 12H4"})})})]})]}),"search"===eg&&(0,n.jsxs)("div",{className:"p-2 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:ti.contentSearchInputRef,type:"text",value:ti.contentSearchQuery,onChange:e=>ti.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&ti.performContentSearch(ti.contentSearchQuery)},placeholder:es("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),ti.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>{ti.setContentSearchQuery(""),ti.contentSearchInputRef.current?.focus()},className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:es("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:()=>ti.performContentSearch(ti.contentSearchQuery),disabled:ti.isSearching||!ti.contentSearchQuery.trim(),className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",children:ti.isSearching?"...":es("common.search")})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-xs",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ti.searchOptions.caseSensitive,onChange:e=>ti.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:es("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ti.searchOptions.wholeWord,onChange:e=>ti.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:es("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:ti.searchOptions.regex,onChange:e=>ti.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:es("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:ti.searchOptions.fileType,onChange:e=>ti.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:es("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground"})]})]}),"history"===eg&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:tm.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground 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"})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:tm.branches?.current||"HEAD"}),(0,n.jsx)("div",{className:"flex flex-shrink-0 items-center rounded border border-border overflow-hidden text-xs",children:["head","worktree"].map(e=>(0,n.jsx)("button",{onClick:()=>tm.setCompareDiffMode(e),className:`px-1.5 py-0.5 transition-colors ${tm.compareDiffMode===e?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:es("head"===e?"fileBrowser.compareScopeHeadHint":"fileBrowser.compareScopeWorktreeHint"),children:es("head"===e?"fileBrowser.compareScopeHead":"fileBrowser.compareScopeWorktree")},e))})]}),(0,n.jsx)("button",{onClick:()=>tm.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:es("fileBrowser.compareModeOff"),children:es("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(tk,{branches:tm.branches,selectedBranch:tm.compareBaseBranch,onSelect:e=>{tm.setCompareBaseBranch(e),tm.loadCompareFiles(e)},isLoading:tm.isLoadingBranches,pinnedBranches:["origin/main",...tm.upstreamBranch&&"origin/main"!==tm.upstreamBranch?[tm.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(tk,{branches:tm.branches,selectedBranch:tm.selectedBranch,onSelect:e=>{tm.setSelectedBranch(e)},isLoading:tm.isLoadingBranches,pinnedBranches:["origin/main",...tm.upstreamBranch&&"origin/main"!==tm.upstreamBranch?[tm.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>tm.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-hover border border-border",title:es("fileBrowser.compareModeOn"),children:es("fileBrowser.compareMode")})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,n.jsxs)("div",{className:`flex-1 flex flex-col min-h-0 ${"tree"===eg?"":"hidden"}`,children:[ts.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:ts.creatingItem.parentPath?es("fileBrowser.createFileIn",{path:ts.creatingItem.parentPath}):es("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:es("fileBrowser.fileName"),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring",onCompositionStart:()=>{eN.current=!0},onCompositionEnd:()=>{eN.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(eN.current)return;let r=e.target.value.trim();if(!r)return;let n=ts.creatingItem.parentPath,s=n?`${n}/${r}`:r,o=await u.t4.runPromiseExit((0,v.OJ)({cwd:t,path:s,content:""}));if("Success"===o._tag&&o.value.ok)(0,T.oR)(es("toast.createdFile",{name:r}),"success"),ts.setCreatingItem(null),ts.loadDirectory(n),ts.loadFileIndex(),n&&ts.setExpandedPaths(e=>new Set([...e,n])),tD(s);else if("Success"===o._tag){let e=o.value.data?.error;(0,T.oR)(e||es("toast.createFailed"),"error")}else(0,T.oR)(es("toast.createFailed"),"error")}else"Escape"===e.key&&ts.setCreatingItem(null)},onBlur:()=>ts.setCreatingItem(null)})]}),ts.isLoadingFiles&&0===ts.files.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:es("common.loading")}):ts.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ts.fileError}):(0,n.jsx)(U,{files:ts.files,selectedPath:ts.selectedPath,expandedPaths:ts.effectiveExpandedPaths,matchedPaths:ts.matchedPaths,gitStatusMap:tX,loadingDirs:ts.loadingDirs,onSelect:e=>{ts.setShouldScrollToSelected(!1),tD(e)},onToggle:ts.handleToggle,cwd:t,shouldScrollToSelected:ts.shouldScrollToSelected,onScrolledToSelected:()=>ts.setShouldScrollToSelected(!1),onCreateFile:e=>ts.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>eL({path:e,isDirectory:t,name:r}),onRefresh:()=>ts.loadFiles(),onCopyFile:t8,onPaste:t9,onExplain:ei?ed:void 0,explainDisabled:ei?.isLoading})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===eg?"":"hidden"}`,children:ti.isSearching?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ti.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ti.searchError}):0===ti.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ti.contentSearchQuery?es("fileBrowser.noContentSearchResults"):es("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[ti.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground border-b border-border flex-shrink-0",children:[es("fileBrowser.nFilesNMatches",{files:ti.searchStats.totalFiles,matches:ti.searchStats.totalMatches}),ti.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",es("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(U,{files:tA.files,selectedPath:ts.selectedPath,expandedPaths:tH,onSelect:e=>{let t=tA.matchMap.get(e);tD(e,t?.matches[0]?.lineNumber),eA||eH(!0)},onToggle:tz,cwd:t,onExplain:ei?ed:void 0,explainDisabled:ei?.isLoading,renderActions:tO,className:"flex-1 overflow-y-auto py-1 min-w-max"})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"recent"===eg?"":"hidden"}`,children:0===ts.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:es("fileBrowser.noRecentFiles")}):(0,n.jsx)(U,{files:ts.recentFilesTree,selectedPath:ts.selectedPath,expandedPaths:ts.recentTreeDirPaths,onSelect:tD,onToggle:I.tE,cwd:t,onExplain:ei?ed:void 0,explainDisabled:ei?.isLoading})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===eg?"":"hidden"}`,children:td.statusLoading?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):td.statusError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center p-4",children:(0,n.jsx)("span",{className:"text-red-11 text-sm",children:td.statusError})}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:es("fileBrowser.stagingArea",{count:td.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>td.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:es("fileBrowser.refreshChanges"),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 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"})})})]}),(td.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:td.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:es("fileBrowser.unstageAll")})]}),(0,n.jsx)(M.VO,{files:td.stagedTree,selectedPath:td.statusSelectedFile?.type==="staged"?td.statusSelectedFile.file.path:null,expandedPaths:td.stagedExpandedPaths,onSelect:e=>e.file&&td.handleStatusFileSelect(e.file,"staged"),onToggle:td.handleStagedToggle,cwd:t,showChangeClass:!0,hideIndicatorsOnHover:!0,emptyMessage:es("fileBrowser.noStagedFiles"),className:"py-1",onExplain:ei?ec:void 0,explainDisabled:ei?.isLoading,renderActions:e=>{if(e.isDirectory){let t=(0,M.wI)(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),td.handleUnstageFiles(t.map(e=>e.path))},className:"hidden group-hover:block p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-colors",title:es("fileBrowser.unstageNFiles",{count:t.length}),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:"M20 12H4"})})})}return(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),td.handleUnstage(e.path)},className:"hidden group-hover:block p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-colors",title:es("fileBrowser.unstageFile"),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:"M20 12H4"})})})}})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:es("fileBrowser.workspace",{count:td.status?.unstaged.length||0})}),(td.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:td.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:es("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:td.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:es("fileBrowser.stageAll")})]})]}),(0,n.jsx)(M.VO,{files:td.unstagedTree,selectedPath:td.statusSelectedFile?.type==="unstaged"?td.statusSelectedFile.file.path:null,expandedPaths:td.unstagedExpandedPaths,onSelect:e=>e.file&&td.handleStatusFileSelect(e.file,"unstaged"),onToggle:td.handleUnstagedToggle,cwd:t,showChangeClass:!0,hideIndicatorsOnHover:!0,emptyMessage:es("fileBrowser.noUnstagedChanges"),className:"py-1",onExplain:ei?eu:void 0,explainDisabled:ei?.isLoading,renderActions:e=>{if(e.isDirectory){let t=(0,M.wI)(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"hidden group-hover:flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),td.handleDiscardFiles(r)},className:"p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-colors",title:es("fileBrowser.discardNFiles",{count:t.length}),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 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),td.handleStageFiles(t.map(e=>e.path))},className:"p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-colors",title:es("fileBrowser.stageNFiles",{count:t.length}),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"})})})]})}return e.file?(0,n.jsxs)("div",{className:"hidden group-hover:flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),td.handleDiscardFile(e.file)},className:"p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-colors",title:es("fileBrowser.discardChanges"),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 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),td.handleStage(e.path)},className:"p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-colors",title:es("fileBrowser.stageFile"),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"})})})]}):null}})]})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"history"===eg?"":"hidden"}`,children:tm.historyError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,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)("p",{className:"text-muted-foreground",children:tm.historyError})]})}):tm.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:tm.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:es("fileBrowser.loadingDiff")}):0===tm.compareFiles.length?(0,n.jsxs)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:[(0,n.jsx)("div",{children:es("fileBrowser.noDiffFiles")}),"head"===tm.compareDiffMode&&(0,n.jsx)("button",{onClick:()=>tm.setCompareDiffMode("worktree"),className:"mt-2 text-xs text-brand hover:underline",children:es("fileBrowser.noDiffFilesHeadHint")})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",children:es("worktree"===tm.compareDiffMode?"fileBrowser.nFilesChangedWorktree":"fileBrowser.nFilesChanged",{count:tm.compareFiles.length,branch:tm.compareBaseBranch})}),(0,n.jsxs)("span",{className:"flex flex-shrink-0 items-center gap-1.5 text-xs tabular-nums",children:[(0,n.jsxs)("span",{className:"text-green-11",children:["+",tj.additions]}),(0,n.jsxs)("span",{className:"text-red-11",children:["-",tj.deletions]})]})]}),(0,n.jsx)(M.VO,{files:tm.compareFileTree,expandedPaths:tm.compareExpandedPaths,onToggle:tm.handleCompareToggle,selectedPath:tm.compareSelectedFile?.path||null,onSelect:e=>{e.file&&tm.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0,showChangeClass:!0,onExplain:ei?ty:void 0,explainDisabled:ei?.isLoading})]})}):(0,n.jsx)("div",{ref:tm.commitListRef,className:"flex-1 overflow-y-auto",onScroll:tm.handleCommitListScroll,children:tm.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:es("fileBrowser.loadingCommits")}):0===tm.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:es("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[tm.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>tm.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-hover ${tm.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[e.changeClass&&(0,n.jsx)(g.N,{cls:e.changeClass}),(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-foreground-subtle","data-tooltip":e.date,children:[e.relativeDate," \xb7 ",(0,I.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),tm.isLoadingMore&&(0,n.jsx)("div",{className:"p-3 text-center",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),!tm.hasMoreCommits&&tm.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-foreground-subtle",children:es("fileBrowser.allLoaded",{count:tm.commits.length})})]})})})]})]}),(0,n.jsx)("div",{onPointerDown:e1,onPointerMove:e2,onPointerUp:e5,onPointerCancel:e5,className:"w-[5px] flex-shrink-0 relative cursor-col-resize group",children:(0,n.jsx)("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border group-hover:bg-brand transition-colors"})}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[("tree"===eg||"search"===eg||"recent"===eg)&&(ts.blameSelectedCommit?(0,n.jsx)(W,{isOpen:!0,onClose:()=>ts.setBlameSelectedCommit(null),commit:ts.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:ts.selectedPath||void 0,onLocateInTree:rl,onContentSearch:e=>{eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)}}):"map"===ew?t5&&t2.diff?(0,n.jsx)(tg,{cwd:t,filePath:t2.diff.filePath,oldContent:t2.diff.oldContent,newContent:t2.diff.newContent,isNew:t2.diff.isNew,isDeleted:t2.diff.isDeleted,changedFiles:tc,fileGitStatusMap:tu,compact:"compact"===eQ,enableComments:!0,onSwitchToCode:()=>ek("code"),onContentSearch:t1,headerExtraLeft:rm,headerExtraRight:rx}):(0,n.jsx)(e6,{cwd:t,highlightedFilePath:ts.selectedPath,changedFiles:tc,onSwitchToCode:()=>ek("code"),enableComments:!0,onContentSearch:t1,headerExtraLeft:rm,headerExtraRight:rx}):ts.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 border-b border-border flex-shrink-0 flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:ts.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${ts.selectedPath}`),(0,T.oR)(es("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:es("common.copyAbsPath"),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)("button",{onClick:e=>{e.stopPropagation(),rl(ts.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:es("fileBrowser.locateInTree"),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",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:ts.showEditor?(0,n.jsxs)(n.Fragment,{children:[eB.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:es("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>eF.current?.save(),disabled:!eB.isDirty||eB.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eB.isDirty&&!eB.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:eB.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):es("common.save")}),(0,n.jsx)("button",{onClick:()=>eF.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:es("fileBrowser.closeEdit"),children:es("fileBrowser.closeBtn")})]}):t5?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(C.y,{value:eQ,onChange:eG}),(0,n.jsx)(S.q,{value:eJ,onChange:eY}),!(0,F.e$)(ts.selectedPath)&&!(0,F.aR)(ts.selectedPath)&&!(0,F.Hz)(ts.selectedPath)&&!(0,F.Zy)(ts.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ek("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:es("blockViewer.viewerToggle.toBlock"),children:es("common.codeMap")}),(0,n.jsx)("button",{onClick:t2.toggleDiff,className:"px-1.5 py-0.5 text-xs rounded transition-colors bg-brand text-white",children:es("fileBrowser.exitDiff")})]}):(0,n.jsxs)(n.Fragment,{children:["tree"===eg&&t2.canDiff&&(0,n.jsx)("button",{onClick:t2.toggleDiff,className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:es("fileBrowser.viewDiff"),children:es("common.diff")}),ts.fileContent?.type==="text"&&(0,F.e$)(ts.selectedPath)&&(0,n.jsx)(en.ShareReviewToggle,{content:ts.fileContent.content||"",sourceFile:ts.selectedPath&&t&&ts.selectedPath.startsWith(t)?ts.selectedPath.slice(t.endsWith("/")?t.length:t.length+1):ts.selectedPath||""}),ts.fileContent?.type==="text"&&(0,F.Hz)(ts.selectedPath)&&ts.previewMarkdown&&!ts.showBlame&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:[!0,!1].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),tl(t=>({version:t.version+1,collapsed:e}))},className:`px-2 py-0.5 text-xs transition-colors ${ta.collapsed===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:es(e?"fileBrowser.collapseAllJson":"fileBrowser.expandAllJson")},String(e)))}),ts.fileContent?.type==="text"&&((0,F.e$)(ts.selectedPath)||(0,F.aR)(ts.selectedPath)||(0,F.Hz)(ts.selectedPath)||(0,F.Zy)(ts.selectedPath))&&($=(E=(0,F.aR)(ts.selectedPath))?ts.previewHtml:ts.previewMarkdown,(0,n.jsx)("button",{onClick:()=>E?ts.setPreviewHtml(e=>!e):ts.setPreviewMarkdown(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${$?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:$?es("fileBrowser.exitPreview"):es("common.preview")})),ts.fileContent?.type==="text"&&((0,F.C_)(ts.selectedPath||"")||(0,F.OG)(ts.selectedPath||""))&&(z=(H=ts.selectedPath||"").startsWith("/")?H:t?`${t.replace(/\/$/,"")}/${H}`:H,_=(0,F.OG)(H),(0,n.jsx)("button",{onClick:()=>void(_?eh(z):ex(z)),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:es(_?"bots.addTooltip":"skills.addTooltip"),children:(0,n.jsx)(G.A,{className:"w-3.5 h-3.5"})})),ts.fileContent?.type==="text"&&(0,F.aR)(ts.selectedPath)&&(V=(q=ts.selectedPath||"").startsWith("/")?q:t?`${t.replace(/\/$/,"")}/${q}`:q,(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>em(V),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:es("htmlApps.addTooltip"),children:(0,n.jsx)(G.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:V}})),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:es("common.openInConsole"),children:(0,n.jsx)(J.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>{let e=(0,Z.Xe)(V);window.open((0,Z.PB)(e,window.location.origin),"_blank")},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:es("browser.openInNewWindow"),children:(0,n.jsx)(Y.A,{className:"w-3.5 h-3.5"})})]})),ts.fileContent?.type==="text"&&!(ts.previewMarkdown&&((0,F.e$)(ts.selectedPath)||(0,F.Hz)(ts.selectedPath)||(0,F.Zy)(ts.selectedPath))||ts.previewHtml&&(0,F.aR)(ts.selectedPath))&&(0,n.jsx)("button",{onClick:ts.handleToggleBlame,disabled:ts.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ts.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-hover"} disabled:opacity-50`,title:es("fileBrowser.viewBlame"),children:ts.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),ts.fileContent?.type==="text"&&!(ts.previewMarkdown&&((0,F.e$)(ts.selectedPath)||(0,F.Hz)(ts.selectedPath)||(0,F.Zy)(ts.selectedPath))||ts.previewHtml&&(0,F.aR)(ts.selectedPath))&&(0,n.jsx)("button",{onClick:()=>ts.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:es("fileBrowser.editFile"),children:es("common.edit")}),ts.fileContent?.type==="text"&&ts.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(ts.fileContent.content),(0,T.oR)(es("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:es("fileBrowser.copyFileContent"),children:es("common.copy")}),ts.fileContent?.type==="text"&&!(0,F.e$)(ts.selectedPath)&&!(0,F.aR)(ts.selectedPath)&&!(0,F.Hz)(ts.selectedPath)&&!(0,F.Zy)(ts.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ek("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:es("blockViewer.viewerToggle.toBlock"),children:es("common.codeMap")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:ts.isLoadingContent?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ts.fileContent?"text"===ts.fileContent.type&&"string"==typeof ts.fileContent.content?t5?t2.isLoadingDiff&&!t2.diff?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):t2.diff?"unified"===eJ?(0,n.jsx)(k.xU,{oldContent:t2.diff.oldContent,newContent:t2.diff.newContent,filePath:t2.diff.filePath,cwd:t,enableComments:!0,compact:"compact"===eQ,onContentSearch:t1,onTokenHover:(e,t,r)=>tJ(t2.diff?.filePath,!0,e,t,r),onTokenHoverLeave:te.onTokenMouseLeave,onTokenHoverCancel:te.clearHover}):(0,n.jsx)(k.xZ,{oldContent:t2.diff.oldContent,newContent:t2.diff.newContent,filePath:t2.diff.filePath,isNew:t2.diff.isNew,isDeleted:t2.diff.isDeleted,cwd:t,enableComments:!0,compact:"compact"===eQ,onContentSearch:t1,onTokenHover:(e,t,r)=>tJ(t2.diff?.filePath,!0,e,t,r),onTokenHoverLeave:te.onTokenMouseLeave,onTokenHoverCancel:te.clearHover}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{children:es("fileBrowser.diffLoadFailed")}),(0,n.jsx)("button",{onClick:t2.toggleDiff,className:"mt-2 text-brand hover:underline text-sm",children:es("fileBrowser.exitDiff")})]})}):ts.showBlame&&ts.blameError?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-red-11",children:ts.blameError}),(0,n.jsx)("button",{onClick:()=>ts.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:es("fileBrowser.backToPreview")})]})}):ts.showBlame&&0===ts.blameLines.length&&ts.isLoadingBlame?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ts.previewMarkdown&&(0,F.Hz)(ts.selectedPath)&&!ts.showBlame?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-background text-foreground",children:[(0,n.jsx)(B._,{search:e3}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:e4,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,n.jsx)(F.d9.Provider,{value:ta,children:to})})})]}):ts.previewMarkdown&&(0,F.Zy)(ts.selectedPath)&&!ts.showBlame?(0,n.jsx)(Q.C0,{content:ts.fileContent.content,filePath:ts.selectedPath,className:"h-full"}):ts.previewMarkdown&&(0,F.e$)(ts.selectedPath)&&!ts.showBlame?(0,n.jsx)("div",{className:"h-full flex flex-col",children:(0,n.jsx)(N.M,{content:ts.fileContent.content,filePath:ts.selectedPath,cwd:t,embedded:!0,onLocalMdLink:rp,scrollToAnchor:rh})}):ts.previewHtml&&(0,F.aR)(ts.selectedPath)&&!ts.showBlame?(0,n.jsx)(er.O,{content:ts.fileContent.content,filePath:ts.selectedPath,cwd:t,onContentSearch:e=>{eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)}}):(0,n.jsx)(K.Cv,{ref:eF,content:ts.fileContent.content,filePath:ts.selectedPath,cwd:t,enableComments:!0,scrollToLine:eR??ts.targetLineNumber,scrollToLineAlign:null!=eR?"start":ts.targetScrollAlign,onScrollToLineComplete:()=>{eI(null),ts.setTargetLineNumber(null)},highlightKeyword:"search"===eg?ti.contentSearchQuery:null,visibleLineRef:e$,viStateRef:eT,initialCursorLine:ts.initialCursorLine,initialCursorCol:ts.initialCursorCol,onInitialCursorSet:()=>{ts.setInitialCursorLine(null),ts.setInitialCursorCol(null)},onCmdClick:tU?tG:void 0,onTokenHover:tU?tY:void 0,onTokenHoverLeave:tU?te.onTokenMouseLeave:void 0,onTokenHoverCancel:tU?te.clearHover:void 0,blameLines:ts.showBlame&&ts.blameLines.length>0?ts.blameLines:void 0,inlineBlameLines:ts.blameLines.length>0?ts.blameLines:void 0,onSelectCommit:ts.setBlameSelectedCommit,editable:ts.showEditor,initialMtime:ts.fileContent.mtime,onEditorClose:e=>{ts.setShowEditor(!1),eI(e)},onSaved:()=>{let e=e$.current??1;ts.loadFileContent(ts.selectedPath),ts.setShowEditor(!1),eI(e)},onEditorStateChange:eD,viMode:!0,onContentMutate:tS,onEnterInsertMode:tP,onViSave:t$,onContentSearch:e=>{eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)}}):"image"===ts.fileContent.type&&ts.selectedPath?(0,n.jsx)(tv.I,{cwd:t,path:ts.selectedPath,refreshKey:ts.fileContent.mtime,alt:ts.selectedPath}):"pdf"===ts.fileContent.type&&ts.selectedPath?(0,n.jsx)(tN,{cwd:t,path:ts.selectedPath,refreshKey:ts.fileContent.mtime}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,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)("p",{children:ts.fileContent.message||es("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:es("fileBrowser.selectFileToPreview")})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,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)("p",{children:es("fileBrowser.selectFileToPreview")})]})})),"status"===eg&&(td.statusSelectedFile&&td.statusDiff?(0,n.jsx)(tw,{cwd:t,selected:td.statusSelectedFile,diff:td.statusDiff,showMarkdownPreview:td.showStatusDiffPreview,setShowMarkdownPreview:td.setShowStatusDiffPreview,changedFiles:tc,fileGitStatusMap:tu,onContentSearch:e=>{eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)},locateInTree:rl,setJsonPreview:ez,onTokenHover:(e,t,r)=>tJ(td.statusDiff?.filePath,!0,e,t,r),onTokenHoverLeave:te.onTokenMouseLeave,onTokenHoverCancel:te.clearHover}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:es("fileBrowser.selectFileToViewDiff")})})),"history"===eg&&!tm.historyError&&(tm.compareMode?tm.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:es("fileBrowser.loadingDiffContent")}):tm.compareFileDiff?(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border flex-shrink-0",children:[(0,n.jsx)(R,{cwd:t,filePath:tm.compareFileDiff.filePath,onLocateInTree:rl}),!(0,I.u)(tm.compareFileDiff.filePath)&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,n.jsx)(C.y,{value:eq,onChange:eV}),(0,n.jsx)(S.q,{value:eU,onChange:eK})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,I.u)(tm.compareFileDiff.filePath)?(0,n.jsx)(P,{cwd:t,filePath:tm.compareFileDiff.filePath,oldRev:tm.compareFileDiff.oldRev??(tm.compareFileDiff.isNew?null:tm.compareBaseBranch),newRev:"worktree"===tm.compareDiffMode?null:tm.compareFileDiff.newRev??(tm.compareFileDiff.isDeleted?null:"HEAD"),newNode:tm.compareFileDiff.newWorktree?(0,n.jsx)(tv.I,{cwd:t,path:tm.compareFileDiff.filePath}):void 0}):"unified"===eU?(0,n.jsx)(k.xU,{oldContent:tm.compareFileDiff.oldContent,newContent:tm.compareFileDiff.newContent,filePath:tm.compareFileDiff.filePath,cwd:t,enableComments:!0,compact:"compact"===eq,onPreview:tf,previewLabel:th.endsWith(".json")?es("common.readable"):es("common.preview"),onContentSearch:e=>{eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)}}):(0,n.jsx)(k.xZ,{oldContent:tm.compareFileDiff.oldContent,newContent:tm.compareFileDiff.newContent,filePath:tm.compareFileDiff.filePath,isNew:tm.compareFileDiff.isNew,isDeleted:tm.compareFileDiff.isDeleted,cwd:t,enableComments:!0,compact:"compact"===eq,onPreview:tf,previewLabel:th.endsWith(".json")?es("common.readable"):es("common.preview"),onContentSearch:e=>{eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)}})}),eO&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:()=>e_(null),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(N.M,{content:eO.content,filePath:eO.filePath,cwd:t,onClose:tp})})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:tm.compareFiles.length>0?es("fileBrowser.selectFileToViewDiff"):es("fileBrowser.clickCompareToLoad")})}):tm.selectedCommit?(0,n.jsx)(W,{isOpen:!0,onClose:()=>tm.setSelectedCommit(null),commit:tm.selectedCommit,cwd:t,embedded:!0,onLocateInTree:rl,onContentSearch:e=>{eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:es("fileBrowser.selectCommitToView")})})),eW&&(0,n.jsx)(D,{preview:eW,onClose:tb,search:e9,preRef:e8})]})]}),eE&&(0,n.jsx)(eo,{files:ts.files,fileIndex:ts.fileIndex,recentFiles:ts.recentFilePaths,onSelectFile:e=>{tD(e),ts.setShouldScrollToSelected(!0),eb("tree")},onClose:()=>eP(!1)}),(t_||tt.visible)&&(0,n.jsxs)("div",{className:`flex ${tt.visible&&t_?"":"flex-col"}`,children:[t_&&(0,n.jsx)("div",{className:tt.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tI,{results:ti.contentSearchResults,loading:ti.isSearching,totalMatches:ti.searchStats?.totalMatches??0,onSelect:(e,t)=>{ts.selectedPath&&tr.push({filePath:ts.selectedPath,lineNumber:e$.current}),ek("code"),tD(e,t)},onClose:()=>eH(!1),scope:tq,onScopeChange:tV,selectedPath:ts.selectedPath})}),tt.visible&&(0,n.jsx)("div",{className:t_?"flex-1 min-w-0":"",children:(0,n.jsx)(tR,{references:tt.references,loading:tt.loading,onSelect:tZ,onClose:tt.closeReferences})})]})]}),eM&&(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim",onClick:()=>eL(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-lv3 p-4 max-w-sm w-full mx-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-2",children:es("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:es("fileBrowser.confirmDeleteMessage",{name:eM.name}).split(/<\/?file>/g).map((e,t)=>1===t?(0,n.jsx)("span",{className:"font-mono text-foreground",children:e},t):e)}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>eL(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-hover transition-colors",children:es("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=eM;eL(null);let n=await u.t4.runPromiseExit((0,v.VK)({cwd:t,path:e}));if("Success"===n._tag){(0,T.oR)(es("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";ts.loadDirectory(t),ts.loadFileIndex(),ts.selectedPath===e&&tD("")}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:es("toast.deleteFailed");(0,T.oR)(r,"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:es("common.delete")})]})]})})}),te.hoverInfo&&eC&&(0,p.createPortal)((0,n.jsx)(tT,{ref:te.setTooltipEl,displayString:te.hoverInfo.displayString,documentation:te.hoverInfo.documentation,x:te.hoverInfo.x,y:te.hoverInfo.y,container:eC,onMouseEnter:te.onCardMouseEnter,onMouseLeave:te.onCardMouseLeave,onFindReferences:tK?void 0:()=>{let{filePath:e,line:t,column:r}=te.hoverInfo;te.clearHover(),tt.findReferences(e,t,r)},onSearch:e=>{te.clearHover(),eb("search"),ti.setContentSearchQuery(e),ti.performContentSearch(e)},onExplain:ei?e=>{let{filePath:t,line:r}=te.hoverInfo;te.clearHover(),ei.sendMessage(es("explain.symbolMessage",{name:e,path:t,lines:String(r)}))}:void 0,explainDisabled:ei?.isLoading}),eC)]})});function tD({isOpen:e,onClose:t,cwd:r}){let a,{t:l}=(0,o.Bd)(),[i,m]=(0,s.useState)([]),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(""),[L,E]=(0,s.useState)(!1),[P,$]=(0,s.useState)([]),[R,F]=(0,s.useState)(""),[B,D]=(0,s.useState)(!1),A=(0,s.useCallback)((e,t)=>e?._tag==="Fail"&&e.error?.cause instanceof Error?e.error.cause.message:l(t),[l]),H=(0,s.useCallback)(async()=>{b(!0);let e=await u.t4.runPromiseExit((0,w.FK)(r));if("Success"===e._tag){let t=e.value;m(t.worktrees),h(t.nextPath),p(t.nextRandomWord),t.gitUserName&&M(t.gitUserName)}else console.error("Failed to load worktrees:",e.cause),(0,T.oR)(l("toast.worktreeLoadFailed"),"error");b(!1)},[r,l]),W=(0,s.useCallback)(e=>{let{local:t,remote:r}=e;return r.includes("origin/main")?"origin/main":r.includes("origin/master")?"origin/master":t.includes("main")?"main":t.includes("master")?"master":r.length>0?r[0]:t.length>0?t[0]:"main"},[]);(0,s.useEffect)(()=>{e&&(H(),y(null))},[e,H]);let z=async()=>{if(!x)return;let e="origin/main",t=await u.t4.runPromiseExit((0,w.r4)(r));"Success"===t._tag&&(e=W(t.value));let n=f||function(){let e="bcdfghjklmnprstvwz",t=["a","e","i","o","u","ai","au","ea","ee","ia","io","oa","oo","ou","ui"],r="";for(let n=0;n<2;n++)r+=e[Math.floor(Math.random()*e.length)],r+=t[Math.floor(Math.random()*t.length)];return r}(),s=S?`${S}/${n}`:n;j(!0);let o=await u.t4.runPromiseExit((0,w.CM)({action:"add",cwd:r,path:x,newBranch:s,baseBranch:e}));"Success"===o._tag?((0,T.oR)(l("toast.worktreeCreateSuccess",{name:s}),"success"),H()):(console.error("Failed to create worktree:",o.cause),(0,T.oR)(A(o.cause,"toast.worktreeCreateFailed"),"error")),j(!1)},O=async()=>{D(!0),F(""),E(!0);let e=await u.t4.runPromiseExit((0,w.r4)(r));if("Success"===e._tag){let t=e.value,r=t.local??[],n=t.remote??[],s=new Set(i.map(e=>e.branch).filter(Boolean));$([...r.filter(e=>!s.has(e)),...n.filter(e=>!s.has(e)&&!r.includes(e.replace(/^origin\//,"")))])}else(0,T.oR)(l("toast.loadBranchFailed"),"error");D(!1)},_=async e=>{if(!x)return;E(!1),j(!0);let t=await u.t4.runPromiseExit((0,w.CM)({action:"add",cwd:r,path:x,branch:e}));"Success"===t._tag?((0,T.oR)(l("toast.worktreeCreateSuccess",{name:e}),"success"),H()):(console.error("Failed to create worktree:",t.cause),(0,T.oR)(A(t.cause,"toast.worktreeCreateFailed"),"error")),j(!1)},q=async()=>{if(!k)return;C(!0);let e=await u.t4.runPromiseExit((0,w.CM)({action:"remove",cwd:r,path:k.path}));"Success"===e._tag?((0,T.oR)(l("toast.worktreeDeleted"),"success"),y(null),H()):(console.error("Failed to delete worktree:",e.cause),(0,T.oR)(A(e.cause,"toast.worktreeDeleteFailed"),"error")),C(!1)},V=async e=>{let t=e.isLocked?"unlock":"lock",n=await u.t4.runPromiseExit((0,w.CM)({action:t,cwd:r,path:e.path}));"Success"===n._tag?((0,T.oR)(e.isLocked?l("toast.worktreeUnlocked"):l("toast.worktreeLocked"),"success"),H()):(console.error("Failed to toggle lock:",n.cause),(0,T.oR)(A(n.cause,"toast.operationFailed"),"error"))};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-[480px] max-h-[80vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:"Git Worktrees"}),(0,n.jsx)("button",{onClick:t,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:l("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"})})})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:g?(0,n.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):(0,n.jsx)("div",{className:"space-y-2",children:i.map(e=>{let s,o=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${o?"border-brand bg-brand/5":"border-border hover:bg-hover cursor-pointer"}`,onClick:()=>{e.path!==r&&((0,d.F)(c.n.OpenProject,{cwd:e.path}),t())},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${o?"bg-brand":"bg-muted-foreground/30"}`}),(0,n.jsx)("span",{className:"font-medium text-foreground truncate",children:e.branch||(e.isDetached?"detached":"unknown")}),e.isLocked&&(0,n.jsx)("span",{className:"text-amber-11",title:l("git.worktree.locked"),children:"\uD83D\uDD12"}),o&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",l("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),V(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?l("git.worktree.unlock"):l("git.worktree.lock"),children:e.isLocked?(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 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"})}):(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 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",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"})})})]})})]}),(0,n.jsxs)("div",{className:"mt-1 flex items-center justify-between gap-2 pl-4",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:e.path}),null!=e.createdAt&&(s=(0,I.fw)(e.createdAt/1e3),(0,n.jsx)("span",{className:`text-xs flex-shrink-0 ${"just now"===s?"text-brand":"text-muted-foreground/70"}`,"data-tooltip":new Date(e.createdAt).toLocaleString(),children:s}))]}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),L&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-3 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("input",{value:R,onChange:e=>F(e.target.value),placeholder:l("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>E(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:l("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:B?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("common.loading")}):0===(a=P.filter(e=>e.toLowerCase().includes(R.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("git.worktree.noBranches")}):a.map(e=>(0,n.jsx)("button",{onClick:()=>_(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-hover transition-colors truncate",children:(0,n.jsx)("span",{className:`${e.startsWith("origin/")?"text-muted-foreground":"text-foreground"}`,children:e})},e))})]}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:l("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:O,disabled:!x||v,className:`px-3 py-1.5 text-sm rounded transition-colors ${x&&!v?"bg-secondary text-foreground hover:bg-hover":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:l("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:z,disabled:!x||v,className:`px-3 py-1.5 text-sm rounded transition-colors ${x&&!v?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:v?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):l("git.worktree.addWorktree")})]})]}),k&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-scrim rounded-lg",onClick:()=>y(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:l("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:l("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:l("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:k.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:l("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:k.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>y(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:q,disabled:N,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:N?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):l("common.delete")})]})]})})]})}):null}var tA=r(67635),tH=r(73300),tW=r(20986),tz=r(9921),tO=r(66088),t_=r(42790);function tq(e){let t=function(e){let t=0xffffffff;for(let r=0;r<e.length;r++){t^=e.charCodeAt(r);for(let e=0;e<8;e++)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}(e),r="",n=t;for(let e=0;e<4;e++)r+=String.fromCharCode(97+n%26),n=Math.floor(n/26);return r}function tV({open:e,anchorRef:t,initialValue:r,onCancel:a,onSave:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(r),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(null),f=(0,s.useRef)(null),g=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(e){c(r),m(!1);let e=requestAnimationFrame(()=>{f.current?.focus(),f.current?.select()});return()=>cancelAnimationFrame(e)}h(null)},[e,r]);let b=(0,s.useCallback)(()=>{let e=t.current;if(!e)return;let r=e.getBoundingClientRect(),n=g.current?.offsetHeight??0,s=r.bottom+4;if(n&&s+n>window.innerHeight-8){let e=r.top-4-n;e>=8&&(s=e)}let o=r.left;h({top:s,left:o=Math.max(o=Math.min(o,window.innerWidth-260-8),8)})},[t]);if((0,s.useLayoutEffect)(()=>{if(e)return b(),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0),()=>{window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}},[e,b]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&(e.preventDefault(),a())},n=e=>{let r=e.target;g.current?.contains(r)||t.current?.contains(r)||a()};return window.addEventListener("keydown",r),document.addEventListener("mousedown",n,!0),()=>{window.removeEventListener("keydown",r),document.removeEventListener("mousedown",n,!0)}},[e,a,t]),!e||"u"<typeof document)return null;let v=async()=>{if(!u){m(!0);try{await l(d.trim())}finally{m(!1)}}};return(0,p.createPortal)((0,n.jsxs)("div",{ref:g,style:{top:x?.top??0,left:x?.left??0,width:260,visibility:x?"visible":"hidden"},className:"fixed z-[100] rounded-lg border border-border bg-card p-3 shadow-lv3",children:[(0,n.jsx)("div",{className:"mb-2 text-sm font-medium text-foreground",children:i("shortIdBadge.dialogTitle")}),(0,n.jsx)("input",{ref:f,type:"text",value:d,onChange:e=>c(e.target.value.slice(0,64)),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||229===e.keyCode||(e.preventDefault(),v())},placeholder:i("shortIdBadge.dialogPlaceholder"),maxLength:64,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-sm font-mono outline-none focus:border-brand"}),(0,n.jsxs)("div",{className:"mt-3 flex justify-end gap-2 text-sm",children:[(0,n.jsx)("button",{onClick:a,className:"rounded px-3 py-1 text-muted-foreground hover:bg-hover",disabled:u,children:i("common.cancel")}),(0,n.jsx)("button",{onClick:()=>void v(),className:"rounded bg-brand px-3 py-1 text-white hover:opacity-90 disabled:opacity-50",disabled:u,children:u?"…":i("common.save")})]})]}),document.body)}var tU=r(94720);let tK=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:a,fullId:l,projectCwd:i,tabId:d,registered:c}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(!1),f=c??x,[p,g]=(0,s.useState)(""),[b,v]=(0,s.useState)(!1),j=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!l||!i||!d)return;let e=!1;return u.t4.runPromiseExit((0,tU.MR)(i,d)).then(t=>{if(e||"Success"!==t._tag)return;let r=t.value[l];"string"==typeof r&&g(r)}),()=>{e=!0}},[l,i,d]),(0,ea.h)({url:"/ws/global-state",enabled:!!l&&!!i&&!!d,onMessage:e=>{"console-delta"!==e.type||"rename"!==e.op||e.cwd!==i||e.tabId!==d||e.titles&&l&&Object.prototype.hasOwnProperty.call(e.titles,l)&&g(e.titles[l]??"")}});let w=(0,s.useCallback)(async n=>{if(n.stopPropagation(),f)await a(),h(!1),(0,T.oR)(m("toast.disconnected",{id:e}));else{await r(),h(!0);let n=`${"3456"===window.location.port?"cockpit-dev":"cockpit"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,T.oR)(m("toast.copiedCommand",{command:n}))}},[f,e,t,r,a,m]),k=!!(l&&i&&d),y=(0,s.useCallback)(e=>{e.stopPropagation(),k&&v(!0)},[k]),N=(0,s.useCallback)(async e=>{l&&i&&d&&("Success"===(await u.t4.runPromiseExit((0,tU.y8)(i,d,l,e)))._tag&&g(e),v(!1))},[l,i,d]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:w,onDoubleClick:e=>e.stopPropagation(),className:"inline-flex items-center gap-1 text-[10px] font-mono leading-none px-1.5 py-0.5 rounded flex-shrink-0 transition-colors bg-muted/60 hover:bg-muted text-muted-foreground",title:f?m("shortIdBadge.clickToDisconnect"):m("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${f?"bg-green-500":"bg-muted-foreground/40"}`}),e]}),k&&(p?(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[10px] leading-none flex-shrink-0 text-muted-foreground",title:m("shortIdBadge.titleSet",{title:p})||p,children:[(0,n.jsx)("span",{className:"px-1 py-0.5 rounded bg-muted/40 max-w-[120px] truncate",children:p}),(0,n.jsx)("button",{ref:j,onClick:y,className:"opacity-50 hover:opacity-100 transition-opacity","aria-label":m("shortIdBadge.editTitle"),title:m("shortIdBadge.editTitle"),children:"✎"})]}):(0,n.jsxs)("button",{ref:j,onClick:y,className:"inline-flex items-center gap-0.5 text-[10px] leading-none flex-shrink-0 text-muted-foreground/50 hover:text-muted-foreground italic transition-colors",title:m("shortIdBadge.setTitle"),children:["(",m("shortIdBadge.setTitlePlaceholder"),") ✎"]})),(0,n.jsx)(tV,{open:b,anchorRef:j,initialValue:p,onCancel:()=>v(!1),onSave:N})]})});var tQ=r(12786);let tG=(0,s.lazy)(()=>Promise.all([r.e(23888),r.e(71959)]).then(r.bind(r,71959)).then(e=>({default:e.XtermRenderer}))),tJ={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},tY=/\x1b\[[0-9;]*m/g;function tZ({output:e,query:t,mode:r,currentIdx:o,matchListRef:a}){let l=(0,s.useRef)(null);l.current||(l.current=new t_.v,l.current.use_classes=!0);let i=e.split("\n"),d=t.toLowerCase(),c=0;return a.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(tY,""),i=s.toLowerCase().includes(d);if("filter"===r&&!i)return null;if(!i){let r=l.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],m=0,x=s.toLowerCase(),h=0;for(;h<x.length;){let e=x.indexOf(d,h);if(-1===e)break;e>m&&u.push((0,n.jsx)("span",{children:s.slice(m,e)},`t${m}`));let t=c++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{a.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+d.length)},`m${e}`)),h=m=e+d.length}return m<s.length&&u.push((0,n.jsx)("span",{children:s.slice(m)},`t${m}`)),(0,n.jsx)("div",{children:u},t)})})}let tX=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:a,output:l,exitCode:i,isRunning:d,selected:c,onSelect:m,onInterrupt:x,onStdin:h,onDelete:f,onRerun:p,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,subscribePtyRefresh:w,onPtyResize:k,onToggleMaximize:y,maximized:N,expandedHeight:C,bubbleContentHeight:S,onTitleMouseDown:M}){let{t:L}=(0,o.Bd)(),E=(0,s.useRef)(null),P=(0,s.useRef)(null),$=(0,s.useRef)(!0),R=(0,s.useRef)(null),I=(0,s.useRef)(null),F=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(g),B=e&&t?tq(t+e):void 0,[D,A]=(0,s.useState)(!1),[H,W]=(0,s.useState)(""),z=(0,s.useRef)(null),O=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>z.current?v(e,z.current.write):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[v,e]),(0,s.useEffect)(()=>{if(!j||!e)return;let t=()=>z.current?j(e,z.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]),(0,s.useEffect)(()=>{if(!w||!e)return;let t=()=>z.current?w(e,z.current.refresh):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[w,e]);let[_,q]=(0,s.useState)(!1),[V,U]=(0,s.useState)(""),[K,Q]=(0,s.useState)("search"),[G,J]=(0,s.useState)(0),Y=(0,s.useRef)([]),Z=(0,s.useRef)(null),X=(0,s.useRef)(0);(0,s.useEffect)(()=>{Z.current||(Z.current=new t_.v,Z.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=P.current;if(e&&Z.current){if(l.length<X.current&&(Z.current=new t_.v,Z.current.use_classes=!0,X.current=0,e.innerHTML=""),l.length>X.current){let t=l.slice(X.current),r=Z.current.ansi_to_html(t);X.current=l.length,e.insertAdjacentHTML("beforeend",r)}if(E.current){let e=E.current.scrollHeight>E.current.clientHeight;A(e),e&&(E.current.scrollTop=E.current.scrollHeight)}}},[l]),(0,s.useEffect)(()=>(d&&$.current&&E.current&&(null!==R.current&&cancelAnimationFrame(R.current),R.current=requestAnimationFrame(()=>{E.current&&(E.current.scrollTop=E.current.scrollHeight),R.current=null})),()=>{null!==R.current&&cancelAnimationFrame(R.current)}),[l,d]),(0,s.useEffect)(()=>{if(!N)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),y?.())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[N,y]);let ee=l?l.split("\n").length:0,et=(0,s.useCallback)(()=>{q(!0),requestAnimationFrame(()=>O.current?.focus())},[]),er=(0,s.useCallback)(()=>{q(!1),U(""),J(0),z.current?.clearSearch()},[]),en=(0,s.useCallback)(e=>{e.trim()&&(b?z.current?.findNext(e):J(e=>{let t=e+1,r=Y.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(Y.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),es=(0,s.useCallback)(e=>{e.trim()&&(b?z.current?.findPrevious(e):J(e=>{let t=e-1;if(t>=0)return Y.current[t]?.scrollIntoView({block:"nearest"}),t;let r=Y.current.length-1;return r>=0&&Y.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[b]);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),et();return}if("Escape"===e.key&&_){e.preventDefault(),e.stopPropagation(),er();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,_,et,er]);let eo=N&&C?C-41:S??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-card text-foreground dark:text-slate-11 relative overflow-hidden border transition-colors cursor-pointer ${N?"rounded-none border-0":"rounded-2xl rounded-bl-md rounded-br-md"} ${N?"":c?"border-brand":"border-brand/30"}`,onClick:m,children:[N?(0,n.jsxs)("div",{onDoubleClick:()=>y?.(),className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41,flexShrink:0},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded bg-muted text-muted-foreground",children:">_"}),(0,n.jsx)("span",{className:"flex-1 text-xs text-muted-foreground truncate font-mono",children:a}),d&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse"}),L("console.runningText")]}),d&&x&&(0,n.jsx)("button",{onClick:x,className:"text-xs px-3 py-1 rounded-md font-medium bg-destructive text-destructive-foreground transition-all duration-150 hover:bg-destructive/80 hover:shadow-lv2 active:scale-95 active:bg-destructive/70 cursor-pointer select-none",children:"Ctrl+C"}),(0,n.jsx)("button",{onClick:()=>y?.(),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:L("console.restoreTooltip",{modKey:(0,tQ.Mu)()}),children:(0,n.jsx)(ed.A,{className:"w-4 h-4"})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>M?.(),onDoubleClick:e=>{e.stopPropagation(),y?.()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing ${c?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:">_"}),B&&e&&t&&(0,n.jsx)(tK,{shortId:B,type:"terminal",onRegister:()=>{u.t4.runFork((0,tU.Ok)({tabId:t,commandId:e,command:a,projectCwd:r}).pipe(ev.NWQ(()=>ev.rIH)))},onUnregister:()=>{u.t4.runFork((0,tU.jO)({commandId:e}).pipe(ev.NWQ(()=>ev.rIH)))},fullId:e,projectCwd:r,tabId:t}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:a}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(a),(0,T.oR)(L("toast.copiedCmd"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyCommand"),children:(0,n.jsx)(tA.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),D&&!d&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:L("console.totalLines",{count:ee})}),l&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=l.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,T.oR)(L("toast.copiedOutput"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.copyOutput"),children:(0,n.jsx)(tH.A,{className:"w-3.5 h-3.5"})}),p&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),p()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:L("console.rerun"),children:(0,n.jsx)(tW.A,{className:"w-3.5 h-3.5"})}),f&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),f()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:L("console.deleteRecord"),children:(0,n.jsx)(ed.A,{className:"w-3.5 h-3.5"})})]}),_&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card",style:{flexShrink:0},children:[(0,n.jsx)(ei.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:O,value:V,onChange:e=>{let t=e.target.value;U(t),J(0),b&&(t.trim()?z.current?.findNext(t):z.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?es(V):en(V))},placeholder:L("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none",autoComplete:"off",spellCheck:"false"}),!b&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>Q("search"),className:`px-1.5 py-0.5 rounded transition-colors ${"search"===K?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:L("console.searchMode")}),(0,n.jsx)("button",{onClick:()=>Q("filter"),className:`px-1.5 py-0.5 rounded transition-colors ${"filter"===K?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:L("console.filterMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>es(V),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:L("console.prevShiftEnter"),children:(0,n.jsx)(tz.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>en(V),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:L("console.nextEnter"),children:(0,n.jsx)(tO.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:er,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)(ed.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsxs)("div",{className:"relative group",style:{height:eo,overflow:"hidden"},children:[(0,n.jsx)(s.Suspense,{fallback:(0,n.jsx)("div",{className:"px-4 py-2 text-xs text-muted-foreground",style:{height:eo},children:L("console.loadingTerminal")}),children:(0,n.jsx)(tG,{ref:z,output:l,isRunning:d,onInput:h,onResize:k,maximized:N,height:eo,directWrite:!!v})}),!d&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 pointer-events-none"}),!d&&p&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",onClick:e=>{e.stopPropagation(),p()},children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-tooltip text-tooltip-foreground text-xs",children:[(0,n.jsx)(tW.A,{className:"w-3.5 h-3.5"}),L("console.rerun")]})})]}):(0,n.jsx)("div",{ref:E,className:"overflow-auto px-4 py-2",style:{height:eo},onScroll:()=>{if(E.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=E.current;$.current=t-e-r<50}},children:_&&V.trim()?(0,n.jsx)(tZ,{output:l,query:V,mode:K,currentIdx:G,matchListRef:Y}):(0,n.jsx)("pre",{ref:P,className:"text-sm font-mono whitespace-pre-wrap break-words select-text"})}),d&&!N&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse flex-shrink-0"}),b?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-1",children:L("console.clickToInput")}):h?(0,n.jsx)("input",{ref:I,value:H,onChange:e=>W(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=tJ[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(H+"\n"),W("")),"Tab"===e.key&&(e.preventDefault(),h(" "))},placeholder:L("console.stdinPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs font-mono text-foreground outline-none",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:L("console.runningText")}),x&&(0,n.jsx)("button",{onClick:x,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),F&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:F})]}),!d&&void 0!==i&&!N&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${0===i?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:L("console.exitCode",{code:i})}),(0,n.jsx)("span",{className:"flex-1"}),F&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:F})]})]})})}),t0=new Map;function t1(e){t0.set(e.type,e)}function t2(e){return t0.get(e)}function t5(e){for(let t of t0.values())if(t.match(e))return t;return null}let t4=(e,t)=>ev.$mh({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 ej.uV({message:`POST ${e} failed`,cause:t})}),t3=(e,t)=>u.t4.runPromise(t4(`/api/${e}/disconnect`,{id:t}).pipe(ev.NWQ(()=>ev.rIH))),t6=e=>u.t4.runPromise(t4("/api/browser/unregister",{id:e}).pipe(ev.NWQ(()=>ev.rIH))),t8=e=>u.t4.runPromise(e.pipe(ev.h9N(e=>ev.OH5(()=>{if(e.cause instanceof Error)throw e.cause;throw Error(e.message)})))),t9=(e,t)=>{if(e&&"object"==typeof e&&"error"in e){let t=e.error;if("string"==typeof t&&t.length>0)return t;if(t&&"object"==typeof t){let e=t.message;if("string"==typeof e&&e.length>0)return e;let r=t._tag;if("string"==typeof r&&r.length>0)return r}}return`HTTP ${t}`},t7=(e,t)=>t8(ev.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!r.ok)throw Error(t9(n,r.status));return n},catch:t=>new ej.uV({message:`POST ${e} failed`,cause:t})})),re=(e,t)=>t8(ev.$mh({try:async()=>{let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(t9(s,n.status));return s},catch:t=>new ej.uV({message:`GET ${e} failed`,cause:t})})),rt=(e,t)=>t8(ev.$mh({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}`);return r.blob()},catch:t=>new ej.uV({message:`POST blob ${e} failed`,cause:t})}));var rr=r(53853);function rn(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")}function rs(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.set("_cockpit","1"),t.toString()}catch{let t=e.includes("?")?"&":"?";return`${e}${t}_cockpit=1`}}function ro(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.delete("_cockpit"),t.toString()}catch{return e.replace(/[?&]_cockpit=1/,"")}}async function ra(e){let t=(0,rr.f)()?.id??null;return!!t&&new Promise(r=>{try{let n=globalThis.chrome?.runtime;if(!n?.sendMessage)return void r(!1);let s=setTimeout(()=>r(!1),2e3);n.sendMessage(t,{type:"prepare-iframe",url:e},e=>{clearTimeout(s),r(e?.ok??!1)})}catch{r(!1)}})}function rl(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function ri({url:e,id:t,selected:r,maximized:a,expandedHeight:l,bubbleContentHeight:i,onSelect:u,onClose:m,onToggleMaximize:x,onNewTab:h,timestamp:f,onTitleMouseDown:p,initialSleeping:g,onSleep:b,onWake:v,projectCwd:j,baseCwd:w,tabId:k,autoConnect:y}){let{t:N,i18n:C}=(0,o.Bd)(),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),[P,$]=(0,s.useState)(e),[R,I]=(0,s.useState)(null),[F,B]=(0,s.useState)(g??!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(null);(0,s.useEffect)(()=>{$(e)},[e]);let W=(0,s.useRef)(!0),z=(0,s.useCallback)(()=>{F||(B(!0),I(null),b?.(t))},[F,t,b]),O=(0,s.useCallback)(()=>{D.current&&(clearTimeout(D.current),D.current=null)},[]),{shortId:_,connected:q,connect:V,disconnect:U}=function(e,t,r,n,o){let a=(0,s.useMemo)(()=>tq(e),[e]),[l,i]=(0,s.useState)(!1),u=(0,s.useRef)(null),m=(0,s.useRef)([]),x=(0,s.useRef)(null),h=(0,s.useRef)(!1),f=(0,s.useRef)(r);(0,s.useEffect)(()=>{f.current=r});let p=(0,s.useRef)([]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="cockpit:cmd-result"){let{reqId:t,ok:r,data:n,error:s}=e.data,o=u.current;o&&o.readyState===WebSocket.OPEN&&o.send(JSON.stringify({type:"browser:cmd-result",reqId:t,ok:r,data:n,error:s}));return}if(e.data?.type==="cockpit:prepare-screenshot"){let r=t.current;if(!r?.contentWindow)return;let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),(0,d.F)(c.n.ScreenshotPrepare,{cwd:n}),requestAnimationFrame(()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(()=>{let t=r.getBoundingClientRect(),n=window.devicePixelRatio||1,s=t.x,o=t.y;try{let e=window;for(;e!==e.top;){let t=e.frameElement;if(t){let e=t.getBoundingClientRect();s+=e.x,o+=e.y}e=e.parent}}catch{}r.contentWindow?.postMessage({type:"cockpit:screenshot-bounds",reqId:e.data.reqId,bounds:{x:Math.round(s*n),y:Math.round(o*n),width:Math.round(t.width*n),height:Math.round(t.height*n),dpr:n}},"*")},150)})));return}if(e.data?.type==="cockpit:screenshot-done"){window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),(0,d.F)(c.n.ScreenshotDone,{});return}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let g=(0,s.useCallback)(e=>{let r=t.current;if(!r?.contentWindow){let t=u.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"browser:cmd-result",reqId:e.reqId,ok:!1,error:"iframe not available (page may be sleeping)"}));return}r.contentWindow.postMessage({type:"cockpit:cmd",reqId:e.reqId,action:e.action,params:e.params},"*")},[t]);(0,s.useEffect)(()=>{if(!l)return;let r=!1;return h.current=!0,!function s(){if(r||!h.current)return;let a="https:"===window.location.protocol?"wss:":"ws:",l=new URLSearchParams({fullId:e});n&&l.set("projectCwd",n),o&&l.set("tabId",o);let i=new WebSocket(`${a}//${window.location.host}/ws/browser?${l.toString()}`);u.current=i,i.onopen=()=>{for(let e of p.current)e();if(p.current=[],m.current.length>0){for(let e of m.current)g(e);m.current=[]}},i.onmessage=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("browser:cmd"===r.type){let e=r;t.current?.contentWindow&&f.current?g(e):m.current.push(e)}},i.onclose=()=>{u.current=null,!r&&h.current&&(x.current=setTimeout(s,3e3))},i.onerror=()=>i.close()}(),()=>{r=!0,h.current=!1,x.current&&clearTimeout(x.current),u.current&&(u.current.close(),u.current=null),p.current=[]}},[l,e,t,g,n,o]),(0,s.useEffect)(()=>{if(r&&m.current.length>0){for(let e of m.current)g(e);m.current=[]}},[r,g]);let b=(0,s.useCallback)(()=>l&&u.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{p.current.push(e),l||i(!0)}),[l]);return{shortId:a,connected:l,connect:b,disconnect:(0,s.useCallback)(()=>{i(!1)},[])}}(t,H,!!R&&!F&&!S,j,k),K=(0,s.useRef)(q);K.current=q;let Q=(0,s.useRef)(!1);(0,s.useEffect)(()=>{y&&!Q.current&&(Q.current=!0,V())},[y,V]),(0,s.useEffect)(()=>{let e=A.current;if(!e||F)return;let t=new IntersectionObserver(([e])=>{W.current=e.isIntersecting,e.isIntersecting||K.current?O():(D.current&&clearTimeout(D.current),D.current=setTimeout(z,3e5))});return t.observe(e),()=>t.disconnect()},[F,z,O]),(0,s.useEffect)(()=>{F?U():q?O():W.current||(D.current&&clearTimeout(D.current),D.current=setTimeout(z,3e5))},[q,F,U,O,z]),(0,s.useEffect)(()=>{g&&I(null)},[]);let G=(0,s.useCallback)(()=>{if(B(!1),v?.(t),!rn(e))return void I((0,Z.Kx)(e)?(0,Z.hE)(e,w):(0,Z.Xe)(e,w));let r=rs(e);rl(e)?I(r):ra(e).then(()=>I(r))},[e,t,v,w]);(0,s.useEffect)(()=>{if(!e||F){e||I(null);return}if(!rn(e))return void I((0,Z.Kx)(e)?(0,Z.hE)(e,w):(0,Z.Xe)(e,w));let t=rs(e);if(rl(e))return void I(t);let r=!1;return ra(e).then(()=>{r||I(t)}),()=>{r=!0}},[e,F,w]);let J=(0,s.useCallback)(()=>{M(!1);let e=H.current?.contentWindow;if(!e)return;let t=document.documentElement.classList.contains("dark");e.postMessage({type:"THEME_CHANGE",theme:t?"dark":"light"},"*"),e.postMessage({type:"cockpit:language-change",lang:C.language},"*")},[C]);(0,s.useEffect)(()=>{let e=A.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,a=()=>{o&&t&&(t.scrollTop=s)},l=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",a)},i=()=>{o=!1,t.removeEventListener("scroll",a),t.style.overflow=n};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",a),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=A.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?h?.(ro(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&$(ro(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,h]);let Y=(0,s.useCallback)(()=>{M(!1),E(N("browser.pageLoadFailed"))},[]),X=(0,s.useCallback)(()=>{if(F)return void G();let e=A.current?.querySelector("iframe");if(e&&R){M(!0),E(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[F,G,R]);(0,s.useEffect)(()=>{e&&!F&&(M(!0),E(null))},[e,F]);let ee=(0,s.useCallback)(()=>{if(!P)return;let e=rn(P)?P:(0,Z.Kx)(P)?(0,Z.hE)(P,w):(0,Z.Xe)(P,w);window.open((0,Z.PB)(e,window.location.origin),"_blank")},[P,w]);(0,s.useEffect)(()=>{if(!r&&!a)return;let e=e=>{"Escape"===e.key&&a&&(e.stopPropagation(),x()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),x())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[a,r,x]);let et=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e.split("/").pop()||e}}(P),er=a&&l?l-41:i??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
@@ -30,7 +30,7 @@ Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[C,m,k,r,e,_,J,q,
30
30
  `:"";c||$.current.set(t,u),c&&T.current.add(t),a(e=>e.map(e=>e.id===t?{...e,output:c?"":u,exitCode:void 0,isRunning:!0,pid:void 0}:e));let x=I.current.get(t);try{await r2({cwd:n.cwd||m,command:d,commandId:t,tabId:r||"",projectCwd:e,env:k,usePty:c,sourceId:W.current,...c&&x?{cols:x.cols,rows:x.rows}:{},onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)_(t,r.data);else if("exit"===e){let e=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:r+`
31
31
  Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e+`
32
32
  Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,C,m,k,r,e,_,J,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await u.t4.runPromise((0,tU.SN)(e,r,t,W.current).pipe(ev.sFT(e=>ev.OH5(()=>console.error("Failed to delete command:",e))),ev.NWQ(()=>ev.rIH)))},[e,r,q]),ed=(0,s.useCallback)((t,n,s)=>{var o;let a=t2(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(i(e=>[...e,d]),w(d.id),setTimeout(Y,100),s){let t=M&&M.length>0?[...M]:H.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&&u.t4.runFork((0,tU.cm)(e,r,t,W.current).pipe(ev.NWQ(()=>ev.rIH)))}if(r){let n=a.toHistory(d);u.t4.runFork((0,tU.AJ)(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},W.current).pipe(ev.sFT(e=>ev.OH5(()=>console.error(`Failed to save ${t} item:`,e))),ev.NWQ(()=>ev.rIH)))}},[Y,e,r,M]),ec=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),w(e=>e===t?null:e),c(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t2(n._type);e?.onClose?.(n)}r&&u.t4.runFork((0,tU.SN)(e,r,t,W.current).pipe(ev.sFT(e=>ev.OH5(()=>console.error("Failed to delete plugin item:",e))),ev.NWQ(()=>ev.rIH)))},[l,e,r]);A.current=ed,D.current=es;let eu=(0,s.useCallback)((t,n)=>{r&&u.t4.runFork((0,tU.bv)(e,r,t,{sleeping:n},W.current).pipe(ev.NWQ(()=>ev.rIH)))},[e,r]),em=(0,s.useCallback)(e=>{c(t=>new Set(t).add(e)),eu(e,!0)},[eu]),ex=(0,s.useCallback)(e=>{c(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 u.t4.runPromise((0,tU.cm)(e,r,t,W.current).pipe(ev.NWQ(()=>ev.rIH)))},[e,r]),ef=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!M||0===M.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(M.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,M]);H.current=ef,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let ep=async()=>{let t=await u.t4.runPromise((0,tU.QF)(e,r).pipe(ev.sFT(e=>ev.OH5(()=>console.error("Failed to load env:",e))),ev.DM4(()=>({env:{},home:""}))));y(t.env),N.current=t.home},eg=async()=>{S(await u.t4.runPromise((0,tU.Jn)().pipe(ev.sFT(e=>ev.OH5(()=>console.error("Failed to load aliases:",e))),ev.DM4(()=>({})))))},eb=async()=>{if(!r)return;let t=await u.t4.runPromise((0,tU.DN)(e,r).pipe(ev.DM4(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await Z(0),e.current||await ee(e)})(),ep(),eg(),eb(),()=>{e.current=!0}},[Z,ee]),(0,s.useEffect)(()=>()=>{null!==E.current&&cancelAnimationFrame(E.current)},[]),(0,s.useEffect)(()=>()=>{r9()},[]),{commands:o,pluginItems:l,sleepingBubbles:d,consoleItems:ef,currentCwd:m,selectedCommandId:j,setSelectedCommandId:w,customEnv:k,setCustomEnv:y,aliases:C,setAliases:S,isLoadingHistory:h,hasMoreHistory:p,currentPage:b,scrollRef:z,commandHistoryRef:R,ptySizeRef:I,executeCommandRef:D,executeCommand:es,interruptCommand:eo,rerunCommand:el,deleteCommand:ei,addPluginItem:ed,closePluginItem:ec,handleBubbleSleep:em,handleBubbleWake:ex,loadHistory:Z,scrollToBottom:Y,saveBubbleOrder:eh,sendStdin:r4,resizePty:r3,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:G}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[z,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(0),[V,U]=(0,s.useState)(0),[K,Q]=(0,s.useState)(!0),[G,J]=(0,s.useState)(!1),[Y,Z]=(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),el=(0,s.useRef)(!1),ei=(0,s.useRef)(null),ed=(0,s.useRef)(null),ec=(0,s.useRef)([]);(0,s.useEffect)(()=>{ec.current=c},[c]);let eu=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[m]),em=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollTop<50},[m]),ex=(0,s.useCallback)(()=>{ee(!em()),er(!eu())},[eu,em]),eh=(0,s.useCallback)(()=>{es.current?.scrollIntoView({behavior:"smooth"})},[]),ef=async()=>{let t=await u.t4.runPromiseExit((0,tU.D0)(e));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&Q(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>ef())},[]);let ep=(0,s.useCallback)(()=>{el.current=!0},[]),eg=(0,s.useCallback)((e,t)=>{if(!el.current)return void e.preventDefault();el.current=!1,ei.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:hsl(var(--card));color:hsl(var(--foreground));box-shadow:var(--elevation-2);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),eb=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ed.current=t},[]),ej=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ew=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ek=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ey=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=ei.current,r=ed.current;if(ei.current=null,ed.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,R(a)},[R]),eN=(0,s.useCallback)(e=>{O(t=>t===e?null:e)},[]),eC=(0,s.useCallback)((e,t)=>k("browser",e,t),[k]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),x&&eN(x))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[x,eN]),(0,s.useEffect)(()=>{let e=m.current;if(!e)return;let t=new ResizeObserver(([e])=>{U(e.contentRect.height)});return t.observe(e),U(e.clientHeight),()=>t.disconnect()},[m]),(0,s.useEffect)(()=>{let e=m.current;if(e)return z?q(e.clientHeight):(e.style.overflow="",q(0)),()=>{e&&(e.style.overflow="")}},[z,m]),(0,s.useEffect)(()=>{let e=m.current;if(!e||!z||!_)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${z}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[z,_,m]);let[eS,eM]=(0,s.useState)(null);(0,s.useEffect)(()=>{i&&(O(null),eM(i.commandId))},[i]),(0,s.useEffect)(()=>{if(!eS||!c.some(e=>e.data.id===eS))return;let e=requestAnimationFrame(()=>{let e=m.current,t=e?.querySelector(`[data-bubble-id="${CSS.escape(eS)}"]`);if(!e||!t)return;eM(null),h(eS);let r=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r.top-n.top-Math.max(0,(n.height-r.height)/2);e.scrollTo({top:e.scrollTop+s,behavior:"smooth"})});return()=>cancelAnimationFrame(e)},[eS,c,m,h]),(0,s.useEffect)(()=>{if(!eS)return;let e=setTimeout(()=>{eM(null),(0,T.oR)(d("runningTerminals.notFound"),"error")},3e3);return()=>clearTimeout(e)},[eS,d]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&w(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[w]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.url;t&&k("browser",t)};return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[k]);let eL=V>0?Math.floor((V-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:m,onScroll:ex,className:`console-scroll-root flex-1 overflow-y-auto ${z?"":"py-4 px-4"}`,children:0===c.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:d("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:nw.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:d(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:d(e)},e))]})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>w(nb),title:d("console.launchShell"),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-hover 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}),I&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>F(B+1),disabled:D,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors disabled:opacity-50",children:D?d("console.loadingMore"):d("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:z?"flex flex-col gap-3":K?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:c.map(t=>(0,n.jsx)(r7,{item:t,selected:x===t.data.id,maximized:z===t.data.id,initialSleeping:N.has(t.data.id),tabId:r,projectCwd:e,expandedHeight:_,bubbleContentHeight:eL,onDragStart:eg,onDragOver:eb,onDragEnter:ej,onDragLeave:ew,onDrop:ek,onDragEnd:ey,onSelectId:h,onInterruptId:f,onStdin:p,onDeleteCommand:g,onRerun:b,subscribePtyOutput:A,subscribePtyReset:H,subscribePtyRefresh:W,ptySizeRef:v,resizePty:j,onToggleMaximizeId:eN,onTitleMouseDown:ep,onClosePlugin:y,addBrowserItem:eC,onSleep:C,onWake:S},t.data.id))}),(0,n.jsx)("div",{ref:eo})]})}),!z&&c.length>0&&(0,n.jsx)(nf,{showTop:X,showBottom:et,onScrollTop:eh,onScrollBottom:M}),(0,n.jsx)(nh,{cwd:e,currentCwd:L,commandHistoryRef:E,gridLayout:K,onGridLayoutChange:t=>{Q(t),u.t4.runFork((0,tU.Yn)({cwd:e,settings:{gridLayout:t}}).pipe(ev.sFT(e=>ev.OH5(()=>console.error("Failed to save project settings:",e))),ev.NWQ(()=>ev.rIH)))},onExecute:w,onAddPluginItem:k,onShowEnvManager:()=>J(!0),onOpenShell:()=>w(nb),onOpenNote:l}),G&&(0,n.jsx)(nr,{cwd:e,tabId:r,onClose:()=>J(!1),onSave:e=>P(e)}),Y&&(0,n.jsx)(ns,{onClose:()=>Z(!1),onSave:e=>$(e)})]})});var ny=r(83897),nN=r(54271);function nC(e,t,r,n){return n&&r&&t.includes(e)}var nS=r(54356),nM=r(76412),nL=r(24058),nE=r(56058),nP=r(32880),n$=r(29899),nT=r(98307),nR=r(65153),nI=r(45720);function nF({cwd:e,sessionId:t,engine:r,onOpenProjectSessions:a,onOpenSessionBrowser:l,onOpenSettings:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1),m=t?(0,nI.X)(r,t):null;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","data-tooltip":`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:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("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:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("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"})})}),m&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(m).then(()=>{u(!0),setTimeout(()=>u(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-11 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:c?d("chat.copiedCommandTooltip"):d("chat.copyCommandTooltip",{command:m}),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:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("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 nB({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-11":t?.status==="allowed_warning"?"text-amber-11":"text-muted-foreground",d=t?.status==="rejected"?r("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?r("chat.rateLimitWarning","Approaching Limit"):null,c=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 ",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&d&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${i}`,"data-tooltip":[t.rateLimitType&&`Type: ${u(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${c(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:d}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${c(t.resetsAt)}`]})]}),t&&!d&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5","data-tooltip":[t.rateLimitType&&u(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${c(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:c(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 nD({isOpen:e,onClose:t,cwd:r,sessionId:a,onSelectMessage:l}){let{t:d}=(0,o.Bd)(),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(""),[v,j]=(0,s.useState)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(null);(0,H.E)(t,e),(0,s.useEffect)(()=>{if(!e){x(null),f(!1),g(""),j(null);return}if(!r||!a)return void x([]);let t=!1;return u.t4.runPromiseExit((0,m.nM)(r,a)).then(e=>{t||("Success"===e._tag?x(e.value.messages):(console.error("Failed to load user message index:",e.cause),f(!0),x([])))}),()=>{t=!0}},[e,r,a]);let y=(0,s.useMemo)(()=>{if(!c)return[];let e=c.map((e,t)=>({entry:e,ordinal:t+1})),t=p.trim().toLowerCase();return t?e.filter(e=>e.entry.content.toLowerCase().includes(t)):e},[c,p]),N=p.trim().length>0;(0,s.useEffect)(()=>{if(!e||N||!c)return;let t=w.current;t&&(t.scrollTop=t.scrollHeight)},[e,N,c]);let C=(0,s.useCallback)(async e=>{j(e.id);try{await l(e)}finally{j(null)}t()},[l,t]);if(!e)return null;let S=null===c,M=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:i.iG,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.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:d("userMessages.title")}),c&&c.length>0&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:d("userMessages.count",{shown:y.length,total:c.length})})]}),(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:k,type:"text",autoFocus:!0,placeholder:d("userMessages.searchPlaceholder"),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 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),p&&(0,n.jsx)("button",{onClick:()=>{g(""),k.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:d("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-foreground-subtle hover:text-foreground hover:bg-hover 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",{ref:w,className:"flex-1 overflow-y-auto",children:S?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("common.loading")}):h?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:d("userMessages.loadFailed")}):0===c.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noMessages")}):0===y.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:d("userMessages.noResults")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:y.map(({entry:e,ordinal:t})=>{let r,s=e.timestamp?function(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}(e.timestamp):"";return(0,n.jsx)("button",{onClick:()=>{C(e)},className:"w-full px-4 py-3 text-left hover:bg-hover transition-colors","data-tooltip":(r=e.content.trim()).length>500?`${r.slice(0,500)}…`:r,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:[t,"."]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm text-foreground truncate",children:e.content.replace(/\s+/g," ").trim()}),v===e.id&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:d("userMessages.jumping")})]}),s&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:s})]})},e.id)})})})]})});return(0,n.jsx)(b.ZL,{children:M})}var nA=r(67589),nH=r(20917),nW=r(74086),nz=r(201),nO=r(94290),n_=r(80860),nq=r(36351);function nV({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=async t=>{t.stopPropagation();try{var n;if(!navigator.clipboard?.write||"u"<typeof ClipboardItem)throw Error("Clipboard image write is unavailable");let t=await (n=e.preview,new Promise((e,t)=>{let r=new Image;r.onload=()=>{let n=document.createElement("canvas");n.width=r.naturalWidth,n.height=r.naturalHeight;let s=n.getContext("2d");s?(s.drawImage(r,0,0),n.toBlob(r=>{r?e(r):t(Error("Could not encode image"))},"image/png")):t(Error("Canvas is unavailable"))},r.onerror=()=>t(Error("Could not load image")),r.src=n}));await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),(0,T.oR)(r("imagePreview.copiedImage"),"success")}catch{(0,T.oR)(r("common.copyFailed"),"error")}},a=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsxs)("div",{className:"absolute top-4 right-4 flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("imagePreview.copyImage"),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 7V5a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2M7 7h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2Z"})})}),(0,n.jsx)("button",{type:"button",onClick:t,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-6 h-6",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)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(b.ZL,{children:a})}function nU({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 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)(nV,{image:l,onClose:()=>i(null)})]})}var nK=r(93777),nQ=r(38798),nG=r(94514),nJ=r(59883),nY=r(56204),nZ=r(49387),nX=r(21362),n0=r(63393);let n1=()=>Math.random().toString(36).slice(2,10),n2=e=>e.replace(/\\n/g,"\n");function n5(e){let t=[],r=null;for(let[n,s]of e.split(/\r?\n/).entries()){if(!s.trim())continue;let e=s.match(/^\s*-(?:\s+(.*))?$/);if(e){let t=(e[1]??"").trim();if(!r)return{ok:!1,line:n+1};r.isGroup=!0,t&&r.children.push(n2(t));continue}if(/^\s/.test(s))return{ok:!1,line:n+1};let o=s.trim();o&&(r={text:n2(o),children:[],isGroup:!1},t.push(r))}return{ok:!0,nodes:t.map(e=>e.isGroup?{id:n1(),name:e.text,items:e.children.map(e=>({id:n1(),text:e}))}:{id:n1(),text:e.text})}}function n4({title:e,nodes:t,onSave:r,onClose:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>t.flatMap(e=>(0,m._9)(e)?[e.name.replace(/\n/g,"\\n"),...e.items.length>0?e.items.map(e=>`- ${e.text.replace(/\n/g,"\\n")}`):["- "]]:[e.text.replace(/\n/g,"\\n")]).join("\n")),[c,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),f=n5(i);(0,H.E)(a);let p=(0,s.useCallback)(async()=>{let e=n5(i);!e.ok||c||((u(!0),h(!1),await r(e.nodes))?a():(u(!1),h(!0)))},[a,r,c,i]);return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{"data-quick-instruction-layer":"",className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":e,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:e}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l("chat.quickInstructionsMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":l("common.cancel"),children:(0,n.jsx)(ed.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,wrap:"off",value:i,onChange:e=>d(e.target.value),placeholder:l("chat.quickInstructionsMarkdownPlaceholder"),rows:24,spellCheck:!1,className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y overflow-x-auto whitespace-pre px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:f.ok?x?l("chat.saveQuickInstructionsFailed"):"":l("chat.quickInstructionsMarkdownError",{line:f.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:l("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!f.ok||c,onClick:p,className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:l(c?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let n3="data-quick-instruction-layer",n6=()=>Math.random().toString(36).slice(2,10);function n8({groups:e,value:t,onChange:r,onSubmit:a,onCancel:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(0),f=(0,s.useRef)(null),g=(0,s.useRef)(null),b=[null,...e.map(e=>e.id)],v=null===t?i("chat.instructionGroupNone"):e.find(e=>e.id===t)?.name??i("chat.instructionGroupNone"),j=(0,s.useCallback)(()=>{let r=f.current?.getBoundingClientRect();r&&(m(((e,t,r)=>{let n=Math.min(e.width,r.width-16),s=Math.min(Math.max(8,e.left),Math.max(8,r.width-n-8)),o=r.height-e.bottom-2-8,a=e.top-2-8,l=28*t+8;if(o>=Math.min(l,96)||o>=a)return{left:s,top:e.bottom+2,width:n,maxHeight:Math.max(28,Math.min(l,o))};let i=Math.max(28,Math.min(l,a));return{left:s,top:e.top-2-i,width:n,maxHeight:i}})(r,e.length+1,{width:window.innerWidth,height:window.innerHeight})),h(Math.max(0,b.indexOf(t))),c(!0))},[e.length,b,t]),w=(0,s.useCallback)(()=>{c(!1),m(null),f.current?.focus()},[]),k=(0,s.useCallback)(e=>{r(e),w()},[r,w]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;g.current?.contains(t)||f.current?.contains(t)||(c(!1),m(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,s.useEffect)(()=>{if(!d)return;let e=()=>{c(!1),m(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[d]);let y=(0,s.useCallback)(e=>{d?"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),w()):"ArrowDown"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.min(b.length-1,e+1))):"ArrowUp"===e.key?(e.preventDefault(),e.stopPropagation(),h(e=>Math.max(0,e-1))):"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),k(b[x]??null)):"ArrowDown"===e.key||" "===e.key?(e.preventDefault(),e.stopPropagation(),j()):"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),a()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l())},[d,j,w,k,b,x,a,l]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,type:"button",onClick:()=>d?w():j(),onKeyDown:y,className:"w-[140px] min-w-0 flex-shrink-0 px-2 py-1 flex items-center gap-1 text-xs rounded border border-input bg-background hover:bg-hover focus:outline-none focus:ring-1 focus:ring-ring transition-colors",title:i("chat.instructionGroupLabel"),children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-left ${null===t?"text-muted-foreground":""}`,children:v}),(0,n.jsx)(tO.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"})]}),d&&u&&(0,p.createPortal)((0,n.jsx)("div",{ref:g,[n3]:"",role:"listbox",style:{left:u.left,top:u.top,width:u.width,maxHeight:u.maxHeight},className:"fixed z-[60] py-1 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:b.map((r,s)=>{let o=r===t;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":o,onClick:()=>k(r),onMouseEnter:()=>h(s),className:`w-full min-w-0 px-2 py-1 flex items-center gap-1.5 text-xs text-left transition-colors ${s===x?"bg-hover":""}`,children:[(0,n.jsx)(nG.A,{className:`w-3 h-3 flex-shrink-0 ${o?"text-brand":"opacity-0"}`}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${null===r?"text-muted-foreground":""}`,children:null===r?i("chat.instructionGroupNone"):e.find(e=>e.id===r)?.name})]},r??"__none__")})}),document.body)]})}function n9({initialValue:e,placeholder:t,groupChoices:r,initialGroupId:o,onCommit:a,onCancel:l}){let[i,d]=(0,s.useState)(e),[c,u]=(0,s.useState)(o??null),m=(0,s.useCallback)(()=>{let e=i.trim();e&&a(e,c)},[i,c,a]),x=(0,s.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing?"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l()):(e.preventDefault(),e.stopPropagation(),m())},[m,l]);return(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:x,placeholder:t,autoFocus:!0,className:"flex-1 min-w-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring"}),r&&r.length>0&&(0,n.jsx)(n8,{groups:r,value:c,onChange:u,onSubmit:m,onCancel:l})]})}let n7=(e,t)=>`flex items-center group min-w-0 rounded transition-opacity ${e?"opacity-50":""} ${t?"border-t-2 border-brand":""}`,se="p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",st=(0,s.memo)(function({item:e,isDragging:t,isDragOver:r,onSelect:s,onInsert:a,onEdit:l,onDelete:i,onDragStart:d,onDragOver:c,onDrop:u,onDragEnd:m,management:x=!0}){let{t:h}=(0,o.Bd)();return(0,n.jsxs)("div",{draggable:x,onDragStart:x?()=>d(e.id):void 0,onDragOver:x?t=>c(t,e.id):void 0,onDrop:x?()=>u(e.id):void 0,onDragEnd:x?m:void 0,className:n7(t,r),children:[x&&(0,n.jsx)(nJ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsx)($.m,{content:e.text,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.text),className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(nY.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.text})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>a(e.text),className:se,title:h("chat.insertQuickInstruction"),children:(0,n.jsx)(nq.A,{className:"w-3 h-3"})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>l(e.id),className:se,title:h("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:`${se} hover:text-destructive`,title:h("common.delete"),children:(0,n.jsx)(ed.A,{className:"w-3 h-3"})})]})]})}),sr=(0,s.memo)(function({group:e,isOpen:t,isDragging:r,isDragOver:a,isDragActive:l,onHoverOpen:i,onHoverClose:d,onToggle:c,onRename:u,onDelete:m,onDragStart:x,onDragOver:h,onDrop:f,onDragEnd:p,management:g=!0}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>v.current?.getBoundingClientRect(),[]);return(0,n.jsxs)("div",{ref:v,draggable:g,onDragStart:g?()=>x(e.id):void 0,onDragOver:g?t=>h(t,e.id):void 0,onDrop:g?()=>f(e.id):void 0,onDragEnd:g?p:void 0,onMouseEnter:()=>{if(l)return;let t=j();t&&i(e.id,t)},onMouseLeave:()=>{l||d()},className:`${n7(r,a)} ${t?"bg-hover":""}`,children:[g&&(0,n.jsx)(nJ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let t=j();t&&c(e.id,t)},className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",title:e.name,children:[(0,n.jsx)(nQ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0 text-[10px] text-muted-foreground",children:[e.items.length>0&&e.items.length,(0,n.jsx)(nX.A,{className:"w-3 h-3"})]})]}),g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(e.id),className:se,title:b("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>m(e.id),className:`${se} hover:text-destructive`,title:b("common.delete"),children:(0,n.jsx)(ed.A,{className:"w-3 h-3"})})]})]})});function sn({group:e,position:t,groupChoices:r,editId:s,isAdding:a,isDragActive:l,dragId:i,dragOverId:d,onMouseEnter:c,onMouseLeave:u,onSelect:m,onInsert:x,onStartEdit:h,onCommitEdit:f,onCancelEdit:g,onDelete:b,onStartAdd:v,onCommitAdd:j,onCancelAdd:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S=!0}){let{t:M}=(0,o.Bd)();return(0,p.createPortal)((0,n.jsxs)("div",{[n3]:"",onMouseEnter:c,onMouseLeave:()=>{l||u()},style:{left:t.left,top:t.top,width:t.width,maxHeight:t.maxHeight},className:"fixed z-50 p-2 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1 truncate",children:e.name}),S&&(0,n.jsx)("button",{type:"button",onClick:v,className:"p-0.5 text-muted-foreground hover:text-foreground rounded flex-shrink-0",title:M("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}),S&&a&&(0,n.jsx)(n9,{initialValue:"",placeholder:M("chat.quickInstructionPlaceholder"),onCommit:e=>j(e),onCancel:w}),0===e.items.length&&!a&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:M("chat.noQuickInstructions")}),e.items.map(t=>s===t.id?(0,n.jsx)(n9,{initialValue:t.text,placeholder:M("chat.quickInstructionPlaceholder"),groupChoices:r,initialGroupId:e.id,onCommit:(e,r)=>f(t.id,e,r),onCancel:g},`edit-${t.id}`):(0,n.jsx)(st,{item:t,isDragging:i===t.id,isDragOver:d===t.id&&i!==t.id,onSelect:m,onInsert:x,onEdit:h,onDelete:b,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S},t.id))]}),document.body)}function ss({label:e,nodes:t,scope:r,openGroupId:a,flyoutPosition:l,onOpenFlyout:i,onCloseFlyout:d,onKeepFlyout:c,onSave:u,onSelect:x,onInsert:h,management:f=!0,onManage:p}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(null),L=t.filter(m._9),E=a?L.find(e=>e.id===a)??null:null,P=(0,s.useRef)(t);P.current=t;let $=(0,s.useRef)(a);$.current=a;let R=(0,s.useRef)(null);(0,s.useEffect)(()=>{w(!1)},[a]);let I=(0,s.useCallback)(e=>{y(null),u(r,e)},[u,r]),F=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),text:e}])},[I]),B=(0,s.useCallback)(e=>{v(null),I([...P.current,{id:n6(),name:e,items:[]}])},[I]),D=(0,s.useCallback)((e,t,r,n)=>{let s=P.current,o={id:e,text:t};if(r===n)return void I(s.map(t=>(0,m._9)(t)?t.id===n?{...t,items:t.items.map(t=>t.id===e?o:t)}:t:null===n&&t.id===e?o:t));let a=null===r?s.filter(t=>(0,m._9)(t)||t.id!==e):s.map(t=>(0,m._9)(t)&&t.id===r?{...t,items:t.items.filter(t=>t.id!==e)}:t);I(null===n?[...a,o]:a.map(e=>(0,m._9)(e)&&e.id===n?{...e,items:[...e.items,o]}:e))},[I]),A=(0,s.useCallback)((e,t)=>{I(P.current.map(r=>(0,m._9)(r)&&r.id===e?{...r,name:t}:r))},[I]),H=(0,s.useCallback)(async e=>{let t=P.current.find(t=>t.id===e);if(t&&(0,m._9)(t)&&t.items.length>0){if(!await (0,T.lJ)(g("chat.deleteInstructionGroupConfirm",{name:t.name,count:t.items.length}),{danger:!0,confirmText:g("common.delete")}))return;d()}y(null),I(P.current.filter(t=>t.id!==e))},[I,g,d]),W=(0,s.useCallback)(e=>{let t=$.current;t&&I(P.current.map(r=>(0,m._9)(r)&&r.id===t?e(r):r))},[I]),z=(0,s.useCallback)(e=>{w(!1),W(t=>({...t,items:[...t.items,{id:n6(),text:e}]}))},[W]),O=(0,s.useCallback)(e=>{y(null),W(t=>({...t,items:t.items.filter(t=>t.id!==e)}))},[W]),_=(0,s.useCallback)((e,t,r)=>{D(e,t,$.current,r)},[D]),q=(0,s.useCallback)(e=>{R.current=e,C(e)},[]),V=(0,s.useCallback)(()=>{q(null),M(null)},[q]),U=(0,s.useCallback)(e=>{q(e),d()},[q,d]),K=(0,s.useCallback)((e,t)=>{e.preventDefault(),M(t)},[]),Q=(e,t,r)=>{let n=e.findIndex(e=>e.id===t),s=e.findIndex(e=>e.id===r);if(n<0||s<0)return e;let o=[...e],[a]=o.splice(n,1);return o.splice(s,0,a),o},G=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&I(Q(P.current,t,e))},[I,V]),J=(0,s.useCallback)(e=>{let t=R.current;V(),t&&t!==e&&W(r=>({...r,items:Q(r.items,t,e)}))},[W,V]),Y=e=>{let t=P.current.find(t=>(0,m._9)(t)&&t.id===e);return t&&(0,m._9)(t)?t.items.length:0},Z=(0,s.useCallback)((e,t)=>{i(r,e,t,Y(e),!1)},[i,r]),X=(0,s.useCallback)((e,t)=>{$.current===e?d():i(r,e,t,Y(e),!0)},[i,d,r]);return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),f?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("group")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addInstructionGroup"),children:(0,n.jsx)(n0.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>{y(null),v("instruction")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:g("chat.addQuickInstruction"),children:(0,n.jsx)(nt.A,{className:"w-3.5 h-3.5"})})]}):p?(0,n.jsx)("button",{type:"button",onClick:p,className:"p-1 text-muted-foreground hover:text-brand rounded hover:bg-hover transition-colors",title:g("common.edit"),"aria-label":g("common.edit"),children:(0,n.jsx)(nZ.A,{className:"w-3.5 h-3.5"})}):null]}),"instruction"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.quickInstructionPlaceholder"),onCommit:e=>F(e),onCancel:()=>v(null)}),"group"===b&&(0,n.jsx)(n9,{initialValue:"",placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:e=>B(e),onCancel:()=>v(null)}),0===t.length&&!b&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:g("chat.noQuickInstructions")}),t.map(e=>k===e.id?(0,m._9)(e)?(0,n.jsx)(n9,{initialValue:e.name,placeholder:g("chat.instructionGroupNamePlaceholder"),onCommit:t=>A(e.id,t),onCancel:()=>y(null)},`edit-${e.id}`):(0,n.jsx)(n9,{initialValue:e.text,placeholder:g("chat.quickInstructionPlaceholder"),groupChoices:L,initialGroupId:null,onCommit:(t,r)=>D(e.id,t,null,r),onCancel:()=>y(null)},`edit-${e.id}`):(0,m._9)(e)?(0,n.jsx)(sr,{group:e,isOpen:a===e.id,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,isDragActive:null!==N,onHoverOpen:Z,onHoverClose:d,onToggle:X,onRename:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:G,onDragEnd:V,management:f},e.id):(0,n.jsx)(st,{item:e,isDragging:N===e.id,isDragOver:S===e.id&&N!==e.id,onSelect:x,onInsert:h,onEdit:y,onDelete:H,onDragStart:U,onDragOver:K,onDrop:G,onDragEnd:V,management:f},e.id)),E&&l&&(0,n.jsx)(sn,{group:E,position:l,groupChoices:L,editId:k,isAdding:j,isDragActive:null!==N,dragId:N,dragOverId:S,onMouseEnter:c,onMouseLeave:d,onSelect:x,onInsert:h,onStartEdit:y,onCommitEdit:_,onCancelEdit:()=>y(null),onDelete:O,onStartAdd:()=>{y(null),w(!0)},onCommitAdd:z,onCancelAdd:()=>w(!1),onDragStart:q,onDragOver:K,onDrop:J,onDragEnd:V,management:f})]})}function so({cwd:e,anchorRef:t,onClose:r,onSelect:a,onInsert:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useCallback)(()=>{v.current&&(clearTimeout(v.current),v.current=null),j.current&&(clearTimeout(j.current),j.current=null)},[]);(0,s.useEffect)(()=>w,[w]),(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.ZQ)()),e?u.t4.runPromiseExit((0,m.$x)(e)):null]);!t&&("Success"===r._tag?c(r.value.instructions??[]):console.error("Failed to load global instructions:",r.cause),n&&"Success"===n._tag?h(n.value.instructions??[]):n&&console.error("Failed to load project instructions:",n.cause))})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{let n;if((n=e.target)instanceof Element&&null!==n.closest(`[${n3}]`))return;let s=t.current;s&&!s.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),(0,s.useEffect)(()=>{if(!f)return;let e=()=>{w(),p(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[f,w]);let k=(0,s.useCallback)((e,t,r,n,s)=>{w();let o=()=>{var s;let o,a,l,i,d,c,u;return p({scope:e,groupId:t,position:(a=(s={width:window.innerWidth,height:window.innerHeight}).width-r.right-4-8,l=r.left-4-8,i=288,a>=288?o=r.right+4:l>=288?o=r.left-4-288:a>=l?(i=Math.max(180,a),o=r.right+4):(i=Math.max(180,l),o=r.left-4-i),o=Math.min(Math.max(8,o),Math.max(8,s.width-i-8)),c=Math.min(d=Math.max(90,.6*s.height),30*n+40),(u=r.top-4)+c>s.height-8&&(u=s.height-8-c),{left:o,top:u=Math.max(8,u),width:i,maxHeight:d})})};s?o():v.current=setTimeout(o,150)},[w]),y=(0,s.useCallback)(()=>{w(),j.current=setTimeout(()=>p(null),300)},[w]),N=(0,s.useCallback)(()=>w(),[w]),C=(0,s.useCallback)(async(t,r)=>{let n="global"===t?c:h;n(r);let s=await u.t4.runPromiseExit((0,m.hZ)("global"===t?{scope:"global",instructions:r}:{cwd:e,instructions:r}));return"Failure"===s._tag?(console.error(`Failed to save ${t} instructions:`,s.cause),!1):(s.value?.instructions&&n(s.value.instructions),!0)},[e]),S=(0,s.useCallback)(e=>{r(),a(e)},[r,a]),M=(0,s.useCallback)(e=>{r(),l(e)},[r,l]),L=(0,s.useCallback)(async e=>!!g&&C(g,e),[g,C]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"absolute bottom-full left-0 mb-2 w-80 max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(ss,{label:i("chat.globalInstructions"),nodes:d,scope:"global",openGroupId:f?.scope==="global"?f.groupId:null,flyoutPosition:f?.scope==="global"?f.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),p(null),b("global")}}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(ss,{label:i("chat.projectInstructions"),nodes:x,scope:"project",openGroupId:f?.scope==="project"?f.groupId:null,flyoutPosition:f?.scope==="project"?f.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),p(null),b("project")}})]})]}),g&&(0,n.jsx)(n4,{title:i("global"===g?"chat.editGlobalInstructions":"chat.editProjectInstructions"),nodes:"global"===g?d:x,onSave:L,onClose:()=>b(null)})]})}var sa=r(96625);let sl=(0,s.memo)(function({onSend:e,disabled:t,cwd:r,engine:a,onShowGitStatus:l,onShowComments:i,hasComments:d,onOpenNote:c,isFavorite:u,onToggleFavorite:m,onCreateScheduledTask:x,draft:h,setDraft:f,draftImages:p,setDraftImages:g}){let{t:b}=(0,o.Bd)(),v=(0,s.useState)(""),j=(0,s.useState)([]),[w,k]=void 0!==h&&f?[h,f]:v,[y,N]=void 0!==p&&g?[p,g]:j,[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(!1),E=(0,s.useRef)(null),P=(0,s.useRef)(null),$=(0,s.useCallback)(()=>{let e=E.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)(()=>{$()},[w,$]);let T=(0,s.useMemo)(()=>a&&"claude"!==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]),R=(0,sa.n)({value:w,onChange:k,textareaRef:E,extraCommands:T}),I=(0,s.useCallback)(()=>{let r=w.trim();(r||y.length>0)&&!t&&(e(r,y.length>0?y:void 0),k(""),N([]),E.current&&(E.current.style.height="auto"))},[w,y,t,e]),F=(0,s.useCallback)(r=>{t||e(r)},[t,e]),B=(0,s.useCallback)(e=>{k(t=>{let r=t.replace(/\s+$/,"");return r?`${r}
33
- ${e}`:e}),requestAnimationFrame(()=>{let e=E.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),D=(0,s.useCallback)(e=>{e.nativeEvent.isComposing||!R.handleKeyDown(e)&&("Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),I()))},[R,I]),A=(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(b("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};N(e=>[...e,s])},s.readAsDataURL(r)}}},[b]),H=(0,s.useCallback)(e=>{N(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nU,{images:y,onRemove:H,disabled:t}),(0,n.jsx)(sa.V,{ac:R,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64"}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[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:b("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"})]})}),i&&(0,n.jsx)("button",{onClick:i,className:`p-2 rounded-lg transition-all active:scale-95 ${d?"text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted"}`,title:b("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"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:b("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"})})}),m&&(0,n.jsx)("button",{onClick:m,className:`p-2 rounded-lg transition-all ${u?"text-amber-9 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95":"text-muted-foreground hover:text-amber-9 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95"}`,title:b(u?"sessions.removeFavorite":"sessions.addFavorite"),"aria-label":b(u?"sessions.removeFavorite":"sessions.addFavorite"),"aria-pressed":u,children:(0,n.jsx)(nO.A,{className:"w-5 h-5",fill:u?"currentColor":"none"})}),x&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>S(!C),className:`p-2 rounded-lg transition-all ${C?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:b("chat.scheduledTasks"),children:(0,n.jsx)(n_.A,{className:"w-5 h-5"})}),C&&(0,n.jsx)(nK.E,{onClose:()=>S(!1),onCreate:x})]}),(0,n.jsxs)("div",{className:"relative",ref:P,children:[(0,n.jsx)("button",{onClick:()=>L(!M),className:`p-2 rounded-lg transition-all ${M?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:b("chat.quickInstructions"),children:(0,n.jsx)(nq.A,{className:"w-5 h-5"})}),M&&(0,n.jsx)(so,{cwd:r,anchorRef:P,onClose:()=>L(!1),onSelect:F,onInsert:B})]}),(0,n.jsx)("textarea",{ref:E,value:w,onChange:e=>{k(e.target.value),R.trackCaret(e.target)},onSelect:e=>R.trackCaret(e.currentTarget),onKeyDown:D,onPaste:A,placeholder:t?b("chat.placeholderDisabled"):b("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"})]})]})});var si=r(57125);function sd(e){return"env"===e?"from env var":"default"===e?"default":null}function sc({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[i,d]=(0,s.useState)(!1),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(""),[C,S]=(0,s.useState)("default"),[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)(""),[$,T]=(0,s.useState)("default"),[R,I]=(0,s.useState)(""),[F,B]=(0,s.useState)(!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(null),[W,z]=(0,s.useState)({top:0,left:0}),O=(0,b.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{A.current&&!A.current.contains(e.target)&&D.current&&!D.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let _=(0,s.useCallback)(async()=>{d(!0),x(null);let e=await u.t4.runPromiseExit((0,m.qD)(()=>f(!0)));if(f(!1),"Failure"===e._tag)x("Connection error");else{let t=e.value;switch(t._tag){case"ok":l(t.models);break;case"not-installed":case"error":x(t.message);break;case"not-running":x("Ollama is not running")}}d(!1)},[]),q=(0,s.useCallback)(e=>{N(e.baseUrl),S(e.baseUrlSource),L(e.hasKey),P(e.maskedKey),T(e.keySource),I(""),B(!1)},[]),V=(0,s.useCallback)(async()=>{g(!0),k(null);let e=await u.t4.runPromiseExit((0,m.F4)());"Failure"===e._tag?k("Failed to load config"):q(e.value),g(!1)},[q]),U=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({baseUrl:y}));"Failure"===e._tag?k("Save failed"):(q(e.value),await _()),j(!1)},K=async()=>{let e=R.trim();if(!e)return;j(!0),k(null);let t=await u.t4.runPromiseExit((0,m.yS)({apiKey:e}));"Failure"===t._tag?k("Save failed"):q(t.value),j(!1)},Q=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({apiKey:""}));"Failure"===e._tag?k("Clear failed"):q(e.value),j(!1)},G=e?e.replace(/:latest$/,""):"Select model",J=sd(C),Y=sd($),Z=r?(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:A,className:`${si.ys} min-w-[300px]`,style:{top:W.top,left:W.left},children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Server URL"}),J&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:J})]}),p?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 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)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:y,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key&&U()},placeholder:"http://127.0.0.1:11434",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:U,disabled:v,className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"})]})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),Y&&M&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Y})]}),p?null:M&&!F?(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:E}),(0,n.jsx)("button",{onClick:()=>{B(!0),I(""),setTimeout(()=>H.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:v,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:v,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:H,type:"password",value:R,onChange:e=>I(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"optional — for authenticated servers",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:K,disabled:v||!R.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"}),M&&(0,n.jsx)("button",{onClick:()=>{B(!1),I("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),w&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:w})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsx)("div",{className:"px-3 pt-1 pb-0.5",children:(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Model"})}),(0,n.jsx)("div",{className:"max-h-[240px] overflow-y-auto",children:i||h?(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"}),h?"Starting Ollama...":"Loading models..."]}):c?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-11",children:c}):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;let a=r.name===e;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs transition-colors ${a?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:a}),(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"ml-auto pl-2 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.jsx)(si.XY,{buttonRef:D,label:G,title:"Configure Ollama",onClick:()=>{if(!r){if(D.current){let e=D.current.getBoundingClientRect(),t=O?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;z({top:e.bottom+4-n,left:e.left-r})}V(),_()}o(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:"ollama"}),testId:"ollama-config-picker"}),Z]})}let su={deepseek:{label:"DeepSeek",apiKeysUrl:"https://platform.deepseek.com/api_keys",modelsEndpoint:"/v1/models"},kimi:{label:"Kimi",apiKeysUrl:"https://www.kimi.com/code/console",modelsEndpoint:"/coding/v1/models"},glm:{label:"GLM",apiKeysUrl:"https://bigmodel.cn/apikey/platform",modelsEndpoint:"/coding/paas/v4/models",regions:[{id:"cn",label:"中国大陆",hint:"open.bigmodel.cn"},{id:"global",label:"International",hint:"api.z.ai"}]}};function sm({engine:e,currentModel:t,onModelChange:r,onHasKeyChange:o}){let a=su[e],[l,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(""),[g,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)([]),[P,$]=(0,s.useState)(null),[T,R]=(0,s.useState)(null),I=(0,s.useRef)(null),F=(0,s.useRef)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let A=(0,s.useRef)(t),H=(0,s.useRef)(r),W=(0,s.useRef)(o);(0,s.useEffect)(()=>{A.current=t,H.current=r,W.current=o}),(0,s.useEffect)(()=>{W.current?.(d)},[d]);let[z,O]=(0,s.useState)({top:0,left:0}),_=(0,b.F2)();(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if(t||"Failure"===r._tag)return;c(r.value.hasKey),h(r.value.maskedKey);let s="Success"===n._tag?n.value?.engines?.[e]:void 0,o=s?.builtinModel;!A.current&&o&&H.current(o)})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{if(!l)return;let e=e=>{F.current&&!F.current.contains(e.target)&&I.current&&!I.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]);let q=(0,s.useCallback)(async()=>{w(!0),C(null),$(null);let[n,s]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if("Failure"===n._tag){C("Failed to load settings"),w(!1);return}c(n.value.hasKey),h(n.value.maskedKey),p(""),v(!1);let o="Success"===s._tag?s.value:void 0,l=o?.engines?.[e],i=l?.builtinModel;a.regions&&R(l?.region??("en"===o?.language?"global":"cn"));let d=[];if(n.value.hasKey){let t=await u.t4.runPromiseExit((0,m.Fi)(e));"Success"===t._tag?d=t.value.models:$("Failed to load models — check the API key")}E(d);let x=d.map(e=>e.id),f=i&&x.includes(i)?i:x[0];!f||t&&x.includes(t)||r(f),w(!1)},[e,t,r,a.regions]),V=(0,s.useCallback)(async t=>{let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{},s={...n,[e]:{...n[e]||{},builtinModel:t}};if("Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:s})))._tag)throw Error("Failed to save settings")},[e]),U=(0,s.useCallback)(async t=>{R(t);let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{};"Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:{...n,[e]:{...n[e]||{},region:t}}})))._tag?C("Failed to save region"):q()},[e,q]),K=async()=>{let t=f.trim();if(!t)return;y(!0),C(null);let r=await u.t4.runPromiseExit((0,m.dQ)(e,t));"Failure"===r._tag?C("Save failed"):(c(r.value.hasKey),h(r.value.maskedKey),p(""),v(!1),q()),y(!1)},Q=async()=>{y(!0),C(null);let t=await u.t4.runPromiseExit((0,m.dQ)(e,""));"Failure"===t._tag?C("Clear failed"):(c(t.value.hasKey),h(t.value.maskedKey),p(""),v(!1),E([])),y(!1)},G=async()=>{let t=await u.t4.runPromiseExit((0,m.Ny)(e));if("Failure"===t._tag||!t.value.apiKey)return void C("Copy failed");try{await navigator.clipboard.writeText(t.value.apiKey)}catch{C("Clipboard unavailable");return}C(null),M(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>M(!1),1500)},J=async e=>{r(e);try{await V(e)}catch{}},Y=d?t||"Select model":"Set API key",Z=d?void 0:si.Aw,X=t||"",ee=l?(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{ref:F,className:`${si.ys} min-w-[280px]`,style:{top:z.top,left:z.left},children:j?(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.jsxs)("div",{className:"flex items-center gap-1 mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),(0,n.jsx)("a",{href:a.apiKeysUrl,target:"_blank",rel:"noopener","data-testid":`${e}-api-keys-link`,title:`Open ${a.label} API keys page`,"aria-label":`Open ${a.label} API keys page`,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",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:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]}),d&&!g?(0,n.jsxs)("div",{className:"flex items-center gap-1.5",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:x}),(0,n.jsx)("button",{onClick:G,"data-testid":`${e}-copy-api-key`,title:S?"Copied":"Copy API key","aria-label":"Copy API key",className:`p-1 rounded transition-colors ${S?"text-green-11":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,disabled:k,children:S?(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:"M5 13l4 4L19 7"})}):(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)("button",{onClick:()=>{v(!0),p(""),setTimeout(()=>B.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:k,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:k,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:B,type:"password",value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"sk-...",className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`,autoFocus:!0}),(0,n.jsx)("button",{onClick:K,disabled:k||!f.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:k?"Saving...":"Save"}),d&&(0,n.jsx)("button",{onClick:()=>{v(!1),p("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),N&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:N})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),a.regions&&(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:"Region"}),(0,n.jsx)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":`${e}-region-toggle`,children:a.regions.map(t=>(0,n.jsx)("button",{type:"button","data-testid":`${e}-region-${t.id}`,onClick:()=>U(t.id),title:t.hint,className:`px-2 py-0.5 ${T===t.id?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-hover"}`,children:t.label},t.id))})]}),(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"}),P&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-red-11",children:P}),!P&&0===L.length&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-muted-foreground",children:d?`No models returned by ${a.modelsEndpoint}`:"Save an API key to list models"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:L.map(e=>{var t;let r=X===e.id,s=(t=e.contextTokens)&&!(t<=0)?t>=1048576?`${Math.round(t/1048576)}M`:`${Math.round(t/1024)}K`:null;return(0,n.jsxs)("button",{onClick:()=>J(e.id),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:r}),(0,n.jsx)("span",{className:"truncate",children:e.id}),e.label&&e.label!==e.id&&(0,n.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.label}),s&&(0,n.jsx)("span",{className:"ml-auto pl-2 text-[10px] text-muted-foreground flex-shrink-0",children:s})]},e.id)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(si.XY,{buttonRef:I,label:Y,labelClassName:Z,title:`Configure ${a.label}`,onClick:()=>{if(!l){if(I.current){let e=I.current.getBoundingClientRect(),t=_?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;O({top:e.bottom+4-n,left:e.left-r})}q()}i(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:e}),testId:`${e}-config-picker`}),ee]})}var sx=r(53317);let sh="claude-opus-5-5",sf="gpt-6.1-sol",sp=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultracode",label:"Ultracode"},{id:"ultrathink",label:"Ultrathink"}],sg=[{id:"claude-sonnet-5-5",label:"Claude Sonnet 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-sonnet-5",label:"Claude Sonnet 5",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"high"},{id:"claude-opus-5-5",label:"Claude Opus 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium",fast:!0},{id:"claude-opus-5",label:"Claude Opus 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",fast:!0},{id:"claude-fable-5-1",label:"Claude Fable 5.1",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",thinking:!0}],sb=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultra",label:"Ultra"}],sv=[{id:"gpt-6-astra",label:"GPT-6-Astra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6.1-sol",label:"GPT-6.1-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6-sol",label:"GPT-6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-6-luna",label:"GPT-6-Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"},{id:"gpt-5.6-sol",label:"GPT-5.6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"}];function sj(e){return sv.find(t=>t.id===e)?.defaultReasoning??"low"}function sw(e,t){let r=sv.find(t=>t.id===e)?.reasoning;return t&&(!r||r.includes(t))?t:sj(e)}function sk(e,t){return e.find(e=>e.id===t)?.label??t}function sy(e){return sg.find(t=>t.id===e)?.fast===!0}function sN(e){return sg.find(t=>t.id===e)?.thinking===!0}function sC(e){let t=sg.find(t=>t.id===e);return t?t.defaultEffort:"high"}function sS(e,t){let r=sg.find(t=>t.id===e),n=r?.effort;return t&&(!r||n?.includes(t))?t:sC(e)}function sM({value:e,selected:t,label:r,defaultValue:s,onSelect:o}){return(0,n.jsxs)("button",{type:"button",onClick:()=>o(e),className:`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${t?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:t})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:r}),(0,n.jsx)("span",{className:"shrink-0",children:s&&(0,n.jsx)("span",{className:"rounded bg-muted px-1.5 text-[10px] font-medium text-muted-foreground",children:"Default"})})]})}function sL({title:e,selected:t,value:r,items:o,onSelect:a,icon:l,testId:i}){let d=(0,s.useRef)(null),c=(0,s.useRef)(null),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=()=>{let e=d.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;h({top:e.bottom+4-n,left:e.left-r})};return(0,s.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.target;c.current?.contains(t)||d.current?.contains(t)||m(!1)},t=()=>p();return document.addEventListener("mousedown",e),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[u]),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:d,label:r,labelMaxWidth:"max-w-[180px]",title:`${e}: ${r}`,onClick:()=>{u||p(),m(e=>!e)},icon:l,testId:i}),u&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:c,className:`${si.ys} min-w-[190px]`,style:{top:x.top,left:x.left},children:[(0,n.jsx)("div",{className:"px-3 pb-1 text-[11px] font-medium text-muted-foreground",children:e}),(0,n.jsx)("div",{className:"flex flex-col",children:o.map(e=>(0,n.jsx)(sM,{value:e.id,selected:t===e.id,label:e.label,defaultValue:e.defaultValue,onSelect:e=>{a(e),m(!1)}},e.id))})]})})]})}function sE(e){let t,r,s,o=e.engine??"claude",a=e.claudeModel??sh,l=sC(a),i=(t=sg.find(e=>e.id===a)?.effort)?t.map(e=>sp.find(t=>t.id===e)??{id:e,label:e}):[],d=sS(a,e.claudeEffort),c=e.claudeFastMode??!1,u=e.claudeThinking??!1,m=e.codexModel??sf,x=sj(m),h=(r=sv.find(e=>e.id===m)?.reasoning)?r.map(e=>sb.find(t=>t.id===e)??{id:e,label:e}):sb,f=sw(m,e.codexReasoningEffort);return"claude"!==o?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:m,value:sv.find(e=>e.id===m)?.label??(0,sx.U)(m),items:sv.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sf})),onSelect:t=>{e.onCodexModelChange?.(t),e.onCodexReasoningEffortChange?.(sj(t))},icon:(0,n.jsx)(si.eV,{engine:"codex"}),testId:"codex-model-picker"}),(0,n.jsx)(sL,{title:"Reasoning",selected:f,value:sk(sb,f),items:h.map(e=>({...e,defaultValue:e.id===x})),onSelect:t=>e.onCodexReasoningEffortChange?.(t),testId:"codex-reasoning-picker"})]}):(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:a,value:(s=sg.find(e=>e.id===a))?s.label:a.startsWith("claude-")?`Claude ${(0,sx.J)(a)}`:a,items:sg.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sh})),onSelect:t=>{e.onClaudeModelChange?.(t);let r=sC(t);r&&e.onClaudeEffortChange?.(r),sy(t)||e.onClaudeFastModeChange?.(!1),sN(t)||e.onClaudeThinkingChange?.(!1)},icon:(0,n.jsx)(si.eV,{engine:"claude"}),testId:"claude-model-picker"}),d&&i.length>0&&(0,n.jsx)(sL,{title:"Reasoning",selected:d,value:sk(sp,d),items:i.map(e=>({...e,defaultValue:e.id===l})),onSelect:t=>e.onClaudeEffortChange?.(t),testId:"claude-reasoning-picker"}),sy(a)&&(0,n.jsx)(sL,{title:"Fast Mode",selected:c?"on":"off",value:c?"Fast On":"Fast Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeFastModeChange?.("on"===t),testId:"claude-fast-mode-picker"}),sN(a)&&(0,n.jsx)(sL,{title:"Thinking",selected:u?"on":"off",value:u?"Thinking On":"Thinking Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeThinkingChange?.("on"===t),testId:"claude-thinking-picker"})]})}var sP=r(6489);let s$=/^#\s+(.*)$/;function sT(e,t=[]){let r=new Map(t.map(e=>[e.name,e.id])),n=[];for(let[t,r]of e.split(/\r?\n/).entries()){let e=r.match(s$);if(e){n.push({name:e[1].trim(),line:t+1,body:[]});continue}let s=n[n.length-1];if(!s){if(r.trim())return{ok:!1,line:t+1,reason:"content-before-heading"};continue}s.body.push(r)}let s=new Set,o=[];for(let e of n){let t=e.body.join("\n").trim();if(!e.name||!t)return{ok:!1,line:e.line,reason:"empty-style"};if(s.has(e.name))return{ok:!1,line:e.line,reason:"duplicate-name"};s.add(e.name),o.push({id:r.get(e.name)??"",name:e.name,content:t})}return{ok:!0,styles:o}}function sR({styles:e,onSave:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(()=>e.map(e=>`# ${e.name}
33
+ ${e}`:e}),requestAnimationFrame(()=>{let e=E.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),D=(0,s.useCallback)(e=>{e.nativeEvent.isComposing||!R.handleKeyDown(e)&&("Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),I()))},[R,I]),A=(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(b("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};N(e=>[...e,s])},s.readAsDataURL(r)}}},[b]),H=(0,s.useCallback)(e=>{N(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(nU,{images:y,onRemove:H,disabled:t}),(0,n.jsx)(sa.V,{ac:R,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64"}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[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:b("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"})]})}),i&&(0,n.jsx)("button",{onClick:i,className:`p-2 rounded-lg transition-all active:scale-95 ${d?"text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted"}`,title:b("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"})})}),c&&(0,n.jsx)("button",{onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:b("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"})})}),m&&(0,n.jsx)("button",{onClick:m,className:`p-2 rounded-lg transition-all ${u?"text-amber-9 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95":"text-muted-foreground hover:text-amber-9 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95"}`,title:b(u?"sessions.removeFavorite":"sessions.addFavorite"),"aria-label":b(u?"sessions.removeFavorite":"sessions.addFavorite"),"aria-pressed":u,children:(0,n.jsx)(nO.A,{className:"w-5 h-5",fill:u?"currentColor":"none"})}),x&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>S(!C),className:`p-2 rounded-lg transition-all ${C?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:b("chat.scheduledTasks"),children:(0,n.jsx)(n_.A,{className:"w-5 h-5"})}),C&&(0,n.jsx)(nK.E,{onClose:()=>S(!1),onCreate:x})]}),(0,n.jsxs)("div",{className:"relative",ref:P,children:[(0,n.jsx)("button",{onClick:()=>L(!M),className:`p-2 rounded-lg transition-all ${M?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:b("chat.quickInstructions"),children:(0,n.jsx)(nq.A,{className:"w-5 h-5"})}),M&&(0,n.jsx)(so,{cwd:r,anchorRef:P,onClose:()=>L(!1),onSelect:F,onInsert:B})]}),(0,n.jsx)("textarea",{ref:E,value:w,onChange:e=>{k(e.target.value),R.trackCaret(e.target)},onSelect:e=>R.trackCaret(e.currentTarget),onKeyDown:D,onPaste:A,placeholder:t?b("chat.placeholderDisabled"):b("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"})]})]})});var si=r(57125);function sd(e){return"env"===e?"from env var":"default"===e?"default":null}function sc({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)([]),[i,d]=(0,s.useState)(!1),[c,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(""),[C,S]=(0,s.useState)("default"),[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)(""),[$,T]=(0,s.useState)("default"),[R,I]=(0,s.useState)(""),[F,B]=(0,s.useState)(!1),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(null),[W,z]=(0,s.useState)({top:0,left:0}),O=(0,b.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{A.current&&!A.current.contains(e.target)&&D.current&&!D.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let _=(0,s.useCallback)(async()=>{d(!0),x(null);let e=await u.t4.runPromiseExit((0,m.qD)(()=>f(!0)));if(f(!1),"Failure"===e._tag)x("Connection error");else{let t=e.value;switch(t._tag){case"ok":l(t.models);break;case"not-installed":case"error":x(t.message);break;case"not-running":x("Ollama is not running")}}d(!1)},[]),q=(0,s.useCallback)(e=>{N(e.baseUrl),S(e.baseUrlSource),L(e.hasKey),P(e.maskedKey),T(e.keySource),I(""),B(!1)},[]),V=(0,s.useCallback)(async()=>{g(!0),k(null);let e=await u.t4.runPromiseExit((0,m.F4)());"Failure"===e._tag?k("Failed to load config"):q(e.value),g(!1)},[q]),U=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({baseUrl:y}));"Failure"===e._tag?k("Save failed"):(q(e.value),await _()),j(!1)},K=async()=>{let e=R.trim();if(!e)return;j(!0),k(null);let t=await u.t4.runPromiseExit((0,m.yS)({apiKey:e}));"Failure"===t._tag?k("Save failed"):q(t.value),j(!1)},Q=async()=>{j(!0),k(null);let e=await u.t4.runPromiseExit((0,m.yS)({apiKey:""}));"Failure"===e._tag?k("Clear failed"):q(e.value),j(!1)},G=e?e.replace(/:latest$/,""):"Select model",J=sd(C),Y=sd($),Z=r?(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:A,className:`${si.ys} min-w-[300px]`,style:{top:W.top,left:W.left},children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Server URL"}),J&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:J})]}),p?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-1 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)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{type:"text",value:y,onChange:e=>N(e.target.value),onKeyDown:e=>{"Enter"===e.key&&U()},placeholder:"http://127.0.0.1:11434",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:U,disabled:v,className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"})]})]}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),Y&&M&&!p&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:Y})]}),p?null:M&&!F?(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:E}),(0,n.jsx)("button",{onClick:()=>{B(!0),I(""),setTimeout(()=>H.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:v,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:v,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:H,type:"password",value:R,onChange:e=>I(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"optional — for authenticated servers",spellCheck:!1,className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`}),(0,n.jsx)("button",{onClick:K,disabled:v||!R.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:v?"...":"Save"}),M&&(0,n.jsx)("button",{onClick:()=>{B(!1),I("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),w&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:w})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsx)("div",{className:"px-3 pt-1 pb-0.5",children:(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Model"})}),(0,n.jsx)("div",{className:"max-h-[240px] overflow-y-auto",children:i||h?(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"}),h?"Starting Ollama...":"Loading models..."]}):c?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-11",children:c}):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;let a=r.name===e;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs transition-colors ${a?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:a}),(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"ml-auto pl-2 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.jsx)(si.XY,{buttonRef:D,label:G,title:"Configure Ollama",onClick:()=>{if(!r){if(D.current){let e=D.current.getBoundingClientRect(),t=O?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;z({top:e.bottom+4-n,left:e.left-r})}V(),_()}o(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:"ollama"}),testId:"ollama-config-picker"}),Z]})}let su={deepseek:{label:"DeepSeek",apiKeysUrl:"https://platform.deepseek.com/api_keys",modelsEndpoint:"/v1/models"},kimi:{label:"Kimi",apiKeysUrl:"https://www.kimi.com/code/console",modelsEndpoint:"/coding/v1/models"},glm:{label:"GLM",apiKeysUrl:"https://bigmodel.cn/apikey/platform",modelsEndpoint:"/coding/paas/v4/models",regions:[{id:"cn",label:"中国大陆",hint:"open.bigmodel.cn"},{id:"global",label:"International",hint:"api.z.ai"}]}};function sm({engine:e,currentModel:t,onModelChange:r,onHasKeyChange:o}){let a=su[e],[l,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(""),[g,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)([]),[P,$]=(0,s.useState)(null),[T,R]=(0,s.useState)(null),I=(0,s.useRef)(null),F=(0,s.useRef)(null),B=(0,s.useRef)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let A=(0,s.useRef)(t),H=(0,s.useRef)(r),W=(0,s.useRef)(o);(0,s.useEffect)(()=>{A.current=t,H.current=r,W.current=o}),(0,s.useEffect)(()=>{W.current?.(d)},[d]);let[z,O]=(0,s.useState)({top:0,left:0}),_=(0,b.F2)();(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if(t||"Failure"===r._tag)return;c(r.value.hasKey),h(r.value.maskedKey);let s="Success"===n._tag?n.value?.engines?.[e]:void 0,o=s?.builtinModel;!A.current&&o&&H.current(o)})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{if(!l)return;let e=e=>{F.current&&!F.current.contains(e.target)&&I.current&&!I.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]);let q=(0,s.useCallback)(async()=>{w(!0),C(null),$(null);let[n,s]=await Promise.all([u.t4.runPromiseExit((0,m.Hw)(e)),u.t4.runPromiseExit((0,m.td)())]);if("Failure"===n._tag){C("Failed to load settings"),w(!1);return}c(n.value.hasKey),h(n.value.maskedKey),p(""),v(!1);let o="Success"===s._tag?s.value:void 0,l=o?.engines?.[e],i=l?.builtinModel;a.regions&&R(l?.region??("en"===o?.language?"global":"cn"));let d=[];if(n.value.hasKey){let t=await u.t4.runPromiseExit((0,m.Fi)(e));"Success"===t._tag?d=t.value.models:$("Failed to load models — check the API key")}E(d);let x=d.map(e=>e.id),f=i&&x.includes(i)?i:x[0];!f||t&&x.includes(t)||r(f),w(!1)},[e,t,r,a.regions]),V=(0,s.useCallback)(async t=>{let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{},s={...n,[e]:{...n[e]||{},builtinModel:t}};if("Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:s})))._tag)throw Error("Failed to save settings")},[e]),U=(0,s.useCallback)(async t=>{R(t);let r=await u.t4.runPromiseExit((0,m.td)()),n=("Success"===r._tag?r.value:{}).engines||{};"Failure"===(await u.t4.runPromiseExit((0,m.em)({engines:{...n,[e]:{...n[e]||{},region:t}}})))._tag?C("Failed to save region"):q()},[e,q]),K=async()=>{let t=f.trim();if(!t)return;y(!0),C(null);let r=await u.t4.runPromiseExit((0,m.dQ)(e,t));"Failure"===r._tag?C("Save failed"):(c(r.value.hasKey),h(r.value.maskedKey),p(""),v(!1),q()),y(!1)},Q=async()=>{y(!0),C(null);let t=await u.t4.runPromiseExit((0,m.dQ)(e,""));"Failure"===t._tag?C("Clear failed"):(c(t.value.hasKey),h(t.value.maskedKey),p(""),v(!1),E([])),y(!1)},G=async()=>{let t=await u.t4.runPromiseExit((0,m.Ny)(e));if("Failure"===t._tag||!t.value.apiKey)return void C("Copy failed");try{await navigator.clipboard.writeText(t.value.apiKey)}catch{C("Clipboard unavailable");return}C(null),M(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>M(!1),1500)},J=async e=>{r(e);try{await V(e)}catch{}},Y=d?t||"Select model":"Set API key",Z=d?void 0:si.Aw,X=t||"",ee=l?(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{ref:F,className:`${si.ys} min-w-[280px]`,style:{top:z.top,left:z.left},children:j?(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.jsxs)("div",{className:"flex items-center gap-1 mb-1.5",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:"API Key"}),(0,n.jsx)("a",{href:a.apiKeysUrl,target:"_blank",rel:"noopener","data-testid":`${e}-api-keys-link`,title:`Open ${a.label} API keys page`,"aria-label":`Open ${a.label} API keys page`,className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",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:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]}),d&&!g?(0,n.jsxs)("div",{className:"flex items-center gap-1.5",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:x}),(0,n.jsx)("button",{onClick:G,"data-testid":`${e}-copy-api-key`,title:S?"Copied":"Copy API key","aria-label":"Copy API key",className:`p-1 rounded transition-colors ${S?"text-green-11":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,disabled:k,children:S?(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:"M5 13l4 4L19 7"})}):(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)("button",{onClick:()=>{v(!0),p(""),setTimeout(()=>B.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-hover text-foreground transition-colors",disabled:k,children:"Edit"}),(0,n.jsx)("button",{onClick:Q,className:"text-[11px] px-2 py-1 rounded text-red-11 hover:bg-red-500/10 transition-colors",disabled:k,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:B,type:"password",value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"===e.key&&K()},placeholder:"sk-...",className:`flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:outline-none font-mono ${si.Fx}`,autoFocus:!0}),(0,n.jsx)("button",{onClick:K,disabled:k||!f.trim(),className:`text-[11px] px-2 py-1 rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${si.$T}`,children:k?"Saving...":"Save"}),d&&(0,n.jsx)("button",{onClick:()=>{v(!1),p("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),N&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-11",children:N})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),a.regions&&(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:"Region"}),(0,n.jsx)("div",{className:"inline-flex rounded-md border border-border overflow-hidden text-xs",role:"group","data-testid":`${e}-region-toggle`,children:a.regions.map(t=>(0,n.jsx)("button",{type:"button","data-testid":`${e}-region-${t.id}`,onClick:()=>U(t.id),title:t.hint,className:`px-2 py-0.5 ${T===t.id?"bg-brand text-white":"bg-transparent text-muted-foreground hover:bg-hover"}`,children:t.label},t.id))})]}),(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"}),P&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-red-11",children:P}),!P&&0===L.length&&(0,n.jsx)("div",{className:"mb-1 text-[11px] text-muted-foreground",children:d?`No models returned by ${a.modelsEndpoint}`:"Save an API key to list models"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:L.map(e=>{var t;let r=X===e.id,s=(t=e.contextTokens)&&!(t<=0)?t>=1048576?`${Math.round(t/1048576)}M`:`${Math.round(t/1024)}K`:null;return(0,n.jsxs)("button",{onClick:()=>J(e.id),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?si.yI:"text-foreground hover:bg-hover"}`,children:[(0,n.jsx)(si.hG,{selected:r}),(0,n.jsx)("span",{className:"truncate",children:e.id}),e.label&&e.label!==e.id&&(0,n.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.label}),s&&(0,n.jsx)("span",{className:"ml-auto pl-2 text-[10px] text-muted-foreground flex-shrink-0",children:s})]},e.id)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(si.XY,{buttonRef:I,label:Y,labelClassName:Z,title:`Configure ${a.label}`,onClick:()=>{if(!l){if(I.current){let e=I.current.getBoundingClientRect(),t=_?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;O({top:e.bottom+4-n,left:e.left-r})}q()}i(e=>!e)},icon:(0,n.jsx)(si.eV,{engine:e}),testId:`${e}-config-picker`}),ee]})}var sx=r(53317);let sh="claude-opus-5-5",sf="gpt-6.1-sol",sp=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultracode",label:"Ultracode"},{id:"ultrathink",label:"Ultrathink"}],sg=[{id:"claude-sonnet-5-5",label:"Claude Sonnet 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-sonnet-5",label:"Claude Sonnet 5",effort:["low","medium","high","xhigh","max","ultrathink"],defaultEffort:"high"},{id:"claude-opus-5-5",label:"Claude Opus 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium",fast:!0},{id:"claude-opus-5",label:"Claude Opus 5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high",fast:!0},{id:"claude-fable-5-1",label:"Claude Fable 5.1",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"high"},{id:"claude-haiku-5-5",label:"Claude Haiku 5.5",effort:["low","medium","high","xhigh","max","ultracode","ultrathink"],defaultEffort:"medium"},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",thinking:!0}],sb=[{id:"low",label:"Low"},{id:"medium",label:"Medium"},{id:"high",label:"High"},{id:"xhigh",label:"Extra High"},{id:"max",label:"Max"},{id:"ultra",label:"Ultra"}],sv=[{id:"gpt-6-astra",label:"GPT-6-Astra",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6.1-sol",label:"GPT-6.1-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"},{id:"gpt-6-sol",label:"GPT-6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"medium"},{id:"gpt-6-luna",label:"GPT-6-Luna",reasoning:["low","medium","high","xhigh","max"],defaultReasoning:"medium"},{id:"gpt-5.6-sol",label:"GPT-5.6-Sol",reasoning:["low","medium","high","xhigh","max","ultra"],defaultReasoning:"low"}];function sj(e){return sv.find(t=>t.id===e)?.defaultReasoning??"low"}function sw(e,t){let r=sv.find(t=>t.id===e)?.reasoning;return t&&(!r||r.includes(t))?t:sj(e)}function sk(e,t){return e.find(e=>e.id===t)?.label??t}function sy(e){return sg.find(t=>t.id===e)?.fast===!0}function sN(e){return sg.find(t=>t.id===e)?.thinking===!0}function sC(e){let t=sg.find(t=>t.id===e);return t?t.defaultEffort:"high"}function sS(e,t){let r=sg.find(t=>t.id===e),n=r?.effort;return t&&(!r||n?.includes(t))?t:sC(e)}function sM({value:e,selected:t,label:r,defaultValue:s,onSelect:o}){return(0,n.jsxs)("button",{type:"button",onClick:()=>o(e),className:`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${t?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:t})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:r}),(0,n.jsx)("span",{className:"shrink-0",children:s&&(0,n.jsx)("span",{className:"rounded bg-muted px-1.5 text-[10px] font-medium text-muted-foreground",children:"Default"})})]})}function sL({title:e,selected:t,value:r,items:o,onSelect:a,icon:l,testId:i}){let d=(0,s.useRef)(null),c=(0,s.useRef)(null),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=()=>{let e=d.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;h({top:e.bottom+4-n,left:e.left-r})};return(0,s.useEffect)(()=>{if(!u)return;let e=e=>{let t=e.target;c.current?.contains(t)||d.current?.contains(t)||m(!1)},t=()=>p();return document.addEventListener("mousedown",e),window.addEventListener("resize",t),window.addEventListener("scroll",t,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",t),window.removeEventListener("scroll",t,!0)}},[u]),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:d,label:r,labelMaxWidth:"max-w-[180px]",title:`${e}: ${r}`,onClick:()=>{u||p(),m(e=>!e)},icon:l,testId:i}),u&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:c,className:`${si.ys} min-w-[190px]`,style:{top:x.top,left:x.left},children:[(0,n.jsx)("div",{className:"px-3 pb-1 text-[11px] font-medium text-muted-foreground",children:e}),(0,n.jsx)("div",{className:"flex flex-col",children:o.map(e=>(0,n.jsx)(sM,{value:e.id,selected:t===e.id,label:e.label,defaultValue:e.defaultValue,onSelect:e=>{a(e),m(!1)}},e.id))})]})})]})}function sE(e){let t,r,s,o=e.engine??"claude",a=e.claudeModel??sh,l=sC(a),i=(t=sg.find(e=>e.id===a)?.effort)?t.map(e=>sp.find(t=>t.id===e)??{id:e,label:e}):[],d=sS(a,e.claudeEffort),c=e.claudeFastMode??!1,u=e.claudeThinking??!1,m=e.codexModel??sf,x=sj(m),h=(r=sv.find(e=>e.id===m)?.reasoning)?r.map(e=>sb.find(t=>t.id===e)??{id:e,label:e}):sb,f=sw(m,e.codexReasoningEffort);return"claude"!==o?(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:m,value:sv.find(e=>e.id===m)?.label??(0,sx.U)(m),items:sv.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sf})),onSelect:t=>{e.onCodexModelChange?.(t),e.onCodexReasoningEffortChange?.(sj(t))},icon:(0,n.jsx)(si.eV,{engine:"codex"}),testId:"codex-model-picker"}),(0,n.jsx)(sL,{title:"Reasoning",selected:f,value:sk(sb,f),items:h.map(e=>({...e,defaultValue:e.id===x})),onSelect:t=>e.onCodexReasoningEffortChange?.(t),testId:"codex-reasoning-picker"})]}):(0,n.jsxs)("div",{className:"flex min-w-0 items-center gap-1","data-agent-model-traits":!0,children:[(0,n.jsx)(sL,{title:"Model",selected:a,value:(s=sg.find(e=>e.id===a))?s.label:a.startsWith("claude-")?`Claude ${(0,sx.J)(a)}`:a,items:sg.map(e=>({id:e.id,label:e.label,defaultValue:e.id===sh})),onSelect:t=>{e.onClaudeModelChange?.(t);let r=sC(t);r&&e.onClaudeEffortChange?.(r),sy(t)||e.onClaudeFastModeChange?.(!1),sN(t)||e.onClaudeThinkingChange?.(!1)},icon:(0,n.jsx)(si.eV,{engine:"claude"}),testId:"claude-model-picker"}),d&&i.length>0&&(0,n.jsx)(sL,{title:"Reasoning",selected:d,value:sk(sp,d),items:i.map(e=>({...e,defaultValue:e.id===l})),onSelect:t=>e.onClaudeEffortChange?.(t),testId:"claude-reasoning-picker"}),sy(a)&&(0,n.jsx)(sL,{title:"Fast Mode",selected:c?"on":"off",value:c?"Fast On":"Fast Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeFastModeChange?.("on"===t),testId:"claude-fast-mode-picker"}),sN(a)&&(0,n.jsx)(sL,{title:"Thinking",selected:u?"on":"off",value:u?"Thinking On":"Thinking Off",items:[{id:"on",label:"On"},{id:"off",label:"Off",defaultValue:!0}],onSelect:t=>e.onClaudeThinkingChange?.("on"===t),testId:"claude-thinking-picker"})]})}var sP=r(6489);let s$=/^#\s+(.*)$/;function sT(e,t=[]){let r=new Map(t.map(e=>[e.name,e.id])),n=[];for(let[t,r]of e.split(/\r?\n/).entries()){let e=r.match(s$);if(e){n.push({name:e[1].trim(),line:t+1,body:[]});continue}let s=n[n.length-1];if(!s){if(r.trim())return{ok:!1,line:t+1,reason:"content-before-heading"};continue}s.body.push(r)}let s=new Set,o=[];for(let e of n){let t=e.body.join("\n").trim();if(!e.name||!t)return{ok:!1,line:e.line,reason:"empty-style"};if(s.has(e.name))return{ok:!1,line:e.line,reason:"duplicate-name"};s.add(e.name),o.push({id:r.get(e.name)??"",name:e.name,content:t})}return{ok:!0,styles:o}}function sR({styles:e,onSave:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(()=>e.map(e=>`# ${e.name}
34
34
  ${e.content}`).join("\n\n")),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),x=sT(l,e);(0,H.E)(r);let h=(0,s.useCallback)(async()=>{let n=sT(l,e);if(n.ok&&!d){if(c(!0),m(!1),await t(n.styles))return void r();c(!1),m(!0)}},[r,t,d,e,l]),f=a("chat.editOutputStyles");return(0,n.jsx)(b.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&r()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":f,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:f}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:a("chat.outputStylesMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:r,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":a("common.cancel"),children:(0,n.jsx)(ed.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),placeholder:a("chat.outputStylesMarkdownPlaceholder"),rows:24,spellCheck:!1,"data-testid":"output-styles-editor",className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:x.ok?u?a("chat.saveQuickInstructionsFailed"):"":a(`chat.outputStylesError.${x.reason}`,{line:x.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:r,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:a("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!x.ok||d,onClick:h,"data-testid":"output-styles-save",className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:a(d?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let sI=[],sF=sI,sB=!1,sD=null,sA=new Set,sH=e=>{sF=e,sA.forEach(e=>e())};function sW(e=!1){return sB&&!e?Promise.resolve():sD||(sD=(async()=>{let e=await u.t4.runPromiseExit((0,m.K4)());(sD=null,"Failure"===e._tag)?console.error("Failed to load output styles:",e.cause):(sB=!0,sH(e.value.styles??sI))})())}async function sz(e){let t=await u.t4.runPromiseExit((0,m.DF)(e));return"Failure"===t._tag?(console.error("Failed to save output styles:",t.cause),!1):(sB=!0,sH(t.value.styles??sI),!0)}let sO=e=>(sA.add(e),()=>{sA.delete(e)}),s_=()=>sF;function sq({value:e,onChange:t}){let{t:r}=(0,o.Bd)(),a=((0,s.useEffect)(()=>{sW()},[]),(0,s.useSyncExternalStore)(sO,s_,()=>sI)),l=(0,s.useRef)(null),i=(0,s.useRef)(null),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)({top:0,left:0}),f=(0,b.F2)(),p=a.find(t=>t.id===e),g=r("chat.outputStyleNone"),v=p?.name??g,j=(0,s.useCallback)(()=>{let e=l.current?.getBoundingClientRect();if(!e)return;let t=f?.getBoundingClientRect();h({top:e.bottom+4-(t?.top??0),left:e.left-(t?.left??0)})},[f]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;i.current?.contains(t)||l.current?.contains(t)||c(!1)};return document.addEventListener("mousedown",e),window.addEventListener("resize",j),window.addEventListener("scroll",j,!0),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("resize",j),window.removeEventListener("scroll",j,!0)}},[d,j]);let w=e=>{t(e),c(!1)},k=e=>`flex w-full items-start gap-2 px-3 py-2 text-left text-xs transition-colors ${e?si.yI:"text-muted-foreground hover:bg-hover hover:text-foreground"}`;return(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(si.XY,{buttonRef:l,label:v,labelMaxWidth:"max-w-[140px]",title:`${r("chat.outputStyle")}: ${v}`,onClick:()=>{d||(j(),sW(!0)),c(e=>!e)},icon:(0,n.jsx)(sP.A,{className:`h-3.5 w-3.5 flex-shrink-0 ${p?"text-brand":""}`}),testId:"output-style-picker"}),d&&(0,n.jsx)(b.ZL,{children:(0,n.jsxs)("div",{ref:i,className:`${si.ys} min-w-[200px] max-w-[320px]`,style:{top:x.top,left:x.left},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 pb-1",children:[(0,n.jsx)("span",{className:"text-[11px] font-medium text-muted-foreground",children:r("chat.outputStyle")}),(0,n.jsx)("button",{type:"button",onClick:()=>{c(!1),m(!0)},className:"p-1 text-muted-foreground hover:text-foreground rounded hover:bg-hover",title:r("chat.editOutputStyles"),"data-testid":"output-style-edit",children:(0,n.jsx)(nZ.A,{className:"w-3 h-3"})})]}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>w(""),className:k(!p),children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:!p})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:g})]}),a.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>w(e.id),className:k(p?.id===e.id),title:e.content,children:[(0,n.jsx)("span",{className:"mt-0.5",children:(0,n.jsx)(si.hG,{selected:p?.id===e.id})}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.name})]},e.id)),0===a.length&&(0,n.jsx)("div",{className:"px-3 py-2 text-[11px] text-muted-foreground",children:r("chat.noOutputStyles")})]})]})}),u&&(0,n.jsx)(sR,{styles:a,onSave:sz,onClose:()=>m(!1)})]})}let sV={CNY:"\xa5",USD:"$"};function sU({hasKey:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),x=(0,s.useCallback)(async()=>{a(!0),c(null);let e=await u.t4.runPromiseExit((0,m.he)());"Failure"===e._tag?(i(null),c(t("chat.balanceFailed",{defaultValue:"Query failed — check the API key"}))):i(e.value),a(!1)},[t]),h=l?l.balances.map(e=>`${sV[e.currency]??(e.currency?`${e.currency} `:"")}${e.totalBalance}`).join(" / "):"",f=!!(l&&!l.isAvailable);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[r&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!r&&d&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:d}),!r&&!d&&l&&(0,n.jsx)("span",{className:`text-xs font-mono ${f?"text-red-11":si.pe.deepseek}`,"data-tooltip":f?t("chat.balanceUnavailable",{defaultValue:"Account is not available for requests"}):void 0,"data-testid":"deepseek-balance-value",children:h||t("chat.balanceEmpty",{defaultValue:"No balance returned"})}),(0,n.jsx)("button",{type:"button","data-testid":"deepseek-balance-button",disabled:!e||r,onClick:x,"data-tooltip":e?void 0:t("chat.balanceNeedsKey",{defaultValue:"Set a DeepSeek API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:t("chat.checkBalance",{defaultValue:"Check balance"})}),(0,n.jsx)("a",{href:"https://platform.deepseek.com/usage",target:"_blank",rel:"noopener","data-testid":"deepseek-usage-link",title:t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),"aria-label":t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover 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:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}let sK={kimi:"https://www.kimi.com/code/console",glm:"https://bigmodel.cn/coding-plan/personal/usage"};function sQ(e){let t=e.remaining??"?",r=e.limit??"?";return`${e.label} ${t}/${r}`}function sG({engine:e,hasKey:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(!1),[i,d]=(0,s.useState)(null),[c,x]=(0,s.useState)(null),h=(0,s.useCallback)(async()=>{l(!0),x(null);let t=await u.t4.runPromiseExit((0,m.dM)(e));"Failure"===t._tag?(d(null),x(r("chat.quotaFailed",{defaultValue:"Quota unavailable — check the API key"}))):d(t.value),l(!1)},[r,e]),f=i?.windows??[],p=[i?.tier,...f.map(sQ)].filter(Boolean).join(" \xb7 "),g=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:`${t.getMonth()+1}/${t.getDate()} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}(f.reduce((e,t)=>t.resetTime&&(!e||t.resetTime>e)?t.resetTime:e,null)),b=f.some(e=>0===e.remaining);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[a&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!a&&c&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:c}),!a&&!c&&i&&(0,n.jsx)("span",{className:`text-xs font-mono ${b?"text-red-11":si.pe[e]}`,"data-tooltip":g?r("chat.quotaResetAt",{defaultValue:"Resets {{time}}",time:g}):void 0,"data-testid":`${e}-quota-value`,children:p||r("chat.quotaEmpty",{defaultValue:"No quota returned"})}),(0,n.jsx)("button",{type:"button","data-testid":`${e}-quota-button`,disabled:!t||a,onClick:h,"data-tooltip":t?void 0:r("chat.quotaNeedsKey",{defaultValue:"Set an API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:r("chat.checkQuota",{defaultValue:"Check quota"})}),(0,n.jsx)("a",{href:sK[e],target:"_blank",rel:"noopener","data-testid":`${e}-console-link`,title:r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),"aria-label":r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover 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:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}var sJ=r(67889),sY=r(46456);function sZ(e){if(0===e.length)return"";let t=[tM.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===eL.Un),n=e.filter(e=>e.filePath!==eL.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(tM.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 sX({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),i=(0,A.r)(),[d,c]=(0,s.useState)([]),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),[v,w]=(0,s.useState)(!1),k=(0,s.useCallback)(async()=>{if(!r)return;x(!0);let e=await u.t4.runPromiseExit((0,sY.$)(r));"Success"===e._tag?c(e.value.comments??[]):console.error("Failed to load comments:",e.cause),x(!1)},[r]);(0,s.useEffect)(()=>{e&&k()},[e,k]);let y=async e=>{let t=await u.t4.runPromiseExit((0,sY.Tu)(r,e));"Success"===t._tag?(c(t=>t.filter(t=>t.id!==e)),(0,eL.Cm)()):console.error("Failed to delete comment:",t.cause)},N=async e=>{f(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await u.t4.runPromiseExit((0,j.K)(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=sZ([n]);await navigator.clipboard.writeText(s),(0,T.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{f(null)}},C=async()=>{if(0!==d.length){g(!0);try{let e=await (0,eL.$3)(r),t=sZ(e);await navigator.clipboard.writeText(t),(0,T.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{g(!1)}}},S=async()=>{if(0!==d.length&&i&&!i.isLoading&&!v){w(!0);try{let e=(await (0,eL.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,eL.Gw)(e,"");i.sendMessage(n),await (0,eL.RP)(r),c([]),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 L=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim 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-lv3 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 ",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:C,disabled:p,className:"p-1 rounded hover:bg-hover text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:p?(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-hover 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:m?(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 border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===eL.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-hover 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(),N(e)},disabled:h===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground transition-opacity disabled:opacity-50",title:l("common.copy"),children:h===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(),y(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover 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 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:[i&&(0,n.jsx)("button",{onClick:S,disabled:0===d.length||i.isLoading||v,className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",title:i.isLoading?l("comments.aiResponding"):void 0,children:v?l("comments.submitting"):l("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===d.length||await (0,eL.RP)(r)&&c([])},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)(b.ZL,{children:L})}let s0=`${sJ.o} pl-3 pr-14 bg-card/50`;function s1({tabId:e,initialCwd:t,initialSessionId:r,engine:l,onEngineChange:i,ollamaModel:x,onOllamaModelChange:h,deepseekModel:g,onDeepseekModelChange:b,kimiModel:v,onKimiModelChange:j,glmModel:w,onGlmModelChange:k,claudeModel:y,onClaudeModelChange:N,claudeEffort:C,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:$,onCodexModelChange:R,codexReasoningEffort:I,onCodexReasoningEffortChange:F,planMode:B,onPlanModeChange:D,noHistory:A,onNoHistoryChange:H,outputStyle:W,onOutputStyleChange:z,hideHeader:O,hideSidebar:_,isActive:q=!0,isFocused:V=q,peerTabId:U,peerSide:K,refreshSignal:Q,onLoadingChange:G,onSessionIdChange:J,onTitleChange:Y,onBotChange:Z,onShowGitStatus:X,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:en,onOpenSession:es,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onOpenSessionBrowser:ei,onOpenSettings:ed}){let ec,{t:eu}=(0,o.Bd)(),em=(0,s.useContext)(a),[ex,eh]=(0,s.useState)(""),[ef,ep]=(0,s.useState)([]),eg=(0,ny.nH)(),[eb,ev]=(0,s.useState)([]),[ej,ew]=(0,s.useState)(null),[ek,ey]=(0,s.useState)(!1),[eN,eC]=(0,s.useState)(!1),[eS,eM]=(0,s.useState)(!1),eE=function(e){let[t,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!e)return void r(!1);let t=!1,n=async()=>{let n=await u.t4.runPromiseExit((0,sY.lb)(e));t||"Success"!==n._tag||r((n.value.comments?.length??0)>0)};n();let s=(0,eL.zL)(n);return()=>{t=!0,s()}},[e]),t}(t),[eP,e$]=(0,s.useState)(!1),[eT,eR]=(0,s.useState)(null),[eI,eF]=(0,s.useState)(!1),eB=B??eI,eD=(0,s.useCallback)(e=>{eF(e),D?.(e)},[D]),[eA,eH]=(0,s.useState)(!1),eW=A??eA,ez=(0,s.useCallback)(e=>{eH(e),H?.(e)},[H]),[eO,e_]=(0,s.useState)(""),eq=W??eO,eV=(0,s.useCallback)(e=>{e_(e),z?.(e)},[z]),[eU,eK]=(0,s.useState)(!1),eQ=(0,s.useRef)(null),eG=(0,s.useRef)(null),eJ=(0,s.useCallback)(async e=>{if(!t)return;let r=await u.t4.runPromiseExit((0,m.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?Y?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,Y]),eY=(0,s.useRef)(null),[eZ,eX]=(0,s.useState)(!1),[e0,e1]=(0,s.useState)(null),[e2,e5]=(0,s.useState)(null),[e4,e3]=(0,s.useState)(nH.R),e6=(0,s.useMemo)(()=>(0,nW.hC)(),[]),e8=(0,s.useRef)(!1);(0,s.useEffect)(()=>{e8.current=eZ},[eZ]);let{isLoadingHistory:e9,isLoadingMore:e7,hasMoreHistory:te,loadMoreHistory:tt,ensureTurnLoaded:tr,loadHistoryByCwdAndSessionId:tn,loadedSessionId:ts,loadedEngine:to,loadedBot:ta}=(0,nA.m)(eb,ev,ej,{cwd:t,initialSessionId:r,onSessionId:ew,onTitleChange:Y,onTokenUsage:eR,liveRunningRef:e8}),tl=to??l??void 0;(0,s.useEffect)(()=>{Z?.(ta)},[ta,Z]);let ti=!tl||"claude"===tl,td="codex"===tl,tc=y??sh,tu=sS(tc,C),tm=$??sf,tx=sw(tm,I),th="deepseek"===tl||"kimi"===tl||"glm"===tl?tl:null,tf="kimi"===th?v:"glm"===th?w:g,tp="kimi"===th?j:"glm"===th?k:b,tg="ollama"===tl||null!==th||ti||td;(0,s.useEffect)(()=>{to&&l!==to&&i?.(to)},[l,to,i]);let{isLoading:tb,tokenUsage:tv,liveOutputTokens:tj,runningStartedAt:tw,rateLimitInfo:tk,apiRetryInfo:ty,backgroundTasks:tN,handleSend:tC,handleStop:tS}=(0,nH.e)(eb,ev,{sessionId:ej,cwd:t,engine:tl,planMode:eB,noHistory:eW,outputStyleId:eq,ollamaModel:x,engineModel:tf,claudeModel:tc,claudeEffort:tu,claudeFastMode:M,claudeThinking:E,codexModel:tm,codexReasoningEffort:tx,onSessionId:ew,onFetchTitle:eJ,onRunComplete:()=>eY.current?.(),taskStore:e6}),tM=(0,s.useCallback)((...e)=>(eQ.current?.pinNextUserMessage(),tC(...e)),[tC]),tL=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(ti){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(eD(!1),(0,T.oR)(eu("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(eD(!0),(0,T.oR)(eu("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(eD(!0),tM(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void tM(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await u.t4.runPromiseExit((0,m.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=eu("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
35
35
 
36
36
  ${o}`),tM(n,r)}else tM(eu("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}tM(e,r)},[tM,t,eu,ti,eD]),tE=(0,s.useCallback)(()=>{eD(!1),tM(eu("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[tM,eD,eu]),tP=ts||ej,t$=q&&!tb&&!!tP;(0,nR.u)(tP,ev,t$,tl,{onRunningChange:e=>{e8.current=e,eX(e)},onLiveOutputTokens:e1,onRunStartedAt:e5,onBackgroundTasks:e=>e3(e.length?e:nH.R),taskStore:e6,onComplete:()=>{t&&tP&&tn(t,tP,!0,10)}}),(0,s.useEffect)(()=>{t$||(eX(!1),e1(null),e5(null),e3(nH.R))},[t$]),(0,s.useEffect)(()=>{eY.current=()=>{t&&tP&&tn(t,tP,!0,10)}},[t,tP,tn]);let tT=(0,s.useRef)(q);(0,s.useEffect)(()=>{q&&!tT.current&&ej&&t&&!tb&&!eZ&&tn(t,ej,!0,10),tT.current=q},[q,ej,t,tb,eZ,tn]);let tR=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!Q||Q.nonce===tR.current)return;tR.current=Q.nonce;let e=ej||ts;!t||!e||Q.sessionId!==ej&&Q.sessionId!==ts||tb||eZ||tn(t,e,!0,10,void 0,!0)},[Q,ej,ts,t,tb,eZ,tn]);let tI=tv||eT,tF=tb?tj:eZ?e0:null,tB=tb?tw:eZ?e2:null,tD=tb?tN:eZ?e4:nH.R;(0,s.useEffect)(()=>{ej&&J?.(ej)},[ej,J]);let tA=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(G?.(tb),tA.current&&!tb&&t&&ej){let e;for(let t=eb.length-1;t>=0;t--)if("user"===eb[t].role&&eb[t].content){e=eb[t].content.slice(0,100);break}(0,d.F)(c.n.SessionComplete,{cwd:t,sessionId:ej,lastUserMessage:e})}tA.current=tb},[tb,G,t]),(0,s.useEffect)(()=>{if(e&&eg&&(eg.setChatLoading(e,q&&tb),q))return()=>{eg.setChatLoading(e,!1)}},[e,tb,q,eg]),(0,s.useEffect)(()=>{if(e&&eg)return eg.registerChat(e=>{eG.current?.(e)},e),()=>{eg.unregisterChat(e)}},[e,eg]),(0,s.useEffect)(()=>{e&&q&&V&&eg&&eg.setActiveTab(e)},[e,q,V,eg]),(0,s.useEffect)(()=>{eG.current=tL},[tL]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ek&&(tb||eZ)&&tS()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ek,tb,eZ,tS]);let tH=(0,s.useCallback)(async(e,r)=>{let n=ts??ej;if(!t||!n)return;let s=await u.t4.runPromiseExit((0,m.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;es?es(e,"single"===r?"Excerpt":"Fork"):(0,d.F)(c.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,T.oR)("single"===r?eu("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):eu("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,ts,ej,es,eu]),tW=(0,s.useRef)(tH);tW.current=tH;let tz=(0,s.useRef)((e,t)=>tW.current(e,t)).current,tO=(0,s.useCallback)(async e=>{let r=ts??ej;if(!t||!r||tb||eZ)return;let n=Math.max(10,eb.filter(e=>"user"===e.role).length),s=await u.t4.runPromiseExit((0,m.$N)(r,{cwd:t,messageUuid:e}));"Success"===s._tag?(ev(t=>{let r=t.findIndex(t=>t.id===e);if(r<0)return t;let n=r;for(;n>=0&&"user"!==t[n].role;)n-=1;if(n<0)return t;let s=n+1;for(;s<t.length&&"user"!==t[s].role;)s+=1;return[...t.slice(0,n),...t.slice(s)]}),await tn(t,r,!1,n,void 0,!0),(0,T.oR)(eu("toast.turnDeleted",{defaultValue:"Turn deleted"}),"success")):(console.error("Delete turn failed:",s.cause),(0,T.oR)(eu("toast.deleteTurnFailed",{defaultValue:"Failed to delete this turn"}),"error"))},[t,ts,ej,tb,eZ,eb,tn,eu]),t_=(0,s.useRef)(tO);t_.current=tO;let tq=(0,s.useRef)(e=>t_.current(e)).current,tV=(0,s.useCallback)(e=>{if(U&&eg){if(!eg.sendToTab(U,e))return void(0,T.oR)(eu("toast.sendToPeerFailed",{defaultValue:"Failed to send to the other pane"}),"error");(0,T.oR)(eu("toast.sentToPeer",{defaultValue:"Sent to the other pane"}),"success")}},[U,eg,eu]),tU=(0,s.useRef)(tV);tU.current=tV;let tK=(0,s.useRef)(e=>tU.current(e)).current,tQ=(0,s.useCallback)(()=>{eM(!0)},[]),tG=(0,s.useCallback)(()=>{e$(!0)},[]),tJ=(0,s.useRef)(eb);tJ.current=eb;let tY=(0,s.useCallback)(async e=>{if(tJ.current.some(t=>t.id===e.id))return void eQ.current?.scrollToMessage(e.id);await tr(e.turnIndex);for(let t=0;t<30;t++)if(await new Promise(e=>requestAnimationFrame(()=>e())),eQ.current?.scrollToMessage(e.id))return},[tr]),tZ=(0,s.useMemo)(()=>{if(en&&t&&e)return r=>{en({...r,cwd:t,tabId:e,sessionId:ej??crypto.randomUUID(),engine:tl,..."ollama"===tl&&x&&{model:x},...th&&tf&&{model:tf},...ti&&{model:tc},...td&&{model:tm}})}},[en,t,e,ej,tl,x,th,tf,ti,tc,td,tm]),tX=tg?(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.noHistoryDesc",{defaultValue:"each prompt is independent"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:eW,onChange:e=>ez(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eW?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(n$.A,{className:"w-3.5 h-3.5"}),eu("chat.noHistory",{defaultValue:"No history context"})]})]}):null,t0=(0,n.jsx)(sq,{value:eq,onChange:eV});return(0,n.jsx)(nW.I$.Provider,{value:e6,children:(0,n.jsxs)("div",{className:`flex ${O&&_?"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:()=>ey(!0),onMouseLeave:()=>ey(!1),children:[!O&&(0,n.jsx)(nF,{cwd:t,sessionId:ej,engine:tl,onOpenProjectSessions:()=>eC(!0),onOpenSessionBrowser:ei,onOpenSettings:ed}),(ti||td)&&(0,n.jsxs)("div",{className:s0,children:[(0,n.jsx)(sE,{engine:td?"codex":"claude",claudeModel:tc,onClaudeModelChange:N,claudeEffort:tu,onClaudeEffortChange:S,claudeFastMode:M,onClaudeFastModeChange:L,claudeThinking:E,onClaudeThinkingChange:P,codexModel:tm,onCodexModelChange:R,codexReasoningEffort:tx,onCodexReasoningEffortChange:F}),ti&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":eu("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:eB,onChange:e=>eD(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eB?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(nT.A,{className:"w-3.5 h-3.5"}),eu("chat.planMode",{defaultValue:"Plan mode"})]})]}),tX,t0]}),"ollama"===tl&&(0,n.jsxs)("div",{className:s0,children:[h&&(0,n.jsx)(sc,{currentModel:x,onModelChange:h}),tX,t0]}),th&&(0,n.jsxs)("div",{className:s0,children:[tp&&(0,n.jsx)(sm,{engine:th,currentModel:tf,onModelChange:tp,onHasKeyChange:eK}),tX,t0,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===th?(0,n.jsx)(sU,{hasKey:eU}):(0,n.jsx)(sG,{engine:th,hasKey:eU})})]}),e9?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:eu("sessions.loadingHistory")})}):(0,n.jsx)(nz.M,{ref:eQ,messages:eb,isLoading:tb||eZ,liveOutputTokens:tF,runningStartedAt:tB,cwd:t,sessionId:ej,engine:tl,botName:ta,apiRetryInfo:ty,backgroundTasks:tD,hasMoreHistory:te,isLoadingMore:e7,onLoadMore:tt,onFork:tz,onDeleteTurn:tq,onSendToPeer:tK,peerSide:K,isActive:q,onContentSearch:eo,onShowFileDiff:ea,onOpenFileLink:el,onApprovePlan:tE,onShowUserMessages:tG}),tI&&(0,n.jsx)(nB,{tokenUsage:tI,rateLimitInfo:tk}),em&&!V?null:(ec=(0,n.jsx)(sl,{onSend:tL,disabled:tb||eZ,cwd:t,engine:tl,onShowGitStatus:X,onShowComments:t?tQ:void 0,hasComments:eE,onOpenNote:ee,isFavorite:et,onToggleFavorite:er,onCreateScheduledTask:tZ,draft:ex,setDraft:eh,draftImages:ef,setDraftImages:ep}),em?(0,p.createPortal)(ec,em):ec)]}),!O&&t&&(0,n.jsx)(f,{isOpen:eN,onClose:()=>eC(!1),cwd:t}),t&&(0,n.jsx)(sX,{isOpen:eS,onClose:()=>eM(!1),cwd:t}),(0,n.jsx)(nD,{isOpen:eP,onClose:()=>e$(!1),cwd:t,sessionId:ts??ej,onSelectMessage:tY})]})})}function s2({tabId:e,cwd:t,sessionId:r,engine:o,onEngineChange:a,ollamaModel:l,onOllamaModelChange:i,deepseekModel:d,onDeepseekModelChange:c,kimiModel:u,onKimiModelChange:m,glmModel:x,onGlmModelChange:h,claudeModel:f,onClaudeModelChange:p,claudeEffort:g,onClaudeEffortChange:b,claudeFastMode:v,onClaudeFastModeChange:j,claudeThinking:w,onClaudeThinkingChange:k,codexModel:y,onCodexModelChange:N,codexReasoningEffort:C,onCodexReasoningEffortChange:S,planMode:M,onPlanModeChange:L,noHistory:E,onNoHistoryChange:P,outputStyle:$,onOutputStyleChange:T,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onStateChange:A,onShowGitStatus:H,onOpenNote:W,isFavorite:z,onToggleFavorite:O,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K}){let Q=(0,s.useCallback)(t=>{A(e,{isLoading:t})},[e,A]),G=(0,s.useCallback)(t=>{A(e,{sessionId:t})},[e,A]),J=(0,s.useCallback)(t=>{A(e,{title:t})},[e,A]),Y=(0,s.useCallback)(t=>{A(e,{bot:t??void 0})},[e,A]),Z=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),X=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),ee=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),et=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),er=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),en=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),es=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),eo=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ea=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),el=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),ei=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),ed=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),ec=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),eu=(0,s.useCallback)(t=>{T?.(e,t)},[e,T]),em=(0,s.useCallback)(()=>{O?.(e)},[e,O]);return(0,n.jsx)(s1,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:Z,ollamaModel:l,onOllamaModelChange:X,deepseekModel:d,onDeepseekModelChange:ee,kimiModel:u,onKimiModelChange:et,glmModel:x,onGlmModelChange:er,claudeModel:f,onClaudeModelChange:en,claudeEffort:g,onClaudeEffortChange:es,claudeFastMode:v,onClaudeFastModeChange:eo,claudeThinking:w,onClaudeThinkingChange:ea,codexModel:y,onCodexModelChange:el,codexReasoningEffort:C,onCodexReasoningEffortChange:ei,planMode:M,onPlanModeChange:ed,noHistory:E,onNoHistoryChange:ec,outputStyle:$,onOutputStyleChange:eu,hideHeader:!0,hideSidebar:!0,isActive:R,isFocused:I,peerTabId:F,peerSide:B,refreshSignal:D,onLoadingChange:Q,onSessionIdChange:G,onTitleChange:J,onBotChange:Y,onShowGitStatus:H,onOpenNote:W,isFavorite:z,onToggleFavorite:r&&O?em:void 0,onCreateScheduledTask:_,onOpenSession:q,onContentSearch:V,onShowFileDiff:U,onOpenFileLink:K})}var s5=r(3292),s4=r(23121),s3=r(88292),s6=r(76900),s8=r(96472);function s9(e,t){if(!t.split)return{};let r=t.panes.indexOf(e);return -1===r?{}:{peerTabId:t.panes[1-r],peerSide:0===r?"right":"left"}}function s7({tabId:e,panes:t,activePane:r,row:s,maximized:a,onFocusPane:l,onClosePane:i,onToggleMaximize:d,children:c}){let{t:u}=(0,o.Bd)(),m=t.indexOf(e),x=t.length>1;return(0,n.jsxs)("div",{onMouseDownCapture:x?()=>l(m):void 0,style:s&&-1!==m&&!a?{order:m}:void 0,className:`group/pane ${function(e,t,r,n,s){let o=t.indexOf(e);if(-1===o)return"relative hidden";if(s)return"absolute inset-0 z-30 border-y border-y-transparent";if(!n)return"relative h-full block";let a=t.length>1?` border-y ${o===r?"border-y-brand":"border-y-transparent"}`:"";return`relative h-full flex-1 min-w-0${a}${o>0?" border-l border-border":""}`}(e,t,r,s,a)}`,children:[x&&-1!==m&&(0,n.jsxs)("div",{className:"absolute top-1 right-1 z-20 flex items-center gap-0.5 opacity-0 pointer-events-none transition-opacity focus-within:opacity-100 focus-within:pointer-events-auto group-hover/pane:opacity-100 group-hover/pane:pointer-events-auto",children:[(0,n.jsx)("button",{type:"button",onClick:()=>d(m),title:u(a?"chat.restorePane":"chat.maximizePane"),"aria-label":u(a?"chat.restorePane":"chat.maximizePane"),"aria-pressed":a,className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:a?(0,n.jsx)(nE.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(nP.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(m),title:u("chat.closePane"),"aria-label":u("chat.closePane"),className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",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"})})})]}),c]})}function oe({initialCwd:e,initialSessionId:t,initialBlank:r,initialView:a,initialFile:i,initialBubble:d}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(a??"agent"),[p,g]=(0,s.useState)(null),{tabs:v,activeTabId:j,activeTab:w,paneTabIds:k,activePane:y,toggleSideBySide:N,focusPane:C,closePane:S,unreadTabs:M,globalLoadingTabs:L,pageVisible:E,dragTabIndex:P,dragOverTabIndex:$,closeTab:T,closeAllTabs:R,switchTab:I,handleSelectSession:F,handleNewTab:B,handleNewCodexTab:D,handleNewKimiTab:A,handleNewGlmTab:H,handleNewOllamaTab:W,handleNewDeepseekTab:z,handleOpenSession:O,updateTabState:_,updateTabEngine:q,updateTabOllamaModel:V,updateTabDeepseekModel:U,updateTabKimiModel:K,updateTabGlmModel:Q,updateTabClaudeModel:G,updateTabClaudeEffort:J,updateTabClaudeFastMode:Y,updateTabClaudeThinking:Z,updateTabCodexModel:X,updateTabCodexReasoningEffort:ee,updateTabPlanMode:et,updateTabNoHistory:er,updateTabOutputStyle:en,handleTabDragStart:es,handleTabDragOver:eo,handleTabDrop:el,handleTabDragEnd:ei}=(0,nS.useTabState)({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:x}),{isPinned:ed,pinSession:ec,unpinSession:eu}=(0,s5.P)(),{createTask:em}=(0,s4.nS)(),ex=(0,s.useCallback)(e=>{let t=v.find(t=>t.id===e);return!!t?.sessionId&&ed(t.sessionId)},[v,ed]),eh=(0,s.useCallback)(t=>{let r=v.find(e=>e.id===t);r?.sessionId&&(ed(r.sessionId)?eu(r.sessionId):ec(r.sessionId,r.cwd||e||"",r.title))},[v,ed,ec,eu,e]),[ef,ep]=(0,s.useState)(!1),[eg,eb]=(0,s.useState)(!1),[ej,ew]=(0,s.useState)(!1),[ek,ey]=(0,s.useState)(null),[eN,eC]=(0,s.useState)(!1),[eS,eM]=(0,s.useState)("tree"),[eL,eE]=(0,s.useState)(0),[eP,e$]=(0,s.useState)(null),[eT,eR]=(0,s.useState)(0),[eI,eF]=(0,s.useState)(i?{path:i,nonce:0}:null),[eB,eD]=(0,s.useState)(d?{commandId:d,nonce:0}:null),eA=(0,s.useRef)(()=>{}),[eH,eW]=(0,s.useState)(null),ez=null!==eH,eO=(0,s.useMemo)(()=>{let e;return{panes:e=ez?[j]:k,activePane:ez?0:y,row:e.length>1||ez,split:e.length>1,diffOrder:e.length}},[k,y,j,ez]),[e_,eq]=(0,s.useState)(null),[eV,eU]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!a&&u.t4.runPromiseExit((0,s6.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&h(t.activeView)}})},[e,a]);let[eK,eQ]=(0,s.useState)(!1),eG=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eG.current=x,h("console"),eQ(!0)):(eQ(!1),eG.current&&"console"!==eG.current&&h(eG.current),eG.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[x]);let eJ=(0,s.useCallback)(t=>{h(t),e&&(u.t4.runFork((0,s6.Yn)({cwd:e,settings:{activeView:t}}).pipe(ev.NWQ(()=>ev.rIH))),u.t4.runFork(ev.qIB(s3.d,r=>r.publish(c.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>eJ("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[eJ]);let eY=(0,s.useCallback)(async()=>{if(!e)return;let t=await u.t4.runPromiseExit((0,s6.b2)(e));if("Success"===t._tag){let r=t.value;if(eC(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&ey(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>eY())},[eY]);let eZ=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&eY()},[eY]);(0,ea.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:eZ,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),eJ("agent")):"2"===e.key?(e.preventDefault(),eJ("explorer")):"3"===e.key?(e.preventDefault(),eJ("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"SESSION_NUMBERS",cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*")},[e,v]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eU(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eU(t.data.projectNumber),t.data?.type==="GET_SESSION_NUMBERS"&&t.data?.requestId&&e)return void window.parent.postMessage({type:"SESSION_NUMBERS",requestId:t.data.requestId,cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){F(r),n&&eJ("agent");let t=v.find(e=>e.sessionId===r);t&&eq(e=>({sessionId:r,nonce:(e?.nonce??0)+1})),e&&!t?.isLoading&&(u.t4.runFork((0,s8.KJ)(e,r,"normal").pipe(ev.NWQ(()=>ev.rIH))),u.t4.runFork((0,s8.M2)(r).pipe(ev.NWQ(()=>ev.rIH))))}}t.data?.type==="OPEN_FILE"&&"string"==typeof t.data?.path&&eA.current({path:t.data.path}),t.data?.type==="FOCUS_CONSOLE_BUBBLE"&&"string"==typeof t.data?.commandId&&(eJ("console"),eD(e=>({commandId:t.data.commandId,nonce:(e?.nonce??0)+1})))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[F,eJ,e,v]);let eX=(0,s.useCallback)(()=>{eM("status"),eE(e=>e+1),eJ("explorer")},[eJ]),e0=(0,s.useCallback)(e=>{e$(e),eR(e=>e+1),eJ("explorer")},[eJ]),e1=(0,s.useCallback)(()=>eJ("agent"),[eJ]),[e2,e5]=(0,s.useState)(!1);(0,s.useEffect)(()=>{ez||e5(!1)},[ez]);let[e4,e3]=(0,s.useState)(!1),e6=e4&&eO.split?eO.panes[eO.activePane]??null:null;(0,s.useEffect)(()=>{eO.split||e3(!1)},[eO.split]);let e8=(0,s.useCallback)(e=>{e3(e=>!e),C(e)},[C]),e9=(0,s.useCallback)(()=>e5(e=>!e),[]),e7=(0,s.useCallback)(()=>eW(null),[]),te=(0,s.useRef)(null),tt=(0,s.useCallback)(e=>{let t=te.current;if(!t)return;let r=e.offset>0&&null!==e.target&&t.contains(e.target);if("move"===e.phase){if(!r)return;let n=Math.min(.5*e.offset,t.offsetWidth);t.style.transition="none",t.style.transform=`translateX(${n}px)`;return}r&&e.triggered?(t.style.transition="transform 140ms ease-out, opacity 140ms ease-out",t.style.transform="translateX(100%)",t.style.opacity="0",window.setTimeout(e7,140)):(t.style.transition="transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1)",t.style.transform="")},[e7]);(0,s.useEffect)(()=>{let e=te.current;e&&(e.style.transition="",e.style.transform="",e.style.opacity="")},[eH]);let tr=(0,s.useRef)(ez);(0,s.useEffect)(()=>{tr.current=ez},[ez]);let tn=(0,s.useRef)(e6);(0,s.useEffect)(()=>{tn.current=e6},[e6]);let ts=(0,s.useCallback)(()=>{tr.current?e7():null!==tn.current?e3(!1):N()},[N,e7]),to=(0,s.useCallback)((e,t,r,n,s)=>{eW(o=>{var a;return a={messageId:e,toolCalls:t,cwd:r,sessionId:n},!0!==s?a:o?.messageId!==a.messageId?o:{...o,toolCalls:a.toolCalls}}),s||eJ("agent")},[eJ]),ta=(0,s.useCallback)(e=>{eF({...e,nonce:Date.now()}),eJ("explorer")},[eJ]);(0,s.useEffect)(()=>{eA.current=ta},[ta]);let tl=(0,s.useCallback)(()=>{e&&u.t4.runFork(ev.qIB(s3.d,t=>t.publish(c.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(ny.k_,{children:(0,n.jsx)(tF.fY,{activeView:x,onViewChange:eJ,onOverscroll:tt,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)(nM.TabManagerTopBar,{initialCwd:e,activeTab:w,isGitRepo:eN,currentBranch:ek,onOpenWorktree:()=>eb(!0),onOpenAliasManager:()=>ew(!0),onBranchSwitched:eY}),eK&&(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:"●"}),m("console.screenshotting")]}),e?(0,n.jsxs)(tF.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex flex-col",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewOllamaTab:W,onNewDeepseekTab:z,onOpenProjectSessions:()=>ep(!0),onDragStart:es,onDragOver:eo,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsxs)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:[v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:G,claudeEffort:e.claudeEffort,onClaudeEffortChange:J,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,"agent"===x,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,onShowGitStatus:eX,onContentSearch:e0,onShowFileDiff:to,onOpenFileLink:ta,onOpenNote:tl,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id)),eH&&(0,n.jsx)("div",{ref:te,"data-diff-column":"",className:e2?"absolute inset-0 z-30 bg-card":"h-full flex-1 min-w-0 border-l border-border",style:e2?void 0:{order:eO.diffOrder},children:(0,n.jsx)(nN.e$,{toolCalls:eH.toolCalls,cwd:eH.cwd,sessionId:eH.sessionId,onClose:e7,onContentSearch:e0,fullscreen:e2,onToggleFullscreen:e9},eH.messageId)})]})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(tB,{onClose:e1,cwd:e,initialTab:eS,tabSwitchTrigger:eL,initialSearchQuery:eP,searchQueryTrigger:eT,fileOpenRequest:eI})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(b.a9,{children:(0,n.jsx)(nk,{cwd:e,tabId:"default",onOpenNote:tl,focusBubble:eB})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nL.TabBar,{tabs:v,selectedTabId:j,sideBySide:eO.split,onToggleSideBySide:ts,unreadTabs:M,globalLoadingTabs:L,dragTabIndex:P,dragOverTabIndex:$,isPinned:ex,onSwitchTab:I,onCloseTab:T,onCloseAllTabs:R,onNewTab:B,onNewCodexTab:D,onNewKimiTab:A,onNewGlmTab:H,onNewDeepseekTab:z,onDragStart:es,onDragOver:eo,onDrop:el,onDragEnd:ei}),(0,n.jsx)(l,{value:eO.split?p:null,children:(0,n.jsx)("div",{className:`flex-1 overflow-hidden relative ${eO.row?"flex":""}`,children:v.map(e=>(0,n.jsx)(s7,{tabId:e.id,panes:eO.panes,activePane:eO.activePane,row:eO.row,maximized:e6===e.id,onFocusPane:C,onClosePane:S,onToggleMaximize:e8,children:(0,n.jsx)(s2,{tabId:e.id,...s9(e.id,eO),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:q,ollamaModel:e.ollamaModel,onOllamaModelChange:V,deepseekModel:e.deepseekModel,onDeepseekModelChange:U,kimiModel:e.kimiModel,onKimiModelChange:K,glmModel:e.glmModel,onGlmModelChange:Q,claudeModel:e.claudeModel,onClaudeModelChange:G,claudeEffort:e.claudeEffort,onClaudeEffortChange:J,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Y,claudeThinking:e.claudeThinking,onClaudeThinkingChange:Z,codexModel:e.codexModel,onCodexModelChange:X,codexReasoningEffort:e.codexReasoningEffort,onCodexReasoningEffortChange:ee,planMode:e.planMode,onPlanModeChange:et,noHistory:e.noHistory,onNoHistoryChange:er,outputStyle:e.outputStyle,onOutputStyleChange:en,isActive:nC(e.id,k,!0,E),isFocused:e.id===j,refreshSignal:e_,onStateChange:_,isFavorite:ex(e.id),onToggleFavorite:eh,onCreateScheduledTask:em,onOpenSession:O})},e.id))})}),eO.split&&(0,n.jsx)("div",{ref:g,className:"flex-shrink-0"})]})]}),e&&(0,n.jsx)(f,{isOpen:ef,onClose:()=>ep(!1),cwd:e,onSelectSession:F,projectNumber:eV,openSessionIds:v.map(e=>e.sessionId)}),e&&eN&&(0,n.jsx)(tD,{isOpen:eg,onClose:()=>eb(!1),cwd:e}),ej&&(0,n.jsx)(ns,{onClose:()=>ew(!1),onSave:()=>ew(!1)})]})})})}},96472:(e,t,r)=>{r.d(t,{KJ:()=>l,M2:()=>d,T$:()=>i,ej:()=>a,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.$mh({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.$mh({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.$mh({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,action:"status"})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=(e,t)=>n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,action:"touch"})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"touchRecentSession failed",cause:e})}),d=e=>n.$mh({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})})},96625:(e,t,r)=>{r.d(t,{V:()=>m,n:()=>u});var n=r(95155),s=r(12115),o=r(79114),a=r(58250),l=r(23348),i=r(33442),d=r(86957),c=r(83448);function u({value:e,onChange:t,textareaRef:r,extraCommands:n}){let[o,m]=(0,s.useState)(e.length),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)([]),[v,j]=(0,s.useState)(0),[w,k]=(0,s.useState)(()=>e.length>0),y=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.t4.runPromiseExit((0,c.M5)()).then(e=>{"Success"===e._tag?h(e.value):console.error("Failed to load commands:",e.cause)})},[]);let N=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,c.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;p((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)(()=>(N(),(0,a.U)(N)),[N]);let C=(0,s.useCallback)(async()=>{let e=await d.t4.runPromiseExit((0,l.jm)());"Success"===e._tag?b(e.value.flatMap(e=>e.valid?[{name:`@${e.name}`,description:e.description,source:"bot"}]:[])):console.error("Failed to load bots:",e.cause)},[]);(0,s.useEffect)(()=>(C(),(0,i.a)(C)),[C]);let S=(0,s.useMemo)(()=>{let t=0===o?0:e.lastIndexOf("\n",o-1)+1,r=e.indexOf("\n",o),n=-1===r?e.length:r;return{text:e.slice(t,n),start:t,end:n}},[e,o]),M=(0,s.useMemo)(()=>{let e=S.text.match(/^\s*(\/@|\/|@)([a-zA-Z0-9-]*)$/);return e?{marker:e[1],verb:e[2].toLowerCase()}:null},[S.text]),L=(0,s.useMemo)(()=>{if(!M)return[];let{verb:e}=M,t=t=>t.name.slice(1).toLowerCase().startsWith(e);return"@"===M.marker?g.filter(t):[...(n??[]).filter(t),...x.filter(t),...f.filter(t)]},[M,n,x,f,g]),E=!w&&!!M&&L.length>0,P=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{P.current!==e&&(queueMicrotask(()=>j(0)),w&&queueMicrotask(()=>k(!1)),P.current=e)},[e,w]),(0,s.useLayoutEffect)(()=>{if(E&&y.current){let e=y.current.children[v];e&&e.scrollIntoView({block:"nearest"})}},[v,E]);let $=(0,s.useCallback)(e=>{m(e.selectionStart??0)},[]),T=(0,s.useCallback)(n=>{let s=M?.marker??"/",o=`${s}${n.name.slice(1)} `,a=e.slice(0,S.start),l=e.slice(S.end),i=a.length+o.length;t(a+o+l),m(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,S,M,t,r]),R=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!E||0===L.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),j(e=>(e+1)%L.length),!0):"ArrowUp"===e.key?(t(),j(e=>(e-1+L.length)%L.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),T(L[v]),!0):"Escape"===e.key&&(t(),k(!0),!0)},[E,L,v,T]);return{isOpen:E,items:L,selectedIndex:v,marker:M?.marker??"/",listRef:y,selectCommand:T,handleKeyDown:R,trackCaret:$}}function m({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:a,selectedIndex:l,marker:i,listRef:d,selectCommand:c}=e;return s&&0!==a.length?(0,n.jsx)("div",{ref:d,className:`overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 ${t}`,children:a.map((e,t)=>{let s=t>0?a[t-1]:null,o="skill"===e.source&&(!s||"skill"!==s.source),d="bot"===e.source&&(!s||"bot"!==s.source),u="builtin"===e.source&&0===t;return(0,n.jsxs)("div",{children:[u&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),d&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Bots"}),(0,n.jsxs)("div",{onClick:()=>c(e),className:`px-4 py-2 cursor-pointer ${t===l?"bg-brand/10":"hover:bg-hover"}`,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:i+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?r(`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";case"bot":return"bg-teal-9/15 text-teal-11 dark:bg-teal-9/25 dark:text-teal-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill";case"bot":return"Bot"}})(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)})}):null}}}]);