@surething/cockpit 1.0.227 → 1.0.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next-prod/BUILD_ID +1 -1
- package/.next-prod/app-path-routes-manifest.json +2 -2
- package/.next-prod/build-manifest.json +2 -2
- package/.next-prod/prerender-manifest.json +3 -3
- package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_global-error.html +1 -1
- package/.next-prod/server/app/_global-error.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/_not-found.html +2 -2
- package/.next-prod/server/app/_not-found.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +2 -2
- package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
- package/.next-prod/server/app-paths-manifest.json +2 -2
- package/.next-prod/server/chunks/9658.js +1 -1
- package/.next-prod/server/middleware-build-manifest.js +1 -1
- package/.next-prod/server/pages/404.html +2 -2
- package/.next-prod/server/pages/500.html +1 -1
- package/.next-prod/server/server-reference-manifest.json +1 -1
- package/.next-prod/static/chunks/{217-259a6d7d3cac75d8.js → 217-ee98c428d2c2630a.js} +1 -1
- package/.next-prod/trace +13 -13
- package/.next-prod/trace-build +1 -1
- package/package.json +1 -1
- /package/.next-prod/static/{t45T3Imr0gQh7MYDeURiy → u_R4oaNwWvzUpY5No5EIX}/_buildManifest.js +0 -0
- /package/.next-prod/static/{t45T3Imr0gQh7MYDeURiy → u_R4oaNwWvzUpY5No5EIX}/_ssgManifest.js +0 -0
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
⚠️ ${r}`:`⚠️ ${r}`,isStreaming:!1}:e));return}if("stream_event"===r){N(e=>e?null:e),E(e=>e?null:e);let t=e.event;if(t?.type==="content_block_delta"&&t.delta?.type==="text_delta"){let e=t.delta.text||"";A.current&&A.current.messageId===n?A.current.text+=e:A.current={messageId:n,text:e},_.current||(_.current=setTimeout(F,50))}return}if("assistant"===r&&t(t=>(0,s.F)(t,e,{engine:u,assistantId:n})),"user"===r&&t(t=>(0,s.F)(t,e,{engine:u,assistantId:n})),"result"===r){N(null),_.current&&(clearTimeout(_.current),_.current=null),F();let r=P.current;r&&c&&t(e=>(2===e.length&&p(r),e));let l=e.usage,a=e.total_cost_usd;l&&w({inputTokens:l.input_tokens||0,outputTokens:l.output_tokens||0,cacheCreationInputTokens:l.cache_creation_input_tokens||0,cacheReadInputTokens:l.cache_read_input_tokens||0,totalCostUsd:a||0}),t(t=>(0,s.F)(t,e,{engine:u,assistantId:n}))}},[t,F,x,p,c,u,g]);return(0,a.h)({url:M?`/ws/session-stream?sessionId=${encodeURIComponent(M.runKey)}`:"/ws/session-stream",enabled:!!M,onMessage:e=>{$.current=!0,I.current&&(clearTimeout(I.current),I.current=null);let n=T.current;if(n)if("run-snapshot"===e.type&&Array.isArray(e.events)){for(let r of(_.current&&(clearTimeout(_.current),_.current=null),A.current=null,t(e=>e.map(e=>e.id===n.assistantId?{...e,content:"",toolCalls:[]}:e)),e.events))V(r,n.assistantId);e.status&&"running"!==e.status&&D()}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type)return void D();V(e.message,n.assistantId)}else"run-idle"===e.type&&D()}}),{isLoading:b,tokenUsage:y,rateLimitInfo:k,apiRetryInfo:C,ptyNotice:S,handleSend:(0,r.useCallback)(async(e,n,r)=>{let s=r&&"permissionMode"in r?"plan"===r.permissionMode:m,a=n?.map(e=>({type:"base64",media_type:e.media_type,data:e.data})),i={id:`user-${Date.now()}`,role:"user",content:e,images:a};t(e=>[...e,i]),v(!0),N(null),E(null);let x=`assistant-${Date.now()}`,p={id:x,role:"assistant",content:"",toolCalls:[],isStreaming:!0};t(e=>[...e,p]);let g=!u||"claude"===u||"claude2"===u,b="pty"===d&&g,y=function(){try{return crypto.randomUUID()}catch{return`run-${Date.now()}-${Math.floor(1e9*Math.random())}`}}();try{if("ollama"===u&&!h)throw Error("Please select an Ollama model first (click the model picker above)");let n="codex"===u?"/api/chat/codex":"kimi"===u?"/api/chat/kimi":"ollama"===u?"/api/chat/ollama":"deepseek"===u?"/api/chat/deepseek":"/api/chat",r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:e,sessionId:P.current,runId:y,images:a,cwd:c,language:l.A.language,..."ollama"===u&&h&&{model:h},..."deepseek"===u&&f&&{model:f},..."claude2"===u&&{engine:"claude2"},...b&&{mode:"pty",ptyCols:o.EE,ptyRows:o.K2},...s&&!b&&g&&{permissionMode:"plan"}})});if(400===r.status&&"deepseek"===u){let e=await r.json().catch(()=>null);throw Error(e?.error||"DeepSeek request failed")}if(!r.ok)throw Error(l.A.t("chat.requestFailed",{defaultValue:"Request failed"}));let i=await r.json().catch(()=>({}));R({runKey:i.runKey||y,assistantId:x}),$.current=!1,I.current&&clearTimeout(I.current),I.current=setTimeout(()=>{T.current&&!$.current&&(t(e=>e.map(e=>e.id!==x||e.content?e:{...e,content:l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."})})),D())},15e3)}catch(n){console.error("Chat error:",n);let e=n instanceof Error?n.message:l.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."});t(t=>t.map(t=>t.id===x?{...t,content:e,isStreaming:!1}:t)),v(!1),R(null)}},[c,u,d,m,h,f,t,D]),handleStop:O,abortControllerRef:L}}},22576:(e,t,n)=>{n.d(t,{X:()=>r});function r(e,t){let n=e.split("\n"),r=t.split("\n"),s=[],l=n.length,a=r.length,o=Array(l+1).fill(null).map(()=>Array(a+1).fill(0));for(let e=1;e<=l;e++)for(let t=1;t<=a;t++)n[e-1]===r[t-1]?o[e][t]=o[e-1][t-1]+1:o[e][t]=Math.max(o[e-1][t],o[e][t-1]);let i=l,c=a,u=[];for(;i>0||c>0;)i>0&&c>0&&n[i-1]===r[c-1]?(u.push({type:"unchanged",content:n[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||o[i][c-1]>=o[i-1][c])?(u.push({type:"added",content:r[c-1],newLineNum:c}),c--):(u.push({type:"removed",content:n[i-1],oldLineNum:i}),i--);for(;u.length>0;)s.push(u.pop());return s}},27570:(e,t,n)=>{n.d(t,{L:()=>s});var r=n(12115);function s({enabled:e,container:t,resolveLineRange:n,buildLineSnapshot:l,dragThresholdPx:a=5}){let o=(0,r.useRef)(null),i=(0,r.useRef)(()=>{}),c=(0,r.useRef)(n),u=(0,r.useRef)(l),d=(0,r.useRef)(a);return c.current=n,u.current=l,d.current=a,(0,r.useEffect)(()=>{if(!e||!t)return;let n=!1,r=0,s=0,l=()=>{o.current&&(o.current=null,i.current())},a=e=>{n=!0,r=e.clientX,s=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||l()},m=e=>{n=!1;let a=e.target;if(a?.closest?.(".floating-toolbar"))return;let m=d.current,h=Math.abs(e.clientX-r)>m||Math.abs(e.clientY-s)>m,f=window.getSelection();if(!f||f.isCollapsed||!f.toString().trim()||!h)return void l();let x=f.getRangeAt(0);if(!t.contains(x.commonAncestorContainer))return void l();let p=c.current(x.startContainer),g=c.current(x.endContainer);if(!p||!g)return void l();let b=Math.min(p.start,g.start),v=Math.max(p.end,g.end),y=f.toString(),w=u.current({start:b,end:v});o.current={x:e.clientX,y:e.clientY,range:{start:b,end:v},selectedText:y,lineSnapshot:w},i.current()},h=()=>{if(n||!o.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||l()};return t.addEventListener("mousedown",a),document.addEventListener("mouseup",m),document.addEventListener("selectionchange",h),()=>{t.removeEventListener("mousedown",a),document.removeEventListener("mouseup",m),document.removeEventListener("selectionchange",h)}},[e,t]),{toolbarRef:o,bumpRef:i,clearToolbar:()=>{o.current&&(o.current=null,i.current())}}}},37614:(e,t,n)=>{n.d(t,{t:()=>a});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,comment:n,container:o,onClose:i,onUpdateComment:c,onDeleteComment:u}){let{t:d}=(0,l.Bd)(),[m,h]=(0,s.useState)(!1),[f,x]=(0,s.useState)(n.content),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&o){let n=o.getBoundingClientRect(),r=p.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s+r.width>n.width-16&&(s=n.width-r.width-16),s<16&&(s=16),l+r.height>n.height-16&&(l=l-r.height-8),l<16&&(l=16),queueMicrotask(()=>b({x:s,y:l}))}},[e,t,o]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i]);let v=async()=>{f.trim()&&(await c(n.id,f.trim()),h(!1))},y=async()=>{await u(n.id),i()};return(0,r.jsx)("div",{ref:p,className:"absolute z-[200] w-96 bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:(0,r.jsx)("div",{className:"p-3",children:m?(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("textarea",{value:f,onChange:e=>x(e.target.value),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:3,autoFocus:!0,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),v()),"Escape"===e.key&&(h(!1),x(n.content))}}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)("button",{onClick:()=>{h(!1),x(n.content)},className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground",children:d("common.cancel")}),(0,r.jsx)("button",{onClick:v,className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90",children:d("common.save")})]})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:n.content}),(0,r.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:d("comments.lineRange",{start:n.startLine,end:n.endLine})}),(0,r.jsxs)("div",{className:"flex gap-1",children:[(0,r.jsx)("button",{onClick:()=>h(!0),className:"p-1 rounded hover:bg-accent text-muted-foreground",title:d("common.edit"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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"})})}),(0,r.jsx)("button",{onClick:y,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-red-9",title:d("common.delete"),children:(0,r.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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"})})})]})]})]})})})}},38408:(e,t,n)=>{n.d(t,{Cv:()=>P,XO:()=>A});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(86957),i=n(60938),c=n(70188),u=n(7320),d=n(56978),m=n(17196),h=n(89109),f=n(37614),x=n(69809),p=n(64428);function g({blame:e,onClick:t}){let{t:n}=(0,l.Bd)(),a=(0,s.useRef)(null),o=(0,s.useRef)(null),i=(0,p.F2)(),c=(0,s.useRef)(!1),u=(0,s.useRef)(!1),d=(0,s.useRef)(null),m=(0,s.useRef)(null),h=(0,s.useRef)(null),f=(0,s.useRef)(e);(0,s.useEffect)(()=>{f.current=e},[e]);let b=(0,s.useRef)(t);(0,s.useEffect)(()=>{b.current=t},[t]);let v=(0,s.useCallback)(()=>{let e,t=o.current,n=a.current;if(!t||!n)return;let r=n.getBoundingClientRect(),s=t.getBoundingClientRect(),l=i?.getBoundingClientRect(),c=l?.left??0,u=l?.top??0,d=l?.width??window.innerWidth,m=l?.height??window.innerHeight,h=r.left-c;h+s.width>d-8&&(h=d-s.width-8),h<8&&(h=8);let f=r.top-u,x=r.bottom-u;(e=f-s.height-4<0?x+4:f-s.height-4)+s.height>m-8&&(e=m-s.height-8),t.style.left=`${h}px`,t.style.top=`${e}px`},[i]),y=(0,s.useCallback)(()=>{d.current&&(clearTimeout(d.current),d.current=null),m.current&&(clearTimeout(m.current),m.current=null),c.current=!1,u.current=!1,o.current&&(o.current.style.display="none"),h.current&&(document.removeEventListener("mousedown",h.current.down),document.removeEventListener("mouseup",h.current.up),h.current=null)},[]),w=(0,s.useCallback)(()=>{let e=o.current;if(!e||c.current)return;c.current=!0,e.style.left="-9999px",e.style.top="-9999px",e.style.display="block",requestAnimationFrame(()=>requestAnimationFrame(v));let t=0,n=0,r=e=>{t=e.clientX,n=e.clientY},s=e=>{if(!(Math.abs(e.clientX-t)>5||Math.abs(e.clientY-n)>5)){let t;t=e.target,o.current?.contains(t)||a.current?.contains(t)||y()}};document.addEventListener("mousedown",r),document.addEventListener("mouseup",s),h.current={down:r,up:s}},[v,y]),k=(0,s.useCallback)(()=>{if(d.current&&clearTimeout(d.current),m.current&&(clearTimeout(m.current),m.current=null),c.current)return;let e=window.getSelection();(!e||e.isCollapsed)&&(d.current=setTimeout(w,500))},[w]),j=(0,s.useCallback)(()=>{d.current&&(clearTimeout(d.current),d.current=null),c.current&&(m.current=setTimeout(()=>{u.current||y()},200))},[y]),C=(0,s.useCallback)(()=>{u.current=!0,m.current&&(clearTimeout(m.current),m.current=null)},[]),N=(0,s.useCallback)(()=>{u.current=!1,y()},[y]),S=(0,s.useCallback)(e=>{e.stopPropagation();let t=window.getSelection();t&&t.toString().length>0&&o.current?.contains(t.anchorNode)||(b.current?.(f.current),y())},[y]);(0,s.useEffect)(()=>()=>y(),[y]);let E=e.message.split("\n")[0]||"",L=e.message.split("\n").slice(1).join("\n").trim();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("span",{ref:a,className:"select-none text-xs text-muted-foreground/50 ml-6 cursor-default hover:text-muted-foreground/80",onMouseEnter:k,onMouseLeave:j,children:[e.author.split(" ")[0],", ",function(e){let t=x.A.t,n=Math.floor((Date.now()-1e3*e)/1e3);if(n<60)return t("common.justNow");let r=Math.floor(n/60);if(r<60)return t("common.minutesAgo",{count:r});let s=Math.floor(r/60);if(s<24)return t("common.hoursAgo",{count:s});let l=Math.floor(s/24);if(l<30)return t("common.daysAgo",{count:l});let a=Math.floor(l/30);return a<12?t("common.monthsAgo",{count:a}):t("common.yearsAgo",{count:Math.floor(a/12)})}(e.time)," \xb7 ",E]}),(0,r.jsx)(p.ZL,{children:(0,r.jsxs)("div",{ref:o,className:"fixed z-[9999] bg-card border border-border rounded-lg shadow-xl p-3 text-xs text-foreground whitespace-pre-wrap max-w-md select-text",style:{display:"none",minWidth:280,cursor:"text"},"data-inline-blame-tip":"",onMouseEnter:C,onMouseLeave:N,children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,r.jsx)("span",{className:"font-mono text-brand",children:e.hash}),(0,r.jsx)("span",{className:"text-muted-foreground",children:e.author}),(0,r.jsx)("span",{className:"text-muted-foreground/60",children:new Date(1e3*e.time).toLocaleString()})]}),(0,r.jsx)("div",{className:"font-medium",children:E}),L&&(0,r.jsx)("div",{className:"mt-1 text-muted-foreground",children:L}),(0,r.jsx)("div",{className:"mt-2 text-[11px] text-brand border-t border-border pt-2 cursor-pointer hover:underline",onClick:S,children:n("codeViewer.clickToViewDetails")})]})})]})}let b=[{bg:"rgba(59, 130, 246, 0.15)",border:"rgb(59, 130, 246)"},{bg:"rgba(16, 185, 129, 0.15)",border:"rgb(16, 185, 129)"},{bg:"rgba(245, 158, 11, 0.15)",border:"rgb(245, 158, 11)"},{bg:"rgba(239, 68, 68, 0.15)",border:"rgb(239, 68, 68)"},{bg:"rgba(168, 85, 247, 0.15)",border:"rgb(168, 85, 247)"},{bg:"rgba(236, 72, 153, 0.15)",border:"rgb(236, 72, 153)"},{bg:"rgba(20, 184, 166, 0.15)",border:"rgb(20, 184, 166)"},{bg:"rgba(249, 115, 22, 0.15)",border:"rgb(249, 115, 22)"}];function v(e,t){let n,r=document.caretRangeFromPoint(e.clientX,e.clientY);if(!r||!t.contains(r.startContainer))return 1;let s=r.startContainer,l=r.startOffset,a=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),o=1;for(;n=a.nextNode();){if(n===s){o+=l;break}o+=n.textContent?.length||0}return o}let y=(0,s.memo)(function({virtualKey:e,lineNum:t,highlightedHtml:n,hasComments:a,firstComment:o,lineCommentsCount:i,isInRange:c,showLineNumbers:u,lineNumChars:d,commentsEnabled:m,virtualItemSize:h,virtualItemStart:f,onCommentBubbleClick:x,onCmdClick:p,onTokenHover:b,onTokenHoverLeave:y,flashLine:w,blameLine:k,showBlameInfo:j,blameAuthorColor:C,isBlameHovered:N,onBlameClick:S,onBlameMouseEnter:E,onBlameMouseLeave:L,inlineBlameData:M,onInlineBlameClick:R,isCursorLine:T,cursorCol:$}){let{t:I}=(0,l.Bd)(),P=(0,s.useMemo)(()=>T&&null!=$?function(e,t){let n=0,r=0;for(;r<e.length;){if("<"===e[r]){let t=e.indexOf(">",r);if(-1!==t){r=t+1;continue}}if(n===t){let t;if("&"===e[r]){let n=e.indexOf(";",r);t=-1!==n&&n-r<10?n+1:r+1}else t=r+1;let n=e.substring(r,t);return e.substring(0,r)+'<span class="vi-char-cursor">'+n+"</span>"+e.substring(t)}if("&"===e[r]){let t=e.indexOf(";",r);r=-1!==t&&t-r<10?t+1:r+1}else r++;n++}return e+'<span class="vi-char-cursor"> </span>'}(n,$):n,[n,T,$]),A=(0,s.useCallback)(e=>{if(!e.metaKey||!p)return;e.preventDefault(),e.stopPropagation();let n=e.currentTarget,r=v(e,n);window.getSelection()?.removeAllRanges(),p(t,r)},[t,p]),_=(0,s.useCallback)(e=>{if(!b||0!==e.buttons)return;let n=window.getSelection();if(n&&!n.isCollapsed)return;let r=e.target;if("SPAN"!==r.tagName||!r.style.color)return;let s=e.currentTarget,l=v(e,s),a=r.getBoundingClientRect();b(t,l,{x:a.left,y:a.bottom+4})},[t,b]),F=(0,s.useCallback)(()=>{k&&S&&S(k)},[k,S]),D=(0,s.useCallback)(e=>{k&&E&&E(k,e)},[k,E]);return(0,r.jsxs)("div",{"data-line":t,style:{position:"absolute",top:0,left:0,width:"100%",height:`${h}px`,transform:`translateY(${f}px)`,backgroundColor:N&&C?C.bg:void 0},className:`flex ${w===t?"flash-line":""} ${T?"vi-cursor-line":""} ${c?"bg-blue-9/20":a?"bg-amber-9/10":"hover:bg-accent/50"}`,children:[(0,r.jsxs)("div",{className:"flex shrink-0 sticky left-0 z-[2] bg-secondary",style:{backgroundColor:N&&C?C.bg:void 0},children:[k&&C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"w-1 flex-shrink-0",style:{backgroundColor:C.border}}),(0,r.jsx)("div",{className:"w-48 flex-shrink-0 px-2 flex items-center gap-2 border-r border-border text-muted-foreground cursor-pointer hover:bg-accent/50",onMouseEnter:D,onMouseLeave:L,onClick:F,title:I("codeViewer.clickToViewCommit"),children:j?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"font-medium",style:{color:C.border},children:k.hash}),(0,r.jsx)("span",{className:"truncate flex-1",children:k.author.split(" ")[0]})]}):null})]}),u&&(0,r.jsxs)("span",{className:`flex-shrink-0 flex items-center justify-end gap-0.5 pr-2 select-none border-r border-border font-variant-tabular ${c?"bg-blue-9/30 text-blue-11":"bg-card/50 text-slate-9"}`,children:[m&&a&&o&&(0,r.jsx)("button",{onClick:e=>x(o,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:I("codeViewer.nComments",{count:i}),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),m&&!a&&(0,r.jsx)("span",{className:"w-4"}),(0,r.jsx)("span",{className:"text-right",style:{minWidth:`${d}ch`},children:t})]})]}),(0,r.jsxs)("span",{className:"flex-1 px-3 whitespace-pre select-text",onClick:A,onMouseOver:_,onMouseLeave:y,"data-code-content":!0,children:[(0,r.jsx)("span",{dangerouslySetInnerHTML:{__html:P}}),M&&(0,r.jsx)(g,{blame:M,onClick:R})]})]},e)});var w=n(64702),k=n(1058),j=n(90717),C=n(48347),N=n(27570);function S(e,t,n){let r,s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),l=0;for(;(r=s.nextNode())&&r!==t;)l+=r.textContent.length;return l+n}function E(e,t){let n,r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=t,l=null;for(;n=r.nextNode();){l=n;let e=n.textContent.length;if(s<=e)return{node:n,offset:s};s-=e}return l?{node:l,offset:l.textContent.length}:null}var L=n(82292),M=n(34075);let R="white-space:pre;padding:0 12px;min-height:20px;line-height:20px";function T(e){let t=window.getSelection();if(!t?.rangeCount)return null;let n=t.getRangeAt(0),r=n.startContainer;for(;r&&r.parentElement!==e;)r=r.parentElement;if(!r)return null;let s=Array.from(e.children).indexOf(r);if(s<0)return null;let l=document.createRange();return l.selectNodeContents(r),l.setEnd(n.startContainer,n.startOffset),{line:s,offset:l.toString().length}}function $(e,t){let n,r=e.children[t.line];if(!r)return;let s=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),l=t.offset;for(;n=s.nextNode();){let e=n.textContent?.length||0;if(l<=e){let e=window.getSelection(),t=document.createRange();t.setStart(n,l),t.collapse(!0),e?.removeAllRanges(),e?.addRange(t);return}l-=e}let a=window.getSelection(),o=document.createRange();o.selectNodeContents(r),o.collapse(!1),a?.removeAllRanges(),a?.addRange(o)}function I(e){return e.map(e=>`<div style="${R}">${e}</div>`).join("")}let P=(0,s.forwardRef)(function({content:e,filePath:t,showLineNumbers:n=!0,showSearch:x=!0,className:p="",cwd:g,enableComments:v=!1,scrollToLine:P=null,scrollToLineAlign:A="center",onScrollToLineComplete:_,highlightKeyword:F=null,visibleLineRef:D,onCmdClick:O,onTokenHover:V,onTokenHoverLeave:B,onTokenHoverCancel:H,blameLines:W,inlineBlameLines:z,onSelectCommit:U,editable:K=!1,initialMtime:q,onEditorClose:X,onSaved:J,onEditorStateChange:Z,viMode:Y=!1,onContentMutate:Q,onEnterInsertMode:G,onViSave:ee,viStateRef:et,initialCursorLine:en,initialCursorCol:er,onInitialCursorSet:es,onContentSearch:el},ea){let{t:eo}=(0,l.Bd)(),ei=(0,s.useRef)(e),ec=(0,s.useRef)(!1),[eu,ed]=(0,s.useState)(!1),[em,eh]=(0,s.useState)(!1),[ef,ex]=(0,s.useState)(()=>e.split("\n").length),ep=(0,s.useRef)(e.split("\n").length),[eg,eb]=(0,s.useState)({show:!1}),ev=(0,s.useRef)(null),ey=(0,s.useRef)(null),ew=(0,s.useRef)(q),ek=(0,s.useRef)(null),ej=(0,s.useRef)(!1),eC=(0,s.useRef)(!1),{parentRef:eN,containerRef:eS,searchInputRef:eE,floatingToolbarRef:eL,suppressHoverRef:eM,bumpToolbarRef:eR,savedSelectionRef:eT,highlightedLines:e$,isMounted:eI,cmdHeld:eP,flashLine:eA,isSearchVisible:e_,searchQuery:eF,caseSensitive:eD,wholeWord:eO,currentMatchIndex:eV,viewingComment:eB,addCommentInput:eH,sendToAIInput:eW,aiBridge:ez,commentsEnabled:eU,updateComment:eK,deleteComment:eq,lines:eX,matches:eJ,rowData:eZ,virtualizer:eY,commentsByEndLine:eQ,linesWithComments:eG,setIsSearchVisible:e0,setSearchQuery:e1,setCaseSensitive:e2,setWholeWord:e5,setViewingComment:e4,setAddCommentInput:e3,setSendToAIInput:e8,goToNextMatch:e6,goToPrevMatch:e9,handleSearchKeyDown:e7,handleCommentBubbleClick:te,handleToolbarAddComment:tt,handleToolbarSendToAI:tn,handleToolbarSearch:tr,handleCommentSubmit:ts,handleSendToAISubmit:tl,getHighlightedLineHtml:ta,suppressMatchScrollRef:to,inlineBlameLineRef:ti,inlineBlameVersion:tc}=function({content:e,filePath:t,showSearch:n=!0,cwd:r,enableComments:l=!1,scrollToLine:a=null,scrollToLineAlign:o="center",onScrollToLineComplete:i,visibleLineRef:c,onContentSearch:u}){let[h,f]=(0,s.useState)(!1),x=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,C.r)();(0,s.useEffect)(()=>{f(!0)},[]);let[v,y]=(0,s.useState)(!1),[E,L]=(0,s.useState)(null),M=(0,s.useRef)(null),[R,T]=(0,s.useState)(!1),[$,I]=(0,s.useState)(""),[P,A]=(0,s.useState)(!1),[_,F]=(0,s.useState)(!1),[D,O]=(0,s.useState)(0),[V,B]=(0,s.useState)(0),H=(0,s.useRef)(!1),[W,z]=(0,s.useState)(null),U=(0,s.useRef)(!1),K=(0,s.useRef)(null),[q,X]=(0,s.useState)(null),[J,Z]=(0,s.useState)(null),Y=(0,s.useMemo)(()=>e.split("\n"),[e]),[Q,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{x.current!==Q&&G(x.current)});let ee=l&&!!r,{toolbarRef:et,bumpRef:en,clearToolbar:er}=(0,N.L)({enabled:ee,container:Q,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,n=t?.closest("[data-line]");if(!n)return null;let r=parseInt(n.getAttribute("data-line")||"0",10);return!Number.isFinite(r)||r<=0?null:{start:r,end:r}},buildLineSnapshot:({start:e,end:t})=>Y.slice(e-1,t).join("\n")}),es=(0,s.useRef)(null),[el,ea]=(0,s.useState)(0),{comments:eo,addComment:ei,updateComment:ec,deleteComment:eu,refresh:ed}=(0,k._)({cwd:r||"",filePath:t}),em=(0,d.C)(Y,t),eh=(0,s.useMemo)(()=>{let e=new Map;for(let t of eo){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[eo]),ef=(0,s.useMemo)(()=>{let e=new Set;for(let t of eo)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[eo]),ex=(0,s.useMemo)(()=>(0,m.Np)(Y,$,P,_),[Y,$,P,_]);(0,s.useEffect)(()=>{ex.length>0&&O(0)},[ex.length,$,P,_]);let ep=(0,s.useMemo)(()=>{let e=[];for(let t=0;t<Y.length;t++)e.push({type:"code",lineIndex:t});return e},[Y.length]),eg=(0,w.Te)({count:ep.length,getScrollElement:()=>x.current,estimateSize:()=>20,overscan:10});(0,s.useEffect)(()=>{if(!c)return;let e=x.current;if(!e)return;let t=()=>{if(!eg.range)return;let t=e.scrollTop;for(let e of eg.getVirtualItems())if(e.start>=t){let t=ep[e.index];t?.type==="code"&&(c.current=t.lineIndex+1);return}};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[c,ep]),(0,s.useEffect)(()=>{let e=e=>{"Meta"===e.key&&y(!0)},t=e=>{"Meta"===e.key&&y(!1)},n=()=>y(!1);return window.addEventListener("keydown",e),window.addEventListener("keyup",t),window.addEventListener("blur",n),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t),window.removeEventListener("blur",n)}},[]),(0,s.useEffect)(()=>{if(!n)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),T(!0),setTimeout(()=>g.current?.focus(),0)),"Escape"===e.key&&(R?(T(!1),I("")):J?Z(null):q?X(null):et.current?er():W&&z(null))},t=p.current;if(t)return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[n,R,J,q,W]),(0,s.useEffect)(()=>{if(H.current){H.current=!1;return}if(ex.length>0&&D>=0&&D<ex.length){let e=ex[D],t=ep.findIndex(t=>"code"===t.type&&t.lineIndex===e.lineIndex);t>=0&&eg.scrollToIndex(t,{align:"center"})}},[D,ex,eg,ep,V]);let eb=(0,s.useCallback)(()=>{0!==ex.length&&(O(e=>(e+1)%ex.length),B(e=>e+1))},[ex.length]),ev=(0,s.useCallback)(()=>{0!==ex.length&&(O(e=>(e-1+ex.length)%ex.length),B(e=>e+1))},[ex.length]),ey=(0,s.useRef)(a);ey.current=a,(0,s.useEffect)(()=>{if(null!==ey.current&&ey.current>0&&ep.length>0){let e=ey.current,t=e-1,n=ep.findIndex(e=>"code"===e.type&&e.lineIndex===t);if(n>=0){let t=()=>{eg.scrollToIndex(n,{align:o}),"center"===o&&(M.current&&clearTimeout(M.current),L(e),M.current=setTimeout(()=>L(null),500)),i?.()};"start"===o?requestAnimationFrame(t):setTimeout(t,150)}}},[a,o,ep.length,eg,i]);let ew=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ev():eb()),"Escape"===e.key&&(T(!1),I(""))},[eb,ev]),ek=(0,s.useCallback)((e,t)=>{ee&&(t.stopPropagation(),z({comment:e,x:t.clientX,y:t.clientY}),er(),X(null),Z(null))},[ee,er]);(0,s.useEffect)(()=>{if(!ee)return;let e=x.current,t=!1,n=()=>{t=!0,K.current=null,U.current=!0},r=()=>{t=!1;let e=window.getSelection();if(!e||e.isCollapsed||!e.toString().trim()){U.current=!1;return}let n=e.getRangeAt(0),r=x.current;if(!r||!r.contains(n.commonAncestorContainer))return;let s=n.startContainer,l=n.endContainer,a=(s.nodeType===Node.TEXT_NODE?s.parentElement:s)?.closest("[data-line]"),o=(l.nodeType===Node.TEXT_NODE?l.parentElement:l)?.closest("[data-line]");if(!a||!o)return;let i=parseInt(a.getAttribute("data-line")||"0",10),c=parseInt(o.getAttribute("data-line")||"0",10);i&&c&&(U.current=!0,K.current={startLine:i,startOffset:S(a,n.startContainer,n.startOffset),endLine:c,endOffset:S(o,n.endContainer,n.endOffset)})},s=()=>{if(t)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(K.current=null,U.current=!1)};return e?.addEventListener("mousedown",n),document.addEventListener("mouseup",r),document.addEventListener("selectionchange",s),()=>{e?.removeEventListener("mousedown",n),document.removeEventListener("mouseup",r),document.removeEventListener("selectionchange",s)}},[ee]),(0,s.useEffect)(()=>{let e=x.current;if(!e)return;let t=t=>{let n,r;if(!e.contains(t.target)){if(t.target.closest?.("[data-inline-blame-tip]"))return;null!==es.current&&(es.current=null,ea(e=>e+1));return}let s=window.getSelection();if(s&&!s.isCollapsed&&s.toString().trim())return;let l=(n=t.target,(r=n.closest?.("[data-line]"))?parseInt(r.getAttribute("data-line")||"0",10):null);l!==es.current&&(es.current=l,requestAnimationFrame(()=>ea(e=>e+1)))};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]);let ej=(0,s.useCallback)(()=>{let e=et.current;e&&(X({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,et]),eC=(0,s.useCallback)(()=>{let e=et.current;e&&(Z({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,et]),eN=(0,s.useCallback)(()=>{let e=et.current;if(!e||!u)return;let t=e.selectedText.trim();er(),t&&u(t)},[u,er,et]),eS=(0,s.useCallback)(async e=>{q&&(await ei(q.range.start,q.range.end,e,q.selectedText),X(null))},[q,ei]),eE=(0,s.useCallback)(async e=>{if(J&&b&&r)try{let n=await (0,j.$3)(r),s=[];for(let e of n)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:J.range.start,endLine:J.range.end,codeContent:J.lineSnapshot});let l=(0,j.Gw)(s,e);b.sendMessage(l),await (0,j.RP)(r),ed(),Z(null)}catch(e){console.error("Failed to send to AI:",e)}},[J,b,t,r,ed]),eL=(0,s.useCallback)((e,t,n)=>{let r=Y[e];if(!r)return t;let s=[];if($&&ex.length>0)for(let t of ex.filter(t=>t.lineIndex===e)){let n=ex[D]?.lineIndex===e&&ex[D]?.startCol===t.startCol;s.push({start:t.startCol,end:t.endCol,cls:n?"hl-cur":"hl-m"})}if(n&&!$&&n.length>=1){let e=n.toLowerCase(),t=r.toLowerCase(),l=0;for(;-1!==(l=t.indexOf(e,l));)s.push({start:l,end:l+n.length,cls:"hl-kw"}),l+=1}if(0===s.length)return t;s.sort((e,t)=>e.start-t.start||e.end-t.end);let l=[],a=0;for(let e of s){if(e.start<a)continue;e.start>a&&l.push((0,m.ZD)(r.substring(a,e.start)));let t=(0,m.ZD)(r.substring(e.start,e.end));l.push(`<span class="${e.cls}">${t}</span>`),a=e.end}if(a<r.length&&l.push((0,m.ZD)(r.substring(a))),t!==(0,m.ZD)(r)){let e=t;for(let t of s){let n=r.substring(t.start,t.end),s=(0,m.ZD)(n),l=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),a=RegExp(`(?<=>)([^<]*?)(${l})`,""),o=`$1<span class="${t.cls}">${s}</span>`,i=e.replace(a,o);i.length>e.length+200||(e=i)}return e}return l.join("")},[$,ex,D,Y]);return{parentRef:x,containerRef:p,searchInputRef:g,floatingToolbarRef:et,suppressHoverRef:U,savedSelectionRef:K,highlightedLines:em,isMounted:h,cmdHeld:v,flashLine:E,isSearchVisible:R,searchQuery:$,caseSensitive:P,wholeWord:_,currentMatchIndex:D,viewingComment:W,bumpToolbarRef:en,addCommentInput:q,sendToAIInput:J,aiBridge:b,commentsEnabled:ee,comments:eo,updateComment:ec,deleteComment:eu,lines:Y,matches:ex,rowData:ep,virtualizer:eg,commentsByEndLine:eh,linesWithComments:ef,setIsSearchVisible:T,setSearchQuery:I,suppressMatchScrollRef:H,setCaseSensitive:A,setWholeWord:F,setViewingComment:z,setAddCommentInput:X,setSendToAIInput:Z,goToNextMatch:eb,goToPrevMatch:ev,handleSearchKeyDown:ew,handleCommentBubbleClick:ek,handleToolbarAddComment:ej,handleToolbarSendToAI:eC,handleToolbarSearch:eN,handleCommentSubmit:eS,handleSendToAISubmit:eE,getHighlightedLineHtml:eL,inlineBlameLineRef:es,inlineBlameVersion:el}}({content:e,filePath:t,showSearch:x,cwd:g,enableComments:!K&&v,scrollToLine:K?null:P,scrollToLineAlign:K?"center":A,onScrollToLineComplete:K?void 0:_,visibleLineRef:K?void 0:D,onContentSearch:el}),tu=(0,c.iN)(),td=(0,s.useRef)(null),tm=(0,s.useRef)(null),th=(0,s.useRef)({line:0,col:0}),tf=(0,s.useRef)({line:0,col:0}),tx=function({lines:e,enabled:t,onContentChange:n,onEnterInsert:r,onSave:l,getVisibleLineCount:a,scrollToLine:o,onSearchExecute:i,onSearchNext:c,onSearchPrev:u,onSearchClear:d}){let[m,h]=(0,s.useState)("normal"),[f,x]=(0,s.useState)(-1),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(!1),[y,w]=(0,s.useState)(""),[k,j]=(0,s.useState)(""),[C,N]=(0,s.useState)(""),[S,E]=(0,s.useState)(""),L=(0,s.useRef)([]),M=(0,s.useRef)([]),R=(0,s.useRef)([]),T=(0,s.useRef)(null),$=(0,s.useRef)(e);(0,s.useEffect)(()=>{$.current=e}),(0,s.useEffect)(()=>{0!==e.length&&queueMicrotask(()=>x(t=>Math.min(t,e.length-1)))},[e.length]);let I=(0,s.useCallback)((e,t)=>Math.max(0,Math.min(t,Math.max(0,($.current[e]??"").length-1))),[]),P=(0,s.useRef)(e.length);(0,s.useEffect)(()=>{let t=Math.abs(e.length-P.current);P.current=e.length,t>10&&(queueMicrotask(()=>{x(-1),g(0),v(!1)}),L.current=[],M.current=[],R.current=[])},[e]);let A=(0,s.useCallback)(()=>{T.current&&(clearTimeout(T.current),T.current=null),w("")},[]),_=(0,s.useCallback)(()=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{w(""),T.current=null},500)},[]),F=(0,s.useCallback)((e,t)=>{L.current.push(t),M.current=[],v(!0),n(e.join("\n"))},[n]),D=(0,s.useCallback)((e,t)=>{let n=Math.max(0,Math.min(e,$.current.length-1));x(n),g(I(n,t??0)),o(n,"auto")},[o,I]),O=(0,s.useCallback)(e=>{x(t=>{let n=Math.max(0,Math.min(t+e,$.current.length-1));return o(n,"auto"),g(e=>Math.max(0,Math.min(e,Math.max(0,($.current[n]??"").length-1)))),n})},[o]),V=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1);if(0===e.length)return;let n=e[t];R.current=[n];let r=[...e];r.splice(t,1),0===r.length&&r.push("");let s=Math.min(t,r.length-1);F(r,{lineIndex:t,oldLines:[n],newLines:[],cursorLine:t}),x(s),g(0)},[f,F]),B=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1);e.length>0&&(R.current=[e[t]])},[f]),H=(0,s.useCallback)(()=>{let e=R.current;if(0===e.length)return;let t=$.current,n=Math.min(f,t.length-1)+1,r=[...t];r.splice(n,0,...e),F(r,{lineIndex:n,oldLines:[],newLines:[...e],cursorLine:f}),x(n),g(0),o(n,"auto")},[f,F,o]),W=(0,s.useCallback)(()=>{let e=$.current,t=Math.min(f,e.length-1),n=e[t];if(!n||0===n.length)return;let r=n.substring(1),s=[...e];s[t]=r,F(s,{lineIndex:t,oldLines:[n],newLines:[r],cursorLine:f})},[f,F]),z=(0,s.useCallback)(()=>{let e=L.current;if(0===e.length)return;let t=e.pop(),r=[...$.current];0===t.newLines.length&&t.oldLines.length>0?r.splice(t.lineIndex,0,...t.oldLines):0===t.oldLines.length&&t.newLines.length>0?(r.splice(t.lineIndex,t.newLines.length),0===r.length&&r.push("")):r.splice(t.lineIndex,t.newLines.length,...t.oldLines),M.current.push(t),n(r.join("\n")),x(Math.min(t.cursorLine,r.length-1)),o(Math.min(t.cursorLine,r.length-1),"auto"),0===e.length&&v(!1)},[n,o]),U=(0,s.useCallback)(()=>{let e=M.current;if(0===e.length)return;let t=e.pop(),r=[...$.current];0===t.newLines.length&&t.oldLines.length>0?(r.splice(t.lineIndex,t.oldLines.length),0===r.length&&r.push("")):0===t.oldLines.length&&t.newLines.length>0?r.splice(t.lineIndex,0,...t.newLines):r.splice(t.lineIndex,t.oldLines.length,...t.newLines),L.current.push(t),v(!0),n(r.join("\n"));let s=t.lineIndex+Math.max(0,t.newLines.length-1);x(Math.min(s,r.length-1)),o(Math.min(s,r.length-1),"auto")},[n,o]),K=(0,s.useCallback)(e=>{let t=$.current,n=Math.min(f,t.length-1);if("o"===e||"O"===e){let r="o"===e?n+1:n,s=[...t];s.splice(r,0,""),F(s,{lineIndex:r,oldLines:[],newLines:[""],cursorLine:f}),n=r,x(r)}h("insert"),r(n,p,e)},[f,p,F,r]),q=(0,s.useCallback)(()=>{h("normal"),A()},[A]),X=(0,s.useCallback)(()=>{h("command"),j("")},[]),J=(0,s.useCallback)(()=>{h("normal"),j("")},[]),Z=(0,s.useCallback)(()=>{h("search"),N("")},[]),Y=(0,s.useCallback)(()=>{h("normal"),N("")},[]),Q=(0,s.useCallback)(e=>{let t=e.trim();if("w"===t){l?.(),h("normal"),j("");return}if("q"===t){h("normal"),j("");return}if("wq"===t){l?.(),h("normal"),j("");return}if("noh"===t||"nohlsearch"===t){d?.(),h("normal"),j("");return}let n=parseInt(t,10);if(!isNaN(n)&&n>0){let e=Math.min(n-1,$.current.length-1);x(e),o(e,"center"),h("normal"),j("");return}h("normal"),j("")},[l,d,o]),G=(0,s.useCallback)(e=>{if(!e){h("normal"),N("");return}E(e),i?.(e),h("normal"),N("")},[i]),ee=(0,s.useCallback)(e=>{if(!t)return!1;let n=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;if("insert"===m)return("Escape"===e.key||!!n)&&(q(),!0);if("command"===m)return!e.isComposing&&("Escape"===e.key||n?J():"Enter"===e.key?Q(k):"Backspace"===e.key?0===k.length?J():j(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||j(t=>t+e.key),!0);if("search"===m)return!e.isComposing&&("Escape"===e.key||n?Y():"Enter"===e.key?G(C):"Backspace"===e.key?0===C.length?Y():N(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||N(t=>t+e.key),!0);if(f<0&&(x(0),g(0)),e.metaKey)return!1;if(e.ctrlKey)return"d"===e.key?(O(Math.max(1,Math.floor(a()/2))),A(),!0):"u"===e.key?(O(-Math.max(1,Math.floor(a()/2))),A(),!0):"r"===e.key&&(U(),A(),!0);let r=e.key,s=y+r;if("g"===s)return w("g"),_(),!0;if("gg"===s)return D(0),A(),!0;if("d"===s)return w("d"),_(),!0;if("dd"===s)return V(),A(),!0;if("y"===s)return w("y"),_(),!0;if("yy"===s)return B(),A(),!0;if(y&&s!==r&&A(),"j"===r||"ArrowDown"===r)return O(1),!0;if("k"===r||"ArrowUp"===r)return O(-1),!0;if("h"===r||"ArrowLeft"===r)return g(e=>Math.max(0,e-1)),!0;if("l"===r||"ArrowRight"===r){let e=Math.max(0,($.current[f]??"").length-1);return g(t=>Math.min(e,t+1)),!0}if("0"===r)return g(0),!0;if("$"===r)return g(Math.max(0,($.current[f]??"").length-1)),!0;if("^"===r){let e=($.current[f]??"").search(/\S/);return g(e>=0?e:0),!0}return"G"===r?(D($.current.length-1),!0):"x"===r?(W(),!0):"p"===r?(H(),!0):"u"===r?(z(),!0):"i"===r||"a"===r||"I"===r||"A"===r||"o"===r||"O"===r?(K(r),!0):"/"===r?(Z(),!0):"n"===r?(c?.(),!0):"N"===r?(u?.(),!0):":"===r?(X(),!0):"Escape"!==r&&1===r.length},[t,m,y,k,C,f,q,K,X,J,Z,Y,Q,G,O,D,a,V,B,H,W,z,U,A,_,c,u]);return{state:{mode:m,cursorLine:f,cursorCol:p,isDirty:b,keyBuffer:y,commandInput:k,searchInput:C,lastSearch:S},handleKeyDown:ee,enterNormal:q,enterInsert:K,setCursorLine:x,setCursorCol:g,setCommandInput:j,setSearchInput:N,setIsDirty:v,clearUndoHistory:(0,s.useCallback)(()=>{L.current=[],M.current=[]},[])}}({lines:eX,enabled:Y&&!K,onContentChange:e=>{th.current={line:tf.current.line,col:tf.current.col},Q?.(e)},onEnterInsert:(e,t,n)=>{let r=t;if("a"===n)r=t+1;else if("A"===n)r=(eX[e]??"").length;else if("I"===n){let t=(eX[e]??"").search(/\S/);r=t>=0?t:0}else("o"===n||"O"===n)&&(r=0);th.current={line:e,col:r},G?.(e)},onSave:ee,getVisibleLineCount:()=>{let e=eN.current;return e?Math.floor(e.clientHeight/20):20},scrollToLine:(e,t)=>{let n=eZ.findIndex(t=>"code"===t.type&&t.lineIndex===e);n>=0&&eY.scrollToIndex(n,{align:t||"auto"})},onSearchExecute:e=>{e1(e),e0(!1)},onSearchNext:e6,onSearchPrev:e9,onSearchClear:()=>{e1("")}});(0,s.useEffect)(()=>{et&&(et.current={cursorLine:tx.state.cursorLine,cursorCol:tx.state.cursorCol}),tf.current={line:tx.state.cursorLine,col:tx.state.cursorCol}},[et,tx.state.cursorLine,tx.state.cursorCol]);let tp=(0,s.useRef)(null);(0,s.useEffect)(()=>{Y&&!K&&null!=en&&t&&tp.current!==t&&(tp.current=t,tx.setCursorLine(en-1),null!=er&&tx.setCursorCol(er-1),es?.())},[Y,K,en,er,t]),(0,s.useEffect)(()=>{if(!Y||K)return;let e=eS.current;if(!e)return;let t=e=>{let t=e.target;"TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable||tx.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[Y,K,tx.handleKeyDown]),(0,s.useEffect)(()=>{if(!Y||K)return;let e=eS.current;e&&"normal"===tx.state.mode&&requestAnimationFrame(()=>{let t=document.activeElement;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||e.focus()})},[Y,K,tx.state.mode,e]);let tg=(0,s.useCallback)(e=>{if(!Y||K)return;let t=e.target.closest("[data-line]");if(t){let n=parseInt(t.getAttribute("data-line"),10);if(!isNaN(n)){tx.setCursorLine(n-1);let r=t.querySelector("[data-code-content]");if(r){let t=document.caretRangeFromPoint(e.clientX,e.clientY);if(t&&r.contains(t.startContainer)){let e,s=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),l=0;for(;e=s.nextNode();){if(e===t.startContainer){l+=t.startOffset;break}l+=e.textContent?.length||0}let a=eX[n-1]??"";tx.setCursorCol(Math.max(0,Math.min(l,Math.max(0,a.length-1))))}}}}let n=e.target;if("TEXTAREA"===n.tagName||"INPUT"===n.tagName||n.isContentEditable)return;let r=eS.current;r&&r.focus()},[Y,K,tx.setCursorLine,tx.setCursorCol,eX]),tb=(0,s.useCallback)(e=>{Y&&!K&&requestAnimationFrame(()=>{let e=window.getSelection(),t=e?.toString().trim();t&&/^\S+$/.test(t)&&(to.current=!0,e1(t))})},[Y,K,e1,to]);(0,s.useEffect)(()=>{"command"===tx.state.mode?setTimeout(()=>td.current?.focus(),0):"search"===tx.state.mode&&setTimeout(()=>tm.current?.focus(),0)},[tx.state.mode]),(0,s.useEffect)(()=>{let e=eN.current;if(!e)return;let t=()=>{(H??B)?.()};return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t)},[H,B]),(0,s.useEffect)(()=>{eH||eW?(eM.current=!0,B?.()):eL.current||(eM.current=!1)},[eH,eW,B]),(0,s.useLayoutEffect)(()=>{let e=eT.current;if(!e)return;let t=window.getSelection();if(t&&!t.isCollapsed)return;let n=eN.current;if(!n)return;let r=n.querySelector(`[data-line="${e.startLine}"]`),s=n.querySelector(`[data-line="${e.endLine}"]`);if(!r||!s)return;let l=E(r,e.startOffset),a=E(s,e.endOffset);if(l&&a)try{let e=document.createRange();e.setStart(l.node,l.offset),e.setEnd(a.node,a.offset),t?.removeAllRanges(),t?.addRange(e)}catch{}});let tv=(0,s.useCallback)((e,t,n)=>{eM.current||V?.(e,t,n)},[V]),ty=(0,s.useCallback)((e,t)=>{eM.current||O?.(e,t)},[O]),tw=Math.max(4,String(K?ef:eX.length).length),tk=(0,s.useMemo)(()=>{let e=0;for(let t of eX){let n=0;for(let e=0;e<t.length;e++)" "===t[e]?n+=2-n%2:n+=1;n>e&&(e=n)}return e},[eX]);(0,s.useEffect)(()=>{if(K){ei.current=e;let t=e.split("\n").length;ep.current=t,ex(t),ec.current=!1,ed(!1),eb({show:!1}),ew.current=q}},[K,e,q]),(0,s.useEffect)(()=>{if(!K)return;let t=ev.current;if(!t)return;let n=e.split("\n");t.innerHTML=I(n.map((e,t)=>e$[t]||(0,m.ZD)(e||" "))),requestAnimationFrame(()=>{let e,r;Y?(e=Math.max(0,Math.min(th.current.line,n.length-1)),r=th.current.col):(e=Math.max(0,Math.min((D?.current??1)-1,n.length-1)),r=0),t.focus(),$(t,{line:e,offset:r});let s=D?.current??1;ey.current&&(ey.current.scrollTop=(s-1)*20)})},[K]),(0,s.useEffect)(()=>{K&&Z?.({isDirty:eu,isSaving:em})},[K,eu,em,Z]);let tj=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return ei.current;let t=[];for(let n of e.childNodes){let e=n.textContent||"";t.push(" "===e?"":e)}return t.join("\n")},[]),tC=(0,s.useCallback)(()=>{ek.current&&clearTimeout(ek.current),ek.current=setTimeout(async()=>{let e=ev.current;if(e&&!eC.current){ei.current=tj();try{let n=await (0,m.kS)(),r=(0,m.sQ)(t),s=document.documentElement.classList.contains("dark"),l=ei.current.split("\n"),a=n.codeToTokens(l.join("\n"),{lang:r,theme:s?"github-dark":"github-light"}).tokens.map(e=>(0,m.b8)(e)),o=T(e);ej.current=!0,e.innerHTML=I(a),ej.current=!1,o&&$(e,o)}catch{}}},300)},[t,tj]);(0,s.useEffect)(()=>{if(K)return()=>{ek.current&&clearTimeout(ek.current)}},[K]);let tN=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return;ec.current||(ec.current=!0,ed(!0));let t=e.children.length;t!==ep.current&&(ep.current=t,ex(t))},[]),tS=(0,s.useCallback)(()=>{ej.current||eC.current||(tN(),tC())},[tN,tC]),tE=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&("Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," ")),"Enter"===e.key)){e.preventDefault();let t=ev.current;if(!t)return;let n=window.getSelection();if(!n?.rangeCount)return;let r=n.getRangeAt(0);r.deleteContents();let s=r.startContainer;for(;s&&s.parentElement!==t;)s=s.parentElement;if(!s||!(s instanceof HTMLElement))return;let l=T(t),a=Array.from(t.children).indexOf(s),o=s.textContent||"",i=l?.offset??o.length,c=o.substring(0,i),u=o.substring(i);s.innerHTML=(0,m.ZD)(c||" ");let d=document.createElement("div");d.setAttribute("style",R),d.innerHTML=(0,m.ZD)(u||" "),s.after(d),$(t,{line:a+1,offset:0}),tN(),tC()}},[tN,tC]),tL=(0,s.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)},[]),tM=(0,s.useCallback)(async(e=!1)=>{if(!g)return;ei.current=tj(),eh(!0);let n=await o.t4.runPromiseExit((0,i.OJ)({cwd:g,path:t,content:ei.current,expectedMtime:e?void 0:ew.current}));if("Failure"===n._tag){console.error("Error saving file:",n.cause),(0,M.oR)(eo("toast.saveFailed"),"error"),eh(!1);return}let r=n.value,s=r.data;if(409===r.status&&s?.conflict){let e=await o.t4.runPromiseExit((0,i.K9)(g,t));"Success"===e._tag&&e.value.ok&&"string"==typeof e.value.data?.content?eb({show:!0,diskContent:e.value.data.content}):eb({show:!0}),eh(!1);return}if(!r.ok){console.error("Error saving file: status",r.status),(0,M.oR)(eo("toast.saveFailed"),"error"),eh(!1);return}let l=s?.mtime;l&&(ew.current=l),ec.current=!1,ed(!1),eb({show:!1}),(0,M.oR)(eo("toast.savedSuccess"),"success"),J?.(),eh(!1)},[g,t,tj,J,eo]),tR=(0,s.useCallback)(async()=>{eu&&!em&&await tM(!1)},[eu,em,tM]),tT=(0,s.useCallback)(async()=>{eb({show:!1}),await tM(!0)},[tM]),t$=(0,s.useCallback)(()=>{if(void 0!==eg.diskContent){ei.current=eg.diskContent;let t=eg.diskContent.split("\n").length;ep.current=t,ex(t);let n=eg.diskContent!==e;ec.current=n,ed(n);let r=ev.current;r&&(r.innerHTML=I(eg.diskContent.split("\n").map(e=>(0,m.ZD)(e||" "))),tC())}eb({show:!1}),J?.()},[eg.diskContent,e,J,tC]),tI=(0,s.useCallback)(()=>{let e=ey.current;return e?Math.floor(e.scrollTop/20)+1:D?.current??1},[D]),tP=(0,s.useCallback)(async()=>{(!eu||await (0,M.lJ)(eo("codeViewer.unsavedConfirm"),{danger:!0,confirmText:eo("codeViewer.discardChanges"),cancelText:eo("codeViewer.continueEditing")}))&&X?.(tI())},[eu,X,tI]);(0,s.useEffect)(()=>{if(!K)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),tR())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[K,tR]);let tA=(0,s.useCallback)(()=>{let e=tj();Q?.(e);let t=ev.current,n=t?T(t):null,r=tI();if(tx.enterNormal(),n){tx.setCursorLine(n.line);let t=e.split("\n")[n.line]??"";tx.setCursorCol(Math.max(0,Math.min(n.offset,Math.max(0,t.length-1))))}else tx.setCursorLine(Math.max(0,r-1));X?.(r)},[tj,Q,tI,X,tx]);(0,s.useEffect)(()=>{if(!K)return;let e=e=>{let t="Escape"===e.key,n=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;(t||Y&&n)&&(e.preventDefault(),e.stopPropagation(),Y?ec.current?(0,M.lJ)(eo("codeViewer.unsavedExitConfirm"),{danger:!0,confirmText:eo("codeViewer.discardChanges"),cancelText:eo("codeViewer.continueEditing")}).then(e=>{e&&tA()}):tA():tP())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[K,Y,tP,tA]);let t_=(0,s.useCallback)(()=>{ec.current||(ec.current=!0,ed(!0))},[]);(0,s.useImperativeHandle)(ea,()=>({save:tR,close:tP,markDirty:t_,get isDirty(){return ec.current},get isSaving(){return em}}),[tR,tP,t_,em]);let tF=!!(W&&W.length>0),tD=(0,s.useMemo)(()=>{if(!W)return new Map;let e=[...new Set(W.map(e=>e.author))],t=new Map;return e.forEach((e,n)=>{t.set(e,b[n%b.length])}),t},[W]),[tO,tV]=(0,s.useState)(null),[tB,tH]=(0,s.useState)(null);(0,s.useEffect)(()=>{tV(null),tH(null)},[W]);let tW=(0,s.useCallback)((e,t)=>{tV(e.author);let n=t.currentTarget.getBoundingClientRect();tH({line:e,x:n.right+8,y:n.top})},[]),tz=(0,s.useCallback)(()=>{tV(null),tH(null)},[]),tU=(0,s.useCallback)(e=>{U&&(U({hash:e.hashFull,shortHash:e.hash,author:e.author,authorEmail:e.authorEmail,date:new Date(1e3*e.time).toISOString(),subject:e.message.split("\n")[0]||"",body:e.message.split("\n").slice(1).join("\n").trim(),time:e.time}),tH(null))},[U]),tK=`${tw+2}ch`;return(0,r.jsxs)("div",{ref:eS,className:`h-full flex flex-col outline-none ${p}`,tabIndex:0,onClick:tg,onDoubleClick:tb,children:[K&&eg.show&&(0,r.jsxs)("div",{className:"px-4 py-2 bg-amber-500/15 border-b border-amber-500/30 flex items-center gap-3 flex-shrink-0",children:[(0,r.jsx)("svg",{className:"w-5 h-5 text-amber-500 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,r.jsx)("span",{className:"text-sm text-foreground flex-1",children:eo("codeViewer.fileModifiedExternally")}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("button",{onClick:t$,className:"px-3 py-1 text-sm rounded border border-border hover:bg-accent transition-colors",children:eo("codeViewer.useDiskVersion")}),(0,r.jsx)("button",{onClick:tT,className:"px-3 py-1 text-sm rounded bg-amber-500 text-white hover:bg-amber-600 transition-colors",children:eo("codeViewer.forceOverwrite")})]})]}),!K&&x&&e_&&(0,r.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,r.jsx)("input",{ref:eE,type:"text",value:eF,onChange:e=>e1(e.target.value),onKeyDown:e7,placeholder:eo("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,r.jsx)("button",{onClick:()=>e2(!eD),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eD?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:eo("codeViewer.caseSensitive"),children:"Aa"}),(0,r.jsx)("button",{onClick:()=>e5(!eO),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eO?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:eo("codeViewer.wholeWordMatch"),children:"[ab]"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:eJ.length>0?`${eV+1}/${eJ.length}`:eo("common.noMatch")}),(0,r.jsx)("button",{onClick:e9,disabled:0===eJ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:eo("common.previous"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),(0,r.jsx)("button",{onClick:e6,disabled:0===eJ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:eo("common.next"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})}),(0,r.jsx)("button",{onClick:()=>{e0(!1),e1("")},className:"p-1 rounded hover:bg-accent",title:eo("common.close"),children:(0,r.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),K?(0,r.jsx)("div",{ref:ey,className:"flex-1 overflow-auto bg-secondary",children:(0,r.jsxs)("div",{className:"flex",style:{minHeight:"100%"},children:[(0,r.jsx)("div",{className:"flex-shrink-0 font-mono text-sm select-none sticky left-0 z-[2] bg-secondary",style:{width:tK},children:Array.from({length:ef},(e,t)=>(0,r.jsx)("div",{className:"text-right text-muted-foreground/50 pr-3",style:{height:20,lineHeight:"20px"},children:t+1},t))}),(0,r.jsx)("div",{ref:ev,contentEditable:!0,suppressContentEditableWarning:!0,onInput:tS,onKeyDown:tE,onPaste:tL,onCompositionStart:()=>{eC.current=!0},onCompositionEnd:()=>{eC.current=!1,tS()},spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",className:"flex-1 font-mono text-sm outline-none",style:{caretColor:"var(--foreground)",tabSize:2}})]})}):(0,r.jsx)("div",{ref:eN,className:`flex-1 overflow-auto font-mono text-sm bg-secondary${eP?" cmd-held-container":""}`,children:(0,r.jsx)("div",{style:{height:`${eY.getTotalSize()}px`,minWidth:"100%",width:tF?`calc(${tw+tk+10}ch + 13rem)`:`${tw+tk+10}ch`,position:"relative"},children:eY.getVirtualItems().map(e=>{let t=eZ[e.index];if("code"!==t.type)return null;let s=t.lineIndex,l=s+1,a=e$[s]||(0,m.ZD)(eX[s]||""),o=ta(s,a,F),i=eG.has(l),c=eQ.get(l),u=c?.[0],d=!!(eH&&l>=eH.range.start&&l<=eH.range.end),h=tc>=0?ti.current:null,f=!K&&z&&h===l?z[s]??null:null,x=tF?W[s]:void 0,p=tF&&s>0?W[s-1]:void 0,g=!!x&&(!p||p.hash!==x.hash),b=x?tD.get(x.author):void 0;return(0,r.jsx)(y,{virtualKey:e.key,lineNum:l,highlightedHtml:o,hasComments:i,firstComment:u,lineCommentsCount:c?.length,isInRange:d,showLineNumbers:n,lineNumChars:tw,commentsEnabled:eU,virtualItemSize:e.size,virtualItemStart:e.start,onCommentBubbleClick:te,onCmdClick:ty,onTokenHover:tv,onTokenHoverLeave:B,flashLine:eA,blameLine:x,showBlameInfo:g,blameAuthorColor:b,isBlameHovered:!!(x&&tO===x.author),onBlameClick:tU,onBlameMouseEnter:tW,onBlameMouseLeave:tz,inlineBlameData:f,onInlineBlameClick:tU,isCursorLine:Y&&!K&&tx.state.cursorLine===s,cursorCol:Y&&!K&&tx.state.cursorLine===s?tx.state.cursorCol:void 0},e.key)})})}),Y&&(0,r.jsxs)("div",{className:"vi-status-bar flex-shrink-0 h-6 bg-card border-t border-border flex items-center px-3 text-xs font-mono select-none",children:["normal"===tx.state.mode&&(0,r.jsx)("span",{className:"text-green-11 font-medium",children:"NORMAL"}),"insert"===tx.state.mode&&(0,r.jsx)("span",{className:"text-blue-11 font-medium",children:"INSERT"}),"command"===tx.state.mode&&(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("span",{className:"text-foreground",children:":"}),(0,r.jsx)("input",{ref:td,value:tx.state.commandInput,onChange:e=>tx.setCommandInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tx.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),"search"===tx.state.mode&&(0,r.jsxs)("div",{className:"flex items-center flex-1",children:[(0,r.jsx)("span",{className:"text-foreground",children:"/"}),(0,r.jsx)("input",{ref:tm,value:tx.state.searchInput,onChange:e=>tx.setSearchInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tx.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),tx.state.keyBuffer&&"normal"===tx.state.mode&&(0,r.jsx)("span",{className:"ml-2 text-muted-foreground",children:tx.state.keyBuffer}),tx.state.isDirty&&("normal"===tx.state.mode||"command"===tx.state.mode)&&(0,r.jsx)("span",{className:"ml-2 text-amber-11",children:"[+]"}),(0,r.jsxs)("span",{className:"ml-auto text-muted-foreground",children:[tx.state.cursorLine+1,":",tx.state.cursorCol+1]})]}),eI&&tu&&(0,a.createPortal)((0,r.jsxs)(r.Fragment,{children:[!K&&(0,r.jsx)(h.f,{floatingToolbarRef:eL,bumpRef:eR,container:tu,onAddComment:tt,onSendToAI:tn,onSearch:el?tr:void 0,isChatLoading:ez?.isLoading}),!K&&eH&&(0,r.jsx)(u.t,{x:eH.x,y:eH.y,range:eH.range,lineSnapshot:eH.lineSnapshot,container:tu,onSubmit:ts,onClose:()=>e3(null)}),!K&&eW&&(0,r.jsx)(u.G,{x:eW.x,y:eW.y,range:eW.range,filePath:t,lineSnapshot:eW.lineSnapshot,container:tu,onSubmit:tl,onClose:()=>e8(null),isChatLoading:ez?.isLoading}),!K&&eB&&(0,r.jsx)(f.t,{x:eB.x,y:eB.y,comment:eB.comment,container:tu,onClose:()=>e4(null),onUpdateComment:eK,onDeleteComment:eq}),tB&&(0,r.jsxs)("div",{className:"fixed z-50 bg-card border border-border rounded-lg shadow-lg p-3 max-w-lg",style:{left:Math.min(tB.x,window.innerWidth-450),top:Math.max(8,Math.min(tB.y,window.innerHeight-200))},children:[(0,r.jsxs)("div",{className:"flex items-start gap-3",children:[(0,r.jsx)("div",{className:"px-2 py-0.5 rounded text-xs font-mono font-medium text-white flex-shrink-0",style:{backgroundColor:tD.get(tB.line.author)?.border||"#666"},children:tB.line.hash}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-foreground",children:tB.line.author}),(0,r.jsx)("div",{className:"text-xs text-muted-foreground",children:tB.line.authorEmail})]})]}),(0,r.jsx)("div",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:tB.line.message}),(0,r.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground border-t border-border pt-2",children:[(0,L.fw)(tB.line.time)," \xb7 ",new Date(1e3*tB.line.time).toLocaleString(),(0,r.jsx)("span",{className:"ml-2 text-brand",children:eo("codeViewer.clickToViewDetails")})]})]})]}),tu)]})});function A({content:e,filePath:t,className:n=""}){let l=(0,s.useMemo)(()=>e.split("\n"),[e]),a=(0,d.C)(l,t),o=Math.max(4,String(l.length).length);return(0,r.jsx)("pre",{className:`overflow-auto text-sm font-mono bg-secondary p-2 ${n}`,children:l.map((e,t)=>(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"text-slate-9 select-none pr-4 text-right",style:{minWidth:`${o+2}ch`},children:t+1}),(0,r.jsx)("span",{className:"flex-1",dangerouslySetInnerHTML:{__html:a[t]||(0,m.ZD)(e||" ")}})]},t))})}},46456:(e,t,n)=>{n.d(t,{$:()=>i,BC:()=>c,Tu:()=>d,lb:()=>o,tj:()=>m,vv:()=>u});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),a=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:n=>new s.uV({message:`${t.method} ${e} failed`,cause:n})}),o=(e,t)=>l(`/api/comments?cwd=${encodeURIComponent(e)}${t?`&filePath=${encodeURIComponent(t)}`:""}`),i=e=>l(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`),c=e=>l("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),u=(e,t,n)=>l("/api/comments",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,id:t,content:n})}),d=(e,t)=>a(`/api/comments?cwd=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:"DELETE"}),m=e=>a(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`,{method:"DELETE"})},47215:(e,t,n)=>{n.d(t,{C6:()=>a,WU:()=>v,e$:()=>b,jU:()=>l,oK:()=>y,u:()=>g,xb:()=>o,zs:()=>x});var r=n(12115),s=n(69809);function l(e){try{return JSON.parse(e),!0}catch{return!1}}function a(e){try{let t=JSON.parse(e);return JSON.stringify(t,null,2)}catch{return e}}function o(e){try{let t=JSON.parse(e);return f(t,0)}catch{return e}}let i="#79c0ff",c="#a5d6ff",u="#ff7b72",d="#8b949e",m=(e,t)=>r.createElement("span",{style:{color:e}},t);function h({label:e,labelColor:t,value:n,indent:l}){let[a,o]=r.useState(!1),[i,u]=r.useState({x:0,y:0}),x="string"==typeof n&&n.replace(/\\n/g,"\n").split("\n").length>3,p={onMouseDown:e=>{u({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-i.x,n=e.clientY-i.y;t*t+n*n>25||(e.stopPropagation(),o(e=>!e))},style:{cursor:"pointer"}};if(x&&a&&"string"==typeof n){let l=n.replace(/\\n/g,"\n").split("\n")[0],a=n.replace(/\\n/g,"\n").split("\n").length;return r.createElement("span",p,m(t,e),m(d,": "),m(c,l),m("#6e7681",` ${s.A.t("toolCall.foldedLines",{count:a})}`))}let g=r.createElement(r.Fragment,null,m(t,e),m(d,": "),f(n,l));return x?r.createElement("span",p,g):g}function f(e,t){let n=" ".repeat(t);if(null===e)return m(u,"null");if(void 0===e)return m(u,"undefined");if("string"==typeof e)return m(c,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+n));if("number"==typeof e)return m("#79c0ff",String(e));if("boolean"==typeof e)return m(u,String(e));if(Array.isArray(e))return 0===e.length?m(d,"[]"):r.createElement(r.Fragment,null,m(d,"["),"\n",...e.map((s,l)=>r.createElement("span",{key:l},n+" ",r.createElement(h,{label:`[${l}]`,labelColor:i,value:s,indent:t+1}),l<e.length-1?r.createElement(r.Fragment,null,m(d,","),"\n"):"\n")),n,m(d,"]"));if("object"==typeof e){let s=Object.entries(e);return 0===s.length?m(d,"{}"):r.createElement(r.Fragment,null,m(d,"{"),"\n",...s.map(([e,l],a)=>r.createElement("span",{key:e},n+" ",r.createElement(h,{label:e,labelColor:i,value:l,indent:t+1}),a<s.length-1?r.createElement(r.Fragment,null,m(d,","),"\n"):"\n")),n,m(d,"}"))}return String(e)}function x(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path&&"string"==typeof t.old_string&&"string"==typeof t.new_string)return t}catch{}return null}let p=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function g(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return p.has(t)}function b(e){return e.toLowerCase().endsWith(".md")}function v(e,t){let n=t.startsWith("/")?[]:e.split("/").slice(0,-1);for(let e of t.replace(/^\//,"").split("/"))""!==e&&"."!==e&&(".."===e?n.pop():n.push(e));return n.join("/")}function y(e){try{let t=JSON.parse(e);if(t&&"string"==typeof t.file_path)return t.file_path}catch{let t=e.trim();if(t.startsWith("/")&&!t.includes("\n")&&t.length<500)return t}return null}},48347:(e,t,n)=>{n.d(t,{H:()=>a,r:()=>o});var r=n(95155),s=n(12115);let l=(0,s.createContext)(null);function a({value:e,children:t}){return(0,r.jsx)(l.Provider,{value:e,children:t})}function o(){return(0,s.useContext)(l)}},48948:(e,t,n)=>{n.d(t,{F:()=>r});function r(e,t,n){let{engine:r,assistantId:s}=n;if("stream_event"===t.type){let n=t.event;if(n?.type==="content_block_delta"&&n.delta?.type==="text_delta"&&n.delta.text){let t=n.delta.text;return e.map(e=>e.id===s?{...e,content:(e.content||"")+t}:e)}return e}if("assistant"===t.type){let n=t.message?.content;if(!Array.isArray(n))return e;let l=e,a=t.message?.model==="<synthetic>";if("codex"===r||"kimi"===r||"ollama"===r||a){let e=n.filter(e=>"text"===e.type&&e.text).map(e=>e.text).join("");e&&(l=l.map(t=>t.id===s?{...t,content:(t.content||"")+e}:t))}for(let e of n)if(e.name){let t={id:e.id||`tool-${s}-${e.name}`,name:e.name,input:e.input||{},isLoading:!0};l=l.map(e=>e.id!==s||e.toolCalls?.some(e=>e.id===t.id)?e:{...e,toolCalls:[...e.toolCalls||[],t]})}return l}if("user"===t.type){let n=t.message?.content;if(!Array.isArray(n))return e;let r=e;for(let e of n)if(e.tool_use_id){let t=e.tool_use_id,n="string"==typeof e.content?e.content:JSON.stringify(e.content);r=r.map(e=>e.id===s?{...e,toolCalls:e.toolCalls?.map(e=>e.id===t?{...e,result:n,isLoading:!1}:e)}:e)}return r}if("error"===t.type){let n=t.error||"An error occurred. Please try again.";return e.map(e=>e.id===s?{...e,content:e.content?`${e.content}
|
|
4
4
|
|
|
5
|
-
⚠️ ${n}`:`⚠️ ${n}`,isStreaming:!1}:e)}if("result"===t.type){let n="string"==typeof t.result?t.result.trim():"";return e.map(e=>e.id===s?{...e,content:!e.content&&n?n:e.content,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e)}return e}},50860:(e,t,n)=>{n.d(t,{I:()=>o});var r=n(95155),s=n(12115),l=n(86957),a=n(60938);function o(e){let{refreshKey:t,className:n="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:i}=e,c="absPath"in e&&"string"==typeof e.absPath,u=c?void 0:e.cwd,d=c?void 0:e.path,m=c?e.absPath:void 0,[h,f]=(0,s.useState)({kind:"loading"}),x=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++x.current;return f({kind:"loading"}),(async()=>{if(c){if(e!==x.current)return;f({kind:"ready",etag:null,size:0});return}let t=await l.t4.runPromiseExit((0,a.r6)(u,d));if(e!==x.current)return;if("Failure"===t._tag){let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;f({kind:"error",message:n instanceof Error?n.message:"Unknown error"});return}let n=t.value;if(!n.ok)return f({kind:"error",message:`stat failed (${n.status})`});let r=n.data;r&&r.exists?"too-large"===r.category?f({kind:"too-large",size:r.size??0}):"image"!==r.category?f({kind:"error",message:`Not an image (${r.category})`}):f({kind:"ready",etag:r.etag||`t-${r.mtimeMs??Date.now()}`,size:r.size??0}):f({kind:"missing"})})(),()=>{x.current++}},[c,u,d,m,t]),"loading"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(h.size/1024/1024)," MB)"]})});if("error"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-red-11",children:h.message})});let p=c?`/api/file?path=${encodeURIComponent(m)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(u)}&path=${encodeURIComponent(d)}&v=${encodeURIComponent(h.etag)}`;return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("img",{src:p,alt:i??(d||m),className:o})})}},56045:(e,t,n)=>{n.d(t,{_:()=>o,o:()=>a});var r=n(12115),s=n(69809);let l="json-search-highlight-style";function a(e){let[t,n]=(0,r.useState)(!1),[s,a]=(0,r.useState)(""),[o,i]=(0,r.useState)(!1),[c,u]=(0,r.useState)(0),[d,m]=(0,r.useState)(0),h=(0,r.useRef)(null),f=(0,r.useRef)([]),x=(0,r.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[];let n=e.current;if(!n||!s){u(0),m(0);return}!function(){if(document.getElementById(l))return;let e=document.createElement("style");e.id=l,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let r=n.textContent||"",a=o?s:s.toLowerCase(),i=o?r:r.toLowerCase(),c=[],d=0;for(;d<i.length;){let e=i.indexOf(a,d);if(-1===e)break;c.push([e,e+a.length]),d=e+1}if(0===c.length){u(0),m(0);return}let h=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),x=0,p=0,g=[],b=null,v=0;for(;(t=h.nextNode())&&p<c.length;){let e=t.textContent?.length||0,n=x,r=x+e;for(;p<c.length;){let[e,s]=c[p];if(e>=r)break;if(!b)if(e>=n)(b=document.createRange()).setStart(t,e-n),v=s;else break;if(v<=r)b.setEnd(t,v-n),g.push(b),b=null,p++;else break}x=r}f.current=g,u(g.length),m(e=>g.length>0?Math.min(e,g.length-1):0),CSS.highlights&&g.length>0&&CSS.highlights.set("json-search",new Highlight(...g))},[e,s,o]),p=(0,r.useCallback)((e,t)=>{let n=e.getBoundingClientRect();(t.top<n.top||t.bottom>n.bottom)&&(e.scrollTop+=t.top-n.top-n.height/2+t.height/2)},[]),g=(0,r.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let n=f.current[t];if(!n||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(n));let r=n.getBoundingClientRect(),s=e.current?.parentElement;s&&p(s,r)},[e,p]);(0,r.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,r.useEffect)(()=>{g(d)},[d,c,g]),(0,r.useEffect)(()=>{let t=e.current;if(!t||!s)return;let n=new MutationObserver(()=>x());return n.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>n.disconnect()},[e,s,x]),(0,r.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[])},[t]),(0,r.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let b=(0,r.useCallback)(()=>{0!==c&&m(e=>(e+1)%c)},[c]),v=(0,r.useCallback)(()=>{0!==c&&m(e=>(e-1+c)%c)},[c]),y=(0,r.useCallback)(()=>{n(!0),setTimeout(()=>h.current?.focus(),0)},[]),w=(0,r.useCallback)(()=>{n(!1),a(""),m(0)},[]),k=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?v():b()),"Escape"===e.key&&(e.preventDefault(),w())},[b,v,w]);return{isVisible:t,query:s,setQuery:a,caseSensitive:o,setCaseSensitive:i,matchCount:c,currentIndex:d,searchInputRef:h,open:y,close:w,goToNext:b,goToPrev:v,handleKeyDown:k}}function o({search:e}){return e.isVisible?r.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},r.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:s.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),r.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:s.A.t("codeViewer.caseSensitive")},"Aa"),r.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:s.A.t("common.noMatch")),r.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.previous")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),r.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.next")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),r.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:s.A.t("common.close")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}},56978:(e,t,n)=>{n.d(t,{C:()=>l});var r=n(12115),s=n(17196);function l(e,t){let[n,l]=(0,r.useState)(null),[a,o]=(0,r.useState)(!1);(0,r.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()},[]);let i=(0,r.useMemo)(()=>e.join("\n"),[e]),c=`${i}:${t}:${a}`,u=(0,r.useMemo)(()=>n&&n.key===c?n.html:e.map(e=>(0,s.ZD)(e||" ")),[e,c,n]);return(0,r.useEffect)(()=>{if(0===e.length)return;let n=!1;return(async()=>{try{let r=await (0,s.kS)();if(n)return;let o=(0,s.sQ)(t),i=e.join("\n"),u=r.codeToTokens(i,{lang:o,theme:a?"github-dark":"github-light"}),d=[];for(let e=0;e<u.tokens.length;e++)if(d[e]=(0,s.b8)(u.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),n))return;l({key:c,html:d})}catch(e){console.error("Line highlight error:",e)}})(),()=>{n=!0}},[i,t,a]),u}},60938:(e,t,n)=>{n.d(t,{DZ:()=>c,Ft:()=>h,K9:()=>p,Nn:()=>w,OJ:()=>b,VK:()=>k,YW:()=>m,__:()=>y,dt:()=>v,eA:()=>g,eE:()=>f,gZ:()=>u,mP:()=>i,nM:()=>j,r6:()=>x,r9:()=>d});var r=n(49433),s=n(82680);let l=(e,t={})=>r.tryPromise({try:async()=>{let n=await fetch(e,t.init);if(t.passThroughStatuses&&t.passThroughStatuses.includes(n.status))return await n.json().catch(()=>({}));if(!n.ok){let e;try{e=(await n.json()).error}catch{}throw Error(e||`HTTP ${n.status}`)}return await n.json()},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),a=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t),r=null;try{r=await n.json()}catch{}return{status:n.status,ok:n.ok,data:r}},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),o=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),i=e=>l(`/api/files/init?cwd=${encodeURIComponent(e)}`),c=e=>l(`/api/files/index?cwd=${encodeURIComponent(e)}`),u=(e,t)=>l(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),d=e=>l(`/api/files/recent?cwd=${encodeURIComponent(e)}`),m=(e,t,n)=>o("/api/files/recent",{cwd:e,file:t,...n??{}}),h=(e,t)=>o("/api/files/expanded",{cwd:e,paths:t}),f=(e,t)=>l(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`).pipe(r.catchAll(e=>r.succeed({error:e.message}))),x=(e,t)=>a(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),p=(e,t)=>a(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),g=e=>l(`/api/files/text?${e.toString()}`),b=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=null;try{n=await t.json()}catch{}return{status:t.status,ok:t.ok,data:n}},catch:e=>new s.uV({message:"POST /api/files/save failed",cause:e})}),v=()=>l("/api/files/clipboard"),y=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/clipboard",{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:"POST /api/files/clipboard failed",cause:e})}),w=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/paste failed",cause:e})}),k=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/delete failed",cause:e})}),j=e=>l(`/api/file?path=${encodeURIComponent(e)}`)},65153:(e,t,n)=>{n.d(t,{u:()=>a});var r=n(12115),s=n(2111),l=n(48948);function a(e,t,n,a,o){let i=(0,r.useRef)(null),c=(0,r.useRef)(0),u=()=>{let e=`live-asst-${++c.current}`;return i.current=e,t(t=>[...t,{id:e,role:"assistant",content:"",isStreaming:!0}]),e},d=e=>{if("system"===e.type&&"init"===e.subtype)return void u();if("user"===e.type&&e._human){let n=e.message?.content,r="string"==typeof n?n:Array.isArray(n)?n.map(e=>e?.text||"").join(""):"",s=`live-user-${++c.current}`;t(e=>{for(let t=e.length-1;t>=0;t--)if("user"===e[t].role){if(e[t].content===r)return e;break}return[...e,{id:s,role:"user",content:r}]});return}let n=i.current??u();t(t=>(0,l.F)(t,e,{engine:a,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void o?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"";for(let n of(t(e=>{let t=e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("live-")));if(s){let e=t[t.length-1];if(e&&"user"===e.role&&e.content===s)return t.slice(0,t.length-1)}return t}),i.current=null,c.current=0,e.events))d(n);o?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){o?.onRunningChange?.(!1),o?.onComplete?.();return}d(e.message),o?.onRunningChange?.(!0)}else"run-idle"===e.type&&o?.onRunningChange?.(!1)}})}},67362:(e,t,n)=>{n.d(t,{xU:()=>j,xZ:()=>k});var r=n(95155),s=n(12115),l=n(47650),a=n(79114),o=n(64702),i=n(1058),c=n(90717),u=n(70188),d=n(48347),m=n(89109),h=n(7320),f=n(22576),x=n(34075),p=n(56978),g=n(17196);function b({lines:e,containerRef:t}){let n=(0,s.useRef)(null),[l,a]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let r=()=>{let{scrollTop:t,scrollHeight:r,clientHeight:s}=e,l=n.current?.clientHeight||0;if(r<=s)a({top:0,height:l});else{let e=l/r;a({top:t*e,height:s*e})}};return r(),e.addEventListener("scroll",r),window.addEventListener("resize",r),()=>{e.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[t]),0===e.length)return null;let o=100/e.length;return(0,r.jsxs)("div",{ref:n,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let r=t.current,s=n.current;if(!r||!s)return;let l=s.getBoundingClientRect(),a=(e.clientY-l.top)/l.height*r.scrollHeight-r.clientHeight/2;r.scrollTo({top:Math.max(0,a),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,r.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*o}%`,height:`${Math.max(o,.5)}%`,minHeight:"2px"}},t)),(0,r.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${l.top}px`,height:`${Math.max(l.height,10)}px`}})]})}var v=n(37614),y=n(27570);function w(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}function k({oldContent:e,newContent:t,filePath:n,isNew:j=!1,isDeleted:C=!1,cwd:N,enableComments:S=!1,onPreview:E,previewLabel:L,onContentSearch:M,targetLine:R,compact:T=!1,symbols:$}){let{t:I}=(0,a.Bd)(),P=L??I("common.preview"),A=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),_=(0,s.useRef)(null),F=(0,s.useRef)(null),D=(0,s.useRef)(null),O=(0,s.useRef)(!1),[V,B]=(0,s.useState)(!1),H=(0,u.iN)(),W=(0,d.r)(),z=S&&!!N,{comments:U,addComment:K,updateComment:q,deleteComment:X,refresh:J}=(0,i._)({cwd:N||"",filePath:n}),[Z,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{D.current!==Q&&G(D.current)});let{toolbarRef:ee,bumpRef:et,clearToolbar:en}=(0,y.L)({enabled:z,container:Q,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,n=t?.closest("[data-new-line]");if(!n)return null;let r=parseInt(n.getAttribute("data-new-line")||"0",10);return!Number.isFinite(r)||r<=0?null:{start:r,end:r}},buildLineSnapshot:({start:e,end:t})=>{let n=[],r=0;for(let s of A)("unchanged"===s.type||"added"===s.type)&&++r>=e&&r<=t&&n.push(s.content);return n.join("\n")}}),[er,es]=(0,s.useState)(null),[el,ea]=(0,s.useState)(null);(0,s.useEffect)(()=>{B(!0)},[]);let eo=(0,s.useMemo)(()=>{let e=new Set;for(let t of U)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[U]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of U){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[U]),ec=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),en(),es(null),ea(null)},[en]),eu=(0,s.useCallback)(()=>{let e=ee.current;e&&(es({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),ed=(0,s.useCallback)(()=>{let e=ee.current;e&&(ea({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),em=(0,s.useCallback)(()=>{let e=ee.current;if(!e||!M)return;let t=e.selectedText.trim();en(),t&&M(t)},[M,en,ee]),eh=(0,s.useCallback)(async e=>{if(el&&W&&N)try{let t=await (0,c.$3)(N),r=[];for(let e of t)r.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});r.push({filePath:n,startLine:el.range.start,endLine:el.range.end,codeContent:el.lineSnapshot});let s=(0,c.Gw)(r,e);W.sendMessage(s),await (0,c.RP)(N),J(),ea(null)}catch(e){console.error("Failed to send to AI:",e)}},[el,W,n,N,J]),ef=(0,s.useCallback)(async e=>{er&&(await K(er.range.start,er.range.end,e,er.selectedText),es(null))},[er,K]);(0,s.useEffect)(()=>{let e=F.current,t=D.current;if(!e||!t)return;let n=(e,t)=>{O.current||(O.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{O.current=!1}))},r=()=>n(e,t),s=()=>n(t,e);return e.addEventListener("scroll",r),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",r),t.removeEventListener("scroll",s)}},[]);let{leftLines:ex,rightLines:ep}=(0,s.useMemo)(()=>{let e=[],t=[],n=0,r=0;for(let s=0;s<A.length;s++){let l=A[s];if("unchanged"===l.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});n++,r++,e.push({lineNum:n,content:l.content,type:"unchanged",originalIdx:s}),t.push({lineNum:r,content:l.content,type:"unchanged",originalIdx:s})}else"removed"===l.type?(n++,e.push({lineNum:n,content:l.content,type:"removed",originalIdx:s})):"added"===l.type&&(r++,t.push({lineNum:r,content:l.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[A]),eg=(0,s.useMemo)(()=>A.map(e=>e.content),[A]),eb=(0,p.C)(eg,n),[ev,ey]=(0,s.useState)(()=>new Map);(0,s.useLayoutEffect)(()=>{ey(new Map),eL.measure()},[ex,ep]);let ew=(0,s.useMemo)(()=>$??[],[$]),{rows:ek,gaps:ej}=(0,s.useMemo)(()=>T?function(e,t,n,r=[]){let s=e.length,l=n=>"unchanged"!==e[n].type||"unchanged"!==t[n].type,a=new Set;for(let e=0;e<s;e++){if(!l(e))continue;let t=Math.max(0,e-3),n=Math.min(s-1,e+3);for(let e=t;e<=n;e++)a.add(e)}let o=[];for(let e=0;e<s;e++){if(a.has(e))continue;let t=e;for(;e<s&&!a.has(e);)e++;o.push({id:o.length,startIdx:t,endIdx:e-1}),e--}for(let e of o){let t=n.get(e.id)??{topRevealed:0,bottomRevealed:0},r=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,r)),l=Math.max(0,Math.min(t.bottomRevealed,r-s));for(let t=e.startIdx;t<e.startIdx+s;t++)a.add(t);for(let t=e.endIdx-l+1;t<=e.endIdx;t++)a.add(t)}let i=[];for(let e=0;e<s;e++){let n;if(a.has(e)){i.push({kind:"diff",idx:e});continue}let l=e;for(;e<s&&!a.has(e);)e++;let c=e-1;e--;let u=o.find(e=>e.startIdx<=l&&c<=e.endIdx);if(!u)continue;let d=c-l+1,m=Math.min(20,d);if(r.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){n=function(e,t){let n=null;for(let r of e)r.startLine<=t&&t<=r.endLine&&(!n||r.endLine-r.startLine<n.endLine-n.startLine)&&(n=r);return n}(r,s)??void 0;break}}i.push({kind:"gap-expand",gapId:u.id,direction:"up",revealCount:m}),i.push({kind:"gap-label",gapId:u.id,hiddenCount:d,enclosingFn:n}),i.push({kind:"gap-expand",gapId:u.id,direction:"down",revealCount:m})}return{rows:i,gaps:o}}(ex,ep,ev,ew):{rows:ex.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[T,ex,ex,ep,ev,ew]),eC=(0,s.useCallback)((e,t)=>{let n=ej.find(t=>t.id===e);n&&ey(r=>{let s=r.get(e)??{topRevealed:0,bottomRevealed:0},l=n.endIdx-n.startIdx+1-s.topRevealed-s.bottomRevealed;if(l<=0)return r;let a=Math.min(20,l),o="up"===t?{...s,topRevealed:s.topRevealed+a}:{...s,bottomRevealed:s.bottomRevealed+a};return new Map(r).set(e,o)})},[ej]),eN=(0,s.useCallback)(e=>{for(let t of ej)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ej]),eS=(0,s.useCallback)(e=>ek[e]?.kind==="gap-label"?28:20,[ek]),eE=(0,s.useCallback)(e=>{let t=ek[e];if(!t)return e;if("gap-label"===t.kind)return`gl:${t.gapId}`;if("gap-expand"===t.kind)return`ge:${t.gapId}:${t.direction}`;let n=ex[t.idx],r=ep[t.idx];return`d:${n?.lineNum??"x"}:${n?.type??"x"}:${r?.lineNum??"x"}:${r?.type??"x"}`},[ek,ex,ep]),eL=(0,o.Te)({count:ek.length,getScrollElement:()=>_.current,estimateSize:eS,getItemKey:eE,overscan:20}),eM=j?"w-1/4":C?"w-3/4":"w-1/2",eR=j?"w-3/4":C?"w-1/4":"w-1/2",eT=(0,s.useMemo)(()=>ek.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=ex[e.idx],n=ep[e.idx];return"removed"===t.type?{type:"removed"}:n?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ek,ex,ep]),e$=eL.getTotalSize(),eI=eL.getVirtualItems();return(0,s.useEffect)(()=>{if(!R)return;let e=("after"===R.side?ep:ex).findIndex(e=>e.lineNum===R.line);if(-1===e)return;let t=ek.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=eN(e);if(null!==t){let e=ej.find(e=>e.id===t);if(!e)return;let n=e.endIdx-e.startIdx+1;ey(e=>{let r=e.get(t)??{topRevealed:0,bottomRevealed:0};if(r.topRevealed+r.bottomRevealed>=n)return e;let s=new Map(e);return s.set(t,{topRevealed:n,bottomRevealed:0}),s})}return}let n=requestAnimationFrame(()=>{eL.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(n)},[R,ex,ep,ek]),(0,r.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,r.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,r.jsx)("div",{className:`${eM} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:j?"(New File)":C?"Deleted":"Old"}),(0,r.jsxs)("div",{className:`${eR} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,r.jsx)("span",{className:"block text-center",children:C?"(Deleted)":"New"}),(0,r.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[E&&(0,r.jsx)("button",{onClick:E,className:"text-muted-foreground hover:text-foreground transition-colors",children:P}),!C&&t&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,x.oR)(I("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:I("common.copy")})]})]}),(0,r.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,r.jsx)("div",{ref:_,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,r.jsxs)("div",{className:"flex",style:{height:`${e$}px`},children:[(0,r.jsx)("div",{ref:F,className:`${eM} overflow-x-auto border-r border-border`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eI.map(e=>{let t=ek[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let n="gap-label"===t.kind;return(0,r.jsx)("div",{ref:eL.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:n?"bg-accent border-y border-border":""},e.key)}let n=ex[t.idx];return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===n.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:n.lineNum||""}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n.originalIdx>=0&&eb[n.originalIdx]||(0,g.ZD)(n.content||" ")}})]},e.key)})})}),(0,r.jsx)("div",{ref:D,className:`${eR} overflow-x-auto`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eI.map(e=>{let t=ek[e.index];if("gap-expand"===t.kind)return(0,r.jsx)("button",{ref:eL.measureElement,"data-index":e.index,type:"button",onClick:()=>eC(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,r.jsx)("span",{className:"select-none",children:I("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:I("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,r.jsx)("span",{className:"truncate min-w-0 font-medium",title:w(t.enclosingFn),children:w(t.enclosingFn)})]})]},e.key);let n=ep[t.idx],s=n?.lineNum||0,l=s>0&&eo.has(s),a=ei.get(s),o=a?.[0],i=er&&s>=er.range.start&&s<=er.range.end,c=el&&s>=el.range.start&&s<=el.range.end,u=i||c;return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${u?"bg-blue-9/20":l?"bg-amber-9/10":n?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${u?"bg-blue-9/30":""}`,style:{width:z?"52px":"40px"},children:[z&&s>0&&l&&o&&(0,r.jsx)("button",{onClick:e=>ec(o,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:I("codeViewer.nComments",{count:a?.length}),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),z&&s>0&&!l&&(0,r.jsx)("span",{className:"w-4"}),(0,r.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n?.originalIdx>=0&&eb[n.originalIdx]||(0,g.ZD)(n?.content||" ")}})]},e.key)})})})]})}),(0,r.jsx)(b,{lines:eT,containerRef:_})]}),V&&H&&(0,l.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.f,{floatingToolbarRef:ee,bumpRef:et,container:H,onAddComment:eu,onSendToAI:ed,onSearch:M?em:void 0,isChatLoading:W?.isLoading??!1}),er&&(0,r.jsx)(h.t,{x:er.x,y:er.y,range:er.range,lineSnapshot:er.lineSnapshot,container:H,onSubmit:ef,onClose:()=>es(null)}),el&&(0,r.jsx)(h.G,{x:el.x,y:el.y,range:el.range,filePath:n,lineSnapshot:el.lineSnapshot,container:H,onSubmit:eh,onClose:()=>ea(null),isChatLoading:W?.isLoading}),Z&&(0,r.jsx)(v.t,{x:Z.x,y:Z.y,comment:Z.comment,container:H,onClose:()=>Y(null),onUpdateComment:q,onDeleteComment:X})]}),H)]})}function j({oldContent:e,newContent:t,filePath:n}){let l=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),a=(0,s.useRef)(null),i=(0,s.useMemo)(()=>l.map(e=>e.content),[l]),c=(0,p.C)(i,n),u=(0,s.useCallback)(e=>{let t=l[e];return t?`${t.type}:${t.oldLineNum??"x"}:${t.newLineNum??"x"}`:e},[l]),d=(0,o.Te)({count:l.length,getScrollElement:()=>a.current,estimateSize:()=>20,getItemKey:u,overscan:20});return(0,r.jsx)("div",{ref:a,className:"font-mono text-sm overflow-auto h-full",children:(0,r.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=l[e.index];return(0,r.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,r.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,r.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:c[e.index]||(0,g.ZD)(t.content||" ")}})]},e.key)})})})}},70188:(e,t,n)=>{n.d(t,{Ee:()=>m,SU:()=>c,ft:()=>d,iN:()=>u});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,r.jsx)(i.Provider,{value:e,children:t})}function u(){return(0,s.useContext)(i)}function d({x:e,y:t,path:n,cwd:c,isDirectory:u,onClose:m,onCreateFile:h,onDelete:f,onRefresh:x,onCopyFile:p,onPaste:g}){let{t:b}=(0,l.Bd)(),v=(0,s.useRef)(null),y=(0,s.useContext)(i),w=n.split("/").pop()||n,k=`${c}/${n}`,j=n.includes("/")?n.substring(0,n.lastIndexOf("/")):"",C=j?`${c}/${j}`:c,N=u?n:j,S=u?k:C;(0,s.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&m()},t=e=>{"Escape"===e.key&&m()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[m]);let[E,L]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(v.current&&y){let n=y.getBoundingClientRect(),r=v.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s=Math.min(s,n.width-r.width-8),l=Math.min(l,n.height-r.height-8),L({x:s=Math.max(8,s),y:l=Math.max(8,l)})}else if(v.current){let n=v.current.getBoundingClientRect();L({x:Math.max(8,Math.min(e,window.innerWidth-n.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-n.height-8))})}},[e,t,y]);let M=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,o.oR)(b("toast.copiedName",{name:t}),"success")}catch{(0,o.oR)(b("toast.copyFailed"),"error")}m()},[m,b]),R=u?n:j,T=[{label:b("fileContextMenu.copyRelativePath"),value:n},{label:b("fileContextMenu.copyAbsolutePath"),value:k},{label:b("fileContextMenu.copyRelativeDirPath"),value:N||"."},{label:b("fileContextMenu.copyAbsoluteDirPath"),value:S},{label:u?b("fileContextMenu.copyFolderName"):b("fileContextMenu.copyFileName"),value:w}],$=(0,r.jsxs)("div",{ref:v,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:E.x,top:E.y},children:[h&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),h(R)},children:b("fileContextMenu.createFile")}),p&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),p(n)},children:u?b("fileContextMenu.copyFolder"):b("fileContextMenu.copyFile")}),g&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),g(R)},children:b("fileContextMenu.pasteHere")}),f&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{m(),f(n,u,w)},children:u?b("fileContextMenu.deleteFolder"):b("fileContextMenu.deleteFile")}),(h||f||p||g)&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),T.map((e,t)=>(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>M(e.value,e.label),children:e.label},t))]});return y?(0,a.createPortal)($,y):$}function m(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,n,r)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:n,isDirectory:r})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},75346:(e,t,n)=>{n.d(t,{n:()=>s});var r=n(88292);let s={SessionChange:(0,r.R)("session-change"),ViewChange:(0,r.R)("view-change"),OpenNote:(0,r.R)("open-note"),LangChange:(0,r.R)("lang-change"),TabAdd:(0,r.R)("tab-add"),TabClose:(0,r.R)("tab-close"),SwitchSession:(0,r.R)("switch-session"),ProjectChange:(0,r.R)("project-change"),OpenProject:(0,r.R)("open-project"),SessionComplete:(0,r.R)("session-complete"),OpenTokenStats:(0,r.R)("open-token-stats"),PinnedSessionsChanged:(0,r.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,r.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,r.R)("screenshot-prepare"),ScreenshotDone:(0,r.R)("screenshot-done")}},82292:(e,t,n)=>{function r(e,t){for(let n of e){if(n.path===t)return n;if(n.children){let e=r(n.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let n=r(t,e);if(n?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function l(e){let t=[];for(let n of e){let e=n.split("/"),r=t;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1,l=e.slice(0,t+1).join("/"),a=r.find(e=>e.name===n);a||(a={name:n,path:l,isDirectory:!s,children:s?void 0:[]},r.push(a)),!s&&a.children&&(r=a.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&n(e.children)})};return n(t),t}function a(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),r.children&&n(r.children))};return n(e),t}n.d(t,{B_:()=>f,HR:()=>function e(t,n){if(0===n.length)return t;let r=new Map(n.map(e=>[e.path,e]));return t.map(t=>{let n=r.get(t.path);return n&&t.isDirectory?void 0===t.children&&void 0!==n.children?{...t,children:n.children}:void 0!==t.children&&void 0!==n.children?{...t,children:e(t.children,n.children)}:t:t})},KH:()=>u,MB:()=>r,S7:()=>s,fw:()=>d,q3:()=>c,r6:()=>m,tE:()=>h,tW:()=>a,u:()=>i,v3:()=>l});let o=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return o.has(t||"")}function c(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase(),l=e=>{if(r.add(e.path),e.children)for(let t of e.children)l(t)},a=(e,t)=>{let o=e.name.toLowerCase(),i=n?o===s:o.includes(s);if(i&&e.children)return l(e),t.forEach(e=>r.add(e)),!0;let c=!1;if(e.children)for(let n of e.children)a(n,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(r.add(e.path),t.forEach(e=>r.add(e)),!0)};for(let t of e)a(t,[]);return r}function u(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let l=e[t].toLowerCase();if(n?l===s:l.includes(s)){for(let t=0;t<=e.length-1;t++)r.add(e.slice(0,t+1).join("/"));break}}}return r}function d(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),n=Math.floor(t/60),r=Math.floor(n/24),s=Math.floor(r/30),l=Math.floor(r/365);return l>0?`${l}y ago`:s>0?`${s}mo ago`:r>0?`${r}d ago`:n>0?`${n}h ago`:t>0?`${t}m ago`:"just now"}function m(e){let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0"),a=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return r?`${s}-${l} ${a}:${o}`:`${t.getFullYear()}-${s}-${l} ${a}:${o}`}let h=()=>{},f=50},83448:(e,t,n)=>{n.d(t,{Cr:()=>b,JC:()=>d,M5:()=>c,QW:()=>f,Zr:()=>h,an:()=>g,em:()=>i,l1:()=>u,n_:()=>m,qD:()=>p,td:()=>o});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),a=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),o=()=>l("/api/settings"),i=e=>l("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>l("/api/commands"),u=()=>l("/api/skills"),d=e=>a("/api/bash",e),m=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),h=(e,t)=>a(`/api/session/${encodeURIComponent(e)}/fork`,t),f=e=>l(`/api/sessions/projects/${encodeURIComponent(e)}`),x=()=>r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),p=e=>r.gen(function*(){let t=yield*x();if("not-running"!==t._tag)return t;e&&(yield*r.sync(e));let n=yield*r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===n._tag)return{_tag:"not-installed",message:n.message};if("error"===n._tag)return{_tag:"error",message:n.message};let l=yield*x();return"not-running"===l._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:l}),g=e=>l(`/api/file?path=${encodeURIComponent(e)}`),b=e=>l(`/api/claude-stats?engine=${encodeURIComponent(e)}`)},83897:(e,t,n)=>{n.d(t,{k_:()=>o,nH:()=>i});var r=n(95155),s=n(12115),l=n(48347);let a=(0,s.createContext)(null);function o({children:e}){let t=(0,s.useRef)(new Map),n=(0,s.useRef)(null),[i,c]=(0,s.useState)(!1),u=(0,s.useCallback)((e,n)=>{t.current.set(n,e)},[]),d=(0,s.useCallback)(e=>{t.current.delete(e)},[]),m=(0,s.useCallback)(e=>{n.current=e},[]),h=(0,s.useCallback)(e=>{let r=n.current;if(!r)return void console.warn("No active tab to send message");let s=t.current.get(r);s?s(e):console.warn(`No chat sender registered for tab ${r}`)},[]),f=(0,s.useMemo)(()=>({sendMessage:h,isLoading:i,registerChat:u,unregisterChat:d,setActiveTab:m,setIsLoading:c}),[h,i,u,d,m]),x=(0,s.useMemo)(()=>({sendMessage:h,isLoading:i}),[h,i]);return(0,r.jsx)(a.Provider,{value:f,children:(0,r.jsx)(l.H,{value:x,children:e})})}function i(){return(0,s.useContext)(a)}},85839:(e,t,n)=>{n.d(t,{m:()=>i,z:()=>o});var r=n(12115),s=n(49433),l=n(86957),a=n(82680);let o=e=>s.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new a.uV({message:"session-by-path failed",cause:e})});function i(e,t,n,{cwd:c,initialSessionId:u,onSessionId:d,onTitleChange:m,onTokenUsage:h,liveRunningRef:f}){let[x,p]=(0,r.useState)(!1),[g,b]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),[w,k]=(0,r.useState)(void 0),[j,C]=(0,r.useState)(0),[N,S]=(0,r.useState)(null),[E,L]=(0,r.useState)(null),M=(0,r.useRef)(m);M.current=m;let R=(0,r.useRef)(h);R.current=h;let T=(0,r.useRef)(void 0),$=(0,r.useRef)(0),I=(0,r.useCallback)(async(e,n,r=!1,s,a)=>{if(r){let e=Date.now();if(e-$.current<5e3)return;$.current=e}r||p(!0);try{let i={cwd:e,sessionId:n,limit:s,beforeTurnIndex:a};r&&T.current&&(i.ifFingerprint=T.current);let c=await l.t4.runPromiseExit(o(i));if("Success"===c._tag&&c.value){let e=c.value;if(e.notModified)return;e.fingerprint&&(T.current=e.fingerprint),void 0!==e.totalTurns&&C(e.totalTurns),void 0!==e.hasMore&&y(e.hasMore),e.messages&&e.messages.length>0&&(r?t(t=>{let n=e.messages;if(t.length===n.length&&t.length>0&&t[t.length-1].content===n[n.length-1].content)return t;let r=0;for(let e=0;e<Math.min(t.length,n.length)&&t[e].id===n[e].id&&t[e].content===n[e].content;e++)r=e+1;return r===t.length&&r<n.length?[...t,...n.slice(r)]:n}):f?.current||t(e.messages),S(n)),e.sessionId&&d(e.sessionId),e.engine&&L(e.engine),e.title&&M.current?.(e.title),e.usage&&R.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{r||p(!1)}},[t,d]),P=(0,r.useCallback)(async()=>{if(c&&n&&!g&&v){b(!0);try{let r=void 0!==w?w:j-Math.ceil(e.filter(e=>"user"===e.role).length),s=await l.t4.runPromiseExit(o({cwd:c,sessionId:n,limit:10,beforeTurnIndex:r>0?r:void 0}));if("Success"===s._tag&&s.value){let e=s.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let s=e.messages.filter(e=>"user"===e.role).length;k(r-s),S(n)}void 0!==e.hasMore&&y(e.hasMore),e.fingerprint&&(T.current=e.fingerprint)}else"Failure"===s._tag&&console.error("Failed to load more history:",s.cause)}finally{b(!1)}}},[c,n,g,v,w,j,e,t]),A=(0,r.useCallback)(async e=>{p(!0);let n=s.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new a.uV({message:"load session history failed",cause:e})}),r=await l.t4.runPromiseExit(n);"Success"===r._tag&&r.value?.messages&&r.value.messages.length>0?(t(r.value.messages),S(e)):"Failure"===r._tag&&console.error("Failed to load history:",r.cause),p(!1)},[t]);return(0,r.useEffect)(()=>{c&&u&&I(c,u,!1,10)},[]),{isLoadingHistory:x,isLoadingMore:g,hasMoreHistory:v,loadMoreHistory:P,loadHistory:A,loadHistoryByCwdAndSessionId:I,loadedSessionId:N,loadedEngine:E}}},89109:(e,t,n)=>{n.d(t,{f:()=>o});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,visible:n,container:s,onAddComment:o,onSendToAI:i,onSearch:c,isChatLoading:u}){let{t:d}=(0,l.Bd)(),m=s.getBoundingClientRect(),h=e-m.left,f=Math.max(0,t-m.top-40);return(0,r.jsxs)("div",{className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:h+8,top:f,visibility:n?"visible":"hidden",pointerEvents:n?"auto":"none"},children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:o,children:d("floatingToolbar.addComment")}),(0,r.jsx)("button",{className:"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",onClick:i,disabled:u,title:d(u?"comments.aiResponding":"floatingToolbar.sendToAI"),children:d("floatingToolbar.sendToAI")}),c&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:c,children:d("floatingToolbar.search")})]})}let o=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c}){let[u,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let m=(0,s.useMemo)(()=>e.current,[u]);return(0,r.jsx)(a,{x:m?.x??0,y:m?.y??0,visible:!!m,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c})})},90717:(e,t,n)=>{n.d(t,{$3:()=>d,Cm:()=>u,Gw:()=>f,RP:()=>m,Un:()=>h,zL:()=>c});var r=n(69809),s=n(49433),l=n(86957),a=n(82680),o=n(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function u(){i.forEach(e=>e())}async function d(e){let t=await l.t4.runPromiseExit((0,o.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let n=t.value.comments??[];if(0===n.length)return[];let r=new Map;for(let e of n)e.selectedText||(r.has(e.filePath)||r.set(e.filePath,[]),r.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(r.keys()).map(async t=>{let n=await l.t4.runPromiseExit(s.tryPromise({try:async()=>{let n=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null},catch:e=>new a.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===n._tag&&n.value&&"string"==typeof n.value.content?i.set(t,n.value.content.split("\n")):"Failure"===n._tag&&console.error(`Failed to read file ${t}:`,n.cause)}));let c=[];for(let e of n){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),n="";if(t){let r=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);n=t.slice(r,s).join("\n")}c.push({...e,codeContent:n})}return c}async function m(e){let t=await l.t4.runPromiseExit((0,o.tj)(e));return"Success"===t._tag?(u(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let h="__chat__";function f(e,t){let n=e.filter(e=>e.filePath===h),s=e.filter(e=>e.filePath!==h),l=[];for(let e of(s.length>0&&(l.push(`${r.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{l.push(`[${t+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),l.push("```"),l.push(e.codeContent),l.push("```"),e.note&&l.push(r.A.t("comments.note",{content:e.note})),l.push("")})),n)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");l.push(t),e.note&&l.push(e.note),l.push("")}return l.push(r.A.t("comments.question",{question:t})),l.join("\n")}},95045:(e,t,n)=>{n.d(t,{F:()=>a});var r=n(49433),s=n(88292),l=n(86957);let a=(e,t)=>{l.t4.runFork(r.flatMap(s.d,n=>n.publish(e,t)))}},95942:(e,t,n)=>{n.d(t,{EE:()=>o,K2:()=>i,ri:()=>c});var r=n(95155),s=n(12115),l=n(79114),a=n(8422);let o=80,i=24,c=(0,s.forwardRef)(function({visible:e,running:t,onInput:n},c){let{t:u}=(0,l.Bd)(),d=(0,s.useRef)(n);(0,s.useEffect)(()=>{d.current=n},[n]);let[m,h]=(0,s.useState)(!1),f=(0,s.useRef)(!1);(0,s.useEffect)(()=>{t&&!f.current?h(!0):!t&&f.current&&h(!1),f.current=t},[t]);let x=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(""),b=(0,s.useCallback)(()=>{if(p.current||!x.current)return;let e=new a.B({cols:o,rows:i,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace',convertEol:!1,scrollback:2e3,theme:{background:"#0a0a0a",foreground:"#d4d4d8"},disableStdin:!1,allowProposedApi:!0});e.open(x.current),e.onData(e=>d.current?.(e)),g.current&&e.write(g.current),p.current=e},[]);return((0,s.useEffect)(()=>{m&&e?b():(p.current?.dispose(),p.current=null)},[m,e,b]),(0,s.useImperativeHandle)(c,()=>({write:e=>{g.current+=e,g.current.length>2e5&&(g.current=g.current.slice(-15e4)),p.current?.write(e)},clear:()=>{g.current="",p.current?.clear()}}),[]),e)?(0,r.jsxs)("div",{className:"absolute top-12 right-3 z-30 rounded-lg border border-border bg-card shadow-lg overflow-hidden",style:{width:m?"auto":180},"data-testid":"pty-floating-window",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),"data-testid":"pty-floating-toggle",className:"w-full flex items-center justify-between gap-3 px-2.5 py-1.5 text-xs bg-accent/60 hover:bg-accent",children:[(0,r.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${t?"bg-green-500 animate-pulse":"bg-muted-foreground"}`}),(0,r.jsxs)("span",{className:"text-muted-foreground",children:[u("chat.ptyTerminal"),t?` \xb7 ${u("chat.ptyRunning")}`:""]})]}),(0,r.jsx)("span",{className:"text-muted-foreground",children:m?`${u("chat.ptyCollapse")} ▾`:`${u("chat.ptyExpand")} ▸`})]}),(0,r.jsx)("div",{ref:x,"data-testid":"pty-floating-term",style:{display:m?"block":"none",padding:4},className:"bg-[#0a0a0a]"})]}):null})}}]);
|
|
5
|
+
⚠️ ${n}`:`⚠️ ${n}`,isStreaming:!1}:e)}if("result"===t.type){let n="string"==typeof t.result?t.result.trim():"";return e.map(e=>e.id===s?{...e,content:!e.content&&n?n:e.content,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e)}return e}},50860:(e,t,n)=>{n.d(t,{I:()=>o});var r=n(95155),s=n(12115),l=n(86957),a=n(60938);function o(e){let{refreshKey:t,className:n="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:i}=e,c="absPath"in e&&"string"==typeof e.absPath,u=c?void 0:e.cwd,d=c?void 0:e.path,m=c?e.absPath:void 0,[h,f]=(0,s.useState)({kind:"loading"}),x=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++x.current;return f({kind:"loading"}),(async()=>{if(c){if(e!==x.current)return;f({kind:"ready",etag:null,size:0});return}let t=await l.t4.runPromiseExit((0,a.r6)(u,d));if(e!==x.current)return;if("Failure"===t._tag){let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause;f({kind:"error",message:n instanceof Error?n.message:"Unknown error"});return}let n=t.value;if(!n.ok)return f({kind:"error",message:`stat failed (${n.status})`});let r=n.data;r&&r.exists?"too-large"===r.category?f({kind:"too-large",size:r.size??0}):"image"!==r.category?f({kind:"error",message:`Not an image (${r.category})`}):f({kind:"ready",etag:r.etag||`t-${r.mtimeMs??Date.now()}`,size:r.size??0}):f({kind:"missing"})})(),()=>{x.current++}},[c,u,d,m,t]),"loading"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(h.size/1024/1024)," MB)"]})});if("error"===h.kind)return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("div",{className:"text-sm text-red-11",children:h.message})});let p=c?`/api/file?path=${encodeURIComponent(m)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(u)}&path=${encodeURIComponent(d)}&v=${encodeURIComponent(h.etag)}`;return(0,r.jsx)("div",{className:n,children:(0,r.jsx)("img",{src:p,alt:i??(d||m),className:o})})}},56045:(e,t,n)=>{n.d(t,{_:()=>o,o:()=>a});var r=n(12115),s=n(69809);let l="json-search-highlight-style";function a(e){let[t,n]=(0,r.useState)(!1),[s,a]=(0,r.useState)(""),[o,i]=(0,r.useState)(!1),[c,u]=(0,r.useState)(0),[d,m]=(0,r.useState)(0),h=(0,r.useRef)(null),f=(0,r.useRef)([]),x=(0,r.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[];let n=e.current;if(!n||!s){u(0),m(0);return}!function(){if(document.getElementById(l))return;let e=document.createElement("style");e.id=l,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let r=n.textContent||"",a=o?s:s.toLowerCase(),i=o?r:r.toLowerCase(),c=[],d=0;for(;d<i.length;){let e=i.indexOf(a,d);if(-1===e)break;c.push([e,e+a.length]),d=e+1}if(0===c.length){u(0),m(0);return}let h=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),x=0,p=0,g=[],b=null,v=0;for(;(t=h.nextNode())&&p<c.length;){let e=t.textContent?.length||0,n=x,r=x+e;for(;p<c.length;){let[e,s]=c[p];if(e>=r)break;if(!b)if(e>=n)(b=document.createRange()).setStart(t,e-n),v=s;else break;if(v<=r)b.setEnd(t,v-n),g.push(b),b=null,p++;else break}x=r}f.current=g,u(g.length),m(e=>g.length>0?Math.min(e,g.length-1):0),CSS.highlights&&g.length>0&&CSS.highlights.set("json-search",new Highlight(...g))},[e,s,o]),p=(0,r.useCallback)((e,t)=>{let n=e.getBoundingClientRect();(t.top<n.top||t.bottom>n.bottom)&&(e.scrollTop+=t.top-n.top-n.height/2+t.height/2)},[]),g=(0,r.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let n=f.current[t];if(!n||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(n));let r=n.getBoundingClientRect(),s=e.current?.parentElement;s&&p(s,r)},[e,p]);(0,r.useEffect)(()=>{queueMicrotask(()=>x())},[x]),(0,r.useEffect)(()=>{g(d)},[d,c,g]),(0,r.useEffect)(()=>{let t=e.current;if(!t||!s)return;let n=new MutationObserver(()=>x());return n.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>n.disconnect()},[e,s,x]),(0,r.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),f.current=[])},[t]),(0,r.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let b=(0,r.useCallback)(()=>{0!==c&&m(e=>(e+1)%c)},[c]),v=(0,r.useCallback)(()=>{0!==c&&m(e=>(e-1+c)%c)},[c]),y=(0,r.useCallback)(()=>{n(!0),setTimeout(()=>h.current?.focus(),0)},[]),w=(0,r.useCallback)(()=>{n(!1),a(""),m(0)},[]),k=(0,r.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?v():b()),"Escape"===e.key&&(e.preventDefault(),w())},[b,v,w]);return{isVisible:t,query:s,setQuery:a,caseSensitive:o,setCaseSensitive:i,matchCount:c,currentIndex:d,searchInputRef:h,open:y,close:w,goToNext:b,goToPrev:v,handleKeyDown:k}}function o({search:e}){return e.isVisible?r.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},r.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:s.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),r.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:s.A.t("codeViewer.caseSensitive")},"Aa"),r.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:s.A.t("common.noMatch")),r.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.previous")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),r.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:s.A.t("common.next")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),r.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:s.A.t("common.close")},r.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}},56978:(e,t,n)=>{n.d(t,{C:()=>l});var r=n(12115),s=n(17196);function l(e,t){let[n,l]=(0,r.useState)(null),[a,o]=(0,r.useState)(!1);(0,r.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()},[]);let i=(0,r.useMemo)(()=>e.join("\n"),[e]),c=`${i}:${t}:${a}`,u=(0,r.useMemo)(()=>n&&n.key===c?n.html:e.map(e=>(0,s.ZD)(e||" ")),[e,c,n]);return(0,r.useEffect)(()=>{if(0===e.length)return;let n=!1;return(async()=>{try{let r=await (0,s.kS)();if(n)return;let o=(0,s.sQ)(t),i=e.join("\n"),u=r.codeToTokens(i,{lang:o,theme:a?"github-dark":"github-light"}),d=[];for(let e=0;e<u.tokens.length;e++)if(d[e]=(0,s.b8)(u.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),n))return;l({key:c,html:d})}catch(e){console.error("Line highlight error:",e)}})(),()=>{n=!0}},[i,t,a]),u}},60938:(e,t,n)=>{n.d(t,{DZ:()=>c,Ft:()=>h,K9:()=>p,Nn:()=>w,OJ:()=>b,VK:()=>k,YW:()=>m,__:()=>y,dt:()=>v,eA:()=>g,eE:()=>f,gZ:()=>u,mP:()=>i,nM:()=>j,r6:()=>x,r9:()=>d});var r=n(49433),s=n(82680);let l=(e,t={})=>r.tryPromise({try:async()=>{let n=await fetch(e,t.init);if(t.passThroughStatuses&&t.passThroughStatuses.includes(n.status))return await n.json().catch(()=>({}));if(!n.ok){let e;try{e=(await n.json()).error}catch{}throw Error(e||`HTTP ${n.status}`)}return await n.json()},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),a=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t),r=null;try{r=await n.json()}catch{}return{status:n.status,ok:n.ok,data:r}},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),o=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),i=e=>l(`/api/files/init?cwd=${encodeURIComponent(e)}`),c=e=>l(`/api/files/index?cwd=${encodeURIComponent(e)}`),u=(e,t)=>l(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),d=e=>l(`/api/files/recent?cwd=${encodeURIComponent(e)}`),m=(e,t,n)=>o("/api/files/recent",{cwd:e,file:t,...n??{}}),h=(e,t)=>o("/api/files/expanded",{cwd:e,paths:t}),f=(e,t)=>l(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`).pipe(r.catchAll(e=>r.succeed({error:e.message}))),x=(e,t)=>a(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),p=(e,t)=>a(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),g=e=>l(`/api/files/text?${e.toString()}`),b=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=null;try{n=await t.json()}catch{}return{status:t.status,ok:t.ok,data:n}},catch:e=>new s.uV({message:"POST /api/files/save failed",cause:e})}),v=()=>l("/api/files/clipboard"),y=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/clipboard",{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:"POST /api/files/clipboard failed",cause:e})}),w=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/paste",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/paste failed",cause:e})}),k=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/files/delete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),n=await t.json().catch(()=>null);if(!t.ok)throw Error(n?.error||`HTTP ${t.status}`);return n},catch:e=>new s.uV({message:"POST /api/files/delete failed",cause:e})}),j=e=>l(`/api/file?path=${encodeURIComponent(e)}`)},65153:(e,t,n)=>{n.d(t,{u:()=>a});var r=n(12115),s=n(2111),l=n(48948);function a(e,t,n,a,o){let i=(0,r.useRef)(null),c=(0,r.useRef)(0),u=()=>{let e=`live-asst-${++c.current}`;return i.current=e,t(t=>[...t,{id:e,role:"assistant",content:"",isStreaming:!0}]),e},d=e=>{if("system"===e.type&&"init"===e.subtype)return void u();if("user"===e.type&&e._human){let n=e.message?.content,r="string"==typeof n?n:Array.isArray(n)?n.map(e=>e?.text||"").join(""):"",s=`live-user-${++c.current}`;t(e=>{for(let t=e.length-1;t>=0;t--)if("user"===e[t].role){if(e[t].content===r)return e;break}return[...e,{id:s,role:"user",content:r}]});return}let n=i.current??u();t(t=>(0,l.F)(t,e,{engine:a,assistantId:n}))};(0,s.h)({url:e?`/ws/session-stream?sessionId=${encodeURIComponent(e)}`:"/ws/session-stream",enabled:n&&!!e,onMessage:e=>{if("run-snapshot"===e.type&&Array.isArray(e.events)){if("running"!==e.status)return void o?.onRunningChange?.(!1);let n=e.events.find(e=>e?.type==="user"&&e?._human),r=n?.message?.content,s="string"==typeof r?r:"",l=new Set,a=new Set;for(let t of e.events){let e=t?.uuid;if("string"==typeof e&&l.add(e),t?.type==="assistant"&&Array.isArray(t.message?.content))for(let e of t.message.content)e?.name&&"string"==typeof e.id&&a.add(e.id)}for(let n of(t(e=>{let t=e.filter(e=>!("string"==typeof e.id&&e.id.startsWith("live-")));if(!s)return t;let n=-1;for(let e=t.length-1;e>=0;e--)if("user"===t[e].role){t[e].content===s&&(n=e);break}return -1===n?t:t.slice(n+1).every(e=>"assistant"===e.role&&("string"==typeof e.id&&l.has(e.id)||!!e.toolCalls?.length&&e.toolCalls.every(e=>a.has(e.id))))?t.slice(0,n):t}),i.current=null,c.current=0,e.events))d(n);o?.onRunningChange?.(!0)}else if("run-event"===e.type&&e.message){if("run-ended"===e.message.type){o?.onRunningChange?.(!1),o?.onComplete?.();return}d(e.message),o?.onRunningChange?.(!0)}else"run-idle"===e.type&&o?.onRunningChange?.(!1)}})}},67362:(e,t,n)=>{n.d(t,{xU:()=>j,xZ:()=>k});var r=n(95155),s=n(12115),l=n(47650),a=n(79114),o=n(64702),i=n(1058),c=n(90717),u=n(70188),d=n(48347),m=n(89109),h=n(7320),f=n(22576),x=n(34075),p=n(56978),g=n(17196);function b({lines:e,containerRef:t}){let n=(0,s.useRef)(null),[l,a]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let r=()=>{let{scrollTop:t,scrollHeight:r,clientHeight:s}=e,l=n.current?.clientHeight||0;if(r<=s)a({top:0,height:l});else{let e=l/r;a({top:t*e,height:s*e})}};return r(),e.addEventListener("scroll",r),window.addEventListener("resize",r),()=>{e.removeEventListener("scroll",r),window.removeEventListener("resize",r)}},[t]),0===e.length)return null;let o=100/e.length;return(0,r.jsxs)("div",{ref:n,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let r=t.current,s=n.current;if(!r||!s)return;let l=s.getBoundingClientRect(),a=(e.clientY-l.top)/l.height*r.scrollHeight-r.clientHeight/2;r.scrollTo({top:Math.max(0,a),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,r.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*o}%`,height:`${Math.max(o,.5)}%`,minHeight:"2px"}},t)),(0,r.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${l.top}px`,height:`${Math.max(l.height,10)}px`}})]})}var v=n(37614),y=n(27570);function w(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}function k({oldContent:e,newContent:t,filePath:n,isNew:j=!1,isDeleted:C=!1,cwd:N,enableComments:S=!1,onPreview:E,previewLabel:L,onContentSearch:M,targetLine:R,compact:T=!1,symbols:$}){let{t:I}=(0,a.Bd)(),P=L??I("common.preview"),A=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),_=(0,s.useRef)(null),F=(0,s.useRef)(null),D=(0,s.useRef)(null),O=(0,s.useRef)(!1),[V,B]=(0,s.useState)(!1),H=(0,u.iN)(),W=(0,d.r)(),z=S&&!!N,{comments:U,addComment:K,updateComment:q,deleteComment:X,refresh:J}=(0,i._)({cwd:N||"",filePath:n}),[Z,Y]=(0,s.useState)(null),[Q,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{D.current!==Q&&G(D.current)});let{toolbarRef:ee,bumpRef:et,clearToolbar:en}=(0,y.L)({enabled:z,container:Q,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,n=t?.closest("[data-new-line]");if(!n)return null;let r=parseInt(n.getAttribute("data-new-line")||"0",10);return!Number.isFinite(r)||r<=0?null:{start:r,end:r}},buildLineSnapshot:({start:e,end:t})=>{let n=[],r=0;for(let s of A)("unchanged"===s.type||"added"===s.type)&&++r>=e&&r<=t&&n.push(s.content);return n.join("\n")}}),[er,es]=(0,s.useState)(null),[el,ea]=(0,s.useState)(null);(0,s.useEffect)(()=>{B(!0)},[]);let eo=(0,s.useMemo)(()=>{let e=new Set;for(let t of U)for(let n=t.startLine;n<=t.endLine;n++)e.add(n);return e},[U]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of U){let n=t.endLine;e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[U]),ec=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),en(),es(null),ea(null)},[en]),eu=(0,s.useCallback)(()=>{let e=ee.current;e&&(es({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),ed=(0,s.useCallback)(()=>{let e=ee.current;e&&(ea({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,ee]),em=(0,s.useCallback)(()=>{let e=ee.current;if(!e||!M)return;let t=e.selectedText.trim();en(),t&&M(t)},[M,en,ee]),eh=(0,s.useCallback)(async e=>{if(el&&W&&N)try{let t=await (0,c.$3)(N),r=[];for(let e of t)r.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});r.push({filePath:n,startLine:el.range.start,endLine:el.range.end,codeContent:el.lineSnapshot});let s=(0,c.Gw)(r,e);W.sendMessage(s),await (0,c.RP)(N),J(),ea(null)}catch(e){console.error("Failed to send to AI:",e)}},[el,W,n,N,J]),ef=(0,s.useCallback)(async e=>{er&&(await K(er.range.start,er.range.end,e,er.selectedText),es(null))},[er,K]);(0,s.useEffect)(()=>{let e=F.current,t=D.current;if(!e||!t)return;let n=(e,t)=>{O.current||(O.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{O.current=!1}))},r=()=>n(e,t),s=()=>n(t,e);return e.addEventListener("scroll",r),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",r),t.removeEventListener("scroll",s)}},[]);let{leftLines:ex,rightLines:ep}=(0,s.useMemo)(()=>{let e=[],t=[],n=0,r=0;for(let s=0;s<A.length;s++){let l=A[s];if("unchanged"===l.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});n++,r++,e.push({lineNum:n,content:l.content,type:"unchanged",originalIdx:s}),t.push({lineNum:r,content:l.content,type:"unchanged",originalIdx:s})}else"removed"===l.type?(n++,e.push({lineNum:n,content:l.content,type:"removed",originalIdx:s})):"added"===l.type&&(r++,t.push({lineNum:r,content:l.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[A]),eg=(0,s.useMemo)(()=>A.map(e=>e.content),[A]),eb=(0,p.C)(eg,n),[ev,ey]=(0,s.useState)(()=>new Map);(0,s.useLayoutEffect)(()=>{ey(new Map),eL.measure()},[ex,ep]);let ew=(0,s.useMemo)(()=>$??[],[$]),{rows:ek,gaps:ej}=(0,s.useMemo)(()=>T?function(e,t,n,r=[]){let s=e.length,l=n=>"unchanged"!==e[n].type||"unchanged"!==t[n].type,a=new Set;for(let e=0;e<s;e++){if(!l(e))continue;let t=Math.max(0,e-3),n=Math.min(s-1,e+3);for(let e=t;e<=n;e++)a.add(e)}let o=[];for(let e=0;e<s;e++){if(a.has(e))continue;let t=e;for(;e<s&&!a.has(e);)e++;o.push({id:o.length,startIdx:t,endIdx:e-1}),e--}for(let e of o){let t=n.get(e.id)??{topRevealed:0,bottomRevealed:0},r=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,r)),l=Math.max(0,Math.min(t.bottomRevealed,r-s));for(let t=e.startIdx;t<e.startIdx+s;t++)a.add(t);for(let t=e.endIdx-l+1;t<=e.endIdx;t++)a.add(t)}let i=[];for(let e=0;e<s;e++){let n;if(a.has(e)){i.push({kind:"diff",idx:e});continue}let l=e;for(;e<s&&!a.has(e);)e++;let c=e-1;e--;let u=o.find(e=>e.startIdx<=l&&c<=e.endIdx);if(!u)continue;let d=c-l+1,m=Math.min(20,d);if(r.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){n=function(e,t){let n=null;for(let r of e)r.startLine<=t&&t<=r.endLine&&(!n||r.endLine-r.startLine<n.endLine-n.startLine)&&(n=r);return n}(r,s)??void 0;break}}i.push({kind:"gap-expand",gapId:u.id,direction:"up",revealCount:m}),i.push({kind:"gap-label",gapId:u.id,hiddenCount:d,enclosingFn:n}),i.push({kind:"gap-expand",gapId:u.id,direction:"down",revealCount:m})}return{rows:i,gaps:o}}(ex,ep,ev,ew):{rows:ex.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[T,ex,ex,ep,ev,ew]),eC=(0,s.useCallback)((e,t)=>{let n=ej.find(t=>t.id===e);n&&ey(r=>{let s=r.get(e)??{topRevealed:0,bottomRevealed:0},l=n.endIdx-n.startIdx+1-s.topRevealed-s.bottomRevealed;if(l<=0)return r;let a=Math.min(20,l),o="up"===t?{...s,topRevealed:s.topRevealed+a}:{...s,bottomRevealed:s.bottomRevealed+a};return new Map(r).set(e,o)})},[ej]),eN=(0,s.useCallback)(e=>{for(let t of ej)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ej]),eS=(0,s.useCallback)(e=>ek[e]?.kind==="gap-label"?28:20,[ek]),eE=(0,s.useCallback)(e=>{let t=ek[e];if(!t)return e;if("gap-label"===t.kind)return`gl:${t.gapId}`;if("gap-expand"===t.kind)return`ge:${t.gapId}:${t.direction}`;let n=ex[t.idx],r=ep[t.idx];return`d:${n?.lineNum??"x"}:${n?.type??"x"}:${r?.lineNum??"x"}:${r?.type??"x"}`},[ek,ex,ep]),eL=(0,o.Te)({count:ek.length,getScrollElement:()=>_.current,estimateSize:eS,getItemKey:eE,overscan:20}),eM=j?"w-1/4":C?"w-3/4":"w-1/2",eR=j?"w-3/4":C?"w-1/4":"w-1/2",eT=(0,s.useMemo)(()=>ek.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=ex[e.idx],n=ep[e.idx];return"removed"===t.type?{type:"removed"}:n?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ek,ex,ep]),e$=eL.getTotalSize(),eI=eL.getVirtualItems();return(0,s.useEffect)(()=>{if(!R)return;let e=("after"===R.side?ep:ex).findIndex(e=>e.lineNum===R.line);if(-1===e)return;let t=ek.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=eN(e);if(null!==t){let e=ej.find(e=>e.id===t);if(!e)return;let n=e.endIdx-e.startIdx+1;ey(e=>{let r=e.get(t)??{topRevealed:0,bottomRevealed:0};if(r.topRevealed+r.bottomRevealed>=n)return e;let s=new Map(e);return s.set(t,{topRevealed:n,bottomRevealed:0}),s})}return}let n=requestAnimationFrame(()=>{eL.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(n)},[R,ex,ep,ek]),(0,r.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,r.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,r.jsx)("div",{className:`${eM} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:j?"(New File)":C?"Deleted":"Old"}),(0,r.jsxs)("div",{className:`${eR} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,r.jsx)("span",{className:"block text-center",children:C?"(Deleted)":"New"}),(0,r.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[E&&(0,r.jsx)("button",{onClick:E,className:"text-muted-foreground hover:text-foreground transition-colors",children:P}),!C&&t&&(0,r.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,x.oR)(I("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:I("common.copy")})]})]}),(0,r.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,r.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,r.jsx)("div",{ref:_,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,r.jsxs)("div",{className:"flex",style:{height:`${e$}px`},children:[(0,r.jsx)("div",{ref:F,className:`${eM} overflow-x-auto border-r border-border`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eI.map(e=>{let t=ek[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let n="gap-label"===t.kind;return(0,r.jsx)("div",{ref:eL.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:n?"bg-accent border-y border-border":""},e.key)}let n=ex[t.idx];return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===n.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:n.lineNum||""}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n.originalIdx>=0&&eb[n.originalIdx]||(0,g.ZD)(n.content||" ")}})]},e.key)})})}),(0,r.jsx)("div",{ref:D,className:`${eR} overflow-x-auto`,children:(0,r.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eI.map(e=>{let t=ek[e.index];if("gap-expand"===t.kind)return(0,r.jsx)("button",{ref:eL.measureElement,"data-index":e.index,type:"button",onClick:()=>eC(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":I("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,r.jsx)("span",{className:"select-none",children:I("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,r.jsx)("span",{className:"flex-shrink-0",children:I("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,r.jsx)("span",{className:"truncate min-w-0 font-medium",title:w(t.enclosingFn),children:w(t.enclosingFn)})]})]},e.key);let n=ep[t.idx],s=n?.lineNum||0,l=s>0&&eo.has(s),a=ei.get(s),o=a?.[0],i=er&&s>=er.range.start&&s<=er.range.end,c=el&&s>=el.range.start&&s<=el.range.end,u=i||c;return(0,r.jsxs)("div",{ref:eL.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${u?"bg-blue-9/20":l?"bg-amber-9/10":n?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${u?"bg-blue-9/30":""}`,style:{width:z?"52px":"40px"},children:[z&&s>0&&l&&o&&(0,r.jsx)("button",{onClick:e=>ec(o,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:I("codeViewer.nComments",{count:a?.length}),children:(0,r.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,r.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),z&&s>0&&!l&&(0,r.jsx)("span",{className:"w-4"}),(0,r.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,r.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:n?.originalIdx>=0&&eb[n.originalIdx]||(0,g.ZD)(n?.content||" ")}})]},e.key)})})})]})}),(0,r.jsx)(b,{lines:eT,containerRef:_})]}),V&&H&&(0,l.createPortal)((0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.f,{floatingToolbarRef:ee,bumpRef:et,container:H,onAddComment:eu,onSendToAI:ed,onSearch:M?em:void 0,isChatLoading:W?.isLoading??!1}),er&&(0,r.jsx)(h.t,{x:er.x,y:er.y,range:er.range,lineSnapshot:er.lineSnapshot,container:H,onSubmit:ef,onClose:()=>es(null)}),el&&(0,r.jsx)(h.G,{x:el.x,y:el.y,range:el.range,filePath:n,lineSnapshot:el.lineSnapshot,container:H,onSubmit:eh,onClose:()=>ea(null),isChatLoading:W?.isLoading}),Z&&(0,r.jsx)(v.t,{x:Z.x,y:Z.y,comment:Z.comment,container:H,onClose:()=>Y(null),onUpdateComment:q,onDeleteComment:X})]}),H)]})}function j({oldContent:e,newContent:t,filePath:n}){let l=(0,s.useMemo)(()=>(0,f.X)(e,t),[e,t]),a=(0,s.useRef)(null),i=(0,s.useMemo)(()=>l.map(e=>e.content),[l]),c=(0,p.C)(i,n),u=(0,s.useCallback)(e=>{let t=l[e];return t?`${t.type}:${t.oldLineNum??"x"}:${t.newLineNum??"x"}`:e},[l]),d=(0,o.Te)({count:l.length,getScrollElement:()=>a.current,estimateSize:()=>20,getItemKey:u,overscan:20});return(0,r.jsx)("div",{ref:a,className:"font-mono text-sm overflow-auto h-full",children:(0,r.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=l[e.index];return(0,r.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,r.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,r.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,r.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:c[e.index]||(0,g.ZD)(t.content||" ")}})]},e.key)})})})}},70188:(e,t,n)=>{n.d(t,{Ee:()=>m,SU:()=>c,ft:()=>d,iN:()=>u});var r=n(95155),s=n(12115),l=n(79114),a=n(47650),o=n(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,r.jsx)(i.Provider,{value:e,children:t})}function u(){return(0,s.useContext)(i)}function d({x:e,y:t,path:n,cwd:c,isDirectory:u,onClose:m,onCreateFile:h,onDelete:f,onRefresh:x,onCopyFile:p,onPaste:g}){let{t:b}=(0,l.Bd)(),v=(0,s.useRef)(null),y=(0,s.useContext)(i),w=n.split("/").pop()||n,k=`${c}/${n}`,j=n.includes("/")?n.substring(0,n.lastIndexOf("/")):"",C=j?`${c}/${j}`:c,N=u?n:j,S=u?k:C;(0,s.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&m()},t=e=>{"Escape"===e.key&&m()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[m]);let[E,L]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(v.current&&y){let n=y.getBoundingClientRect(),r=v.current.getBoundingClientRect(),s=e-n.left,l=t-n.top;s=Math.min(s,n.width-r.width-8),l=Math.min(l,n.height-r.height-8),L({x:s=Math.max(8,s),y:l=Math.max(8,l)})}else if(v.current){let n=v.current.getBoundingClientRect();L({x:Math.max(8,Math.min(e,window.innerWidth-n.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-n.height-8))})}},[e,t,y]);let M=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,o.oR)(b("toast.copiedName",{name:t}),"success")}catch{(0,o.oR)(b("toast.copyFailed"),"error")}m()},[m,b]),R=u?n:j,T=[{label:b("fileContextMenu.copyRelativePath"),value:n},{label:b("fileContextMenu.copyAbsolutePath"),value:k},{label:b("fileContextMenu.copyRelativeDirPath"),value:N||"."},{label:b("fileContextMenu.copyAbsoluteDirPath"),value:S},{label:u?b("fileContextMenu.copyFolderName"):b("fileContextMenu.copyFileName"),value:w}],$=(0,r.jsxs)("div",{ref:v,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:E.x,top:E.y},children:[h&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),h(R)},children:b("fileContextMenu.createFile")}),p&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),p(n)},children:u?b("fileContextMenu.copyFolder"):b("fileContextMenu.copyFile")}),g&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),g(R)},children:b("fileContextMenu.pasteHere")}),f&&(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{m(),f(n,u,w)},children:u?b("fileContextMenu.deleteFolder"):b("fileContextMenu.deleteFile")}),(h||f||p||g)&&(0,r.jsx)("div",{className:"my-1 border-t border-border"}),T.map((e,t)=>(0,r.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>M(e.value,e.label),children:e.label},t))]});return y?(0,a.createPortal)($,y):$}function m(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,n,r)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:n,isDirectory:r})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},75346:(e,t,n)=>{n.d(t,{n:()=>s});var r=n(88292);let s={SessionChange:(0,r.R)("session-change"),ViewChange:(0,r.R)("view-change"),OpenNote:(0,r.R)("open-note"),LangChange:(0,r.R)("lang-change"),TabAdd:(0,r.R)("tab-add"),TabClose:(0,r.R)("tab-close"),SwitchSession:(0,r.R)("switch-session"),ProjectChange:(0,r.R)("project-change"),OpenProject:(0,r.R)("open-project"),SessionComplete:(0,r.R)("session-complete"),OpenTokenStats:(0,r.R)("open-token-stats"),PinnedSessionsChanged:(0,r.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,r.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,r.R)("screenshot-prepare"),ScreenshotDone:(0,r.R)("screenshot-done")}},82292:(e,t,n)=>{function r(e,t){for(let n of e){if(n.path===t)return n;if(n.children){let e=r(n.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let n=r(t,e);if(n?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function l(e){let t=[];for(let n of e){let e=n.split("/"),r=t;for(let t=0;t<e.length;t++){let n=e[t],s=t===e.length-1,l=e.slice(0,t+1).join("/"),a=r.find(e=>e.name===n);a||(a={name:n,path:l,isDirectory:!s,children:s?void 0:[]},r.push(a)),!s&&a.children&&(r=a.children)}}let n=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&n(e.children)})};return n(t),t}function a(e){let t=[],n=e=>{for(let r of e)r.isDirectory&&(t.push(r.path),r.children&&n(r.children))};return n(e),t}n.d(t,{B_:()=>f,HR:()=>function e(t,n){if(0===n.length)return t;let r=new Map(n.map(e=>[e.path,e]));return t.map(t=>{let n=r.get(t.path);return n&&t.isDirectory?void 0===t.children&&void 0!==n.children?{...t,children:n.children}:void 0!==t.children&&void 0!==n.children?{...t,children:e(t.children,n.children)}:t:t})},KH:()=>u,MB:()=>r,S7:()=>s,fw:()=>d,q3:()=>c,r6:()=>m,tE:()=>h,tW:()=>a,u:()=>i,v3:()=>l});let o=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return o.has(t||"")}function c(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase(),l=e=>{if(r.add(e.path),e.children)for(let t of e.children)l(t)},a=(e,t)=>{let o=e.name.toLowerCase(),i=n?o===s:o.includes(s);if(i&&e.children)return l(e),t.forEach(e=>r.add(e)),!0;let c=!1;if(e.children)for(let n of e.children)a(n,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(r.add(e.path),t.forEach(e=>r.add(e)),!0)};for(let t of e)a(t,[]);return r}function u(e,t,n=!1){let r=new Set;if(!t)return r;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let l=e[t].toLowerCase();if(n?l===s:l.includes(s)){for(let t=0;t<=e.length-1;t++)r.add(e.slice(0,t+1).join("/"));break}}}return r}function d(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),n=Math.floor(t/60),r=Math.floor(n/24),s=Math.floor(r/30),l=Math.floor(r/365);return l>0?`${l}y ago`:s>0?`${s}mo ago`:r>0?`${r}d ago`:n>0?`${n}h ago`:t>0?`${t}m ago`:"just now"}function m(e){let t=new Date(e),n=new Date,r=t.getFullYear()===n.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0"),a=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return r?`${s}-${l} ${a}:${o}`:`${t.getFullYear()}-${s}-${l} ${a}:${o}`}let h=()=>{},f=50},83448:(e,t,n)=>{n.d(t,{Cr:()=>b,JC:()=>d,M5:()=>c,QW:()=>f,Zr:()=>h,an:()=>g,em:()=>i,l1:()=>u,n_:()=>m,qD:()=>p,td:()=>o});var r=n(49433),s=n(82680);let l=(e,t)=>r.tryPromise({try:async()=>{let n=await fetch(e,t);if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:n=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:n})}),a=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),o=()=>l("/api/settings"),i=e=>l("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>l("/api/commands"),u=()=>l("/api/skills"),d=e=>a("/api/bash",e),m=e=>r.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),h=(e,t)=>a(`/api/session/${encodeURIComponent(e)}/fork`,t),f=e=>l(`/api/sessions/projects/${encodeURIComponent(e)}`),x=()=>r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),p=e=>r.gen(function*(){let t=yield*x();if("not-running"!==t._tag)return t;e&&(yield*r.sync(e));let n=yield*r.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===n._tag)return{_tag:"not-installed",message:n.message};if("error"===n._tag)return{_tag:"error",message:n.message};let l=yield*x();return"not-running"===l._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:l}),g=e=>l(`/api/file?path=${encodeURIComponent(e)}`),b=e=>l(`/api/claude-stats?engine=${encodeURIComponent(e)}`)},83897:(e,t,n)=>{n.d(t,{k_:()=>o,nH:()=>i});var r=n(95155),s=n(12115),l=n(48347);let a=(0,s.createContext)(null);function o({children:e}){let t=(0,s.useRef)(new Map),n=(0,s.useRef)(null),[i,c]=(0,s.useState)(!1),u=(0,s.useCallback)((e,n)=>{t.current.set(n,e)},[]),d=(0,s.useCallback)(e=>{t.current.delete(e)},[]),m=(0,s.useCallback)(e=>{n.current=e},[]),h=(0,s.useCallback)(e=>{let r=n.current;if(!r)return void console.warn("No active tab to send message");let s=t.current.get(r);s?s(e):console.warn(`No chat sender registered for tab ${r}`)},[]),f=(0,s.useMemo)(()=>({sendMessage:h,isLoading:i,registerChat:u,unregisterChat:d,setActiveTab:m,setIsLoading:c}),[h,i,u,d,m]),x=(0,s.useMemo)(()=>({sendMessage:h,isLoading:i}),[h,i]);return(0,r.jsx)(a.Provider,{value:f,children:(0,r.jsx)(l.H,{value:x,children:e})})}function i(){return(0,s.useContext)(a)}},85839:(e,t,n)=>{n.d(t,{m:()=>i,z:()=>o});var r=n(12115),s=n(49433),l=n(86957),a=n(82680);let o=e=>s.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new a.uV({message:"session-by-path failed",cause:e})});function i(e,t,n,{cwd:c,initialSessionId:u,onSessionId:d,onTitleChange:m,onTokenUsage:h,liveRunningRef:f}){let[x,p]=(0,r.useState)(!1),[g,b]=(0,r.useState)(!1),[v,y]=(0,r.useState)(!1),[w,k]=(0,r.useState)(void 0),[j,C]=(0,r.useState)(0),[N,S]=(0,r.useState)(null),[E,L]=(0,r.useState)(null),M=(0,r.useRef)(m);M.current=m;let R=(0,r.useRef)(h);R.current=h;let T=(0,r.useRef)(void 0),$=(0,r.useRef)(0),I=(0,r.useCallback)(async(e,n,r=!1,s,a)=>{if(r){let e=Date.now();if(e-$.current<5e3)return;$.current=e}r||p(!0);try{let i={cwd:e,sessionId:n,limit:s,beforeTurnIndex:a};r&&T.current&&(i.ifFingerprint=T.current);let c=await l.t4.runPromiseExit(o(i));if("Success"===c._tag&&c.value){let e=c.value;if(e.notModified)return;e.fingerprint&&(T.current=e.fingerprint),void 0!==e.totalTurns&&C(e.totalTurns),void 0!==e.hasMore&&y(e.hasMore),e.messages&&e.messages.length>0&&(r?t(t=>{let n=e.messages;if(t.length===n.length&&t.length>0&&t[t.length-1].content===n[n.length-1].content)return t;let r=0;for(let e=0;e<Math.min(t.length,n.length)&&t[e].id===n[e].id&&t[e].content===n[e].content;e++)r=e+1;return r===t.length&&r<n.length?[...t,...n.slice(r)]:n}):f?.current||t(e.messages),S(n)),e.sessionId&&d(e.sessionId),e.engine&&L(e.engine),e.title&&M.current?.(e.title),e.usage&&R.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{r||p(!1)}},[t,d]),P=(0,r.useCallback)(async()=>{if(c&&n&&!g&&v){b(!0);try{let r=void 0!==w?w:j-Math.ceil(e.filter(e=>"user"===e.role).length),s=await l.t4.runPromiseExit(o({cwd:c,sessionId:n,limit:10,beforeTurnIndex:r>0?r:void 0}));if("Success"===s._tag&&s.value){let e=s.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let s=e.messages.filter(e=>"user"===e.role).length;k(r-s),S(n)}void 0!==e.hasMore&&y(e.hasMore),e.fingerprint&&(T.current=e.fingerprint)}else"Failure"===s._tag&&console.error("Failed to load more history:",s.cause)}finally{b(!1)}}},[c,n,g,v,w,j,e,t]),A=(0,r.useCallback)(async e=>{p(!0);let n=s.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new a.uV({message:"load session history failed",cause:e})}),r=await l.t4.runPromiseExit(n);"Success"===r._tag&&r.value?.messages&&r.value.messages.length>0?(t(r.value.messages),S(e)):"Failure"===r._tag&&console.error("Failed to load history:",r.cause),p(!1)},[t]);return(0,r.useEffect)(()=>{c&&u&&I(c,u,!1,10)},[]),{isLoadingHistory:x,isLoadingMore:g,hasMoreHistory:v,loadMoreHistory:P,loadHistory:A,loadHistoryByCwdAndSessionId:I,loadedSessionId:N,loadedEngine:E}}},89109:(e,t,n)=>{n.d(t,{f:()=>o});var r=n(95155),s=n(12115),l=n(79114);function a({x:e,y:t,visible:n,container:s,onAddComment:o,onSendToAI:i,onSearch:c,isChatLoading:u}){let{t:d}=(0,l.Bd)(),m=s.getBoundingClientRect(),h=e-m.left,f=Math.max(0,t-m.top-40);return(0,r.jsxs)("div",{className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:h+8,top:f,visibility:n?"visible":"hidden",pointerEvents:n?"auto":"none"},children:[(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:o,children:d("floatingToolbar.addComment")}),(0,r.jsx)("button",{className:"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",onClick:i,disabled:u,title:d(u?"comments.aiResponding":"floatingToolbar.sendToAI"),children:d("floatingToolbar.sendToAI")}),c&&(0,r.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:c,children:d("floatingToolbar.search")})]})}let o=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c}){let[u,d]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>d(e=>e+1)},[t]);let m=(0,s.useMemo)(()=>e.current,[u]);return(0,r.jsx)(a,{x:m?.x??0,y:m?.y??0,visible:!!m,container:n,onAddComment:l,onSendToAI:o,onSearch:i,isChatLoading:c})})},90717:(e,t,n)=>{n.d(t,{$3:()=>d,Cm:()=>u,Gw:()=>f,RP:()=>m,Un:()=>h,zL:()=>c});var r=n(69809),s=n(49433),l=n(86957),a=n(82680),o=n(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function u(){i.forEach(e=>e())}async function d(e){let t=await l.t4.runPromiseExit((0,o.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let n=t.value.comments??[];if(0===n.length)return[];let r=new Map;for(let e of n)e.selectedText||(r.has(e.filePath)||r.set(e.filePath,[]),r.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(r.keys()).map(async t=>{let n=await l.t4.runPromiseExit(s.tryPromise({try:async()=>{let n=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return n.ok?await n.json():null},catch:e=>new a.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===n._tag&&n.value&&"string"==typeof n.value.content?i.set(t,n.value.content.split("\n")):"Failure"===n._tag&&console.error(`Failed to read file ${t}:`,n.cause)}));let c=[];for(let e of n){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),n="";if(t){let r=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);n=t.slice(r,s).join("\n")}c.push({...e,codeContent:n})}return c}async function m(e){let t=await l.t4.runPromiseExit((0,o.tj)(e));return"Success"===t._tag?(u(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let h="__chat__";function f(e,t){let n=e.filter(e=>e.filePath===h),s=e.filter(e=>e.filePath!==h),l=[];for(let e of(s.length>0&&(l.push(`${r.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{l.push(`[${t+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),l.push("```"),l.push(e.codeContent),l.push("```"),e.note&&l.push(r.A.t("comments.note",{content:e.note})),l.push("")})),n)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");l.push(t),e.note&&l.push(e.note),l.push("")}return l.push(r.A.t("comments.question",{question:t})),l.join("\n")}},95045:(e,t,n)=>{n.d(t,{F:()=>a});var r=n(49433),s=n(88292),l=n(86957);let a=(e,t)=>{l.t4.runFork(r.flatMap(s.d,n=>n.publish(e,t)))}},95942:(e,t,n)=>{n.d(t,{EE:()=>o,K2:()=>i,ri:()=>c});var r=n(95155),s=n(12115),l=n(79114),a=n(8422);let o=80,i=24,c=(0,s.forwardRef)(function({visible:e,running:t,onInput:n},c){let{t:u}=(0,l.Bd)(),d=(0,s.useRef)(n);(0,s.useEffect)(()=>{d.current=n},[n]);let[m,h]=(0,s.useState)(!1),f=(0,s.useRef)(!1);(0,s.useEffect)(()=>{t&&!f.current?h(!0):!t&&f.current&&h(!1),f.current=t},[t]);let x=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(""),b=(0,s.useCallback)(()=>{if(p.current||!x.current)return;let e=new a.B({cols:o,rows:i,fontSize:11,fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace',convertEol:!1,scrollback:2e3,theme:{background:"#0a0a0a",foreground:"#d4d4d8"},disableStdin:!1,allowProposedApi:!0});e.open(x.current),e.onData(e=>d.current?.(e)),g.current&&e.write(g.current),p.current=e},[]);return((0,s.useEffect)(()=>{m&&e?b():(p.current?.dispose(),p.current=null)},[m,e,b]),(0,s.useImperativeHandle)(c,()=>({write:e=>{g.current+=e,g.current.length>2e5&&(g.current=g.current.slice(-15e4)),p.current?.write(e)},clear:()=>{g.current="",p.current?.clear()}}),[]),e)?(0,r.jsxs)("div",{className:"absolute top-12 right-3 z-30 rounded-lg border border-border bg-card shadow-lg overflow-hidden",style:{width:m?"auto":180},"data-testid":"pty-floating-window",children:[(0,r.jsxs)("button",{type:"button",onClick:()=>h(e=>!e),"data-testid":"pty-floating-toggle",className:"w-full flex items-center justify-between gap-3 px-2.5 py-1.5 text-xs bg-accent/60 hover:bg-accent",children:[(0,r.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,r.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${t?"bg-green-500 animate-pulse":"bg-muted-foreground"}`}),(0,r.jsxs)("span",{className:"text-muted-foreground",children:[u("chat.ptyTerminal"),t?` \xb7 ${u("chat.ptyRunning")}`:""]})]}),(0,r.jsx)("span",{className:"text-muted-foreground",children:m?`${u("chat.ptyCollapse")} ▾`:`${u("chat.ptyExpand")} ▸`})]}),(0,r.jsx)("div",{ref:x,"data-testid":"pty-floating-term",style:{display:m?"block":"none",padding:4},className:"bg-[#0a0a0a]"})]}):null})}}]);
|