@qt4798/pi-web 0.18.3 → 0.18.4
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/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +9 -9
- package/.next/build-manifest.json +2 -2
- package/.next/prerender-manifest.json +3 -3
- package/.next/required-server-files.js +1 -1
- package/.next/required-server-files.json +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +1 -1
- package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/api/app-update/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +3 -3
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +3 -3
- package/.next/server/app/index.segments/_full.segment.rsc +3 -3
- package/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +1 -1
- package/.next/server/app/login.segments/_full.segment.rsc +1 -1
- package/.next/server/app/login.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/page.js +2 -2
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +9 -9
- package/.next/server/chunks/7915.js +1 -1
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/chunks/app/{page-bf524eccd13171ca.js → page-bd73baeec065cb84.js} +2 -2
- package/.next/trace +83 -83
- package/.next/trace-build +1 -1
- package/package.json +1 -1
- /package/.next/static/{_xksA4ZQaCVW_rYzSdTTL → I_FDqLx_bV7v2QRYgPTtm}/_buildManifest.js +0 -0
- /package/.next/static/{_xksA4ZQaCVW_rYzSdTTL → I_FDqLx_bV7v2QRYgPTtm}/_ssgManifest.js +0 -0
|
@@ -191,8 +191,8 @@ ${e}`;(0,o.useEffect)(()=>{t||a(!0)},[t]),(0,o.useEffect)(()=>{if(!l||t)return;l
|
|
|
191
191
|
|
|
192
192
|
Goal: ${r}`:e7)}return t.join("\n\n")}({collaborationMode:ez.current,tokenMode:eT.current,goalText:"goal"===ez.current?eM.current??void 0:void 0}),c=[ez.current,eT.current,d?String(d.length):""].join("|"),u=t?.id??"new";d&&(eE.current.sessionKey!==u||eE.current.signature!==c)?(eE.current={sessionKey:u,signature:c},i=`${d}
|
|
193
193
|
|
|
194
|
-
${r}`):i=r;let h=i,g=o?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),x={role:"user",content:g?.length?[...r.trim()?[{type:"text",text:r}]:[],...g]:r,timestamp:Date.now()};z(e=>[...e,x]),rs.current=ch(x),ri.current=a;let f="goal"===ez.current&&!l&&s.length>0&&"idle"===eP.current.status;f&&(eM.current=s,eF(e=>({...e,status:"running",goalText:s,turnsUsed:0,noProgressTurns:0,tokensUsed:0})),eD.current=!0),tY.current=!0,q(!0),td(l?{kind:"running_command"}:{kind:"waiting_model"}),A({type:"start"}),t3.current=!0,tu(!0),t8.current=!0;let m=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),v=null,y=!1;try{if(p&&n){let e=tV.current??await rn.current,t=e??await rC();if(t){v=t,rS(1,r),ea&&(tt(ea),e&&await tM(t,{type:"set_model",provider:ea.provider,modelId:ea.modelId}));let n=await Promise.race([rM(t).then(()=>!0).catch(()=>!1),cd(4e3).then(()=>!1)]);y=!0,await tM(t,{type:"prompt",message:h,...m?.length?{images:m}:{}}),n||rU(t,a),f&&tM(t,{type:"goal_start",goalText:s}).catch(()=>{})}else throw Error("Unable to create a session for this message")}else if(t){v=t.id;let e=await Promise.race([rM(t.id).then(()=>!0).catch(()=>!1),cd(4e3).then(()=>!1)]);y=!0,await tM(t.id,{type:"prompt",message:h,...m?.length?{images:m}:{}}),e||rU(t.id,a),f&&tM(t.id,{type:"goal_start",goalText:s}).catch(()=>{})}l&&v&&rU(v,a)}catch(t){if(console.error("Failed to send message:",t),y&&v)return void rU(v,a);if(tX.current=!1,rR(),t instanceof ca){let e=rs.current;e&&z(t=>{let r=t[t.length-1];return r?.role==="user"&&ch(r)===e?t.slice(0,-1):t}),rW({type:"error",message:t.message})}else{let r=rs.current;r&&z(e=>{let t=e[e.length-1];return t?.role==="user"&&ch(t)===r?e.slice(0,-1):e}),e.chatInputRef?.current?.replaceMessage?.(x),rW({type:"error",message:`Failed to send message: ${t instanceof Error?t.message:String(t)}`})}rs.current=null,tY.current=!1,q(!1),td(null),A({type:"end"})}},[p,n,ea,t,rC,rM,rS,rU,rW,rT,rR,rg]),rY=(0,o.useCallback)(async(r,n)=>{if(tY.current||t1.current)return;let o=`${n?"!!":"!"}${r}`;t1.current=!0,Y({command:r,excludeFromContext:n}),V(!0);try{let e=tV.current??t?.id??await rC();if(!e)throw Error("Unable to create a session for the shell command");rS(1,o),await tM(e,{type:"bash",command:r,excludeFromContext:n}),await rj(e)}catch(t){console.error("Failed to execute shell command:",t),rW({type:"error",message:t instanceof Error?t.message:String(t)}),e.chatInputRef?.current?.insertIfEmpty(o)}finally{t1.current=!1,Y(null),V(!1)}},[rW,rC,rj,e.chatInputRef,rS,t]),rG=(0,o.useCallback)(async()=>{let e=tV.current;if(e)try{await tM(e,{type:t1.current?"abort_bash":"abort"})}catch(e){console.error("Failed to abort:",e)}},[]),rX=(0,o.useCallback)(async e=>{let t=tV.current;if(t){eY(e);try{let{cancelled:r,newSessionId:n}=await tM(t,{type:"fork",entryId:e})??{};!r&&n&&l?.(n)}catch(e){console.error("Fork failed:",e)}finally{eY(null)}}},[l]),rZ=(0,o.useCallback)(async e=>{if(t1.current)return!1;let t=tV.current;if(!t)return!1;try{let r=await tM(t,{type:"navigate_tree",targetId:e});if(r?.cancelled||tV.current!==t)return!1;return S(e),await rj(t),tV.current===t}catch(e){return console.error("Failed to navigate:",e),!1}},[rj]),rQ=(0,o.useCallback)(async e=>{S(e);let t=tV.current;t&&(await rN(t,e),e&&tM(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[rN]),r0=(0,o.useCallback)(async(e,t)=>{if(p){let r={provider:e,modelId:t};ru.current=r,ed(r),tt(r);let n=tV.current??await rn.current;if(!n)return;try{await tM(n,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let r=tV.current;if(!r)return;let n=++rl.current,o=eG??g?.context.model??null;eX({provider:e,modelId:t});try{await tM(r,{type:"set_model",provider:e,modelId:t})}catch(r){console.error("Failed to set model:",r),rl.current===n&&(eX(o&&(o.provider!==e||o.modelId!==t)?o:null),rW({type:"error",message:r instanceof Error?r.message:String(r)}))}},[rW,eG,g?.context.model,p,ed]),r1=(0,o.useCallback)(async()=>{let e=tV.current;if(e&&!tr){tn(!0),ti(null),tl(null);try{let t=await tM(e,{type:"compact"});tl(cg(t,"manual")),await rj(e,!0)}catch(e){ti(e instanceof Error?e.message:String(e)),tl(null)}finally{tn(!1)}}},[tr,rj]),r2=(0,o.useCallback)(async e=>{let r=++ra.current,o=n??t?.cwd??"",i=o?`/api/models?cwd=${encodeURIComponent(o)}`:"/api/models",s=rd.current;s?.abort();let l=new AbortController;rd.current=l;let a=()=>l.abort();e?.aborted?l.abort():e?.addEventListener("abort",a,{once:!0});try{let e=await fetch(i,{signal:l.signal});if(!e.ok){let t=`HTTP ${e.status}`;try{let r=await e.json();r?.error&&(t=r.error)}catch{}throw Error(t)}let t=await e.json();if(r!==ra.current||h!==rc.current)return;el(null),X(t.models),et(t.thinkingLevels??{}),en(t.thinkingLevelMaps??{}),ei(t.modelScopeWarnings??[]);let n=t.modelList??[];if(Q(n),p&&!tV.current){let e=(t.defaultModel?n.find(e=>e.id===t.defaultModel?.modelId&&e.provider===t.defaultModel?.provider):void 0)??n[0];eu(e?{provider:e.provider,modelId:e.id}:null);let r=e?t.thinkingLevelPins?.[`${e.provider}/${e.id}`]:void 0;null===rp.current&&eO(r??"auto")}}catch(e){if(l.signal.aborted||r!==ra.current||h!==rc.current)return;el(e instanceof Error?e.message:String(e))}finally{e?.removeEventListener("abort",a),rd.current===l&&(rd.current=null)}},[p,h,n,t?.cwd]),r6=(0,o.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,r,n=""]=t,o=n.trim(),i=tV.current??await rC(),s=e=>(e.handled&&(e.error?rW({type:"error",message:e.error}):"openSessionStats"!==e.action&&rW({type:"success",message:e.message??"Command completed"})),e);try{switch(r){case"compact":{if(!i||tr)return s({handled:!0,error:"No active session to compact"});tn(!0),ti(null),tl(null);let e=await tM(i,{type:"compact",...o?{customInstructions:o}:{}});return tl(cg(e,"manual")),await rj(i,!0)&&rS(),s({handled:!0,message:"Compacted context"})}case"reload":if(!i)return s({handled:!0,error:"No active session to reload"});return await tM(i,{type:"reload"}),await Promise.all([rj(i,!1,!0),rw(i),rz(),r2()]),s({handled:!0,message:"Reloaded session resources"});case"name":if(!i)return s({handled:!0,error:"No active session to name"});if(!o)return s({handled:!0,error:"Usage: /name <name>"});return await tM(i,{type:"set_session_name",name:e9(o)}),await rj(i)&&rS(),s({handled:!0,message:`Session renamed to ${o}`});case"session":{if(!i)return s({handled:!0,error:"No active session"});let e=await tM(i,{type:"get_session_stats"});return e&&ty(e),u?.(),s({handled:!0,action:"openSessionStats"})}case"copy":{if(!i)return s({handled:!0,error:"No active session"});let e=await tM(i,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return s({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),s({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return s({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===r&&tn(!1)}},[rW,rC,tr,r2,rj,rz,rw,rS,u]),r4=(0,o.useCallback)(async e=>{let t=!1;try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(r.ok){let e=await r.json(),n=e.state;if(e.running&&n&&(n.isStreaming||n.isPromptRunning||n.isBashRunning||n.isCompacting))return;t=!0}}catch{}t?rD():rU(e)},[rU,rD]),r5=(0,o.useCallback)(async(e,t)=>{let r=tV.current;if(!r)return;let n=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tY.current=!0,q(!0),td(e=>e??{kind:"waiting_model"});try{await tM(r,{type:"steer",message:e,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to steer:",e),r4(r)}},[r4]),r3=(0,o.useCallback)(async(e,t,r)=>{let n=tV.current;if(!n)return;let o=r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tY.current=!0,q(!0),td(e=>e??{kind:"waiting_model"});try{await tM(n,{type:"prompt",message:e,streamingBehavior:t,...o?.length?{images:o}:{}})}catch(e){console.error("Failed to queue prompt:",e),r4(n)}},[r4]),r8=(0,o.useCallback)(async(e,t)=>{let r=tV.current;if(!r)return;let n=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tY.current=!0,q(!0),td(e=>e??{kind:"waiting_model"});try{await tM(r,{type:"follow_up",message:e,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to follow up:",e),r4(r)}},[r4]),r7=(0,o.useCallback)(async()=>{let e=tV.current;if(e)try{await tM(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),r9=(0,o.useCallback)(async()=>{let t=tV.current;if(t)try{let r=await tM(t,{type:"clear_queue"});tE({steering:[],followUp:[]});let n=[...r?.steering??[],...r?.followUp??[]];n.length>0&&e.chatInputRef?.current?.prependText(n.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),rW({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,rW,tE]);(0,o.useEffect)(()=>{0===t$.length&&tA(!1)},[t$.length]);let ne=(0,o.useCallback)(async(e,t,r=!1)=>{let n=tV.current;if(!n)return t$;try{let o=await tM(n,{type:"resolve_recovery",keep:e,discard:t,continueRun:r}),i=o?.remaining??[];return tL(i),r&&e.length>0&&(async()=>{try{let e=await fetch(`/api/agent/${encodeURIComponent(n)}`);if(!e.ok)return;let t=await e.json(),r=t.state;if(!t.running||!r||!r.isStreaming&&!r.isPromptRunning)return;tG.current=!!r.isStreaming,tX.current=!!r.isPromptRunning,tY.current=!0,q(!0),td(cn(r)),A({type:"start"}),rI(n),!r.isStreaming&&r.isPromptRunning&&rU(n)}catch{}})(),i}catch(e){return console.error("Failed to resolve queued message recovery:",e),rW({type:"error",message:"Failed to resolve queued message recovery"}),t$}},[t$,rW,rI,rU,tL]),nt=(0,o.useCallback)(async()=>{let e=tV.current;if(!e)return null;try{return await tM(e,{type:"export_queue"})}catch(e){return console.error("Failed to export queue:",e),rW({type:"error",message:"Failed to export queue"}),null}},[rW]),nr=(0,o.useCallback)(async e=>{let t=tV.current;if(!t)return null;try{let r=await tM(t,{type:"import_queue",entries:e});return r&&tE(ci(r)),r?.imported??0}catch(e){return console.error("Failed to import queue:",e),rW({type:"error",message:"Failed to import queue"}),null}},[rW,tE]),nn=(0,o.useCallback)(async e=>{let t=tV.current;if(!t)return null;try{let r=await tM(t,{type:"stage_recovery",entries:e});return r?.pendingRecovery&&tL(r.pendingRecovery),(r?.staged??0)>0&&tA(!0),r?.staged??0}catch(e){return console.error("Failed to stage imported queue:",e),rW({type:"error",message:"Failed to stage imported queue"}),null}},[rW,tL]),no=(0,o.useCallback)(async(e,t,r)=>{let n=tV.current;if(!n)return!1;try{let o=await tM(n,{type:"move_queue",kind:e,fromIndex:t,toIndex:r});return o&&tE(ci(o)),!0}catch(e){return console.error("Failed to move queued message:",e),rW({type:"error",message:e instanceof Error?e.message:"Failed to move queued message"}),!1}},[rW,tE]),ni=(0,o.useCallback)(async(e,t)=>{let r=tV.current;if(!r)return null;try{let n=await tM(r,{type:"recall_queue_item",kind:e,index:t});return n&&(void 0!==n.steering||void 0!==n.followUp)&&tE(ci(n)),n?.entry?{text:n.entry.text,images:n.entry.images?.map(({data:e,mimeType:t})=>({data:e,mimeType:t}))}:null}catch(e){return console.error("Failed to recall queued message:",e),rW({type:"error",message:e instanceof Error?e.message:"Failed to recall queued message"}),null}},[rW,tE]),ns=(0,o.useCallback)(async(e,t,r,n)=>{let o=tV.current;if(!o)return!1;try{let i=await tM(o,{type:"requeue_at",kind:e,index:t,text:r,images:n?.map(({data:e,mimeType:t})=>({type:"image",data:e,mimeType:t}))});return i&&tE(ci(i)),!0}catch(e){return console.error("Failed to requeue message:",e),rW({type:"error",message:e instanceof Error?e.message:"Failed to requeue message"}),!1}},[rW,tE]),nl=(0,o.useCallback)(async(e,t)=>{let r=tV.current;if(!r)return!1;try{let n=await tM(r,{type:"remove_queue_item",kind:e,index:t});return n&&tE(ci(n)),!0}catch(e){return console.error("Failed to remove queued message:",e),rW({type:"error",message:e instanceof Error?e.message:"Failed to remove queued message"}),!1}},[rW,tE]),na=(0,o.useCallback)(async e=>{if(rp.current="auto"===e?null:e,eO(e),"auto"===e)return;let t=tV.current??await rn.current;if(t)try{await tM(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),nd=(0,o.useCallback)(async e=>{let t=(0,d9.xG)(e);rf(e);let r=tV.current??await rn.current;if(r)try{await tM(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[rf]),nc=(0,o.useRef)(0),nu=(0,o.useCallback)(async e=>{let t=tV.current??await rn.current,r=++nc.current;if("plan"===e){if(eg.current="plan"===ep?"default":ep,t)try{await tM(t,{type:"prompt",message:"/plan"})}catch(e){if(nc.current!==r)return;console.error("Failed to enter plan mode:",e)}return}if(t){try{if(await tM(t,{type:"prompt",message:"/plan exit"}),nc.current!==r)return}catch(e){if(nc.current!==r)return;console.error("Failed to exit plan mode:",e)}if(nc.current!==r)return;try{await tM(t,{type:"set_tools",toolNames:(0,d9.xG)(eg.current)})}catch(e){console.error("Failed to restore tools after plan exit:",e)}}},[ep]),np=(0,o.useCallback)(e=>{e$.current=e,em(e);let t=tV.current;if(!t){ev.current=e;return}ev.current=null,fetch(`/api/modes?session=${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(e=>{console.error("Failed to persist mode settings:",e)})},[]),nh=(0,o.useCallback)(e=>{let t=e1(e),r="plan"===ez.current;if(np({...e$.current,collaborationMode:t}),ez.current=t,eE.current={sessionKey:"",signature:""},"goal"!==t){eM.current=null,eD.current=!1,eF(e=>"idle"===e.status?e:{...e,status:"idle",goalText:null});let e=tV.current;e&&tM(e,{type:"goal_stop"}).catch(()=>{})}return"plan"!==t||r?"plan"!==t&&r?nu("normal"):Promise.resolve():nu("plan")},[np,nu]),ng=(0,o.useCallback)(async e=>{np({...e$.current,tokenMode:e2(e)});let t=tV.current??await rn.current;if(t)try{if("economy"!==e||ex.current){if("economy"!==e){let e=ex.current?d9.SC:(0,d9.xG)("plan"===ep?"default":ep);await tM(t,{type:"set_tools",toolNames:e})}}else await tM(t,{type:"set_tools",toolNames:[...e4]})}catch(e){console.error("Failed to apply token mode tools:",e)}},[np,ep]),nx=(0,o.useCallback)(async e=>{np({...e$.current,toolApprovalMode:e6(e)});let t=tV.current??await rn.current;if(t)try{await tM(t,{type:"set_approval_mode",mode:e6(e)})}catch(e){console.error("Failed to apply approval mode:",e)}},[np]),nf=(0,o.useCallback)(async e=>{np({...e$.current,permissionRules:e});let t=tV.current??await rn.current;if(t)try{await tM(t,{type:"set_approval_policy",policy:e})}catch(e){console.error("Failed to apply permission rules:",e)}},[np]),nm=(0,o.useCallback)(async(e,t,r,n)=>{let o=tV.current;if(o){if("always"===n){let r=eN.current.find(t=>t.id===e);if(r){let e=ao(r.toolName,r.args),n=e?`${r.toolName}(${e})`:r.toolName,o=e$.current.permissionRules;(t?o.allow:o.deny).includes(n)||nf(t?{...o,allow:[...o.allow,n]}:{...o,deny:[...o.deny,n]})}}try{await tM(o,{type:"resolve_approval",id:e,approve:t,reason:r})}catch(e){console.error("Failed to resolve approval:",e)}finally{eL(t=>t.filter(t=>t.id!==e))}}},[nf]),nv=(0,o.useCallback)(e=>{eM.current=e},[]),ny=(0,o.useCallback)(e=>{let t=e.trim();if(!t)return;eM.current=t,eF(e=>({...e,status:"running",goalText:t,turnsUsed:0,noProgressTurns:0,tokensUsed:0,startedAt:Date.now()}));let r=tV.current;r&&tM(r,{type:"goal_start",goalText:t}).catch(()=>{})},[]),nb=(0,o.useCallback)(()=>{if("running"!==eP.current.status)return;eF(e=>({...e,status:"paused"}));let e=tV.current;e&&tM(e,{type:"goal_pause"}).catch(()=>{})},[]),nk=(0,o.useCallback)(()=>{let e=eP.current;if("paused"!==e.status&&"blocked"!==e.status)return;eF(e=>({...e,status:"running"}));let t=tV.current;t&&tM(t,{type:"goal_resume"}).catch(()=>{})},[]),nj=(0,o.useCallback)(()=>{eD.current=!1,eM.current=null,eF(e=>({...e,status:"idle",goalText:null,turnsUsed:0,noProgressTurns:0}));let e=tV.current;e&&tM(e,{type:"goal_stop"}).catch(()=>{})},[]),nw=(0,o.useCallback)(e=>{let t=e.trim();if(!t)return;eF(e=>({...e,goalText:t}));let r=tV.current;r&&tM(r,{type:"goal_edit",goalText:t}).catch(()=>{})},[]),nS=(0,o.useCallback)(()=>{let e=rr.current,t=t5.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,n=Math.max(0,e.scrollHeight-e.clientHeight),o=Math.min(Math.max(0,r-16),n);t7.current=o>=n-150,re.current=Date.now()+700,e.scrollTo({top:o,behavior:"smooth"})},[]),nC=(0,o.useCallback)(e=>{if(e instanceof KeyboardEvent){if(!cl.has(e.key)||e.target instanceof Element&&e.target.closest("input, textarea, [contenteditable='true']"))return}else if(e instanceof PointerEvent){let t=rr.current;if(t&&e.target instanceof Element&&!t.contains(e.target))return}t9.current=Date.now()+1200},[]),nz=(0,o.useCallback)(()=>{let e=rr.current;if(e){let{scrollTop:t,clientHeight:r,scrollHeight:n}=e;t7.current=t+r>=n-150}if(Date.now()<t9.current){t8.current=!1;return}Date.now()<re.current||(t8.current=!1)},[]);(0,o.useEffect)(()=>{if(tQ.current=!0,t){tV.current=t.id;let e=eR.current,r=eI.current;("auto"!==e||r.allow.length||r.ask.length||r.deny.length)&&(tM(t.id,{type:"set_approval_mode",mode:e}).catch(()=>{}),tM(t.id,{type:"set_approval_policy",policy:r}).catch(()=>{}));let n=e=>{!t2.current&&(t2.current=!0,e.isBashRunning&&(t1.current=!0,V(!0)),rw(t.id),(e.isStreaming||e.isPromptRunning)&&(tG.current=!!e.isStreaming,tX.current=!!e.isPromptRunning,tY.current=!0,q(!0),td(cn(e)),A({type:"resume"}),rI(t.id),!e.isStreaming&&e.isPromptRunning&&rU(t.id)))};(async()=>{try{let e,r=new AbortController,o=setTimeout(()=>r.abort(),2e4);try{e=await fetch(`/api/sessions/${encodeURIComponent(t.id)}/state`,{signal:r.signal})}finally{clearTimeout(o)}if(!e.ok)throw Error(`HTTP ${e.status}`);let i=await e.json();if(!tQ.current||tV.current!==t.id)return;i.running&&i.state&&n(i.state)}catch{}})(),rj(t.id,!0,!0).then(e=>{e?.running&&e.state&&n(e.state),e?.state&&(void 0!==e.state.isCompacting&&tn(e.state.isCompacting),void 0!==e.state.contextUsage&&eq(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&eV(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&eO(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&tC(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&tT(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&tE(ci(e.state.queuedMessages)),void 0!==e.state.pendingRecovery&&tL(e.state.pendingRecovery??[])),e?.running||(async()=>{for(let e=0;e<5;e++){if(e>0&&await new Promise(e=>setTimeout(e,2e3)),!tQ.current||tV.current!==t.id||tY.current)return;try{let e=await fetch(`/api/agent/${encodeURIComponent(t.id)}`);if(!e.ok)continue;let r=await e.json();if(!tQ.current||tV.current!==t.id)return;if(r?.running&&r.state)return void n(r.state)}catch{}}})()})}return()=>{tQ.current=!1,f.current?.abort(),v.current?.abort(),rg(),tD(),rT(),rR()}},[rg]),(0,o.useEffect)(()=>{c?.(eK)},[eK,c]),(0,o.useEffect)(()=>{d&&d(g?.tree??[],w,rQ)},[g?.tree,w,rQ,d]),(0,o.useEffect)(()=>(window.addEventListener("keydown",nC),window.addEventListener("pointerdown",nC,{passive:!0}),()=>{window.removeEventListener("keydown",nC),window.removeEventListener("pointerdown",nC)}),[nC]),(0,o.useEffect)(()=>{let e=rr.current;if(e)return e.addEventListener("wheel",nC,{passive:!0}),e.addEventListener("touchstart",nC,{passive:!0}),e.addEventListener("scroll",nz,{passive:!0}),()=>{e.removeEventListener("wheel",nC),e.removeEventListener("touchstart",nC),e.removeEventListener("scroll",nz)}},[C.length,y,nz,nC]),(0,o.useEffect)(()=>{C.length>0&&(t3.current?(t4.current=!0,t5.current&&(t3.current=!1,nS())):y||!t4.current?(y||(t4.current=!0),rK("instant")):!tY.current&&(t8.current||t7.current)&&(rK("smooth"),nI(e=>e+1)))},[C.length,y,_,rK,nS]);let nT=(0,o.useRef)(null),[nR,nI]=(0,o.useState)(0),nM=`${t?.id??null}#${nR}`;(0,o.useEffect)(()=>{let e;if(y){nT.current=null;return}if(0===C.length||nT.current===nM)return;nT.current=nM;let t=!1,r=!1,n=-1,o=0,i=Date.now(),s=()=>{if(t||r)return;let l=rr.current;if(l){if(Date.now()<t9.current){let{scrollTop:e,clientHeight:t,scrollHeight:n}=l;if(e+t<n-150){r=!0;return}}if(rK("instant"),l.scrollHeight===n){if((o+=1)>=4||Date.now()-i>=3e4)return}else if(n=l.scrollHeight,o=0,Date.now()-i>=3e4)return;e=window.setTimeout(s,o>0?500:250)}};return e=window.setTimeout(s,250),()=>{t=!0,void 0!==e&&window.clearTimeout(e)}},[y,rK,nM]),(0,o.useEffect)(()=>{let e=new AbortController;return r2(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[r2,a]),(0,o.useEffect)(()=>{if(!es)return;let e=()=>{"visible"===document.visibilityState&&r2()};return document.addEventListener("visibilitychange",e),window.addEventListener("online",e),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("online",e)}},[es,r2]),(0,o.useEffect)(()=>{if(!to)return;let e=setTimeout(()=>ti(null),3e3);return()=>clearTimeout(e)},[to]),(0,o.useEffect)(()=>{if(!ts)return;let e=setTimeout(()=>tl(null),6e3);return()=>clearTimeout(e)},[ts]),(0,o.useEffect)(()=>{if(0===tf.visible.length)return;let e=tf.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{tm({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!tf.visible[0])return;let t=setTimeout(()=>{tm({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[tf.visible]),(0,o.useEffect)(()=>{ty(null)},[C.length,e_?.tokens,e_?.percent,e_?.contextWindow]);let nE=g?.tree??[];return{data:g,loading:y,error:k,activeLeafId:w,messages:C,activeToolResults:T,entryIds:I,historyCursor:E,hasEarlierMessages:W,streamState:N,agentRunning:_,bashRunning:K,pendingBash:J,modelNames:G,modelList:Z,modelThinkingLevels:ee,modelThinkingLevelMaps:er,modelScopeWarnings:eo,modelsError:es,newSessionModel:ea,toolPreset:ep,thinkingLevel:eH,retryInfo:eB,contextUsage:e_,systemPrompt:eK,forkingEntryId:eJ,isCompacting:tr,compactError:to,compactResult:ts,currentModel:ry,displayModel:rb,sessionStats:rk,tokenRate:P,planMode:eC,collaborationMode:ek,tokenMode:ej,toolApprovalMode:ew,permissionRules:eS,modeSettings:ef,approvalRequests:eW,handleCollaborationModeChange:nh,handleTokenModeChange:ng,handleToolApprovalModeChange:nx,handlePermissionRulesChange:nf,resolveApproval:nm,setActiveGoalText:nv,goalState:eA,handleGoalStart:ny,handleGoalPause:nb,handleGoalResume:nk,handleGoalStop:nj,handleGoalEdit:nw,slashCommands:tp,slashCommandsLoading:tg,queuedMessages:tR,pendingRecovery:t$,recoveryIsImport:tN,notices:tf.visible,extensionDialog:tb,extensionCustomUi:tj,extensionStatuses:tS,extensionWidgets:tz,respondToExtensionUi:rE,sendExtensionCustomInput:r$,agentPhase:ta,isNew:p,promptAnchorActive:tc,branchTree:nE,sessionIdRef:tV,eventSourceRef:tH,messagesEndRef:rt,scrollContainerRef:rr,lastUserMsgRef:t5,pendingScrollToUserRef:t3,initialScrollDoneRef:t4,scrollUserMsgToTop:nS,handleSend:rJ,executeBash:rY,handleAbort:rG,handleFork:rX,handleNavigate:rZ,handleModelChange:r0,handleCompact:r1,handleSteer:r5,handleFollowUp:r8,handlePromptWithStreamingBehavior:r3,handleAbortCompaction:r7,handleRecallQueue:r9,resolveRecovery:ne,exportQueueData:nt,importQueueData:nr,stageQueueImport:nn,moveQueuedMessage:no,recallQueuedMessage:ni,requeueAt:ns,removeQueuedMessage:nl,handleBuiltinSlashCommand:r6,handleToolPresetChange:nd,handleThinkingLevelChange:na,loadTools:rw,loadSlashCommands:rz,reloadModels:r2,setActiveLeafId:S,setData:x,setMessages:z,loadContext:rN,dispatch:A,setAgentRunning:q,setForkingEntryId:eY,handleLeafChange:rQ,handleAgentEventRef:t6}}({session:e,newSessionCwd:t,onAgentEnd:N,onSessionCreated:s,onSessionForked:a,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:u,onSystemPromptChange:p,onSessionStatsPanelOpen:g}),[tC,tz]=(0,o.useState)(!1);(0,o.useEffect)(()=>{0===ef.length&&tz(!1)},[ef.length]);let tT=(0,o.useMemo)(()=>{let e=O.findLast(e=>"assistant"===e.role&&!!e.usage);if(!e?.usage)return null;let t=e.usage;return{model:e.model??"",input:t.input??0,output:t.output??0,cacheRead:t.cacheRead??0,costCNY:lL(e.model)?lN(e.model,t):0,costUSD:lL(e.model)?0:t.cost?.total??0}},[O]),[tR,tI]=(0,o.useState)(!1),[tE,t$]=(0,o.useState)(null),tW=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(!ta){tW.current=!1;return}if(q){tW.current=!0;return}tW.current&&(tW.current=!1,t$(function(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if("assistant"!==r.role)continue;let n=r.content;if("string"==typeof n&&n.trim())return n;if(Array.isArray(n)){let e=n.filter(e=>"text"===e.type).map(e=>e.text??"").join("\n").trim();if(e)return e}}for(let t=e.length-1;t>=0;t--){let r=e[t];if("toolResult"!==r.role)continue;let n=r.content,o="string"==typeof n?n:Array.isArray(n)?n.map(e=>e.text??"").join("\n"):"";if(!o)continue;let i=o.match(/\*\*Proposed Plan\*\*\s*\n+([\s\S]+)/i);if(i?.[1]?.trim())return i[1].trim()}return null}(O)??null),tI(!0))},[q,ta,O]);let tL=(0,o.useCallback)(()=>{tI(!1);let e=tN.current;e&&tp("plan"===td?"normal":td).catch(e=>{console.error("Failed to leave plan mode before executing:",e)}).then(()=>{eF(E("tasks.planReviewExecutePrompt",{plan:e}))})},[tp,eF,E,td]),tN=(0,o.useRef)(null);(0,o.useEffect)(()=>{tN.current=tE},[tE]);let tA=(0,o.useCallback)(e=>{tI(!1),eF(e)},[eF]),tF=(0,o.useCallback)(()=>{tI(!1),tp("plan"===td?"normal":td)},[tp,td]);(0,o.useEffect)(()=>{ey&&L.current!==ey.id&&(L.current=ey.id,W.current&&$.current())},[ey]),(0,o.useEffect)(()=>(l=q||K?eD:null,()=>void(l=null)),[q,K,eD]);let[tP,tD]=(0,o.useState)(!1),[tH,tO]=(0,o.useState)(!1),[tB,tU]=(0,o.useState)(!1),t_=(0,o.useCallback)(()=>{let e=e$.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;tD(e.scrollTop>1),tO(t>1),tU(t>240)},[e$]),tq=(0,o.useCallback)(()=>{window.requestAnimationFrame(()=>{let e=e$.current,t=eE.current;if(!e||!t)return;let r=Math.max(88,c?.current?.measureHeight?.()??0),n=()=>{if(!e||!t)return;let n=Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop-96-e.clientHeight+r);e.scrollTo({top:n,behavior:"auto"})};n(),t_(),window.setTimeout(n,200)})},[eE,e$,t_,c]);(0,o.useEffect)(()=>{let e=e$.current;if(!e)return;let t=new ResizeObserver(t_);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),e.addEventListener("scroll",t_,{passive:!0}),t_(),()=>{e.removeEventListener("scroll",t_),t.disconnect()}},[O.length,e$,t_]);let tK=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let t=e$.current;if(!t)return;let r=()=>{if(tK.current||!tw||!tj||t.scrollTop>8)return;let r=e?.id;if(!r)return;tK.current=!0;let n=t.scrollHeight-t.scrollTop;tS(r,eR,tj).finally(()=>{tK.current=!1,requestAnimationFrame(()=>{let e=t.scrollHeight-n;Math.abs(t.scrollTop-e)>1&&t.scrollTo({top:e,behavior:"auto"})})})};return t.addEventListener("scroll",r,{passive:!0}),()=>t.removeEventListener("scroll",r)},[e$,tj,tw,tS,e?.id,eR]);let tV=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(!tw||!tj)return;let t=e$.current,r=e?.id;if(!t||!r||tK.current||tV.current||D||t.scrollTop>8||t.scrollHeight>t.clientHeight+50)return;tV.current=!0;let n=t.scrollHeight-t.scrollTop;tS(r,eR,tj).finally(()=>{tV.current=!1,requestAnimationFrame(()=>{let e=t.scrollHeight-n;Math.abs(t.scrollTop-e)>1&&t.scrollTo({top:e,behavior:"auto"})})})},[e$,tj,tw,tS,e?.id,eR,D,O.length]);let tJ=(0,o.useRef)(null),tY=(0,o.useRef)([]),tG=(0,o.useRef)(new Map),tX=(0,o.useRef)(null),[tZ,tQ]=(0,o.useState)(0);(0,o.useEffect)(()=>{let e=tX.current;if(!e)return void tQ(e=>0===e?e:0);let t=()=>{let t=Math.round(e.getBoundingClientRect().height);tQ(e=>e===t?e:t)};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[]);let t0=(0,o.useMemo)(()=>({getOffsetForIndex:e=>tJ.current?.getOffsetForIndex(e)?.[0]??0,sizeFor:e=>{let t=tJ.current;if(!t)return 0;let r=t.measurementsCache[e];return r?.size??t.options.estimateSize?.(e)??0},totalHeight:()=>tJ.current?.getTotalSize()??0,refToItemIndex:e=>tY.current[e],itemCount:tY.current.length}),[]),t1=eu?[eu.sessionId,eu.sessionFile??"",eu.sessionName??"",eu.userMessages,eu.assistantMessages,eu.toolCalls,eu.toolResults,eu.totalMessages,eu.tokens.input,eu.tokens.output,eu.tokens.cacheRead,eu.tokens.cacheWrite,eu.tokens.total,eu.cost??0,eu.totalActiveMs??0].join("|"):null,t2=(0,o.useRef)(eu);t2.current=eu,(0,o.useEffect)(()=>{h?.(t2.current)},[t1,h]),(0,o.useEffect)(()=>()=>{h?.(null)},[h]);let t6=ei?`${ei.percent??"null"}|${ei.contextWindow}|${ei.tokens??"null"}`:null,t4=(0,o.useRef)(ei);t4.current=ei,(0,o.useEffect)(()=>{x?.(t4.current)},[t6,x]),(0,o.useEffect)(()=>()=>{x?.(null)},[x]);let{isDragOver:t5,handleDragEnter:t3,handleDragOver:t8,handleDragLeave:t7,handleDrop:t9}=function(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{e.dataTransfer.files.length&&(e.preventDefault(),n.current+=1,r(!0))},[]),s=(0,o.useCallback)(e=>{e.dataTransfer.files.length&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:s,handleDragLeave:(0,o.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files),t.dataTransfer)},[e])}}((0,o.useCallback)((e,t)=>{if(q){let t=e.filter(e=>e.type.startsWith("image/"));t.length&&c?.current?.addImages(t);return}c?.current?.addFiles(e,t)},[q,c])),re=O.filter(e=>"user"===e.role||"assistant"===e.role),rt=(0,o.useMemo)(()=>{let e=new Set,t=[];for(let n=O.length-1;n>=0&&t.length<50;n-=1){var r;let o="user"!==(r=O[n]).role?null:("string"==typeof r.content?r.content:r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n")).trim()||null;!o||e.has(o)||(e.add(o),t.push(o))}return t},[O]),rr=(S=re.length,(C=(0,o.useRef)([])).current.length!==S&&(C.current=Array.from({length:S},(e,t)=>C.current[t]??null)),C),rn=ez&&0===O.length&&!_.isStreaming&&!q,ro=e?.cwd??t??void 0,ri=(0,o.useMemo)(()=>(function(e,t,r,n){let o=new Map(n);for(let t of e)"toolResult"===t.role&&o.set(t.toolCallId,t);let i=-1;for(let t=e.length-1;t>=0;t--)if("user"===e[t].role){i=t;break}let s=new Map,l=0;e.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&s.set(t,l++)});let a=[];for(let n=0;n<e.length;){let i,s=e[n],l="custom"===s.role&&"compaction"===s.customType;if(0===n&&"user"!==s.role&&!l){let r=1;for(;r<e.length&&"user"!==e[r].role;)r+=1;let i=Array.from({length:r},(e,t)=>t).filter(t=>ss(e[t])),s=st(e,t,i,o);if(s.length>0){a.push({kind:"turn",userIdx:-1,endIdx:r,startsCompactionTurn:!1,finalAssistantIdx:-1,visibleProcessIndices:i,processBlocks:s,processSegments:i3(s),finalAnswerMessage:null,writtenFiles:void 0}),n=r;continue}}if("user"!==s.role&&!l){a.push({kind:"single",idx:n}),n+=1;continue}let d=n,c=d+1;for(;c<e.length&&"user"!==e[c].role;)c+=1;let u=function(e,t,r){for(let o=r-1;o>t;o--){var n;if("assistant"===(n=e[o]).role&&i6(n).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return o}for(let n=r-1;n>t;n--)if(e[n]?.role==="assistant")return n;return -1}(e,d,c);if(-1===u){let r=Array.from({length:c-d-1},(e,t)=>d+1+t).filter(t=>ss(e[t])),i=st(e,t,r,o);a.push({kind:"turn",userIdx:d,endIdx:c,startsCompactionTurn:l,finalAssistantIdx:u,visibleProcessIndices:r,processBlocks:i,processSegments:i3(i),finalAnswerMessage:null,writtenFiles:void 0}),n=c;continue}let p=[];for(let e=d+1;e<u;e++)p.push(e);let h=p.filter(t=>ss(e[t])),g=e[u],x=i6(g),f=x.processBlocks.length>0?sl(g,x.processBlocks,{omitUsage:!0}):null,m=x.answerBlocks.length>0?sl(g,x.answerBlocks):null,v=st(e,t,h,o);if(f&&(v=v.concat(se(g,{messageIndex:u,entryId:t[u],toolResults:o}).processBlocks)),m){let t=[];for(let r=d+1;r<=u;r++){let n=e[r];if(n?.role==="assistant")for(let e of n.content??[])t.push(e)}i=function(e,t,r){let n=new Set,o=[];for(let i of e){if("toolCall"!==i.type||!function(e){let t,r;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||"edit"===(r=e.toLowerCase())||r.startsWith("edit_")||r.endsWith(".edit")||r.endsWith("_edit")||r.includes("str_replace")||r.includes("replace_editor")}(i.toolName))continue;let e=t?.get(i.toolCallId);if(!e||e.isError)continue;let s=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(i.input);if(!s)continue;let l=function(e,t){let r;if(!e)return null;let n=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),o=e=>n?e.replace(/\\/g,"/"):e,i=o(e),s=t?o(t).replace(/\/+$/,""):void 0,l=/^[a-zA-Z]:\//.test(i),a=i.startsWith("//");if(l||a)r=i;else if(i.startsWith("/")){let e=s?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??s?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];r=e?`${e}${i}`:i}else{if(!s)return null;r=`${s}/${i}`}return so(r)}(s,r);l&&(n.has(l)||(n.add(l),o.push({filePath:l})))}return o}(t,o,r)}a.push({kind:"turn",userIdx:d,endIdx:c,startsCompactionTurn:l,finalAssistantIdx:u,visibleProcessIndices:h,processBlocks:v,processSegments:i3(v),finalAnswerMessage:m,writtenFiles:i}),n=c}return{toolResultsMap:o,lastUserIdx:i,visibleRefIndexByMessage:s,items:a}})(O,U,ro,B),[O,U,ro,B]),rs=ec?X[`${ec.provider}:${ec.modelId}`]??null:null,rl=ec?Z[`${ec.provider}:${ec.modelId}`]??null:null,ra=(0,o.useCallback)(()=>{et()},[et]),rd=(0,o.useCallback)(e=>{tp(e)},[tp]),rc=e?.relation?.kind==="subagent"?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"14px 16px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:12},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,n.jsx)("path",{d:"M12 7v4"})]}),E("subagent.readOnlyNotice")]}):(0,n.jsx)(dO,{ref:c,onSend:eF,onBash:eP,tasksBoardEnabled:b,onAbort:eD,onSteer:q?e_:void 0,onFollowUp:q?eq:void 0,onPromptWithStreamingBehavior:q?eK:void 0,isStreaming:q,model:ec,modelNames:Y,modelList:G,modelScopeWarnings:Q,modelsError:ee,onRetryModels:ra,onModelChange:eB,compactResult:ed,toolPreset:er,onToolPresetChange:e||ez?ti:void 0,collaborationMode:td,toolApprovalMode:tc,onCollaborationModeChange:rd,onToolApprovalModeChange:th,goalState:tf,onGoalStart:tm,onGoalPause:tv,onGoalResume:ty,onGoalStop:tb,thinkingLevel:en,onThinkingLevelChange:e||ez?ts:void 0,availableThinkingLevels:rs,thinkingLevelMap:rl,retryInfo:eo,queuedMessages:ex,inputHistory:rt,onRecallQueue:eJ,onMoveQueue:te,onRecallOne:tt,onRequeueAt:tr,onRemoveQueueItem:tn,slashCommands:eh,slashCommandsLoading:eg,onLoadSlashCommands:tl,onBuiltinCommand:to,onAudioUnlock:I,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t,topCenterControl:tB?(0,n.jsx)("button",{type:"button",className:"chat-input-top-center",onClick:tq,title:E("desktop.scrollToBottom"),"aria-label":E("desktop.scrollToBottom"),children:(0,n.jsx)(lT.Z,{size:16,weight:"bold","aria-hidden":"true"})}):void 0}),ru=ej.filter(e=>"belowEditor"!==e.placement),rp=ej.filter(e=>"belowEditor"===e.placement),rh=el?E("desktop.compacting"):function(e,t){if(e?.kind==="running_tools"){let r=e.tools.map(e=>e.name);return 0===r.length?t("desktop.runningTool"):t("desktop.runningTools",{tools:r.length<=3?r.join(", "):`${r.slice(0,2).join(", ")} (+${r.length-2})`})}return e?.kind==="waiting_model"?t("desktop.waitingForModel"):e?.kind==="running_command"?t("desktop.runningCommand"):null}(eC,E);return D?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:E("desktop.loadingSession")}):H?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:H}):(0,n.jsxs)("div",{className:"relative flex h-full min-w-0 flex-col overflow-hidden",onDragEnter:t3,onDragOver:t8,onDragLeave:t7,onDrop:t9,children:[t5&&(0,n.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,n.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,n.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${e}s`}},e))}),(0,n.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,n.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,n.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,n.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,n.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,n.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,n.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,n.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,n.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,n.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,n.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),ey&&(0,n.jsx)(ck,{request:ey,onRespond:ew}),eb&&(0,n.jsx)(cj,{request:eb,onInput:eS}),!ez&&ef.length>0&&!tC&&(0,n.jsx)(d_,{items:ef,sessionId:e?.id,onResolve:eY,onExport:eG,onStageImport:eX,onDismiss:()=>tz(!0),mode:em?"import":"recovery"}),tg.length>0&&(0,n.jsx)(as,{request:tg[0]??null,queuedCount:Math.max(0,tg.length-1),busy:!1,onResolve:(e,t,r)=>{let n=tg[0];n&&tx(n.id,e,t,r)}}),rn?(0,n.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto",children:(0,n.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,n.jsx)("div",{style:{display:"flex",justifyContent:"center",marginBottom:28},children:(0,n.jsxs)("svg",{fill:"currentColor",fillRule:"evenodd",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",style:{width:64,height:64,color:"var(--accent)",opacity:.85},"aria-label":"Pi",children:[(0,n.jsx)("title",{children:"Pi"}),(0,n.jsx)("path",{clipRule:"evenodd",d:"M1 1h16.5v11H12v5.5H6.5V23H1V1zm5.5 5.5V12H12V6.5H6.5z"}),(0,n.jsx)("path",{d:"M17.5 12H23v11h-5.5V12z"})]})}),M&&(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:10,marginBottom:18,marginTop:-14},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.18.3"]})]}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.85.1"]})]})]}),(0,n.jsx)("div",{style:{padding:"0 34px 6px 7px",paddingRight:M?16:34},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,n.jsx)("div",{ref:m,style:{display:"flex",alignItems:"center",minWidth:0,flex:1,minHeight:48}}),(0,n.jsxs)("div",{style:{display:M?"none":"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.18.3"]})]}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.85.1"]})]})]})]})}),(0,n.jsx)("div",{style:{padding:"0 16px",paddingRight:M?16:34},children:(0,n.jsx)(cb,{notices:ev,align:"right"})}),"goal"===td&&(0,n.jsx)(an,{goalState:tf,onPause:tv,onResume:ty,onStop:tb,onEdit:tk}),rc,(0,n.jsx)("div",{style:{padding:"0 16px 6px",paddingRight:M?16:34,marginTop:-15},children:(0,n.jsx)(d1,{onViewFullHistory:v,cwd:ro,systemPrompt:y,sessionStats:eu,contextUsage:ei,hasSession:!!e,showChat:!0,showSoundLabel:!0,soundEnabled:z,onSoundToggle:T,onCompact:e?eU:void 0,onAbortCompaction:eV,isCompacting:el,compactError:ea,lastTurnUsage:tT})})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden z-0",children:[(0,n.jsx)("div",{style:{position:"absolute",top:12,left:0,right:18*!M,zIndex:40,padding:"0 16px",pointerEvents:"none"},children:(0,n.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,n.jsx)(cb,{notices:ev,floating:!0,align:"right"})})}),(0,n.jsxs)("div",{className:"relative flex-1 min-h-0 min-w-0",children:[(0,n.jsx)("div",{ref:e$,className:"h-full min-w-0 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:(0,n.jsx)("div",{style:{minWidth:0,padding:"0 16px"},children:(0,n.jsxs)("div",{style:{width:"100%",minWidth:0,maxWidth:820,margin:"0 auto"},children:[(0,n.jsxs)("div",{ref:tX,children:[(0,n.jsx)(cv,{statuses:ek}),(0,n.jsx)(cy,{widgets:ru})]}),(()=>{let{toolResultsMap:t,lastUserIdx:r,visibleRefIndexByMessage:o,items:i}=ri,s=tG.current,l=(i,l={})=>{let a=l.messageOverride??O[i];if(!a||"toolResult"===a.role)return null;let d="user"===a.role||"assistant"===a.role,c=o.get(i),u=l.keyPrefix??"message",p=!1;if("assistant"===a.role){p=!0;for(let e=i+1;e<O.length;e++){let t=O[e].role;if("user"===t)break;if("assistant"===t){p=!1;break}}p&&_.isStreaming&&i===O.length-1&&(p=!1)}void 0!==l.showTimestamp&&(p=l.showTimestamp);let h=(0,n.jsx)(lO,{message:a,toolResults:t,modelNames:Y,cwd:ro,onOpenFile:f,entryId:U[i],onFork:q||ez?void 0:eH,forking:es===U[i],onNavigate:q?void 0:eO,onEditContent:A,onQuoteReply:F,onOpenSession:k,onCreateTask:P,showTimestamp:p,prevTimestamp:i>0?O[i-1].timestamp:void 0,sessionId:e?.id??eM.current??void 0,writtenFiles:l.writtenFiles},`${u}-view-${i}`);return d&&!1!==l.attachRef&&void 0!==c?(0,n.jsx)("div",{ref:((e,t)=>{let n=s.get(t);if(!n){let e={isLastUser:!1};n={state:e,callback:r=>{rr.current[t]=r,e.isLastUser&&(eW.current=r,r&&eL.current&&(eL.current=!1,eN.current=!0,eA()))}},s.set(t,n)}return n.state.isLastUser=e===r,n.callback})(i,c),children:h},`${u}-${i}`):h},a=[],d=[],c=[],u=(e,t,r)=>{null!==e&&(a.push(e),d.push(t),c.push(r))},p=(e,t)=>U[e]||`${t}-${e}`,h=e=>`live-answer-u${e}`,g=e=>`answer-${p(e,"user")}`,x=e=>`subagent-${e}`,m=e=>i5(e.result?.details)?e.result.details.sessionId:"",v=(e,t)=>`live-process-u${e}-seg${t}`,y=(e,t,r)=>`process-${p(e,"user")}-${r||`seg${t}`}`;for(let s of i){if("single"===s.kind){if(O[s.idx]?.role==="toolResult")continue;u(l(s.idx),o.get(s.idx),p(s.idx,"single"));continue}let{userIdx:i,endIdx:a,startsCompactionTurn:d,finalAssistantIdx:c}=s;if((q||_.isStreaming)&&a===O.length&&(i===r||d)){i>=0&&u(l(i),o.get(i),p(i,"user"));let r=_.streamingMessage?.role==="assistant",s=[],d=!r&&c>=0?c:a;for(let e=i+1;e<d;e++)ss(O[e])&&s.push(e);let g=st(O,U,s,t),y=null;if(!r&&c>=0){let e=O[c],r=i6(e,{isStreaming:!0}),n=se(e,{messageIndex:c,entryId:U[c],toolResults:t,isStreaming:!0});g=g.concat(n.processBlocks),r.answerBlocks.length>0&&(y=sl(e,r.answerBlocks,{omitUsage:!0}))}if(r){let e=_.streamingMessage,r=i6(e,{isStreaming:!0}),n=se(e,{messageIndex:O.length,toolResults:t,isStreaming:!0});g=g.concat(n.processBlocks),r.answerBlocks.length>0&&(y=sl(e,r.answerBlocks,{omitUsage:!0}))}if(g.length>0){let t=s.map(e=>o.get(e)).find(e=>"number"==typeof e);i3(g).forEach((r,o)=>{"subagent"===r.kind&&r.subagent?u((0,n.jsx)(a2,{run:r.subagent,onOpenSubagent:j,sessionRun:w?.get(m(r.subagent))},x(r.subagent.toolCallId)),t,x(r.subagent.toolCallId)):u((0,n.jsx)("div",{ref:void 0===t?void 0:e=>{rr.current[t]=e},children:(0,n.jsx)(aQ,{blocks:r.blocks,isStreaming:q||_.isStreaming,cwd:ro,onOpenFile:f,sessionId:e?.id??eM.current??void 0,tokenRate:ep})},v(i,o)),t,v(i,o))})}y&&u((0,n.jsx)(lO,{message:y,isStreaming:!0,modelNames:Y,cwd:ro,onOpenFile:f,onQuoteReply:F,onOpenSession:k},`live-answer-${i}`),c>=0?o.get(c):void 0,h(i));continue}if(-1===c&&0===s.processBlocks.length){if(i>=0)for(let e=i;e<a;e++)u(l(e),o.get(e),p(e,"raw"));continue}i>=0&&u(l(i),o.get(i),p(i,"user"));let{finalAnswerMessage:b,writtenFiles:S,visibleProcessIndices:C}=s;if(s.processBlocks.length>0){let t=C.map(e=>o.get(e)).find(e=>"number"==typeof e)??(b?void 0:o.get(c));s.processSegments.forEach((r,o)=>{"subagent"===r.kind&&r.subagent?u((0,n.jsx)(a2,{run:r.subagent,onOpenSubagent:j,sessionRun:w?.get(m(r.subagent))},x(r.subagent.toolCallId)),t,x(r.subagent.toolCallId)):u((0,n.jsx)("div",{ref:void 0===t?void 0:e=>{rr.current[t]=e},children:(0,n.jsx)(aQ,{blocks:r.blocks,isStreaming:!1,defaultExpanded:!1,onAutoExpanded:void 0,cwd:ro,onOpenFile:f,sessionId:e?.id??eM.current??void 0})},`process-group-${i}-${o}`),t,y(i,o,r.blocks[0]?.id??""))})}if(b&&u(l(c,{messageOverride:b,writtenFiles:S}),o.get(c),g(i)),c>=0)for(let e=c+1;e<a;e++)u(l(e),o.get(e),p(e,"tail"))}let b=[],S=d.map((e,t)=>({startRef:e,itemIdx:t})).filter(e=>void 0!==e.startRef);return S.forEach((e,t)=>{let r=S[t+1]?.startRef??re.length;for(let t=e.startRef;t<r;t++)b[t]=e.itemIdx}),tY.current=b,(0,n.jsx)(d6,{scrollElementRef:e$,items:a,itemKeys:c,virtualizerRef:tJ,headerHeight:tZ})})(),rh&&(el||q&&!_.streamingMessage)&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[rh,eC?.kind==="waiting_model"&&(0,n.jsx)("span",{style:{display:"inline-block",width:12,height:12,marginLeft:6,verticalAlign:"-2px",border:"1.5px solid var(--text-muted)",borderTopColor:"transparent",borderRadius:"50%",animation:"spin 0.6s linear infinite"}})]})}),V&&(0,n.jsx)(lO,{message:{role:"bashExecution",command:V.command,output:"",excludeFromContext:V.excludeFromContext},sessionId:e?.id??eM.current??void 0}),K&&!V&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:E("desktop.runningShellCommand")})}),(0,n.jsx)("div",{style:{height:96}}),(0,n.jsx)("div",{ref:eE}),(0,n.jsx)(l8,{open:tR,planText:tE,busy:q,onExecute:tL,onFeedback:tA,onExit:tF,onClose:()=>tI(!1)})]})})}),tP&&(0,n.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-8 bg-gradient-to-b from-[var(--bg)] to-transparent"}),tH&&(0,n.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8 bg-gradient-to-t from-[var(--bg)] to-transparent"})]}),M?null:(0,n.jsx)(d3,{messages:O,streamingMessage:_.streamingMessage,scrollContainer:e$,messageRefs:rr,virtualizer:t0})]}),(0,n.jsxs)("div",{className:"relative z-10",children:[(0,n.jsx)("div",{style:{padding:"0 16px",paddingRight:M?16:34},children:(0,n.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,n.jsx)(cy,{widgets:rp})})}),rc,(0,n.jsx)("div",{className:`session-info-bar-wrap${M?" is-mobile":""}`,children:(0,n.jsx)("div",{className:"session-info-bar-inner",children:(0,n.jsx)(d1,{onViewFullHistory:v,cwd:ro,systemPrompt:y,sessionStats:eu,contextUsage:ei,hasSession:!!e,showChat:!0,soundEnabled:z,onSoundToggle:T,onCompact:e?eU:void 0,onAbortCompaction:eV,isCompacting:el,compactError:ea,branchTree:eT,branchActiveLeafId:eR,onBranchLeafChange:eI,lastTurnUsage:tT})})})]})]})]})}function cv({statuses:e}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,maxWidth:"100%",padding:"4px 8px",border:"1px solid color-mix(in srgb, var(--accent) 24%, var(--border))",borderRadius:6,background:"color-mix(in srgb, var(--accent) 7%, var(--bg))",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:e.key}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.text})]},e.key))})}function cy({widgets:e}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:e.map(e=>(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"5px 9px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:e.key}),(0,n.jsx)("pre",{style:{margin:0,padding:"8px 9px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:e.lines.join("\n")})]},e.key))})}function cb({notices:e,floating:t=!1,align:r="left"}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:"right"===r?"flex-end":"stretch",marginBottom:10*!t},children:e.map((r,o)=>{let i="error"===r.type?"var(--status-error)":"warning"===r.type?"var(--status-warning)":"success"===r.type?"#10b981":"var(--accent)";return(0,n.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:10,minHeight:44,maxHeight:180,marginBottom:6*(o!==e.length-1),overflowY:"auto",overflowX:"hidden",borderRadius:14,border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",background:"var(--bg)",color:"var(--text-muted)",width:"fit-content",maxWidth:"min(100%, 620px)",boxShadow:t?"0 1px 2px rgba(15,23,42,0.05), 0 10px 28px -14px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",fontSize:13,lineHeight:1.45,transformOrigin:"top center",animation:r.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"0 12px"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i,flexShrink:0}}),(0,n.jsx)("span",{style:{padding:"10px 0",minWidth:0,maxWidth:"100%",overflowWrap:"anywhere",whiteSpace:"pre-wrap"},children:r.message})]},r.id)})})}function ck({request:e,onRespond:t}){let{t:r}=(0,J.s)(),[i,s]=(0,o.useState)("editor"===e.method?e.prefill??"":""),l=(0,o.useCallback)(e=>e?.focus(),[]);(0,o.useEffect)(()=>{s("editor"===e.method?e.prefill??"":"")},[e]);let a=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:i})};return(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:"min(560px, 100%)",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:r("desktop.extensionRequest")})]}),(0,n.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,n.jsx)(la,{children:e.message}),"select"===e.method&&(0,n.jsx)("div",{onKeyDown:e=>{if(!["ArrowDown","ArrowRight","ArrowUp","ArrowLeft","Home","End"].includes(e.key))return;let t=Array.from(e.currentTarget.querySelectorAll("[data-extension-option]")),r=t.indexOf(e.target);if(r<0)return;e.preventDefault();let n="Home"===e.key?0:"End"===e.key?t.length-1:(r+("ArrowDown"===e.key||"ArrowRight"===e.key?1:-1)+t.length)%t.length;t[n]?.focus()},style:{display:"grid",gap:8},children:e.options.map((r,o)=>(0,n.jsx)("div",{role:"button",tabIndex:0,"data-extension-option":!0,"aria-label":r,ref:0===o?l:void 0,onClick:()=>t(e,{value:r}),onKeyDown:n=>{("Enter"===n.key||" "===n.key)&&(n.preventDefault(),t(e,{value:r}))},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},children:(0,n.jsx)("div",{inert:!0,children:(0,n.jsx)(la,{children:r})})},r))}),"input"===e.method&&(0,n.jsx)("input",{autoFocus:!0,className:"extension-input",value:i,placeholder:e.placeholder,onChange:e=>s(e.target.value),onKeyDown:r=>{"Enter"===r.key&&a(),"Escape"===r.key&&t(e,{cancelled:!0})},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,n.jsx)("textarea",{autoFocus:!0,value:i,onChange:e=>s(e.target.value),onKeyDown:r=>{"Escape"===r.key&&t(e,{cancelled:!0}),(r.metaKey||r.ctrlKey)&&"Enter"===r.key&&a()},style:{width:"100%",minHeight:220,padding:10,borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:r("desktop.cancel")}),"confirm"===e.method?(0,n.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"var(--accent-fg)",cursor:"pointer"},children:r("desktop.confirm")}):"select"!==e.method?(0,n.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"var(--accent-fg)",cursor:"pointer"},children:r("desktop.submit")}):null]})]})})}function cj({request:e,onInput:t}){let{t:r}=(0,J.s)(),i=(0,o.useRef)(null),s=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,r=[];for(let n of e){let e=iX(n).trimEnd();if(t.test(e))continue;let o=n,i=i0(o);("│"===i||"┃"===i)&&" "===i0(o=iQ(o,0))&&(o=iQ(o,0));let s=function(e){let t=iZ(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(o),l=s>=0?iZ(o)[s]?.char:void 0;("│"===l||"┃"===l)&&(o=iQ(o,s)),r.push(function(e){let t=e;for(;;){let e=iZ(t),r=e[e.length-1];if(!r||""!==r.char.trim())return t;t=t.slice(0,r.start)+t.slice(r.end)}}(o))}for(;r.length>0&&""===iX(r[0]).trim();)r.shift();for(;r.length>0&&""===iX(r[r.length-1]).trim();)r.pop();return r.length?r:e}(e.lines);return(0,o.useEffect)(()=>{i.current?.focus()},[e.id]),(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,n.jsxs)("div",{ref:i,tabIndex:0,role:"dialog","aria-modal":"true",onKeyDown:r=>{let n=function(e){if(e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length){let t=e.key.toLowerCase();if(t>="a"&&t<="z")return String.fromCharCode(t.charCodeAt(0)-96)}switch(e.key){case"ArrowUp":return"\x1b[A";case"ArrowDown":return"\x1b[B";case"ArrowRight":return"\x1b[C";case"ArrowLeft":return"\x1b[D";case"Enter":return"\r";case"Escape":return"\x1b";case"Backspace":return"";case"Tab":return" ";case" ":return" ";default:if(!e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length)return e.key;return null}}(r);n&&(r.preventDefault(),r.stopPropagation(),t(e,n))},style:{width:"min(920px, 100%)",maxHeight:"min(760px, calc(100vh - 40px))",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:r("desktop.extensionPanel")}),(0,n.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:r("desktop.close")})]}),(0,n.jsx)("pre",{style:{margin:0,padding:14,maxHeight:"calc(min(760px, 100vh - 40px) - 48px)",overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(s.length?s:[""]).map((e,t,r)=>{var i;return(0,n.jsxs)(o.Fragment,{children:[(i=`line-${t}`,(function(e){let t,r=[],n={},o=0;for(iJ.lastIndex=0;null!==(t=iJ.exec(e));)t.index>o&&r.push({text:e.slice(o,t.index),style:n}),n=function(e,t){let r={...e};for(let e=0;e<t.length;e++){let n=t[e];if(0===n)for(let e of Object.keys(r))delete r[e];else if(1===n)r.fontWeight=700;else if(2===n)r.opacity=.65;else if(3===n)r.fontStyle="italic";else if(4===n)r.textDecoration="underline";else if(22===n)delete r.fontWeight,delete r.opacity;else if(23===n)delete r.fontStyle;else if(24===n)delete r.textDecoration;else if(39===n)delete r.color;else if(49===n)delete r.backgroundColor;else if(n>=30&&n<=37)r.color=iY[n-30];else if(n>=90&&n<=97)r.color=iG[n-90];else if(n>=40&&n<=47)r.backgroundColor=iY[n-40];else if(n>=100&&n<=107)r.backgroundColor=iG[n-100];else if((38===n||48===n)&&2===t[e+1]){let[o,i,s]=[t[e+2],t[e+3],t[e+4]];[o,i,s].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===n?r.color=`rgb(${o}, ${i}, ${s})`:r.backgroundColor=`rgb(${o}, ${i}, ${s})`),e+=4}else if((38===n||48===n)&&5===t[e+1]){let o=function(e){if(e>=0&&e<8)return iY[e];if(e>=8&&e<16)return iG[e-8];if(e>=16&&e<=231){let t=e-16,r=Math.floor(t/36),n=Math.floor(t%36/6),o=e=>0===e?0:55+40*e;return`rgb(${o(r)}, ${o(n)}, ${o(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);o&&(38===n?r.color=o:r.backgroundColor=o),e+=2}}return r}(n,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),o=t.index+t[0].length;return o<e.length&&r.push({text:e.slice(o),style:n}),r})(e).map((e,t)=>Object.keys(e.style).length>0?(0,n.jsx)("span",{style:e.style,children:e.text},`${i}-${t}`):e.text)),t<r.length-1?"\n":null]},t)})})]})})}var cw=r(93549);let cS={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",avif:"image/avif"},cC={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",weba:"audio/webm"};function cz(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}function cT(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function cR(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let r=t.getRangeAt(0);if(!e.contains(r.startContainer)||!e.contains(r.endContainer))return null;let n=Number(cT(r.startContainer)?.dataset.lineNumber),o=Number(cT(r.endContainer)?.dataset.lineNumber);return Number.isInteger(n)&&Number.isInteger(o)?n<=o?{startLine:n,endLine:o}:{startLine:o,endLine:n}:null}function cI(e,t,r,n={}){let o=ob(e),i=new URLSearchParams({type:t});for(let[e,t]of(r&&i.set("sessionId",r),Object.entries(n)))void 0!==t&&i.set(e,String(t));return`/api/files/${o}?${i.toString()}`}function cM({filePath:e,sourceSessionId:t}){let{t:r}=(0,J.s)();return(0,n.jsx)("a",{href:cI(e,"download",t),download:ok(e),title:r("desktop.downloadFile"),style:{display:"flex",alignItems:"center",justifyContent:"center",height:20,padding:"0 5px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,textDecoration:"none"},children:(0,n.jsx)(I.z,{size:11,"aria-hidden":"true"})})}let cE={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,tabSize:2},c$={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,padding:"12px 0 12px 16px",color:"var(--text-dim)",textAlign:"right",userSelect:"none"};async function cW(e,t){let r=await fetch(`/api/files/${ob(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!r.ok)throw Error((await r.json().catch(()=>({}))).error??`HTTP ${r.status}`);let n=await r.json();return"number"==typeof n.size?n.size:0}let cL={delete:"3px solid var(--git-status-deleted)",add:"3px solid var(--git-status-added)",edit:"3px solid var(--git-status-modified)"},cN="var(--git-status-deleted-bg)",cA="var(--git-status-added-bg)",cF="var(--git-status-added)";function cP(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function cD({oldContent:e,newContent:t}){let{t:r}=(0,J.s)(),o=function(e,t){let r=e.length,n=t.length,o=r+n,i=Array(2*o+1).fill(0),s=[];for(let l=0;l<=o;l++){s.push([...i]);for(let a=-l;a<=l;a+=2){let d,c=(d=a===-l||a!==l&&i[a-1+o]<i[a+1+o]?i[a+1+o]:i[a-1+o]+1)-a;for(;d<r&&c<n&&e[d]===t[c];)d++,c++;if(i[a+o]=d,d>=r&&c>=n){let i=[],a=r,d=n;for(let r=l;r>0;r--){let n,l=s[r-1],c=a-d;n=c===-r||c!==r&&l[c-1+o]<l[c+1+o]?c+1:c-1;let u=l[n+o],p=u-n;for(;a>u&&d>p;)a--,d--,i.unshift({type:"unchanged",text:e[a]});r>0&&(a>u?(a--,i.unshift({type:"removed",text:e[a]})):(d--,i.unshift({type:"added",text:t[d]})))}for(;a>0&&d>0;)a--,d--,i.unshift({type:"unchanged",text:e[a]});return i}}}return[...e.map(e=>({type:"removed",text:e})),...t.map(e=>({type:"added",text:e}))]}(e.split("\n"),t.split("\n"));if(!o.some(e=>"unchanged"!==e.type))return(0,n.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:r("desktop.noChanges")});let i=new Set(o.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),s=new Set;for(let e of i)for(let t=Math.max(0,e-3);t<=Math.min(o.length-1,e+3);t++)s.add(t);let l=[],a=0;for(;a<o.length;)if(s.has(a)){let e=[];for(;a<o.length&&s.has(a);)e.push(o[a]),a++;l.push({hidden:!1,lines:e})}else{let e=0;for(;a<o.length&&!s.has(a);)e++,a++;l.push({hidden:!0,count:e})}let d=[],c=1;for(let e of o)"removed"===e.type?d.push(0):d.push(c++);let u=0;return(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,minWidth:"max-content"},children:l.map((e,t)=>{if(e.hidden){let o=(0,n.jsx)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:r("desktop.unchangedLines",{count:e.count})},t);return u+=e.count,o}let o=[],i=[],s=[],l=()=>{if(i.length||s.length){let e=i.length&&s.length?"edit":i.length?"delete":"add";for(let t of i)o.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of s)o.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});i=[],s=[]}};e.lines.forEach((e,r)=>{"unchanged"===e.type?(l(),o.push({key:`${t}:${r}`,kind:"context",text:e.text,lineNo:d[u+r],block:null})):"removed"===e.type?i.push({key:`${t}:${r}`,text:e.text}):s.push({key:`${t}:${r}`,text:e.text,lineNo:d[u+r]})}),l();let a=o.map(e=>{let t="removed"===e.kind?cN:"added"===e.kind?cA:"transparent",r=e.block?cL[e.block]:"3px solid transparent",o="added"===e.kind?cF:"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",background:t,borderLeft:r},children:[(0,n.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:o,userSelect:"none",fontSize:11,lineHeight:1.6,flexShrink:0},children:e.lineNo??""}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)});return u+=e.lines.length,(0,n.jsx)("div",{children:a},t)})})}function cH({patch:e}){let t=lk(e);if(!t)return null;let r=[],o=[],i=[],s=()=>{if(o.length||i.length){let e=o.length&&i.length?"edit":o.length?"delete":"add";for(let t of o)r.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of i)r.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});o=[],i=[]}};return t.forEach((e,t)=>{e.rows.forEach((e,n)=>{if("hunk"===e.type){s(),r.push({key:`${t}:${n}:h`,kind:"hunk",text:e.text,lineNo:null,block:null});return}let{left:l,right:a}=e;if("context"===l.type&&"context"===a.type){s(),r.push({key:`${t}:${n}:c`,kind:"context",text:l.text,lineNo:a.lineNo,block:null});return}"removed"===l.type&&o.push({key:`${t}:${n}:l`,text:l.text}),"added"===a.type&&i.push({key:`${t}:${n}:r`,text:a.text,lineNo:a.lineNo})})}),s(),(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:"max-content"},children:r.map(e=>{if("hunk"===e.kind)return(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{height:"1.55em"}}),(0,n.jsx)("div",{style:{padding:"3px 12px",color:"var(--accent-blue)",background:"var(--bg-secondary)"},children:e.text}),(0,n.jsx)("div",{style:{height:"1.55em"}})]},e.key);let t="removed"===e.kind?cN:"added"===e.kind?cA:"transparent",r=e.block?cL[e.block]:"3px solid transparent",o="added"===e.kind?cF:"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",background:t,borderLeft:r},children:[(0,n.jsx)("span",{style:{width:44,flexShrink:0,padding:"0 8px 0 16px",textAlign:"right",color:o,userSelect:"none",fontSize:11},children:e.lineNo??""}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)})})}function cO({filePath:e,cwd:t,sourceSessionId:r}){let{t:i}=(0,J.s)(),[s,l]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),g=(0,o.useRef)(null),x=ok(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{l(0),d(null),u(null),h(null),g.current&&(g.current.close(),g.current=null);let t=new EventSource(cI(e,"watch",r));return g.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}l(e=>e+1)}),()=>{t.close(),g.current=null}},[e,r]);let f=cI(e,"read",r,s?{v:s}:void 0),m=null!=a?cP(a):null;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-status-bar",style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,flexWrap:"wrap",rowGap:4},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 1 auto"},title:e,children:oj(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:x||i("desktop.image")}),c&&(0,n.jsxs)("span",{children:[c.w," \xd7 ",c.h]}),m&&(0,n.jsx)("span",{children:m}),(0,n.jsx)(cM,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",alignItems:"center",justifyContent:"center",padding:16,backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:p?(0,n.jsx)("div",{style:{color:"var(--status-error)",fontSize:13},children:p}):(0,n.jsx)("img",{src:f,alt:e,onLoad:e=>{let t=e.currentTarget;u({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>h(i("desktop.failedToLoadImage")),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function cB({filePath:e,cwd:t,sourceSessionId:r}){let{t:i}=(0,J.s)(),[s,l]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),g=(0,o.useRef)(null),x=ok(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{l(0),d(null),u(null),h(null),g.current&&(g.current.close(),g.current=null);let t=new EventSource(cI(e,"watch",r));return g.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}u(null),h(null),l(e=>e+1)}),()=>{t.close(),g.current=null}},[e,r]);let f=cI(e,"read",r,s?{v:s}:void 0);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-status-bar",style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,flexWrap:"wrap",rowGap:4},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 1 auto"},title:e,children:oj(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:x||i("desktop.audio")}),null!=c&&(0,n.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),r=Math.floor(t/60);return`${r}:${String(t%60).padStart(2,"0")}`}(c)}),null!=a&&(0,n.jsx)("span",{children:cP(a)}),(0,n.jsx)(cM,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,n.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[p&&(0,n.jsx)("div",{style:{color:"var(--status-error)",fontSize:13,marginBottom:12,textAlign:"center"},children:p}),(0,n.jsx)("audio",{controls:!0,preload:"metadata",src:f,onLoadedMetadata:e=>u(e.currentTarget.duration),onError:()=>h(i("desktop.failedToLoadAudio")),style:{width:"100%"}},f)]})})]})}function cU({filePath:e,cwd:t,sourceSessionId:r}){let{t:i}=(0,J.s)(),[s,l]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),p=(0,o.useRef)(null),h=cz(e),g="pdf"===h,x=g?cI(e,"read",r,s?{v:s}:void 0):cI(e,"preview",r,s?{v:s}:void 0);return(0,o.useEffect)(()=>{l(0),d(null),u(null),p.current&&(p.current.close(),p.current=null),fetch(cI(e,"meta",r)).then(e=>e.json()).then(e=>{e.error&&u(e.error),"number"==typeof e.size&&(d(e.size),!g&&e.size>0xa00000&&u(i("desktop.docxTooLargeForPreview")))}).catch(e=>u(String(e)));let t=new EventSource(cI(e,"watch",r));return p.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(d(t.size),!g&&t.size>0xa00000))return void u(i("desktop.docxTooLargeForPreview"))}catch{}u(null),l(e=>e+1)}),()=>{t.close(),p.current=null}},[e,g,r,i]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-status-bar",style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,flexWrap:"wrap",rowGap:4},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:oj(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===h?i("desktop.docxPreview"):"pdf"}),null!=a&&(0,n.jsx)("span",{children:cP(a)}),(0,n.jsx)(cM,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:c?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"var(--status-error)",fontSize:13,textAlign:"center"},children:c}):(0,n.jsx)("iframe",{src:x,sandbox:g?void 0:"allow-same-origin",title:i("desktop.previewFile",{file:ok(e)}),style:{width:"100%",height:"100%",border:"none",background:g?"var(--bg)":"#eef1f5"}},x)})]})}function c_({filePath:e,cwd:t,sourceSessionId:r,onOpenFile:o,onAtMention:i,onMentionLines:s,initialDisplayMode:l,onFileSaved:a}){let d;return null!==(cS[cz(e)]??null)?(0,n.jsx)(cO,{filePath:e,cwd:t,sourceSessionId:r}):null!==(cC[cz(e)]??null)?(0,n.jsx)(cB,{filePath:e,cwd:t,sourceSessionId:r}):null!==("pdf"===(d=cz(e))||"docx"===d?d:null)?(0,n.jsx)(cU,{filePath:e,cwd:t,sourceSessionId:r}):(0,n.jsx)(cq,{filePath:e,cwd:t,sourceSessionId:r,onOpenFile:o,onAtMention:i,onMentionLines:s,initialDisplayMode:l,onFileSaved:a})}function cq({filePath:e,cwd:t,sourceSessionId:r,onOpenFile:i,onAtMention:s,onMentionLines:l,initialDisplayMode:a,onFileSaved:d}){let c,u,{t:p}=(0,J.s)(),[g,x]=(0,o.useState)(null),[m,v]=(0,o.useState)(null),[y,b]=(0,o.useState)(null),[k,j]=(0,o.useState)(!0),[w,S]=(0,o.useState)(!1),[C,z]=(0,o.useState)(null),[T,R]=(0,o.useState)(!1),[I,M]=(0,o.useState)("source"),[E,$]=(0,o.useState)(!1),[W,L]=(0,o.useState)(0),[N,A]=(0,o.useState)(null),F=(0,o.useRef)(null),P=(0,o.useRef)(null),[D,H]=(0,o.useState)(!1),[O,B]=(0,o.useState)(""),[U,_]=(0,o.useState)(""),[q,K]=(0,o.useState)(!1),[V,Y]=(0,o.useState)(null),[G,X]=(0,o.useState)(!1),Z=(0,o.useRef)(null),Q=(0,o.useRef)(null),ee=(0,o.useRef)(0),et=(0,o.useRef)(!1);(0,o.useEffect)(()=>{et.current=D},[D]);let er=D&&O!==U,en=!!(g?.content&&g.content.includes("\0")),eo=(0,o.useCallback)(async e=>{if(!t)return void b(null);try{let r=new URLSearchParams({cwd:t,path:e}),n=await fetch(`/api/git/diff?${r.toString()}`),o=await n.json();b(n.ok&&o.supported&&"string"==typeof o.patch?o:null)}catch{b(null)}},[t]),ei=(0,o.useCallback)((e,t=!1,n=0)=>fetch(cI(e,"read",r,n?{offset:n}:void 0)).then(e=>e.json()).then(e=>e.error?(z(e.error),null):(t?(x(t=>(t&&v(t.content),e)),L(e=>e+1)):n?x(t=>t?{...e,content:t.content+e.content}:e):x(e),e)).catch(e=>(z(String(e)),null)),[r]);(0,o.useEffect)(()=>{j(!0),z(null),x(null),v(null),b(null),R(!1),M("source"),$(!1),L(0),H(!1),B(""),_(""),Y(null),X(!1),K(!1),F.current&&(F.current.close(),F.current=null),ei(e).then(e=>{e?.truncated||e?.language!=="markdown"&&e?.language!=="html"||"diff"===a||R(!0)}).finally(()=>j(!1)),eo(e);let t=new EventSource(cI(e,"watch",r));return F.current=t,t.addEventListener("change",()=>{et.current?X(!0):(ei(e,!0),eo(e))}),()=>{t.close(),F.current=null}},[e,ei,eo,a,r]);let es=(0,o.useCallback)(()=>{g&&!en&&(B(g.content),_(g.content),Y(null),X(!1),H(!0))},[g,en]),el=(0,o.useCallback)(()=>{H(!1),B(""),_(""),Y(null),X(!1)},[]),ea=(0,o.useCallback)(()=>{(!er||window.confirm(p("files.unsavedChanges")))&&el()},[er,el,p]),ed=(0,o.useCallback)(async()=>{if(!g||q)return;let t=++ee.current;K(!0),Y(null);try{let r=await cW(e,O);if(t!==ee.current)return;x(e=>e?{...e,content:O,size:r}:e),_(O),K(!1),el(),eo(e),d?.()}catch(e){if(t!==ee.current)return;Y(e instanceof Error?e.message:String(e)),K(!1)}},[g,q,O,e,el,eo,d]);(0,o.useEffect)(()=>{if(!D)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()){e.preventDefault(),ed();return}"Escape"===e.key&&(e.preventDefault(),ea())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[D,ed,ea]),(0,o.useEffect)(()=>{if(!er)return;let e=e=>{e.preventDefault(),e.returnValue=""};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[er]);let ec=(0,o.useCallback)(()=>{let e=Z.current,t=Q.current;e&&t&&(t.scrollTop=e.scrollTop)},[]),eu=(0,o.useCallback)(e=>{if("Tab"!==e.key||e.metaKey||e.ctrlKey||e.altKey)return;e.preventDefault();let t=e.currentTarget,{selectionStart:r,selectionEnd:n}=t;B(t.value.slice(0,r)+" "+t.value.slice(n)),requestAnimationFrame(()=>{let e=Z.current;if(!e)return;let t=r+2;e.selectionStart=t,e.selectionEnd=t})},[]),ep=(0,o.useMemo)(()=>s0(g?.content??""),[g?.content]),eh=y?.supported===!0&&"string"==typeof y.patch;(0,o.useEffect)(()=>{"diff"===a&&eh&&M("diff")},[eh,a]);let eg=eh&&y?.status==="deleted",ex=(0,o.useCallback)(r=>{l&&r&&l(oj(e,t),r.startLine,r.endLine)},[t,e,l]);if((0,o.useEffect)(()=>{let e=()=>{let e=P.current,t="source"===I&&!T;A(l&&t&&e?cR(e,window.getSelection()):null)};if(e(),l&&"source"===I&&!T)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[g?.content,l,T,I]),(0,o.useEffect)(()=>{if(!l||"source"!==I||T)return;let e=e=>{if(e.repeat||"i"!==e.key.toLowerCase()||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest("input, textarea, [contenteditable='true']"))return;let r=P.current,n=r?cR(r,window.getSelection()):null;n&&(e.preventDefault(),ex(n))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ex,l,T,I]),k)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:p("desktop.loadingFile")});if(eg&&!g)return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"5px 16px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:e,children:oj(e,t)}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:(0,n.jsx)(cH,{patch:y.patch})})]});if(C)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--status-error)",fontSize:13},children:C});if(!g)return null;let ef="html"===g.language,em="markdown"===g.language,ev=(u=(c=oy(e).replace(/\/+$/,"")).lastIndexOf("/"))<0?"":0===u?"/":2===u&&/^[a-zA-Z]:\//.test(c)?c.slice(0,3):c.slice(0,u),ey=g.content.split("\n"),eb=null!==m&&m!==g.content||eh,ek=!eg&&!en&&oC();return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-status-bar",style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,flexWrap:"wrap",rowGap:4},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 1 auto"},title:e,children:oj(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:g.language}),"source"===I&&!D&&(0,n.jsx)("span",{children:p("desktop.lines",{count:ey.length})}),(0,n.jsx)("span",{children:cP(g.size)}),eb&&!D&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>M("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===I?"var(--bg-selected)":"var(--bg-hover)",color:"source"===I?"var(--text)":"var(--text-muted)",fontWeight:"source"===I?600:400},children:p("desktop.source")}),(0,n.jsxs)("button",{onClick:()=>M("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===I?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===I?"var(--text)":"var(--text-muted)",fontWeight:"diff"===I?600:400},children:[p("desktop.diff")," ",W>0&&(0,n.jsxs)("span",{style:{color:"var(--git-status-added)",marginLeft:2},children:["+",W]})]})]}),"source"===I&&!T&&!D&&(0,n.jsx)("button",{onClick:()=>$(e=>!e),title:E?p("desktop.disableWordWrap"):p("desktop.enableWordWrap"),style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:E?"var(--bg-selected)":"var(--bg-hover)",color:E?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:E?600:400},children:p("desktop.wrap")}),ef&&"source"===I&&!D&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>R(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:T?"var(--bg-hover)":"var(--bg-selected)",color:T?"var(--text-muted)":"var(--text)",fontWeight:T?400:600},children:p("desktop.code")}),(0,n.jsx)("button",{onClick:()=>R(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:T?"var(--bg-selected)":"var(--bg-hover)",color:T?"var(--text)":"var(--text-muted)",fontWeight:T?600:400},children:p("desktop.preview")})]}),em&&"source"===I&&!D&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>R(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:T?"var(--bg-selected)":"var(--bg-hover)",color:T?"var(--text)":"var(--text-muted)",fontWeight:T?600:400},children:p("desktop.preview")}),(0,n.jsx)("button",{onClick:()=>R(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:T?"var(--bg-hover)":"var(--bg-selected)",color:T?"var(--text-muted)":"var(--text)",fontWeight:T?400:600},children:p("desktop.raw")})]}),D?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>void ed(),disabled:q,title:p("files.saveHint"),"aria-label":p("files.save"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-selected)",color:"var(--text)",cursor:"pointer"},children:(0,n.jsx)(cw.g,{size:13,"aria-hidden":"true"})}),(0,n.jsx)("button",{type:"button",onClick:ea,disabled:q,title:p("files.cancelEdit"),"aria-label":p("files.cancelEdit"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,n.jsx)(h.X,{size:13,"aria-hidden":"true"})})]}):"source"===I&&ek?(0,n.jsx)("button",{type:"button",onClick:es,title:p("files.edit"),"aria-label":p("files.edit"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,n.jsx)(f.I,{size:13,"aria-hidden":"true"})}):null,(s||l)&&!D&&(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{N&&l?ex(N):s?.(oj(e,t),!1)},title:N?p("desktop.mentionSelectedLines",{start:N.startLine,end:N.endLine}):p("desktop.mentionFile"),"aria-label":N?p("desktop.mentionSelectedLines",{start:N.startLine,end:N.endLine}):p("desktop.mentionFile"),style:{height:20,minWidth:20,padding:"0 5px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:"@"}),!D&&(0,n.jsx)(cM,{filePath:e,sourceSessionId:r})]}),g?.truncated&&"source"===I&&!D&&(0,n.jsxs)("div",{className:"file-viewer-load-more",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:10,padding:"5px 8px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsxs)("span",{children:[cP(g.nextOffset)," / ",cP(g.size)]}),(0,n.jsx)("button",{type:"button",disabled:w,onClick:()=>{S(!0),ei(e,!1,g.nextOffset).finally(()=>S(!1))},style:{padding:"2px 10px",fontSize:11,cursor:"pointer",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-hover)",color:"var(--text)",opacity:w?.6:1},children:w?p("i18n.loading"):p("i18n.loadMore")})]}),(0,n.jsx)("div",{ref:P,style:{flex:1,overflow:"auto",background:"var(--bg)"},children:D?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[G&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 12px",borderBottom:"1px solid var(--border)",background:"rgba(214,168,75,0.14)",color:"#d6a84b",fontSize:11,flexShrink:0},children:[(0,n.jsx)("span",{style:{flex:1},children:p("files.externalModified")}),(0,n.jsx)("button",{type:"button",onClick:()=>{(!er||window.confirm(p("files.reloadOverwriteConfirm")))&&ei(e).then(e=>{e&&(B(e.content),_(e.content),X(!1))})},disabled:q,style:{padding:"2px 8px",fontSize:11,border:"1px solid #d6a84b",borderRadius:4,background:"transparent",color:"#d6a84b",cursor:"pointer"},children:p("files.reload")})]}),V&&(0,n.jsx)("div",{style:{padding:"5px 12px",borderBottom:"1px solid var(--border)",background:"rgba(248,113,113,0.14)",color:"var(--status-error)",fontSize:11,flexShrink:0},children:p("files.saveFailed",{error:V})}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsx)("div",{ref:Q,"aria-hidden":"true",style:{...c$,height:"100%",overflow:"hidden",whiteSpace:"pre",pointerEvents:"none"},children:O.split("\n").map((e,t)=>`${t+1}
|
|
195
|
-
`).join("")}),(0,n.jsx)("textarea",{ref:Z,className:"file-editor-textarea",value:O,onChange:e=>B(e.target.value),onScroll:ec,onKeyDown:eu,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",wrap:"off",style:{flex:1,height:"100%",resize:"none",border:"none",outline:"none",background:"var(--bg)",color:"var(--text)",...cE,whiteSpace:"pre",overflow:"auto",padding:0,tabSize:2}})]})]}):"diff"===I&&eb?eh?(0,n.jsx)(cH,{patch:y.patch}):(0,n.jsx)(cD,{oldContent:m,newContent:g.content}):ef&&T?(0,n.jsx)("iframe",{srcDoc:g.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:p("desktop.htmlPreview")}):em&&T?(0,n.jsx)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:(0,n.jsx)(sd.oz,{remarkPlugins:s6,rehypePlugins:s4,components:{h1:({children:e})=>(0,n.jsx)("h1",{id:sQ(e),children:e}),h2:({children:e})=>(0,n.jsx)("h2",{id:sQ(e),children:e}),h3:({children:e})=>(0,n.jsx)("h3",{id:sQ(e),children:e}),code({className:e,children:t,...r}){let o=e?.replace("language-","").toLowerCase()??"",i=String(t);return e?.includes("language-")||i.includes("\n")?"mermaid"===o?(0,n.jsx)(lc,{code:i.replace(/\n$/,"")}):(0,n.jsx)(lh,{code:i.replace(/\n$/,""),lang:o}):(0,n.jsx)("code",{className:"inline max-w-full whitespace-normal break-words [overflow-wrap:anywhere] align-baseline bg-(--bg-secondary) border border-(--border) px-1.5 py-0.5 text-xs font-mono text-(--accent-blue)",...r,children:t})},pre:({children:e})=>(0,n.jsx)(n.Fragment,{children:e}),a({href:e,children:r,...o}){delete o.node;let s="text-(--accent-blue) underline underline-offset-2 hover:text-(--accent-blue)/80",l=i?si(e,ev,t??ev):null;return l&&i?(0,n.jsx)("a",{href:e,...o,className:s,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),i(l))},children:r}):(0,n.jsx)("a",{href:e,...o,className:s,target:"_blank",rel:"noopener noreferrer",children:r})},table:({children:e})=>(0,n.jsx)("div",{className:"my-3 rounded-lg overflow-hidden border border-(--border)",children:(0,n.jsx)("div",{className:"overflow-x-auto",children:(0,n.jsx)("table",{className:"w-full text-sm border-collapse [&_tr:last-child>td]:border-b-0",children:e})})})},children:ep})}):(0,n.jsx)(sc.A,{language:"text"===g.language?"plaintext":g.language,style:s5,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal",minWidth:"3em",paddingRight:"1em"},customStyle:{margin:0,padding:"12px 0",background:"var(--bg)",fontSize:13,lineHeight:1.6,fontFamily:"var(--font-mono)",minHeight:"100%"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},lineProps:e=>({className:"file-source-line","data-line-number":String(e)}),wrapLongLines:E,children:g.content})})]})}function cK({sessionId:e,label:t,running:r=!1,onOpenFile:i}){let{t:s}=(0,J.s)(),[l,a]=(0,o.useState)([]),[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(!0),[h,g]=(0,o.useState)(null);(0,o.useEffect)(()=>{let t=!1;return(async r=>{r&&p(!0);try{let r=await fetch(`/api/sessions/${encodeURIComponent(e)}?tail=500`,{cache:"no-store"}),n=await r.json();if(t)return;if(!r.ok)throw Error(n.error??`HTTP ${r.status}`);a(n.context?.messages??[]),c([]),g(null)}catch(e){if(t)return;g(e instanceof Error?e.message:String(e))}finally{t||p(!1)}})(!0),()=>{t=!0}},[e]),(0,o.useEffect)(()=>{if(!r)return;let t=!1,n=window.setInterval(async()=>{if("visible"===document.visibilityState)try{let r=await fetch(`/api/sessions/${encodeURIComponent(e)}?tail=500`,{cache:"no-store"});if(!r.ok)return;let n=await r.json();if(t)return;a(n.context?.messages??[])}catch{}},2500);return()=>{t=!0,window.clearInterval(n)}},[r,e]);let x=(0,o.useMemo)(()=>{let e=new Map;for(let t of l)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[l]),f=(0,o.useMemo)(()=>l.filter(e=>"user"===e.role||"assistant"===e.role),[l]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,background:"var(--bg)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t||s("subagent.transcriptTitle")}),r&&(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--accent)",whiteSpace:"nowrap"},children:s("agentSwitcher.status.running")})]}),(0,n.jsxs)("div",{className:"scroll-overlay",style:{flex:1,minHeight:0,overflowY:"auto",padding:"10px 12px"},children:[u&&0===l.length&&(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontSize:12},children:s("subagent.transcriptLoading")}),h&&0===l.length&&(0,n.jsx)("div",{style:{color:"var(--status-error)",fontSize:12},children:s("subagent.transcriptFailed",{error:h})}),!u&&!h&&0===f.length&&(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontSize:12},children:s(r?"subagent.transcriptWaiting":"subagent.transcriptEmpty")}),f.map((t,r)=>(0,n.jsx)(lO,{message:t,toolResults:x,entryId:d[r],sessionId:e,onOpenFile:i},`subagent-msg-${r}`))]})]})}function cV({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i}){let{t:s}=(0,J.s)(),l=(0,o.useRef)(null),[a,d]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!t)return;let e=l.current;if(!e)return;let r=e.querySelector(`[data-tab-id="${CSS.escape(t)}"]`);r?.scrollIntoView({block:"nearest",inline:"nearest"})},[t,e.length]),(0,o.useEffect)(()=>{let e=l.current;if(!e)return;let t=()=>d(e.scrollWidth>e.clientWidth+1);t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[e.length]);let c=(0,o.useCallback)((t,n)=>{if(t.target!==t.currentTarget)return;if("Enter"===t.key||" "===t.key){t.preventDefault(),r(n.id);return}if(!["ArrowLeft","ArrowRight","Home","End"].includes(t.key))return;t.preventDefault();let o=e.findIndex(e=>e.id===n.id),i="Home"===t.key?0:"End"===t.key?e.length-1:(o+("ArrowRight"===t.key?1:-1)+e.length)%e.length;r(e[i].id);let s=l.current;s?.querySelector(`[data-tab-id="${CSS.escape(e[i].id)}"]`)?.focus()},[r,e]);return(0,n.jsx)("div",{ref:l,role:"tablist",className:`file-tab-bar${a?"":" no-overflow"}`,children:e.map(o=>{let l=o.id===t;return(0,n.jsxs)("div",{role:"tab","data-tab-id":o.id,"aria-label":"terminal"===o.kind?s("terminal.tabLabel",{name:o.label}):"subagent"===o.kind?s("subagent.transcriptTitle")+": "+o.label:o.label,"aria-selected":l,tabIndex:l||!t&&e[0].id===o.id?0:-1,className:"file-tab",onKeyDown:e=>c(e,o),onClick:()=>r(o.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:e=>{1===e.button&&(e.preventDefault(),e.stopPropagation(),o.closing||i(o.id))},children:[(0,n.jsx)("span",{className:"file-tab-icon",children:"subagent"===o.kind?(0,n.jsx)(U.d,{size:13,"aria-hidden":"true"}):"terminal"===o.kind?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}):ov(o.label,13)}),(0,n.jsx)("span",{className:"file-tab-label",title:o.filePath,children:o.label}),(0,n.jsx)("button",{type:"button",className:"file-tab-close",disabled:o.closing,onClick:e=>{e.stopPropagation(),i(o.id)},title:s("desktop.closeTab"),"aria-label":s("desktop.closeTabWithLabel",{label:o.label}),children:(0,n.jsx)(h.X,{size:11,"aria-hidden":"true"})})]},o.id)})})}let cJ="pi-web:file-tabs";function cY(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}let cG=new Set(["awaiting_input","review","failed"]),cX=(0,o.createContext)(null);function cZ(){let e=(0,o.useContext)(cX);if(!e)throw Error("useTasksView must be used within TasksViewProvider");return e}function cQ({children:e}){let{t}=(0,J.s)(),r=(0,o.useRef)(t);(0,o.useEffect)(()=>{r.current=t},[t]);let[i,s]=(0,o.useState)([]),[l,a]=(0,o.useState)([]),d=(0,o.useRef)(0),c=(0,o.useCallback)(async()=>{let e=++d.current;try{let t=await (0,di.Wt)(),r=(await Promise.all(t.map(e=>(0,di.Vk)(e).catch(()=>[])))).flat().sort((e,t)=>t.id-e.id);if(e!==d.current)return;a(e=>c0(e,t)?e:t),s(e=>c0(e,r)?e:r)}catch{}},[]);(0,o.useEffect)(()=>{c();let e=null,t=!1,r=()=>{t||((e=new EventSource("/api/tasks/events")).onmessage=()=>{c()},e.onerror=()=>{e?.close(),e=null,c(),setTimeout(r,2e3)})};r();let n=()=>{"visible"===document.visibilityState&&c()},o=()=>void c();document.addEventListener("visibilitychange",n),window.addEventListener("online",o);let i=setInterval(()=>void c(),6e4);return()=>{t=!0,e?.close(),document.removeEventListener("visibilitychange",n),window.removeEventListener("online",o),clearInterval(i)}},[c]);let u=(0,o.useMemo)(()=>i.filter(e=>cG.has(e.status)&&null==e.archivedAt).length,[i]),p=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=p.current;if((p.current=new Map(i.map(e=>[e.id,e.status])),e&&0!==i.length)&&"Notification"in window){for(let r of i)if(e.get(r.id)!==r.status&&("review"===r.status||"failed"===r.status)&&null==r.archivedAt&&"visible"!==document.visibilityState)try{let e="review"===r.status?t("tasks.notifyReview",{title:r.title}):t("tasks.notifyFailed",{title:r.title});!function(e,t){new Promise(r=>{if(!("Notification"in window))return void r();let n=()=>{try{new Notification(e,{body:t,tag:"pi-tasks"})}catch{}r()};"granted"===Notification.permission?n():"denied"!==Notification.permission?Notification.requestPermission().then(e=>{"granted"===e?n():r()}):r()})}("Pi Web Tasks",e)}catch{}}},[i,t]);let h=(0,o.useMemo)(()=>({tasks:i,projects:l,attentionCount:u,refetch:c}),[i,l,u,c]);return(0,n.jsx)(cX.Provider,{value:h,children:e})}function c0(e,t){return JSON.stringify(e)===JSON.stringify(t)}var c1=r(4539),c2=r(12449),c6=r(2571);let c4=["todo","inProgress","attention","done"];function c5(e){return"review"===e.status&&0===e.filesChanged}function c3(){return{defaultAgentType:null,modeId:null,configValues:{},autoProcess:!0,maxConcurrent:1,mergeStrategy:"merge",deleteWorktreeDefault:!0,preflightCommand:null,initCommand:null,stagePrompts:null}}let c8=["todo","inProgress","attention","done"],c7={todo:{id:"todo",marker:"var(--text-dim)"},inProgress:{id:"inProgress",marker:"var(--accent)"},attention:{id:"attention",marker:"var(--status-warning)"},done:{id:"done",marker:"var(--status-success)"}};var c9=r(54775),ue=r(98998),ut=r(36668);function ur({task:e}){let{t}=(0,J.s)(),r=t("failed"===e.status&&"interrupted"===e.failureReason?"tasks.statusInterrupted":function(e){switch(e){case"todo":return"tasks.statusTodo";case"queued":return"tasks.statusQueued";case"preparing":return"tasks.statusPreparing";case"running":return"tasks.statusRunning";case"awaiting_input":return"tasks.statusAwaitingInput";case"review":return"tasks.statusReview";case"merging":return"tasks.statusMerging";case"done":return"tasks.statusDone";case"failed":return"tasks.statusFailed";case"canceled":return"tasks.statusCanceled"}}(e.status)),o={display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:600,lineHeight:1.4,flexShrink:0,whiteSpace:"nowrap"};switch(e.status){case"queued":case"preparing":case"running":case"merging":return(0,n.jsxs)("span",{style:{...o,color:"var(--accent)"},children:[(0,n.jsx)(c9.N,{size:11,className:"pi-spin",style:{animation:"pi-spin 1s linear infinite"},"aria-hidden":"true"}),r]});case"awaiting_input":case"review":return(0,n.jsx)("span",{style:{...o,border:"1px solid rgba(245,158,11,0.45)",background:"rgba(245,158,11,0.08)",color:"var(--status-warning)"},children:r});case"done":return(0,n.jsxs)("span",{style:{...o,background:"rgba(16,185,129,0.12)",color:"#059669"},children:[(0,n.jsx)(x.J,{size:10,weight:"bold","aria-hidden":"true"}),r]});case"failed":return(0,n.jsx)("span",{style:{...o,background:"rgba(239,68,68,0.12)",color:"var(--status-error)"},children:r});default:return(0,n.jsx)("span",{style:{...o,background:"var(--bg-hover)",color:"var(--text-muted)"},children:r})}}function un({task:e}){let t=e.preflight;if(!t||"review"!==e.status)return null;let r="passed"===t.status?{background:"rgba(16,185,129,0.12)",color:"#059669"}:"failed"===t.status?{background:"rgba(239,68,68,0.12)",color:"var(--status-error)"}:{background:"var(--bg-hover)",color:"var(--text-muted)"};return(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,padding:"1px 6px",fontSize:10,fontWeight:500,lineHeight:1.5,maxWidth:"100%",...r},title:t.command,children:["running"===t.status?(0,n.jsx)(c9.N,{size:10,style:{animation:"pi-spin 1s linear infinite"},"aria-hidden":"true"}):"passed"===t.status?(0,n.jsx)(eo.r,{size:10,"aria-hidden":"true"}):(0,n.jsx)(r4.J,{size:10,"aria-hidden":"true"}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.command})]})}function uo({task:e,folderName:t,now:r,onOpen:o,onStart:i,onCancel:s,onRetry:l,onRequeue:a,onViewSession:d,onMerge:c,onArchive:u,onEdit:p}){let{t:h}=(0,J.s)(),g=null!=e.archivedAt,f="running"===e.status||"awaiting_input"===e.status||"merging"===e.status,m=null!=e.filesChanged&&e.filesChanged>0?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontFamily:"var(--font-mono)",fontSize:10},children:[(0,n.jsxs)("span",{style:{color:"#059669"},children:["+",e.additions??0]}),(0,n.jsxs)("span",{style:{color:"var(--status-error)"},children:["-",e.deletions??0]})]}):null,v=function(e,t){if(!e)return"";let r=new Date(e).getTime();if(Number.isNaN(r))return"";let n=Math.floor(Math.max(0,t-r)/6e4);if(n<1)return"now";if(n<60)return`${n}m`;let o=Math.floor(n/60);if(o<24)return`${o}h`;let i=Math.floor(o/24);return`${i}d`}(e.finishedAt??e.settledAt??e.startedAt??e.createdAt,r),{primary:y,more:b}=(()=>{let t=[],r=null;if(g)return{primary:r={icon:R.T,label:h("tasks.actionUnarchive"),onClick:u},more:t};switch(e.status){case"todo":r={icon:c6.j,label:h("tasks.actionStart"),onClick:i},t.push({icon:aD.S,label:h("tasks.actionEdit"),onClick:p});break;case"queued":case"preparing":case"running":case"awaiting_input":r={icon:ue.k,label:h("tasks.actionCancel"),onClick:s};break;case"review":r=c5(e)?{icon:x.J,label:h("tasks.actionComplete"),onClick:c}:{icon:ut.r,label:h("tasks.actionMerge"),onClick:c};break;case"merging":break;case"failed":r={icon:C.S,label:h("tasks.actionRetry"),onClick:l},t.push({icon:aD.S,label:h("tasks.actionEdit"),onClick:p}),t.push({icon:R.T,label:h("tasks.actionArchive"),onClick:u});break;case"done":r={icon:R.T,label:h("tasks.actionArchive"),onClick:u};break;case"canceled":r={icon:l3.f,label:h("tasks.actionRequeue"),onClick:a},t.push({icon:R.T,label:h("tasks.actionArchive"),onClick:u})}return{primary:r,more:t}})(),k=[...b];return null!=e.conversationId&&k.push({icon:l5.y,label:h("tasks.actionViewSession"),onClick:d}),(0,n.jsxs)("div",{role:"button",tabIndex:0,onClick:o,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),o())},style:{display:"flex",flexDirection:"column",cursor:"pointer",borderRadius:12,border:"1px solid color-mix(in srgb, var(--border) 85%, transparent)",background:"var(--bg-panel)",padding:12,textAlign:"left",transition:"border-color 0.12s",opacity:g?.6:1,boxShadow:"0 1px 2px rgba(0,0,0,0.04)"},className:"task-card-hover",onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="color-mix(in srgb, var(--border) 85%, transparent)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{minWidth:0,overflowWrap:"break-word",fontSize:13,fontWeight:500,lineHeight:1.4},children:e.title}),(0,n.jsx)(ur,{task:e})]}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"2px 6px",marginTop:6,fontSize:11,color:"var(--text-muted)"},children:[t?(0,n.jsx)("span",{style:{maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}):null,t&&e.workBranch?(0,n.jsx)("span",{style:{opacity:.5},children:"/"}):null,e.workBranch?(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:180},children:e.workBranch}):null,(t||e.workBranch)&&(m||v)?(0,n.jsx)("span",{style:{opacity:.5},children:"\xb7"}):null,m,m&&v?(0,n.jsx)("span",{style:{opacity:.5},children:"\xb7"}):null,v?(0,n.jsx)("span",{style:{flexShrink:0},children:v}):null,(0,n.jsx)(un,{task:e})]}),e.lastError&&("failed"===e.status||"review"===e.status)?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:8,borderRadius:8,background:"rgba(239,68,68,0.08)",padding:"6px 8px",fontSize:11,color:"var(--status-error)"},children:[(0,n.jsx)(lE.t,{size:13,style:{flexShrink:0},"aria-hidden":"true"}),(0,n.jsx)("span",{style:{minWidth:0,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.lastError}),(0,n.jsx)("button",{type:"button",style:{flexShrink:0,fontWeight:600,background:"none",border:"none",cursor:"pointer",color:"inherit",fontSize:11,textDecoration:"underline"},onClick:e=>{e.stopPropagation(),o()},children:h("tasks.errorView")})]}):null,"review"===e.status&&e.resultSummary?(0,n.jsx)("p",{style:{margin:"6px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:11,lineHeight:1.5,color:"var(--text-muted)"},children:e.resultSummary}):null,f&&e.latestProgress?(0,n.jsx)("p",{style:{margin:"6px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:11,lineHeight:1.5,color:"var(--text-muted)",fontStyle:"italic"},children:e.latestProgress}):null,y||k.length>0?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:12,paddingTop:12,borderTop:"1px solid var(--border)"},children:[y?(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),y.onClick()},style:{display:"inline-flex",alignItems:"center",gap:5,padding:"4px 10px",borderRadius:7,background:"var(--accent)",color:"var(--accent-fg)",border:"none",cursor:"pointer",fontSize:11,fontWeight:600},children:[(0,n.jsx)(y.icon,{size:12,weight:"bold","aria-hidden":"true"}),y.label]}):null,(0,n.jsx)("div",{style:{flex:1}}),k.map(e=>(0,n.jsx)("button",{type:"button",title:e.label,"aria-label":e.label,onClick:t=>{t.stopPropagation(),e.onClick()},style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,borderRadius:999,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",opacity:0,transition:"opacity 0.12s, background 0.12s, color 0.12s"},className:"task-card-secondary",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(e.icon,{size:13,"aria-hidden":"true"})},e.label))]}):null]})}function ui({open:e,onOpenChange:t,task:r}){let{t:i}=(0,J.s)(),{refetch:s}=cZ(),[l,a]=(0,o.useState)(""),[d,c]=(0,o.useState)(!1);if(W(!d,()=>t(!1)),(0,o.useEffect)(()=>{e&&(a(""),c(!1))},[e,r]),!e||!r)return null;let u=async()=>{if(!d){c(!0);try{await (0,di.oQ)(r.id,r.projectRoot,"cancel",{reason:l.trim()||null}),t(!1),s()}catch(e){console.error("cancel failed",e)}finally{c(!1)}}};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.cancelTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:i("tasks.cancelDescription")}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:i("tasks.cancelReasonLabel")}),(0,n.jsx)("textarea",{value:l,onChange:e=>a(e.target.value),placeholder:i("tasks.cancelReasonPlaceholder"),rows:3,autoFocus:!0,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:d,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("tasks.cancelKeep")}),(0,n.jsx)("button",{type:"button",onClick:()=>void u(),disabled:d,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("tasks.cancelSubmit")})]})]})]})})}function us({open:e,onOpenChange:t,task:r}){let{t:i}=(0,J.s)(),{refetch:s}=cZ(),[l,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(!1);W(!d,()=>t(!1));let u=r?.worktreePath!=null;if((0,o.useEffect)(()=>{if(!e||!r)return;c(!1);let t=!1;return(0,di.CG)(r.projectRoot).then(e=>{t||a(e.deleteWorktreeDefault)}).catch(()=>{t||a(!0)}),()=>{t=!0}},[e,r]),!e||!r)return null;let p=async()=>{if(!d){c(!0);try{await (0,di.ZX)(r.id,r.projectRoot,u&&l),t(!1),s()}catch(e){console.error("complete failed",e)}finally{c(!1)}}};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.completeTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:i("tasks.completeDescription")}),u?(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:l,onChange:e=>a(e.target.checked),style:{accentColor:"var(--accent)"}}),i("tasks.completeDeleteWorktree")]}):null,(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:d,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void p(),disabled:d,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("tasks.completeSubmit")})]})]})]})})}var ul=r(51285),ua=r(16894);function ud({open:e,onOpenChange:t,task:r,onViewSession:i,onMerge:s,onEdit:l,onCancel:a,onRetry:d,onRequeue:c,onComplete:u}){let{t:p}=(0,J.s)(),{refetch:g}=cZ(),[f,m]=(0,o.useState)([]),[v,y]=(0,o.useState)([]),[k,j]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[T,I]=(0,o.useState)(!1),[M,E]=(0,o.useState)(!1),[$,L]=(0,o.useState)(""),[N,A]=(0,o.useState)(!1),[F,P]=(0,o.useState)(!1),[D,H]=(0,o.useState)(!1);W(!0,()=>t(!1));let O=r?.id??null,B=r?.projectRoot??null,U=(0,o.useCallback)(async()=>{if(null==O||null==B)return;let[e,t]=await Promise.all([(0,di.HB)(B,O).catch(()=>[]),r?.worktreePath?(0,di.JH)(B,O).then(e=>e.files).catch(()=>[]):Promise.resolve([])]);m(e),y(t)},[O,B,r?.worktreePath]);(0,o.useEffect)(()=>{if(!e||null==O)return;m([]),y([]),E(!1),L(""),U();let t=window.setInterval(()=>void U(),5e3);return()=>window.clearInterval(t)},[e,O,U]);let _=(0,o.useCallback)(async e=>{H(!0);try{await e()}catch(e){console.error("detail action failed",e)}finally{H(!1),g()}},[g]),q=(0,o.useCallback)(async e=>{if(null!=B&&null!=O){I(!0);try{let t=await (0,di.h)(B,O,e);S(t.supported&&t.patch?t.patch:null)}catch{S(null)}finally{I(!1)}}},[B,O]),K=async()=>{null!=r&&null!=B&&(await _(()=>(0,di.bH)(r.id,B,F)),t(!1))},V=async()=>{null!=r&&null!=B&&$.trim()&&(await _(()=>(0,di.in)(r.id,B,$.trim())),E(!1),L(""))};if(!e||null==r||null==B)return null;let Y=[];if(null==r.archivedAt)switch(r.status){case"todo":Y.push({label:p("tasks.actionStart"),icon:c6.j,onClick:()=>void _(()=>(0,di.oQ)(r.id,B,"start")),filled:!0}),Y.push({label:p("tasks.actionEdit"),icon:aD.S,onClick:()=>l(r)});break;case"queued":case"preparing":case"running":case"awaiting_input":Y.push({label:p("tasks.actionCancel"),icon:ue.k,onClick:()=>a(r),danger:!0});break;case"review":Y.push({label:c5(r)?p("tasks.actionComplete"):p("tasks.actionMerge"),icon:c5(r)?x.J:ul.Y,onClick:()=>c5(r)?u(r):s(r),filled:!0}),Y.push({label:p("tasks.actionReturn"),icon:l3.f,onClick:()=>E(!0)});break;case"failed":Y.push({label:p("tasks.actionRetry"),icon:C.S,onClick:()=>d(r),filled:!0}),Y.push({label:p("tasks.actionEdit"),icon:aD.S,onClick:()=>l(r)});break;case"done":Y.push({label:p("tasks.actionArchive"),icon:R.T,onClick:()=>void _(()=>(0,di.et)(r.id,B,!0))});break;case"canceled":Y.push({label:p("tasks.actionRequeue"),icon:l3.f,onClick:()=>c(r),filled:!0})}else Y.push({label:p("tasks.actionUnarchive"),icon:R.T,onClick:()=>void _(()=>(0,di.et)(r.id,B,!1))});return null!=r.conversationId&&Y.push({label:p("tasks.actionViewSession"),icon:l5.y,onClick:()=>i(r)}),(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:800,background:"rgba(0,0,0,0.35)"},children:(0,n.jsxs)("div",{style:{position:"absolute",top:0,right:0,bottom:0,width:"min(480px, 90vw)",background:"var(--bg-panel)",borderLeft:"1px solid var(--border)",display:"flex",flexDirection:"column",boxShadow:"-8px 0 32px rgba(0,0,0,0.2)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,padding:"16px 16px 0"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("h3",{style:{margin:0,fontSize:15,fontWeight:600,lineHeight:1.4,overflowWrap:"break-word"},children:r.title}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:6},children:[(0,n.jsx)(ur,{task:r}),r.workBranch?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(b.Z,{size:12,"aria-hidden":"true"}),r.workBranch]}):null]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":p("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex",flexShrink:0},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:8,padding:"14px 16px 0"},children:Y.map(e=>{let t,r;return(0,n.jsxs)("button",{type:"button",onClick:e.onClick,disabled:D,style:(t=e.filled,r=e.danger,{display:"inline-flex",alignItems:"center",gap:5,padding:"7px 12px",borderRadius:8,fontSize:12,fontWeight:600,cursor:"pointer",background:t?"var(--accent)":r?"rgba(239,68,68,0.1)":"var(--bg-hover)",color:t?"#fff":r?"var(--status-error)":"var(--text)",border:t||r?"none":"1px solid var(--border)"}),children:[(0,n.jsx)(e.icon,{size:13,weight:"bold","aria-hidden":"true"}),e.label]},e.label)})}),M&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"12px 16px 0"},children:[(0,n.jsx)("textarea",{value:$,onChange:e=>L(e.target.value),placeholder:p("tasks.returnPlaceholder"),rows:3,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12,resize:"vertical",fontFamily:"inherit"}}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:()=>E(!1),style:{padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:p("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void V(),disabled:!$.trim(),style:{padding:"6px 14px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:p("tasks.returnSubmit")})]})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"14px 16px 0",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:p("tasks.metaProject")}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11},children:r.projectRoot})]}),r.createdAt?(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:p("tasks.metaCreated")}),(0,n.jsx)("span",{children:new Date(r.createdAt).toLocaleString()})]}):null,r.mergeCommit?(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:p("tasks.metaCommit")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11},children:r.mergeCommit})]}):null]}),v.length>0&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"14px 16px 0"},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:p("tasks.changedFiles")}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2,maxHeight:140,overflowY:"auto"},children:v.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;j(t=e.file),S(null),q(t)},style:{display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"4px 6px",borderRadius:6,background:"none",border:"none",color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,n.jsx)(ua.o,{size:13,style:{flexShrink:0,color:"var(--text-muted)"},"aria-hidden":"true"}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11},children:e.file}),(0,n.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"#059669",flexShrink:0},children:["+",e.additions]}),(0,n.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--status-error)",flexShrink:0},children:["-",e.deletions]})]},e.file))})]}),null!=k&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"12px 16px 0",minHeight:0,flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)"},children:p("tasks.diff")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:k}),(0,n.jsx)("button",{type:"button",onClick:()=>j(null),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,n.jsx)(h.X,{size:12,"aria-hidden":"true"})})]}),T?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",padding:8},children:p("tasks.loading")}):w?(0,n.jsx)("pre",{style:{margin:0,maxHeight:200,overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10,fontSize:11,lineHeight:1.5,fontFamily:"var(--font-mono)",color:"var(--text-muted)",whiteSpace:"pre"},children:w.split("\n").map((e,t)=>{let r;return e.startsWith("+")&&!e.startsWith("+++")?r="#059669":e.startsWith("-")&&!e.startsWith("---")?r="var(--status-error)":e.startsWith("@@")&&(r="var(--accent)"),(0,n.jsx)("div",{style:{color:r},children:e||" "},t)})}):(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",padding:8},children:p("tasks.noDiff")})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"14px 16px 0",flex:1,minHeight:0},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:p("tasks.timeline")}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",paddingBottom:8},children:0===f.length?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:8},children:p("tasks.noEvents")}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[...f].reverse().map(e=>{var t;let r,o;return(0,n.jsxs)("div",{style:{display:"flex",gap:8,padding:"4px 6px",borderRadius:6,fontSize:11},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0,fontFamily:"var(--font-mono)",fontSize:10,paddingTop:1},children:new Date(e.createdAt).toLocaleTimeString()}),(0,n.jsx)("span",{style:{color:"var(--text)",flexShrink:0,fontWeight:500},children:(t=e.kind,(o=p(r=`tasks.event_${t}`))===r?t:o)}),e.payload?.feedback?(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontStyle:"italic",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:String(e.payload.feedback)}):null]},e.id)})})})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:N?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:F,onChange:e=>P(e.target.checked),style:{accentColor:"var(--accent)"}}),p("tasks.deleteWorktree")]}),(0,n.jsx)("button",{type:"button",onClick:()=>A(!1),style:{padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:p("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void K(),disabled:D,style:{padding:"6px 14px",borderRadius:8,background:"var(--status-error)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:p("tasks.deleteConfirm")})]}):(0,n.jsxs)("button",{type:"button",onClick:()=>A(!0),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--status-error)",fontSize:12,cursor:"pointer"},children:[(0,n.jsx)(z.l,{size:13,"aria-hidden":"true"}),p("tasks.delete")]})})]})})}var uc=r(17757);function uu({open:e,onOpenChange:t,task:r,defaultProject:i,projects:s,prefillTitle:l,prefillPrompt:a,onSubmit:d}){let{t:c}=(0,J.s)(),[u,p]=(0,o.useState)(""),[g,x]=(0,o.useState)(""),[f,m]=(0,o.useState)(""),[v,y]=(0,o.useState)([]),[b,k]=(0,o.useState)(""),[j,w]=(0,o.useState)(!1);W(!j,()=>t(!1));let S=(0,o.useRef)(!1);if((0,o.useEffect)(()=>{if(!e){S.current=!1;return}S.current||(S.current=!0,p(r?.projectRoot??i??s[0]??""),x(r?.title??l??""),m(r?.config?.prompt??a??""),(0,di.VB)().then(y).catch(()=>void 0))},[e,r,i,s,l,a]),!e)return null;let C=async()=>{if(u&&g.trim()&&!j){w(!0);try{await d(u,g.trim(),{prompt:f.trim(),agentType:r?.config?.agentType??null,modelId:r?.config?.modelId??null,thinkingLevel:r?.config?.thinkingLevel??null}),t(!1)}catch(e){console.error("submit task failed",e)}finally{w(!1)}}},T=async()=>{if(b.trim()&&g.trim())try{await (0,di.nY)({name:b.trim(),title:g.trim(),config:{prompt:f.trim()}}),k(""),(0,di.VB)().then(y).catch(()=>void 0)}catch(e){console.error("save template failed",e)}},R=async e=>{try{await (0,di.B_)(e),(0,di.VB)().then(y).catch(()=>void 0)}catch(e){console.error("delete template failed",e)}},I={width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none"};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:900,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",maxHeight:"80vh",overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:r?c("tasks.editTitle"):c("tasks.newTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":c("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[v.length>0&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:c("tasks.templates")}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:v.map(e=>(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,background:"var(--bg-hover)",padding:"3px 8px",fontSize:11},children:[(0,n.jsx)("button",{type:"button",onClick:()=>{x(e.title),m(e.config?.prompt??"")},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text)",fontSize:11,padding:0},children:e.name}),(0,n.jsx)("button",{type:"button",onClick:()=>void R(e.id),"aria-label":c("tasks.deleteTemplate"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)",padding:0,display:"flex"},children:(0,n.jsx)(z.l,{size:10,"aria-hidden":"true"})})]},e.id))})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldProject")}),(0,n.jsx)("select",{value:u,onChange:e=>p(e.target.value),style:I,children:s.map(e=>(0,n.jsx)("option",{value:e,children:e.split("/").filter(Boolean).pop()??e},e))})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldTitle")}),(0,n.jsx)("input",{value:g,onChange:e=>x(e.target.value),placeholder:c("tasks.fieldTitlePlaceholder"),style:I,autoFocus:!0})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldPrompt")}),(0,n.jsx)("textarea",{value:f,onChange:e=>m(e.target.value),placeholder:c("tasks.fieldPromptPlaceholder"),rows:6,style:{...I,resize:"vertical",fontFamily:"inherit",lineHeight:1.5}})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("input",{value:b,onChange:e=>k(e.target.value),placeholder:c("tasks.templateNamePlaceholder"),style:{...I,flex:1}}),(0,n.jsxs)("button",{type:"button",onClick:()=>void T(),disabled:!b.trim()||!g.trim(),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"8px 12px",borderRadius:8,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,n.jsx)(uc.D,{size:13,"aria-hidden":"true"}),c("tasks.saveAsTemplate")]})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:c("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void C(),disabled:!u||!g.trim()||j,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:c("tasks.save")})]})]})]})})}function up({open:e,onOpenChange:t,task:r}){let{t:i}=(0,J.s)(),{refetch:s}=cZ(),[l,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(""),[u,p]=(0,o.useState)(!0),[g,x]=(0,o.useState)(!1);if(W(!g,()=>t(!1)),(0,o.useEffect)(()=>{e&&r&&(a(!0),c(r.title),x(!1),(0,di.CG)(r.projectRoot).then(e=>p(e.deleteWorktreeDefault)).catch(()=>p(!0)))},[e,r]),!e||!r)return null;let f=async()=>{if((l||d.trim())&&!g){x(!0);try{await (0,di.oB)(r.id,r.projectRoot,l?null:d.trim(),u),t(!1),s()}catch(e){console.error("merge failed",e)}finally{x(!1)}}};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.mergeTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"radio",checked:l,onChange:()=>a(!0),style:{accentColor:"var(--accent)"}}),i("tasks.mergeAutoMessage")]}),(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"radio",checked:!l,onChange:()=>a(!1),style:{accentColor:"var(--accent)"}}),i("tasks.mergeManualMessage")]}),!l&&(0,n.jsx)("input",{value:d,onChange:e=>c(e.target.value),placeholder:i("tasks.mergeMessagePlaceholder"),style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit"}}),(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:u,onChange:e=>p(e.target.checked),style:{accentColor:"var(--accent)"}}),i("tasks.mergeDeleteWorktree")]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void f(),disabled:!l&&!d.trim()||g,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("tasks.mergeConfirm")})]})]})]})})}function uh({open:e,onOpenChange:t,task:r,kind:i}){let{t:s}=(0,J.s)(),{refetch:l}=cZ(),[a,d]=(0,o.useState)(""),[c,u]=(0,o.useState)(!1);if(W(!c,()=>t(!1)),(0,o.useEffect)(()=>{e&&(d(""),u(!1))},[e,r]),!e||!r)return null;let p="retry"===i,g=async()=>{if(!c){u(!0);try{await (0,di.oQ)(r.id,r.projectRoot,i,{note:a.trim()||null}),t(!1),l()}catch(e){console.error("restart failed",e)}finally{u(!1)}}};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(480px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s(p?"tasks.restartTitleRetry":"tasks.restartTitleRequeue")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:s("tasks.restartDescription")}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:s("tasks.actionAddNote")}),(0,n.jsx)("textarea",{value:a,onChange:e=>d(e.target.value),placeholder:s(p?"tasks.followUpPlaceholderRetry":"tasks.followUpPlaceholderRequeue"),rows:3,autoFocus:!0,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:c,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void g(),disabled:c,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s(p?"tasks.actionRetry":"tasks.actionRequeue")})]})]})]})})}let ug=["work","retry","return","merge"];function ux({open:e,onOpenChange:t,projectRoot:r}){let{t:i}=(0,J.s)(),{projects:s}=cZ(),[l,a]=(0,o.useState)(""),[d,c]=(0,o.useState)(()=>c3()),[u,p]=(0,o.useState)(!1),[g,x]=(0,o.useState)(!1);if(W(!g,()=>t(!1)),(0,o.useEffect)(()=>{if(!e)return;let t=r??s[0]??"";a(t),t&&(0,di.Pf)(t).then(e=>{p(null!=e),c(e??c3())}).catch(()=>{p(!1),c(c3())})},[e,r,s]),!e)return null;let f=(e,t)=>{c(r=>({...r,[e]:t}))},m=async()=>{if(l&&!g){x(!0);try{await (0,di.eA)(l,d),p(!0),t(!1)}catch(e){console.error("save settings failed",e)}finally{x(!1)}}},v=async()=>{if(l)try{await (0,di.E)(l),p(!1),c(c3())}catch(e){console.error("reset settings failed",e)}},y={width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"7px 10px",color:"var(--text)",fontSize:12,outline:"none",fontFamily:"inherit"},b={display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 0",borderBottom:"1px solid var(--border)"};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:960,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, calc(100vw - 48px))",maxHeight:"82vh",overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.settingsTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"14px 16px 16px"},children:[(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500},children:i("tasks.settingsProject")}),(0,n.jsx)("select",{value:l,onChange:e=>a(e.target.value),style:y,children:s.map(e=>(0,n.jsx)("option",{value:e,children:e.split("/").filter(Boolean).pop()??e},e))})]}),l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:b,children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsAutoProcess")}),(0,n.jsx)("input",{type:"checkbox",checked:d.autoProcess,onChange:e=>f("autoProcess",e.target.checked),style:{accentColor:"var(--accent)"}})]}),(0,n.jsxs)("div",{style:b,children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsMaxConcurrent")}),(0,n.jsx)("input",{type:"number",min:0,value:d.maxConcurrent,onChange:e=>f("maxConcurrent",Math.max(0,Number(e.target.value)||0)),style:{...y,width:90}})]}),(0,n.jsxs)("div",{style:b,children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsMergeStrategy")}),(0,n.jsxs)("select",{value:d.mergeStrategy,onChange:e=>f("mergeStrategy",e.target.value),style:{...y,width:140},children:[(0,n.jsx)("option",{value:"merge",children:i("tasks.mergeStrategyMerge")}),(0,n.jsx)("option",{value:"squash",children:i("tasks.mergeStrategySquash")})]})]}),(0,n.jsxs)("div",{style:b,children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsDeleteWorktree")}),(0,n.jsx)("input",{type:"checkbox",checked:d.deleteWorktreeDefault,onChange:e=>f("deleteWorktreeDefault",e.target.checked),style:{accentColor:"var(--accent)"}})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsPreflightCommand")}),(0,n.jsx)("input",{value:d.preflightCommand??"",onChange:e=>f("preflightCommand",e.target.value||null),placeholder:i("tasks.settingsPreflightPlaceholder"),style:{...y,fontFamily:"var(--font-mono)",fontSize:11}})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsInitCommand")}),(0,n.jsx)("input",{value:d.initCommand??"",onChange:e=>f("initCommand",e.target.value||null),placeholder:i("tasks.settingsInitPlaceholder"),style:{...y,fontFamily:"var(--font-mono)",fontSize:11}})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,paddingTop:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500},children:i("tasks.settingsStagePrompts")}),ug.map(e=>(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:i(`tasks.stage.${e}`)}),(0,n.jsx)("input",{value:d.stagePrompts?.[e]??"",onChange:t=>f("stagePrompts",{...d.stagePrompts??{},[e]:t.target.value}),style:{...y,fontSize:11}})]},e))]}),u&&(0,n.jsx)("button",{type:"button",onClick:()=>void v(),style:{alignSelf:"flex-start",padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",fontSize:12,cursor:"pointer"},children:i("tasks.settingsReset")})]}):(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",padding:8},children:i("tasks.settingsNoProject")}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void m(),disabled:!l||g,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("tasks.save")})]})]})]})})}function uf({open:e,onOpenChange:t,task:r}){let{t:i}=(0,J.s)();return(W(e&&!!r,()=>t(!1)),(0,o.useEffect)(()=>{if(!e)return},[e,r]),e&&r)?(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:970,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.sessionTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"14px 16px 16px",fontSize:12},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:i("tasks.sessionId")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:r.conversationId??"—"})]}),r.sessionFile?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:i("tasks.sessionFile")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:r.sessionFile})]}):null,(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6},children:i("tasks.sessionHint")}),(0,n.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:4},children:(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("i18n.close")})})]})]})}):null}let um="__all__",uv="pi-tasks-board-filter",uy={showCanceled:!1,showArchived:!1},ub="pi:open-task-settings";function uk(){let{t:e}=(0,J.s)(),{attentionCount:t}=cZ();return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,height:36,flexShrink:0,padding:"0 16px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsxs)("h1",{style:{margin:0,display:"flex",alignItems:"center",gap:6,fontSize:13,fontWeight:600},children:[(0,n.jsx)(eV.x,{size:15,color:"var(--text-muted)","aria-hidden":"true"}),e("tasks.title"),(0,n.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 8px",fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em"},children:"Beta"})]}),t>0?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,background:"rgba(239,68,68,0.12)",color:"var(--status-error)",padding:"1px 8px",fontSize:10,fontWeight:700},children:[t," ",e("tasks.attentionBadge")]}):null,(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsxs)("button",{type:"button",onClick:()=>window.dispatchEvent(new Event(ub)),style:{display:"inline-flex",alignItems:"center",gap:5,height:26,padding:"0 10px",borderRadius:7,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:"pointer"},title:e("tasks.settingsTitle"),children:[(0,n.jsx)(c1.O,{size:13,"aria-hidden":"true"}),e("tasks.settingsTitle")]})]})}function uj({activeProject:e}){let{t}=(0,J.s)(),{tasks:i,projects:s,refetch:l}=cZ(),[a,d]=(0,o.useState)(null),[c,p]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(uv);if(e){let t=JSON.parse(e);return{showCanceled:t.showCanceled??!1,showArchived:t.showArchived??!1}}}catch{}return uy})()),[h,g]=(0,o.useState)(!1);(0,o.useEffect)(()=>{try{window.localStorage.setItem(uv,JSON.stringify(c))}catch{}},[c]);let[x,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(!1),b=(0,o.useRef)(null),k=(0,o.useRef)({x:0,y:0}),j=(0,o.useRef)(null),w=(0,o.useRef)(null),[S,C]=(0,o.useState)(null),z=(0,o.useRef)(null);z.current=S;let T=(0,o.useRef)(!1),R=(0,o.useRef)(!1),[I,M]=(0,o.useState)(()=>Date.now());(0,o.useEffect)(()=>{let e=window.setInterval(()=>M(Date.now()),6e4);return()=>window.clearInterval(e)},[]);let[E,$]=(0,o.useState)(!1),[W,L]=(0,o.useState)(null),[N,A]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=()=>{let e,t=(e=aa,aa=null,e);t&&(L(null),A(t),$(!0))};return e(),window.addEventListener(al,e),()=>window.removeEventListener(al,e)},[]);let[F,P]=(0,o.useState)(null),[D,H]=(0,o.useState)(null),[O,B]=(0,o.useState)(!1),[U,_]=(0,o.useState)(null),[q,K]=(0,o.useState)(!1),[V,Y]=(0,o.useState)(null),[G,X]=(0,o.useState)("retry"),[Z,Q]=(0,o.useState)(!1),[ee,et]=(0,o.useState)(null),[er,en]=(0,o.useState)(!1),[eo,ei]=(0,o.useState)(!1),[es,el]=(0,o.useState)(null),[ea,ed]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=()=>ei(!0);return window.addEventListener(ub,e),()=>window.removeEventListener(ub,e)},[]);let ec=(0,o.useMemo)(()=>null==a?i:i.filter(e=>e.projectRoot===a),[i,a]),eu=(0,o.useMemo)(()=>(function(e,t,r=!1){let n={todo:[],inProgress:[],attention:[],done:[]};for(let o of e)("canceled"!==o.status||t)&&(null==o.archivedAt||r)&&n[function(e){switch(e){case"todo":case"queued":return"todo";case"preparing":case"running":return"inProgress";case"awaiting_input":case"review":case"merging":case"failed":return"attention";case"done":case"canceled":return"done"}}(o.status)].push(o);for(let e of c4)n[e].sort((e,t)=>(t.updatedAt??"").localeCompare(e.updatedAt??""));return n})(ec,c.showCanceled,c.showArchived),[ec,c]),ep=(0,o.useMemo)(()=>{let e=eu.todo;if(null==S)return e;let t=new Map(e.map(e=>[e.id,e])),r=S.flatMap(e=>t.get(e)??[]);for(let t of e)S.includes(t.id)||r.push(t);return r},[eu.todo,S]),eh=(0,o.useMemo)(()=>i.find(e=>e.id===F)??null,[i,F]),eg=(0,o.useMemo)(()=>i.find(e=>e.id===es)??null,[i,es]),ex=(0,o.useCallback)(async e=>{try{await e()}catch(e){console.error("task action failed",e)}finally{l()}},[l]),ef=(0,o.useCallback)(e=>{null!=e.conversationId&&(el(e.id),ed(!0))},[el,ed]),em=(0,o.useCallback)(e=>{H(e),B(!0)},[H,B]),ev=(0,o.useCallback)(()=>{L(null),$(!0)},[L,$]),ey=(0,o.useCallback)((e,t)=>{let r=j.current,n=b.current;r&&n&&(r.style.transform=`translate3d(${e-n.dx}px, ${t-n.dy}px, 0)`)},[]),eb=e=>{let t=e.currentTarget.getBoundingClientRect();b.current={dx:e.clientX-t.left,dy:e.clientY-t.top,width:t.width}},ek=(0,o.useCallback)(e=>{if(f(null),v(!1),e){T.current=!1;return}requestAnimationFrame(()=>{T.current=!1})},[f,v]),ej=(0,o.useCallback)(()=>{R.current=!0,C(null),ek(!0)},[ek,C]);(0,o.useEffect)(()=>{if(!x)return;let e=()=>{document.hidden&&ej()};return window.addEventListener("blur",ej),document.addEventListener("visibilitychange",e),()=>{window.removeEventListener("blur",ej),document.removeEventListener("visibilitychange",e)}},[x,ej]),(0,o.useEffect)(()=>{x&&!ep.some(e=>e.id===x.task.id)&&ej()},[x,ep,ej]);let ew=(0,o.useCallback)((e,t,r)=>{if(R.current){ek(!0),C(null);return}let n=w.current?.getBoundingClientRect(),o=null!=n&&t>=n.left&&t<=n.right&&r>=n.top&&r<=n.bottom;if(ek(!1),o){C(null);let t=i.find(t=>t.id===e.id);t?.status==="todo"&&null!=a&&ex(()=>(0,di.oQ)(e.id,e.projectRoot,"start"));return}let s=z.current;null!=a&&null!=s&&(async()=>{try{await (0,di.Lu)(a,s)}catch(e){console.error("reorder failed",e)}await l(),C(null)})()},[ex,ek,a,l,i]),eS=(0,o.useCallback)(()=>{ex(async()=>{let e=await (0,di.a5)(a);e>0&&console.log(`started ${e} tasks`)})},[ex,a]),eC=(0,o.useCallback)(()=>{let e=eu.done.filter(e=>null==e.archivedAt);0!==e.length&&ex(()=>Promise.all(e.map(e=>(0,di.et)(e.id,e.projectRoot,!0))))},[ex,eu.done]),ez=+(c.showCanceled!==uy.showCanceled)+ +(c.showArchived!==uy.showArchived),eT=i.length>0,eR=(0,o.useMemo)(()=>{let t=new Set(s);return e&&t.add(e),[...t].sort()},[s,e]),eI=(0,o.useMemo)(()=>{let e=new Map;for(let t of eR)e.set(t,t.split("/").filter(Boolean).pop()??t);return e},[eR]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[eT&&(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:8,padding:"14px 16px 8px"},children:[(0,n.jsxs)("select",{value:a??um,onChange:e=>d(e.target.value===um?null:e.target.value),style:{height:30,borderRadius:999,padding:"0 10px",background:"var(--bg-panel)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,fontWeight:500,cursor:"pointer",maxWidth:"14rem"},"aria-label":t("tasks.allFolders"),children:[(0,n.jsx)("option",{value:um,children:t("tasks.allFolders")}),eR.map(e=>(0,n.jsx)("option",{value:e,children:eI.get(e)??e},e))]}),(0,n.jsxs)("div",{style:{position:"relative"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>g(e=>!e),style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,fontWeight:500,cursor:"pointer"},children:[(0,n.jsx)(c2.n,{size:13,"aria-hidden":"true"}),t("tasks.filter"),ez>0?(0,n.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 6px",fontSize:10,fontWeight:700},children:ez}):null]}),h&&(0,n.jsx)("div",{style:{position:"absolute",top:34,left:0,zIndex:50,width:200,borderRadius:12,padding:6,background:"var(--bg-panel)",border:"1px solid var(--border)",boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[["showCanceled",t("tasks.showCanceled")],["showArchived",t("tasks.showArchived")]].map(([e,t])=>(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:8,cursor:"pointer",fontSize:12},children:[(0,n.jsx)("input",{type:"checkbox",checked:c[e],onChange:t=>p(r=>({...r,[e]:t.target.checked})),style:{accentColor:"var(--accent)"}}),t]},e))})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsxs)("button",{type:"button",onClick:eS,style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 12px",background:"none",border:"none",color:"var(--text)",fontSize:12,cursor:"pointer"},title:t("tasks.startAll"),children:[(0,n.jsx)(c6.j,{size:13,"aria-hidden":"true"}),t("tasks.startAll")]}),(0,n.jsxs)("button",{type:"button",onClick:ev,style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 14px",background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,n.jsx)(y.F,{size:13,weight:"bold","aria-hidden":"true"}),t("tasks.new")]})]}),eT?(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowX:"auto"},children:(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:16,minWidth:"56rem",height:"100%",padding:"4px 16px 16px"},children:c8.map(e=>{let r="todo"===e?ep:eu[e],o=c7[e],i=e=>(0,n.jsx)(uo,{task:e,folderName:e.projectRoot?eI.get(e.projectRoot)??null:null,now:I,onOpen:()=>{T.current||P(e.id)},onStart:()=>void ex(()=>(0,di.oQ)(e.id,e.projectRoot,"start")),onCancel:()=>{_(e),K(!0)},onRetry:()=>{Y(e),X("retry"),Q(!0)},onRequeue:()=>{Y(e),X("requeue"),Q(!0)},onViewSession:()=>ef(e),onMerge:()=>{c5(e)?(et(e),en(!0)):em(e)},onArchive:()=>void ex(()=>(0,di.et)(e.id,e.projectRoot,null==e.archivedAt)),onEdit:()=>{L(e),$(!0)}},e.id);return(0,n.jsxs)("div",{ref:"inProgress"===e?w:void 0,style:{display:"flex",flexDirection:"column",minHeight:0,gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,height:24,flexShrink:0,padding:"0 2px"},children:[(0,n.jsx)("span",{style:{width:3,height:14,borderRadius:999,background:o.marker,flexShrink:0},"aria-hidden":"true"}),(0,n.jsx)("h2",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:t(`tasks.col${e[0].toUpperCase()}${e.slice(1)}`)}),(0,n.jsx)("span",{style:{borderRadius:999,background:"var(--bg-hover)",padding:"1px 8px",fontSize:10,fontWeight:600,color:"var(--text-muted)"},children:r.length}),(0,n.jsx)("div",{style:{flex:1}}),"done"===e&&eu.done.some(e=>null==e.archivedAt)?(0,n.jsx)("button",{type:"button",onClick:eC,style:{background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--text-muted)",padding:"2px 6px",borderRadius:6},children:t("tasks.archiveAllDone")}):null]}),0===r.length?(0,n.jsx)("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:4,borderRadius:12,border:"1px dashed var(--border)",padding:16,textAlign:"center",..."inProgress"===e&&x?m?{borderColor:"var(--accent)",background:"rgba(37,99,235,0.08)"}:{borderColor:"var(--accent)"}:{}},children:(0,n.jsx)("p",{style:{fontSize:12,color:"var(--text-muted)"},children:t(`tasks.emptyCol${e[0].toUpperCase()}${e.slice(1)}`)})}):(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",borderRadius:12,transition:"background 0.15s, box-shadow 0.15s",..."inProgress"===e&&x?m?{background:"rgba(37,99,235,0.06)",boxShadow:"inset 0 0 0 2px var(--accent)"}:{boxShadow:"inset 0 0 0 1px rgba(37,99,235,0.25)"}:{}},children:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:16,paddingBottom:4},children:r.map(t=>"todo"===e?(0,n.jsx)("div",{draggable:!0,onDragStart:e=>{var r,n;e.dataTransfer.effectAllowed="move",r=e.clientX,n=e.clientY,T.current=!0,R.current=!1,k.current={x:r,y:n},f({task:t,width:b.current?.width??280})},onDrag:e=>{var t,r;let n,o;return k.current={x:t=e.clientX,y:r=e.clientY},ey(t,r),void((o=null!=(n=w.current?.getBoundingClientRect())&&t>=n.left&&t<=n.right&&r>=n.top&&r<=n.bottom)!==m&&v(o))},onDragEnd:e=>ew(t,e.clientX,e.clientY),onPointerDown:eb,style:{cursor:"grab",opacity:x?.task.id===t.id?.4:1},children:i(t)},t.id):(0,n.jsx)("div",{children:i(t)},t.id))})})]},e)})})}):(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12,padding:32,textAlign:"center"},children:[(0,n.jsx)(eV.x,{size:40,color:"var(--text-dim)",opacity:.4,"aria-hidden":"true"}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("p",{style:{fontSize:14,fontWeight:500,color:"var(--text)"},children:t("tasks.empty")}),(0,n.jsx)("p",{style:{maxWidth:320,fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:t("tasks.emptyHint")})]}),(0,n.jsxs)("button",{type:"button",onClick:ev,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 14px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,n.jsx)(y.F,{size:13,weight:"bold","aria-hidden":"true"}),t("tasks.new")]})]}),(0,n.jsx)(uu,{open:E,onOpenChange:$,task:W,defaultProject:N?.projectRoot??a??e??null,projects:eR,prefillTitle:N?N.text.slice(0,80):void 0,prefillPrompt:N?N.text:void 0,onSubmit:async(e,t,n)=>{await ex(async()=>{let{createTaskApi:o}=await Promise.resolve().then(r.bind(r,23084)),{updateTaskApi:i}=await Promise.resolve().then(r.bind(r,23084));W?await i(W.id,e,{title:t,config:n}):await o({projectRoot:e,title:t,config:n})}),$(!1),A(null)}}),(0,n.jsx)(ud,{open:null!=F,onOpenChange:e=>{e||P(null)},task:eh,onViewSession:ef,onMerge:em,onEdit:e=>{L(e),$(!0)},onCancel:e=>{_(e),K(!0)},onRetry:e=>{Y(e),X("retry"),Q(!0)},onRequeue:e=>{Y(e),X("requeue"),Q(!0)},onComplete:e=>{et(e),en(!0)}}),(0,n.jsx)(up,{open:O,onOpenChange:B,task:D}),(0,n.jsx)(ui,{open:q,onOpenChange:K,task:U}),(0,n.jsx)(uh,{open:Z,onOpenChange:Q,task:V,kind:G}),(0,n.jsx)(us,{open:er,onOpenChange:en,task:ee}),(0,n.jsx)(uf,{open:ea&&null!=eg,onOpenChange:ed,task:eg}),(0,n.jsx)(ux,{open:eo,onOpenChange:ei,projectRoot:a}),x?(0,u.createPortal)((0,n.jsx)("div",{ref:j,style:{position:"fixed",left:0,top:0,zIndex:999,pointerEvents:"none",width:x.width,willChange:"transform"},"aria-hidden":"true",children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,borderRadius:12,border:m?"1px solid var(--accent)":"1px solid var(--border)",background:"var(--bg-panel)",padding:12,boxShadow:"0 8px 24px rgba(0,0,0,0.2)",transform:"rotate(-1deg)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{minWidth:0,overflowWrap:"break-word",fontSize:13,fontWeight:500},children:x.task.title}),(0,n.jsx)(ur,{task:x.task})]}),m?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:"var(--accent)"},children:[(0,n.jsx)(c6.j,{size:11,weight:"bold","aria-hidden":"true"}),t("tasks.dropToStart")]}):null]})}),document.body):null]})}var uw=r(62235),uS=r(1022);function uC(){return!!window.__TAURI_INTERNALS__}let uz=null;function uT(){return uz||(uz=r.e(8518).then(r.bind(r,38518)).then(e=>e.getCurrentWindow())),uz}async function uR(e){let t=await uT();await e(t)}async function uI(){await uR(e=>e.minimize())}async function uM(){await uR(e=>e.toggleMaximize())}async function uE(){await uR(e=>e.startDragging())}async function u$(){await uR(e=>e.close())}async function uW(){return(await uT()).isMaximized()}function uL(){let[e,t]=(0,o.useState)(null);return(0,o.useEffect)(()=>{uC()&&t(function(){if("u"<typeof navigator)return null;let e=navigator.platform||"";return/mac/i.test(e)?"macos":/win/i.test(e)?"windows":/linux/i.test(e)?"linux":null}())},[]),{platform:e,isDesktop:null!==e,isMacOS:"macos"===e,dragRegionProps:e?{"data-tauri-drag-region":!0}:{}}}let uN="pi-web-island-pos";function uA(e,t,r,n,o,i){return{x:Math.min(Math.max(0,e),Math.max(0,r-o)),y:Math.min(Math.max(0,t),Math.max(0,n-i))}}let uF={display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",borderRadius:7,transition:"background 0.12s, color 0.12s"};function uP({onRefreshSession:e}={}){let{t:t}=(0,J.s)(),{isDark:r}=eN(),{isDesktop:i,isMacOS:s}=uL(),l=i&&!s,[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),g=(0,o.useRef)(null),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{l&&uT().then(()=>void 0,e=>{throw uz=null,e}).catch(e=>{console.error("[DynamicIsland] window API preload failed:",e)})},[l]);let f=(0,o.useCallback)(e=>{e().catch(e=>{console.error("[DynamicIsland] window command failed:",e),u(String(e)),window.setTimeout(()=>u(null),4e3)})},[]),m=(0,o.useCallback)(()=>{window.location.reload()},[]);(0,o.useEffect)(()=>{if(!uC()||!l)return;let e=()=>{uW().then(d)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[l]),(0,o.useEffect)(()=>{if(l)try{let e=localStorage.getItem(uN);if(e){let t=JSON.parse(e);"number"==typeof t.x&&"number"==typeof t.y&&h(uA(t.x,t.y,window.innerWidth,window.innerHeight,168,34))}}catch{}},[l]),(0,o.useEffect)(()=>{if(l&&p)try{localStorage.setItem(uN,JSON.stringify(p))}catch{}},[p,l]);let[v,y]=(0,o.useState)(0);(0,o.useEffect)(()=>{if(!l)return;let e=()=>{y(window.innerWidth),h(e=>e?uA(e.x,e.y,window.innerWidth,window.innerHeight,168,34):e)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[l]);let b=(0,o.useCallback)(e=>{if(0!==e.button||e.target.closest?.("[data-island-btn]"))return;let t=g.current;if(!t)return;let r=t.getBoundingClientRect();x.current={startX:e.clientX,startY:e.clientY,origX:r.left,origY:r.top},e.currentTarget.setPointerCapture(e.pointerId)},[]),k=(0,o.useCallback)(e=>{let t=x.current;if(!t)return;let r=e.clientX-t.startX,n=e.clientY-t.startY;h(uA(t.origX+r,t.origY+n,window.innerWidth,window.innerHeight,168,34))},[]),j=(0,o.useCallback)(e=>{x.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},[]),w=(0,o.useCallback)(()=>uM().then(()=>{d(e=>!e)}),[]),S=(0,o.useCallback)(e=>{if(!x.current&&!e.target.closest?.("[data-island-btn]")){h(null);try{localStorage.removeItem(uN)}catch{}}},[]);if(!l)return null;let z=v||window.innerWidth,T=null!==p?p.x:Math.max(0,z-168-14);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:g,role:"toolbar","aria-label":t("desktop.islandLabel"),title:t("desktop.islandResetHint"),onPointerDown:b,onPointerMove:k,onPointerUp:j,onPointerCancel:j,onDoubleClick:S,onMouseDown:e=>e.stopPropagation(),onDoubleClickCapture:e=>e.stopPropagation(),style:{position:"fixed",top:null!==p?p.y:100,left:T,zIndex:700,display:"flex",alignItems:"center",gap:1,padding:"3px 5px",borderRadius:999,background:"color-mix(in srgb, var(--bg-panel) 88%, transparent)",border:"1px solid var(--border)",boxShadow:r?"0 6px 24px rgba(0,0,0,0.45)":"0 6px 20px rgba(0,0,0,0.12)",cursor:"grab",userSelect:"none",touchAction:"none"},children:[(0,n.jsx)("span",{"data-island-grip":!0,"aria-hidden":"true",title:t("desktop.islandDrag"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:12,height:26,flexShrink:0,marginRight:2,color:"var(--text-dim)",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"6",height:"14",viewBox:"0 0 6 14",fill:"currentColor","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"1.5",cy:"2",r:"1.2"}),(0,n.jsx)("circle",{cx:"4.5",cy:"2",r:"1.2"}),(0,n.jsx)("circle",{cx:"1.5",cy:"7",r:"1.2"}),(0,n.jsx)("circle",{cx:"4.5",cy:"7",r:"1.2"}),(0,n.jsx)("circle",{cx:"1.5",cy:"12",r:"1.2"}),(0,n.jsx)("circle",{cx:"4.5",cy:"12",r:"1.2"})]})}),e&&(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.refreshSession"),title:t("desktop.refreshSession"),onClick:()=>{try{e()}catch(e){console.error("[DynamicIsland] refresh session failed:",e)}},style:uF,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(uS.P,{size:13,"aria-hidden":"true"})}),(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.reloadPage"),title:t("desktop.reloadPage"),onClick:m,style:uF,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(C.S,{size:13,"aria-hidden":"true"})}),(0,n.jsx)("span",{"aria-hidden":"true",style:{width:1,height:18,flexShrink:0,background:"var(--border)",margin:"0 3px"}}),(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.minimize"),title:t("desktop.minimize"),onClick:()=>f(uI),style:uF,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})})}),(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t(a?"desktop.restore":"desktop.maximize"),title:t(a?"desktop.restore":"desktop.maximize"),onClick:()=>f(w),style:uF,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:a?(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,n.jsx)("rect",{x:"2",y:"0.5",width:"7.5",height:"7.5"}),(0,n.jsx)("path",{d:"M0.5 2.5 V9.5 H7.5"})]}):(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,n.jsx)("rect",{x:"0.5",y:"0.5",width:"9",height:"9"})})}),(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.close"),title:t("desktop.close"),onClick:()=>f(u$),style:uF,onMouseEnter:e=>{e.currentTarget.style.background="#e81123",e.currentTarget.style.color="#fff"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,n.jsx)("line",{x1:"0",y1:"0",x2:"10",y2:"10"}),(0,n.jsx)("line",{x1:"10",y1:"0",x2:"0",y2:"10"})]})})]}),c&&(0,n.jsx)("div",{role:"alert",style:{position:"fixed",top:(null!==p?p.y:100)+34+6,left:T,zIndex:700,maxWidth:280,padding:"5px 10px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--status-error, #f85149)",color:"var(--status-error, #f85149)",fontSize:11,lineHeight:1.5,wordBreak:"break-all",boxShadow:r?"0 6px 24px rgba(0,0,0,0.45)":"0 6px 20px rgba(0,0,0,0.12)",pointerEvents:"none"},children:c})]})}function uD(){try{return window.localStorage}catch{return null}}let uH="pi-web:desktop-server-hint-seen";function uO(e=uD()){if(e)try{e.setItem(uH,"1")}catch{}}function uB(){let{t:e}=(0,J.s)(),[t,r]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=!1;try{e=new URLSearchParams(window.location.search).has("piweb_connected")}catch{e=!1}e&&function(e=uD()){if(!e)return!1;try{return"1"!==e.getItem(uH)}catch{return!1}}()&&r(!0)},[]);let i=(0,o.useCallback)(()=>{uO(),r(!1)},[]),s=(0,o.useCallback)(()=>{uO(),r(!1),window.location.href="piweb-switch://manage"},[]);return t?(0,n.jsxs)("div",{role:"status",style:{position:"fixed",top:56,right:16,zIndex:700,width:288,padding:"14px 16px 14px",borderRadius:12,background:"var(--bg-panel)",border:"1px solid var(--border)",boxShadow:"0 12px 36px rgba(0,0,0,0.32)",color:"var(--text)"},children:[(0,n.jsx)("span",{"aria-hidden":"true",style:{position:"absolute",top:-6,right:28,width:10,height:10,background:"var(--bg-panel)",borderTop:"1px solid var(--border)",borderLeft:"1px solid var(--border)",transform:"rotate(45deg)"}}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10},children:[(0,n.jsx)(L.X,{size:18,color:"var(--accent)",style:{flexShrink:0,marginTop:1}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:13.5,fontWeight:600,lineHeight:1.45},children:e("desktop.serverHintTitle")}),(0,n.jsx)("p",{style:{margin:"6px 0 0",fontSize:12.5,lineHeight:1.65,color:"var(--text-muted)"},children:e("desktop.serverHintBody")})]}),(0,n.jsx)("button",{type:"button",onClick:i,"aria-label":e("desktop.serverHintDismiss"),title:e("desktop.serverHintDismiss"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,flexShrink:0,background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)"},children:(0,n.jsx)(h.X,{size:14,"aria-hidden":"true"})})]}),(0,n.jsx)("button",{type:"button",onClick:s,style:{marginTop:12,width:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:"8px 12px",borderRadius:9,background:"var(--accent)",border:"none",color:"var(--accent-fg)",fontSize:13,fontWeight:600,cursor:"pointer"},children:e("desktop.serverHintAction")})]}):null}function uU({isDark:e,toggleTheme:t,translate:r}){let[i,s]=(0,o.useState)(!1);(0,o.useEffect)(()=>{s(!0)},[]);let l=r(i?e?"desktop.switchToLight":"desktop.switchToDark":"desktop.switchToLight");return(0,n.jsx)("button",{className:"app-no-drag",suppressHydrationWarning:!0,onClick:e=>{let r=e.currentTarget.getBoundingClientRect();t({x:r.left+r.width/2,y:r.top+r.height/2})},title:l,"aria-label":l,"aria-pressed":!i||e,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:i?e?(0,n.jsx)(ed.b,{size:16,"aria-hidden":"true"}):(0,n.jsx)(ea.A,{size:16,"aria-hidden":"true"}):(0,n.jsx)(ed.b,{size:16,"aria-hidden":"true"})})}function u_({topBarRef:e,sidebarOpen:t,onSidebarToggle:r,isDark:i,toggleTheme:s,isMobile:l,showTasks:a,tasksBoardEnabled:d,onToggleTasks:c,systemPrompt:u,activeTopPanel:p,topPanelPos:h,sessionStats:g,selectedSession:f,contextUsage:m,copiedSessionField:v,onCopySessionField:y,rightPanelOpen:b,onToggleFilePanel:k,onRefreshSession:w,onOpenSettings:S,sessionTitle:z,onWorkspaceControlsHostChange:T,onTitleRightHostChange:R,desktopChrome:I,windowDrag:M}){let E,$,N,A,F,P,D,H,O,B,U,{t:_}=(0,J.s)(),[q,K]=(0,o.useState)(!1);W(q,()=>K(!1));let[V,Y]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{try{Y(new URLSearchParams(window.location.search).has("piweb_connected"))}catch{Y(!1)}},[]),(0,n.jsxs)(n.Fragment,{children:[V&&(0,n.jsx)(uB,{}),(0,n.jsxs)("div",{ref:e,className:"app-title-bar",...I?.dragRegionProps,...M,style:{display:"flex",alignItems:"center",flexShrink:0,borderBottom:"1px solid var(--border)",height:48,background:"var(--bg-panel)",position:"relative",zIndex:600,paddingLeft:76*!!I?.isMacOS},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",minWidth:0,height:"100%",flex:"0 1 auto",position:"relative",zIndex:1},children:[(0,n.jsx)("button",{className:"app-no-drag",onClick:r,title:t?_("desktop.hideSidebar"):_("desktop.showSidebar"),"aria-label":t?_("desktop.hideSidebar"):_("desktop.showSidebar"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:t?(0,n.jsx)(uw.V,{size:16,"aria-hidden":"true"}):(0,n.jsx)(j.B,{size:16,"aria-hidden":"true"})}),(0,n.jsx)("div",{className:"app-no-drag",ref:T,style:{flex:"0 1 auto",minWidth:0,maxWidth:"min(60vw, 820px)",height:"100%",display:"flex",alignItems:"center",padding:"0 8px 0 0",overflow:"visible"}})]}),(0,n.jsxs)("div",{className:"app-title-drag",style:{...l?{position:"relative",flex:"1 1 auto",minWidth:0}:{position:"absolute",left:"var(--pi-titlebar-sidebar-offset, 0px)",right:0,top:0,bottom:0},display:"flex",alignItems:"center",justifyContent:l?"flex-start":"center",padding:l?"0 8px 0 4px":"0 12px",overflow:"hidden",userSelect:"none"},children:[z&&(0,n.jsx)("button",{type:"button",className:"app-no-drag",onClick:()=>{l&&K(!0)},style:{display:"block",flex:"0 1 auto",minWidth:0,maxWidth:l?"100%":"calc(100% - 320px)",fontSize:12,fontWeight:500,color:"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",background:"none",border:"none",cursor:"pointer",padding:"2px 6px",borderRadius:5},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:z}),(0,n.jsx)("div",{className:"app-no-drag",ref:R,style:{flexShrink:0,display:"flex",alignItems:"center",marginLeft:4}})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:3,minWidth:0,height:"100%",flexShrink:+!l,overflow:"hidden",marginLeft:"auto",position:"relative",zIndex:1},children:[!l&&d&&(0,n.jsx)("button",{className:"app-no-drag",onClick:c,title:a?_("desktop.hideTaskBoard"):_("desktop.showTaskBoard"),"aria-label":a?_("desktop.hideTaskBoard"):_("desktop.showTaskBoard"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:a?"var(--bg-selected)":"none",border:"none",color:a?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=a?"var(--bg-selected)":"none",e.currentTarget.style.color=a?"var(--text)":"var(--text-muted)"},children:(0,n.jsx)(eV.x,{size:16,"aria-hidden":"true"})}),(0,n.jsx)("button",{className:"app-no-drag",onClick:k,title:b?_("desktop.hideFilePanel"):_("desktop.showFilePanel"),"aria-label":b?_("desktop.hideFilePanel"):_("desktop.showFilePanel"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=b?"var(--bg-selected)":"none",e.currentTarget.style.color=b?"var(--text)":"var(--text-muted)"},children:(0,n.jsx)(uw.V,{size:16,"aria-hidden":"true",style:{transform:"scaleX(-1)"}})}),(0,n.jsx)(uU,{isDark:i,toggleTheme:s,translate:_}),V&&(0,n.jsx)("button",{className:"app-no-drag",type:"button",onClick:()=>{window.location.href="piweb-switch://manage"},title:_("desktop.serverSwitch"),"aria-label":_("desktop.serverSwitch"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(L.X,{size:16,"aria-hidden":"true"})}),!V&&!l&&(0,n.jsx)("button",{className:"app-no-drag",type:"button",onClick:w,title:_("desktop.refreshSession"),"aria-label":_("desktop.refreshSession"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(C.S,{size:16,"aria-hidden":"true"})}),(0,n.jsx)("button",{className:"app-no-drag",type:"button",onClick:S,title:_("desktop.settings"),"aria-label":_("desktop.settings"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(c1.O,{size:16,"aria-hidden":"true"})})]})]}),(0,n.jsx)(uP,{onRefreshSession:w}),p&&h&&(0,n.jsxs)("div",{style:{position:"fixed",top:h.top,left:h.left,width:h.width,maxHeight:`calc(100dvh - ${h.top}px)`,overflowY:"auto",zIndex:500},children:["system"===p&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:u?(0,n.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:u}):""===u?(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})}),"session"===p&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",padding:"12px 16px"},children:g?(E=[...g.sessionName?[{label:_("desktop.name"),value:g.sessionName,copyField:null}]:[],{label:_("desktop.sessionInfoFile"),value:g.sessionFile??_("desktop.sessionInfoInMemory"),copyField:"file"},{label:_("desktop.sessionInfoId"),value:g.sessionId,copyField:"id"}],$=[[_("desktop.sessionInfoUser"),g.userMessages.toLocaleString()],[_("desktop.sessionInfoAssistant"),g.assistantMessages.toLocaleString()],[_("desktop.sessionInfoToolCalls"),g.toolCalls.toLocaleString()],[_("desktop.sessionInfoToolResults"),g.toolResults.toLocaleString()],[_("desktop.sessionInfoTotal"),g.totalMessages.toLocaleString()]],N=[[_("desktop.sessionInfoInput"),g.tokens.input.toLocaleString()],[_("desktop.sessionInfoOutput"),g.tokens.output.toLocaleString()],...g.tokens.cacheRead>0?[[_("desktop.sessionInfoCacheRead"),g.tokens.cacheRead.toLocaleString()]]:[],...g.tokens.cacheWrite>0?[[_("desktop.sessionInfoCacheWrite"),g.tokens.cacheWrite.toLocaleString()]]:[],[_("desktop.sessionInfoTotal"),g.tokens.total.toLocaleString()]],A=m??g.contextUsage,P=[...g.cost>0?[[_("desktop.sessionInfoCost"),`$${g.cost.toFixed(4)}`]]:[],...A?.contextWindow?[[_("desktop.sessionInfoContext"),`${null!==A.percent?`${A.percent.toFixed(1)}%`:"?"} / ${(F=A.contextWindow)>=1e6?`${(F/1e6).toFixed(1)}M`:F>=1e3?`${(F/1e3).toFixed(0)}k`:String(F)}`]]:[]],D=(e,t,r="left",o=!1)=>(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:e}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:o?"max-content max-content":"auto minmax(0, 1fr)",columnGap:o?14:12,rowGap:4,justifyContent:o?"start":void 0},children:t.map(([t,i])=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:t}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:o?"normal":"anywhere",textAlign:r,whiteSpace:"right"===r?"nowrap":"normal"},children:i})]},`${e}:${t}`))})]}),H=(e,t)=>{let r=v===e;return(0,n.jsx)("button",{type:"button",title:r?_("desktop.copied"):_({file:"desktop.copyFilePath",id:"desktop.copySessionId",projectDir:"desktop.copyProjectDir",gitBranch:"desktop.copyGitBranch",gitWorktree:"desktop.copyGitWorktree"}[e]),onClick:()=>y(e,t),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:r?"var(--accent)":"var(--text-dim)",background:"transparent",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",flex:"0 0 auto",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=r?"var(--accent)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:r?(0,n.jsx)(x.J,{size:12,"aria-hidden":"true"}):(0,n.jsx)(sa.Q,{size:12,"aria-hidden":"true"})})},O=(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:_("desktop.sessionInfoTitle")}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:E.map(e=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,n.jsx)("div",{children:e.copyField?H(e.copyField,e.value):null})]},`session-info:${e.label}`))})]}),U=(B=[...f?[{label:_("desktop.projectDir"),value:f.projectRoot??f.cwd,copyField:"projectDir"}]:[],...f?.branch?[{label:_("desktop.gitBranch"),value:f.branch,copyField:"gitBranch"}]:[],...f?.isWorktree?[{label:_("desktop.gitWorktree"),value:f.cwd,copyField:"gitWorktree"}]:[]]).length>0?(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:_("desktop.projectSection")}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:B.map(e=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,n.jsx)("div",{children:e.copyField?H(e.copyField,e.value):null})]},`project-info:${e.label}`))})]}):null,(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:l?"1fr":"minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)",gap:l?16:24,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:l?16:20,minWidth:0},children:[O,U]}),D(_("desktop.sessionInfoMessages"),$),D(_("desktop.sessionInfoTokens"),[...N,...P],"right",!0)]})):(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:_("desktop.sendMessageForSessionInfo")})})]}),q&&z&&(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:3e3,display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:48,background:"rgba(0,0,0,0.35)"},children:(0,n.jsx)("div",{role:"dialog","aria-label":z,style:{maxWidth:"min(560px, calc(100vw - 32px))",maxHeight:"min(60vh, 400px)",overflow:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 16px 40px rgba(0,0,0,0.3)",padding:"14px 18px",fontSize:13,lineHeight:1.6,color:"var(--text)",wordBreak:"break-word",whiteSpace:"pre-wrap"},children:z})})]})}function uq({cwd:e,busy:t,error:r,onCancelAction:o,onConfirmAction:i}){let{t:s}=(0,J.s)();return W(!t,o),(0,n.jsx)("div",{role:"presentation",style:{position:"fixed",inset:0,zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center",padding:16,background:"rgba(0, 0, 0, 0.4)"},children:(0,n.jsxs)("section",{role:"dialog","aria-modal":"true","aria-labelledby":"project-trust-title",style:{width:440,maxWidth:"100%",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",boxShadow:"0 12px 36px rgba(0, 0, 0, 0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:12,padding:"18px 18px 14px"},children:[(0,n.jsx)(ai.o,{size:21,weight:"duotone",color:"var(--accent-orange)",style:{flexShrink:0,marginTop:1},"aria-hidden":"true"}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("h2",{id:"project-trust-title",style:{margin:0,fontSize:15,fontWeight:700,color:"var(--text)"},children:s("desktop.trustProjectTitle")}),(0,n.jsx)("p",{style:{margin:"7px 0 0",fontSize:12,lineHeight:1.6,color:"var(--text-muted)"},children:s("desktop.trustProjectBody")}),(0,n.jsx)("code",{style:{display:"block",marginTop:10,padding:"8px 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:e}),r&&(0,n.jsx)("div",{role:"alert",style:{marginTop:10,color:"var(--accent-red)",fontSize:12,lineHeight:1.5},children:r})]})]}),(0,n.jsxs)("footer",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,n.jsx)("button",{type:"button",onClick:o,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:t?"not-allowed":"pointer",fontSize:12},children:s("desktop.cancel")}),(0,n.jsx)("button",{type:"button",onClick:i,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--accent)",borderRadius:5,background:"var(--accent)",color:"white",cursor:t?"wait":"pointer",opacity:t?.7:1,fontSize:12,fontWeight:600},children:s(t?"desktop.trustingProject":"desktop.trustProject")})]})]})})}function uK(e,t,r){let n=Number.isFinite(e)?e:t,o=Math.max(t,r);return Math.round(Math.max(t,Math.min(o,n)))}function uV(e){return uK(.42*e,360,640)}function uJ(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function uY(e){let{ariaLabel:t,cssVariable:r,defaultWidth:n,getDefaultWidth:i,getMaxWidth:s,growthDirection:l,maxWidth:a,minWidth:d,storageKey:c,widthRef:u}=e,p=(0,o.useRef)(null),h=(0,o.useRef)(null),g=(0,o.useRef)(!1),[x,f]=(0,o.useState)(n),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1);(0,o.useEffect)(()=>{b(!0)},[]);let k=(0,o.useCallback)(()=>Math.min(a,Math.max(d,s())),[s,a,d]),j=(0,o.useCallback)(e=>uK(e,d,k()),[k,d]),w=(0,o.useCallback)(e=>{u.current=e;let t=`${e}px`;p.current?.style.setProperty(r,t),p.current?.parentElement?.style.setProperty(r,t)},[r,u]),S=(0,o.useCallback)((e,t={})=>{let{forcePersist:r=!1,persist:n=!0}=t,o=j(e),i=o!==u.current;return w(o),f(o),n&&(i||r)&&uJ(c,o),o},[w,j,c,u]),C=(0,o.useCallback)(e=>{document.body.style.cursor=e.previousCursor,document.body.style.userSelect=e.previousUserSelect},[]),z=(0,o.useCallback)(e=>{let t=h.current;if(t&&t.pointerId===e){h.current=null,C(t),v(!1),S(u.current,{forcePersist:!0});try{t.target.hasPointerCapture(e)&&t.target.releasePointerCapture(e)}catch{}}},[S,C,u]),T=(0,o.useCallback)(e=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),e.stopPropagation();let t=h.current;t&&z(t.pointerId);let r=e.currentTarget;r.focus({preventScroll:!0}),r.setPointerCapture(e.pointerId),h.current={pointerId:e.pointerId,startX:e.clientX,startWidth:u.current,target:r,previousCursor:document.body.style.cursor,previousUserSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none",v(!0)},[z,u]),R=(0,o.useCallback)(e=>{let t=h.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void z(e.pointerId);e.preventDefault();let r="right"===l?1:-1,n=j(t.startWidth+(e.clientX-t.startX)*r);w(n),e.currentTarget.setAttribute("aria-valuenow",String(n)),e.currentTarget.setAttribute("aria-valuetext",`${n} px`)},[w,j,z,l]),I=(0,o.useCallback)(e=>{z(e.pointerId)},[z]),M=(0,o.useCallback)(e=>{z(e.pointerId)},[z]),E=(0,o.useCallback)(e=>{z(e.pointerId)},[z]),$=(0,o.useCallback)(()=>{S(i?.()??n,{forcePersist:!0})},[S,n,i]),W=(0,o.useCallback)(()=>{S(u.current)},[S,u]),L=(0,o.useCallback)(e=>{let t=e.shiftKey?32:12,r="right"===l?"ArrowRight":"ArrowLeft",n="right"===l?"ArrowLeft":"ArrowRight";e.key===r?(e.preventDefault(),S(u.current+t,{forcePersist:!0})):e.key===n?(e.preventDefault(),S(u.current-t,{forcePersist:!0})):"Home"===e.key?(e.preventDefault(),S(d,{forcePersist:!0})):"End"===e.key?(e.preventDefault(),S(k(),{forcePersist:!0})):"Enter"===e.key&&(e.preventDefault(),$())},[S,k,l,d,$,u]);return(0,o.useEffect)(()=>{if(g.current)return;g.current=!0;let e=function(e){try{let t=window.localStorage.getItem(e);if(null===t)return null;let r=Number.parseInt(t,10);return Number.isFinite(r)?r:null}catch{return null}}(c),t=S(e??i?.()??n,{persist:!1});null!==e&&e!==t&&uJ(c,t)},[S,n,i,c]),(0,o.useEffect)(()=>{if(!g.current)return;S(u.current);let e=()=>{S(u.current)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[S,u]),(0,o.useEffect)(()=>{if(!m)return;let e=()=>{let e=h.current;e&&z(e.pointerId)},t=()=>{"visible"!==document.visibilityState&&e()};return window.addEventListener("blur",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("blur",e),document.removeEventListener("visibilitychange",t)}},[z,m]),(0,o.useEffect)(()=>()=>{let e=h.current;e&&(h.current=null,C(e))},[C]),{isResizing:m,panelRef:p,reclampWidth:W,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":y?k():a,"aria-valuemin":d,"aria-valuenow":x,"aria-valuetext":`${x} px`,onDoubleClick:$,onKeyDown:L,onLostPointerCapture:E,onPointerCancel:M,onPointerDown:T,onPointerMove:R,onPointerUp:I,role:"separator",tabIndex:0},width:x}}function uG({status:e}){return"running"===e||"starting"===e?(0,n.jsxs)("svg",{className:"animate-spin",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,n.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):"queued"===e?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M12 7v5l3 2"})]}):"failed"===e?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"m9 9 6 6M15 9l-6 6"})]}):"aborted"===e||"interrupted"===e?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M9 9h6v6H9z"})]}):(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"m8 12 3 3 5-6"})]})}function uX({session:e,main:t,selected:r,running:o,onSelect:i}){let{locale:s,t:l}=(0,J.s)(),a=e.relation?.kind==="subagent"?e.relation:null,d=o?"running":a?.status??"completed",c=t?l("agentSwitcher.main"):a?.description||n6(e),u=t?n6(e):`${a?.profile??l("agentSwitcher.subagent")} \xb7 ${function(e,t){let r=new Date(e).getTime();if(!Number.isFinite(r))return"";let n=Math.round((r-Date.now())/1e3),o=new Intl.RelativeTimeFormat(t,{numeric:"auto"});if(60>Math.abs(n))return o.format(n,"second");let i=Math.round(n/60);if(60>Math.abs(i))return o.format(i,"minute");let s=Math.round(i/60);return 24>Math.abs(s)?o.format(s,"hour"):o.format(Math.round(s/24),"day")}(e.modified,s)}`;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":r,onClick:i,style:{width:"100%",minHeight:56,display:"grid",gridTemplateColumns:"28px minmax(0, 1fr) auto",alignItems:"center",gap:9,padding:"7px 12px",border:"none",borderBottom:"1px solid var(--border)",borderLeft:r?"2px solid var(--accent)":"2px solid transparent",background:r?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{style:{width:28,height:28,display:"grid",placeItems:"center",color:t?"var(--text-muted)":"var(--accent)"},children:t?(0,n.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"8",r:"4"}),(0,n.jsx)("path",{d:"M4 21a8 8 0 0 1 16 0"})]}):(0,n.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"5",y:"7",width:"14",height:"11",rx:"2"}),(0,n.jsx)("path",{d:"M9 11h.01M15 11h.01M9 15h6M12 7V4M10 4h4"})]})}),(0,n.jsxs)("span",{style:{minWidth:0},children:[(0,n.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:r?600:500},title:c,children:c}),(0,n.jsx)("span",{style:{display:"block",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:11},title:u,children:u})]}),(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",gap:6,color:t&&!o?"var(--text-dim)":"running"===d||"starting"===d?"var(--accent)":"queued"===d?"var(--text-dim)":"completed"===d?"var(--status-success)":"failed"===d?"var(--status-error)":"aborted"===d?"var(--status-warning)":"var(--text-dim)",fontSize:11,whiteSpace:"nowrap"},children:t&&!o?r?l("agentSwitcher.current"):null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(uG,{status:d}),(0,n.jsx)("span",{children:l(`agentSwitcher.status.${d}`)})]})})]})}function uZ({rootSession:e,subagents:t,selectedSessionId:r,runningSessionIds:i,onSelectSession:s}){let{t:l}=(0,J.s)(),[a,d]=(0,o.useState)(""),c=(0,o.useMemo)(()=>[...t].sort((e,t)=>{let r=i.has(e.id);return r!==i.has(t.id)?r?-1:1:t.modified.localeCompare(e.modified)}),[i,t]),u=a.trim().toLowerCase(),p=u?c.filter(e=>{let t=e.relation?.kind==="subagent"?e.relation:null;return[t?.description,t?.profile,e.name,e.firstMessage].some(e=>e?.toLowerCase().includes(u))}):c,h=t.filter(e=>i.has(e.id)).length;return(0,n.jsx)("div",{role:"listbox","aria-label":l("agentSwitcher.title"),style:{background:"var(--bg-panel)",borderLeft:"1px solid var(--border)",borderRight:"1px solid var(--border)",borderBottom:"1px solid var(--border)",borderRadius:"0 0 6px 6px",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",overflow:"hidden"},children:(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{minHeight:44,display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("strong",{style:{fontSize:12,fontWeight:600},children:l("agentSwitcher.title")}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:l("agentSwitcher.count",{count:t.length})}),h>0&&(0,n.jsx)("span",{style:{marginLeft:"auto",color:"var(--accent)",fontSize:11},children:l("agentSwitcher.runningCount",{count:h})})]}),t.length>8&&(0,n.jsx)("div",{style:{padding:8,borderBottom:"1px solid var(--border)"},children:(0,n.jsx)("input",{type:"search",value:a,onChange:e=>d(e.target.value),placeholder:l("agentSwitcher.search"),"aria-label":l("agentSwitcher.search"),style:{width:"100%",height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none"}})}),(0,n.jsxs)("div",{style:{maxHeight:"min(58dvh, 480px)",overflowY:"auto"},children:[(0,n.jsx)(uX,{session:e,main:!0,selected:e.id===r,running:i.has(e.id),onSelect:()=>s(e)}),p.map(e=>(0,n.jsx)(uX,{session:e,selected:e.id===r,running:i.has(e.id),onSelect:()=>s(e)},e.id)),0===p.length&&(0,n.jsx)("div",{style:{padding:"22px 12px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:l("agentSwitcher.noMatches")})]})]})})}function uQ(){var e;let t,r,a=(0,s.useRouter)(),d=(0,s.useSearchParams)(),c=(0,o.useMemo)(()=>{let e;return{requestedCwd:e=d.get("cwd")?.trim()||null,sessionId:e?null:d.get("session"),sidebarCollapsed:"collapsed"===d.get("sidebar")}},[d]),{isDark:u,toggleTheme:p}=eN(),{t:h}=(0,J.s)(),g=tu(),[x,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(null),[y,b]=(0,o.useState)(0),[k,j]=(0,o.useState)(0),[w,S]=(0,o.useState)(0),[C,z]=(0,o.useState)(!1),[T,R]=(0,o.useState)("models"),[I,M]=(0,o.useState)(0),[E,$]=(0,o.useState)(null),[W,L]=(0,o.useState)(!1),[N,A]=(0,o.useState)(!1),[F,P]=(0,o.useState)(null),[D,H]=(0,o.useState)(()=>!c.sidebarCollapsed),[O,B]=(0,o.useState)(!1);(0,o.useEffect)(()=>{g&&H(!1)},[g]),(0,o.useEffect)(()=>{B(!0)},[]);let U=(0,o.useRef)(null),_=(0,o.useRef)(null),[q,K]=(0,o.useState)(null),[V,Y]=(0,o.useState)(null),[G,X]=(0,o.useState)(null),Z=uL(),Q=function(){let{isDesktop:e,isMacOS:t}=uL(),r=(0,o.useCallback)(e=>{var t;0===e.button&&(t=e.target).closest("[data-tauri-drag-region]")&&!t.closest('button, a, input, textarea, select, [role="button"], [contenteditable="true"], [data-no-drag]')&&(e.preventDefault(),e.stopPropagation(),2===e.detail?uM():uE())},[]);return e&&!t?{onMouseDown:r}:{}}(),[ee,et]=(0,o.useState)(null),er=(0,o.useCallback)(e=>{et(e)},[]),[en,eo]=(0,o.useState)(null),ei=(0,o.useCallback)(e=>{eo(e)},[]),[es,el]=(0,o.useState)(null),ea=(0,o.useRef)(null),ed=(0,o.useCallback)((e,t)=>{ni(t).then(()=>{ea.current&&clearTimeout(ea.current),el(e),ea.current=setTimeout(()=>el(null),1400)})},[]);(0,o.useEffect)(()=>()=>{ea.current&&clearTimeout(ea.current)},[]);let[ec,eu]=(0,o.useState)(null),ep=(0,o.useCallback)(e=>{eu(e)},[]),[eh,eg]=(0,o.useState)(null),[ex,ef]=(0,o.useState)(null),em=(0,o.useCallback)(()=>{g&&H(!1),eg("session")},[g]),ev=(0,o.useCallback)(()=>{g&&eg(null),H(e=>!e)},[g]);(0,o.useEffect)(()=>{if(!eh||!_.current)return;let e=()=>{let e=_.current.getBoundingClientRect();ef({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(_.current),()=>t.disconnect()},[eh]);let[ey,eb]=(0,o.useState)([]),[ek,ej]=(0,o.useState)(null),[ew,eS]=(0,o.useState)(!1),eC=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e;if(!eC.current){eC.current=!0;try{e=function(e){try{let t=JSON.parse(e??"null");if(!cY(t))return{tabs:[],activeId:null,open:!1};let r=[],n=new Set;for(let e of Array.isArray(t.tabs)?t.tabs:[]){if(!cY(e))continue;let t="string"==typeof e.id?e.id:"",o="string"==typeof e.filePath?e.filePath:"",i="string"==typeof e.label?e.label:"",s="subagent"===e.kind,l="string"==typeof e.sessionId?e.sessionId:"";!(!t||!i||n.has(t))&&(s?l:o)&&(n.add(t),r.push({id:t,label:i,filePath:o,..."terminal"===e.kind?{kind:"terminal"}:{},...s?{kind:"subagent",sessionId:l}:{},..."string"==typeof e.sourceSessionId?{sourceSessionId:e.sourceSessionId}:{},..."diff"===e.initialDisplayMode?{initialDisplayMode:"diff"}:{}}))}let o="string"==typeof t.activeId&&r.some(e=>e.id===t.activeId)?t.activeId:r[r.length-1]?.id??null;return{tabs:r,activeId:o,open:!0===t.open&&r.length>0}}catch{return{tabs:[],activeId:null,open:!1}}}(localStorage.getItem(cJ))}catch{return}0!==e.tabs.length&&(eb(e.tabs),ej(e.activeId),eS(e.open))}},[]),(0,o.useEffect)(()=>{if(eC.current)try{localStorage.setItem(cJ,JSON.stringify({tabs:ey.filter(e=>!e.closing).map(e=>({id:e.id,label:e.label,filePath:e.filePath,...e.kind?{kind:e.kind}:{},...e.sessionId?{sessionId:e.sessionId}:{},...e.sourceSessionId?{sourceSessionId:e.sourceSessionId}:{},...e.initialDisplayMode?{initialDisplayMode:e.initialDisplayMode}:{}})),activeId:ek,open:ew}))}catch{}},[ey,ek,ew]);let[ez,eT]=(0,o.useState)(!1),[eR,eI]=(0,o.useState)([]),[eM,eE]=(0,o.useState)(()=>new Set);(0,o.useEffect)(()=>{if(!ez)return void eI(e=>0===e.length?e:[]);let e=!1,t=()=>{fetch("/api/sessions",{cache:"no-store"}).then(e=>e.json()).then(t=>{e||(eI(t.sessions??[]),eE(new Set(t.runningSessionIds??[])))}).catch(()=>{})};t();let r=setInterval(t,3e3);return()=>{e=!0,clearInterval(r)}},[ez,x?.id,y]);let e$=(0,o.useCallback)(async e=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}`,{cache:"no-store"}),r=await t.json();if(!t.ok||!r.info)throw Error(r.error??`HTTP ${t.status}`);e9.current(r.info)}catch(e){console.error("[pi-web] failed to open session:",e instanceof Error?e.message:e)}},[]),eW=(0,o.useRef)(260),eL=(0,o.useRef)(uV(1366)),eA=(0,o.useCallback)(()=>uV(window.innerWidth),[]),eF=(0,o.useCallback)(()=>(function(e){let{viewportWidth:t,rightPanelOpen:r,rightPanelWidth:n}=e;if(t<=640)return 480;let o=t<960;return Math.min(480,t-(o?320:420)-(!o&&r?n:0))})({viewportWidth:window.innerWidth,rightPanelOpen:ew,rightPanelWidth:eL.current}),[ew]),eP=(0,o.useCallback)(()=>(function(e){let{viewportWidth:t,sidebarOpen:r,sidebarWidth:n}=e;return t<960?1200:Math.min(1200,t-420-(r?n:0))})({viewportWidth:window.innerWidth,sidebarOpen:D,sidebarWidth:eW.current}),[D]),eD=uY({ariaLabel:h("desktop.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:eF,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:eW}),eH=uY({ariaLabel:h("desktop.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:uV(1366),getDefaultWidth:eA,getMaxWidth:eP,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:eL}),eO=eD.reclampWidth,eB=eH.reclampWidth;(0,o.useEffect)(()=>{ew&&(eO(),eB())},[eB,eO,ew]);let eU=(0,o.useCallback)((e,t)=>{U.current?.insertText(dn(e,t))},[]),e_=(0,o.useCallback)(e=>{let t=e.map(e=>dn(e,!1)).join("");t&&U.current?.insertText(t)},[]),eq=(0,o.useCallback)((e,t,r)=>{let n,o,i,s;U.current?.insertText((n=Math.max(1,Math.min(t,r)),o=Math.max(1,Math.max(t,r)),i=e.includes(" ")?`@"${e}"`:`@${e}`,s=n===o?`:${n}`:`:${n}-${o}`,`${i}${s} `))},[]),[eK,eV]=(0,o.useState)(()=>c.sessionId),[eJ,eY]=(0,o.useState)(null),[eG,eX]=(0,o.useState)(()=>c.requestedCwd?"validating":"idle"),[eZ,eQ]=(0,o.useState)(null),[e0,e1]=(0,o.useState)(()=>!eK),e2=(0,o.useRef)(!1),e6=(0,o.useRef)(new Map),[e4,e5]=(0,o.useState)(null),e3=(0,o.useRef)("");(0,o.useEffect)(()=>{let e=`${c.requestedCwd??""}|${c.sessionId??""}`;e3.current!==e&&(e3.current=e,eV(c.sessionId),e1(!c.sessionId),c.requestedCwd||eX("idle"),eQ(null))},[c]),(0,o.useEffect)(()=>{let e=c.requestedCwd;if(!e)return;let t=new AbortController;return eX("validating"),eQ(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok||!t.cwd)throw Error(t.error??`HTTP ${e.status}`);e2.current=!0,v(t.cwd),eX("ready")}).catch(e=>{t.signal.aborted||(eQ(e instanceof Error?e.message:String(e)),eX("error"))}),()=>t.abort()},[c]);let e8=(0,o.useCallback)((e,t)=>{if(!e)return;if(eY(e),e2.current&&x&&iE(x.projectRoot??x.cwd,t??e)){if(e2.current=!1,x){let e=x.projectRoot??x.cwd;e&&e6.current.set(e,x.id)}return}e2.current=!1;let r=t??e;if(x&&iE(x.projectRoot??x.cwd,r)){(x.projectRoot??x.cwd)&&e6.current.set(r,x.id);return}if(x){let e=x.projectRoot??x.cwd;e&&e6.current.set(e,x.id)}f(null),v(t=>t&&t!==e?null:t),j(e=>e+1),et(null),eg(null),window.history.replaceState(null,"","/");let n=e6.current.get(r);e5(n?{projectRoot:r,sessionId:n}:null)},[x]);(0,o.useEffect)(()=>{let e=eJ?ok(eJ)||eJ:null;document.title=e?`${e} — Pi Agent Web`:"Pi Agent Web"},[eJ]);let e7=(0,o.useCallback)((e,t=!1)=>{if(t||e5(null),!t&&x){let t=iE(x.projectRoot??x.cwd,e.projectRoot??e.cwd);if(x.id===e.id&&t){g&&H(!1);return}}let r=e.projectRoot??e.cwd;r&&e6.current.set(r,e.id),v(null),f(e),j(e=>e+1),et(null),e1(!0),g&&!t&&H(!1),t&&(e2.current=!0),t||window.history.replaceState(null,"",`?session=${encodeURIComponent(e.id)}`)},[g,x]),e9=(0,o.useRef)(()=>{});(0,o.useEffect)(()=>{e9.current=e7},[e7]);let te=(0,o.useCallback)(e=>{fetch("/api/sessions").then(e=>e.ok?e.json():null).then(t=>{let r=t?.sessions.find(t=>t.id===e);r&&f(t=>!t||t.id!==e||t.projectRoot&&t.name?t:r)}).catch(()=>{})},[]);(0,o.useEffect)(()=>{if(!e4)return;let{projectRoot:e,sessionId:t}=e4;e9.current({path:"",id:t,cwd:e,created:"",modified:"",messageCount:0,firstMessage:"",projectRoot:e},!0),te(t),window.history.replaceState(null,"",`?session=${encodeURIComponent(t)}`),e5(null)},[e4,te]);let tt=(0,o.useCallback)((e,t)=>{e5(null),f(null),v(t),j(e=>e+1),et(null),eg(null),g&&H(!1),window.history.replaceState(null,"","/")},[a,g]);!function(e){let{onNewSession:t,activeCwd:r}=e;(0,o.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(!l)return;let t=e.target?.tagName;if("TEXTAREA"===t||"INPUT"===t)return;e.preventDefault(),l();return}if("n"===e.key&&e.ctrlKey&&e.altKey){if(!r||!t)return;e.preventDefault(),t(r)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[r,t])}({onNewSession:e=>tt(`kb-${Date.now()}`,e),activeCwd:eJ});let tr=(0,o.useCallback)(e=>{v(null),e5(null);let t=e.projectRoot??e.cwd;t&&e6.current.set(t,e.id),f(e),e.cwd&&eY(e.cwd),b(e=>e+1),te(e.id),window.history.replaceState(null,"",`?session=${encodeURIComponent(e.id)}`),window.setTimeout(()=>b(e=>e+1),1200),window.setTimeout(()=>b(e=>e+1),4e3)},[a,te]),tn=(0,o.useCallback)(()=>{b(e=>e+1),S(e=>e+1)},[]),to=(0,o.useCallback)(e=>{b(e=>e+1),j(e=>e+1),v(null),e5(null),f(t=>{let r={...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e},n=r.projectRoot??r.cwd;return n&&e6.current.set(n,e),r}),te(e),window.history.replaceState(null,"",`?session=${encodeURIComponent(e)}`)},[a,te]),ti=(0,o.useCallback)(()=>{e1(!0)},[]),ts=(0,o.useCallback)(e=>{if(b(e=>e+1),x?.id===e){let e=x.cwd;f(null),v(e??null),j(e=>e+1),et(null),eg(null),window.history.replaceState(null,"","/")}},[a,x]),tl=(0,o.useCallback)((e,t,r,n)=>{let o="string"==typeof r||null===r?r:void 0,i="object"==typeof r&&null!==r?r:n,s=`file:${e}`;eb(r=>{let n=r.find(e=>e.id===s);return n?o&&n.sourceSessionId!==o||i?.initialDisplayMode&&n.initialDisplayMode!==i.initialDisplayMode?r.map(e=>e.id===s?{...e,sourceSessionId:o??e.sourceSessionId,initialDisplayMode:i?.initialDisplayMode??e.initialDisplayMode}:e):r:[...r,{id:s,label:t,filePath:e,sourceSessionId:o,initialDisplayMode:i?.initialDisplayMode}]}),ej(s),eS(!0),g&&H(!1)},[g]),ta=(0,o.useCallback)(e=>{tl(e,ok(e),x?.id??null)},[tl,x?.id]),td=(0,o.useMemo)(()=>{let e=new Map;for(let t of eR){if(t.relation?.kind!=="subagent")continue;let r=t.relation;e.set(t.id,{status:eM.has(t.id)?"running":r.status,...r.createdAt?{createdAt:r.createdAt}:{},...r.completedAt?{completedAt:r.completedAt}:{}})}return e},[eR,eM]),tc=(0,o.useCallback)((e,t)=>{let r=`subagent:${e}`;eb(n=>n.some(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:"",kind:"subagent",sessionId:e}]),ej(r),eS(!0),g&&H(!1)},[g]),tp=(0,o.useCallback)(e=>{eb(t=>{let r=t.filter(t=>t.id!==e);return 0===r.length&&eS(!1),r}),ej(t=>{if(t!==e)return t;let r=ey.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:null})},[ey]),th=(0,o.useCallback)(e=>{S(e=>e+1),tl(e,ok(e))},[tl]),tg=(0,o.useCallback)((e,t)=>{S(e=>e+1);let r=e.endsWith("/")?e:e+"/",n=n=>n===e||t&&n.startsWith(r);eb(e=>{let t=e.filter(e=>!n(e.filePath));return 0===t.length&&eS(!1),t}),ej(e=>{if(!e)return e;let t=ey.find(t=>t.id===e);if(!t||!n(t.filePath))return e;let r=ey.filter(e=>!n(e.filePath));return r.length>0?r[r.length-1].id:null})},[ey]),tx=x?n6({name:x.name||en?.sessionName||void 0,firstMessage:x.firstMessage,id:x.id},(x.cwd??eJ??"").replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()):(t=eJ??m)?t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t:null,tf=(0,o.useCallback)(()=>{x&&window.open(`/api/sessions/${encodeURIComponent(x.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[x]),tm=m??(null===x&&eJ?eJ:null),tv="validating"!==eG&&"error"!==eG&&(null!==x||null!==tm),ty=x?.cwd??tm,[tb,tk]=(0,o.useState)(!1),tj=(0,o.useCallback)(()=>{g||tk(e=>!e)},[g]),[tw,tS]=(0,o.useState)(!0);(0,o.useEffect)(()=>{let e=!1,t=()=>fetch("/api/features").then(e=>e.ok?e.json():null).then(t=>{!e&&t&&"boolean"==typeof t.tasksBoard&&(tS(t.tasksBoard),t.tasksBoard||tk(!1))}).catch(()=>{});t();let r=()=>t();return window.addEventListener("pi:features-changed",r),()=>{e=!0,window.removeEventListener("pi:features-changed",r)}},[]);let tC=e0&&!tv;(0,o.useEffect)(()=>{let e=()=>{g||tk(!0)};return window.addEventListener(cf,e),()=>window.removeEventListener(cf,e)},[g]),(0,o.useEffect)(()=>{if($(null),L(!1),P(null),!ty)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(ty)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);$(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[ty]);let tz=(0,o.useCallback)(async()=>{if(ty&&!N){A(!0),P(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ty})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);$(t),L(!1),M(e=>e+1),j(e=>e+1)}catch(e){P(e instanceof Error?e.message:String(e))}finally{A(!1)}}},[N,ty]),tT=ey.find(e=>e.id===ek)??null,tR=eJ??x?.cwd??m,tI=(0,o.useCallback)(e=>{R(e),z(!0)},[]),tM=(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(iO,{selectedSessionId:x?.id??null,onSelectSession:e7,onNewSession:tt,initialSessionId:eK,onInitialRestoreDone:ti,refreshKey:y,onSessionDeleted:ts,selectedCwd:x?.cwd??m??null,onCwdChange:e8,onOpenFile:tl,selectedSessionStats:en,onOpenSettings:e=>{tI(e??"models")},explorerRefreshKey:w,onAtMention:eU,onAtMentions:e_,onFileCreated:th,onFileDeleted:tg,workspaceControlsHosts:{title:q,welcome:G,titleRight:V},showWorkspaceControls:!0})});return(0,n.jsxs)(cQ,{children:[(0,n.jsx)("style",{children:`
|
|
194
|
+
${r}`):i=r;let h=i,g=o?.map(e=>({type:"image",source:{type:"base64",media_type:e.mimeType,data:e.data}})),x={role:"user",content:g?.length?[...r.trim()?[{type:"text",text:r}]:[],...g]:r,timestamp:Date.now()};z(e=>[...e,x]),rs.current=ch(x),ri.current=a;let f="goal"===ez.current&&!l&&s.length>0&&"idle"===eP.current.status;f&&(eM.current=s,eF(e=>({...e,status:"running",goalText:s,turnsUsed:0,noProgressTurns:0,tokensUsed:0})),eD.current=!0),tY.current=!0,q(!0),td(l?{kind:"running_command"}:{kind:"waiting_model"}),A({type:"start"}),t3.current=!0,tu(!0),t8.current=!0;let m=o?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType})),v=null,y=!1;try{if(p&&n){let e=tV.current??await rn.current,t=e??await rC();if(t){v=t,rS(1,r),ea&&(tt(ea),e&&await tM(t,{type:"set_model",provider:ea.provider,modelId:ea.modelId}));let n=await Promise.race([rM(t).then(()=>!0).catch(()=>!1),cd(4e3).then(()=>!1)]);y=!0,await tM(t,{type:"prompt",message:h,...m?.length?{images:m}:{}}),n||rU(t,a),f&&tM(t,{type:"goal_start",goalText:s}).catch(()=>{})}else throw Error("Unable to create a session for this message")}else if(t){v=t.id;let e=await Promise.race([rM(t.id).then(()=>!0).catch(()=>!1),cd(4e3).then(()=>!1)]);y=!0,await tM(t.id,{type:"prompt",message:h,...m?.length?{images:m}:{}}),e||rU(t.id,a),f&&tM(t.id,{type:"goal_start",goalText:s}).catch(()=>{})}l&&v&&rU(v,a)}catch(t){if(console.error("Failed to send message:",t),y&&v)return void rU(v,a);if(tX.current=!1,rR(),t instanceof ca){let e=rs.current;e&&z(t=>{let r=t[t.length-1];return r?.role==="user"&&ch(r)===e?t.slice(0,-1):t}),rW({type:"error",message:t.message})}else{let r=rs.current;r&&z(e=>{let t=e[e.length-1];return t?.role==="user"&&ch(t)===r?e.slice(0,-1):e}),e.chatInputRef?.current?.replaceMessage?.(x),rW({type:"error",message:`Failed to send message: ${t instanceof Error?t.message:String(t)}`})}rs.current=null,tY.current=!1,q(!1),td(null),A({type:"end"})}},[p,n,ea,t,rC,rM,rS,rU,rW,rT,rR,rg]),rY=(0,o.useCallback)(async(r,n)=>{if(tY.current||t1.current)return;let o=`${n?"!!":"!"}${r}`;t1.current=!0,Y({command:r,excludeFromContext:n}),V(!0);try{let e=tV.current??t?.id??await rC();if(!e)throw Error("Unable to create a session for the shell command");rS(1,o),await tM(e,{type:"bash",command:r,excludeFromContext:n}),await rj(e)}catch(t){console.error("Failed to execute shell command:",t),rW({type:"error",message:t instanceof Error?t.message:String(t)}),e.chatInputRef?.current?.insertIfEmpty(o)}finally{t1.current=!1,Y(null),V(!1)}},[rW,rC,rj,e.chatInputRef,rS,t]),rG=(0,o.useCallback)(async()=>{let e=tV.current;if(e)try{await tM(e,{type:t1.current?"abort_bash":"abort"})}catch(e){console.error("Failed to abort:",e)}},[]),rX=(0,o.useCallback)(async e=>{let t=tV.current;if(t){eY(e);try{let{cancelled:r,newSessionId:n}=await tM(t,{type:"fork",entryId:e})??{};!r&&n&&l?.(n)}catch(e){console.error("Fork failed:",e)}finally{eY(null)}}},[l]),rZ=(0,o.useCallback)(async e=>{if(t1.current)return!1;let t=tV.current;if(!t)return!1;try{let r=await tM(t,{type:"navigate_tree",targetId:e});if(r?.cancelled||tV.current!==t)return!1;return S(e),await rj(t),tV.current===t}catch(e){return console.error("Failed to navigate:",e),!1}},[rj]),rQ=(0,o.useCallback)(async e=>{S(e);let t=tV.current;t&&(await rN(t,e),e&&tM(t,{type:"navigate_tree",targetId:e}).catch(()=>{}))},[rN]),r0=(0,o.useCallback)(async(e,t)=>{if(p){let r={provider:e,modelId:t};ru.current=r,ed(r),tt(r);let n=tV.current??await rn.current;if(!n)return;try{await tM(n,{type:"set_model",provider:e,modelId:t})}catch(e){console.error("Failed to set model:",e)}return}let r=tV.current;if(!r)return;let n=++rl.current,o=eG??g?.context.model??null;eX({provider:e,modelId:t});try{await tM(r,{type:"set_model",provider:e,modelId:t})}catch(r){console.error("Failed to set model:",r),rl.current===n&&(eX(o&&(o.provider!==e||o.modelId!==t)?o:null),rW({type:"error",message:r instanceof Error?r.message:String(r)}))}},[rW,eG,g?.context.model,p,ed]),r1=(0,o.useCallback)(async()=>{let e=tV.current;if(e&&!tr){tn(!0),ti(null),tl(null);try{let t=await tM(e,{type:"compact"});tl(cg(t,"manual")),await rj(e,!0)}catch(e){ti(e instanceof Error?e.message:String(e)),tl(null)}finally{tn(!1)}}},[tr,rj]),r2=(0,o.useCallback)(async e=>{let r=++ra.current,o=n??t?.cwd??"",i=o?`/api/models?cwd=${encodeURIComponent(o)}`:"/api/models",s=rd.current;s?.abort();let l=new AbortController;rd.current=l;let a=()=>l.abort();e?.aborted?l.abort():e?.addEventListener("abort",a,{once:!0});try{let e=await fetch(i,{signal:l.signal});if(!e.ok){let t=`HTTP ${e.status}`;try{let r=await e.json();r?.error&&(t=r.error)}catch{}throw Error(t)}let t=await e.json();if(r!==ra.current||h!==rc.current)return;el(null),X(t.models),et(t.thinkingLevels??{}),en(t.thinkingLevelMaps??{}),ei(t.modelScopeWarnings??[]);let n=t.modelList??[];if(Q(n),p&&!tV.current){let e=(t.defaultModel?n.find(e=>e.id===t.defaultModel?.modelId&&e.provider===t.defaultModel?.provider):void 0)??n[0];eu(e?{provider:e.provider,modelId:e.id}:null);let r=e?t.thinkingLevelPins?.[`${e.provider}/${e.id}`]:void 0;null===rp.current&&eO(r??"auto")}}catch(e){if(l.signal.aborted||r!==ra.current||h!==rc.current)return;el(e instanceof Error?e.message:String(e))}finally{e?.removeEventListener("abort",a),rd.current===l&&(rd.current=null)}},[p,h,n,t?.cwd]),r6=(0,o.useCallback)(async e=>{if(!e.startsWith("/"))return{handled:!1};let t=e.match(/^\/([^\s]+)(?:\s+([\s\S]*))?$/);if(!t)return{handled:!1};let[,r,n=""]=t,o=n.trim(),i=tV.current??await rC(),s=e=>(e.handled&&(e.error?rW({type:"error",message:e.error}):"openSessionStats"!==e.action&&rW({type:"success",message:e.message??"Command completed"})),e);try{switch(r){case"compact":{if(!i||tr)return s({handled:!0,error:"No active session to compact"});tn(!0),ti(null),tl(null);let e=await tM(i,{type:"compact",...o?{customInstructions:o}:{}});return tl(cg(e,"manual")),await rj(i,!0)&&rS(),s({handled:!0,message:"Compacted context"})}case"reload":if(!i)return s({handled:!0,error:"No active session to reload"});return await tM(i,{type:"reload"}),await Promise.all([rj(i,!1,!0),rw(i),rz(),r2()]),s({handled:!0,message:"Reloaded session resources"});case"name":if(!i)return s({handled:!0,error:"No active session to name"});if(!o)return s({handled:!0,error:"Usage: /name <name>"});return await tM(i,{type:"set_session_name",name:e9(o)}),await rj(i)&&rS(),s({handled:!0,message:`Session renamed to ${o}`});case"session":{if(!i)return s({handled:!0,error:"No active session"});let e=await tM(i,{type:"get_session_stats"});return e&&ty(e),u?.(),s({handled:!0,action:"openSessionStats"})}case"copy":{if(!i)return s({handled:!0,error:"No active session"});let e=await tM(i,{type:"get_last_assistant_text"}),t=e?.text??"";if(!t)return s({handled:!0,error:"No assistant message to copy"});return await navigator.clipboard.writeText(t),s({handled:!0,message:"Copied last assistant message"})}default:return{handled:!1}}}catch(e){return s({handled:!0,error:e instanceof Error?e.message:String(e)})}finally{"compact"===r&&tn(!1)}},[rW,rC,tr,r2,rj,rz,rw,rS,u]),r4=(0,o.useCallback)(async e=>{let t=!1;try{let r=await fetch(`/api/agent/${encodeURIComponent(e)}`);if(r.ok){let e=await r.json(),n=e.state;if(e.running&&n&&(n.isStreaming||n.isPromptRunning||n.isBashRunning||n.isCompacting))return;t=!0}}catch{}t?rD():rU(e)},[rU,rD]),r5=(0,o.useCallback)(async(e,t)=>{let r=tV.current;if(!r)return;let n=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tY.current=!0,q(!0),td(e=>e??{kind:"waiting_model"});try{await tM(r,{type:"steer",message:e,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to steer:",e),r4(r)}},[r4]),r3=(0,o.useCallback)(async(e,t,r)=>{let n=tV.current;if(!n)return;let o=r?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tY.current=!0,q(!0),td(e=>e??{kind:"waiting_model"});try{await tM(n,{type:"prompt",message:e,streamingBehavior:t,...o?.length?{images:o}:{}})}catch(e){console.error("Failed to queue prompt:",e),r4(n)}},[r4]),r8=(0,o.useCallback)(async(e,t)=>{let r=tV.current;if(!r)return;let n=t?.map(e=>({type:"image",data:e.data,mimeType:e.mimeType}));tY.current=!0,q(!0),td(e=>e??{kind:"waiting_model"});try{await tM(r,{type:"follow_up",message:e,...n?.length?{images:n}:{}})}catch(e){console.error("Failed to follow up:",e),r4(r)}},[r4]),r7=(0,o.useCallback)(async()=>{let e=tV.current;if(e)try{await tM(e,{type:"abort_compaction"})}catch(e){console.error("Failed to abort compaction:",e)}},[]),r9=(0,o.useCallback)(async()=>{let t=tV.current;if(t)try{let r=await tM(t,{type:"clear_queue"});tE({steering:[],followUp:[]});let n=[...r?.steering??[],...r?.followUp??[]];n.length>0&&e.chatInputRef?.current?.prependText(n.join("\n\n"))}catch(e){console.error("Failed to recall queued messages:",e),rW({type:"error",message:"Failed to recall queued messages"})}},[e.chatInputRef,rW,tE]);(0,o.useEffect)(()=>{0===t$.length&&tA(!1)},[t$.length]);let ne=(0,o.useCallback)(async(e,t,r=!1)=>{let n=tV.current;if(!n)return t$;try{let o=await tM(n,{type:"resolve_recovery",keep:e,discard:t,continueRun:r}),i=o?.remaining??[];return tL(i),r&&e.length>0&&(async()=>{try{let e=await fetch(`/api/agent/${encodeURIComponent(n)}`);if(!e.ok)return;let t=await e.json(),r=t.state;if(!t.running||!r||!r.isStreaming&&!r.isPromptRunning)return;tG.current=!!r.isStreaming,tX.current=!!r.isPromptRunning,tY.current=!0,q(!0),td(cn(r)),A({type:"start"}),rI(n),!r.isStreaming&&r.isPromptRunning&&rU(n)}catch{}})(),i}catch(e){return console.error("Failed to resolve queued message recovery:",e),rW({type:"error",message:"Failed to resolve queued message recovery"}),t$}},[t$,rW,rI,rU,tL]),nt=(0,o.useCallback)(async()=>{let e=tV.current;if(!e)return null;try{return await tM(e,{type:"export_queue"})}catch(e){return console.error("Failed to export queue:",e),rW({type:"error",message:"Failed to export queue"}),null}},[rW]),nr=(0,o.useCallback)(async e=>{let t=tV.current;if(!t)return null;try{let r=await tM(t,{type:"import_queue",entries:e});return r&&tE(ci(r)),r?.imported??0}catch(e){return console.error("Failed to import queue:",e),rW({type:"error",message:"Failed to import queue"}),null}},[rW,tE]),nn=(0,o.useCallback)(async e=>{let t=tV.current;if(!t)return null;try{let r=await tM(t,{type:"stage_recovery",entries:e});return r?.pendingRecovery&&tL(r.pendingRecovery),(r?.staged??0)>0&&tA(!0),r?.staged??0}catch(e){return console.error("Failed to stage imported queue:",e),rW({type:"error",message:"Failed to stage imported queue"}),null}},[rW,tL]),no=(0,o.useCallback)(async(e,t,r)=>{let n=tV.current;if(!n)return!1;try{let o=await tM(n,{type:"move_queue",kind:e,fromIndex:t,toIndex:r});return o&&tE(ci(o)),!0}catch(e){return console.error("Failed to move queued message:",e),rW({type:"error",message:e instanceof Error?e.message:"Failed to move queued message"}),!1}},[rW,tE]),ni=(0,o.useCallback)(async(e,t)=>{let r=tV.current;if(!r)return null;try{let n=await tM(r,{type:"recall_queue_item",kind:e,index:t});return n&&(void 0!==n.steering||void 0!==n.followUp)&&tE(ci(n)),n?.entry?{text:n.entry.text,images:n.entry.images?.map(({data:e,mimeType:t})=>({data:e,mimeType:t}))}:null}catch(e){return console.error("Failed to recall queued message:",e),rW({type:"error",message:e instanceof Error?e.message:"Failed to recall queued message"}),null}},[rW,tE]),ns=(0,o.useCallback)(async(e,t,r,n)=>{let o=tV.current;if(!o)return!1;try{let i=await tM(o,{type:"requeue_at",kind:e,index:t,text:r,images:n?.map(({data:e,mimeType:t})=>({type:"image",data:e,mimeType:t}))});return i&&tE(ci(i)),!0}catch(e){return console.error("Failed to requeue message:",e),rW({type:"error",message:e instanceof Error?e.message:"Failed to requeue message"}),!1}},[rW,tE]),nl=(0,o.useCallback)(async(e,t)=>{let r=tV.current;if(!r)return!1;try{let n=await tM(r,{type:"remove_queue_item",kind:e,index:t});return n&&tE(ci(n)),!0}catch(e){return console.error("Failed to remove queued message:",e),rW({type:"error",message:e instanceof Error?e.message:"Failed to remove queued message"}),!1}},[rW,tE]),na=(0,o.useCallback)(async e=>{if(rp.current="auto"===e?null:e,eO(e),"auto"===e)return;let t=tV.current??await rn.current;if(t)try{await tM(t,{type:"set_thinking_level",level:e})}catch(e){console.error("Failed to set thinking level:",e)}},[]),nd=(0,o.useCallback)(async e=>{let t=(0,d9.xG)(e);rf(e);let r=tV.current??await rn.current;if(r)try{await tM(r,{type:"set_tools",toolNames:t})}catch(e){console.error("Failed to set tools:",e)}},[rf]),nc=(0,o.useRef)(0),nu=(0,o.useCallback)(async e=>{let t=tV.current??await rn.current,r=++nc.current;if("plan"===e){if(eg.current="plan"===ep?"default":ep,t)try{await tM(t,{type:"prompt",message:"/plan"})}catch(e){if(nc.current!==r)return;console.error("Failed to enter plan mode:",e)}return}if(t){try{if(await tM(t,{type:"prompt",message:"/plan exit"}),nc.current!==r)return}catch(e){if(nc.current!==r)return;console.error("Failed to exit plan mode:",e)}if(nc.current!==r)return;try{await tM(t,{type:"set_tools",toolNames:(0,d9.xG)(eg.current)})}catch(e){console.error("Failed to restore tools after plan exit:",e)}}},[ep]),np=(0,o.useCallback)(e=>{e$.current=e,em(e);let t=tV.current;if(!t){ev.current=e;return}ev.current=null,fetch(`/api/modes?session=${encodeURIComponent(t)}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(e=>{console.error("Failed to persist mode settings:",e)})},[]),nh=(0,o.useCallback)(e=>{let t=e1(e),r="plan"===ez.current;if(np({...e$.current,collaborationMode:t}),ez.current=t,eE.current={sessionKey:"",signature:""},"goal"!==t){eM.current=null,eD.current=!1,eF(e=>"idle"===e.status?e:{...e,status:"idle",goalText:null});let e=tV.current;e&&tM(e,{type:"goal_stop"}).catch(()=>{})}return"plan"!==t||r?"plan"!==t&&r?nu("normal"):Promise.resolve():nu("plan")},[np,nu]),ng=(0,o.useCallback)(async e=>{np({...e$.current,tokenMode:e2(e)});let t=tV.current??await rn.current;if(t)try{if("economy"!==e||ex.current){if("economy"!==e){let e=ex.current?d9.SC:(0,d9.xG)("plan"===ep?"default":ep);await tM(t,{type:"set_tools",toolNames:e})}}else await tM(t,{type:"set_tools",toolNames:[...e4]})}catch(e){console.error("Failed to apply token mode tools:",e)}},[np,ep]),nx=(0,o.useCallback)(async e=>{np({...e$.current,toolApprovalMode:e6(e)});let t=tV.current??await rn.current;if(t)try{await tM(t,{type:"set_approval_mode",mode:e6(e)})}catch(e){console.error("Failed to apply approval mode:",e)}},[np]),nf=(0,o.useCallback)(async e=>{np({...e$.current,permissionRules:e});let t=tV.current??await rn.current;if(t)try{await tM(t,{type:"set_approval_policy",policy:e})}catch(e){console.error("Failed to apply permission rules:",e)}},[np]),nm=(0,o.useCallback)(async(e,t,r,n)=>{let o=tV.current;if(o){if("always"===n){let r=eN.current.find(t=>t.id===e);if(r){let e=ao(r.toolName,r.args),n=e?`${r.toolName}(${e})`:r.toolName,o=e$.current.permissionRules;(t?o.allow:o.deny).includes(n)||nf(t?{...o,allow:[...o.allow,n]}:{...o,deny:[...o.deny,n]})}}try{await tM(o,{type:"resolve_approval",id:e,approve:t,reason:r})}catch(e){console.error("Failed to resolve approval:",e)}finally{eL(t=>t.filter(t=>t.id!==e))}}},[nf]),nv=(0,o.useCallback)(e=>{eM.current=e},[]),ny=(0,o.useCallback)(e=>{let t=e.trim();if(!t)return;eM.current=t,eF(e=>({...e,status:"running",goalText:t,turnsUsed:0,noProgressTurns:0,tokensUsed:0,startedAt:Date.now()}));let r=tV.current;r&&tM(r,{type:"goal_start",goalText:t}).catch(()=>{})},[]),nb=(0,o.useCallback)(()=>{if("running"!==eP.current.status)return;eF(e=>({...e,status:"paused"}));let e=tV.current;e&&tM(e,{type:"goal_pause"}).catch(()=>{})},[]),nk=(0,o.useCallback)(()=>{let e=eP.current;if("paused"!==e.status&&"blocked"!==e.status)return;eF(e=>({...e,status:"running"}));let t=tV.current;t&&tM(t,{type:"goal_resume"}).catch(()=>{})},[]),nj=(0,o.useCallback)(()=>{eD.current=!1,eM.current=null,eF(e=>({...e,status:"idle",goalText:null,turnsUsed:0,noProgressTurns:0}));let e=tV.current;e&&tM(e,{type:"goal_stop"}).catch(()=>{})},[]),nw=(0,o.useCallback)(e=>{let t=e.trim();if(!t)return;eF(e=>({...e,goalText:t}));let r=tV.current;r&&tM(r,{type:"goal_edit",goalText:t}).catch(()=>{})},[]),nS=(0,o.useCallback)(()=>{let e=rr.current,t=t5.current;if(!e||!t)return;let r=t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,n=Math.max(0,e.scrollHeight-e.clientHeight),o=Math.min(Math.max(0,r-16),n);t7.current=o>=n-150,re.current=Date.now()+700,e.scrollTo({top:o,behavior:"smooth"})},[]),nC=(0,o.useCallback)(e=>{if(e instanceof KeyboardEvent){if(!cl.has(e.key)||e.target instanceof Element&&e.target.closest("input, textarea, [contenteditable='true']"))return}else if(e instanceof PointerEvent){let t=rr.current;if(t&&e.target instanceof Element&&!t.contains(e.target))return}t9.current=Date.now()+1200},[]),nz=(0,o.useCallback)(()=>{let e=rr.current;if(e){let{scrollTop:t,clientHeight:r,scrollHeight:n}=e;t7.current=t+r>=n-150}if(Date.now()<t9.current){t8.current=!1;return}Date.now()<re.current||(t8.current=!1)},[]);(0,o.useEffect)(()=>{if(tQ.current=!0,t){tV.current=t.id;let e=eR.current,r=eI.current;("auto"!==e||r.allow.length||r.ask.length||r.deny.length)&&(tM(t.id,{type:"set_approval_mode",mode:e}).catch(()=>{}),tM(t.id,{type:"set_approval_policy",policy:r}).catch(()=>{}));let n=e=>{!t2.current&&(t2.current=!0,e.isBashRunning&&(t1.current=!0,V(!0)),rw(t.id),(e.isStreaming||e.isPromptRunning)&&(tG.current=!!e.isStreaming,tX.current=!!e.isPromptRunning,tY.current=!0,q(!0),td(cn(e)),A({type:"resume"}),rI(t.id),!e.isStreaming&&e.isPromptRunning&&rU(t.id)))};(async()=>{try{let e,r=new AbortController,o=setTimeout(()=>r.abort(),2e4);try{e=await fetch(`/api/sessions/${encodeURIComponent(t.id)}/state`,{signal:r.signal})}finally{clearTimeout(o)}if(!e.ok)throw Error(`HTTP ${e.status}`);let i=await e.json();if(!tQ.current||tV.current!==t.id)return;i.running&&i.state&&n(i.state)}catch{}})(),rj(t.id,!0,!0).then(e=>{e?.running&&e.state&&n(e.state),e?.state&&(void 0!==e.state.isCompacting&&tn(e.state.isCompacting),void 0!==e.state.contextUsage&&eq(e.state.contextUsage??null),void 0!==e.state.systemPrompt&&eV(e.state.systemPrompt??null),void 0!==e.state.thinkingLevel&&eO(e.state.thinkingLevel??"auto"),void 0!==e.state.extensionStatuses&&tC(e.state.extensionStatuses??[]),void 0!==e.state.extensionWidgets&&tT(e.state.extensionWidgets??[]),void 0!==e.state.queuedMessages&&tE(ci(e.state.queuedMessages)),void 0!==e.state.pendingRecovery&&tL(e.state.pendingRecovery??[])),e?.running||(async()=>{for(let e=0;e<5;e++){if(e>0&&await new Promise(e=>setTimeout(e,2e3)),!tQ.current||tV.current!==t.id||tY.current)return;try{let e=await fetch(`/api/agent/${encodeURIComponent(t.id)}`);if(!e.ok)continue;let r=await e.json();if(!tQ.current||tV.current!==t.id)return;if(r?.running&&r.state)return void n(r.state)}catch{}}})()})}return()=>{tQ.current=!1,f.current?.abort(),v.current?.abort(),rg(),tD(),rT(),rR()}},[rg]),(0,o.useEffect)(()=>{c?.(eK)},[eK,c]),(0,o.useEffect)(()=>{d&&d(g?.tree??[],w,rQ)},[g?.tree,w,rQ,d]),(0,o.useEffect)(()=>(window.addEventListener("keydown",nC),window.addEventListener("pointerdown",nC,{passive:!0}),()=>{window.removeEventListener("keydown",nC),window.removeEventListener("pointerdown",nC)}),[nC]),(0,o.useEffect)(()=>{let e=rr.current;if(e)return e.addEventListener("wheel",nC,{passive:!0}),e.addEventListener("touchstart",nC,{passive:!0}),e.addEventListener("scroll",nz,{passive:!0}),()=>{e.removeEventListener("wheel",nC),e.removeEventListener("touchstart",nC),e.removeEventListener("scroll",nz)}},[C.length,y,nz,nC]),(0,o.useEffect)(()=>{C.length>0&&(t3.current?(t4.current=!0,t5.current&&(t3.current=!1,nS())):y||!t4.current?(y||(t4.current=!0),rK("instant")):!tY.current&&(t8.current||t7.current)&&(rK("smooth"),nI(e=>e+1)))},[C.length,y,_,rK,nS]);let nT=(0,o.useRef)(null),[nR,nI]=(0,o.useState)(0),nM=`${t?.id??null}#${nR}`;(0,o.useEffect)(()=>{let e;if(y){nT.current=null;return}if(0===C.length||nT.current===nM)return;nT.current=nM;let t=!1,r=!1,n=-1,o=0,i=Date.now(),s=()=>{if(t||r)return;let l=rr.current;if(l){if(Date.now()<t9.current){let{scrollTop:e,clientHeight:t,scrollHeight:n}=l;if(e+t<n-150){r=!0;return}}if(rK("instant"),l.scrollHeight===n){if((o+=1)>=4||Date.now()-i>=3e4)return}else if(n=l.scrollHeight,o=0,Date.now()-i>=3e4)return;e=window.setTimeout(s,o>0?500:250)}};return e=window.setTimeout(s,250),()=>{t=!0,void 0!==e&&window.clearTimeout(e)}},[y,rK,nM]),(0,o.useEffect)(()=>{let e=new AbortController;return r2(e.signal).catch(e=>{if(e instanceof DOMException&&"AbortError"===e.name)return}),()=>e.abort()},[r2,a]),(0,o.useEffect)(()=>{if(!es)return;let e=()=>{"visible"===document.visibilityState&&r2()};return document.addEventListener("visibilitychange",e),window.addEventListener("online",e),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("online",e)}},[es,r2]),(0,o.useEffect)(()=>{if(!to)return;let e=setTimeout(()=>ti(null),3e3);return()=>clearTimeout(e)},[to]),(0,o.useEffect)(()=>{if(!ts)return;let e=setTimeout(()=>tl(null),6e3);return()=>clearTimeout(e)},[ts]),(0,o.useEffect)(()=>{if(0===tf.visible.length)return;let e=tf.visible.find(e=>e.exiting);if(e){let t=setTimeout(()=>{tm({type:"remove",id:e.id})},180);return()=>clearTimeout(t)}if(!tf.visible[0])return;let t=setTimeout(()=>{tm({type:"mark_oldest_exiting"})},5e3);return()=>clearTimeout(t)},[tf.visible]),(0,o.useEffect)(()=>{ty(null)},[C.length,e_?.tokens,e_?.percent,e_?.contextWindow]);let nE=g?.tree??[];return{data:g,loading:y,error:k,activeLeafId:w,messages:C,activeToolResults:T,entryIds:I,historyCursor:E,hasEarlierMessages:W,streamState:N,agentRunning:_,bashRunning:K,pendingBash:J,modelNames:G,modelList:Z,modelThinkingLevels:ee,modelThinkingLevelMaps:er,modelScopeWarnings:eo,modelsError:es,newSessionModel:ea,toolPreset:ep,thinkingLevel:eH,retryInfo:eB,contextUsage:e_,systemPrompt:eK,forkingEntryId:eJ,isCompacting:tr,compactError:to,compactResult:ts,currentModel:ry,displayModel:rb,sessionStats:rk,tokenRate:P,planMode:eC,collaborationMode:ek,tokenMode:ej,toolApprovalMode:ew,permissionRules:eS,modeSettings:ef,approvalRequests:eW,handleCollaborationModeChange:nh,handleTokenModeChange:ng,handleToolApprovalModeChange:nx,handlePermissionRulesChange:nf,resolveApproval:nm,setActiveGoalText:nv,goalState:eA,handleGoalStart:ny,handleGoalPause:nb,handleGoalResume:nk,handleGoalStop:nj,handleGoalEdit:nw,slashCommands:tp,slashCommandsLoading:tg,queuedMessages:tR,pendingRecovery:t$,recoveryIsImport:tN,notices:tf.visible,extensionDialog:tb,extensionCustomUi:tj,extensionStatuses:tS,extensionWidgets:tz,respondToExtensionUi:rE,sendExtensionCustomInput:r$,agentPhase:ta,isNew:p,promptAnchorActive:tc,branchTree:nE,sessionIdRef:tV,eventSourceRef:tH,messagesEndRef:rt,scrollContainerRef:rr,lastUserMsgRef:t5,pendingScrollToUserRef:t3,initialScrollDoneRef:t4,scrollUserMsgToTop:nS,handleSend:rJ,executeBash:rY,handleAbort:rG,handleFork:rX,handleNavigate:rZ,handleModelChange:r0,handleCompact:r1,handleSteer:r5,handleFollowUp:r8,handlePromptWithStreamingBehavior:r3,handleAbortCompaction:r7,handleRecallQueue:r9,resolveRecovery:ne,exportQueueData:nt,importQueueData:nr,stageQueueImport:nn,moveQueuedMessage:no,recallQueuedMessage:ni,requeueAt:ns,removeQueuedMessage:nl,handleBuiltinSlashCommand:r6,handleToolPresetChange:nd,handleThinkingLevelChange:na,loadTools:rw,loadSlashCommands:rz,reloadModels:r2,setActiveLeafId:S,setData:x,setMessages:z,loadContext:rN,dispatch:A,setAgentRunning:q,setForkingEntryId:eY,handleLeafChange:rQ,handleAgentEventRef:t6}}({session:e,newSessionCwd:t,onAgentEnd:N,onSessionCreated:s,onSessionForked:a,modelsRefreshKey:d,chatInputRef:c,onBranchDataChange:u,onSystemPromptChange:p,onSessionStatsPanelOpen:g}),[tC,tz]=(0,o.useState)(!1);(0,o.useEffect)(()=>{0===ef.length&&tz(!1)},[ef.length]);let tT=(0,o.useMemo)(()=>{let e=O.findLast(e=>"assistant"===e.role&&!!e.usage);if(!e?.usage)return null;let t=e.usage;return{model:e.model??"",input:t.input??0,output:t.output??0,cacheRead:t.cacheRead??0,costCNY:lL(e.model)?lN(e.model,t):0,costUSD:lL(e.model)?0:t.cost?.total??0}},[O]),[tR,tI]=(0,o.useState)(!1),[tE,t$]=(0,o.useState)(null),tW=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(!ta){tW.current=!1;return}if(q){tW.current=!0;return}tW.current&&(tW.current=!1,t$(function(e){for(let t=e.length-1;t>=0;t--){let r=e[t];if("assistant"!==r.role)continue;let n=r.content;if("string"==typeof n&&n.trim())return n;if(Array.isArray(n)){let e=n.filter(e=>"text"===e.type).map(e=>e.text??"").join("\n").trim();if(e)return e}}for(let t=e.length-1;t>=0;t--){let r=e[t];if("toolResult"!==r.role)continue;let n=r.content,o="string"==typeof n?n:Array.isArray(n)?n.map(e=>e.text??"").join("\n"):"";if(!o)continue;let i=o.match(/\*\*Proposed Plan\*\*\s*\n+([\s\S]+)/i);if(i?.[1]?.trim())return i[1].trim()}return null}(O)??null),tI(!0))},[q,ta,O]);let tL=(0,o.useCallback)(()=>{tI(!1);let e=tN.current;e&&tp("plan"===td?"normal":td).catch(e=>{console.error("Failed to leave plan mode before executing:",e)}).then(()=>{eF(E("tasks.planReviewExecutePrompt",{plan:e}))})},[tp,eF,E,td]),tN=(0,o.useRef)(null);(0,o.useEffect)(()=>{tN.current=tE},[tE]);let tA=(0,o.useCallback)(e=>{tI(!1),eF(e)},[eF]),tF=(0,o.useCallback)(()=>{tI(!1),tp("plan"===td?"normal":td)},[tp,td]);(0,o.useEffect)(()=>{ey&&L.current!==ey.id&&(L.current=ey.id,W.current&&$.current())},[ey]),(0,o.useEffect)(()=>(l=q||K?eD:null,()=>void(l=null)),[q,K,eD]);let[tP,tD]=(0,o.useState)(!1),[tH,tO]=(0,o.useState)(!1),[tB,tU]=(0,o.useState)(!1),t_=(0,o.useCallback)(()=>{let e=e$.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;tD(e.scrollTop>1),tO(t>1),tU(t>240)},[e$]),tq=(0,o.useCallback)(()=>{window.requestAnimationFrame(()=>{let e=e$.current,t=eE.current;if(!e||!t)return;let r=Math.max(88,c?.current?.measureHeight?.()??0),n=()=>{if(!e||!t)return;let n=Math.max(0,t.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop-96-e.clientHeight+r);e.scrollTo({top:n,behavior:"auto"})};n(),t_(),window.setTimeout(n,200)})},[eE,e$,t_,c]);(0,o.useEffect)(()=>{let e=e$.current;if(!e)return;let t=new ResizeObserver(t_);return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),e.addEventListener("scroll",t_,{passive:!0}),t_(),()=>{e.removeEventListener("scroll",t_),t.disconnect()}},[O.length,e$,t_]);let tK=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let t=e$.current;if(!t)return;let r=()=>{if(tK.current||!tw||!tj||t.scrollTop>8)return;let r=e?.id;if(!r)return;tK.current=!0;let n=t.scrollHeight-t.scrollTop;tS(r,eR,tj).finally(()=>{tK.current=!1,requestAnimationFrame(()=>{let e=t.scrollHeight-n;Math.abs(t.scrollTop-e)>1&&t.scrollTo({top:e,behavior:"auto"})})})};return t.addEventListener("scroll",r,{passive:!0}),()=>t.removeEventListener("scroll",r)},[e$,tj,tw,tS,e?.id,eR]);let tV=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(!tw||!tj)return;let t=e$.current,r=e?.id;if(!t||!r||tK.current||tV.current||D||t.scrollTop>8||t.scrollHeight>t.clientHeight+50)return;tV.current=!0;let n=t.scrollHeight-t.scrollTop;tS(r,eR,tj).finally(()=>{tV.current=!1,requestAnimationFrame(()=>{let e=t.scrollHeight-n;Math.abs(t.scrollTop-e)>1&&t.scrollTo({top:e,behavior:"auto"})})})},[e$,tj,tw,tS,e?.id,eR,D,O.length]);let tJ=(0,o.useRef)(null),tY=(0,o.useRef)([]),tG=(0,o.useRef)(new Map),tX=(0,o.useRef)(null),[tZ,tQ]=(0,o.useState)(0);(0,o.useEffect)(()=>{let e=tX.current;if(!e)return void tQ(e=>0===e?e:0);let t=()=>{let t=Math.round(e.getBoundingClientRect().height);tQ(e=>e===t?e:t)};t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[]);let t0=(0,o.useMemo)(()=>({getOffsetForIndex:e=>tJ.current?.getOffsetForIndex(e)?.[0]??0,sizeFor:e=>{let t=tJ.current;if(!t)return 0;let r=t.measurementsCache[e];return r?.size??t.options.estimateSize?.(e)??0},totalHeight:()=>tJ.current?.getTotalSize()??0,refToItemIndex:e=>tY.current[e],itemCount:tY.current.length}),[]),t1=eu?[eu.sessionId,eu.sessionFile??"",eu.sessionName??"",eu.userMessages,eu.assistantMessages,eu.toolCalls,eu.toolResults,eu.totalMessages,eu.tokens.input,eu.tokens.output,eu.tokens.cacheRead,eu.tokens.cacheWrite,eu.tokens.total,eu.cost??0,eu.totalActiveMs??0].join("|"):null,t2=(0,o.useRef)(eu);t2.current=eu,(0,o.useEffect)(()=>{h?.(t2.current)},[t1,h]),(0,o.useEffect)(()=>()=>{h?.(null)},[h]);let t6=ei?`${ei.percent??"null"}|${ei.contextWindow}|${ei.tokens??"null"}`:null,t4=(0,o.useRef)(ei);t4.current=ei,(0,o.useEffect)(()=>{x?.(t4.current)},[t6,x]),(0,o.useEffect)(()=>()=>{x?.(null)},[x]);let{isDragOver:t5,handleDragEnter:t3,handleDragOver:t8,handleDragLeave:t7,handleDrop:t9}=function(e){let[t,r]=(0,o.useState)(!1),n=(0,o.useRef)(0),i=(0,o.useCallback)(e=>{e.dataTransfer.files.length&&(e.preventDefault(),n.current+=1,r(!0))},[]),s=(0,o.useCallback)(e=>{e.dataTransfer.files.length&&e.preventDefault()},[]);return{isDragOver:t,handleDragEnter:i,handleDragOver:s,handleDragLeave:(0,o.useCallback)(()=>{n.current-=1,n.current<=0&&(n.current=0,r(!1))},[]),handleDrop:(0,o.useCallback)(t=>{t.preventDefault(),n.current=0,r(!1),e(Array.from(t.dataTransfer.files),t.dataTransfer)},[e])}}((0,o.useCallback)((e,t)=>{if(q){let t=e.filter(e=>e.type.startsWith("image/"));t.length&&c?.current?.addImages(t);return}c?.current?.addFiles(e,t)},[q,c])),re=O.filter(e=>"user"===e.role||"assistant"===e.role),rt=(0,o.useMemo)(()=>{let e=new Set,t=[];for(let n=O.length-1;n>=0&&t.length<50;n-=1){var r;let o="user"!==(r=O[n]).role?null:("string"==typeof r.content?r.content:r.content.filter(e=>"text"===e.type).map(e=>e.text).join("\n")).trim()||null;!o||e.has(o)||(e.add(o),t.push(o))}return t},[O]),rr=(S=re.length,(C=(0,o.useRef)([])).current.length!==S&&(C.current=Array.from({length:S},(e,t)=>C.current[t]??null)),C),rn=ez&&0===O.length&&!_.isStreaming&&!q,ro=e?.cwd??t??void 0,ri=(0,o.useMemo)(()=>(function(e,t,r,n){let o=new Map(n);for(let t of e)"toolResult"===t.role&&o.set(t.toolCallId,t);let i=-1;for(let t=e.length-1;t>=0;t--)if("user"===e[t].role){i=t;break}let s=new Map,l=0;e.forEach((e,t)=>{("user"===e.role||"assistant"===e.role)&&s.set(t,l++)});let a=[];for(let n=0;n<e.length;){let i,s=e[n],l="custom"===s.role&&"compaction"===s.customType;if(0===n&&"user"!==s.role&&!l){let r=1;for(;r<e.length&&"user"!==e[r].role;)r+=1;let i=Array.from({length:r},(e,t)=>t).filter(t=>ss(e[t])),s=st(e,t,i,o);if(s.length>0){a.push({kind:"turn",userIdx:-1,endIdx:r,startsCompactionTurn:!1,finalAssistantIdx:-1,visibleProcessIndices:i,processBlocks:s,processSegments:i3(s),finalAnswerMessage:null,writtenFiles:void 0}),n=r;continue}}if("user"!==s.role&&!l){a.push({kind:"single",idx:n}),n+=1;continue}let d=n,c=d+1;for(;c<e.length&&"user"!==e[c].role;)c+=1;let u=function(e,t,r){for(let o=r-1;o>t;o--){var n;if("assistant"===(n=e[o]).role&&i6(n).answerBlocks.some(e=>"image"===e.type||"text"===e.type&&e.text.trim().length>0))return o}for(let n=r-1;n>t;n--)if(e[n]?.role==="assistant")return n;return -1}(e,d,c);if(-1===u){let r=Array.from({length:c-d-1},(e,t)=>d+1+t).filter(t=>ss(e[t])),i=st(e,t,r,o);a.push({kind:"turn",userIdx:d,endIdx:c,startsCompactionTurn:l,finalAssistantIdx:u,visibleProcessIndices:r,processBlocks:i,processSegments:i3(i),finalAnswerMessage:null,writtenFiles:void 0}),n=c;continue}let p=[];for(let e=d+1;e<u;e++)p.push(e);let h=p.filter(t=>ss(e[t])),g=e[u],x=i6(g),f=x.processBlocks.length>0?sl(g,x.processBlocks,{omitUsage:!0}):null,m=x.answerBlocks.length>0?sl(g,x.answerBlocks):null,v=st(e,t,h,o);if(f&&(v=v.concat(se(g,{messageIndex:u,entryId:t[u],toolResults:o}).processBlocks)),m){let t=[];for(let r=d+1;r<=u;r++){let n=e[r];if(n?.role==="assistant")for(let e of n.content??[])t.push(e)}i=function(e,t,r){let n=new Set,o=[];for(let i of e){if("toolCall"!==i.type||!function(e){let t,r;return"write"===(t=e.toLowerCase())||t.startsWith("write_")||t.endsWith(".write")||t.endsWith("_write")||"edit"===(r=e.toLowerCase())||r.startsWith("edit_")||r.endsWith(".edit")||r.endsWith("_edit")||r.includes("str_replace")||r.includes("replace_editor")}(i.toolName))continue;let e=t?.get(i.toolCallId);if(!e||e.isError)continue;let s=function(e){if(!e)return null;let t=e.file_path??e.path;return"string"==typeof t&&t.length>0?t:null}(i.input);if(!s)continue;let l=function(e,t){let r;if(!e)return null;let n=/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\")||void 0!==t&&(/^[a-zA-Z]:[\\/]/.test(t)||t.startsWith("\\\\")),o=e=>n?e.replace(/\\/g,"/"):e,i=o(e),s=t?o(t).replace(/\/+$/,""):void 0,l=/^[a-zA-Z]:\//.test(i),a=i.startsWith("//");if(l||a)r=i;else if(i.startsWith("/")){let e=s?.match(/^([a-zA-Z]:)(?:\/|$)/)?.[1]??s?.match(/^(\/\/[^/]+\/[^/]+)(?:\/|$)/)?.[1];r=e?`${e}${i}`:i}else{if(!s)return null;r=`${s}/${i}`}return so(r)}(s,r);l&&(n.has(l)||(n.add(l),o.push({filePath:l})))}return o}(t,o,r)}a.push({kind:"turn",userIdx:d,endIdx:c,startsCompactionTurn:l,finalAssistantIdx:u,visibleProcessIndices:h,processBlocks:v,processSegments:i3(v),finalAnswerMessage:m,writtenFiles:i}),n=c}return{toolResultsMap:o,lastUserIdx:i,visibleRefIndexByMessage:s,items:a}})(O,U,ro,B),[O,U,ro,B]),rs=ec?X[`${ec.provider}:${ec.modelId}`]??null:null,rl=ec?Z[`${ec.provider}:${ec.modelId}`]??null:null,ra=(0,o.useCallback)(()=>{et()},[et]),rd=(0,o.useCallback)(e=>{tp(e)},[tp]),rc=e?.relation?.kind==="subagent"?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:"14px 16px",borderTop:"1px solid var(--border)",color:"var(--text-dim)",fontSize:12},children:[(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,n.jsx)("path",{d:"M12 7v4"})]}),E("subagent.readOnlyNotice")]}):(0,n.jsx)(dO,{ref:c,onSend:eF,onBash:eP,tasksBoardEnabled:b,onAbort:eD,onSteer:q?e_:void 0,onFollowUp:q?eq:void 0,onPromptWithStreamingBehavior:q?eK:void 0,isStreaming:q,model:ec,modelNames:Y,modelList:G,modelScopeWarnings:Q,modelsError:ee,onRetryModels:ra,onModelChange:eB,compactResult:ed,toolPreset:er,onToolPresetChange:e||ez?ti:void 0,collaborationMode:td,toolApprovalMode:tc,onCollaborationModeChange:rd,onToolApprovalModeChange:th,goalState:tf,onGoalStart:tm,onGoalPause:tv,onGoalResume:ty,onGoalStop:tb,thinkingLevel:en,onThinkingLevelChange:e||ez?ts:void 0,availableThinkingLevels:rs,thinkingLevelMap:rl,retryInfo:eo,queuedMessages:ex,inputHistory:rt,onRecallQueue:eJ,onMoveQueue:te,onRecallOne:tt,onRequeueAt:tr,onRemoveQueueItem:tn,slashCommands:eh,slashCommandsLoading:eg,onLoadSlashCommands:tl,onBuiltinCommand:to,onAudioUnlock:I,draftKey:e?.id??(t?`new:${t}`:void 0),cwd:e?.cwd??t,topCenterControl:tB?(0,n.jsx)("button",{type:"button",className:"chat-input-top-center",onClick:tq,title:E("desktop.scrollToBottom"),"aria-label":E("desktop.scrollToBottom"),children:(0,n.jsx)(lT.Z,{size:16,weight:"bold","aria-hidden":"true"})}):void 0}),ru=ej.filter(e=>"belowEditor"!==e.placement),rp=ej.filter(e=>"belowEditor"===e.placement),rh=el?E("desktop.compacting"):function(e,t){if(e?.kind==="running_tools"){let r=e.tools.map(e=>e.name);return 0===r.length?t("desktop.runningTool"):t("desktop.runningTools",{tools:r.length<=3?r.join(", "):`${r.slice(0,2).join(", ")} (+${r.length-2})`})}return e?.kind==="waiting_model"?t("desktop.waitingForModel"):e?.kind==="running_command"?t("desktop.runningCommand"):null}(eC,E);return D?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-text-muted",children:E("desktop.loadingSession")}):H?(0,n.jsx)("div",{className:"flex h-full items-center justify-center text-red-400",children:H}):(0,n.jsxs)("div",{className:"relative flex h-full min-w-0 flex-col overflow-hidden",onDragEnter:t3,onDragOver:t8,onDragLeave:t7,onDrop:t9,children:[t5&&(0,n.jsxs)("div",{className:"pointer-events-none absolute inset-0 z-50 flex animate-[drop-zone-in_0.15s_ease_both] items-center justify-center bg-[rgba(37,99,235,0.06)] backdrop-blur-[1px]",children:[(0,n.jsx)("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center",children:[0,.8,1.6].map(e=>(0,n.jsx)("div",{className:"absolute h-[720px] w-[720px] rounded-full border-[1.5px] border-solid border-[rgba(37,99,235,0.5)] animate-[drop-ripple_2.4s_ease-out_infinite_backwards]",style:{transformOrigin:"center",animationDelay:`${e}s`}},e))}),(0,n.jsxs)("svg",{width:"280",height:"280",viewBox:"0 0 140 140",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"drop-shadow-[0_6px_18px_rgba(37,99,235,0.18)]",children:[(0,n.jsx)("rect",{x:"28",y:"44",width:"84",height:"60",rx:"8",fill:"rgba(37,99,235,0.08)",stroke:"rgba(37,99,235,0.50)",strokeWidth:"1.8"}),(0,n.jsx)("path",{d:"M36 100 L54 72 L68 88 L80 74 L104 100Z",fill:"rgba(37,99,235,0.16)",stroke:"rgba(37,99,235,0.40)",strokeWidth:"1.4",strokeLinejoin:"round"}),(0,n.jsx)("circle",{cx:"96",cy:"58",r:"8",fill:"rgba(37,99,235,0.22)",stroke:"rgba(37,99,235,0.55)",strokeWidth:"1.6"}),(0,n.jsxs)("g",{stroke:"rgba(37,99,235,0.45)",strokeWidth:"1.4",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"96",y1:"46",x2:"96",y2:"43"}),(0,n.jsx)("line",{x1:"96",y1:"70",x2:"96",y2:"73"}),(0,n.jsx)("line",{x1:"84",y1:"58",x2:"81",y2:"58"}),(0,n.jsx)("line",{x1:"108",y1:"58",x2:"111",y2:"58"}),(0,n.jsx)("line",{x1:"87.5",y1:"49.5",x2:"85.4",y2:"47.4"}),(0,n.jsx)("line",{x1:"104.5",y1:"66.5",x2:"106.6",y2:"68.6"}),(0,n.jsx)("line",{x1:"104.5",y1:"49.5",x2:"106.6",y2:"47.4"}),(0,n.jsx)("line",{x1:"87.5",y1:"66.5",x2:"85.4",y2:"68.6"})]})]})]}),ey&&(0,n.jsx)(ck,{request:ey,onRespond:ew}),eb&&(0,n.jsx)(cj,{request:eb,onInput:eS}),!ez&&ef.length>0&&!tC&&(0,n.jsx)(d_,{items:ef,sessionId:e?.id,onResolve:eY,onExport:eG,onStageImport:eX,onDismiss:()=>tz(!0),mode:em?"import":"recovery"}),tg.length>0&&(0,n.jsx)(as,{request:tg[0]??null,queuedCount:Math.max(0,tg.length-1),busy:!1,onResolve:(e,t,r)=>{let n=tg[0];n&&tx(n.id,e,t,r)}}),rn?(0,n.jsx)("div",{className:"flex flex-1 flex-col items-center justify-center overflow-y-auto",children:(0,n.jsxs)("div",{className:"w-full max-w-[820px]",children:[(0,n.jsx)("div",{style:{display:"flex",justifyContent:"center",marginBottom:28},children:(0,n.jsxs)("svg",{fill:"currentColor",fillRule:"evenodd",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",style:{width:64,height:64,color:"var(--accent)",opacity:.85},"aria-label":"Pi",children:[(0,n.jsx)("title",{children:"Pi"}),(0,n.jsx)("path",{clipRule:"evenodd",d:"M1 1h16.5v11H12v5.5H6.5V23H1V1zm5.5 5.5V12H12V6.5H6.5z"}),(0,n.jsx)("path",{d:"M17.5 12H23v11h-5.5V12z"})]})}),M&&(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",gap:10,marginBottom:18,marginTop:-14},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.18.4"]})]}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.85.1"]})]})]}),(0,n.jsx)("div",{style:{padding:"0 34px 6px 7px",paddingRight:M?16:34},children:(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:[(0,n.jsx)("div",{ref:m,style:{display:"flex",alignItems:"center",minWidth:0,flex:1,minHeight:48}}),(0,n.jsxs)("div",{style:{display:M?"none":"flex",flexDirection:"column",alignItems:"flex-end",gap:2,flexShrink:0},children:[(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["web ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.18.4"]})]}),(0,n.jsxs)("span",{style:{fontSize:11,color:"var(--text-muted)",fontFamily:"var(--font-mono)"},children:["pi ",(0,n.jsxs)("span",{style:{color:"var(--text)"},children:["v","0.85.1"]})]})]})]})}),(0,n.jsx)("div",{style:{padding:"0 16px",paddingRight:M?16:34},children:(0,n.jsx)(cb,{notices:ev,align:"right"})}),"goal"===td&&(0,n.jsx)(an,{goalState:tf,onPause:tv,onResume:ty,onStop:tb,onEdit:tk}),rc,(0,n.jsx)("div",{style:{padding:"0 16px 6px",paddingRight:M?16:34,marginTop:-15},children:(0,n.jsx)(d1,{onViewFullHistory:v,cwd:ro,systemPrompt:y,sessionStats:eu,contextUsage:ei,hasSession:!!e,showChat:!0,showSoundLabel:!0,soundEnabled:z,onSoundToggle:T,onCompact:e?eU:void 0,onAbortCompaction:eV,isCompacting:el,compactError:ea,lastTurnUsage:tT})})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative flex flex-1 overflow-hidden z-0",children:[(0,n.jsx)("div",{style:{position:"absolute",top:12,left:0,right:18*!M,zIndex:40,padding:"0 16px",pointerEvents:"none"},children:(0,n.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,n.jsx)(cb,{notices:ev,floating:!0,align:"right"})})}),(0,n.jsxs)("div",{className:"relative flex-1 min-h-0 min-w-0",children:[(0,n.jsx)("div",{ref:e$,className:"h-full min-w-0 overflow-x-hidden overflow-y-auto pt-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:(0,n.jsx)("div",{style:{minWidth:0,padding:"0 16px"},children:(0,n.jsxs)("div",{style:{width:"100%",minWidth:0,maxWidth:820,margin:"0 auto"},children:[(0,n.jsxs)("div",{ref:tX,children:[(0,n.jsx)(cv,{statuses:ek}),(0,n.jsx)(cy,{widgets:ru})]}),(()=>{let{toolResultsMap:t,lastUserIdx:r,visibleRefIndexByMessage:o,items:i}=ri,s=tG.current,l=(i,l={})=>{let a=l.messageOverride??O[i];if(!a||"toolResult"===a.role)return null;let d="user"===a.role||"assistant"===a.role,c=o.get(i),u=l.keyPrefix??"message",p=!1;if("assistant"===a.role){p=!0;for(let e=i+1;e<O.length;e++){let t=O[e].role;if("user"===t)break;if("assistant"===t){p=!1;break}}p&&_.isStreaming&&i===O.length-1&&(p=!1)}void 0!==l.showTimestamp&&(p=l.showTimestamp);let h=(0,n.jsx)(lO,{message:a,toolResults:t,modelNames:Y,cwd:ro,onOpenFile:f,entryId:U[i],onFork:q||ez?void 0:eH,forking:es===U[i],onNavigate:q?void 0:eO,onEditContent:A,onQuoteReply:F,onOpenSession:k,onCreateTask:P,showTimestamp:p,prevTimestamp:i>0?O[i-1].timestamp:void 0,sessionId:e?.id??eM.current??void 0,writtenFiles:l.writtenFiles},`${u}-view-${i}`);return d&&!1!==l.attachRef&&void 0!==c?(0,n.jsx)("div",{ref:((e,t)=>{let n=s.get(t);if(!n){let e={isLastUser:!1};n={state:e,callback:r=>{rr.current[t]=r,e.isLastUser&&(eW.current=r,r&&eL.current&&(eL.current=!1,eN.current=!0,eA()))}},s.set(t,n)}return n.state.isLastUser=e===r,n.callback})(i,c),children:h},`${u}-${i}`):h},a=[],d=[],c=[],u=(e,t,r)=>{null!==e&&(a.push(e),d.push(t),c.push(r))},p=(e,t)=>U[e]||`${t}-${e}`,h=e=>`live-answer-u${e}`,g=e=>`answer-${p(e,"user")}`,x=e=>`subagent-${e}`,m=e=>i5(e.result?.details)?e.result.details.sessionId:"",v=(e,t)=>`live-process-u${e}-seg${t}`,y=(e,t,r)=>`process-${p(e,"user")}-${r||`seg${t}`}`;for(let s of i){if("single"===s.kind){if(O[s.idx]?.role==="toolResult")continue;u(l(s.idx),o.get(s.idx),p(s.idx,"single"));continue}let{userIdx:i,endIdx:a,startsCompactionTurn:d,finalAssistantIdx:c}=s;if((q||_.isStreaming)&&a===O.length&&(i===r||d)){i>=0&&u(l(i),o.get(i),p(i,"user"));let r=_.streamingMessage?.role==="assistant",s=[],d=!r&&c>=0?c:a;for(let e=i+1;e<d;e++)ss(O[e])&&s.push(e);let g=st(O,U,s,t),y=null;if(!r&&c>=0){let e=O[c],r=i6(e,{isStreaming:!0}),n=se(e,{messageIndex:c,entryId:U[c],toolResults:t,isStreaming:!0});g=g.concat(n.processBlocks),r.answerBlocks.length>0&&(y=sl(e,r.answerBlocks,{omitUsage:!0}))}if(r){let e=_.streamingMessage,r=i6(e,{isStreaming:!0}),n=se(e,{messageIndex:O.length,toolResults:t,isStreaming:!0});g=g.concat(n.processBlocks),r.answerBlocks.length>0&&(y=sl(e,r.answerBlocks,{omitUsage:!0}))}if(g.length>0){let t=s.map(e=>o.get(e)).find(e=>"number"==typeof e);i3(g).forEach((r,o)=>{"subagent"===r.kind&&r.subagent?u((0,n.jsx)(a2,{run:r.subagent,onOpenSubagent:j,sessionRun:w?.get(m(r.subagent))},x(r.subagent.toolCallId)),t,x(r.subagent.toolCallId)):u((0,n.jsx)("div",{ref:void 0===t?void 0:e=>{rr.current[t]=e},children:(0,n.jsx)(aQ,{blocks:r.blocks,isStreaming:q||_.isStreaming,cwd:ro,onOpenFile:f,sessionId:e?.id??eM.current??void 0,tokenRate:ep})},v(i,o)),t,v(i,o))})}y&&u((0,n.jsx)(lO,{message:y,isStreaming:!0,modelNames:Y,cwd:ro,onOpenFile:f,onQuoteReply:F,onOpenSession:k},`live-answer-${i}`),c>=0?o.get(c):void 0,h(i));continue}if(-1===c&&0===s.processBlocks.length){if(i>=0)for(let e=i;e<a;e++)u(l(e),o.get(e),p(e,"raw"));continue}i>=0&&u(l(i),o.get(i),p(i,"user"));let{finalAnswerMessage:b,writtenFiles:S,visibleProcessIndices:C}=s;if(s.processBlocks.length>0){let t=C.map(e=>o.get(e)).find(e=>"number"==typeof e)??(b?void 0:o.get(c));s.processSegments.forEach((r,o)=>{"subagent"===r.kind&&r.subagent?u((0,n.jsx)(a2,{run:r.subagent,onOpenSubagent:j,sessionRun:w?.get(m(r.subagent))},x(r.subagent.toolCallId)),t,x(r.subagent.toolCallId)):u((0,n.jsx)("div",{ref:void 0===t?void 0:e=>{rr.current[t]=e},children:(0,n.jsx)(aQ,{blocks:r.blocks,isStreaming:!1,defaultExpanded:!1,onAutoExpanded:void 0,cwd:ro,onOpenFile:f,sessionId:e?.id??eM.current??void 0})},`process-group-${i}-${o}`),t,y(i,o,r.blocks[0]?.id??""))})}if(b&&u(l(c,{messageOverride:b,writtenFiles:S}),o.get(c),g(i)),c>=0)for(let e=c+1;e<a;e++)u(l(e),o.get(e),p(e,"tail"))}let b=[],S=d.map((e,t)=>({startRef:e,itemIdx:t})).filter(e=>void 0!==e.startRef);return S.forEach((e,t)=>{let r=S[t+1]?.startRef??re.length;for(let t=e.startRef;t<r;t++)b[t]=e.itemIdx}),tY.current=b,(0,n.jsx)(d6,{scrollElementRef:e$,items:a,itemKeys:c,virtualizerRef:tJ,headerHeight:tZ})})(),rh&&(el||q&&!_.streamingMessage)&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsxs)("span",{className:"animate-[pulse_1.5s_infinite]",children:[rh,eC?.kind==="waiting_model"&&(0,n.jsx)("span",{style:{display:"inline-block",width:12,height:12,marginLeft:6,verticalAlign:"-2px",border:"1.5px solid var(--text-muted)",borderTopColor:"transparent",borderRadius:"50%",animation:"spin 0.6s linear infinite"}})]})}),V&&(0,n.jsx)(lO,{message:{role:"bashExecution",command:V.command,output:"",excludeFromContext:V.excludeFromContext},sessionId:e?.id??eM.current??void 0}),K&&!V&&(0,n.jsx)("div",{className:"py-2 text-[13px] text-text-muted",children:(0,n.jsx)("span",{className:"animate-[pulse_1.5s_infinite]",children:E("desktop.runningShellCommand")})}),(0,n.jsx)("div",{style:{height:96}}),(0,n.jsx)("div",{ref:eE}),(0,n.jsx)(l8,{open:tR,planText:tE,busy:q,onExecute:tL,onFeedback:tA,onExit:tF,onClose:()=>tI(!1)})]})})}),tP&&(0,n.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 z-10 h-8 bg-gradient-to-b from-[var(--bg)] to-transparent"}),tH&&(0,n.jsx)("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8 bg-gradient-to-t from-[var(--bg)] to-transparent"})]}),M?null:(0,n.jsx)(d3,{messages:O,streamingMessage:_.streamingMessage,scrollContainer:e$,messageRefs:rr,virtualizer:t0})]}),(0,n.jsxs)("div",{className:"relative z-10",children:[(0,n.jsx)("div",{style:{padding:"0 16px",paddingRight:M?16:34},children:(0,n.jsx)("div",{style:{maxWidth:820,margin:"0 auto"},children:(0,n.jsx)(cy,{widgets:rp})})}),rc,(0,n.jsx)("div",{className:`session-info-bar-wrap${M?" is-mobile":""}`,children:(0,n.jsx)("div",{className:"session-info-bar-inner",children:(0,n.jsx)(d1,{onViewFullHistory:v,cwd:ro,systemPrompt:y,sessionStats:eu,contextUsage:ei,hasSession:!!e,showChat:!0,soundEnabled:z,onSoundToggle:T,onCompact:e?eU:void 0,onAbortCompaction:eV,isCompacting:el,compactError:ea,branchTree:eT,branchActiveLeafId:eR,onBranchLeafChange:eI,lastTurnUsage:tT})})})]})]})]})}function cv({statuses:e}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:10},children:e.map(e=>(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,maxWidth:"100%",padding:"4px 8px",border:"1px solid color-mix(in srgb, var(--accent) 24%, var(--border))",borderRadius:6,background:"color-mix(in srgb, var(--accent) 7%, var(--bg))",color:"var(--text-muted)",fontSize:12},children:[(0,n.jsx)("span",{style:{color:"var(--accent)",fontFamily:"var(--font-mono)",fontSize:11},children:e.key}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.text})]},e.key))})}function cy({widgets:e}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:10},children:e.map(e=>(0,n.jsxs)("div",{style:{border:"1px solid var(--border)",borderRadius:7,background:"var(--bg-panel)",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"5px 9px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:e.key}),(0,n.jsx)("pre",{style:{margin:0,padding:"8px 9px",color:"var(--text-muted)",fontSize:12,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)"},children:e.lines.join("\n")})]},e.key))})}function cb({notices:e,floating:t=!1,align:r="left"}){return 0===e.length?null:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",alignItems:"right"===r?"flex-end":"stretch",marginBottom:10*!t},children:e.map((r,o)=>{let i="error"===r.type?"var(--status-error)":"warning"===r.type?"var(--status-warning)":"success"===r.type?"#10b981":"var(--accent)";return(0,n.jsxs)("div",{className:"notice-shelf-item",style:{display:"flex",alignItems:"center",gap:10,minHeight:44,maxHeight:180,marginBottom:6*(o!==e.length-1),overflowY:"auto",overflowX:"hidden",borderRadius:14,border:"1px solid color-mix(in srgb, var(--border) 70%, transparent)",background:"var(--bg)",color:"var(--text-muted)",width:"fit-content",maxWidth:"min(100%, 620px)",boxShadow:t?"0 1px 2px rgba(15,23,42,0.05), 0 10px 28px -14px rgba(15,23,42,0.24)":"0 1px 2px rgba(15,23,42,0.04), 0 8px 24px -12px rgba(15,23,42,0.10)",fontSize:13,lineHeight:1.45,transformOrigin:"top center",animation:r.exiting?"notice-shelf-out 0.18s ease-in forwards":"notice-shelf-in 0.18s ease-out both",padding:"0 12px"},children:[(0,n.jsx)("span",{style:{width:7,height:7,borderRadius:"50%",background:i,flexShrink:0}}),(0,n.jsx)("span",{style:{padding:"10px 0",minWidth:0,maxWidth:"100%",overflowWrap:"anywhere",whiteSpace:"pre-wrap"},children:r.message})]},r.id)})})}function ck({request:e,onRespond:t}){let{t:r}=(0,J.s)(),[i,s]=(0,o.useState)("editor"===e.method?e.prefill??"":""),l=(0,o.useCallback)(e=>e?.focus(),[]);(0,o.useEffect)(()=>{s("editor"===e.method?e.prefill??"":"")},[e]);let a=()=>{"confirm"===e.method?t(e,{confirmed:!0}):t(e,{value:i})};return(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:90,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true",style:{width:"min(560px, 100%)",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{padding:"12px 14px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:14,fontWeight:650},children:e.title}),(0,n.jsx)("div",{style:{marginTop:3,color:"var(--text-dim)",fontSize:11,fontFamily:"var(--font-mono)"},children:r("desktop.extensionRequest")})]}),(0,n.jsxs)("div",{style:{padding:14},children:["confirm"===e.method&&(0,n.jsx)(la,{children:e.message}),"select"===e.method&&(0,n.jsx)("div",{onKeyDown:e=>{if(!["ArrowDown","ArrowRight","ArrowUp","ArrowLeft","Home","End"].includes(e.key))return;let t=Array.from(e.currentTarget.querySelectorAll("[data-extension-option]")),r=t.indexOf(e.target);if(r<0)return;e.preventDefault();let n="Home"===e.key?0:"End"===e.key?t.length-1:(r+("ArrowDown"===e.key||"ArrowRight"===e.key?1:-1)+t.length)%t.length;t[n]?.focus()},style:{display:"grid",gap:8},children:e.options.map((r,o)=>(0,n.jsx)("div",{role:"button",tabIndex:0,"data-extension-option":!0,"aria-label":r,ref:0===o?l:void 0,onClick:()=>t(e,{value:r}),onKeyDown:n=>{("Enter"===n.key||" "===n.key)&&(n.preventDefault(),t(e,{value:r}))},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",cursor:"pointer",textAlign:"left",fontSize:13},children:(0,n.jsx)("div",{inert:!0,children:(0,n.jsx)(la,{children:r})})},r))}),"input"===e.method&&(0,n.jsx)("input",{autoFocus:!0,className:"extension-input",value:i,placeholder:e.placeholder,onChange:e=>s(e.target.value),onKeyDown:r=>{"Enter"===r.key&&a(),"Escape"===r.key&&t(e,{cancelled:!0})},style:{width:"100%",padding:"9px 10px",borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",fontSize:13}}),"editor"===e.method&&(0,n.jsx)("textarea",{autoFocus:!0,value:i,onChange:e=>s(e.target.value),onKeyDown:r=>{"Escape"===r.key&&t(e,{cancelled:!0}),(r.metaKey||r.ctrlKey)&&"Enter"===r.key&&a()},style:{width:"100%",minHeight:220,padding:10,borderRadius:7,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text)",outline:"none",resize:"vertical",fontSize:13,lineHeight:1.55,fontFamily:"var(--font-mono)"}})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 14px",borderTop:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("button",{onClick:()=>t(e,{cancelled:!0}),style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg)",color:"var(--text-muted)",cursor:"pointer"},children:r("desktop.cancel")}),"confirm"===e.method?(0,n.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"var(--accent-fg)",cursor:"pointer"},children:r("desktop.confirm")}):"select"!==e.method?(0,n.jsx)("button",{onClick:a,style:{padding:"6px 10px",borderRadius:6,border:"1px solid var(--accent)",background:"var(--accent)",color:"var(--accent-fg)",cursor:"pointer"},children:r("desktop.submit")}):null]})]})})}function cj({request:e,onInput:t}){let{t:r}=(0,J.s)(),i=(0,o.useRef)(null),s=function(e){let t=/^[┌├└╭╰][─┬┴┼]+[┐┤┘╮╯]$/,r=[];for(let n of e){let e=iX(n).trimEnd();if(t.test(e))continue;let o=n,i=i0(o);("│"===i||"┃"===i)&&" "===i0(o=iQ(o,0))&&(o=iQ(o,0));let s=function(e){let t=iZ(e);for(let e=t.length-1;e>=0;e--)if(""!==t[e].char.trim())return e;return -1}(o),l=s>=0?iZ(o)[s]?.char:void 0;("│"===l||"┃"===l)&&(o=iQ(o,s)),r.push(function(e){let t=e;for(;;){let e=iZ(t),r=e[e.length-1];if(!r||""!==r.char.trim())return t;t=t.slice(0,r.start)+t.slice(r.end)}}(o))}for(;r.length>0&&""===iX(r[0]).trim();)r.shift();for(;r.length>0&&""===iX(r[r.length-1]).trim();)r.pop();return r.length?r:e}(e.lines);return(0,o.useEffect)(()=>{i.current?.focus()},[e.id]),(0,n.jsx)("div",{style:{position:"absolute",inset:0,zIndex:95,display:"flex",alignItems:"center",justifyContent:"center",padding:20,background:"rgba(0,0,0,0.18)"},children:(0,n.jsxs)("div",{ref:i,tabIndex:0,role:"dialog","aria-modal":"true",onKeyDown:r=>{let n=function(e){if(e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length){let t=e.key.toLowerCase();if(t>="a"&&t<="z")return String.fromCharCode(t.charCodeAt(0)-96)}switch(e.key){case"ArrowUp":return"\x1b[A";case"ArrowDown":return"\x1b[B";case"ArrowRight":return"\x1b[C";case"ArrowLeft":return"\x1b[D";case"Enter":return"\r";case"Escape":return"\x1b";case"Backspace":return"";case"Tab":return" ";case" ":return" ";default:if(!e.ctrlKey&&!e.metaKey&&!e.altKey&&1===e.key.length)return e.key;return null}}(r);n&&(r.preventDefault(),r.stopPropagation(),t(e,n))},style:{width:"min(920px, 100%)",maxHeight:"min(760px, calc(100vh - 40px))",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg)",boxShadow:"0 20px 60px rgba(0,0,0,0.28)",overflow:"hidden",outline:"none"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("div",{style:{color:"var(--text)",fontSize:13,fontWeight:650},children:r("desktop.extensionPanel")}),(0,n.jsx)("button",{onClick:()=>t(e,"\x03"),style:{padding:"5px 9px",borderRadius:6,border:"1px solid var(--border)",background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer",fontSize:12},children:r("desktop.close")})]}),(0,n.jsx)("pre",{style:{margin:0,padding:14,maxHeight:"calc(min(760px, 100vh - 40px) - 48px)",overflow:"auto",background:"var(--bg-panel)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.45,whiteSpace:"pre"},children:(s.length?s:[""]).map((e,t,r)=>{var i;return(0,n.jsxs)(o.Fragment,{children:[(i=`line-${t}`,(function(e){let t,r=[],n={},o=0;for(iJ.lastIndex=0;null!==(t=iJ.exec(e));)t.index>o&&r.push({text:e.slice(o,t.index),style:n}),n=function(e,t){let r={...e};for(let e=0;e<t.length;e++){let n=t[e];if(0===n)for(let e of Object.keys(r))delete r[e];else if(1===n)r.fontWeight=700;else if(2===n)r.opacity=.65;else if(3===n)r.fontStyle="italic";else if(4===n)r.textDecoration="underline";else if(22===n)delete r.fontWeight,delete r.opacity;else if(23===n)delete r.fontStyle;else if(24===n)delete r.textDecoration;else if(39===n)delete r.color;else if(49===n)delete r.backgroundColor;else if(n>=30&&n<=37)r.color=iY[n-30];else if(n>=90&&n<=97)r.color=iG[n-90];else if(n>=40&&n<=47)r.backgroundColor=iY[n-40];else if(n>=100&&n<=107)r.backgroundColor=iG[n-100];else if((38===n||48===n)&&2===t[e+1]){let[o,i,s]=[t[e+2],t[e+3],t[e+4]];[o,i,s].every(e=>"number"==typeof e&&Number.isFinite(e))&&(38===n?r.color=`rgb(${o}, ${i}, ${s})`:r.backgroundColor=`rgb(${o}, ${i}, ${s})`),e+=4}else if((38===n||48===n)&&5===t[e+1]){let o=function(e){if(e>=0&&e<8)return iY[e];if(e>=8&&e<16)return iG[e-8];if(e>=16&&e<=231){let t=e-16,r=Math.floor(t/36),n=Math.floor(t%36/6),o=e=>0===e?0:55+40*e;return`rgb(${o(r)}, ${o(n)}, ${o(t%6)})`}if(e>=232&&e<=255){let t=8+(e-232)*10;return`rgb(${t}, ${t}, ${t})`}}(t[e+2]);o&&(38===n?r.color=o:r.backgroundColor=o),e+=2}}return r}(n,t[1]?t[1].split(";").map(e=>Number(e||"0")):[0]),o=t.index+t[0].length;return o<e.length&&r.push({text:e.slice(o),style:n}),r})(e).map((e,t)=>Object.keys(e.style).length>0?(0,n.jsx)("span",{style:e.style,children:e.text},`${i}-${t}`):e.text)),t<r.length-1?"\n":null]},t)})})]})})}var cw=r(93549);let cS={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",bmp:"image/bmp",ico:"image/x-icon",avif:"image/avif"},cC={mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",oga:"audio/ogg",opus:"audio/ogg",m4a:"audio/mp4",aac:"audio/aac",flac:"audio/flac",weba:"audio/webm"};function cz(e){return(e.replace(/\\/g,"/").split("/").pop()??"").toLowerCase().split(".").pop()??""}function cT(e){let t=e.nodeType===Node.ELEMENT_NODE?e:e.parentElement;return t?.closest(".file-source-line[data-line-number]")??null}function cR(e,t){if(!t||t.isCollapsed||0===t.rangeCount)return null;let r=t.getRangeAt(0);if(!e.contains(r.startContainer)||!e.contains(r.endContainer))return null;let n=Number(cT(r.startContainer)?.dataset.lineNumber),o=Number(cT(r.endContainer)?.dataset.lineNumber);return Number.isInteger(n)&&Number.isInteger(o)?n<=o?{startLine:n,endLine:o}:{startLine:o,endLine:n}:null}function cI(e,t,r,n={}){let o=ob(e),i=new URLSearchParams({type:t});for(let[e,t]of(r&&i.set("sessionId",r),Object.entries(n)))void 0!==t&&i.set(e,String(t));return`/api/files/${o}?${i.toString()}`}function cM({filePath:e,sourceSessionId:t}){let{t:r}=(0,J.s)();return(0,n.jsx)("a",{href:cI(e,"download",t),download:ok(e),title:r("desktop.downloadFile"),style:{display:"flex",alignItems:"center",justifyContent:"center",height:20,padding:"0 5px",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:4,color:"var(--text-muted)",cursor:"pointer",flexShrink:0,textDecoration:"none"},children:(0,n.jsx)(I.z,{size:11,"aria-hidden":"true"})})}let cE={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,tabSize:2},c$={fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,padding:"12px 0 12px 16px",color:"var(--text-dim)",textAlign:"right",userSelect:"none"};async function cW(e,t){let r=await fetch(`/api/files/${ob(e)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t})});if(!r.ok)throw Error((await r.json().catch(()=>({}))).error??`HTTP ${r.status}`);let n=await r.json();return"number"==typeof n.size?n.size:0}let cL={delete:"3px solid var(--git-status-deleted)",add:"3px solid var(--git-status-added)",edit:"3px solid var(--git-status-modified)"},cN="var(--git-status-deleted-bg)",cA="var(--git-status-added-bg)",cF="var(--git-status-added)";function cP(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function cD({oldContent:e,newContent:t}){let{t:r}=(0,J.s)(),o=function(e,t){let r=e.length,n=t.length,o=r+n,i=Array(2*o+1).fill(0),s=[];for(let l=0;l<=o;l++){s.push([...i]);for(let a=-l;a<=l;a+=2){let d,c=(d=a===-l||a!==l&&i[a-1+o]<i[a+1+o]?i[a+1+o]:i[a-1+o]+1)-a;for(;d<r&&c<n&&e[d]===t[c];)d++,c++;if(i[a+o]=d,d>=r&&c>=n){let i=[],a=r,d=n;for(let r=l;r>0;r--){let n,l=s[r-1],c=a-d;n=c===-r||c!==r&&l[c-1+o]<l[c+1+o]?c+1:c-1;let u=l[n+o],p=u-n;for(;a>u&&d>p;)a--,d--,i.unshift({type:"unchanged",text:e[a]});r>0&&(a>u?(a--,i.unshift({type:"removed",text:e[a]})):(d--,i.unshift({type:"added",text:t[d]})))}for(;a>0&&d>0;)a--,d--,i.unshift({type:"unchanged",text:e[a]});return i}}}return[...e.map(e=>({type:"removed",text:e})),...t.map(e=>({type:"added",text:e}))]}(e.split("\n"),t.split("\n"));if(!o.some(e=>"unchanged"!==e.type))return(0,n.jsx)("div",{style:{padding:"12px 16px",fontSize:12,color:"var(--text-dim)",fontFamily:"var(--font-mono)"},children:r("desktop.noChanges")});let i=new Set(o.flatMap((e,t)=>"unchanged"!==e.type?[t]:[])),s=new Set;for(let e of i)for(let t=Math.max(0,e-3);t<=Math.min(o.length-1,e+3);t++)s.add(t);let l=[],a=0;for(;a<o.length;)if(s.has(a)){let e=[];for(;a<o.length&&s.has(a);)e.push(o[a]),a++;l.push({hidden:!1,lines:e})}else{let e=0;for(;a<o.length&&!s.has(a);)e++,a++;l.push({hidden:!0,count:e})}let d=[],c=1;for(let e of o)"removed"===e.type?d.push(0):d.push(c++);let u=0;return(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:13,lineHeight:1.6,minWidth:"max-content"},children:l.map((e,t)=>{if(e.hidden){let o=(0,n.jsx)("div",{style:{padding:"2px 16px",color:"var(--text-dim)",background:"var(--bg-panel)",fontSize:11,borderTop:"1px solid var(--border)",borderBottom:"1px solid var(--border)"},children:r("desktop.unchangedLines",{count:e.count})},t);return u+=e.count,o}let o=[],i=[],s=[],l=()=>{if(i.length||s.length){let e=i.length&&s.length?"edit":i.length?"delete":"add";for(let t of i)o.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of s)o.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});i=[],s=[]}};e.lines.forEach((e,r)=>{"unchanged"===e.type?(l(),o.push({key:`${t}:${r}`,kind:"context",text:e.text,lineNo:d[u+r],block:null})):"removed"===e.type?i.push({key:`${t}:${r}`,text:e.text}):s.push({key:`${t}:${r}`,text:e.text,lineNo:d[u+r]})}),l();let a=o.map(e=>{let t="removed"===e.kind?cN:"added"===e.kind?cA:"transparent",r=e.block?cL[e.block]:"3px solid transparent",o="added"===e.kind?cF:"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",background:t,borderLeft:r},children:[(0,n.jsx)("span",{style:{minWidth:44,padding:"0 8px 0 16px",textAlign:"right",color:o,userSelect:"none",fontSize:11,lineHeight:1.6,flexShrink:0},children:e.lineNo??""}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)});return u+=e.lines.length,(0,n.jsx)("div",{children:a},t)})})}function cH({patch:e}){let t=lk(e);if(!t)return null;let r=[],o=[],i=[],s=()=>{if(o.length||i.length){let e=o.length&&i.length?"edit":o.length?"delete":"add";for(let t of o)r.push({key:t.key,kind:"removed",text:t.text,lineNo:null,block:e});for(let t of i)r.push({key:t.key,kind:"added",text:t.text,lineNo:t.lineNo,block:e});o=[],i=[]}};return t.forEach((e,t)=>{e.rows.forEach((e,n)=>{if("hunk"===e.type){s(),r.push({key:`${t}:${n}:h`,kind:"hunk",text:e.text,lineNo:null,block:null});return}let{left:l,right:a}=e;if("context"===l.type&&"context"===a.type){s(),r.push({key:`${t}:${n}:c`,kind:"context",text:l.text,lineNo:a.lineNo,block:null});return}"removed"===l.type&&o.push({key:`${t}:${n}:l`,text:l.text}),"added"===a.type&&i.push({key:`${t}:${n}:r`,text:a.text,lineNo:a.lineNo})})}),s(),(0,n.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,minWidth:"max-content"},children:r.map(e=>{if("hunk"===e.kind)return(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{style:{height:"1.55em"}}),(0,n.jsx)("div",{style:{padding:"3px 12px",color:"var(--accent-blue)",background:"var(--bg-secondary)"},children:e.text}),(0,n.jsx)("div",{style:{height:"1.55em"}})]},e.key);let t="removed"===e.kind?cN:"added"===e.kind?cA:"transparent",r=e.block?cL[e.block]:"3px solid transparent",o="added"===e.kind?cF:"var(--text-dim)";return(0,n.jsxs)("div",{style:{display:"flex",background:t,borderLeft:r},children:[(0,n.jsx)("span",{style:{width:44,flexShrink:0,padding:"0 8px 0 16px",textAlign:"right",color:o,userSelect:"none",fontSize:11},children:e.lineNo??""}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,padding:"0 8px 0 0",whiteSpace:"pre",color:"var(--text)"},children:e.text||"\xa0"})]},e.key)})})}function cO({filePath:e,cwd:t,sourceSessionId:r}){let{t:i}=(0,J.s)(),[s,l]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),g=(0,o.useRef)(null),x=ok(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{l(0),d(null),u(null),h(null),g.current&&(g.current.close(),g.current=null);let t=new EventSource(cI(e,"watch",r));return g.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}l(e=>e+1)}),()=>{t.close(),g.current=null}},[e,r]);let f=cI(e,"read",r,s?{v:s}:void 0),m=null!=a?cP(a):null;return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-status-bar",style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,flexWrap:"wrap",rowGap:4},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 1 auto"},title:e,children:oj(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:x||i("desktop.image")}),c&&(0,n.jsxs)("span",{children:[c.w," \xd7 ",c.h]}),m&&(0,n.jsx)("span",{children:m}),(0,n.jsx)(cM,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg-panel)",display:"flex",alignItems:"center",justifyContent:"center",padding:16,backgroundImage:"linear-gradient(45deg, var(--bg) 25%, transparent 25%), linear-gradient(-45deg, var(--bg) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bg) 75%), linear-gradient(-45deg, transparent 75%, var(--bg) 75%)",backgroundSize:"16px 16px",backgroundPosition:"0 0, 0 8px, 8px -8px, -8px 0px"},children:p?(0,n.jsx)("div",{style:{color:"var(--status-error)",fontSize:13},children:p}):(0,n.jsx)("img",{src:f,alt:e,onLoad:e=>{let t=e.currentTarget;u({w:t.naturalWidth,h:t.naturalHeight})},onError:()=>h(i("desktop.failedToLoadImage")),style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"}})})]})}function cB({filePath:e,cwd:t,sourceSessionId:r}){let{t:i}=(0,J.s)(),[s,l]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),g=(0,o.useRef)(null),x=ok(e).toLowerCase().split(".").pop()??"";(0,o.useEffect)(()=>{l(0),d(null),u(null),h(null),g.current&&(g.current.close(),g.current=null);let t=new EventSource(cI(e,"watch",r));return g.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);"number"==typeof t.size&&d(t.size)}catch{}u(null),h(null),l(e=>e+1)}),()=>{t.close(),g.current=null}},[e,r]);let f=cI(e,"read",r,s?{v:s}:void 0);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-status-bar",style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,flexWrap:"wrap",rowGap:4},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 1 auto"},title:e,children:oj(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:x||i("desktop.audio")}),null!=c&&(0,n.jsx)("span",{children:function(e){if(!Number.isFinite(e))return"";let t=Math.round(e),r=Math.floor(t/60);return`${r}:${String(t%60).padStart(2,"0")}`}(c)}),null!=a&&(0,n.jsx)("span",{children:cP(a)}),(0,n.jsx)(cM,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24,background:"var(--bg-panel)"},children:(0,n.jsxs)("div",{style:{width:"min(680px, 100%)"},children:[p&&(0,n.jsx)("div",{style:{color:"var(--status-error)",fontSize:13,marginBottom:12,textAlign:"center"},children:p}),(0,n.jsx)("audio",{controls:!0,preload:"metadata",src:f,onLoadedMetadata:e=>u(e.currentTarget.duration),onError:()=>h(i("desktop.failedToLoadAudio")),style:{width:"100%"}},f)]})})]})}function cU({filePath:e,cwd:t,sourceSessionId:r}){let{t:i}=(0,J.s)(),[s,l]=(0,o.useState)(0),[a,d]=(0,o.useState)(null),[c,u]=(0,o.useState)(null),p=(0,o.useRef)(null),h=cz(e),g="pdf"===h,x=g?cI(e,"read",r,s?{v:s}:void 0):cI(e,"preview",r,s?{v:s}:void 0);return(0,o.useEffect)(()=>{l(0),d(null),u(null),p.current&&(p.current.close(),p.current=null),fetch(cI(e,"meta",r)).then(e=>e.json()).then(e=>{e.error&&u(e.error),"number"==typeof e.size&&(d(e.size),!g&&e.size>0xa00000&&u(i("desktop.docxTooLargeForPreview")))}).catch(e=>u(String(e)));let t=new EventSource(cI(e,"watch",r));return p.current=t,t.addEventListener("change",e=>{try{let t=JSON.parse(e.data);if("number"==typeof t.size&&(d(t.size),!g&&t.size>0xa00000))return void u(i("desktop.docxTooLargeForPreview"))}catch{}u(null),l(e=>e+1)}),()=>{t.close(),p.current=null}},[e,g,r,i]),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-status-bar",style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,flexWrap:"wrap",rowGap:4},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:oj(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:"docx"===h?i("desktop.docxPreview"):"pdf"}),null!=a&&(0,n.jsx)("span",{children:cP(a)}),(0,n.jsx)(cM,{filePath:e,sourceSessionId:r})]}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,background:"var(--bg-panel)"},children:c?(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",padding:24,color:"var(--status-error)",fontSize:13,textAlign:"center"},children:c}):(0,n.jsx)("iframe",{src:x,sandbox:g?void 0:"allow-same-origin",title:i("desktop.previewFile",{file:ok(e)}),style:{width:"100%",height:"100%",border:"none",background:g?"var(--bg)":"#eef1f5"}},x)})]})}function c_({filePath:e,cwd:t,sourceSessionId:r,onOpenFile:o,onAtMention:i,onMentionLines:s,initialDisplayMode:l,onFileSaved:a}){let d;return null!==(cS[cz(e)]??null)?(0,n.jsx)(cO,{filePath:e,cwd:t,sourceSessionId:r}):null!==(cC[cz(e)]??null)?(0,n.jsx)(cB,{filePath:e,cwd:t,sourceSessionId:r}):null!==("pdf"===(d=cz(e))||"docx"===d?d:null)?(0,n.jsx)(cU,{filePath:e,cwd:t,sourceSessionId:r}):(0,n.jsx)(cq,{filePath:e,cwd:t,sourceSessionId:r,onOpenFile:o,onAtMention:i,onMentionLines:s,initialDisplayMode:l,onFileSaved:a})}function cq({filePath:e,cwd:t,sourceSessionId:r,onOpenFile:i,onAtMention:s,onMentionLines:l,initialDisplayMode:a,onFileSaved:d}){let c,u,{t:p}=(0,J.s)(),[g,x]=(0,o.useState)(null),[m,v]=(0,o.useState)(null),[y,b]=(0,o.useState)(null),[k,j]=(0,o.useState)(!0),[w,S]=(0,o.useState)(!1),[C,z]=(0,o.useState)(null),[T,R]=(0,o.useState)(!1),[I,M]=(0,o.useState)("source"),[E,$]=(0,o.useState)(!1),[W,L]=(0,o.useState)(0),[N,A]=(0,o.useState)(null),F=(0,o.useRef)(null),P=(0,o.useRef)(null),[D,H]=(0,o.useState)(!1),[O,B]=(0,o.useState)(""),[U,_]=(0,o.useState)(""),[q,K]=(0,o.useState)(!1),[V,Y]=(0,o.useState)(null),[G,X]=(0,o.useState)(!1),Z=(0,o.useRef)(null),Q=(0,o.useRef)(null),ee=(0,o.useRef)(0),et=(0,o.useRef)(!1);(0,o.useEffect)(()=>{et.current=D},[D]);let er=D&&O!==U,en=!!(g?.content&&g.content.includes("\0")),eo=(0,o.useCallback)(async e=>{if(!t)return void b(null);try{let r=new URLSearchParams({cwd:t,path:e}),n=await fetch(`/api/git/diff?${r.toString()}`),o=await n.json();b(n.ok&&o.supported&&"string"==typeof o.patch?o:null)}catch{b(null)}},[t]),ei=(0,o.useCallback)((e,t=!1,n=0)=>fetch(cI(e,"read",r,n?{offset:n}:void 0)).then(e=>e.json()).then(e=>e.error?(z(e.error),null):(t?(x(t=>(t&&v(t.content),e)),L(e=>e+1)):n?x(t=>t?{...e,content:t.content+e.content}:e):x(e),e)).catch(e=>(z(String(e)),null)),[r]);(0,o.useEffect)(()=>{j(!0),z(null),x(null),v(null),b(null),R(!1),M("source"),$(!1),L(0),H(!1),B(""),_(""),Y(null),X(!1),K(!1),F.current&&(F.current.close(),F.current=null),ei(e).then(e=>{e?.truncated||e?.language!=="markdown"&&e?.language!=="html"||"diff"===a||R(!0)}).finally(()=>j(!1)),eo(e);let t=new EventSource(cI(e,"watch",r));return F.current=t,t.addEventListener("change",()=>{et.current?X(!0):(ei(e,!0),eo(e))}),()=>{t.close(),F.current=null}},[e,ei,eo,a,r]);let es=(0,o.useCallback)(()=>{g&&!en&&(B(g.content),_(g.content),Y(null),X(!1),H(!0))},[g,en]),el=(0,o.useCallback)(()=>{H(!1),B(""),_(""),Y(null),X(!1)},[]),ea=(0,o.useCallback)(()=>{(!er||window.confirm(p("files.unsavedChanges")))&&el()},[er,el,p]),ed=(0,o.useCallback)(async()=>{if(!g||q)return;let t=++ee.current;K(!0),Y(null);try{let r=await cW(e,O);if(t!==ee.current)return;x(e=>e?{...e,content:O,size:r}:e),_(O),K(!1),el(),eo(e),d?.()}catch(e){if(t!==ee.current)return;Y(e instanceof Error?e.message:String(e)),K(!1)}},[g,q,O,e,el,eo,d]);(0,o.useEffect)(()=>{if(!D)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"s"===e.key.toLowerCase()){e.preventDefault(),ed();return}"Escape"===e.key&&(e.preventDefault(),ea())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[D,ed,ea]),(0,o.useEffect)(()=>{if(!er)return;let e=e=>{e.preventDefault(),e.returnValue=""};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[er]);let ec=(0,o.useCallback)(()=>{let e=Z.current,t=Q.current;e&&t&&(t.scrollTop=e.scrollTop)},[]),eu=(0,o.useCallback)(e=>{if("Tab"!==e.key||e.metaKey||e.ctrlKey||e.altKey)return;e.preventDefault();let t=e.currentTarget,{selectionStart:r,selectionEnd:n}=t;B(t.value.slice(0,r)+" "+t.value.slice(n)),requestAnimationFrame(()=>{let e=Z.current;if(!e)return;let t=r+2;e.selectionStart=t,e.selectionEnd=t})},[]),ep=(0,o.useMemo)(()=>s0(g?.content??""),[g?.content]),eh=y?.supported===!0&&"string"==typeof y.patch;(0,o.useEffect)(()=>{"diff"===a&&eh&&M("diff")},[eh,a]);let eg=eh&&y?.status==="deleted",ex=(0,o.useCallback)(r=>{l&&r&&l(oj(e,t),r.startLine,r.endLine)},[t,e,l]);if((0,o.useEffect)(()=>{let e=()=>{let e=P.current,t="source"===I&&!T;A(l&&t&&e?cR(e,window.getSelection()):null)};if(e(),l&&"source"===I&&!T)return document.addEventListener("selectionchange",e),()=>document.removeEventListener("selectionchange",e)},[g?.content,l,T,I]),(0,o.useEffect)(()=>{if(!l||"source"!==I||T)return;let e=e=>{if(e.repeat||"i"!==e.key.toLowerCase()||!e.metaKey&&!e.ctrlKey||e.altKey||e.shiftKey)return;let t=e.target;if(t instanceof Element&&t.closest("input, textarea, [contenteditable='true']"))return;let r=P.current,n=r?cR(r,window.getSelection()):null;n&&(e.preventDefault(),ex(n))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ex,l,T,I]),k)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-muted)",fontSize:13},children:p("desktop.loadingFile")});if(eg&&!g)return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsx)("div",{style:{padding:"5px 16px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontFamily:"var(--font-mono)",fontSize:11},title:e,children:oj(e,t)}),(0,n.jsx)("div",{style:{flex:1,overflow:"auto",background:"var(--bg)"},children:(0,n.jsx)(cH,{patch:y.patch})})]});if(C)return(0,n.jsx)("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--status-error)",fontSize:13},children:C});if(!g)return null;let ef="html"===g.language,em="markdown"===g.language,ev=(u=(c=oy(e).replace(/\/+$/,"")).lastIndexOf("/"))<0?"":0===u?"/":2===u&&/^[a-zA-Z]:\//.test(c)?c.slice(0,3):c.slice(0,u),ey=g.content.split("\n"),eb=null!==m&&m!==g.content||eh,ek=!eg&&!en&&oC();return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[(0,n.jsxs)("div",{className:"file-viewer-status-bar",style:{display:"flex",alignItems:"center",gap:12,padding:"4px 16px",borderBottom:"1px solid var(--border)",fontSize:11,color:"var(--text-dim)",background:"var(--bg)",flexShrink:0,flexWrap:"wrap",rowGap:4},children:[(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:"0 1 auto"},title:e,children:oj(e,t)}),(0,n.jsx)("span",{style:{marginLeft:"auto"},children:g.language}),"source"===I&&!D&&(0,n.jsx)("span",{children:p("desktop.lines",{count:ey.length})}),(0,n.jsx)("span",{children:cP(g.size)}),eb&&!D&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>M("source"),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:"source"===I?"var(--bg-selected)":"var(--bg-hover)",color:"source"===I?"var(--text)":"var(--text-muted)",fontWeight:"source"===I?600:400},children:p("desktop.source")}),(0,n.jsxs)("button",{onClick:()=>M("diff"),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:"diff"===I?"var(--bg-selected)":"var(--bg-hover)",color:"diff"===I?"var(--text)":"var(--text-muted)",fontWeight:"diff"===I?600:400},children:[p("desktop.diff")," ",W>0&&(0,n.jsxs)("span",{style:{color:"var(--git-status-added)",marginLeft:2},children:["+",W]})]})]}),"source"===I&&!T&&!D&&(0,n.jsx)("button",{onClick:()=>$(e=>!e),title:E?p("desktop.disableWordWrap"):p("desktop.enableWordWrap"),style:{padding:"2px 8px",fontSize:11,cursor:"pointer",background:E?"var(--bg-selected)":"var(--bg-hover)",color:E?"var(--text)":"var(--text-muted)",border:"1px solid var(--border)",borderRadius:5,fontWeight:E?600:400},children:p("desktop.wrap")}),ef&&"source"===I&&!D&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>R(!1),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:T?"var(--bg-hover)":"var(--bg-selected)",color:T?"var(--text-muted)":"var(--text)",fontWeight:T?400:600},children:p("desktop.code")}),(0,n.jsx)("button",{onClick:()=>R(!0),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:T?"var(--bg-selected)":"var(--bg-hover)",color:T?"var(--text)":"var(--text-muted)",fontWeight:T?600:400},children:p("desktop.preview")})]}),em&&"source"===I&&!D&&(0,n.jsxs)("div",{style:{display:"flex",borderRadius:5,overflow:"hidden",border:"1px solid var(--border)"},children:[(0,n.jsx)("button",{onClick:()=>R(!0),style:{padding:"2px 8px",fontSize:11,border:"none",cursor:"pointer",background:T?"var(--bg-selected)":"var(--bg-hover)",color:T?"var(--text)":"var(--text-muted)",fontWeight:T?600:400},children:p("desktop.preview")}),(0,n.jsx)("button",{onClick:()=>R(!1),style:{padding:"2px 8px",fontSize:11,border:"none",borderLeft:"1px solid var(--border)",cursor:"pointer",background:T?"var(--bg-hover)":"var(--bg-selected)",color:T?"var(--text-muted)":"var(--text)",fontWeight:T?400:600},children:p("desktop.raw")})]}),D?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>void ed(),disabled:q,title:p("files.saveHint"),"aria-label":p("files.save"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-selected)",color:"var(--text)",cursor:"pointer"},children:(0,n.jsx)(cw.g,{size:13,"aria-hidden":"true"})}),(0,n.jsx)("button",{type:"button",onClick:ea,disabled:q,title:p("files.cancelEdit"),"aria-label":p("files.cancelEdit"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,n.jsx)(h.X,{size:13,"aria-hidden":"true"})})]}):"source"===I&&ek?(0,n.jsx)("button",{type:"button",onClick:es,title:p("files.edit"),"aria-label":p("files.edit"),style:{height:20,minWidth:20,padding:"0 5px",display:"inline-flex",alignItems:"center",justifyContent:"center",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:(0,n.jsx)(f.I,{size:13,"aria-hidden":"true"})}):null,(s||l)&&!D&&(0,n.jsx)("button",{type:"button",onPointerDown:e=>e.preventDefault(),onClick:()=>{N&&l?ex(N):s?.(oj(e,t),!1)},title:N?p("desktop.mentionSelectedLines",{start:N.startLine,end:N.endLine}):p("desktop.mentionFile"),"aria-label":N?p("desktop.mentionSelectedLines",{start:N.startLine,end:N.endLine}):p("desktop.mentionFile"),style:{height:20,minWidth:20,padding:"0 5px",border:"1px solid var(--border)",borderRadius:4,background:"var(--bg-panel)",color:"var(--text-muted)",cursor:"pointer"},children:"@"}),!D&&(0,n.jsx)(cM,{filePath:e,sourceSessionId:r})]}),g?.truncated&&"source"===I&&!D&&(0,n.jsxs)("div",{className:"file-viewer-load-more",style:{display:"flex",alignItems:"center",justifyContent:"center",gap:10,padding:"5px 8px",borderBottom:"1px solid var(--border)",color:"var(--text-dim)",fontSize:11},children:[(0,n.jsxs)("span",{children:[cP(g.nextOffset)," / ",cP(g.size)]}),(0,n.jsx)("button",{type:"button",disabled:w,onClick:()=>{S(!0),ei(e,!1,g.nextOffset).finally(()=>S(!1))},style:{padding:"2px 10px",fontSize:11,cursor:"pointer",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg-hover)",color:"var(--text)",opacity:w?.6:1},children:w?p("i18n.loading"):p("i18n.loadMore")})]}),(0,n.jsx)("div",{ref:P,style:{flex:1,overflow:"auto",background:"var(--bg)"},children:D?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[G&&(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"5px 12px",borderBottom:"1px solid var(--border)",background:"rgba(214,168,75,0.14)",color:"#d6a84b",fontSize:11,flexShrink:0},children:[(0,n.jsx)("span",{style:{flex:1},children:p("files.externalModified")}),(0,n.jsx)("button",{type:"button",onClick:()=>{(!er||window.confirm(p("files.reloadOverwriteConfirm")))&&ei(e).then(e=>{e&&(B(e.content),_(e.content),X(!1))})},disabled:q,style:{padding:"2px 8px",fontSize:11,border:"1px solid #d6a84b",borderRadius:4,background:"transparent",color:"#d6a84b",cursor:"pointer"},children:p("files.reload")})]}),V&&(0,n.jsx)("div",{style:{padding:"5px 12px",borderBottom:"1px solid var(--border)",background:"rgba(248,113,113,0.14)",color:"var(--status-error)",fontSize:11,flexShrink:0},children:p("files.saveFailed",{error:V})}),(0,n.jsxs)("div",{style:{flex:1,display:"flex",overflow:"hidden"},children:[(0,n.jsx)("div",{ref:Q,"aria-hidden":"true",style:{...c$,height:"100%",overflow:"hidden",whiteSpace:"pre",pointerEvents:"none"},children:O.split("\n").map((e,t)=>`${t+1}
|
|
195
|
+
`).join("")}),(0,n.jsx)("textarea",{ref:Z,className:"file-editor-textarea",value:O,onChange:e=>B(e.target.value),onScroll:ec,onKeyDown:eu,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",wrap:"off",style:{flex:1,height:"100%",resize:"none",border:"none",outline:"none",background:"var(--bg)",color:"var(--text)",...cE,whiteSpace:"pre",overflow:"auto",padding:0,tabSize:2}})]})]}):"diff"===I&&eb?eh?(0,n.jsx)(cH,{patch:y.patch}):(0,n.jsx)(cD,{oldContent:m,newContent:g.content}):ef&&T?(0,n.jsx)("iframe",{srcDoc:g.content,sandbox:"allow-scripts",style:{width:"100%",height:"100%",border:"none",background:"var(--bg)"},title:p("desktop.htmlPreview")}):em&&T?(0,n.jsx)("div",{className:"markdown-body markdown-file-preview",style:{padding:"24px 32px"},children:(0,n.jsx)(sd.oz,{remarkPlugins:s6,rehypePlugins:s4,components:{h1:({children:e})=>(0,n.jsx)("h1",{id:sQ(e),children:e}),h2:({children:e})=>(0,n.jsx)("h2",{id:sQ(e),children:e}),h3:({children:e})=>(0,n.jsx)("h3",{id:sQ(e),children:e}),code({className:e,children:t,...r}){let o=e?.replace("language-","").toLowerCase()??"",i=String(t);return e?.includes("language-")||i.includes("\n")?"mermaid"===o?(0,n.jsx)(lc,{code:i.replace(/\n$/,"")}):(0,n.jsx)(lh,{code:i.replace(/\n$/,""),lang:o}):(0,n.jsx)("code",{className:"inline max-w-full whitespace-normal break-words [overflow-wrap:anywhere] align-baseline bg-(--bg-secondary) border border-(--border) px-1.5 py-0.5 text-xs font-mono text-(--accent-blue)",...r,children:t})},pre:({children:e})=>(0,n.jsx)(n.Fragment,{children:e}),a({href:e,children:r,...o}){delete o.node;let s="text-(--accent-blue) underline underline-offset-2 hover:text-(--accent-blue)/80",l=i?si(e,ev,t??ev):null;return l&&i?(0,n.jsx)("a",{href:e,...o,className:s,onClick:e=>{if(e.defaultPrevented||0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.currentTarget.getAttribute("target");t&&"_self"!==t||(e.preventDefault(),i(l))},children:r}):(0,n.jsx)("a",{href:e,...o,className:s,target:"_blank",rel:"noopener noreferrer",children:r})},table:({children:e})=>(0,n.jsx)("div",{className:"my-3 rounded-lg overflow-hidden border border-(--border)",children:(0,n.jsx)("div",{className:"overflow-x-auto",children:(0,n.jsx)("table",{className:"w-full text-sm border-collapse [&_tr:last-child>td]:border-b-0",children:e})})})},children:ep})}):(0,n.jsx)(sc.A,{language:"text"===g.language?"plaintext":g.language,style:s5,showLineNumbers:!0,lineNumberStyle:{color:"var(--text-dim)",fontStyle:"normal",minWidth:"3em",paddingRight:"1em"},customStyle:{margin:0,padding:"12px 0",background:"var(--bg)",fontSize:13,lineHeight:1.6,fontFamily:"var(--font-mono)",minHeight:"100%"},codeTagProps:{style:{fontFamily:"var(--font-mono)"}},lineProps:e=>({className:"file-source-line","data-line-number":String(e)}),wrapLongLines:E,children:g.content})})]})}function cK({sessionId:e,label:t,running:r=!1,onOpenFile:i}){let{t:s}=(0,J.s)(),[l,a]=(0,o.useState)([]),[d,c]=(0,o.useState)([]),[u,p]=(0,o.useState)(!0),[h,g]=(0,o.useState)(null);(0,o.useEffect)(()=>{let t=!1;return(async r=>{r&&p(!0);try{let r=await fetch(`/api/sessions/${encodeURIComponent(e)}?tail=500`,{cache:"no-store"}),n=await r.json();if(t)return;if(!r.ok)throw Error(n.error??`HTTP ${r.status}`);a(n.context?.messages??[]),c([]),g(null)}catch(e){if(t)return;g(e instanceof Error?e.message:String(e))}finally{t||p(!1)}})(!0),()=>{t=!0}},[e]),(0,o.useEffect)(()=>{if(!r)return;let t=!1,n=window.setInterval(async()=>{if("visible"===document.visibilityState)try{let r=await fetch(`/api/sessions/${encodeURIComponent(e)}?tail=500`,{cache:"no-store"});if(!r.ok)return;let n=await r.json();if(t)return;a(n.context?.messages??[])}catch{}},2500);return()=>{t=!0,window.clearInterval(n)}},[r,e]);let x=(0,o.useMemo)(()=>{let e=new Map;for(let t of l)"toolResult"===t.role&&e.set(t.toolCallId,t);return e},[l]),f=(0,o.useMemo)(()=>l.filter(e=>"user"===e.role||"assistant"===e.role),[l]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,background:"var(--bg)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexShrink:0,padding:"8px 12px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:600,color:"var(--text)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t||s("subagent.transcriptTitle")}),r&&(0,n.jsx)("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--accent)",whiteSpace:"nowrap"},children:s("agentSwitcher.status.running")})]}),(0,n.jsxs)("div",{className:"scroll-overlay",style:{flex:1,minHeight:0,overflowY:"auto",padding:"10px 12px"},children:[u&&0===l.length&&(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontSize:12},children:s("subagent.transcriptLoading")}),h&&0===l.length&&(0,n.jsx)("div",{style:{color:"var(--status-error)",fontSize:12},children:s("subagent.transcriptFailed",{error:h})}),!u&&!h&&0===f.length&&(0,n.jsx)("div",{style:{color:"var(--text-dim)",fontSize:12},children:s(r?"subagent.transcriptWaiting":"subagent.transcriptEmpty")}),f.map((t,r)=>(0,n.jsx)(lO,{message:t,toolResults:x,entryId:d[r],sessionId:e,onOpenFile:i},`subagent-msg-${r}`))]})]})}function cV({tabs:e,activeTabId:t,onSelectTab:r,onCloseTab:i}){let{t:s}=(0,J.s)(),l=(0,o.useRef)(null),[a,d]=(0,o.useState)(!1);(0,o.useEffect)(()=>{if(!t)return;let e=l.current;if(!e)return;let r=e.querySelector(`[data-tab-id="${CSS.escape(t)}"]`);r?.scrollIntoView({block:"nearest",inline:"nearest"})},[t,e.length]),(0,o.useEffect)(()=>{let e=l.current;if(!e)return;let t=()=>d(e.scrollWidth>e.clientWidth+1);t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[e.length]);let c=(0,o.useCallback)((t,n)=>{if(t.target!==t.currentTarget)return;if("Enter"===t.key||" "===t.key){t.preventDefault(),r(n.id);return}if(!["ArrowLeft","ArrowRight","Home","End"].includes(t.key))return;t.preventDefault();let o=e.findIndex(e=>e.id===n.id),i="Home"===t.key?0:"End"===t.key?e.length-1:(o+("ArrowRight"===t.key?1:-1)+e.length)%e.length;r(e[i].id);let s=l.current;s?.querySelector(`[data-tab-id="${CSS.escape(e[i].id)}"]`)?.focus()},[r,e]);return(0,n.jsx)("div",{ref:l,role:"tablist",className:`file-tab-bar${a?"":" no-overflow"}`,children:e.map(o=>{let l=o.id===t;return(0,n.jsxs)("div",{role:"tab","data-tab-id":o.id,"aria-label":"terminal"===o.kind?s("terminal.tabLabel",{name:o.label}):"subagent"===o.kind?s("subagent.transcriptTitle")+": "+o.label:o.label,"aria-selected":l,tabIndex:l||!t&&e[0].id===o.id?0:-1,className:"file-tab",onKeyDown:e=>c(e,o),onClick:()=>r(o.id),onMouseDown:e=>{1===e.button&&e.preventDefault()},onAuxClick:e=>{1===e.button&&(e.preventDefault(),e.stopPropagation(),o.closing||i(o.id))},children:[(0,n.jsx)("span",{className:"file-tab-icon",children:"subagent"===o.kind?(0,n.jsx)(U.d,{size:13,"aria-hidden":"true"}):"terminal"===o.kind?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}):ov(o.label,13)}),(0,n.jsx)("span",{className:"file-tab-label",title:o.filePath,children:o.label}),(0,n.jsx)("button",{type:"button",className:"file-tab-close",disabled:o.closing,onClick:e=>{e.stopPropagation(),i(o.id)},title:s("desktop.closeTab"),"aria-label":s("desktop.closeTabWithLabel",{label:o.label}),children:(0,n.jsx)(h.X,{size:11,"aria-hidden":"true"})})]},o.id)})})}let cJ="pi-web:file-tabs";function cY(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}let cG=new Set(["awaiting_input","review","failed"]),cX=(0,o.createContext)(null);function cZ(){let e=(0,o.useContext)(cX);if(!e)throw Error("useTasksView must be used within TasksViewProvider");return e}function cQ({children:e}){let{t}=(0,J.s)(),r=(0,o.useRef)(t);(0,o.useEffect)(()=>{r.current=t},[t]);let[i,s]=(0,o.useState)([]),[l,a]=(0,o.useState)([]),d=(0,o.useRef)(0),c=(0,o.useCallback)(async()=>{let e=++d.current;try{let t=await (0,di.Wt)(),r=(await Promise.all(t.map(e=>(0,di.Vk)(e).catch(()=>[])))).flat().sort((e,t)=>t.id-e.id);if(e!==d.current)return;a(e=>c0(e,t)?e:t),s(e=>c0(e,r)?e:r)}catch{}},[]);(0,o.useEffect)(()=>{c();let e=null,t=!1,r=()=>{t||((e=new EventSource("/api/tasks/events")).onmessage=()=>{c()},e.onerror=()=>{e?.close(),e=null,c(),setTimeout(r,2e3)})};r();let n=()=>{"visible"===document.visibilityState&&c()},o=()=>void c();document.addEventListener("visibilitychange",n),window.addEventListener("online",o);let i=setInterval(()=>void c(),6e4);return()=>{t=!0,e?.close(),document.removeEventListener("visibilitychange",n),window.removeEventListener("online",o),clearInterval(i)}},[c]);let u=(0,o.useMemo)(()=>i.filter(e=>cG.has(e.status)&&null==e.archivedAt).length,[i]),p=(0,o.useRef)(null);(0,o.useEffect)(()=>{let e=p.current;if((p.current=new Map(i.map(e=>[e.id,e.status])),e&&0!==i.length)&&"Notification"in window){for(let r of i)if(e.get(r.id)!==r.status&&("review"===r.status||"failed"===r.status)&&null==r.archivedAt&&"visible"!==document.visibilityState)try{let e="review"===r.status?t("tasks.notifyReview",{title:r.title}):t("tasks.notifyFailed",{title:r.title});!function(e,t){new Promise(r=>{if(!("Notification"in window))return void r();let n=()=>{try{new Notification(e,{body:t,tag:"pi-tasks"})}catch{}r()};"granted"===Notification.permission?n():"denied"!==Notification.permission?Notification.requestPermission().then(e=>{"granted"===e?n():r()}):r()})}("Pi Web Tasks",e)}catch{}}},[i,t]);let h=(0,o.useMemo)(()=>({tasks:i,projects:l,attentionCount:u,refetch:c}),[i,l,u,c]);return(0,n.jsx)(cX.Provider,{value:h,children:e})}function c0(e,t){return JSON.stringify(e)===JSON.stringify(t)}var c1=r(4539),c2=r(12449),c6=r(2571);let c4=["todo","inProgress","attention","done"];function c5(e){return"review"===e.status&&0===e.filesChanged}function c3(){return{defaultAgentType:null,modeId:null,configValues:{},autoProcess:!0,maxConcurrent:1,mergeStrategy:"merge",deleteWorktreeDefault:!0,preflightCommand:null,initCommand:null,stagePrompts:null}}let c8=["todo","inProgress","attention","done"],c7={todo:{id:"todo",marker:"var(--text-dim)"},inProgress:{id:"inProgress",marker:"var(--accent)"},attention:{id:"attention",marker:"var(--status-warning)"},done:{id:"done",marker:"var(--status-success)"}};var c9=r(54775),ue=r(98998),ut=r(36668);function ur({task:e}){let{t}=(0,J.s)(),r=t("failed"===e.status&&"interrupted"===e.failureReason?"tasks.statusInterrupted":function(e){switch(e){case"todo":return"tasks.statusTodo";case"queued":return"tasks.statusQueued";case"preparing":return"tasks.statusPreparing";case"running":return"tasks.statusRunning";case"awaiting_input":return"tasks.statusAwaitingInput";case"review":return"tasks.statusReview";case"merging":return"tasks.statusMerging";case"done":return"tasks.statusDone";case"failed":return"tasks.statusFailed";case"canceled":return"tasks.statusCanceled"}}(e.status)),o={display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,padding:"2px 8px",fontSize:10,fontWeight:600,lineHeight:1.4,flexShrink:0,whiteSpace:"nowrap"};switch(e.status){case"queued":case"preparing":case"running":case"merging":return(0,n.jsxs)("span",{style:{...o,color:"var(--accent)"},children:[(0,n.jsx)(c9.N,{size:11,className:"pi-spin",style:{animation:"pi-spin 1s linear infinite"},"aria-hidden":"true"}),r]});case"awaiting_input":case"review":return(0,n.jsx)("span",{style:{...o,border:"1px solid rgba(245,158,11,0.45)",background:"rgba(245,158,11,0.08)",color:"var(--status-warning)"},children:r});case"done":return(0,n.jsxs)("span",{style:{...o,background:"rgba(16,185,129,0.12)",color:"#059669"},children:[(0,n.jsx)(x.J,{size:10,weight:"bold","aria-hidden":"true"}),r]});case"failed":return(0,n.jsx)("span",{style:{...o,background:"rgba(239,68,68,0.12)",color:"var(--status-error)"},children:r});default:return(0,n.jsx)("span",{style:{...o,background:"var(--bg-hover)",color:"var(--text-muted)"},children:r})}}function un({task:e}){let t=e.preflight;if(!t||"review"!==e.status)return null;let r="passed"===t.status?{background:"rgba(16,185,129,0.12)",color:"#059669"}:"failed"===t.status?{background:"rgba(239,68,68,0.12)",color:"var(--status-error)"}:{background:"var(--bg-hover)",color:"var(--text-muted)"};return(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,padding:"1px 6px",fontSize:10,fontWeight:500,lineHeight:1.5,maxWidth:"100%",...r},title:t.command,children:["running"===t.status?(0,n.jsx)(c9.N,{size:10,style:{animation:"pi-spin 1s linear infinite"},"aria-hidden":"true"}):"passed"===t.status?(0,n.jsx)(eo.r,{size:10,"aria-hidden":"true"}):(0,n.jsx)(r4.J,{size:10,"aria-hidden":"true"}),(0,n.jsx)("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t.command})]})}function uo({task:e,folderName:t,now:r,onOpen:o,onStart:i,onCancel:s,onRetry:l,onRequeue:a,onViewSession:d,onMerge:c,onArchive:u,onEdit:p}){let{t:h}=(0,J.s)(),g=null!=e.archivedAt,f="running"===e.status||"awaiting_input"===e.status||"merging"===e.status,m=null!=e.filesChanged&&e.filesChanged>0?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:3,fontFamily:"var(--font-mono)",fontSize:10},children:[(0,n.jsxs)("span",{style:{color:"#059669"},children:["+",e.additions??0]}),(0,n.jsxs)("span",{style:{color:"var(--status-error)"},children:["-",e.deletions??0]})]}):null,v=function(e,t){if(!e)return"";let r=new Date(e).getTime();if(Number.isNaN(r))return"";let n=Math.floor(Math.max(0,t-r)/6e4);if(n<1)return"now";if(n<60)return`${n}m`;let o=Math.floor(n/60);if(o<24)return`${o}h`;let i=Math.floor(o/24);return`${i}d`}(e.finishedAt??e.settledAt??e.startedAt??e.createdAt,r),{primary:y,more:b}=(()=>{let t=[],r=null;if(g)return{primary:r={icon:R.T,label:h("tasks.actionUnarchive"),onClick:u},more:t};switch(e.status){case"todo":r={icon:c6.j,label:h("tasks.actionStart"),onClick:i},t.push({icon:aD.S,label:h("tasks.actionEdit"),onClick:p});break;case"queued":case"preparing":case"running":case"awaiting_input":r={icon:ue.k,label:h("tasks.actionCancel"),onClick:s};break;case"review":r=c5(e)?{icon:x.J,label:h("tasks.actionComplete"),onClick:c}:{icon:ut.r,label:h("tasks.actionMerge"),onClick:c};break;case"merging":break;case"failed":r={icon:C.S,label:h("tasks.actionRetry"),onClick:l},t.push({icon:aD.S,label:h("tasks.actionEdit"),onClick:p}),t.push({icon:R.T,label:h("tasks.actionArchive"),onClick:u});break;case"done":r={icon:R.T,label:h("tasks.actionArchive"),onClick:u};break;case"canceled":r={icon:l3.f,label:h("tasks.actionRequeue"),onClick:a},t.push({icon:R.T,label:h("tasks.actionArchive"),onClick:u})}return{primary:r,more:t}})(),k=[...b];return null!=e.conversationId&&k.push({icon:l5.y,label:h("tasks.actionViewSession"),onClick:d}),(0,n.jsxs)("div",{role:"button",tabIndex:0,onClick:o,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),o())},style:{display:"flex",flexDirection:"column",cursor:"pointer",borderRadius:12,border:"1px solid color-mix(in srgb, var(--border) 85%, transparent)",background:"var(--bg-panel)",padding:12,textAlign:"left",transition:"border-color 0.12s",opacity:g?.6:1,boxShadow:"0 1px 2px rgba(0,0,0,0.04)"},className:"task-card-hover",onMouseEnter:e=>{e.currentTarget.style.borderColor="var(--accent)"},onMouseLeave:e=>{e.currentTarget.style.borderColor="color-mix(in srgb, var(--border) 85%, transparent)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{minWidth:0,overflowWrap:"break-word",fontSize:13,fontWeight:500,lineHeight:1.4},children:e.title}),(0,n.jsx)(ur,{task:e})]}),(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"2px 6px",marginTop:6,fontSize:11,color:"var(--text-muted)"},children:[t?(0,n.jsx)("span",{style:{maxWidth:160,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}):null,t&&e.workBranch?(0,n.jsx)("span",{style:{opacity:.5},children:"/"}):null,e.workBranch?(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:180},children:e.workBranch}):null,(t||e.workBranch)&&(m||v)?(0,n.jsx)("span",{style:{opacity:.5},children:"\xb7"}):null,m,m&&v?(0,n.jsx)("span",{style:{opacity:.5},children:"\xb7"}):null,v?(0,n.jsx)("span",{style:{flexShrink:0},children:v}):null,(0,n.jsx)(un,{task:e})]}),e.lastError&&("failed"===e.status||"review"===e.status)?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:8,borderRadius:8,background:"rgba(239,68,68,0.08)",padding:"6px 8px",fontSize:11,color:"var(--status-error)"},children:[(0,n.jsx)(lE.t,{size:13,style:{flexShrink:0},"aria-hidden":"true"}),(0,n.jsx)("span",{style:{minWidth:0,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.lastError}),(0,n.jsx)("button",{type:"button",style:{flexShrink:0,fontWeight:600,background:"none",border:"none",cursor:"pointer",color:"inherit",fontSize:11,textDecoration:"underline"},onClick:e=>{e.stopPropagation(),o()},children:h("tasks.errorView")})]}):null,"review"===e.status&&e.resultSummary?(0,n.jsx)("p",{style:{margin:"6px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:11,lineHeight:1.5,color:"var(--text-muted)"},children:e.resultSummary}):null,f&&e.latestProgress?(0,n.jsx)("p",{style:{margin:"6px 0 0",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden",fontSize:11,lineHeight:1.5,color:"var(--text-muted)",fontStyle:"italic"},children:e.latestProgress}):null,y||k.length>0?(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6,marginTop:12,paddingTop:12,borderTop:"1px solid var(--border)"},children:[y?(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),y.onClick()},style:{display:"inline-flex",alignItems:"center",gap:5,padding:"4px 10px",borderRadius:7,background:"var(--accent)",color:"var(--accent-fg)",border:"none",cursor:"pointer",fontSize:11,fontWeight:600},children:[(0,n.jsx)(y.icon,{size:12,weight:"bold","aria-hidden":"true"}),y.label]}):null,(0,n.jsx)("div",{style:{flex:1}}),k.map(e=>(0,n.jsx)("button",{type:"button",title:e.label,"aria-label":e.label,onClick:t=>{t.stopPropagation(),e.onClick()},style:{display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,borderRadius:999,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",cursor:"pointer",opacity:0,transition:"opacity 0.12s, background 0.12s, color 0.12s"},className:"task-card-secondary",onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(e.icon,{size:13,"aria-hidden":"true"})},e.label))]}):null]})}function ui({open:e,onOpenChange:t,task:r}){let{t:i}=(0,J.s)(),{refetch:s}=cZ(),[l,a]=(0,o.useState)(""),[d,c]=(0,o.useState)(!1);if(W(!d,()=>t(!1)),(0,o.useEffect)(()=>{e&&(a(""),c(!1))},[e,r]),!e||!r)return null;let u=async()=>{if(!d){c(!0);try{await (0,di.oQ)(r.id,r.projectRoot,"cancel",{reason:l.trim()||null}),t(!1),s()}catch(e){console.error("cancel failed",e)}finally{c(!1)}}};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.cancelTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:i("tasks.cancelDescription")}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:i("tasks.cancelReasonLabel")}),(0,n.jsx)("textarea",{value:l,onChange:e=>a(e.target.value),placeholder:i("tasks.cancelReasonPlaceholder"),rows:3,autoFocus:!0,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:d,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("tasks.cancelKeep")}),(0,n.jsx)("button",{type:"button",onClick:()=>void u(),disabled:d,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("tasks.cancelSubmit")})]})]})]})})}function us({open:e,onOpenChange:t,task:r}){let{t:i}=(0,J.s)(),{refetch:s}=cZ(),[l,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(!1);W(!d,()=>t(!1));let u=r?.worktreePath!=null;if((0,o.useEffect)(()=>{if(!e||!r)return;c(!1);let t=!1;return(0,di.CG)(r.projectRoot).then(e=>{t||a(e.deleteWorktreeDefault)}).catch(()=>{t||a(!0)}),()=>{t=!0}},[e,r]),!e||!r)return null;let p=async()=>{if(!d){c(!0);try{await (0,di.ZX)(r.id,r.projectRoot,u&&l),t(!1),s()}catch(e){console.error("complete failed",e)}finally{c(!1)}}};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.completeTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:i("tasks.completeDescription")}),u?(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:l,onChange:e=>a(e.target.checked),style:{accentColor:"var(--accent)"}}),i("tasks.completeDeleteWorktree")]}):null,(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:d,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void p(),disabled:d,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("tasks.completeSubmit")})]})]})]})})}var ul=r(51285),ua=r(16894);function ud({open:e,onOpenChange:t,task:r,onViewSession:i,onMerge:s,onEdit:l,onCancel:a,onRetry:d,onRequeue:c,onComplete:u}){let{t:p}=(0,J.s)(),{refetch:g}=cZ(),[f,m]=(0,o.useState)([]),[v,y]=(0,o.useState)([]),[k,j]=(0,o.useState)(null),[w,S]=(0,o.useState)(null),[T,I]=(0,o.useState)(!1),[M,E]=(0,o.useState)(!1),[$,L]=(0,o.useState)(""),[N,A]=(0,o.useState)(!1),[F,P]=(0,o.useState)(!1),[D,H]=(0,o.useState)(!1);W(!0,()=>t(!1));let O=r?.id??null,B=r?.projectRoot??null,U=(0,o.useCallback)(async()=>{if(null==O||null==B)return;let[e,t]=await Promise.all([(0,di.HB)(B,O).catch(()=>[]),r?.worktreePath?(0,di.JH)(B,O).then(e=>e.files).catch(()=>[]):Promise.resolve([])]);m(e),y(t)},[O,B,r?.worktreePath]);(0,o.useEffect)(()=>{if(!e||null==O)return;m([]),y([]),E(!1),L(""),U();let t=window.setInterval(()=>void U(),5e3);return()=>window.clearInterval(t)},[e,O,U]);let _=(0,o.useCallback)(async e=>{H(!0);try{await e()}catch(e){console.error("detail action failed",e)}finally{H(!1),g()}},[g]),q=(0,o.useCallback)(async e=>{if(null!=B&&null!=O){I(!0);try{let t=await (0,di.h)(B,O,e);S(t.supported&&t.patch?t.patch:null)}catch{S(null)}finally{I(!1)}}},[B,O]),K=async()=>{null!=r&&null!=B&&(await _(()=>(0,di.bH)(r.id,B,F)),t(!1))},V=async()=>{null!=r&&null!=B&&$.trim()&&(await _(()=>(0,di.in)(r.id,B,$.trim())),E(!1),L(""))};if(!e||null==r||null==B)return null;let Y=[];if(null==r.archivedAt)switch(r.status){case"todo":Y.push({label:p("tasks.actionStart"),icon:c6.j,onClick:()=>void _(()=>(0,di.oQ)(r.id,B,"start")),filled:!0}),Y.push({label:p("tasks.actionEdit"),icon:aD.S,onClick:()=>l(r)});break;case"queued":case"preparing":case"running":case"awaiting_input":Y.push({label:p("tasks.actionCancel"),icon:ue.k,onClick:()=>a(r),danger:!0});break;case"review":Y.push({label:c5(r)?p("tasks.actionComplete"):p("tasks.actionMerge"),icon:c5(r)?x.J:ul.Y,onClick:()=>c5(r)?u(r):s(r),filled:!0}),Y.push({label:p("tasks.actionReturn"),icon:l3.f,onClick:()=>E(!0)});break;case"failed":Y.push({label:p("tasks.actionRetry"),icon:C.S,onClick:()=>d(r),filled:!0}),Y.push({label:p("tasks.actionEdit"),icon:aD.S,onClick:()=>l(r)});break;case"done":Y.push({label:p("tasks.actionArchive"),icon:R.T,onClick:()=>void _(()=>(0,di.et)(r.id,B,!0))});break;case"canceled":Y.push({label:p("tasks.actionRequeue"),icon:l3.f,onClick:()=>c(r),filled:!0})}else Y.push({label:p("tasks.actionUnarchive"),icon:R.T,onClick:()=>void _(()=>(0,di.et)(r.id,B,!1))});return null!=r.conversationId&&Y.push({label:p("tasks.actionViewSession"),icon:l5.y,onClick:()=>i(r)}),(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:800,background:"rgba(0,0,0,0.35)"},children:(0,n.jsxs)("div",{style:{position:"absolute",top:0,right:0,bottom:0,width:"min(480px, 90vw)",background:"var(--bg-panel)",borderLeft:"1px solid var(--border)",display:"flex",flexDirection:"column",boxShadow:"-8px 0 32px rgba(0,0,0,0.2)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,padding:"16px 16px 0"},children:[(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("h3",{style:{margin:0,fontSize:15,fontWeight:600,lineHeight:1.4,overflowWrap:"break-word"},children:r.title}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:6},children:[(0,n.jsx)(ur,{task:r}),r.workBranch?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-muted)"},children:[(0,n.jsx)(b.Z,{size:12,"aria-hidden":"true"}),r.workBranch]}):null]})]}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":p("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex",flexShrink:0},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:8,padding:"14px 16px 0"},children:Y.map(e=>{let t,r;return(0,n.jsxs)("button",{type:"button",onClick:e.onClick,disabled:D,style:(t=e.filled,r=e.danger,{display:"inline-flex",alignItems:"center",gap:5,padding:"7px 12px",borderRadius:8,fontSize:12,fontWeight:600,cursor:"pointer",background:t?"var(--accent)":r?"rgba(239,68,68,0.1)":"var(--bg-hover)",color:t?"#fff":r?"var(--status-error)":"var(--text)",border:t||r?"none":"1px solid var(--border)"}),children:[(0,n.jsx)(e.icon,{size:13,weight:"bold","aria-hidden":"true"}),e.label]},e.label)})}),M&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,padding:"12px 16px 0"},children:[(0,n.jsx)("textarea",{value:$,onChange:e=>L(e.target.value),placeholder:p("tasks.returnPlaceholder"),rows:3,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:12,resize:"vertical",fontFamily:"inherit"}}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[(0,n.jsx)("button",{type:"button",onClick:()=>E(!1),style:{padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:p("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void V(),disabled:!$.trim(),style:{padding:"6px 14px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:p("tasks.returnSubmit")})]})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"14px 16px 0",fontSize:12,color:"var(--text-muted)"},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:p("tasks.metaProject")}),(0,n.jsx)("span",{style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11},children:r.projectRoot})]}),r.createdAt?(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:p("tasks.metaCreated")}),(0,n.jsx)("span",{children:new Date(r.createdAt).toLocaleString()})]}):null,r.mergeCommit?(0,n.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,n.jsx)("span",{style:{flexShrink:0,color:"var(--text-dim)",width:64},children:p("tasks.metaCommit")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11},children:r.mergeCommit})]}):null]}),v.length>0&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"14px 16px 0"},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:p("tasks.changedFiles")}),(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2,maxHeight:140,overflowY:"auto"},children:v.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>{var t;j(t=e.file),S(null),q(t)},style:{display:"flex",alignItems:"center",gap:8,textAlign:"left",padding:"4px 6px",borderRadius:6,background:"none",border:"none",color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,n.jsx)(ua.o,{size:13,style:{flexShrink:0,color:"var(--text-muted)"},"aria-hidden":"true"}),(0,n.jsx)("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"var(--font-mono)",fontSize:11},children:e.file}),(0,n.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"#059669",flexShrink:0},children:["+",e.additions]}),(0,n.jsxs)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--status-error)",flexShrink:0},children:["-",e.deletions]})]},e.file))})]}),null!=k&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,padding:"12px 16px 0",minHeight:0,flexShrink:0},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)"},children:p("tasks.diff")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1},children:k}),(0,n.jsx)("button",{type:"button",onClick:()=>j(null),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:2,display:"flex"},children:(0,n.jsx)(h.X,{size:12,"aria-hidden":"true"})})]}),T?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",padding:8},children:p("tasks.loading")}):w?(0,n.jsx)("pre",{style:{margin:0,maxHeight:200,overflow:"auto",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10,fontSize:11,lineHeight:1.5,fontFamily:"var(--font-mono)",color:"var(--text-muted)",whiteSpace:"pre"},children:w.split("\n").map((e,t)=>{let r;return e.startsWith("+")&&!e.startsWith("+++")?r="#059669":e.startsWith("-")&&!e.startsWith("---")?r="var(--status-error)":e.startsWith("@@")&&(r="var(--accent)"),(0,n.jsx)("div",{style:{color:r},children:e||" "},t)})}):(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",padding:8},children:p("tasks.noDiff")})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"14px 16px 0",flex:1,minHeight:0},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:p("tasks.timeline")}),(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",paddingBottom:8},children:0===f.length?(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-dim)",padding:8},children:p("tasks.noEvents")}):(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[...f].reverse().map(e=>{var t;let r,o;return(0,n.jsxs)("div",{style:{display:"flex",gap:8,padding:"4px 6px",borderRadius:6,fontSize:11},children:[(0,n.jsx)("span",{style:{color:"var(--text-dim)",flexShrink:0,fontFamily:"var(--font-mono)",fontSize:10,paddingTop:1},children:new Date(e.createdAt).toLocaleTimeString()}),(0,n.jsx)("span",{style:{color:"var(--text)",flexShrink:0,fontWeight:500},children:(t=e.kind,(o=p(r=`tasks.event_${t}`))===r?t:o)}),e.payload?.feedback?(0,n.jsx)("span",{style:{color:"var(--text-muted)",fontStyle:"italic",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:String(e.payload.feedback)}):null]},e.id)})})})]}),(0,n.jsx)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"10px 16px",borderTop:"1px solid var(--border)",flexShrink:0},children:N?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:F,onChange:e=>P(e.target.checked),style:{accentColor:"var(--accent)"}}),p("tasks.deleteWorktree")]}),(0,n.jsx)("button",{type:"button",onClick:()=>A(!1),style:{padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:p("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void K(),disabled:D,style:{padding:"6px 14px",borderRadius:8,background:"var(--status-error)",color:"#fff",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:p("tasks.deleteConfirm")})]}):(0,n.jsxs)("button",{type:"button",onClick:()=>A(!0),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--status-error)",fontSize:12,cursor:"pointer"},children:[(0,n.jsx)(z.l,{size:13,"aria-hidden":"true"}),p("tasks.delete")]})})]})})}var uc=r(17757);function uu({open:e,onOpenChange:t,task:r,defaultProject:i,projects:s,prefillTitle:l,prefillPrompt:a,onSubmit:d}){let{t:c}=(0,J.s)(),[u,p]=(0,o.useState)(""),[g,x]=(0,o.useState)(""),[f,m]=(0,o.useState)(""),[v,y]=(0,o.useState)([]),[b,k]=(0,o.useState)(""),[j,w]=(0,o.useState)(!1);W(!j,()=>t(!1));let S=(0,o.useRef)(!1);if((0,o.useEffect)(()=>{if(!e){S.current=!1;return}S.current||(S.current=!0,p(r?.projectRoot??i??s[0]??""),x(r?.title??l??""),m(r?.config?.prompt??a??""),(0,di.VB)().then(y).catch(()=>void 0))},[e,r,i,s,l,a]),!e)return null;let C=async()=>{if(u&&g.trim()&&!j){w(!0);try{await d(u,g.trim(),{prompt:f.trim(),agentType:r?.config?.agentType??null,modelId:r?.config?.modelId??null,thinkingLevel:r?.config?.thinkingLevel??null}),t(!1)}catch(e){console.error("submit task failed",e)}finally{w(!1)}}},T=async()=>{if(b.trim()&&g.trim())try{await (0,di.nY)({name:b.trim(),title:g.trim(),config:{prompt:f.trim()}}),k(""),(0,di.VB)().then(y).catch(()=>void 0)}catch(e){console.error("save template failed",e)}},R=async e=>{try{await (0,di.B_)(e),(0,di.VB)().then(y).catch(()=>void 0)}catch(e){console.error("delete template failed",e)}},I={width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none"};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:900,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",maxHeight:"80vh",overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:r?c("tasks.editTitle"):c("tasks.newTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":c("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[v.length>0&&(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:11,fontWeight:600,color:"var(--text-muted)",textTransform:"uppercase",letterSpacing:"0.05em"},children:c("tasks.templates")}),(0,n.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:v.map(e=>(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,background:"var(--bg-hover)",padding:"3px 8px",fontSize:11},children:[(0,n.jsx)("button",{type:"button",onClick:()=>{x(e.title),m(e.config?.prompt??"")},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text)",fontSize:11,padding:0},children:e.name}),(0,n.jsx)("button",{type:"button",onClick:()=>void R(e.id),"aria-label":c("tasks.deleteTemplate"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)",padding:0,display:"flex"},children:(0,n.jsx)(z.l,{size:10,"aria-hidden":"true"})})]},e.id))})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldProject")}),(0,n.jsx)("select",{value:u,onChange:e=>p(e.target.value),style:I,children:s.map(e=>(0,n.jsx)("option",{value:e,children:e.split("/").filter(Boolean).pop()??e},e))})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldTitle")}),(0,n.jsx)("input",{value:g,onChange:e=>x(e.target.value),placeholder:c("tasks.fieldTitlePlaceholder"),style:I,autoFocus:!0})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500,color:"var(--text)"},children:c("tasks.fieldPrompt")}),(0,n.jsx)("textarea",{value:f,onChange:e=>m(e.target.value),placeholder:c("tasks.fieldPromptPlaceholder"),rows:6,style:{...I,resize:"vertical",fontFamily:"inherit",lineHeight:1.5}})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:6},children:[(0,n.jsx)("input",{value:b,onChange:e=>k(e.target.value),placeholder:c("tasks.templateNamePlaceholder"),style:{...I,flex:1}}),(0,n.jsxs)("button",{type:"button",onClick:()=>void T(),disabled:!b.trim()||!g.trim(),style:{display:"inline-flex",alignItems:"center",gap:5,padding:"8px 12px",borderRadius:8,background:"var(--bg-hover)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:[(0,n.jsx)(uc.D,{size:13,"aria-hidden":"true"}),c("tasks.saveAsTemplate")]})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:c("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void C(),disabled:!u||!g.trim()||j,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:c("tasks.save")})]})]})]})})}function up({open:e,onOpenChange:t,task:r}){let{t:i}=(0,J.s)(),{refetch:s}=cZ(),[l,a]=(0,o.useState)(!0),[d,c]=(0,o.useState)(""),[u,p]=(0,o.useState)(!0),[g,x]=(0,o.useState)(!1);if(W(!g,()=>t(!1)),(0,o.useEffect)(()=>{e&&r&&(a(!0),c(r.title),x(!1),(0,di.CG)(r.projectRoot).then(e=>p(e.deleteWorktreeDefault)).catch(()=>p(!0)))},[e,r]),!e||!r)return null;let f=async()=>{if((l||d.trim())&&!g){x(!0);try{await (0,di.oB)(r.id,r.projectRoot,l?null:d.trim(),u),t(!1),s()}catch(e){console.error("merge failed",e)}finally{x(!1)}}};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(440px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.mergeTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"radio",checked:l,onChange:()=>a(!0),style:{accentColor:"var(--accent)"}}),i("tasks.mergeAutoMessage")]}),(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"radio",checked:!l,onChange:()=>a(!1),style:{accentColor:"var(--accent)"}}),i("tasks.mergeManualMessage")]}),!l&&(0,n.jsx)("input",{value:d,onChange:e=>c(e.target.value),placeholder:i("tasks.mergeMessagePlaceholder"),style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit"}}),(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13,cursor:"pointer"},children:[(0,n.jsx)("input",{type:"checkbox",checked:u,onChange:e=>p(e.target.checked),style:{accentColor:"var(--accent)"}}),i("tasks.mergeDeleteWorktree")]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void f(),disabled:!l&&!d.trim()||g,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("tasks.mergeConfirm")})]})]})]})})}function uh({open:e,onOpenChange:t,task:r,kind:i}){let{t:s}=(0,J.s)(),{refetch:l}=cZ(),[a,d]=(0,o.useState)(""),[c,u]=(0,o.useState)(!1);if(W(!c,()=>t(!1)),(0,o.useEffect)(()=>{e&&(d(""),u(!1))},[e,r]),!e||!r)return null;let p="retry"===i,g=async()=>{if(!c){u(!0);try{await (0,di.oQ)(r.id,r.projectRoot,i,{note:a.trim()||null}),t(!1),l()}catch(e){console.error("restart failed",e)}finally{u(!1)}}};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:950,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(480px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:s(p?"tasks.restartTitleRetry":"tasks.restartTitleRequeue")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":s("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:"14px 16px 16px"},children:[(0,n.jsx)("p",{style:{margin:0,fontSize:12,lineHeight:1.5,color:"var(--text-muted)"},children:s("tasks.restartDescription")}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:5},children:[(0,n.jsx)("span",{style:{fontSize:12,color:"var(--text-muted)"},children:s("tasks.actionAddNote")}),(0,n.jsx)("textarea",{value:a,onChange:e=>d(e.target.value),placeholder:s(p?"tasks.followUpPlaceholderRetry":"tasks.followUpPlaceholderRequeue"),rows:3,autoFocus:!0,style:{width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"8px 10px",color:"var(--text)",fontSize:13,outline:"none",fontFamily:"inherit",resize:"vertical"}})]}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),disabled:c,style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:s("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void g(),disabled:c,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:s(p?"tasks.actionRetry":"tasks.actionRequeue")})]})]})]})})}let ug=["work","retry","return","merge"];function ux({open:e,onOpenChange:t,projectRoot:r}){let{t:i}=(0,J.s)(),{projects:s}=cZ(),[l,a]=(0,o.useState)(""),[d,c]=(0,o.useState)(()=>c3()),[u,p]=(0,o.useState)(!1),[g,x]=(0,o.useState)(!1);if(W(!g,()=>t(!1)),(0,o.useEffect)(()=>{if(!e)return;let t=r??s[0]??"";a(t),t&&(0,di.Pf)(t).then(e=>{p(null!=e),c(e??c3())}).catch(()=>{p(!1),c(c3())})},[e,r,s]),!e)return null;let f=(e,t)=>{c(r=>({...r,[e]:t}))},m=async()=>{if(l&&!g){x(!0);try{await (0,di.eA)(l,d),p(!0),t(!1)}catch(e){console.error("save settings failed",e)}finally{x(!1)}}},v=async()=>{if(l)try{await (0,di.E)(l),p(!1),c(c3())}catch(e){console.error("reset settings failed",e)}},y={width:"100%",background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:"7px 10px",color:"var(--text)",fontSize:12,outline:"none",fontFamily:"inherit"},b={display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,padding:"10px 0",borderBottom:"1px solid var(--border)"};return(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:960,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(560px, calc(100vw - 48px))",maxHeight:"82vh",overflowY:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.settingsTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"14px 16px 16px"},children:[(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500},children:i("tasks.settingsProject")}),(0,n.jsx)("select",{value:l,onChange:e=>a(e.target.value),style:y,children:s.map(e=>(0,n.jsx)("option",{value:e,children:e.split("/").filter(Boolean).pop()??e},e))})]}),l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{style:b,children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsAutoProcess")}),(0,n.jsx)("input",{type:"checkbox",checked:d.autoProcess,onChange:e=>f("autoProcess",e.target.checked),style:{accentColor:"var(--accent)"}})]}),(0,n.jsxs)("div",{style:b,children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsMaxConcurrent")}),(0,n.jsx)("input",{type:"number",min:0,value:d.maxConcurrent,onChange:e=>f("maxConcurrent",Math.max(0,Number(e.target.value)||0)),style:{...y,width:90}})]}),(0,n.jsxs)("div",{style:b,children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsMergeStrategy")}),(0,n.jsxs)("select",{value:d.mergeStrategy,onChange:e=>f("mergeStrategy",e.target.value),style:{...y,width:140},children:[(0,n.jsx)("option",{value:"merge",children:i("tasks.mergeStrategyMerge")}),(0,n.jsx)("option",{value:"squash",children:i("tasks.mergeStrategySquash")})]})]}),(0,n.jsxs)("div",{style:b,children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsDeleteWorktree")}),(0,n.jsx)("input",{type:"checkbox",checked:d.deleteWorktreeDefault,onChange:e=>f("deleteWorktreeDefault",e.target.checked),style:{accentColor:"var(--accent)"}})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsPreflightCommand")}),(0,n.jsx)("input",{value:d.preflightCommand??"",onChange:e=>f("preflightCommand",e.target.value||null),placeholder:i("tasks.settingsPreflightPlaceholder"),style:{...y,fontFamily:"var(--font-mono)",fontSize:11}})]}),(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:12},children:i("tasks.settingsInitCommand")}),(0,n.jsx)("input",{value:d.initCommand??"",onChange:e=>f("initCommand",e.target.value||null),placeholder:i("tasks.settingsInitPlaceholder"),style:{...y,fontFamily:"var(--font-mono)",fontSize:11}})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6,paddingTop:4},children:[(0,n.jsx)("span",{style:{fontSize:12,fontWeight:500},children:i("tasks.settingsStagePrompts")}),ug.map(e=>(0,n.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("span",{style:{fontSize:11,color:"var(--text-muted)"},children:i(`tasks.stage.${e}`)}),(0,n.jsx)("input",{value:d.stagePrompts?.[e]??"",onChange:t=>f("stagePrompts",{...d.stagePrompts??{},[e]:t.target.value}),style:{...y,fontSize:11}})]},e))]}),u&&(0,n.jsx)("button",{type:"button",onClick:()=>void v(),style:{alignSelf:"flex-start",padding:"6px 12px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text-muted)",fontSize:12,cursor:"pointer"},children:i("tasks.settingsReset")})]}):(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",padding:8},children:i("tasks.settingsNoProject")}),(0,n.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",gap:8,marginTop:4},children:[(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 14px",borderRadius:8,background:"none",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,cursor:"pointer"},children:i("i18n.cancel")}),(0,n.jsx)("button",{type:"button",onClick:()=>void m(),disabled:!l||g,style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("tasks.save")})]})]})]})})}function uf({open:e,onOpenChange:t,task:r}){let{t:i}=(0,J.s)();return(W(e&&!!r,()=>t(!1)),(0,o.useEffect)(()=>{if(!e)return},[e,r]),e&&r)?(0,n.jsx)("div",{style:{position:"fixed",inset:0,zIndex:970,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0,0,0,0.45)"},children:(0,n.jsxs)("div",{style:{width:"min(520px, calc(100vw - 48px))",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:14,boxShadow:"0 16px 48px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 16px 0"},children:[(0,n.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:0},children:i("tasks.sessionTitle")}),(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),"aria-label":i("i18n.close"),style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-muted)",padding:4,display:"flex"},children:(0,n.jsx)(h.X,{size:16,"aria-hidden":"true"})})]}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10,padding:"14px 16px 16px",fontSize:12},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:i("tasks.sessionId")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:r.conversationId??"—"})]}),r.sessionFile?(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4,background:"var(--bg)",border:"1px solid var(--border)",borderRadius:8,padding:10},children:[(0,n.jsx)("span",{style:{color:"var(--text-muted)"},children:i("tasks.sessionFile")}),(0,n.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:r.sessionFile})]}):null,(0,n.jsx)("div",{style:{fontSize:11,color:"var(--text-muted)",lineHeight:1.6},children:i("tasks.sessionHint")}),(0,n.jsx)("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:4},children:(0,n.jsx)("button",{type:"button",onClick:()=>t(!1),style:{padding:"8px 16px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:i("i18n.close")})})]})]})}):null}let um="__all__",uv="pi-tasks-board-filter",uy={showCanceled:!1,showArchived:!1},ub="pi:open-task-settings";function uk(){let{t:e}=(0,J.s)(),{attentionCount:t}=cZ();return(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,height:36,flexShrink:0,padding:"0 16px",borderBottom:"1px solid var(--border)",background:"var(--bg-panel)"},children:[(0,n.jsxs)("h1",{style:{margin:0,display:"flex",alignItems:"center",gap:6,fontSize:13,fontWeight:600},children:[(0,n.jsx)(eV.x,{size:15,color:"var(--text-muted)","aria-hidden":"true"}),e("tasks.title"),(0,n.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 8px",fontSize:9,fontWeight:700,textTransform:"uppercase",letterSpacing:"0.04em"},children:"Beta"})]}),t>0?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,borderRadius:999,background:"rgba(239,68,68,0.12)",color:"var(--status-error)",padding:"1px 8px",fontSize:10,fontWeight:700},children:[t," ",e("tasks.attentionBadge")]}):null,(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsxs)("button",{type:"button",onClick:()=>window.dispatchEvent(new Event(ub)),style:{display:"inline-flex",alignItems:"center",gap:5,height:26,padding:"0 10px",borderRadius:7,background:"none",border:"none",color:"var(--text-muted)",fontSize:12,cursor:"pointer"},title:e("tasks.settingsTitle"),children:[(0,n.jsx)(c1.O,{size:13,"aria-hidden":"true"}),e("tasks.settingsTitle")]})]})}function uj({activeProject:e}){let{t}=(0,J.s)(),{tasks:i,projects:s,refetch:l}=cZ(),[a,d]=(0,o.useState)(null),[c,p]=(0,o.useState)(()=>(function(){try{let e=window.localStorage.getItem(uv);if(e){let t=JSON.parse(e);return{showCanceled:t.showCanceled??!1,showArchived:t.showArchived??!1}}}catch{}return uy})()),[h,g]=(0,o.useState)(!1);(0,o.useEffect)(()=>{try{window.localStorage.setItem(uv,JSON.stringify(c))}catch{}},[c]);let[x,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(!1),b=(0,o.useRef)(null),k=(0,o.useRef)({x:0,y:0}),j=(0,o.useRef)(null),w=(0,o.useRef)(null),[S,C]=(0,o.useState)(null),z=(0,o.useRef)(null);z.current=S;let T=(0,o.useRef)(!1),R=(0,o.useRef)(!1),[I,M]=(0,o.useState)(()=>Date.now());(0,o.useEffect)(()=>{let e=window.setInterval(()=>M(Date.now()),6e4);return()=>window.clearInterval(e)},[]);let[E,$]=(0,o.useState)(!1),[W,L]=(0,o.useState)(null),[N,A]=(0,o.useState)(null);(0,o.useEffect)(()=>{let e=()=>{let e,t=(e=aa,aa=null,e);t&&(L(null),A(t),$(!0))};return e(),window.addEventListener(al,e),()=>window.removeEventListener(al,e)},[]);let[F,P]=(0,o.useState)(null),[D,H]=(0,o.useState)(null),[O,B]=(0,o.useState)(!1),[U,_]=(0,o.useState)(null),[q,K]=(0,o.useState)(!1),[V,Y]=(0,o.useState)(null),[G,X]=(0,o.useState)("retry"),[Z,Q]=(0,o.useState)(!1),[ee,et]=(0,o.useState)(null),[er,en]=(0,o.useState)(!1),[eo,ei]=(0,o.useState)(!1),[es,el]=(0,o.useState)(null),[ea,ed]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=()=>ei(!0);return window.addEventListener(ub,e),()=>window.removeEventListener(ub,e)},[]);let ec=(0,o.useMemo)(()=>null==a?i:i.filter(e=>e.projectRoot===a),[i,a]),eu=(0,o.useMemo)(()=>(function(e,t,r=!1){let n={todo:[],inProgress:[],attention:[],done:[]};for(let o of e)("canceled"!==o.status||t)&&(null==o.archivedAt||r)&&n[function(e){switch(e){case"todo":case"queued":return"todo";case"preparing":case"running":return"inProgress";case"awaiting_input":case"review":case"merging":case"failed":return"attention";case"done":case"canceled":return"done"}}(o.status)].push(o);for(let e of c4)n[e].sort((e,t)=>(t.updatedAt??"").localeCompare(e.updatedAt??""));return n})(ec,c.showCanceled,c.showArchived),[ec,c]),ep=(0,o.useMemo)(()=>{let e=eu.todo;if(null==S)return e;let t=new Map(e.map(e=>[e.id,e])),r=S.flatMap(e=>t.get(e)??[]);for(let t of e)S.includes(t.id)||r.push(t);return r},[eu.todo,S]),eh=(0,o.useMemo)(()=>i.find(e=>e.id===F)??null,[i,F]),eg=(0,o.useMemo)(()=>i.find(e=>e.id===es)??null,[i,es]),ex=(0,o.useCallback)(async e=>{try{await e()}catch(e){console.error("task action failed",e)}finally{l()}},[l]),ef=(0,o.useCallback)(e=>{null!=e.conversationId&&(el(e.id),ed(!0))},[el,ed]),em=(0,o.useCallback)(e=>{H(e),B(!0)},[H,B]),ev=(0,o.useCallback)(()=>{L(null),$(!0)},[L,$]),ey=(0,o.useCallback)((e,t)=>{let r=j.current,n=b.current;r&&n&&(r.style.transform=`translate3d(${e-n.dx}px, ${t-n.dy}px, 0)`)},[]),eb=e=>{let t=e.currentTarget.getBoundingClientRect();b.current={dx:e.clientX-t.left,dy:e.clientY-t.top,width:t.width}},ek=(0,o.useCallback)(e=>{if(f(null),v(!1),e){T.current=!1;return}requestAnimationFrame(()=>{T.current=!1})},[f,v]),ej=(0,o.useCallback)(()=>{R.current=!0,C(null),ek(!0)},[ek,C]);(0,o.useEffect)(()=>{if(!x)return;let e=()=>{document.hidden&&ej()};return window.addEventListener("blur",ej),document.addEventListener("visibilitychange",e),()=>{window.removeEventListener("blur",ej),document.removeEventListener("visibilitychange",e)}},[x,ej]),(0,o.useEffect)(()=>{x&&!ep.some(e=>e.id===x.task.id)&&ej()},[x,ep,ej]);let ew=(0,o.useCallback)((e,t,r)=>{if(R.current){ek(!0),C(null);return}let n=w.current?.getBoundingClientRect(),o=null!=n&&t>=n.left&&t<=n.right&&r>=n.top&&r<=n.bottom;if(ek(!1),o){C(null);let t=i.find(t=>t.id===e.id);t?.status==="todo"&&null!=a&&ex(()=>(0,di.oQ)(e.id,e.projectRoot,"start"));return}let s=z.current;null!=a&&null!=s&&(async()=>{try{await (0,di.Lu)(a,s)}catch(e){console.error("reorder failed",e)}await l(),C(null)})()},[ex,ek,a,l,i]),eS=(0,o.useCallback)(()=>{ex(async()=>{let e=await (0,di.a5)(a);e>0&&console.log(`started ${e} tasks`)})},[ex,a]),eC=(0,o.useCallback)(()=>{let e=eu.done.filter(e=>null==e.archivedAt);0!==e.length&&ex(()=>Promise.all(e.map(e=>(0,di.et)(e.id,e.projectRoot,!0))))},[ex,eu.done]),ez=+(c.showCanceled!==uy.showCanceled)+ +(c.showArchived!==uy.showArchived),eT=i.length>0,eR=(0,o.useMemo)(()=>{let t=new Set(s);return e&&t.add(e),[...t].sort()},[s,e]),eI=(0,o.useMemo)(()=>{let e=new Map;for(let t of eR)e.set(t,t.split("/").filter(Boolean).pop()??t);return e},[eR]);return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[eT&&(0,n.jsxs)("div",{style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:8,padding:"14px 16px 8px"},children:[(0,n.jsxs)("select",{value:a??um,onChange:e=>d(e.target.value===um?null:e.target.value),style:{height:30,borderRadius:999,padding:"0 10px",background:"var(--bg-panel)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,fontWeight:500,cursor:"pointer",maxWidth:"14rem"},"aria-label":t("tasks.allFolders"),children:[(0,n.jsx)("option",{value:um,children:t("tasks.allFolders")}),eR.map(e=>(0,n.jsx)("option",{value:e,children:eI.get(e)??e},e))]}),(0,n.jsxs)("div",{style:{position:"relative"},children:[(0,n.jsxs)("button",{type:"button",onClick:()=>g(e=>!e),style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 12px",background:"var(--bg-panel)",border:"1px solid var(--border)",color:"var(--text)",fontSize:12,fontWeight:500,cursor:"pointer"},children:[(0,n.jsx)(c2.n,{size:13,"aria-hidden":"true"}),t("tasks.filter"),ez>0?(0,n.jsx)("span",{style:{borderRadius:999,background:"rgba(37,99,235,0.12)",color:"var(--accent)",padding:"1px 6px",fontSize:10,fontWeight:700},children:ez}):null]}),h&&(0,n.jsx)("div",{style:{position:"absolute",top:34,left:0,zIndex:50,width:200,borderRadius:12,padding:6,background:"var(--bg-panel)",border:"1px solid var(--border)",boxShadow:"0 8px 24px rgba(0,0,0,0.16)"},children:[["showCanceled",t("tasks.showCanceled")],["showArchived",t("tasks.showArchived")]].map(([e,t])=>(0,n.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 8px",borderRadius:8,cursor:"pointer",fontSize:12},children:[(0,n.jsx)("input",{type:"checkbox",checked:c[e],onChange:t=>p(r=>({...r,[e]:t.target.checked})),style:{accentColor:"var(--accent)"}}),t]},e))})]}),(0,n.jsx)("div",{style:{flex:1}}),(0,n.jsxs)("button",{type:"button",onClick:eS,style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 12px",background:"none",border:"none",color:"var(--text)",fontSize:12,cursor:"pointer"},title:t("tasks.startAll"),children:[(0,n.jsx)(c6.j,{size:13,"aria-hidden":"true"}),t("tasks.startAll")]}),(0,n.jsxs)("button",{type:"button",onClick:ev,style:{display:"inline-flex",alignItems:"center",gap:6,height:30,borderRadius:999,padding:"0 14px",background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,n.jsx)(y.F,{size:13,weight:"bold","aria-hidden":"true"}),t("tasks.new")]})]}),eT?(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowX:"auto"},children:(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(4, minmax(0, 1fr))",gap:16,minWidth:"56rem",height:"100%",padding:"4px 16px 16px"},children:c8.map(e=>{let r="todo"===e?ep:eu[e],o=c7[e],i=e=>(0,n.jsx)(uo,{task:e,folderName:e.projectRoot?eI.get(e.projectRoot)??null:null,now:I,onOpen:()=>{T.current||P(e.id)},onStart:()=>void ex(()=>(0,di.oQ)(e.id,e.projectRoot,"start")),onCancel:()=>{_(e),K(!0)},onRetry:()=>{Y(e),X("retry"),Q(!0)},onRequeue:()=>{Y(e),X("requeue"),Q(!0)},onViewSession:()=>ef(e),onMerge:()=>{c5(e)?(et(e),en(!0)):em(e)},onArchive:()=>void ex(()=>(0,di.et)(e.id,e.projectRoot,null==e.archivedAt)),onEdit:()=>{L(e),$(!0)}},e.id);return(0,n.jsxs)("div",{ref:"inProgress"===e?w:void 0,style:{display:"flex",flexDirection:"column",minHeight:0,gap:8},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,height:24,flexShrink:0,padding:"0 2px"},children:[(0,n.jsx)("span",{style:{width:3,height:14,borderRadius:999,background:o.marker,flexShrink:0},"aria-hidden":"true"}),(0,n.jsx)("h2",{style:{fontSize:12,fontWeight:600,color:"var(--text)"},children:t(`tasks.col${e[0].toUpperCase()}${e.slice(1)}`)}),(0,n.jsx)("span",{style:{borderRadius:999,background:"var(--bg-hover)",padding:"1px 8px",fontSize:10,fontWeight:600,color:"var(--text-muted)"},children:r.length}),(0,n.jsx)("div",{style:{flex:1}}),"done"===e&&eu.done.some(e=>null==e.archivedAt)?(0,n.jsx)("button",{type:"button",onClick:eC,style:{background:"none",border:"none",cursor:"pointer",fontSize:11,color:"var(--text-muted)",padding:"2px 6px",borderRadius:6},children:t("tasks.archiveAllDone")}):null]}),0===r.length?(0,n.jsx)("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:4,borderRadius:12,border:"1px dashed var(--border)",padding:16,textAlign:"center",..."inProgress"===e&&x?m?{borderColor:"var(--accent)",background:"rgba(37,99,235,0.08)"}:{borderColor:"var(--accent)"}:{}},children:(0,n.jsx)("p",{style:{fontSize:12,color:"var(--text-muted)"},children:t(`tasks.emptyCol${e[0].toUpperCase()}${e.slice(1)}`)})}):(0,n.jsx)("div",{style:{flex:1,minHeight:0,overflowY:"auto",borderRadius:12,transition:"background 0.15s, box-shadow 0.15s",..."inProgress"===e&&x?m?{background:"rgba(37,99,235,0.06)",boxShadow:"inset 0 0 0 2px var(--accent)"}:{boxShadow:"inset 0 0 0 1px rgba(37,99,235,0.25)"}:{}},children:(0,n.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:16,paddingBottom:4},children:r.map(t=>"todo"===e?(0,n.jsx)("div",{draggable:!0,onDragStart:e=>{var r,n;e.dataTransfer.effectAllowed="move",r=e.clientX,n=e.clientY,T.current=!0,R.current=!1,k.current={x:r,y:n},f({task:t,width:b.current?.width??280})},onDrag:e=>{var t,r;let n,o;return k.current={x:t=e.clientX,y:r=e.clientY},ey(t,r),void((o=null!=(n=w.current?.getBoundingClientRect())&&t>=n.left&&t<=n.right&&r>=n.top&&r<=n.bottom)!==m&&v(o))},onDragEnd:e=>ew(t,e.clientX,e.clientY),onPointerDown:eb,style:{cursor:"grab",opacity:x?.task.id===t.id?.4:1},children:i(t)},t.id):(0,n.jsx)("div",{children:i(t)},t.id))})})]},e)})})}):(0,n.jsxs)("div",{style:{flex:1,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:12,padding:32,textAlign:"center"},children:[(0,n.jsx)(eV.x,{size:40,color:"var(--text-dim)",opacity:.4,"aria-hidden":"true"}),(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,n.jsx)("p",{style:{fontSize:14,fontWeight:500,color:"var(--text)"},children:t("tasks.empty")}),(0,n.jsx)("p",{style:{maxWidth:320,fontSize:12,color:"var(--text-muted)",lineHeight:1.6},children:t("tasks.emptyHint")})]}),(0,n.jsxs)("button",{type:"button",onClick:ev,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"7px 14px",borderRadius:8,background:"var(--accent)",color:"var(--accent-fg)",border:"none",fontSize:12,fontWeight:600,cursor:"pointer"},children:[(0,n.jsx)(y.F,{size:13,weight:"bold","aria-hidden":"true"}),t("tasks.new")]})]}),(0,n.jsx)(uu,{open:E,onOpenChange:$,task:W,defaultProject:N?.projectRoot??a??e??null,projects:eR,prefillTitle:N?N.text.slice(0,80):void 0,prefillPrompt:N?N.text:void 0,onSubmit:async(e,t,n)=>{await ex(async()=>{let{createTaskApi:o}=await Promise.resolve().then(r.bind(r,23084)),{updateTaskApi:i}=await Promise.resolve().then(r.bind(r,23084));W?await i(W.id,e,{title:t,config:n}):await o({projectRoot:e,title:t,config:n})}),$(!1),A(null)}}),(0,n.jsx)(ud,{open:null!=F,onOpenChange:e=>{e||P(null)},task:eh,onViewSession:ef,onMerge:em,onEdit:e=>{L(e),$(!0)},onCancel:e=>{_(e),K(!0)},onRetry:e=>{Y(e),X("retry"),Q(!0)},onRequeue:e=>{Y(e),X("requeue"),Q(!0)},onComplete:e=>{et(e),en(!0)}}),(0,n.jsx)(up,{open:O,onOpenChange:B,task:D}),(0,n.jsx)(ui,{open:q,onOpenChange:K,task:U}),(0,n.jsx)(uh,{open:Z,onOpenChange:Q,task:V,kind:G}),(0,n.jsx)(us,{open:er,onOpenChange:en,task:ee}),(0,n.jsx)(uf,{open:ea&&null!=eg,onOpenChange:ed,task:eg}),(0,n.jsx)(ux,{open:eo,onOpenChange:ei,projectRoot:a}),x?(0,u.createPortal)((0,n.jsx)("div",{ref:j,style:{position:"fixed",left:0,top:0,zIndex:999,pointerEvents:"none",width:x.width,willChange:"transform"},"aria-hidden":"true",children:(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8,borderRadius:12,border:m?"1px solid var(--accent)":"1px solid var(--border)",background:"var(--bg-panel)",padding:12,boxShadow:"0 8px 24px rgba(0,0,0,0.2)",transform:"rotate(-1deg)"},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[(0,n.jsx)("span",{style:{minWidth:0,overflowWrap:"break-word",fontSize:13,fontWeight:500},children:x.task.title}),(0,n.jsx)(ur,{task:x.task})]}),m?(0,n.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,fontWeight:600,color:"var(--accent)"},children:[(0,n.jsx)(c6.j,{size:11,weight:"bold","aria-hidden":"true"}),t("tasks.dropToStart")]}):null]})}),document.body):null]})}var uw=r(62235),uS=r(1022);function uC(){return!!window.__TAURI_INTERNALS__}let uz=null;function uT(){return uz||(uz=r.e(8518).then(r.bind(r,38518)).then(e=>e.getCurrentWindow())),uz}async function uR(e){let t=await uT();await e(t)}async function uI(){await uR(e=>e.minimize())}async function uM(){await uR(e=>e.toggleMaximize())}async function uE(){await uR(e=>e.startDragging())}async function u$(){await uR(e=>e.close())}async function uW(){return(await uT()).isMaximized()}function uL(){let[e,t]=(0,o.useState)(null);return(0,o.useEffect)(()=>{uC()&&t(function(){if("u"<typeof navigator)return null;let e=navigator.platform||"";return/mac/i.test(e)?"macos":/win/i.test(e)?"windows":/linux/i.test(e)?"linux":null}())},[]),{platform:e,isDesktop:null!==e,isMacOS:"macos"===e,dragRegionProps:e?{"data-tauri-drag-region":!0}:{}}}let uN="pi-web-island-pos";function uA(e,t,r,n,o,i){return{x:Math.min(Math.max(0,e),Math.max(0,r-o)),y:Math.min(Math.max(0,t),Math.max(0,n-i))}}let uF={display:"flex",alignItems:"center",justifyContent:"center",width:26,height:26,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",borderRadius:7,transition:"background 0.12s, color 0.12s"};function uP({onRefreshSession:e}={}){let{t:t}=(0,J.s)(),{isDark:r}=eN(),{isDesktop:i,isMacOS:s}=uL(),l=i&&!s,[a,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),[p,h]=(0,o.useState)(null),g=(0,o.useRef)(null),x=(0,o.useRef)(null);(0,o.useEffect)(()=>{l&&uT().then(()=>void 0,e=>{throw uz=null,e}).catch(e=>{console.error("[DynamicIsland] window API preload failed:",e)})},[l]);let f=(0,o.useCallback)(e=>{e().catch(e=>{console.error("[DynamicIsland] window command failed:",e),u(String(e)),window.setTimeout(()=>u(null),4e3)})},[]),m=(0,o.useCallback)(()=>{window.location.reload()},[]);(0,o.useEffect)(()=>{if(!uC()||!l)return;let e=()=>{uW().then(d)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[l]),(0,o.useEffect)(()=>{if(l)try{let e=localStorage.getItem(uN);if(e){let t=JSON.parse(e);"number"==typeof t.x&&"number"==typeof t.y&&h(uA(t.x,t.y,window.innerWidth,window.innerHeight,168,34))}}catch{}},[l]),(0,o.useEffect)(()=>{if(l&&p)try{localStorage.setItem(uN,JSON.stringify(p))}catch{}},[p,l]);let[v,y]=(0,o.useState)(0);(0,o.useEffect)(()=>{if(!l)return;let e=()=>{y(window.innerWidth),h(e=>e?uA(e.x,e.y,window.innerWidth,window.innerHeight,168,34):e)};return e(),window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[l]);let b=(0,o.useCallback)(e=>{if(0!==e.button||e.target.closest?.("[data-island-btn]"))return;let t=g.current;if(!t)return;let r=t.getBoundingClientRect();x.current={startX:e.clientX,startY:e.clientY,origX:r.left,origY:r.top},e.currentTarget.setPointerCapture(e.pointerId)},[]),k=(0,o.useCallback)(e=>{let t=x.current;if(!t)return;let r=e.clientX-t.startX,n=e.clientY-t.startY;h(uA(t.origX+r,t.origY+n,window.innerWidth,window.innerHeight,168,34))},[]),j=(0,o.useCallback)(e=>{x.current=null;try{e.currentTarget.releasePointerCapture(e.pointerId)}catch{}},[]),w=(0,o.useCallback)(()=>uM().then(()=>{d(e=>!e)}),[]),S=(0,o.useCallback)(e=>{if(!x.current&&!e.target.closest?.("[data-island-btn]")){h(null);try{localStorage.removeItem(uN)}catch{}}},[]);if(!l)return null;let z=v||window.innerWidth,T=null!==p?p.x:Math.max(0,z-168-14);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:g,role:"toolbar","aria-label":t("desktop.islandLabel"),title:t("desktop.islandResetHint"),onPointerDown:b,onPointerMove:k,onPointerUp:j,onPointerCancel:j,onDoubleClick:S,onMouseDown:e=>e.stopPropagation(),onDoubleClickCapture:e=>e.stopPropagation(),style:{position:"fixed",top:null!==p?p.y:100,left:T,zIndex:700,display:"flex",alignItems:"center",gap:1,padding:"3px 5px",borderRadius:999,background:"color-mix(in srgb, var(--bg-panel) 88%, transparent)",border:"1px solid var(--border)",boxShadow:r?"0 6px 24px rgba(0,0,0,0.45)":"0 6px 20px rgba(0,0,0,0.12)",cursor:"grab",userSelect:"none",touchAction:"none"},children:[(0,n.jsx)("span",{"data-island-grip":!0,"aria-hidden":"true",title:t("desktop.islandDrag"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:12,height:26,flexShrink:0,marginRight:2,color:"var(--text-dim)",cursor:"grab"},children:(0,n.jsxs)("svg",{width:"6",height:"14",viewBox:"0 0 6 14",fill:"currentColor","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"1.5",cy:"2",r:"1.2"}),(0,n.jsx)("circle",{cx:"4.5",cy:"2",r:"1.2"}),(0,n.jsx)("circle",{cx:"1.5",cy:"7",r:"1.2"}),(0,n.jsx)("circle",{cx:"4.5",cy:"7",r:"1.2"}),(0,n.jsx)("circle",{cx:"1.5",cy:"12",r:"1.2"}),(0,n.jsx)("circle",{cx:"4.5",cy:"12",r:"1.2"})]})}),e&&(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.refreshSession"),title:t("desktop.refreshSession"),onClick:()=>{try{e()}catch(e){console.error("[DynamicIsland] refresh session failed:",e)}},style:uF,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(uS.P,{size:13,"aria-hidden":"true"})}),(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.reloadPage"),title:t("desktop.reloadPage"),onClick:m,style:uF,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(C.S,{size:13,"aria-hidden":"true"})}),(0,n.jsx)("span",{"aria-hidden":"true",style:{width:1,height:18,flexShrink:0,background:"var(--border)",margin:"0 3px"}}),(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.minimize"),title:t("desktop.minimize"),onClick:()=>f(uI),style:uF,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,n.jsx)("line",{x1:"1",y1:"5",x2:"9",y2:"5"})})}),(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t(a?"desktop.restore":"desktop.maximize"),title:t(a?"desktop.restore":"desktop.maximize"),onClick:()=>f(w),style:uF,onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:a?(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,n.jsx)("rect",{x:"2",y:"0.5",width:"7.5",height:"7.5"}),(0,n.jsx)("path",{d:"M0.5 2.5 V9.5 H7.5"})]}):(0,n.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,n.jsx)("rect",{x:"0.5",y:"0.5",width:"9",height:"9"})})}),(0,n.jsx)("button",{type:"button","data-island-btn":!0,"aria-label":t("desktop.close"),title:t("desktop.close"),onClick:()=>f(u$),style:uF,onMouseEnter:e=>{e.currentTarget.style.background="#e81123",e.currentTarget.style.color="#fff"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,n.jsx)("line",{x1:"0",y1:"0",x2:"10",y2:"10"}),(0,n.jsx)("line",{x1:"10",y1:"0",x2:"0",y2:"10"})]})})]}),c&&(0,n.jsx)("div",{role:"alert",style:{position:"fixed",top:(null!==p?p.y:100)+34+6,left:T,zIndex:700,maxWidth:280,padding:"5px 10px",borderRadius:8,background:"var(--bg-panel)",border:"1px solid var(--status-error, #f85149)",color:"var(--status-error, #f85149)",fontSize:11,lineHeight:1.5,wordBreak:"break-all",boxShadow:r?"0 6px 24px rgba(0,0,0,0.45)":"0 6px 20px rgba(0,0,0,0.12)",pointerEvents:"none"},children:c})]})}function uD(){try{return window.localStorage}catch{return null}}let uH="pi-web:desktop-server-hint-seen";function uO(e=uD()){if(e)try{e.setItem(uH,"1")}catch{}}function uB(){let{t:e}=(0,J.s)(),[t,r]=(0,o.useState)(!1);(0,o.useEffect)(()=>{let e=!1;try{e=new URLSearchParams(window.location.search).has("piweb_connected")}catch{e=!1}e&&function(e=uD()){if(!e)return!1;try{return"1"!==e.getItem(uH)}catch{return!1}}()&&r(!0)},[]);let i=(0,o.useCallback)(()=>{uO(),r(!1)},[]),s=(0,o.useCallback)(()=>{uO(),r(!1),window.location.href="piweb-switch://manage"},[]);return t?(0,n.jsxs)("div",{role:"status",style:{position:"fixed",top:56,right:16,zIndex:700,width:288,padding:"14px 16px 14px",borderRadius:12,background:"var(--bg-panel)",border:"1px solid var(--border)",boxShadow:"0 12px 36px rgba(0,0,0,0.32)",color:"var(--text)"},children:[(0,n.jsx)("span",{"aria-hidden":"true",style:{position:"absolute",top:-6,right:28,width:10,height:10,background:"var(--bg-panel)",borderTop:"1px solid var(--border)",borderLeft:"1px solid var(--border)",transform:"rotate(45deg)"}}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",gap:10},children:[(0,n.jsx)(L.X,{size:18,color:"var(--accent)",style:{flexShrink:0,marginTop:1}}),(0,n.jsxs)("div",{style:{minWidth:0,flex:1},children:[(0,n.jsx)("div",{style:{fontSize:13.5,fontWeight:600,lineHeight:1.45},children:e("desktop.serverHintTitle")}),(0,n.jsx)("p",{style:{margin:"6px 0 0",fontSize:12.5,lineHeight:1.65,color:"var(--text-muted)"},children:e("desktop.serverHintBody")})]}),(0,n.jsx)("button",{type:"button",onClick:i,"aria-label":e("desktop.serverHintDismiss"),title:e("desktop.serverHintDismiss"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,flexShrink:0,background:"none",border:"none",cursor:"pointer",color:"var(--text-dim)"},children:(0,n.jsx)(h.X,{size:14,"aria-hidden":"true"})})]}),(0,n.jsx)("button",{type:"button",onClick:s,style:{marginTop:12,width:"100%",display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:"8px 12px",borderRadius:9,background:"var(--accent)",border:"none",color:"var(--accent-fg)",fontSize:13,fontWeight:600,cursor:"pointer"},children:e("desktop.serverHintAction")})]}):null}function uU({isDark:e,toggleTheme:t,translate:r}){let[i,s]=(0,o.useState)(!1);(0,o.useEffect)(()=>{s(!0)},[]);let l=r(i?e?"desktop.switchToLight":"desktop.switchToDark":"desktop.switchToLight");return(0,n.jsx)("button",{className:"app-no-drag",suppressHydrationWarning:!0,onClick:e=>{let r=e.currentTarget.getBoundingClientRect();t({x:r.left+r.width/2,y:r.top+r.height/2})},title:l,"aria-label":l,"aria-pressed":!i||e,style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:i?e?(0,n.jsx)(ed.b,{size:16,"aria-hidden":"true"}):(0,n.jsx)(ea.A,{size:16,"aria-hidden":"true"}):(0,n.jsx)(ed.b,{size:16,"aria-hidden":"true"})})}function u_({topBarRef:e,sidebarOpen:t,onSidebarToggle:r,isDark:i,toggleTheme:s,isMobile:l,showTasks:a,tasksBoardEnabled:d,onToggleTasks:c,systemPrompt:u,activeTopPanel:p,topPanelPos:h,sessionStats:g,selectedSession:f,contextUsage:m,copiedSessionField:v,onCopySessionField:y,rightPanelOpen:b,onToggleFilePanel:k,onRefreshSession:w,onOpenSettings:S,sessionTitle:z,onWorkspaceControlsHostChange:T,onTitleRightHostChange:R,desktopChrome:I,windowDrag:M}){let E,$,N,A,F,P,D,H,O,B,U,{t:_}=(0,J.s)(),[q,K]=(0,o.useState)(!1);W(q,()=>K(!1));let[V,Y]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{try{Y(new URLSearchParams(window.location.search).has("piweb_connected"))}catch{Y(!1)}},[]),(0,n.jsxs)(n.Fragment,{children:[V&&(0,n.jsx)(uB,{}),(0,n.jsxs)("div",{ref:e,className:"app-title-bar",...I?.dragRegionProps,...M,style:{display:"flex",alignItems:"center",flexShrink:0,borderBottom:"1px solid var(--border)",height:48,background:"var(--bg-panel)",position:"relative",zIndex:600,paddingLeft:76*!!I?.isMacOS},children:[(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",minWidth:0,height:"100%",flex:"0 1 auto",position:"relative",zIndex:1},children:[(0,n.jsx)("button",{className:"app-no-drag",onClick:r,title:t?_("desktop.hideSidebar"):_("desktop.showSidebar"),"aria-label":t?_("desktop.hideSidebar"):_("desktop.showSidebar"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,flexShrink:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",transition:"color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)"},children:t?(0,n.jsx)(uw.V,{size:16,"aria-hidden":"true"}):(0,n.jsx)(j.B,{size:16,"aria-hidden":"true"})}),(0,n.jsx)("div",{className:"app-no-drag",ref:T,style:{flex:"0 1 auto",minWidth:0,maxWidth:"min(60vw, 820px)",height:"100%",display:"flex",alignItems:"center",padding:"0 8px 0 0",overflow:"visible"}})]}),(0,n.jsxs)("div",{className:"app-title-drag",style:{...l?{position:"relative",flex:"1 1 auto",minWidth:0}:{position:"absolute",left:"var(--pi-titlebar-sidebar-offset, 0px)",right:0,top:0,bottom:0},display:"flex",alignItems:"center",justifyContent:l?"flex-start":"center",padding:l?"0 8px 0 4px":"0 12px",overflow:"hidden",userSelect:"none"},children:[z&&(0,n.jsx)("button",{type:"button",className:"app-no-drag",onClick:()=>{l&&K(!0)},style:{display:"block",flex:"0 1 auto",minWidth:0,maxWidth:l?"100%":"calc(100% - 320px)",fontSize:12,fontWeight:500,color:"var(--text-muted)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",background:"none",border:"none",cursor:"pointer",padding:"2px 6px",borderRadius:5},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.background="none"},children:z}),(0,n.jsx)("div",{className:"app-no-drag",ref:R,style:{flexShrink:0,display:"flex",alignItems:"center",marginLeft:4}})]}),(0,n.jsxs)("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:3,minWidth:0,height:"100%",flexShrink:+!l,overflow:"hidden",marginLeft:"auto",position:"relative",zIndex:1},children:[!l&&d&&(0,n.jsx)("button",{className:"app-no-drag",onClick:c,title:a?_("desktop.hideTaskBoard"):_("desktop.showTaskBoard"),"aria-label":a?_("desktop.hideTaskBoard"):_("desktop.showTaskBoard"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:a?"var(--bg-selected)":"none",border:"none",color:a?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=a?"var(--bg-selected)":"none",e.currentTarget.style.color=a?"var(--text)":"var(--text-muted)"},children:(0,n.jsx)(eV.x,{size:16,"aria-hidden":"true"})}),(0,n.jsx)("button",{className:"app-no-drag",onClick:k,title:b?_("desktop.hideFilePanel"):_("desktop.showFilePanel"),"aria-label":b?_("desktop.hideFilePanel"):_("desktop.showFilePanel"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:b?"var(--bg-selected)":"none",border:"none",color:b?"var(--text)":"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background=b?"var(--bg-selected)":"none",e.currentTarget.style.color=b?"var(--text)":"var(--text-muted)"},children:(0,n.jsx)(uw.V,{size:16,"aria-hidden":"true",style:{transform:"scaleX(-1)"}})}),(0,n.jsx)(uU,{isDark:i,toggleTheme:s,translate:_}),V&&(0,n.jsx)("button",{className:"app-no-drag",type:"button",onClick:()=>{window.location.href="piweb-switch://manage"},title:_("desktop.serverSwitch"),"aria-label":_("desktop.serverSwitch"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(L.X,{size:16,"aria-hidden":"true"})}),!V&&!l&&(0,n.jsx)("button",{className:"app-no-drag",type:"button",onClick:w,title:_("desktop.refreshSession"),"aria-label":_("desktop.refreshSession"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(C.S,{size:16,"aria-hidden":"true"})}),(0,n.jsx)("button",{className:"app-no-drag",type:"button",onClick:S,title:_("desktop.settings"),"aria-label":_("desktop.settings"),style:{display:"flex",alignItems:"center",justifyContent:"center",width:36,height:36,padding:0,background:"none",border:"none",color:"var(--text-muted)",cursor:"pointer",flexShrink:0,transition:"background 0.12s, color 0.12s"},onMouseEnter:e=>{e.currentTarget.style.background="var(--bg-hover)",e.currentTarget.style.color="var(--text)"},onMouseLeave:e=>{e.currentTarget.style.background="none",e.currentTarget.style.color="var(--text-muted)"},children:(0,n.jsx)(c1.O,{size:16,"aria-hidden":"true"})})]})]}),(0,n.jsx)(uP,{onRefreshSession:w}),p&&h&&(0,n.jsxs)("div",{style:{position:"fixed",top:h.top,left:h.left,width:h.width,maxHeight:`calc(100dvh - ${h.top}px)`,overflowY:"auto",zIndex:500},children:["system"===p&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)"},children:u?(0,n.jsx)("div",{style:{maxHeight:"min(600px, 75vh)",overflowY:"auto",padding:"12px 16px",color:"var(--text-muted)",fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",fontFamily:"var(--font-mono)"},children:u}):""===u?(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"System prompt is empty (tools are disabled)"}):(0,n.jsx)("div",{style:{padding:"10px 16px",fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:"Send a message to load the system prompt"})}),"session"===p&&(0,n.jsx)("div",{style:{background:"var(--bg-panel)",borderBottom:"1px solid var(--border)",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",padding:"12px 16px"},children:g?(E=[...g.sessionName?[{label:_("desktop.name"),value:g.sessionName,copyField:null}]:[],{label:_("desktop.sessionInfoFile"),value:g.sessionFile??_("desktop.sessionInfoInMemory"),copyField:"file"},{label:_("desktop.sessionInfoId"),value:g.sessionId,copyField:"id"}],$=[[_("desktop.sessionInfoUser"),g.userMessages.toLocaleString()],[_("desktop.sessionInfoAssistant"),g.assistantMessages.toLocaleString()],[_("desktop.sessionInfoToolCalls"),g.toolCalls.toLocaleString()],[_("desktop.sessionInfoToolResults"),g.toolResults.toLocaleString()],[_("desktop.sessionInfoTotal"),g.totalMessages.toLocaleString()]],N=[[_("desktop.sessionInfoInput"),g.tokens.input.toLocaleString()],[_("desktop.sessionInfoOutput"),g.tokens.output.toLocaleString()],...g.tokens.cacheRead>0?[[_("desktop.sessionInfoCacheRead"),g.tokens.cacheRead.toLocaleString()]]:[],...g.tokens.cacheWrite>0?[[_("desktop.sessionInfoCacheWrite"),g.tokens.cacheWrite.toLocaleString()]]:[],[_("desktop.sessionInfoTotal"),g.tokens.total.toLocaleString()]],A=m??g.contextUsage,P=[...g.cost>0?[[_("desktop.sessionInfoCost"),`$${g.cost.toFixed(4)}`]]:[],...A?.contextWindow?[[_("desktop.sessionInfoContext"),`${null!==A.percent?`${A.percent.toFixed(1)}%`:"?"} / ${(F=A.contextWindow)>=1e6?`${(F/1e6).toFixed(1)}M`:F>=1e3?`${(F/1e3).toFixed(0)}k`:String(F)}`]]:[]],D=(e,t,r="left",o=!1)=>(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:e}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:o?"max-content max-content":"auto minmax(0, 1fr)",columnGap:o?14:12,rowGap:4,justifyContent:o?"start":void 0},children:t.map(([t,i])=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:t}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:o?"normal":"anywhere",textAlign:r,whiteSpace:"right"===r?"nowrap":"normal"},children:i})]},`${e}:${t}`))})]}),H=(e,t)=>{let r=v===e;return(0,n.jsx)("button",{type:"button",title:r?_("desktop.copied"):_({file:"desktop.copyFilePath",id:"desktop.copySessionId",projectDir:"desktop.copyProjectDir",gitBranch:"desktop.copyGitBranch",gitWorktree:"desktop.copyGitWorktree"}[e]),onClick:()=>y(e,t),style:{alignSelf:"start",display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,marginTop:-2,color:r?"var(--accent)":"var(--text-dim)",background:"transparent",border:"1px solid var(--border)",borderRadius:4,cursor:"pointer",flex:"0 0 auto",transition:"color 0.12s, border-color 0.12s, background 0.12s"},onMouseEnter:e=>{e.currentTarget.style.color="var(--accent)",e.currentTarget.style.borderColor="var(--accent)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color=r?"var(--accent)":"var(--text-dim)",e.currentTarget.style.borderColor="var(--border)",e.currentTarget.style.background="transparent"},children:r?(0,n.jsx)(x.J,{size:12,"aria-hidden":"true"}):(0,n.jsx)(sa.Q,{size:12,"aria-hidden":"true"})})},O=(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:_("desktop.sessionInfoTitle")}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:E.map(e=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,n.jsx)("div",{children:e.copyField?H(e.copyField,e.value):null})]},`session-info:${e.label}`))})]}),U=(B=[...f?[{label:_("desktop.projectDir"),value:f.projectRoot??f.cwd,copyField:"projectDir"}]:[],...f?.branch?[{label:_("desktop.gitBranch"),value:f.branch,copyField:"gitBranch"}]:[],...f?.isWorktree?[{label:_("desktop.gitWorktree"),value:f.cwd,copyField:"gitWorktree"}]:[]]).length>0?(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("div",{style:{fontSize:11,fontWeight:700,color:"var(--text)",marginBottom:6},children:_("desktop.projectSection")}),(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"auto minmax(0, 1fr) auto",columnGap:12,rowGap:8,alignItems:"start"},children:B.map(e=>(0,n.jsxs)("div",{style:{display:"contents"},children:[(0,n.jsx)("div",{style:{color:"var(--text-dim)",whiteSpace:"nowrap"},children:e.label}),(0,n.jsx)("div",{style:{color:"var(--text-muted)",minWidth:0,overflowWrap:"anywhere",wordBreak:"break-word",whiteSpace:"normal"},children:e.value}),(0,n.jsx)("div",{children:e.copyField?H(e.copyField,e.value):null})]},`project-info:${e.label}`))})]}):null,(0,n.jsxs)("div",{style:{display:"grid",gridTemplateColumns:l?"1fr":"minmax(360px, 1.7fr) minmax(140px, 0.55fr) minmax(190px, 0.75fr)",gap:l?16:24,fontSize:12,lineHeight:1.5,fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:l?16:20,minWidth:0},children:[O,U]}),D(_("desktop.sessionInfoMessages"),$),D(_("desktop.sessionInfoTokens"),[...N,...P],"right",!0)]})):(0,n.jsx)("div",{style:{fontSize:12,color:"var(--text-muted)",fontStyle:"italic"},children:_("desktop.sendMessageForSessionInfo")})})]}),q&&z&&(0,n.jsx)("div",{className:"app-no-drag",onClick:()=>K(!1),style:{position:"fixed",inset:0,zIndex:3e3,display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:48,background:"rgba(0,0,0,0.35)",cursor:"pointer"},children:(0,n.jsxs)("div",{role:"dialog","aria-label":z,style:{position:"relative",maxWidth:"min(560px, calc(100vw - 32px))",maxHeight:"min(60vh, 400px)",overflow:"auto",background:"var(--bg-panel)",border:"1px solid var(--border)",borderRadius:12,boxShadow:"0 16px 40px rgba(0,0,0,0.3)",padding:"14px 40px 14px 18px",fontSize:13,lineHeight:1.6,color:"var(--text)",wordBreak:"break-word",whiteSpace:"pre-wrap",cursor:"default"},children:[z,(0,n.jsx)("button",{type:"button","aria-label":_("i18n.close"),title:_("i18n.close"),onClick:e=>{e.stopPropagation(),K(!1)},style:{position:"sticky",top:0,float:"right",marginLeft:8,display:"inline-flex",alignItems:"center",justifyContent:"center",width:24,height:24,padding:0,border:"none",borderRadius:5,background:"none",color:"var(--text-muted)",cursor:"pointer",fontSize:14,lineHeight:1},onMouseEnter:e=>{e.currentTarget.style.color="var(--text)",e.currentTarget.style.background="var(--bg-hover)"},onMouseLeave:e=>{e.currentTarget.style.color="var(--text-muted)",e.currentTarget.style.background="none"},children:"✕"})]})})]})}function uq({cwd:e,busy:t,error:r,onCancelAction:o,onConfirmAction:i}){let{t:s}=(0,J.s)();return W(!t,o),(0,n.jsx)("div",{role:"presentation",style:{position:"fixed",inset:0,zIndex:1100,display:"flex",alignItems:"center",justifyContent:"center",padding:16,background:"rgba(0, 0, 0, 0.4)"},children:(0,n.jsxs)("section",{role:"dialog","aria-modal":"true","aria-labelledby":"project-trust-title",style:{width:440,maxWidth:"100%",border:"1px solid var(--border)",borderRadius:8,background:"var(--bg-panel)",boxShadow:"0 12px 36px rgba(0, 0, 0, 0.24)",overflow:"hidden"},children:[(0,n.jsxs)("div",{style:{display:"flex",gap:12,padding:"18px 18px 14px"},children:[(0,n.jsx)(ai.o,{size:21,weight:"duotone",color:"var(--accent-orange)",style:{flexShrink:0,marginTop:1},"aria-hidden":"true"}),(0,n.jsxs)("div",{style:{minWidth:0},children:[(0,n.jsx)("h2",{id:"project-trust-title",style:{margin:0,fontSize:15,fontWeight:700,color:"var(--text)"},children:s("desktop.trustProjectTitle")}),(0,n.jsx)("p",{style:{margin:"7px 0 0",fontSize:12,lineHeight:1.6,color:"var(--text-muted)"},children:s("desktop.trustProjectBody")}),(0,n.jsx)("code",{style:{display:"block",marginTop:10,padding:"8px 10px",border:"1px solid var(--border)",borderRadius:5,background:"var(--bg)",color:"var(--text)",fontFamily:"var(--font-mono)",fontSize:11,overflowWrap:"anywhere"},children:e}),r&&(0,n.jsx)("div",{role:"alert",style:{marginTop:10,color:"var(--accent-red)",fontSize:12,lineHeight:1.5},children:r})]})]}),(0,n.jsxs)("footer",{style:{display:"flex",justifyContent:"flex-end",gap:8,padding:"10px 18px",borderTop:"1px solid var(--border)"},children:[(0,n.jsx)("button",{type:"button",onClick:o,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--border)",borderRadius:5,background:"transparent",color:"var(--text-muted)",cursor:t?"not-allowed":"pointer",fontSize:12},children:s("desktop.cancel")}),(0,n.jsx)("button",{type:"button",onClick:i,disabled:t,style:{height:32,padding:"0 12px",border:"1px solid var(--accent)",borderRadius:5,background:"var(--accent)",color:"white",cursor:t?"wait":"pointer",opacity:t?.7:1,fontSize:12,fontWeight:600},children:s(t?"desktop.trustingProject":"desktop.trustProject")})]})]})})}function uK(e,t,r){let n=Number.isFinite(e)?e:t,o=Math.max(t,r);return Math.round(Math.max(t,Math.min(o,n)))}function uV(e){return uK(.42*e,360,640)}function uJ(e,t){try{window.localStorage.setItem(e,String(t))}catch{}}function uY(e){let{ariaLabel:t,cssVariable:r,defaultWidth:n,getDefaultWidth:i,getMaxWidth:s,growthDirection:l,maxWidth:a,minWidth:d,storageKey:c,widthRef:u}=e,p=(0,o.useRef)(null),h=(0,o.useRef)(null),g=(0,o.useRef)(!1),[x,f]=(0,o.useState)(n),[m,v]=(0,o.useState)(!1),[y,b]=(0,o.useState)(!1);(0,o.useEffect)(()=>{b(!0)},[]);let k=(0,o.useCallback)(()=>Math.min(a,Math.max(d,s())),[s,a,d]),j=(0,o.useCallback)(e=>uK(e,d,k()),[k,d]),w=(0,o.useCallback)(e=>{u.current=e;let t=`${e}px`;p.current?.style.setProperty(r,t),p.current?.parentElement?.style.setProperty(r,t)},[r,u]),S=(0,o.useCallback)((e,t={})=>{let{forcePersist:r=!1,persist:n=!0}=t,o=j(e),i=o!==u.current;return w(o),f(o),n&&(i||r)&&uJ(c,o),o},[w,j,c,u]),C=(0,o.useCallback)(e=>{document.body.style.cursor=e.previousCursor,document.body.style.userSelect=e.previousUserSelect},[]),z=(0,o.useCallback)(e=>{let t=h.current;if(t&&t.pointerId===e){h.current=null,C(t),v(!1),S(u.current,{forcePersist:!0});try{t.target.hasPointerCapture(e)&&t.target.releasePointerCapture(e)}catch{}}},[S,C,u]),T=(0,o.useCallback)(e=>{if("mouse"===e.pointerType&&0!==e.button)return;e.preventDefault(),e.stopPropagation();let t=h.current;t&&z(t.pointerId);let r=e.currentTarget;r.focus({preventScroll:!0}),r.setPointerCapture(e.pointerId),h.current={pointerId:e.pointerId,startX:e.clientX,startWidth:u.current,target:r,previousCursor:document.body.style.cursor,previousUserSelect:document.body.style.userSelect},document.body.style.cursor="col-resize",document.body.style.userSelect="none",v(!0)},[z,u]),R=(0,o.useCallback)(e=>{let t=h.current;if(!t||t.pointerId!==e.pointerId)return;if("mouse"===e.pointerType&&0===e.buttons)return void z(e.pointerId);e.preventDefault();let r="right"===l?1:-1,n=j(t.startWidth+(e.clientX-t.startX)*r);w(n),e.currentTarget.setAttribute("aria-valuenow",String(n)),e.currentTarget.setAttribute("aria-valuetext",`${n} px`)},[w,j,z,l]),I=(0,o.useCallback)(e=>{z(e.pointerId)},[z]),M=(0,o.useCallback)(e=>{z(e.pointerId)},[z]),E=(0,o.useCallback)(e=>{z(e.pointerId)},[z]),$=(0,o.useCallback)(()=>{S(i?.()??n,{forcePersist:!0})},[S,n,i]),W=(0,o.useCallback)(()=>{S(u.current)},[S,u]),L=(0,o.useCallback)(e=>{let t=e.shiftKey?32:12,r="right"===l?"ArrowRight":"ArrowLeft",n="right"===l?"ArrowLeft":"ArrowRight";e.key===r?(e.preventDefault(),S(u.current+t,{forcePersist:!0})):e.key===n?(e.preventDefault(),S(u.current-t,{forcePersist:!0})):"Home"===e.key?(e.preventDefault(),S(d,{forcePersist:!0})):"End"===e.key?(e.preventDefault(),S(k(),{forcePersist:!0})):"Enter"===e.key&&(e.preventDefault(),$())},[S,k,l,d,$,u]);return(0,o.useEffect)(()=>{if(g.current)return;g.current=!0;let e=function(e){try{let t=window.localStorage.getItem(e);if(null===t)return null;let r=Number.parseInt(t,10);return Number.isFinite(r)?r:null}catch{return null}}(c),t=S(e??i?.()??n,{persist:!1});null!==e&&e!==t&&uJ(c,t)},[S,n,i,c]),(0,o.useEffect)(()=>{if(!g.current)return;S(u.current);let e=()=>{S(u.current)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[S,u]),(0,o.useEffect)(()=>{if(!m)return;let e=()=>{let e=h.current;e&&z(e.pointerId)},t=()=>{"visible"!==document.visibilityState&&e()};return window.addEventListener("blur",e),document.addEventListener("visibilitychange",t),()=>{window.removeEventListener("blur",e),document.removeEventListener("visibilitychange",t)}},[z,m]),(0,o.useEffect)(()=>()=>{let e=h.current;e&&(h.current=null,C(e))},[C]),{isResizing:m,panelRef:p,reclampWidth:W,separatorProps:{"aria-label":t,"aria-orientation":"vertical","aria-valuemax":y?k():a,"aria-valuemin":d,"aria-valuenow":x,"aria-valuetext":`${x} px`,onDoubleClick:$,onKeyDown:L,onLostPointerCapture:E,onPointerCancel:M,onPointerDown:T,onPointerMove:R,onPointerUp:I,role:"separator",tabIndex:0},width:x}}function uG({status:e}){return"running"===e||"starting"===e?(0,n.jsxs)("svg",{className:"animate-spin",width:"13",height:"13",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),(0,n.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}):"queued"===e?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M12 7v5l3 2"})]}):"failed"===e?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"m9 9 6 6M15 9l-6 6"})]}):"aborted"===e||"interrupted"===e?(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"M9 9h6v6H9z"})]}):(0,n.jsxs)("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("path",{d:"m8 12 3 3 5-6"})]})}function uX({session:e,main:t,selected:r,running:o,onSelect:i}){let{locale:s,t:l}=(0,J.s)(),a=e.relation?.kind==="subagent"?e.relation:null,d=o?"running":a?.status??"completed",c=t?l("agentSwitcher.main"):a?.description||n6(e),u=t?n6(e):`${a?.profile??l("agentSwitcher.subagent")} \xb7 ${function(e,t){let r=new Date(e).getTime();if(!Number.isFinite(r))return"";let n=Math.round((r-Date.now())/1e3),o=new Intl.RelativeTimeFormat(t,{numeric:"auto"});if(60>Math.abs(n))return o.format(n,"second");let i=Math.round(n/60);if(60>Math.abs(i))return o.format(i,"minute");let s=Math.round(i/60);return 24>Math.abs(s)?o.format(s,"hour"):o.format(Math.round(s/24),"day")}(e.modified,s)}`;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":r,onClick:i,style:{width:"100%",minHeight:56,display:"grid",gridTemplateColumns:"28px minmax(0, 1fr) auto",alignItems:"center",gap:9,padding:"7px 12px",border:"none",borderBottom:"1px solid var(--border)",borderLeft:r?"2px solid var(--accent)":"2px solid transparent",background:r?"var(--bg-selected)":"transparent",color:"var(--text)",cursor:"pointer",textAlign:"left"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--bg-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="transparent")},children:[(0,n.jsx)("span",{style:{width:28,height:28,display:"grid",placeItems:"center",color:t?"var(--text-muted)":"var(--accent)"},children:t?(0,n.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("circle",{cx:"12",cy:"8",r:"4"}),(0,n.jsx)("path",{d:"M4 21a8 8 0 0 1 16 0"})]}):(0,n.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"5",y:"7",width:"14",height:"11",rx:"2"}),(0,n.jsx)("path",{d:"M9 11h.01M15 11h.01M9 15h6M12 7V4M10 4h4"})]})}),(0,n.jsxs)("span",{style:{minWidth:0},children:[(0,n.jsx)("span",{style:{display:"block",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,fontWeight:r?600:500},title:c,children:c}),(0,n.jsx)("span",{style:{display:"block",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",color:"var(--text-dim)",fontSize:11},title:u,children:u})]}),(0,n.jsx)("span",{style:{display:"flex",alignItems:"center",gap:6,color:t&&!o?"var(--text-dim)":"running"===d||"starting"===d?"var(--accent)":"queued"===d?"var(--text-dim)":"completed"===d?"var(--status-success)":"failed"===d?"var(--status-error)":"aborted"===d?"var(--status-warning)":"var(--text-dim)",fontSize:11,whiteSpace:"nowrap"},children:t&&!o?r?l("agentSwitcher.current"):null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(uG,{status:d}),(0,n.jsx)("span",{children:l(`agentSwitcher.status.${d}`)})]})})]})}function uZ({rootSession:e,subagents:t,selectedSessionId:r,runningSessionIds:i,onSelectSession:s}){let{t:l}=(0,J.s)(),[a,d]=(0,o.useState)(""),c=(0,o.useMemo)(()=>[...t].sort((e,t)=>{let r=i.has(e.id);return r!==i.has(t.id)?r?-1:1:t.modified.localeCompare(e.modified)}),[i,t]),u=a.trim().toLowerCase(),p=u?c.filter(e=>{let t=e.relation?.kind==="subagent"?e.relation:null;return[t?.description,t?.profile,e.name,e.firstMessage].some(e=>e?.toLowerCase().includes(u))}):c,h=t.filter(e=>i.has(e.id)).length;return(0,n.jsx)("div",{role:"listbox","aria-label":l("agentSwitcher.title"),style:{background:"var(--bg-panel)",borderLeft:"1px solid var(--border)",borderRight:"1px solid var(--border)",borderBottom:"1px solid var(--border)",borderRadius:"0 0 6px 6px",boxShadow:"0 10px 28px rgba(0,0,0,0.10)",overflow:"hidden"},children:(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{style:{minHeight:44,display:"flex",alignItems:"center",gap:8,padding:"7px 12px",borderBottom:"1px solid var(--border)"},children:[(0,n.jsx)("strong",{style:{fontSize:12,fontWeight:600},children:l("agentSwitcher.title")}),(0,n.jsx)("span",{style:{color:"var(--text-dim)",fontSize:11},children:l("agentSwitcher.count",{count:t.length})}),h>0&&(0,n.jsx)("span",{style:{marginLeft:"auto",color:"var(--accent)",fontSize:11},children:l("agentSwitcher.runningCount",{count:h})})]}),t.length>8&&(0,n.jsx)("div",{style:{padding:8,borderBottom:"1px solid var(--border)"},children:(0,n.jsx)("input",{type:"search",value:a,onChange:e=>d(e.target.value),placeholder:l("agentSwitcher.search"),"aria-label":l("agentSwitcher.search"),style:{width:"100%",height:32,padding:"0 10px",border:"1px solid var(--border)",borderRadius:6,background:"var(--bg)",color:"var(--text)",fontSize:12,outline:"none"}})}),(0,n.jsxs)("div",{style:{maxHeight:"min(58dvh, 480px)",overflowY:"auto"},children:[(0,n.jsx)(uX,{session:e,main:!0,selected:e.id===r,running:i.has(e.id),onSelect:()=>s(e)}),p.map(e=>(0,n.jsx)(uX,{session:e,selected:e.id===r,running:i.has(e.id),onSelect:()=>s(e)},e.id)),0===p.length&&(0,n.jsx)("div",{style:{padding:"22px 12px",color:"var(--text-dim)",fontSize:12,textAlign:"center"},children:l("agentSwitcher.noMatches")})]})]})})}function uQ(){var e;let t,r,a=(0,s.useRouter)(),d=(0,s.useSearchParams)(),c=(0,o.useMemo)(()=>{let e;return{requestedCwd:e=d.get("cwd")?.trim()||null,sessionId:e?null:d.get("session"),sidebarCollapsed:"collapsed"===d.get("sidebar")}},[d]),{isDark:u,toggleTheme:p}=eN(),{t:h}=(0,J.s)(),g=tu(),[x,f]=(0,o.useState)(null),[m,v]=(0,o.useState)(null),[y,b]=(0,o.useState)(0),[k,j]=(0,o.useState)(0),[w,S]=(0,o.useState)(0),[C,z]=(0,o.useState)(!1),[T,R]=(0,o.useState)("models"),[I,M]=(0,o.useState)(0),[E,$]=(0,o.useState)(null),[W,L]=(0,o.useState)(!1),[N,A]=(0,o.useState)(!1),[F,P]=(0,o.useState)(null),[D,H]=(0,o.useState)(()=>!c.sidebarCollapsed),[O,B]=(0,o.useState)(!1);(0,o.useEffect)(()=>{g&&H(!1)},[g]),(0,o.useEffect)(()=>{B(!0)},[]);let U=(0,o.useRef)(null),_=(0,o.useRef)(null),[q,K]=(0,o.useState)(null),[V,Y]=(0,o.useState)(null),[G,X]=(0,o.useState)(null),Z=uL(),Q=function(){let{isDesktop:e,isMacOS:t}=uL(),r=(0,o.useCallback)(e=>{var t;0===e.button&&(t=e.target).closest("[data-tauri-drag-region]")&&!t.closest('button, a, input, textarea, select, [role="button"], [contenteditable="true"], [data-no-drag]')&&(e.preventDefault(),e.stopPropagation(),2===e.detail?uM():uE())},[]);return e&&!t?{onMouseDown:r}:{}}(),[ee,et]=(0,o.useState)(null),er=(0,o.useCallback)(e=>{et(e)},[]),[en,eo]=(0,o.useState)(null),ei=(0,o.useCallback)(e=>{eo(e)},[]),[es,el]=(0,o.useState)(null),ea=(0,o.useRef)(null),ed=(0,o.useCallback)((e,t)=>{ni(t).then(()=>{ea.current&&clearTimeout(ea.current),el(e),ea.current=setTimeout(()=>el(null),1400)})},[]);(0,o.useEffect)(()=>()=>{ea.current&&clearTimeout(ea.current)},[]);let[ec,eu]=(0,o.useState)(null),ep=(0,o.useCallback)(e=>{eu(e)},[]),[eh,eg]=(0,o.useState)(null),[ex,ef]=(0,o.useState)(null),em=(0,o.useCallback)(()=>{g&&H(!1),eg("session")},[g]),ev=(0,o.useCallback)(()=>{g&&eg(null),H(e=>!e)},[g]);(0,o.useEffect)(()=>{if(!eh||!_.current)return;let e=()=>{let e=_.current.getBoundingClientRect();ef({top:e.bottom,left:e.left,width:e.width})};e();let t=new ResizeObserver(e);return t.observe(_.current),()=>t.disconnect()},[eh]);let[ey,eb]=(0,o.useState)([]),[ek,ej]=(0,o.useState)(null),[ew,eS]=(0,o.useState)(!1),eC=(0,o.useRef)(!1);(0,o.useEffect)(()=>{let e;if(!eC.current){eC.current=!0;try{e=function(e){try{let t=JSON.parse(e??"null");if(!cY(t))return{tabs:[],activeId:null,open:!1};let r=[],n=new Set;for(let e of Array.isArray(t.tabs)?t.tabs:[]){if(!cY(e))continue;let t="string"==typeof e.id?e.id:"",o="string"==typeof e.filePath?e.filePath:"",i="string"==typeof e.label?e.label:"",s="subagent"===e.kind,l="string"==typeof e.sessionId?e.sessionId:"";!(!t||!i||n.has(t))&&(s?l:o)&&(n.add(t),r.push({id:t,label:i,filePath:o,..."terminal"===e.kind?{kind:"terminal"}:{},...s?{kind:"subagent",sessionId:l}:{},..."string"==typeof e.sourceSessionId?{sourceSessionId:e.sourceSessionId}:{},..."diff"===e.initialDisplayMode?{initialDisplayMode:"diff"}:{}}))}let o="string"==typeof t.activeId&&r.some(e=>e.id===t.activeId)?t.activeId:r[r.length-1]?.id??null;return{tabs:r,activeId:o,open:!0===t.open&&r.length>0}}catch{return{tabs:[],activeId:null,open:!1}}}(localStorage.getItem(cJ))}catch{return}0!==e.tabs.length&&(eb(e.tabs),ej(e.activeId),eS(e.open))}},[]),(0,o.useEffect)(()=>{if(eC.current)try{localStorage.setItem(cJ,JSON.stringify({tabs:ey.filter(e=>!e.closing).map(e=>({id:e.id,label:e.label,filePath:e.filePath,...e.kind?{kind:e.kind}:{},...e.sessionId?{sessionId:e.sessionId}:{},...e.sourceSessionId?{sourceSessionId:e.sourceSessionId}:{},...e.initialDisplayMode?{initialDisplayMode:e.initialDisplayMode}:{}})),activeId:ek,open:ew}))}catch{}},[ey,ek,ew]);let[ez,eT]=(0,o.useState)(!1),[eR,eI]=(0,o.useState)([]),[eM,eE]=(0,o.useState)(()=>new Set);(0,o.useEffect)(()=>{if(!ez)return void eI(e=>0===e.length?e:[]);let e=!1,t=()=>{fetch("/api/sessions",{cache:"no-store"}).then(e=>e.json()).then(t=>{e||(eI(t.sessions??[]),eE(new Set(t.runningSessionIds??[])))}).catch(()=>{})};t();let r=setInterval(t,3e3);return()=>{e=!0,clearInterval(r)}},[ez,x?.id,y]);let e$=(0,o.useCallback)(async e=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}`,{cache:"no-store"}),r=await t.json();if(!t.ok||!r.info)throw Error(r.error??`HTTP ${t.status}`);e9.current(r.info)}catch(e){console.error("[pi-web] failed to open session:",e instanceof Error?e.message:e)}},[]),eW=(0,o.useRef)(260),eL=(0,o.useRef)(uV(1366)),eA=(0,o.useCallback)(()=>uV(window.innerWidth),[]),eF=(0,o.useCallback)(()=>(function(e){let{viewportWidth:t,rightPanelOpen:r,rightPanelWidth:n}=e;if(t<=640)return 480;let o=t<960;return Math.min(480,t-(o?320:420)-(!o&&r?n:0))})({viewportWidth:window.innerWidth,rightPanelOpen:ew,rightPanelWidth:eL.current}),[ew]),eP=(0,o.useCallback)(()=>(function(e){let{viewportWidth:t,sidebarOpen:r,sidebarWidth:n}=e;return t<960?1200:Math.min(1200,t-420-(r?n:0))})({viewportWidth:window.innerWidth,sidebarOpen:D,sidebarWidth:eW.current}),[D]),eD=uY({ariaLabel:h("desktop.resizeSidebar"),cssVariable:"--sidebar-width",defaultWidth:260,getMaxWidth:eF,growthDirection:"right",maxWidth:480,minWidth:180,storageKey:"pi-sidebar-width",widthRef:eW}),eH=uY({ariaLabel:h("desktop.resizeFilePanel"),cssVariable:"--right-panel-width",defaultWidth:uV(1366),getDefaultWidth:eA,getMaxWidth:eP,growthDirection:"left",maxWidth:1200,minWidth:300,storageKey:"pi-right-panel-width",widthRef:eL}),eO=eD.reclampWidth,eB=eH.reclampWidth;(0,o.useEffect)(()=>{ew&&(eO(),eB())},[eB,eO,ew]);let eU=(0,o.useCallback)((e,t)=>{U.current?.insertText(dn(e,t))},[]),e_=(0,o.useCallback)(e=>{let t=e.map(e=>dn(e,!1)).join("");t&&U.current?.insertText(t)},[]),eq=(0,o.useCallback)((e,t,r)=>{let n,o,i,s;U.current?.insertText((n=Math.max(1,Math.min(t,r)),o=Math.max(1,Math.max(t,r)),i=e.includes(" ")?`@"${e}"`:`@${e}`,s=n===o?`:${n}`:`:${n}-${o}`,`${i}${s} `))},[]),[eK,eV]=(0,o.useState)(()=>c.sessionId),[eJ,eY]=(0,o.useState)(null),[eG,eX]=(0,o.useState)(()=>c.requestedCwd?"validating":"idle"),[eZ,eQ]=(0,o.useState)(null),[e0,e1]=(0,o.useState)(()=>!eK),e2=(0,o.useRef)(!1),e6=(0,o.useRef)(new Map),[e4,e5]=(0,o.useState)(null),e3=(0,o.useRef)("");(0,o.useEffect)(()=>{let e=`${c.requestedCwd??""}|${c.sessionId??""}`;e3.current!==e&&(e3.current=e,eV(c.sessionId),e1(!c.sessionId),c.requestedCwd||eX("idle"),eQ(null))},[c]),(0,o.useEffect)(()=>{let e=c.requestedCwd;if(!e)return;let t=new AbortController;return eX("validating"),eQ(null),fetch("/api/cwd/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e}),signal:t.signal}).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok||!t.cwd)throw Error(t.error??`HTTP ${e.status}`);e2.current=!0,v(t.cwd),eX("ready")}).catch(e=>{t.signal.aborted||(eQ(e instanceof Error?e.message:String(e)),eX("error"))}),()=>t.abort()},[c]);let e8=(0,o.useCallback)((e,t)=>{if(!e)return;if(eY(e),e2.current&&x&&iE(x.projectRoot??x.cwd,t??e)){if(e2.current=!1,x){let e=x.projectRoot??x.cwd;e&&e6.current.set(e,x.id)}return}e2.current=!1;let r=t??e;if(x&&iE(x.projectRoot??x.cwd,r)){(x.projectRoot??x.cwd)&&e6.current.set(r,x.id);return}if(x){let e=x.projectRoot??x.cwd;e&&e6.current.set(e,x.id)}f(null),v(t=>t&&t!==e?null:t),j(e=>e+1),et(null),eg(null),window.history.replaceState(null,"","/");let n=e6.current.get(r);e5(n?{projectRoot:r,sessionId:n}:null)},[x]);(0,o.useEffect)(()=>{let e=eJ?ok(eJ)||eJ:null;document.title=e?`${e} — Pi Agent Web`:"Pi Agent Web"},[eJ]);let e7=(0,o.useCallback)((e,t=!1)=>{if(t||e5(null),!t&&x){let t=iE(x.projectRoot??x.cwd,e.projectRoot??e.cwd);if(x.id===e.id&&t){g&&H(!1);return}}let r=e.projectRoot??e.cwd;r&&e6.current.set(r,e.id),v(null),f(e),j(e=>e+1),et(null),e1(!0),g&&!t&&H(!1),t&&(e2.current=!0),t||window.history.replaceState(null,"",`?session=${encodeURIComponent(e.id)}`)},[g,x]),e9=(0,o.useRef)(()=>{});(0,o.useEffect)(()=>{e9.current=e7},[e7]);let te=(0,o.useCallback)(e=>{fetch("/api/sessions").then(e=>e.ok?e.json():null).then(t=>{let r=t?.sessions.find(t=>t.id===e);r&&f(t=>!t||t.id!==e||t.projectRoot&&t.name?t:r)}).catch(()=>{})},[]);(0,o.useEffect)(()=>{if(!e4)return;let{projectRoot:e,sessionId:t}=e4;e9.current({path:"",id:t,cwd:e,created:"",modified:"",messageCount:0,firstMessage:"",projectRoot:e},!0),te(t),window.history.replaceState(null,"",`?session=${encodeURIComponent(t)}`),e5(null)},[e4,te]);let tt=(0,o.useCallback)((e,t)=>{e5(null),f(null),v(t),j(e=>e+1),et(null),eg(null),g&&H(!1),window.history.replaceState(null,"","/")},[a,g]);!function(e){let{onNewSession:t,activeCwd:r}=e;(0,o.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(!l)return;let t=e.target?.tagName;if("TEXTAREA"===t||"INPUT"===t)return;e.preventDefault(),l();return}if("n"===e.key&&e.ctrlKey&&e.altKey){if(!r||!t)return;e.preventDefault(),t(r)}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[r,t])}({onNewSession:e=>tt(`kb-${Date.now()}`,e),activeCwd:eJ});let tr=(0,o.useCallback)(e=>{v(null),e5(null);let t=e.projectRoot??e.cwd;t&&e6.current.set(t,e.id),f(e),e.cwd&&eY(e.cwd),b(e=>e+1),te(e.id),window.history.replaceState(null,"",`?session=${encodeURIComponent(e.id)}`),window.setTimeout(()=>b(e=>e+1),1200),window.setTimeout(()=>b(e=>e+1),4e3)},[a,te]),tn=(0,o.useCallback)(()=>{b(e=>e+1),S(e=>e+1)},[]),to=(0,o.useCallback)(e=>{b(e=>e+1),j(e=>e+1),v(null),e5(null),f(t=>{let r={...t??{path:"",cwd:"",created:"",modified:"",messageCount:0,firstMessage:""},id:e},n=r.projectRoot??r.cwd;return n&&e6.current.set(n,e),r}),te(e),window.history.replaceState(null,"",`?session=${encodeURIComponent(e)}`)},[a,te]),ti=(0,o.useCallback)(()=>{e1(!0)},[]),ts=(0,o.useCallback)(e=>{if(b(e=>e+1),x?.id===e){let e=x.cwd;f(null),v(e??null),j(e=>e+1),et(null),eg(null),window.history.replaceState(null,"","/")}},[a,x]),tl=(0,o.useCallback)((e,t,r,n)=>{let o="string"==typeof r||null===r?r:void 0,i="object"==typeof r&&null!==r?r:n,s=`file:${e}`;eb(r=>{let n=r.find(e=>e.id===s);return n?o&&n.sourceSessionId!==o||i?.initialDisplayMode&&n.initialDisplayMode!==i.initialDisplayMode?r.map(e=>e.id===s?{...e,sourceSessionId:o??e.sourceSessionId,initialDisplayMode:i?.initialDisplayMode??e.initialDisplayMode}:e):r:[...r,{id:s,label:t,filePath:e,sourceSessionId:o,initialDisplayMode:i?.initialDisplayMode}]}),ej(s),eS(!0),g&&H(!1)},[g]),ta=(0,o.useCallback)(e=>{tl(e,ok(e),x?.id??null)},[tl,x?.id]),td=(0,o.useMemo)(()=>{let e=new Map;for(let t of eR){if(t.relation?.kind!=="subagent")continue;let r=t.relation;e.set(t.id,{status:eM.has(t.id)?"running":r.status,...r.createdAt?{createdAt:r.createdAt}:{},...r.completedAt?{completedAt:r.completedAt}:{}})}return e},[eR,eM]),tc=(0,o.useCallback)((e,t)=>{let r=`subagent:${e}`;eb(n=>n.some(e=>e.id===r)?n:[...n,{id:r,label:t,filePath:"",kind:"subagent",sessionId:e}]),ej(r),eS(!0),g&&H(!1)},[g]),tp=(0,o.useCallback)(e=>{eb(t=>{let r=t.filter(t=>t.id!==e);return 0===r.length&&eS(!1),r}),ej(t=>{if(t!==e)return t;let r=ey.filter(t=>t.id!==e);return r.length>0?r[r.length-1].id:null})},[ey]),th=(0,o.useCallback)(e=>{S(e=>e+1),tl(e,ok(e))},[tl]),tg=(0,o.useCallback)((e,t)=>{S(e=>e+1);let r=e.endsWith("/")?e:e+"/",n=n=>n===e||t&&n.startsWith(r);eb(e=>{let t=e.filter(e=>!n(e.filePath));return 0===t.length&&eS(!1),t}),ej(e=>{if(!e)return e;let t=ey.find(t=>t.id===e);if(!t||!n(t.filePath))return e;let r=ey.filter(e=>!n(e.filePath));return r.length>0?r[r.length-1].id:null})},[ey]),tx=x?n6({name:x.name||en?.sessionName||void 0,firstMessage:x.firstMessage,id:x.id},(x.cwd??eJ??"").replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()):(t=eJ??m)?t.replace(/[\\/]+$/,"").split(/[\\/]/).filter(Boolean).pop()||t:null,tf=(0,o.useCallback)(()=>{x&&window.open(`/api/sessions/${encodeURIComponent(x.id)}/export?inline=1`,"_blank","noopener,noreferrer")},[x]),tm=m??(null===x&&eJ?eJ:null),tv="validating"!==eG&&"error"!==eG&&(null!==x||null!==tm),ty=x?.cwd??tm,[tb,tk]=(0,o.useState)(!1),tj=(0,o.useCallback)(()=>{g||tk(e=>!e)},[g]),[tw,tS]=(0,o.useState)(!0);(0,o.useEffect)(()=>{let e=!1,t=()=>fetch("/api/features").then(e=>e.ok?e.json():null).then(t=>{!e&&t&&"boolean"==typeof t.tasksBoard&&(tS(t.tasksBoard),t.tasksBoard||tk(!1))}).catch(()=>{});t();let r=()=>t();return window.addEventListener("pi:features-changed",r),()=>{e=!0,window.removeEventListener("pi:features-changed",r)}},[]);let tC=e0&&!tv;(0,o.useEffect)(()=>{let e=()=>{g||tk(!0)};return window.addEventListener(cf,e),()=>window.removeEventListener(cf,e)},[g]),(0,o.useEffect)(()=>{if($(null),L(!1),P(null),!ty)return;let e=new AbortController;return fetch(`/api/project-trust?cwd=${encodeURIComponent(ty)}`,{signal:e.signal}).then(async e=>{let t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);$(t)}).catch(e=>{e instanceof DOMException&&"AbortError"===e.name||console.error("Failed to load project trust:",e)}),()=>e.abort()},[ty]);let tz=(0,o.useCallback)(async()=>{if(ty&&!N){A(!0),P(null);try{let e=await fetch("/api/project-trust",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:ty})}),t=await e.json();if(!e.ok||t.error)throw Error(t.error??`HTTP ${e.status}`);$(t),L(!1),M(e=>e+1),j(e=>e+1)}catch(e){P(e instanceof Error?e.message:String(e))}finally{A(!1)}}},[N,ty]),tT=ey.find(e=>e.id===ek)??null,tR=eJ??x?.cwd??m,tI=(0,o.useCallback)(e=>{R(e),z(!0)},[]),tM=(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(iO,{selectedSessionId:x?.id??null,onSelectSession:e7,onNewSession:tt,initialSessionId:eK,onInitialRestoreDone:ti,refreshKey:y,onSessionDeleted:ts,selectedCwd:x?.cwd??m??null,onCwdChange:e8,onOpenFile:tl,selectedSessionStats:en,onOpenSettings:e=>{tI(e??"models")},explorerRefreshKey:w,onAtMention:eU,onAtMentions:e_,onFileCreated:th,onFileDeleted:tg,workspaceControlsHosts:{title:q,welcome:G,titleRight:V},showWorkspaceControls:!0})});return(0,n.jsxs)(cQ,{children:[(0,n.jsx)("style",{children:`
|
|
196
196
|
@media (max-width: 640px) {
|
|
197
197
|
.sidebar-overlay-backdrop.sidebar-mobile-pending {
|
|
198
198
|
opacity: 0 !important;
|