pikiloom 0.4.15 → 0.4.16

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.
@@ -0,0 +1,23 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-BVC7kwlX.js","assets/react-vendor-C7Sl8SE7.js","assets/index-5Q-Q7ByM.js","assets/router-DHISdpPk.js","assets/index-FD86DEDF.css","assets/Modal-CBMO5UcS.js","assets/Select-BiSTkS_t.js","assets/DirBrowser-CBp5nyfS.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-w4pkrNas.js"])))=>i.map(i=>d[i]);
2
+ import{c as T,a as Y,u as we,i as kn,f as Mt,A as xs,s as cn,S as fe,B as Je,g as sn,w as ps,b as gs,E as Zt,C as dn,d as ms,e as bs,n as vs,h as Ln,j as _t,k as Te,D as Dt,l as js,m as Mn,_ as In,T as ws,o as ks}from"./index-5Q-Q7ByM.js";import{j as e,r,a as un}from"./react-vendor-C7Sl8SE7.js";import{I as ys}from"./Select-BiSTkS_t.js";import{M as Bt,a as $t}from"./Modal-CBMO5UcS.js";import{D as Ns}from"./DirBrowser-CBp5nyfS.js";import{n as Ss,r as Cs,M as hn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Es}from"./ExtensionsTab-w4pkrNas.js";function Ts({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:T("shrink-0 text-fg-5/40 transition-transform duration-200",t&&"rotate-180",n),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function Ye({open:t,onToggle:n,dot:s,label:a,preview:o,badge:c,collapsedContent:h,children:d,className:g}){return e.jsxs("div",{className:T("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",g),children:[e.jsxs("button",{onClick:n,className:"w-full flex items-center gap-2.5 px-3.5 py-2.5 text-left hover:bg-panel-h/40 transition-colors",children:[s&&e.jsx("span",{className:T("h-[7px] w-[7px] shrink-0 rounded-full",s.color,s.pulse&&"animate-pulse")}),e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:a}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:o}),c,e.jsx(Ts,{open:t})]}),!t&&h,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Ls=5e3,Ms=15e3,Pt=8,Wt=30,Is=1,Ze=new Map,je=new Map,Jt=new Set,An=[];let It=0;function Xt(t){return typeof t=="number"&&Number.isFinite(t)}function De(t,n,s,a){for(t.delete(n),t.set(n,s);t.size>a;){const o=t.keys().next().value;if(!o)break;t.delete(o)}}function Rn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(De(t,n,s,t===je?Wt:Pt),s.value)}function _n(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:Xt(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:Xt(t.turnOffset)?t.turnOffset:void 0,turnLimit:Xt(t.turnLimit)?t.turnLimit:void 0}}function fn(t){const n=_n(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function Pn(){for(;It<Is;){const t=An.shift();if(!t)return;It+=1,t().finally(()=>{It=Math.max(0,It-1),Pn()})}}async function As(t,n={}){const s=t;if(!n.force){const c=Rn(Ze,s);if(c)return c}const a=Ze.get(s);if(a?.promise)return a.promise;const o=Y.getWorkspaceSessions(t,n.request).then(c=>(De(Ze,s,{value:c,expiresAt:c.ok?Date.now()+Ls:0},Pt),c)).finally(()=>{const c=Ze.get(s);c?.promise&&De(Ze,s,{value:c.value,expiresAt:c.expiresAt},Pt)});return De(Ze,s,{value:a?.value,expiresAt:a?.expiresAt??0,promise:o},Pt),o}function Rs(t,n={}){const s=fn(t),a=je.get(s);return a?.value?.ok&&(n.allowStale||a.expiresAt>Date.now())?a.value:null}async function _s(t,n={}){const s=_n(t),a=fn(s);if(!n.force){const h=Rn(je,a);if(h?.ok)return h}const o=je.get(a);if(o?.promise)return o.promise;const c=Y.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(h=>(De(je,a,{value:h,expiresAt:h.ok?Date.now()+Ms:0},Wt),h)).finally(()=>{const h=je.get(a);h?.promise&&De(je,a,{value:h.value,expiresAt:h.expiresAt},Wt)});return De(je,a,{value:o?.value,expiresAt:o?.expiresAt??0,promise:c},Wt),c}function Ps(t){const n=fn(t);Rs(t)||Jt.has(n)||je.get(n)?.promise||(Jt.add(n),An.push(async()=>{try{await _s(t)}catch{}finally{Jt.delete(n)}}),Pn())}const vt=new Map,rn=new Set;let ze=null,Le=0,yn=!1,Xe=null,bt=500;const Ws=8e3;function Bs(t){const n=vt.get(t.type);if(n)for(const s of n)s(t)}function $s(){const t=window.location;return`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}/ws`}function xn(){if(ze)return;Wn();const t=new WebSocket($s());t.onopen=()=>{const n=yn;if(yn=!0,bt=500,n)for(const s of rn)s()},t.onmessage=n=>{try{const s=JSON.parse(n.data);if(s.type==="pong")return;Bs(s)}catch{}},t.onclose=()=>{ze=null,Le>0&&Ds()},t.onerror=()=>{},ze=t}function Os(){Wn(),ze&&(ze.close(),ze=null)}function Wn(){Xe&&(clearTimeout(Xe),Xe=null)}function Ds(){Xe||(Xe=setTimeout(()=>{Xe=null,Le>0&&xn()},bt),bt=Math.min(bt*2,Ws))}function zs(t,n){let s=vt.get(t);s||(s=new Set,vt.set(t,s)),s.add(n),Le++,Le===1&&xn()}function Fs(t,n){const s=vt.get(t);s&&(s.delete(n),s.size===0&&vt.delete(t)),Le=Math.max(0,Le-1),Le===0&&Os()}typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Le>0&&!ze&&(bt=500,xn())});function Nn(t,n){const s=r.useRef(n);s.current=n,r.useEffect(()=>{if(!t)return;const a=o=>s.current(o);return zs(t,a),()=>Fs(t,a)},[t])}function Us(t){const n=r.useRef(t);n.current=t,r.useEffect(()=>{const s=()=>n.current();return rn.add(s),()=>{rn.delete(s)}},[])}function xo(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(h=>({role:h.role,text:h.text,blocks:[{type:"text",content:h.text}]}))||[],s=Hs(n),a=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),o=t.window?.endTurn??a,c=t.window?.startTurn??Math.max(0,o-s.length);return{turns:s,startTurn:c,endTurn:o,totalTurns:a,hasOlder:t.window?.hasOlder??c>0}}function po(t,n){const s=Math.max(0,t.startTurn-n.startTurn);return{turns:[...n.turns.slice(0,s),...t.turns],startTurn:n.startTurn,endTurn:t.endTurn,totalTurns:Math.max(t.totalTurns,n.totalTurns),hasOlder:n.hasOlder}}function go(t,n){if(n.startTurn<=t.startTurn)return n;const s=Math.max(0,n.startTurn-t.startTurn);return{turns:[...t.turns.slice(0,s),...n.turns],startTurn:t.startTurn,endTurn:n.endTurn,totalTurns:n.totalTurns,hasOlder:t.startTurn>0}}function Ks(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
3
+
4
+ `),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function Hs(t){const n=[];let s={user:null,assistant:null};for(const a of t)if(a.role==="user"){if(s.assistant&&Bn(a.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=a}else s.assistant?s.assistant=Ks(s.assistant,a):s.assistant=a;return(s.user||s.assistant)&&n.push(s),n}const Vs=new Set(["task-notification","system-reminder","persisted-output","local-command-stdout","local-command-caveat","local-command-stderr","ide_opened_file","ide_diagnostics","ide_selection","event","analysis","case_id","tool-use-id","output-file"]),Gs=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function Bn(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Vs.has(s[1].toLowerCase())?!0:Gs.some(a=>t.includes(a))}function $n(t,n){const s=t.split(`
5
+ `).filter(a=>a.trim());return s.length<=n?s.join(`
6
+ `):s.slice(-n).join(`
7
+ `)}function qs(t){const n=String(t||"").trim().toLowerCase();return n?n.startsWith("interrupted by user")?"interrupted":n.startsWith("timed out")||n.startsWith("stopped before completion")||n.includes("max tokens")?"incomplete":"error":"error"}function Yt(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function Qs(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function Zs(t){if(!Number.isFinite(t)||t<=0)return"0 B";if(t<1024)return`${t} B`;const n=t/1024;if(n<1024)return`${n.toFixed(n>=100?0:1)} KB`;const s=n/1024;return`${s.toFixed(s>=100?0:1)} MB`}async function Js(t){if(typeof ClipboardItem>"u"||!navigator.clipboard?.write)return!1;try{return await navigator.clipboard.write([new ClipboardItem({[t.type||"image/png"]:t})]),!0}catch{return!1}}function Q(t,n=120){if(t==null)return"";const a=(typeof t=="string"?t:String(t)).replace(/\s+/g," ").trim();return a.length<=n?a:a.slice(0,Math.max(0,n-1))+"…"}function Xs(t){if(!t)return null;try{const n=JSON.parse(t);return n&&typeof n=="object"&&!Array.isArray(n)?n:null}catch{return null}}function On(t){const n=String(t.toolName||"").trim()||"Tool",s=Xs(t.content);if(!s)return n;const a=Q(s.description,120);switch(n){case"Read":{const o=Q(s.file_path||s.path,140);return o?`Read ${o}`:"Read"}case"Edit":{const o=Q(s.file_path||s.path,140);return o?`Edit ${o}`:"Edit"}case"Write":{const o=Q(s.file_path||s.path,140);return o?`Write ${o}`:"Write"}case"Glob":{const o=Q(s.pattern||s.glob,120);return o?`Glob ${o}`:"Glob"}case"Grep":{const o=Q(s.pattern||s.query,120);return o?`Grep ${o}`:"Grep"}case"WebFetch":{const o=Q(s.url,120);return o?`WebFetch ${o}`:"WebFetch"}case"WebSearch":{const o=Q(s.query,120);return o?`WebSearch ${o}`:"WebSearch"}case"TodoWrite":return"Update plan";case"AskUserQuestion":{const c=(Array.isArray(s.questions)?s.questions:[])[0],h=Q(c?.question||s.question,120);return h?`Ask user: ${h}`:"Ask user"}case"Task":{const o=Q(s.description||s.prompt,120);return o?`Task: ${o}`:"Task"}case"Bash":{if(a)return`Bash: ${a}`;const o=Q(s.command,120);return o?`Bash: ${o}`:"Bash"}default:{const o=n.match(/^mcp__[^_]+__(.+)$/),c=o?o[1]:n;if(c==="im_send_file"){const d=Q(s.path,120);return d?`Send file: ${d}`:"Send file"}if(c==="im_list_files")return"List workspace files";if(a)return`${n}: ${a}`;const h=Q(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return h?`${n}: ${h}`:n}}}function Ys(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
8
+ `).map(a=>a.trim()).find(Boolean)||"";return s?Q(s,140):"result"}function er(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),a=t.slice(n+1).trim();return!s||!a?null:{agent:s,sessionId:a}}const mt=new Map;function tr(t,n){return`${t}:${n}`}function nr(t){const n=(()=>{try{return new URL(t.baseURL).host.toLowerCase()}catch{return""}})();return n.includes("openrouter")?"openrouter":n.includes("anthropic")?"anthropic":n.includes("deepseek")?"deepseek":n.includes("googleapis")||n.includes("vertex")?"google":n.includes("openai.com")?"openai":n.includes("dashscope")||n.includes("qwen")||n.includes("aliyun")?"qwen":n.includes("volces")||n.includes("volcengine")||n.includes("doubao")?"doubao":n.includes("bigmodel")||n.includes("zhipu")||n.includes("z.ai")?"glm":n.includes("minimax")?"minimax":t.kind==="anthropic"?"anthropic":t.kind==="google"?"google":t.kind==="openai"?"openai":"custom"}const sr=r.memo(function({session:n,workdir:s,onStreamQueued:a,onSendStart:o,onSendTaskAssigned:c,onSessionChange:h,t:d,streamPhase:g,streamTaskId:m,queuedTaskIds:v,queuedTasks:j,pendingQueuedSends:S,onRecall:y,onSteer:M,onStopAll:L,editDraft:I,onEditDraftConsumed:_,onSelectionChange:E}){const[U,W]=r.useState(""),[R,z]=r.useState(!1),[K,le]=r.useState(null),[ee,A]=r.useState(()=>new Set),[H,Me]=r.useState(()=>new Set),de=r.useRef({prompt:"",files:[]}),ke=we(i=>i.agentStatus?.agents??null),[O,Fe]=r.useState(ke||[]),[Ie,tt]=r.useState(""),[ye,jt]=r.useState(""),[ue,wt]=r.useState(""),[te,ne]=r.useState([]),[Ue,Ae]=r.useState(null),[Ke,nt]=r.useState(null),[se,ae]=r.useState(null),[B,Ne]=r.useState(null),[Z,Re]=r.useState(null),[_e,kt]=r.useState(void 0),[$,re]=r.useState("closed"),[xe,Se]=r.useState(null),oe=r.useRef(null),Pe=r.useRef(!1),st=r.useRef(null),yt=r.useRef(null),He=r.useRef(null),rt=r.useRef([]),[ot,Ce]=r.useState([]),[V,pe]=r.useState(!1),[Ee,ie]=r.useState(0),We=r.useRef(null),Be=we(i=>i.refreshAgentStatus),[he,it]=r.useState([]),[lt,Ft]=r.useState([]),[Nt,Ut]=r.useState({}),at=r.useCallback(async()=>{try{const[i,x,b]=await Promise.all([fetch("/api/models/providers").then(N=>N.json()),fetch("/api/models/profiles").then(N=>N.json()),fetch("/api/models/agents").then(N=>N.json())]);if(i?.ok&&Ft(i.providers||[]),x?.ok&&it(x.profiles||[]),b?.ok){const N={};for(const P of b.bindings||[])N[P.agent]=P.activeProfileId;Ut(N)}}catch{}},[]);r.useEffect(()=>{ke?.length&&Fe(ke)},[ke]),r.useEffect(()=>{rt.current=te},[te]);const $e=tr(n.agent||"",n.sessionId),Ve=r.useRef($e);Ve.current=$e,r.useEffect(()=>{const i=mt.get($e);return i&&(mt.delete($e),i.text&&W(i.text),i.files.length&&ne(i.files.map(Yt))),()=>{const x=oe.current?.value||"",b=rt.current.map(N=>N.file);for(const N of rt.current)URL.revokeObjectURL(N.previewUrl);x||b.length?mt.set(Ve.current,{text:x,files:b}):mt.delete(Ve.current)}},[$e]);const ct=r.useRef({agent:n.agent||"",sessionId:n.sessionId});r.useEffect(()=>{const i=ct.current,x={agent:n.agent||"",sessionId:n.sessionId};ct.current=x,!(i.agent===x.agent&&kn(i.sessionId)&&!kn(x.sessionId))&&(tt(""),jt(""),wt(""),ae(null),Ne(null),Re(null),re("closed"))},[n.agent,n.sessionId]),r.useEffect(()=>{I!=null&&(W(I),_?.(),requestAnimationFrame(()=>{const i=oe.current;i&&(i.focus(),i.setSelectionRange(I.length,I.length))}))},[I,_]),r.useEffect(()=>{if(!s)return;let i=!1;return Y.getSkills(s).then(x=>{!i&&x.ok&&Ce(x.skills)}).catch(()=>{}),()=>{i=!0}},[s]);const dt=V?(()=>{const i=U.match(/^\/(\S*)$/);return i?i[1].toLowerCase():null})():null,ge=dt!==null?ot.filter(i=>i.name.toLowerCase().includes(dt)||i.label&&i.label.toLowerCase().includes(dt)):[];r.useEffect(()=>{ie(0)},[V,U]),r.useEffect(()=>{if(!V||!We.current)return;const i=We.current.querySelector(`[data-skill-idx="${Ee}"]`);i&&i.scrollIntoView({block:"nearest"})},[Ee,V]),r.useEffect(()=>{if(!V)return;const i=x=>{We.current?.contains(x.target)||oe.current?.contains(x.target)||pe(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[V]),r.useEffect(()=>{if($==="closed")return;const i=x=>{const b=x.target;He.current?.contains(b)||document.getElementById("cascade-portal")?.contains(b)||(re("closed"),ae(null),Ne(null),Re(null))};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[$]),r.useLayoutEffect(()=>{if($==="closed"||!He.current){Se(null);return}const i=He.current.getBoundingClientRect();Se({left:i.left,bottom:window.innerHeight-i.top+8})},[$]);const St=v&&v.length?v[0]:null;r.useEffect(()=>{K&&(St||g!==null&&g!=="queued")&&le(null)},[g,K,St]),r.useEffect(()=>{const i=oe.current;i&&(i.style.height="auto",i.style.height=Math.min(i.scrollHeight,200)+"px")},[U]);const ut=r.useCallback(i=>{const x=Array.from(i||[]).filter(b=>b.type.startsWith("image/"));x.length&&ne(b=>[...b,...x.map(Yt)])},[]),Ct=r.useCallback(()=>{Ae(null),ne(i=>(Qs(i),[]))},[]),l=r.useCallback(i=>{ne(x=>{const b=x.find(N=>N.id===i);return b&&URL.revokeObjectURL(b.previewUrl),x.filter(N=>N.id!==i)}),Ae(x=>x===i?null:x)},[]),u=r.useCallback(()=>{const i=U.trim(),x=te.map(q=>q.file);if(!i&&x.length===0||R)return;const b=Ie||n.agent||O.find(q=>q.isDefault)?.agent||"";if(!b)return;const N=O.find(q=>q.agent===b)||null,P=!!n.agent&&b===n.agent,me=(ye||P&&n.model||""||N?.selectedModel||"").trim()||null,be=b==="gemini"?null:(ue||(P?Mt(b,n.thinkingEffort,n.workflowEnabled):"")||Mt(b,N?.selectedEffort,N?.workflowEnabled)||"").trim()||null,X=b!==n.agent,Qt=X?"":n.sessionId,us=X&&n.agent?n.agent:null,hs=X&&n.sessionId?n.sessionId:null;z(!0),de.current={prompt:i,files:x},W(""),mt.delete(Ve.current);const fs=x.length?x.map(q=>URL.createObjectURL(q)):void 0;Ct(),o(i,fs),a(),Y.sendSessionMessage(s,b,Qt,i,{attachments:x,model:me,effort:be,previousAgent:us,previousSessionId:hs}).then(q=>{if(q.taskId&&(le(q.taskId),c?.(q.taskId)),!q.ok)return;const gt=typeof q.sessionKey=="string"?er(q.sessionKey):null;gt&&(gt.agent!==n.agent||gt.sessionId!==n.sessionId)&&gt&&h?.({...gt,workdir:s})}).catch(()=>{}).finally(()=>z(!1))},[O,Ct,te,U,o,c,h,a,Ie,ue,ye,R,n.agent,n.sessionId,s]),f=g==="streaming",p=(()=>{const i=[];return v&&v.length&&i.push(...v),g==="queued"&&m&&!i.includes(m)&&i.unshift(m),K&&!i.includes(K)&&(g==="queued"||!g)&&i.push(K),i})(),w=p[p.length-1]||null,k=p.length>0,C=k||f;r.useEffect(()=>{const i=x=>p.includes(x)||x===m;A(x=>{let b=!1;const N=new Set;for(const P of x)i(P)?N.add(P):b=!0;return b?N:x}),Me(x=>{let b=!1;const N=new Set;for(const P of x)i(P)?N.add(P):b=!0;return b?N:x})},[p,m]),r.useEffect(()=>{!k&&de.current.files.length&&(de.current={prompt:"",files:[]})},[k]);const G=r.useCallback(i=>{if(!ee.has(i)){if(A(x=>{const b=new Set(x);return b.add(i),b}),i===w){const x=de.current;x.prompt&&W(x.prompt),x.files.length&&ne(x.files.map(Yt)),de.current={prompt:"",files:[]}}y?.(i),i===K&&le(null)}},[ee,w,K,y]),[D,J]=r.useState(!1),ht=r.useCallback(async()=>{if(!(D||!L)){J(!0);try{await L()}finally{J(!1)}}},[D,L]),Yn=r.useCallback(i=>{H.has(i)||(Me(x=>{const b=new Set(x);return b.add(i),b}),M?.(i),i===K&&le(null))},[H,K,M]),bn=r.useCallback(i=>{W(`/${i.name} `),pe(!1),requestAnimationFrame(()=>{const x=oe.current;x&&(x.focus(),x.setSelectionRange(x.value.length,x.value.length))})},[]),es=r.useCallback(i=>{W(i);const x=/^\/\S*$/.test(i)&&ot.length>0;pe(x)},[ot.length]),ts=i=>{if(V&&ge.length>0){if(i.key==="ArrowDown"){i.preventDefault(),ie(x=>(x+1)%ge.length);return}if(i.key==="ArrowUp"){i.preventDefault(),ie(x=>(x-1+ge.length)%ge.length);return}if(i.key==="Tab"||i.key==="Enter"&&!i.shiftKey&&!Pe.current){i.preventDefault(),bn(ge[Ee]);return}if(i.key==="Escape"){i.preventDefault(),pe(!1);return}}i.key==="Enter"&&!i.shiftKey&&!Pe.current&&(i.preventDefault(),u())},ns=r.useCallback(i=>{const x=Array.from(i.clipboardData?.items||[]).filter(b=>b.kind==="file"&&b.type.startsWith("image/")).map(b=>b.getAsFile()).filter(b=>!!b);x.length&&(i.preventDefault(),ut(x))},[ut]),ce=Ie||n.agent||O.find(i=>i.isDefault)?.agent||O.find(i=>i.installed)?.agent||O[0]?.agent||"",Et=O.find(i=>i.agent===ce)||null,ft=se||ce,xt=O.find(i=>i.agent===ft)||Et,Tt=r.useMemo(()=>{if(!xt)return[];const i=[];for(const b of xt.models||[])i.push({id:b.id,label:b.id,kind:"native",description:b.alias&&b.alias.toLowerCase()!==b.id.toLowerCase()?b.alias:void 0});const x=new Set(xs[ft]||[]);for(const b of he){const N=lt.find(me=>me.id===b.providerId);if(!N||!x.has(N.kind))continue;const P=b.name.trim().toLowerCase()!==b.modelId.trim().toLowerCase();i.push({id:b.modelId,label:b.name,kind:"profile",profileId:b.id,description:P?`${N.name} · ${b.modelId}`:N.name})}return i},[xt,ft,he,lt]),ss=r.useMemo(()=>Tt.findIndex(i=>i.kind==="profile"),[Tt]),rs=Nt[ft]||null,vn=!!n.agent&&ce===n.agent,pt=ye||vn&&n.model||""||Et?.selectedModel||"",Lt=ce==="gemini"?"":ue||(vn?Mt(ce,n.thinkingEffort,n.workflowEnabled):"")||Mt(ce,Et?.selectedEffort,Et?.workflowEnabled)||"";r.useEffect(()=>{E?.({model:pt||null,effort:Lt||null})},[pt,Lt,E]);const os=Zt[ft]||[],Oe=Ue&&te.find(i=>i.id===Ue)||null,is=Oe?{key:Oe.id,url:Oe.previewUrl,name:Oe.file.name,size:Oe.file.size,file:Oe.file,onRemove:()=>l(Oe.id)}:Ke?{key:Ke,url:Ke}:null,jn=(!!U.trim()||te.length>0)&&!R&&!!ce,Kt=()=>{ae(null),Ne(null),Re(null),kt(void 0)},Ht=r.useCallback(async(i,x,b)=>{const N=i==="gemini"?"":b||"";if(_e!==void 0)try{await fetch(`/api/models/agents/${i}/active`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileId:_e})}),at(),Be()}catch{}tt(i),jt(x),wt(N),Kt(),re("closed")},[_e,at,Be]),ls=()=>{$==="closed"?(Kt(),Be(),at(),re("agent")):(Kt(),re("closed"))},Vt=se||ce,wn=sn(Vt),Gt=B??pt,Ge=Z??Lt,as=Gt?cn(Gt):"",qe=(()=>{const i=Nt[Vt];return i?he.find(x=>x.id===i)??null:null})(),Qe=qe?lt.find(i=>i.id===qe.providerId)??null:null,cs=Qe?nr(Qe):null,qt=qe&&qe.name.trim().toLowerCase()!==qe.modelId.trim().toLowerCase()?qe.name:as,ds=[wn.shortLabel,Qe?Qe.name:null,qt||null,Ge?Ge.charAt(0).toUpperCase()+Ge.slice(1):null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:yt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[C&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[f&&e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-primary/20 bg-primary/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx(fe,{className:"h-3 w-3 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-[12px] font-medium text-fg-3 truncate",children:d("hub.running")}),e.jsxs("button",{onClick:ht,disabled:D,title:d("hub.stopHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none shrink-0",children:[D?e.jsx(fe,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),d("hub.stop")]})]}),p.map((i,x)=>{const b=x===p.length-1,N=p.length>1?`${d("hub.queued")} #${x+1}`:d("hub.queued"),P=S?.find(X=>X.taskId===i)||(b?S?.find(X=>!X.taskId):void 0),me=j?.find(X=>X.taskId===i)?.prompt||P?.prompt||null,be=P?.imageUrls?.length?P.imageUrls:[];return e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-warn/25 bg-warn/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-warn animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-warn shrink-0",children:N}),be.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[be.slice(0,3).map((X,Qt)=>e.jsx("button",{type:"button",onClick:()=>nt(X),title:d("hub.previewImage"),className:"block h-5 w-5 shrink-0 overflow-hidden rounded border border-warn/30 transition-opacity hover:opacity-80",children:e.jsx("img",{src:X,alt:"",className:"h-full w-full object-cover"})},`${X}-${Qt}`)),be.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",be.length-3]})]}),me&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:me})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>Yn(i),disabled:H.has(i),title:d("hub.steerHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-blue-400 hover:bg-blue-400/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[H.has(i)?e.jsx(fe,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),d("hub.steer")]}),e.jsxs("button",{onClick:()=>G(i),disabled:ee.has(i),title:d("hub.recallHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[ee.has(i)?e.jsx(fe,{className:"h-2.5 w-2.5"}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]}),d("hub.recall")]})]})]},i)})]}),e.jsxs("div",{className:"relative rounded-xl border border-edge/40 bg-panel shadow-sm transition-[border-color,box-shadow] duration-200 focus-within:border-fg-5/40 focus-within:shadow-md",children:[e.jsx("input",{ref:st,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:i=>{ut(i.target.files),i.target.value=""}}),te.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:te.map(i=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>Ae(i.id),title:d("hub.previewImage"),className:"group relative h-[72px] w-[72px] overflow-hidden rounded-lg border border-edge/30 bg-panel-alt/30",children:[e.jsx("img",{src:i.previewUrl,alt:i.file.name,className:"h-full w-full object-cover transition-transform duration-200 group-hover:scale-[1.03]"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent px-1.5 pb-1 pt-3 text-left",children:e.jsx("div",{className:"truncate text-[8px] font-medium text-white/90 leading-tight",children:i.file.name})})]}),e.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),l(i.id)},title:d("hub.removeImage"),className:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-black/65 text-white/75 transition-colors hover:bg-black/80 hover:text-white",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]},i.id))})}),V&&ge.length>0&&e.jsxs("div",{ref:We,className:"absolute bottom-full left-0 right-0 mb-1.5 z-50 max-h-[200px] overflow-y-auto rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg animate-in",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-edge/20",children:e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d("hub.skills")})}),e.jsx("div",{className:"py-1",children:ge.map((i,x)=>e.jsxs("button",{"data-skill-idx":x,onMouseDown:b=>{b.preventDefault(),bn(i)},onMouseEnter:()=>ie(x),className:T("flex flex-col w-full px-3 py-1.5 text-left transition-colors",x===Ee?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",i.name]}),(i.label||i.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:i.label||i.description})]},i.name))})]}),e.jsx("textarea",{ref:oe,value:U,onChange:i=>es(i.target.value),onPaste:ns,onKeyDown:ts,onCompositionStart:()=>{Pe.current=!0},onCompositionEnd:()=>{Pe.current=!1},placeholder:d("hub.inputPlaceholder"),rows:1,className:"w-full resize-none bg-transparent px-4 pt-3 pb-1 text-[13.5px] text-fg outline-none placeholder:text-fg-5/25 leading-[1.6]",style:{maxHeight:200,overflow:U.split(`
9
+ `).length>6?"auto":"hidden"}}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>st.current?.click(),title:d("hub.addImages"),className:"flex h-7 w-7 items-center justify-center rounded-lg text-fg-5/50 transition-colors hover:bg-panel-h/60 hover:text-fg-3",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})}),e.jsxs("button",{ref:He,onClick:ls,disabled:!O.length,title:O.length?ds:void 0,className:T("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",$!=="closed"?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[O.length?e.jsx(Je,{brand:Vt,size:12}):e.jsx(fe,{className:"h-3 w-3"}),O.length?e.jsxs("span",{className:"flex items-center gap-1 max-w-[460px] min-w-0 truncate",children:[e.jsx("span",{className:"shrink-0",children:wn.shortLabel}),Qe&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(Je,{brand:cs||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:Qe.name})]}),qt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:Gt||void 0,children:qt})]}),Ge&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"shrink-0",children:Ge.charAt(0).toUpperCase()+Ge.slice(1)})]})]}):e.jsx("span",{className:"max-w-[420px] truncate",children:d("hub.selectAgent")}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:T("text-fg-5/30 transition-transform duration-200",$!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),$!=="closed"&&xe&&un.createPortal(e.jsxs("div",{id:"cascade-portal",className:"fixed z-[200] w-[300px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in",style:{left:xe.left,bottom:xe.bottom},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5 border-b border-edge/20",children:[$!=="agent"&&e.jsx("button",{onClick:()=>{if($==="effort"){const i=xt?.capabilities?.modelSwitch!==!1;re(i?"model":"agent")}else re("agent")},className:"p-0.5 rounded text-fg-5/50 hover:text-fg-3 transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d($==="agent"?"hub.selectAgent":$==="model"?"hub.selectModel":"hub.selectEffort")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const x=xt?.capabilities?.modelSwitch!==!1?["agent","model","effort"]:["agent","effort"],b=x.indexOf($);return x.map((N,P)=>e.jsx("span",{className:T("w-1.5 h-1.5 rounded-full transition-colors",$===N?"bg-primary":P<b?"bg-primary/40":"bg-fg-5/15")},N))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[$==="agent"&&O.filter(i=>i.installed).map(i=>{const x=sn(i.agent),b=ps(i.usage),N=b?gs(b):"ok";return e.jsxs(en,{selected:i.agent===(se||ce),onClick:()=>{if(ae(i.agent),Ne(i.selectedModel||""),Re(i.selectedEffort||""),!(i.capabilities?.modelSwitch!==!1)){(Zt[i.agent]||[]).length?re("effort"):Ht(i.agent,i.selectedModel||"",null);return}re("model")},children:[e.jsx(Je,{brand:i.agent,size:14}),e.jsx("span",{style:{color:x.color},children:x.label}),b&&e.jsxs("span",{className:T("ml-auto font-mono text-[10px]",N==="err"?"text-err":N==="warn"?"text-warn":"text-fg-5"),children:[b.label," ",Math.round(b.usedPercent??0),"%"]})]},i.agent)}),$==="model"&&e.jsxs(e.Fragment,{children:[Tt.map((i,x)=>{const b=x===0&&i.kind==="native",N=x===ss&&i.kind==="profile",P=_e!==void 0?_e:rs,me=i.kind==="profile"?!!i.profileId&&i.profileId===P:!P&&i.id===(B??pt);return e.jsxs("div",{children:[b&&e.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupNative")}),N&&e.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupProfiles")}),e.jsx(en,{selected:me,onClick:()=>{const be=se||ce;if(Ne(i.id),kt(i.profileId??null),Zt[be]?.length){re("effort");return}Ht(be,i.id,null)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:T("truncate text-[11.5px]",i.kind==="native"&&"font-mono text-[11px]"),title:i.id,children:i.label}),i.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:i.description})]})})]},`${i.kind}:${i.profileId||i.id}`)}),Tt.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]}),$==="effort"&&os.map(i=>e.jsx(en,{selected:i===(Z||Lt),onClick:()=>{Re(i),Ht(se||ce,B??pt,i)},children:i.charAt(0).toUpperCase()+i.slice(1)},i))]})]}),document.body),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:u,disabled:!jn,className:T("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",jn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:R?e.jsx(fe,{className:"h-3.5 w-3.5"}):e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})]}),e.jsx(rr,{source:is,onClose:()=>{Ae(null),nt(null)},t:d})]})});function rr({source:t,onClose:n,t:s}){const[a,o]=r.useState(!1);if(r.useEffect(()=>{o(!1)},[t?.key]),r.useEffect(()=>{if(!t)return;const d=g=>{g.key==="Escape"&&n()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[t,n]),!t)return null;const c=t.file,h=t.onRemove;return un.createPortal(e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center bg-black/72 px-4 py-6 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[1024px]",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-[11px] text-white/72",children:[t.name&&e.jsx("span",{className:"truncate font-medium text-white/90",children:t.name}),typeof t.size=="number"&&e.jsx("span",{children:Zs(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await Js(c)&&(o(!0),window.setTimeout(()=>o(!1),1600))},className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s(a?"hub.copied":"hub.copyImage")}),h&&e.jsx("button",{type:"button",onClick:h,className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s("hub.removeImage")}),e.jsx("button",{type:"button",onClick:n,className:"flex h-9 w-9 items-center justify-center rounded-full border border-white/12 bg-white/10 text-white/88 transition-colors hover:bg-white/14",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-white/10 bg-black/35 shadow-[0_20px_70px_rgba(0,0,0,0.45)]",children:e.jsx("img",{src:t.url,alt:t.name||"",className:"max-h-[80vh] w-full object-contain"})})]})}),document.body)}function en({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:T("flex items-center gap-2 w-full px-3 py-2 text-[12px] text-left transition-colors",t?"text-fg bg-panel-h font-medium":"text-fg-3 hover:bg-panel-alt/50 hover:text-fg-2"),children:[s,t&&e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"ml-auto text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),!t&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"ml-auto text-fg-5/20",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})})]})}function or(){return function(t){Ss(t)}}const pn=[Cs,or],Dn=t=>/^https?:\/\//.test(t),ir=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t),lr=/^(Dockerfile|Makefile|Procfile|LICENSE|README|AGENTS|CLAUDE)$/i,ar=/^v?\d+(?:\.\d+)+(?:[-+][a-z0-9][\w.-]*)?$/i,cr=/^(?:\.[A-Za-z0-9_-]{2,}|[A-Za-z0-9_.@-]+\.[A-Za-z0-9][A-Za-z0-9_-]{0,11})$/,tn=/(^|[\s([{<])((?:file:\/\/|~\/|\.{1,2}\/|\/)[^\s<>"'`]+|(?:[A-Za-z0-9_.@-]+\/)[^\s<>"'`]+|(?:\.[A-Za-z0-9_-]{2,}|[A-Za-z0-9_.@-]+\.[A-Za-z0-9][A-Za-z0-9_-]{0,11}|Dockerfile|Makefile|Procfile|LICENSE|README|AGENTS|CLAUDE)(?::\d+(?::\d+)?)?)/g;function dr(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function ur(t){let n=t.trim();const s=[["`","`"],['"','"'],["'","'"],["<",">"]];let a=!0;for(;a&&n.length>=2;){a=!1;for(const[o,c]of s)n.startsWith(o)&&n.endsWith(c)&&(n=n.slice(o.length,-c.length).trim(),a=!0)}return n}function gn(t){let n=ur(t),s="";for(;n.length>1;){const a=n[n.length-1];if(!a||!/[),.;!?]/.test(a)||a==="."&&/^\.[A-Za-z0-9_-]+$/.test(n))break;s=a+s,n=n.slice(0,-1)}return{text:n,trailing:s}}function Ot(t){const n=gn(t).text;if(!n||Dn(n)||ir(n)&&!n.startsWith("file://"))return!1;const s=dr(n);if(!s||ar.test(s))return!1;if(s.startsWith("file://"))return s.length>7;if(/^[A-Za-z]:[\\/]/.test(s))return!0;if(/^(\/|~\/|\.{1,2}\/)/.test(s))return s.length>1;if(s.includes("/")){const a=s.split("/")[0]||"";return!/^[A-Za-z0-9-]+\.[A-Za-z]{2,}$/.test(a)}return lr.test(s)?!0:cr.test(s)}function hr(t){const n=[];let s=0;tn.lastIndex=0;const a=o=>{if(!o)return;const c=n[n.length-1];c?.kind==="text"?c.text+=o:n.push({kind:"text",text:o})};for(let o=tn.exec(t);o;o=tn.exec(t)){const c=o[1]||"",h=o[2]||"",d=o.index+c.length,g=d+h.length,{text:m,trailing:v}=gn(h);!m||!Ot(m)||(d>s&&a(t.slice(s,d)),n.push({kind:"file",text:m}),v&&a(v),s=g)}return s===0?[{kind:"text",text:t}]:(s<t.length&&a(t.slice(s)),n)}function mn(t,n){Y.openInEditor(t,void 0,n||void 0).catch(()=>{})}function zn(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),mn(n,s))}function Fn({locator:t,workdir:n,children:s}){return e.jsx("span",{role:"link",tabIndex:0,title:t,className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",onClick:()=>mn(t,n),onKeyDown:a=>zn(a,t,n),children:s??t})}function ve(t,n){const s=[];return r.Children.toArray(t).forEach((a,o)=>{if(typeof a!="string"&&typeof a!="number"){s.push(a);return}const c=String(a);for(const[h,d]of hr(c).entries())d.kind==="file"?s.push(e.jsx(Fn,{locator:d.text,workdir:n},`${o}-${h}`)):d.text&&s.push(d.text)}),s}function fr({text:t}){const[n,s]=r.useState(!1),a=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:a,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function Sn(t){const n=Ot(t),s=/^(npm |npx |git |python|pip |yarn |pnpm |cargo |go |make )/.test(t);return n?"bg-blue-500/8 border-blue-400/12 text-blue-300/90":s?"bg-amber-500/8 border-amber-400/10 text-amber-300/80":"bg-[rgba(255,255,255,0.06)] border-edge/20 text-fg-3"}function zt(t={}){const n=t.workdir||null;return{h1:({children:s})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:ve(s,n)}),h2:({children:s})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:ve(s,n)}),h3:({children:s})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:ve(s,n)}),p:({children:s})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:ve(s,n)}),strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-fg",children:ve(s,n)}),em:({children:s})=>e.jsx("em",{className:"italic text-fg-3",children:ve(s,n)}),a:({href:s,children:a})=>s&&Dn(s)?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",children:a}):s&&Ot(s)?e.jsx(Fn,{locator:gn(s).text,workdir:n,children:a}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:a}),ul:({children:s})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:s}),ol:({children:s})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:s}),li:({children:s})=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"shrink-0 mt-[10px] w-[5px] h-[5px] rounded-full bg-fg-5/40"}),e.jsx("span",{className:"flex-1",children:ve(s,n)})]}),blockquote:({children:s})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:s}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:s,children:a})=>{const o=String(a).replace(/\n$/,""),c=/language-(\w+)/.exec(s||"");if(!c&&!s&&!o.includes(`
10
+ `))return Ot(o)?e.jsx("code",{role:"link",tabIndex:0,title:o,className:T("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",Sn(o)),onClick:()=>mn(o,n),onKeyDown:d=>zn(d,o,n),children:o}):e.jsx("code",{className:T("px-1.5 py-[1px] rounded text-[12px] font-mono border",Sn(o)),children:o});const h=c?.[1]||"";return e.jsxs("div",{className:"rounded-lg overflow-hidden border border-edge/30 bg-[rgba(0,0,0,0.25)] my-3 not-prose",children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-1.5 border-b border-edge/15 bg-[rgba(0,0,0,0.12)]",children:[e.jsx("span",{className:"text-[10px] font-mono text-fg-5/50",children:h||"text"}),e.jsx(fr,{text:o})]}),e.jsx("pre",{className:"px-3.5 py-3 text-[12px] leading-[1.65] text-fg-3 font-mono whitespace-pre-wrap break-words overflow-x-auto",children:e.jsx("code",{children:o})})]})},pre:({children:s})=>e.jsx(e.Fragment,{children:s}),table:({children:s})=>e.jsx("div",{className:"my-3 overflow-x-auto rounded-lg border border-edge/30",children:e.jsx("table",{className:"w-full text-[12.5px]",children:s})}),thead:({children:s})=>e.jsx("thead",{className:"bg-[rgba(0,0,0,0.1)]",children:s}),th:({children:s})=>e.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-fg-3 border-b border-edge/30",children:ve(s,n)}),td:({children:s})=>e.jsx("td",{className:"px-3 py-1.5 text-fg-4 border-t border-edge/12",children:ve(s,n)}),tr:({children:s})=>e.jsx("tr",{className:"even:bg-[rgba(255,255,255,0.015)]",children:s})}}zt();function et(t){return!!t?.steps?.length}function xr(t,n){let s=t;for(const[a,o]of Object.entries(n))s=s.replace(new RegExp(`\\{${a}\\}`,"g"),o);return s}function pr({status:t}){return t==="completed"?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):t==="inProgress"?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-400 animate-pulse"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/25"})}function Un({plan:t,t:n,className:s}){const[a,o]=r.useState(!1);if(!et(t))return null;const c=t.steps.length,h=t.steps.filter(m=>m.status==="completed").length,d=c>0&&h===c,g=xr(n("hub.planProgress"),{done:String(h),total:String(c)});return e.jsx(Ye,{open:a,onToggle:()=>o(m=>!m),dot:{color:d?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!d},label:g,preview:t.explanation?e.jsx("span",{className:"text-[11.5px] text-fg-4 truncate",children:t.explanation}):void 0,badge:e.jsx("span",{className:T("rounded-md border px-1.5 py-0.5 text-[10px] font-mono",d?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(d?"hub.planDone":"hub.planInProgress")}),className:s,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-1",children:t.steps.map((m,v)=>{const j=m.status==="completed"?"text-fg-5 line-through decoration-fg-5/40":m.status==="inProgress"?"text-fg-3":"text-fg-4";return e.jsxs("div",{className:"flex items-center gap-2 py-[2px]",children:[e.jsx("span",{className:"shrink-0 flex items-center justify-center w-[10px]",children:e.jsx(pr,{status:m.status})}),e.jsx("span",{className:T("text-[12px] leading-[1.5]",j),children:m.step})]},`${v}:${m.step}`)})})})}function Kn(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
11
+ `).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||et(t.plan)||!!(t.subAgents&&t.subAgents.length)}function mo(t){return Kn(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function gr(t){return t.phase!=="done"||!t.error?null:Kn(t)?"hub.streamErrored":"hub.streamFailed"}function mr({detail:t,t:n,className:s}){const a=qs(t);if(a==="interrupted")return e.jsxs("div",{className:T("flex items-center gap-1.5 text-[11px] text-fg-5/55",s),children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-[2px] bg-fg-5/45 shrink-0"}),e.jsx("span",{children:n("hub.turnStopped")})]});const o=a==="error"?{dot:"bg-rose-400/55",text:"text-rose-300/65"}:{dot:"bg-fg-5/40",text:"text-fg-5/55"};return e.jsxs("div",{className:T("flex items-start gap-1.5 text-[11px] leading-[1.6]",o.text,s),children:[e.jsx("span",{className:T("mt-[5px] h-1 w-1 rounded-full shrink-0",o.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const br=64;function vr(t,n){const[s,a]=r.useState(t),o=r.useRef(0),c=r.useRef(null);return r.useEffect(()=>{if(n<=0)return;const h=Date.now()-o.current,d=()=>{o.current=Date.now(),a(t)};return h>=n?d():(c.current&&clearTimeout(c.current),c.current=window.setTimeout(d,n-h)),()=>{c.current&&clearTimeout(c.current)}},[t,n]),n<=0?t:s}function bo({stream:t,t:n,workdir:s}){const a=et(t.plan),[o,c]=r.useState(!1),[h,d]=r.useState(!1),g=r.useRef(null),m=r.useRef(null),v=gr(t),j=r.useMemo(()=>(t.activity||"").split(`
12
+ `).filter(Boolean),[t.activity]),S=t.previewMeta?.toolCalls??[],y=j[j.length-1]||S[S.length-1]?.summary||"";r.useLayoutEffect(()=>{const E=g.current;E&&o&&(E.scrollTop=E.scrollHeight)},[o,t.activity,S.length]),r.useLayoutEffect(()=>{const E=m.current;E&&h&&(E.scrollTop=E.scrollHeight)},[h,t.thinking]);const M=t.subAgents??null,L=vr(t.text,t.phase==="streaming"?br:0),I=r.useMemo(()=>zt({workdir:s}),[s]),_=r.useMemo(()=>e.jsx(hn,{remarkPlugins:pn,components:I,children:L}),[L,I]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[a&&e.jsx(Un,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),M&&M.length>0&&M.map(E=>e.jsx(Hn,{sub:E,t:n},E.id)),(S.length>0||j.length>0)&&e.jsx(Ye,{open:o,onToggle:()=>c(E=>!E),dot:{color:"bg-cyan-400/60",pulse:!0},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[12px] text-fg-4 truncate",children:y}),badge:(S.length||j.length)>1?e.jsx(dn,{children:S.length||j.length}):void 0,children:e.jsx("div",{ref:g,className:"px-3.5 py-2.5 space-y-0.5 max-h-[280px] overflow-y-auto",children:S.length>0?S.map(E=>e.jsx(jr,{call:E},E.id)):j.map((E,U)=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate",children:E})]},U))})}),t.thinking&&e.jsx(Ye,{open:h,onToggle:()=>d(E=>!E),dot:{color:"bg-violet-400/50",pulse:!0},label:n("hub.thinking"),collapsedContent:e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:$n(t.thinking,3)}),children:e.jsx("div",{ref:m,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[280px] overflow-y-auto",children:t.thinking})}),t.text&&e.jsxs("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:[_,t.phase==="streaming"&&e.jsx(on,{className:"ml-1 inline-flex align-text-bottom text-fg-4"})]}),!t.text&&t.phase==="streaming"&&e.jsx("div",{className:"py-1",children:e.jsx(on,{className:"text-fg-5"})}),t.phase==="streaming"&&(t.generatingImages??0)>0&&e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-fg-4",children:[e.jsxs("span",{className:"relative inline-flex items-center justify-center w-3 h-3",children:[e.jsx("span",{className:"absolute inline-flex w-3 h-3 rounded-full bg-cyan-400/40 animate-ping"}),e.jsx("span",{className:"relative inline-block w-1.5 h-1.5 rounded-full bg-cyan-400/80"})]}),e.jsx("span",{children:t.generatingImages===1?"Generating image…":`Generating ${t.generatingImages} images…`})]}),v&&t.error&&e.jsx(mr,{detail:t.error,t:n,className:"pt-0.5"})]})}function jr({call:t}){const[n,s]=r.useState(!1),a=!!(t.input||t.result),o=t.status==="failed"?"bg-rose-400/70":t.status==="running"?"bg-cyan-400/70":"bg-fg-5/30";return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>a&&s(c=>!c),className:`flex w-full items-center gap-1.5 py-[2px] text-left min-w-0 ${a?"cursor-pointer hover:bg-white/[0.03] rounded":"cursor-default"}`,title:a?void 0:t.summary,children:[e.jsx("span",{className:`w-1 h-1 rounded-full shrink-0 ${o} ${t.status==="running"?"animate-pulse":""}`}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate flex-1",children:t.summary}),a&&e.jsx("span",{className:`shrink-0 text-[9px] text-fg-5/40 transition-transform ${n?"rotate-90":""}`,children:"▸"})]}),n&&e.jsxs("div",{className:"ml-2.5 mt-0.5 mb-1 space-y-1 border-l border-white/[0.06] pl-2.5",children:[t.input&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-4/80 max-h-[140px] overflow-y-auto",children:t.input}),t.result&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-5/70 max-h-[140px] overflow-y-auto border-t border-white/[0.04] pt-1",children:t.result})]})]})}function on({className:t}){return e.jsxs("span",{className:`thinking-dots inline-flex items-center gap-[3px] ${t||""}`,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}function Hn({sub:t,t:n}){const[s,a]=r.useState(!1),o=t.status,c=o==="failed"?"bg-rose-400/60":o==="done"?"bg-emerald-400/55":"bg-amber-400/60",h=o==="running",d=t.tools,g=r.useMemo(()=>{const j=new Set,S=[];for(const y of d)j.has(y.name)||(j.add(y.name),S.push(y.name));return S},[d]),m=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",v=t.model?cn(t.model):null;return e.jsx(Ye,{open:s,onToggle:()=>a(j=>!j),dot:{color:c,pulse:h},label:m,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),v&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:v}),!t.description&&g.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:g.join(" · ")})]}),badge:d.length>0?e.jsx(dn,{children:d.length}):void 0,children:e.jsxs("div",{className:"px-3.5 py-2.5 space-y-1 max-h-[260px] overflow-y-auto",children:[t.description&&e.jsx("div",{className:"mb-1.5 text-[12px] text-fg-3 leading-[1.55]",children:t.description}),d.length===0?e.jsxs("div",{className:"text-[11px] font-mono text-fg-5/50",children:["— ",n("hub.subAgentWaiting")||"waiting for first tool…"]}):d.map(j=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/65 truncate",children:j.summary})]},j.id))]})})}function wr({message:t,t:n,workdir:s}){const{activityBlocks:a,thinkingBlocks:o,planBlocks:c,subAgentBlocks:h,outputBlocks:d,noticeBlocks:g}=Vn(t.blocks),m=[...c].reverse().find(j=>et(j.plan));return a.length>0||h.length>0||!!m?.plan||o.length>0||d.length>0||g.length>0?e.jsxs("div",{className:"space-y-3",children:[a.length>0&&e.jsx(Nr,{blocks:a,t:n}),h.map(j=>j.subAgent?e.jsx(Hn,{sub:j.subAgent,t:n},j.toolId||j.subAgent.id):null),m?.plan&&e.jsx(Un,{plan:m.plan,t:n,className:"max-w-[760px]"}),o.length>0&&e.jsx(Cr,{blocks:o,t:n}),d.length>0&&e.jsx(Lr,{blocks:d,t:n,workdir:s}),g.length>0&&e.jsx(yr,{blocks:g,t:n})]}):null}function kr(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:a,subAgentBlocks:o,outputBlocks:c,noticeBlocks:h}=Vn(t.blocks);return c.length>0||n.length>0||o.length>0||s.length>0||a.some(d=>et(d.plan))||h.length>0}function Vn(t){const n=t.filter(s=>s.type==="plan"||s.type==="tool_use"||s.type==="tool_result"||s.type==="image"||s.type==="sub_agent"||!!s.content.trim());return{activityBlocks:n.filter(s=>s.type==="tool_use"||s.type==="tool_result"),thinkingBlocks:n.filter(s=>s.type==="thinking"),planBlocks:n.filter(s=>s.type==="plan"&&et(s.plan)),subAgentBlocks:n.filter(s=>s.type==="sub_agent"),outputBlocks:n.filter(s=>s.type==="text"||s.type==="image"),noticeBlocks:n.filter(s=>s.type==="system_notice")}}function yr({blocks:t,t:n}){const s=t.map(a=>a.content).filter(Boolean).join(`
13
+
14
+ `).trim();return s?e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/[0.06] px-3 py-2 text-[12.5px] leading-[1.7] text-fg-3",children:[e.jsx("span",{className:"mt-[6px] h-1.5 w-1.5 rounded-full bg-amber-400/70 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-mono uppercase tracking-wide text-amber-300/80",children:n("hub.systemNotice")||"Agent notice"}),e.jsx("div",{className:"mt-0.5 break-words whitespace-pre-wrap",children:s})]})]}):null}function Nr({blocks:t,t:n}){const[s,a]=r.useState(!1),o=t.filter(g=>g.type==="tool_use"),c=o.length,h=o[o.length-1],d=h?On(h):"";return e.jsx(Ye,{open:s,onToggle:()=>a(g=>!g),dot:{color:"bg-cyan-400/60"},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[11.5px] font-mono text-fg-4 truncate",children:d}),badge:c>0?e.jsx(dn,{children:c}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((g,m)=>e.jsx(Sr,{block:g},m))})})}function Sr({block:t}){const[n,s]=r.useState(!1),a=t.type==="tool_use",o=a?On(t):Ys(t);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&s(c=>!c),className:T("flex items-center gap-2 py-[3px] w-full text-left group rounded-sm transition-colors",t.content&&"hover:bg-panel-h/30"),children:[e.jsx("span",{className:T("h-1.5 w-1.5 rounded-full shrink-0",a?"bg-fg-5/40":"bg-ok/40")}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 group-hover:text-fg-3 transition-colors truncate",children:o})]}),n&&t.content&&e.jsx("pre",{className:"ml-3 mt-1 mb-2 p-3 rounded-md bg-inset border border-edge text-[11px] leading-[1.6] text-fg-4 font-mono whitespace-pre-wrap break-words max-h-[240px] overflow-y-auto",children:t.content.length>3e3?t.content.slice(0,3e3)+`
15
+ …`:t.content})]})}function Cr({blocks:t,t:n}){const[s,a]=r.useState(!1),o=r.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
16
+
17
+ `).trim();if(!c)return null;const h=$n(c,3);return e.jsx(Ye,{open:s,onToggle:()=>a(d=>!d),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:h?e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:h}):void 0,children:e.jsx(Er,{scrollRef:o,text:c})})}function Er({scrollRef:t,text:n}){return r.useLayoutEffect(()=>{const s=t.current;s&&(s.scrollTop=s.scrollHeight)},[t]),e.jsx("div",{ref:t,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[320px] overflow-y-auto",children:n})}function Tr({block:t,onLightbox:n,t:s}){const a=t.imageCaption?.trim()||"",[o,c]=r.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:a||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),a&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>c(h=>!h),"aria-expanded":o,className:T("self-start inline-flex items-center gap-1 px-2 py-[3px] rounded-md","text-[11px] font-medium tracking-wide","border border-fg-6/40 bg-fg-6/[0.06] text-fg-3","hover:bg-fg-6/[0.12] hover:text-fg-2 hover:border-fg-6/60","transition-colors"),title:s(o?"hub.imagePromptHide":"hub.imagePromptShow"),children:[e.jsx("span",{"aria-hidden":!0,className:"text-[9px] leading-none",children:o?"▾":"▸"}),e.jsx("span",{children:s("hub.imagePrompt")})]}),o&&e.jsx("div",{className:"rounded-md border border-fg-6/30 bg-fg-6/[0.05] px-3 py-2 max-w-[400px] max-h-[260px] overflow-y-auto",children:e.jsx("div",{className:"text-[11.5px] leading-[1.65] text-fg-3 whitespace-pre-wrap break-words",children:a})})]})]})}function Lr({blocks:t,t:n,workdir:s}){const a=t.filter(m=>m.type==="text"),o=t.filter(m=>m.type==="image"),c=a.map(m=>m.content).filter(Boolean).join(`
18
+
19
+ `),[h,d]=r.useState(null),g=r.useMemo(()=>zt({workdir:s}),[s]);return!c.trim()&&o.length===0?null:e.jsxs(e.Fragment,{children:[c.trim()&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:e.jsx(hn,{remarkPlugins:pn,components:g,children:c})}),o.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:o.map((m,v)=>e.jsx(Tr,{block:m,onLightbox:d,t:n},v))}),h&&e.jsx(Gn,{src:h,onClose:()=>d(null)})]})}const vo=r.memo(function({turn:n,turnIndex:s,agent:a,meta:o,model:c,effort:h,providerName:d,t:g,workdir:m,onResend:v,onEdit:j,onFork:S}){const y=n.user&&Bn(n.user.text),M=S&&typeof s=="number"?()=>S(s):void 0,L=r.useMemo(()=>zt({workdir:m}),[m]),I=!!n.assistant&&kr(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!y&&e.jsx(qn,{text:n.user.text,blocks:n.user.blocks,t:g,onResend:v,onEdit:j,onFork:M}),y&&n.user&&!n.assistant&&e.jsx("div",{className:"mb-4 px-4 py-3 rounded-lg bg-[rgba(255,255,255,0.02)] border border-edge/20 text-[12.5px] leading-[1.7] text-fg-4",children:e.jsx(hn,{remarkPlugins:pn,components:L,children:n.user.text})}),I&&e.jsxs(e.Fragment,{children:[e.jsx(Rr,{agent:a,meta:o,model:c,effort:h,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(wr,{message:n.assistant,t:g,workdir:m})})]})]})});function Gn({src:t,onClose:n}){return r.useEffect(()=>{const s=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),un.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm cursor-zoom-out",onClick:n,children:e.jsx("img",{src:t,className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl",onClick:s=>s.stopPropagation()})}),document.body)}const Mr=1500,Ir=16,Cn=8;function Ar(t){const n=t.split(`
20
+ `);return n.length<=Cn?t:n.slice(0,Cn).join(`
21
+ `)}function qn({text:t,blocks:n,t:s,onResend:a,onEdit:o,onFork:c}){const[h,d]=r.useState(!1),[g,m]=r.useState(!1),[v,j]=r.useState(null),S=t?t.split(`
22
+ `).length:0,y=!!t&&(t.length>Mr||S>Ir),[M,L]=r.useState(!1),I=t?y&&!M?Ar(t):t:"",_=!!(a||o||c),E=n?.filter(R=>R.type==="image")||[],U=()=>{navigator.clipboard.writeText(t).then(()=>{m(!0),setTimeout(()=>m(!1),1500)}).catch(()=>{})},W=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(S));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[I,y&&!M&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),y&&e.jsx("button",{type:"button",onClick:()=>L(R=>!R),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:M?s("hub.collapse"):W}),E.length>0&&e.jsx("div",{className:T("flex flex-wrap gap-2",t&&"mt-2"),children:E.map((R,z)=>e.jsx("img",{src:R.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(R.content)},z))})]}),v&&e.jsx(Gn,{src:v,onClose:()=>j(null)}),_&&e.jsxs("div",{className:T("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",h?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(At,{label:s(g?"hub.copied":"hub.copy"),onClick:U,children:g?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),a&&e.jsx(At,{label:s("hub.rerun"),onClick:()=>a(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),o&&e.jsx(At,{label:s("hub.edit"),onClick:()=>o(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),c&&e.jsx(At,{label:s("hub.fork"),onClick:c,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]})})]})]})}function At({label:t,onClick:n,children:s}){return e.jsx("button",{onClick:n,title:t,className:"flex items-center justify-center w-7 h-7 rounded border border-fg-6 bg-panel text-fg-4 shadow-sm hover:text-fg-2 hover:border-edge-h hover:bg-panel-h transition-colors",children:s})}function Rr({agent:t,meta:n,model:s,effort:a,providerName:o,previewMeta:c,liveStartedAt:h}){const d=c?.contextPercent??null,g=c?.contextUsedTokens??0,m=c?.turnOutputTokens??0,v=d!=null||g>0||m>0,j=h!=null&&h>0,S=c?.providerName??o??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(Je,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||a)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&a?" · ":"",a||""]}),S&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/70 px-1.5 py-px rounded bg-fg-5/8",title:`This turn is routed through ${S} (BYOK), not the agent CLI's native auth.`,children:["via ",S]}),(v||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:Br(c),children:[d!=null&&e.jsx($r,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),g>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",Wr(g)]}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Qn(m)]}),j&&e.jsx(_r,{startedAt:h,leadingDot:v})]})]})}function _r({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const o=setInterval(()=>s(c=>c+1),1e3);return()=>clearInterval(o)},[]);const a=Math.max(0,Date.now()-t);return e.jsxs("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:[n?"· ":"",Pr(a)]})}function Pr(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),a=n%60;return s<60?`${s}m${a.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function Wr(t){return`${Qn(t)} tok`}function Qn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function Br(t){if(!t)return"";const n=[];return t.contextPercent!=null&&n.push(`Context: ${t.contextPercent.toFixed(1)}%`),t.inputTokens!=null&&n.push(`Input: ${t.inputTokens.toLocaleString()}`),t.turnOutputTokens!=null?n.push(`Output (turn): ${t.turnOutputTokens.toLocaleString()}`):t.outputTokens!=null&&n.push(`Output: ${t.outputTokens.toLocaleString()}`),t.cachedInputTokens!=null&&n.push(`Cached: ${t.cachedInputTokens.toLocaleString()}`),n.join(" · ")}function $r({pct:t}){const n=t>=85?"bg-rose-400/70":t>=60?"bg-amber-400/70":"bg-emerald-400/70";return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${n}`})}function En(t,n,s){return t==="zh-CN"?n:s}function Or({open:t,onClose:n,workdir:s}){const a=we(c=>c.locale),o=s.split("/").pop()||s;return e.jsxs(Bt,{open:t,onClose:n,wide:!0,children:[e.jsx($t,{title:En(a,`${o} — 项目扩展`,`${o} — Project Extensions`),description:En(a,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(Es,{workdir:s}):null]})}let Tn=In(()=>import("./SessionPanel-BVC7kwlX.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function ln(){return Tn??=In(()=>import("./SessionPanel-BVC7kwlX.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Tn}const Dr=r.lazy(async()=>({default:(await ln()).SessionPanel})),nn=5,zr=240,Fr=120,Ur=12,Kr=900*1e3,F=(t,n)=>`${t}:${n}`;function Hr(t){const n=new Map;for(const d of t)n.set(F(d.agent||"",d.sessionId),d);const s=new Map,a=new Set;for(const d of t){const g=d.migratedFrom;if(!g||g.kind!=="fork"||!g.sessionId)continue;const m=F(g.agent||d.agent||"",g.sessionId);n.has(m)&&(a.add(F(d.agent||"",d.sessionId)),s.has(m)||s.set(m,[]),s.get(m).push(d))}const o=[],c=new Set,h=(d,g)=>{const m=F(d.agent||"",d.sessionId);if(c.has(m))return;c.add(m),o.push(Object.assign({},d,{__forkDepth:g}));const v=s.get(m);if(v)for(const j of v)h(j,g+1)};for(const d of t){const g=F(d.agent||"",d.sessionId);a.has(g)||h(d,0)}for(const d of t)h(d,0);return o}let Vr=0;function Rt(){return`mk-${Date.now().toString(36)}-${(++Vr).toString(36)}`}function Gr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function qr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function Zn(t){switch(t){case"cursor":return"hub.openTargetCursor";case"windsurf":return"hub.openTargetWindsurf";case"finder":return"hub.openTargetFinder";case"default":return"hub.openTargetDefault";default:return"hub.openTargetVsCode"}}const Qr=r.memo(function({active:n=!0}){const s=we(l=>l.locale),a=we(l=>l.state?.runtimeWorkdir??null),o=r.useMemo(()=>ms(s),[s]),[c,h]=r.useState([]),[d,g]=r.useState({}),[m,v]=r.useState({}),[j,S]=r.useState(!0),[y,M]=r.useState(()=>{try{const u=sessionStorage.getItem("pikiloom-layout-mode");if(u==="1"||u==="2"||u==="3"||u==="6")return Number(u)}catch{}const l=window.innerWidth;return l>=1920?3:l>=1280?2:1}),[L,I]=r.useState(()=>{try{const l=sessionStorage.getItem("pikiloom-open-sessions");if(l){const u=JSON.parse(l);if(Array.isArray(u))return u.map(f=>({...f,mountKey:f.mountKey||Rt()}))}}catch{}return[]}),[_,E]=r.useState(()=>{try{const l=sessionStorage.getItem("pikiloom-active-slot");if(l!=null){const u=Number(l);if(Number.isFinite(u)&&u>=0)return u}}catch{}return 0}),U=r.useCallback(l=>{M(l);try{sessionStorage.setItem("pikiloom-layout-mode",String(l))}catch{}},[]),W=r.useCallback(l=>{I(u=>{const f=typeof l=="function"?l(u):l;try{const p=f.map(({pendingPrompt:w,pendingImageUrls:k,...C})=>C);sessionStorage.setItem("pikiloom-open-sessions",JSON.stringify(p))}catch{}return f})},[]),R=r.useCallback(l=>{E(u=>{const f=typeof l=="function"?l(u):l;try{sessionStorage.setItem("pikiloom-active-slot",String(f))}catch{}return f})},[]);r.useEffect(()=>{W(l=>l.length>y?l.slice(0,y):l),R(l=>l>=y?y-1:l)},[y]);const[z,K]=r.useState(!1),le=r.useRef(y);le.current=y;const ee=r.useRef(_);ee.current=_;const A=r.useRef(-1),H=L[_]??null,Me=r.useCallback(l=>{if(!l){W([]),R(0);return}const u=l.mountKey?l:{...l,mountKey:Rt()};W(f=>{const p=f.findIndex(k=>k.agent===u.agent&&k.sessionId===u.sessionId);if(p>=0)return R(p),f;if(f.length<le.current){const k=[...f,u];return R(k.length-1),k}const w=[...f];return w[ee.current]=u,w})},[]),[de,ke]=r.useState(!1),[O,Fe]=r.useState(null),[Ie,tt]=r.useState(""),[ye,jt]=r.useState("all"),[ue,wt]=r.useState({}),te=r.useDeferredValue(Ie),ne=r.useRef(!1),Ue=r.useRef({}),Ae=r.useRef(d);Ae.current=d;const Ke=r.useRef(ue);Ke.current=ue;const nt=r.useRef(new Set),se=r.useRef({});r.useEffect(()=>()=>{for(const l of Object.values(se.current))clearTimeout(l)},[]);const ae=r.useCallback(async()=>{try{const l=await Y.getWorkspaces(),u=l.ok?l.workspaces:[];u.length&&h(f=>f.length===u.length&&f.every((p,w)=>p.path===u[w].path&&p.name===u[w].name)?f:u),ne.current=!0}catch{ne.current=!0}finally{S(!1)}},[]);r.useEffect(()=>{ae()},[ae]);const B=r.useCallback(async(l,u={})=>{if(!Ue.current[l]){Ue.current[l]=!0,u.background||v(f=>({...f,[l]:!0}));try{const f=await As(l,{force:u.force});r.startTransition(()=>{g(p=>{const w=f.sessions||[],k=p[l]||[],C=new Set(w.map(D=>F(D.agent||"",D.sessionId))),G=k.filter(D=>{if(D.runState!=="running")return!1;const J=F(D.agent||"",D.sessionId);if(C.has(J))return!1;const ht=Ke.current[J];return!(ht?.resolvedKey&&ht.resolvedKey!==J)});return{...p,[l]:G.length?[...G,...w]:w}})})}catch{u.background||r.startTransition(()=>{g(f=>({...f,[l]:[]}))})}finally{Ue.current[l]=!1,u.background||v(f=>({...f,[l]:!1}))}}},[]),Ne=r.useRef(a);r.useEffect(()=>{a!==Ne.current&&(Ne.current=a,!(!a||!ne.current)&&ae().then(()=>{B(a,{force:!0})}))},[a,ae,B]);const Z=r.useCallback((l,u)=>{const f=l.agent||"";!f||!l.sessionId||(ln(),Ps({workdir:u,agent:f,sessionId:l.sessionId,rich:!0,turnOffset:0,turnLimit:Ur}))},[]),Re=r.useCallback((l,u,f=Fr)=>{const p=`${u}:${F(l.agent||"",l.sessionId)}`,w=se.current[p];w&&clearTimeout(w),se.current[p]=setTimeout(()=>{delete se.current[p],Z(l,u)},f)},[Z]),_e=r.useCallback((l,u)=>{const f=`${u}:${F(l.agent||"",l.sessionId)}`,p=se.current[f];p&&(clearTimeout(p),delete se.current[f])},[]);r.useEffect(()=>{n&&ln()},[n]),r.useEffect(()=>{if(!n)return;const l=[];return c.forEach((u,f)=>{if(d[u.path]||m[u.path])return;const p=setTimeout(()=>{B(u.path)},f*90);l.push(p)}),()=>{for(const u of l)clearTimeout(u)}},[n,B,m,d,c]);const kt=r.useRef(new Map);Nn(n&&ne.current&&c.length>0?"sessions-changed":null,r.useCallback(l=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const u=l.key,f=u?c.filter(k=>(Ae.current[k.path]||[]).some(C=>F(C.agent||"",C.sessionId)===u)):c,p=f.length?f:c,w=kt.current;for(const k of p)w.has(k.path)&&clearTimeout(w.get(k.path)),w.set(k.path,setTimeout(()=>{w.delete(k.path),B(k.path,{background:!0,force:!0})},300))},[c,B]));const $=r.useCallback(l=>{const u=l.agent||"";return!u||!l.sessionId?l:bs(l,ue[F(u,l.sessionId)]||null)},[ue]);Nn("stream-update",r.useCallback(l=>{const u=l.key;u&&wt(f=>{const p={},w=Date.now()-Kr;for(const[C,G]of Object.entries(f))G.updatedAt>=w&&(p[C]=G);const k=vs(u,l.snapshot??null);if(!k){const C=p[u];return C&&C.phase!=="done"&&(p[u]={...C,phase:"done",updatedAt:Date.now()}),p}return p[u]=k,k.resolvedKey!==u&&(p[k.resolvedKey]={...k,key:k.resolvedKey}),p})},[])),Us(r.useCallback(()=>{if(!(!n||!ne.current||c.length===0))for(const l of c)B(l.path,{background:!0,force:!0})},[n,c,B])),r.useEffect(()=>{if(!n||!ne.current||c.length===0)return;const l=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const f of c)B(f.path,{background:!0,force:!0})};if(l(),typeof document>"u"||typeof window>"u")return;const u=()=>{document.visibilityState==="visible"&&l()};return document.addEventListener("visibilitychange",u),window.addEventListener("focus",u),()=>{document.removeEventListener("visibilitychange",u),window.removeEventListener("focus",u)}},[n,B,c]),r.useEffect(()=>{if(!n)return;const l=[];return c.forEach((u,f)=>{const p=(d[u.path]||[])[0];if(!p)return;const w=`${u.path}:${F(p.agent||"",p.sessionId)}`;if(nt.current.has(w))return;const k=setTimeout(()=>{nt.current.add(w),Z(p,u.path)},zr+f*120);l.push(k)}),()=>{for(const u of l)clearTimeout(u)}},[n,d,Z,c]);const re=r.useCallback(async l=>{try{(await Y.addWorkspace(l)).ok&&(ke(!1),await ae(),B(l))}catch{}},[ae,B]),[xe,Se]=r.useState(null),[oe,Pe]=r.useState(!1),[st,yt]=r.useState(null),He=r.useCallback(l=>{Se(l)},[]),rt=r.useCallback(async()=>{const l=xe;if(l){Pe(!0);try{await Y.removeWorkspace(l),h(u=>u.filter(f=>f.path!==l)),g(u=>{const f={...u};return delete f[l],f}),W(u=>u.filter(f=>f.workdir!==l)),R(0),Se(null)}catch{}finally{Pe(!1)}}},[xe]),ot=r.useCallback(l=>{B(l,{force:!0})},[B]),[Ce,V]=r.useState(null),[pe,Ee]=r.useState(!1),[ie,We]=r.useState(!1),Be=we(l=>l.toast),[he,it]=r.useState(null),lt=r.useCallback((l,u,f)=>{it({anchor:{right:l.right,bottom:l.bottom},target:{workdir:f,agent:u.agent||"",sessionId:u.sessionId,title:Ln(u).slice(0,120)||u.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!he)return;const l=()=>it(null),u=f=>{f.key==="Escape"&&l()};return window.addEventListener("mousedown",l),window.addEventListener("scroll",l,!0),window.addEventListener("resize",l),window.addEventListener("keydown",u),()=>{window.removeEventListener("mousedown",l),window.removeEventListener("scroll",l,!0),window.removeEventListener("resize",l),window.removeEventListener("keydown",u)}},[he]);const Ft=r.useCallback(l=>{Ee(!1),V(l),it(null)},[]),Nt=r.useCallback(async()=>{const l=Ce;if(l){We(!0);try{const u=await Y.deleteSession(l.workdir,l.agent,l.sessionId,pe);if(!u.ok){const f=u.error?.includes("still running")?o("session.deleteRunningError"):u.error||o("session.deleteFailed");Be(f,!1);return}g(f=>{const p=f[l.workdir];if(!p)return f;const w=p.filter(k=>!(k.agent===l.agent&&k.sessionId===l.sessionId));return w.length===p.length?f:{...f,[l.workdir]:w}}),W(f=>f.filter(p=>!(p.workdir===l.workdir&&p.agent===l.agent&&p.sessionId===l.sessionId))),V(null)}catch(u){Be(u?.message||o("session.deleteFailed"),!1)}finally{We(!1)}}},[Ce,pe,o,Be]),Ut=r.useCallback(l=>{W(u=>{let f=!1;const p=u.map(w=>w.mountKey===l&&(w.pendingPrompt!=null||w.pendingImageUrls)?(f=!0,{...w,pendingPrompt:null,pendingImageUrls:void 0}):w);return f?p:u})},[W]),at=r.useCallback((l,u,f)=>{Z({agent:l.agent,sessionId:l.sessionId,runState:"running"},l.workdir),g(k=>{const C=k[l.workdir]||[];if(C.some(J=>J.sessionId===l.sessionId&&J.agent===l.agent))return k;const D={sessionId:l.sessionId,agent:l.agent,runState:"running",lastQuestion:u,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...k,[l.workdir]:[D,...C]}});const p=A.current,w={...l,mountKey:Rt(),pendingPrompt:u||null,pendingImageUrls:f&&f.length?f:void 0};r.startTransition(()=>{Fe(null),W(k=>{if(p>=k.length)return[...k,w];const C=[...k];return C[p]=w,C}),R(p>=0?p:0)}),B(l.workdir,{background:!0,force:!0})},[B,Z,W,R]),$e=r.useCallback((l,u)=>{Z(l,u),Fe(null),r.startTransition(()=>{Me({agent:l.agent||"",sessionId:l.sessionId,workdir:u})})},[Z]),Ve=r.useCallback((l,u)=>{Z({agent:l.agent,sessionId:l.sessionId,runState:"running"},l.workdir),r.startTransition(()=>{u!=null?(W(f=>{if(u>=f.length)return f;const p=[...f];return p[u]={...f[u],agent:l.agent,sessionId:l.sessionId,workdir:l.workdir},p}),R(u)):Me({...l,mountKey:Rt()})}),B(l.workdir,{background:!0,force:!0})},[B,Z]),ct=r.useCallback(l=>{let u=l;if(ye==="running"?u=u.filter(f=>_t(f)==="running"):ye==="review"&&(u=u.filter(f=>_t(f)==="incomplete")),te.trim()){const f=te.toLowerCase();u=u.filter(p=>(p.lastMessageText||"").toLowerCase().includes(f)||(p.lastQuestion||"").toLowerCase().includes(f)||(p.lastAnswer||"").toLowerCase().includes(f)||(p.title||"").toLowerCase().includes(f)||(p.agent||"").toLowerCase().includes(f))}return u},[te,ye]),dt=r.useMemo(()=>{const l={};for(const u of c){const f=(d[u.path]||[]).map($),p=new Map;for(const k of f){const C=F(k.agent||"",k.sessionId),G=ue[C],D=G?.resolvedKey&&G.resolvedKey!==C?G.resolvedKey:C,J=p.get(D);if(!J){p.set(D,k);continue}F(J.agent||"",J.sessionId)!==D&&C===D&&p.set(D,k)}const w=ct([...p.values()]);l[u.path]=Hr(w)}return l},[c,d,ue,ct,$]),ge=r.useCallback(l=>{const u=(d[l.workdir]||[]).find(f=>f.sessionId===l.sessionId&&f.agent===l.agent)??{sessionId:l.sessionId,agent:l.agent,runState:"running"};return $(u)},[$,d]),St=r.useMemo(()=>new Set(L.map(l=>F(l.agent,l.sessionId))),[L]),ut=H?F(H.agent,H.sessionId):null,Ct=r.useCallback(l=>{W(u=>{const f=u.filter((p,w)=>w!==l);return f.length===0?R(0):ee.current>=f.length&&R(f.length-1),f})},[]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:Ie,onChange:l=>tt(l.target.value),placeholder:o("hub.search"),className:"w-full rounded-lg border border-edge/40 bg-inset/50 pl-8 pr-7 py-1.5 text-[12px] text-fg outline-none placeholder:text-fg-5/30 focus:border-primary/30 focus:bg-inset focus:shadow-[0_0_0_3px_rgba(99,102,241,0.06)] transition-all duration-200"}),Ie&&e.jsx("button",{onClick:()=>tt(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-fg-5/30 hover:text-fg-4 transition-colors",children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex items-center rounded-lg bg-inset/30 border border-edge/20 p-0.5",children:["all","running","review"].map(l=>e.jsx("button",{onClick:()=>jt(l),className:T("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",ye===l?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1),inset_0_1px_0_rgba(255,255,255,0.04)]":"text-fg-5/60 hover:text-fg-4"),children:o(`hub.filter${l[0].toUpperCase()+l.slice(1)}`)},l))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(fe,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!de?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:o("hub.noWorkspaces")}):c.map(l=>e.jsx(Yr,{workspace:l,sessions:dt[l.path]||[],loading:!!m[l.path]||!(l.path in d),isActive:l.path===a,selectedKey:ut,openSessionKeys:St,onSelectSession:$e,onNewSession:Fe,onRefresh:ot,onRemove:He,onExtensions:yt,onWarmSession:Re,onCancelWarmSession:_e,onSessionMenuOpen:lt,t:o},l.path))}),e.jsxs("div",{className:"shrink-0 border-t border-edge/20 px-3 py-2 space-y-1.5",children:[e.jsx("div",{className:"flex items-center rounded-md bg-inset/30 border border-edge/20 p-0.5",children:[1,2,3,6].map(l=>e.jsx("button",{onClick:()=>U(l),className:T("flex-1 flex items-center justify-center p-1.5 rounded transition-all",y===l?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1)]":"text-fg-5/40 hover:text-fg-4"),title:o(`hub.layout${l}`),children:l===1?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"})}):l===2?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"12",rx:"1.5"}),e.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"1.5"})]}):l===3?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"0.5",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"11.5",y:"2",width:"4",height:"12",rx:"1"})]}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:[e.jsx("rect",{x:"0.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"0.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"})]})},l))}),e.jsxs(Te,{variant:"ghost",size:"sm",onClick:()=>ke(l=>!l),className:"w-full",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),o("hub.addWorkspace")]})]})]}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden gap-0",children:e.jsx("div",{className:"flex-1 min-h-0 grid gap-3",style:{gridTemplateColumns:`repeat(${y===6?3:y}, 1fr)`,gridTemplateRows:y===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const l=O?L.length<y?L.length:_:-1;return A.current=l,Array.from({length:y},(u,f)=>{if(O&&f===l)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-edge bg-panel flex flex-col",style:{boxShadow:"var(--th-card-shadow)"},children:e.jsx(Jr,{workdir:O,workspaceName:c.find(C=>C.path===O)?.name||O.split("/").pop()||"",onSessionCreated:at,onClose:()=>Fe(null),t:o},O)},`new-${O}`);const p=L[f]??null;if(!p)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-dashed border-edge/40 bg-panel/30 flex items-center justify-center",children:e.jsxs("div",{className:"text-center px-4",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"mx-auto text-fg-5/20 mb-2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("div",{className:"text-[12px] text-fg-5/40",children:o("hub.emptySlot")})]})},`empty-${f}`);const w=ge(p),k=f===_;return e.jsxs("div",{className:T("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",k?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:k?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>R(f),children:[e.jsxs("div",{className:T("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",k?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const C=_t(w);return e.jsx(Dt,{variant:C==="running"?"ok":C==="waiting"?"info":C==="incomplete"?"warn":"idle",pulse:C==="running"||C==="waiting"})})(),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-0",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-fg-5",children:p.workdir.split("/").pop()||p.workdir}),e.jsx("span",{className:"shrink-0 text-fg-6 text-[10px] mx-1",children:"/"}),e.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-fg-3",children:w.title||w.lastQuestion?.slice(0,60)||p.sessionId.slice(0,12)})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-2.5 pl-4 text-[9px] text-fg-5/50 tabular-nums",children:[e.jsx("span",{title:o("hub.created"),children:js(w.createdAt)}),w.runUpdatedAt&&e.jsx("span",{title:o("hub.updated"),children:Mn(w.runUpdatedAt)}),!!w.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),w.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:C=>{C.stopPropagation(),K(G=>!G)},className:T("p-0.5 rounded transition-colors",z?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:o("hub.files"),children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})})}),e.jsx("button",{onClick:C=>{C.stopPropagation(),Ct(f)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:o("hub.closePanel"),children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Dr,{session:w,workdir:p.workdir,active:n&&k,onSessionChange:C=>Ve(C,f),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>Ut(p.mountKey)},p.mountKey)})})]},p.mountKey||F(p.agent,p.sessionId))})})()})}),z&&H&&e.jsx(to,{workdir:H.workdir,onClose:()=>K(!1),t:o}),e.jsx(Zr,{open:de,initialPath:a||void 0,onAdd:re,onClose:()=>ke(!1),t:o}),e.jsxs(Bt,{open:!!xe,onClose:()=>!oe&&Se(null),children:[e.jsx($t,{title:o("hub.removeWorkspace"),onClose:()=>!oe&&Se(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:o("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:o("modal.confirmRemoveWorkspaceHint")}),xe&&e.jsx("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 font-mono text-[11px] text-fg-4 break-all",children:xe}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Te,{variant:"ghost",onClick:()=>Se(null),disabled:oe,children:o("modal.cancel")}),e.jsx(Te,{variant:"primary",onClick:rt,disabled:oe,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:o(oe?"modal.removing":"modal.remove")})]})]}),he&&(()=>{const u=Math.max(8,Math.min(he.anchor.right-160,window.innerWidth-160-8)),f=Math.min(he.anchor.bottom+4,window.innerHeight-60);return e.jsx("div",{className:"fixed z-[60] min-w-[160px] rounded-md border border-edge bg-panel/95 backdrop-blur-md py-1",style:{left:u,top:f,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:p=>p.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>Ft(he.target),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-[12px] text-fg-2 hover:bg-panel-h/60 hover:text-red-400 transition-colors",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),e.jsx("path",{d:"M10 11v6"}),e.jsx("path",{d:"M14 11v6"}),e.jsx("path",{d:"M9 6V4a2 2 0 012-2h2a2 2 0 012 2v2"})]}),o("session.delete")]})})})(),e.jsxs(Bt,{open:!!Ce,onClose:()=>!ie&&V(null),children:[e.jsx($t,{title:o("session.deleteTitle"),onClose:()=>!ie&&V(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:o("session.deleteHint")}),Ce&&e.jsxs("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 text-[11px] text-fg-4 break-all",children:[e.jsx("span",{className:"font-mono text-fg-5",children:Ce.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Ce.title})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:!pe,onChange:()=>Ee(!1),disabled:ie,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:o("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:o("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:pe,onChange:()=>Ee(!0),disabled:ie,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:o("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:o("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Te,{variant:"ghost",onClick:()=>V(null),disabled:ie,children:o("modal.cancel")}),e.jsx(Te,{variant:"primary",onClick:Nt,disabled:ie,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:o(ie?"session.deleting":"modal.remove")})]})]}),e.jsx(Or,{open:!!st,onClose:()=>yt(null),workdir:st||""})]})});function Zr({open:t,initialPath:n,onAdd:s,onClose:a,t:o}){const[c,h]=r.useState(""),d=r.useCallback(g=>h(g),[]);return r.useEffect(()=>{t&&h("")},[t]),e.jsxs(Bt,{open:t,onClose:a,children:[e.jsx($t,{title:o("hub.addWorkspace"),onClose:a}),e.jsx(Ns,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:o}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Te,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:o("hub.add")}),e.jsx(Te,{variant:"secondary",onClick:a,className:"flex-1",children:o("hub.cancel")})]})]})}function Jr({workdir:t,workspaceName:n,onSessionCreated:s,onClose:a,t:o}){const[c,h]=r.useState(null),[d,g]=r.useState([]),m=r.useRef(null),v=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),S=r.useCallback(()=>{},[]),y=r.useCallback((I,_)=>{h(I||null),m.current=I||null;const E=_||[];g(E),v.current=E},[]),M=r.useCallback(I=>{const _=v.current;v.current=[],s(I,m.current||void 0,_.length?_:void 0)},[s]),L=!!c||d.length>0;return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 h-10 border-b border-edge/50 bg-panel/40 backdrop-blur-md z-10",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[13px] font-medium text-fg truncate",children:o("hub.newSession")}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-fg-5/60 shrink-0",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"})}),e.jsx("span",{className:"max-w-[80px] truncate",children:n})]}),e.jsx(Dt,{variant:L?"ok":"idle",pulse:L}),!L&&e.jsx("button",{onClick:a,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:L?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(qn,{text:c||"",blocks:d.map(I=>({type:"image",content:I})),t:o}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(on,{className:"text-fg-5"})})]}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"text-center space-y-1.5",children:e.jsx("div",{className:"text-[13px] text-fg-5",children:o("hub.newSessionHint")})})})}),e.jsx(sr,{session:j,workdir:t,onStreamQueued:S,onSendStart:y,onSessionChange:M,t:o,streamPhase:null})]})}function Xr({git:t}){if(!t)return null;const n=[t.detached?`detached HEAD${t.shortSha?` @ ${t.shortSha}`:""}`:`branch ${t.branch??"?"}`,t.upstream?`upstream ${t.upstream}`:t.detached?"":"no upstream",t.ahead||t.behind?`↑${t.ahead} ahead · ↓${t.behind} behind`:"",t.changed>0?`${t.changed} changed (${t.staged} staged · ${t.unstaged} unstaged · ${t.untracked} untracked)`:"clean"].filter(Boolean).join(`
23
+ `);return e.jsx(ws,{content:n,className:T("shrink-0 items-center",t.changed>0?"text-amber-400/80":t.ahead||t.behind?"text-sky-400/70":"text-fg-5/50"),onClick:s=>s.stopPropagation(),children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.5"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.5"}),e.jsx("circle",{cx:"18",cy:"8",r:"2.5"}),e.jsx("path",{d:"M6 8.5v7"}),e.jsx("path",{d:"M18 10.5c0 4.5-6 3-6 7.5"})]})})}const Yr=r.memo(function({workspace:n,sessions:s,loading:a,isActive:o,selectedKey:c,openSessionKeys:h,onSelectSession:d,onNewSession:g,onRefresh:m,onRemove:v,onExtensions:j,onWarmSession:S,onCancelWarmSession:y,onSessionMenuOpen:M,t:L}){const[I,_]=r.useState(!0),[E,U]=r.useState(nn);r.useEffect(()=>{U(nn)},[s.length]);const W=s.slice(0,E),R=s.length-E,z=n.path,[K,le]=r.useState(null),ee=r.useCallback(()=>{Y.getWorkspaceGit(z).then(A=>le(A.git)).catch(()=>le(null))},[z]);return r.useEffect(()=>{ee()},[ee]),e.jsxs("div",{className:"border-b border-edge/30",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-panel-h/50 transition-colors",onClick:()=>_(A=>!A),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:T("shrink-0 text-fg-5 transition-transform duration-150",I&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[e.jsx("span",{className:T("min-w-0 truncate text-[12px] font-semibold",o?"text-primary":"text-fg-3"),children:n.name}),e.jsx(Xr,{git:K})]}),o&&e.jsx(Dt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:A=>{A.stopPropagation(),g(z)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:L("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:A=>{A.stopPropagation(),j(z)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:L("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:A=>{A.stopPropagation(),m(z),ee()},className:"p-1 rounded text-fg-5 hover:text-fg-2 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),!o&&e.jsx("button",{onClick:A=>{A.stopPropagation(),v(z)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),I&&e.jsx("div",{className:"pb-1",children:a?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(fe,{className:"h-3 w-3 text-fg-5"})}):s.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:L("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[W.map(A=>{const H=F(A.agent||"",A.sessionId),Me=A.__forkDepth||0;return e.jsx(eo,{session:A,isSelected:c===H,isOpen:h?.has(H)??!1,forkDepth:Me,onClick:()=>d(A,z),onWarm:()=>S(A,z),onCancelWarm:()=>y(A,z),onShowMenu:de=>M(de,A,z),menuLabel:L("session.openActions")},H)}),R>0&&e.jsxs("button",{onClick:()=>U(A=>A+nn),className:"flex items-center gap-1.5 w-full px-3 py-1.5 text-[11px] text-fg-5 hover:text-fg-3 hover:bg-panel-h/50 transition-colors",children:[e.jsxs("span",{children:["+ ",L("hub.nMore").replace("{n}",String(R))]}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]})})]})}),eo=r.memo(function({session:n,isSelected:s,isOpen:a,forkDepth:o=0,onClick:c,onWarm:h,onCancelWarm:d,onShowMenu:g,menuLabel:m}){const v=sn(n.agent||""),j=_t(n),S=Ln(n).slice(0,500)||n.sessionId.slice(0,16),y=ks(n,S).slice(0,500),M=n.model?cn(n.model):null,L=o>0?Math.min(o,3)*14:0,I=a?10:12,_=r.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:h,onFocus:h,onMouseLeave:d,onBlur:d,className:T("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":a?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:I+L,...a?{borderLeft:`2px solid ${s?v.color:`${v.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[o>0&&e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-fg-5/60 shrink-0","aria-label":"Fork",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]}),e.jsx(Je,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:v.color},children:v.shortLabel}),M&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:M}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5 shrink-0 transition-opacity group-hover:opacity-0 group-focus-within:opacity-0",children:[!!n.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5 text-fg-5/50 tabular-nums",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-50",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),n.numTurns]}),e.jsx("span",{className:"tabular-nums",children:Mn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Dt,{variant:j==="running"?"ok":j==="waiting"?"info":j==="incomplete"?"warn":"idle",pulse:j==="running"||j==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:S})]}),y&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:y})})]}),e.jsx("button",{ref:_,type:"button","aria-label":m,"aria-haspopup":"menu",onMouseDown:E=>{E.stopPropagation()},onClick:E=>{E.stopPropagation(),E.preventDefault(),_.current&&g(_.current.getBoundingClientRect())},className:"absolute top-1.5 right-1.5 p-1 rounded text-fg-5 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:bg-panel-h hover:text-fg-2 transition-opacity",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"5",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})})]})}),to=r.memo(function({workdir:n,onClose:s,t:a}){const o=we(v=>v.state?.hostApp??null),c=we(v=>v.state?.platform??null),h=we(v=>v.toast),[d,g]=r.useState(()=>qr(o,c)),m=r.useCallback(async v=>{try{const j=await Y.openInEditor(v,d);if(!j.ok)throw new Error(j.error||`Failed to open ${v}`)}catch(j){h(j?.message||String(j),!1)}},[d,h]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:a("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:a("hub.closePanel"),children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"shrink-0 px-2.5 py-1.5 border-b border-edge/20 flex items-center gap-2",children:[e.jsx(ys,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(v=>({value:v,label:a(Zn(v))})),onChange:v=>{Gr(v)&&g(v)},renderIcon:v=>e.jsx(Jn,{target:v,size:14})}),e.jsx(Te,{size:"sm",variant:"ghost",onClick:()=>m(n),className:"flex-1 min-w-0 text-[11px]",children:a("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(no,{basePath:n,openTarget:d,onOpenPath:m,t:a})})]})});function Jn({target:t,size:n=16}){return t==="default"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 16 16",className:"shrink-0 text-fg-4",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 3H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-2"}),e.jsx("path",{d:"M9 2h5v5"}),e.jsx("path",{d:"M14 2L7 9"})]}):e.jsx(Je,{brand:t,size:n})}function no({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:a,t:o}){const[c,h]=r.useState([]),[d,g]=r.useState(!0);r.useEffect(()=>{let v=!1;return g(!0),Y.lsDir(t,!0,n).then(j=>{!v&&j.ok&&h(j.dirs.slice(0,50).map(S=>({entry:S,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{v||g(!1)}),()=>{v=!0}},[t,n]);const m=r.useCallback(v=>{const j=S=>S.map(y=>y.entry.path===v?y.expanded?{...y,expanded:!1}:y.children===null?(Y.lsDir(v,!0,n).then(M=>{M.ok&&h(L=>an(L,v,{children:M.dirs.slice(0,50).map(I=>({entry:I,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{h(M=>an(M,v,{children:[],loading:!1}))}),{...y,loading:!0,expanded:!0}):{...y,expanded:!0}:y.children?{...y,children:j(y.children)}:y);h(S=>j(S))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(fe,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(Xn,{nodes:c,depth:0,onToggle:m,openTarget:s,onOpenPath:a,t:o})})}function Xn({nodes:t,depth:n,onToggle:s,openTarget:a,onOpenPath:o,t:c}){return e.jsx(e.Fragment,{children:t.map(h=>e.jsx(so,{node:h,depth:n,onToggle:s,openTarget:a,onOpenPath:o,t:c},h.entry.path))})}function so({node:t,depth:n,onToggle:s,openTarget:a,onOpenPath:o,t:c}){const{entry:h,expanded:d,children:g,loading:m}=t,v=n*14,[j,S]=r.useState(!1),y=c(Zn(a)),M=c("hub.openWithTarget").replace("{target}",y);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:h.isDir?()=>s(h.path):void 0,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),className:T("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",h.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+v,paddingRight:8},children:[h.isDir?m?e.jsx(fe,{className:"h-2 w-2 text-fg-5 shrink-0"}):e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:T("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),h.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:h.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:L=>{L.stopPropagation(),o(h.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:M,children:e.jsx(Jn,{target:a,subtle:!0})}),!h.isDir&&e.jsx(ro,{filePath:h.path,t:c})]})]}),h.isDir&&d&&g&&g.length>0&&e.jsx(Xn,{nodes:g,depth:n+1,onToggle:s,openTarget:a,onOpenPath:o,t:c})]})}function ro({filePath:t,t:n}){const[s,a]=r.useState(!1);return e.jsx("button",{onClick:o=>{o.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{a(!0),setTimeout(()=>a(!1),1500)}).catch(()=>{})},className:T("p-0.5 rounded transition-colors",s?"text-ok":"text-fg-5 hover:text-fg-3"),title:n("hub.copied"),children:s?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})}function an(t,n,s){return t.map(a=>a.entry.path===n?{...a,...s}:a.children?{...a,children:an(a.children,n,s)}:a)}const jo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Qr},Symbol.toStringTag,{value:"Module"}));export{sr as I,bo as L,mr as R,vo as T,qn as U,po as a,Kn as b,Us as c,on as d,mo as e,Rr as f,jo as i,_s as l,go as m,xo as n,Rs as p,Nn as u};
@@ -1 +1 @@
1
- import{j as s}from"./react-vendor-C7Sl8SE7.js";import{K as t,k as i,S as a}from"./index-BCYshErN.js";function o({primary:e,secondary:l,tertiary:n}){return s.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e&&s.jsxs(i,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(i,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),n&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:n})]})}function c({children:e,className:l}){return s.jsx(t,{padding:"md",elevation:"flat",className:l,children:e})}export{o as A,c as S};
1
+ import{j as s}from"./react-vendor-C7Sl8SE7.js";import{K as t,k as i,S as a}from"./index-5Q-Q7ByM.js";function o({primary:e,secondary:l,tertiary:n}){return s.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e&&s.jsxs(i,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(i,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),n&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:n})]})}function c({children:e,className:l}){return s.jsx(t,{padding:"md",elevation:"flat",className:l,children:e})}export{o as A,c as S};
@@ -6,7 +6,7 @@
6
6
  <link rel="icon" type="image/png" href="/logo.png">
7
7
  <title>Pikiloom</title>
8
8
  <link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
9
- <script type="module" crossorigin src="/assets/index-BCYshErN.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-5Q-Q7ByM.js"></script>
10
10
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-C7Sl8SE7.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/router-DHISdpPk.js">
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-FD86DEDF.css">
@@ -110,6 +110,58 @@ export const PEEKABOO_MCP_ARGV = ['-y', '-p', PEEKABOO_NPX_PACKAGE, 'peekaboo-mc
110
110
  */
111
111
  export const PEEKABOO_WARM_ARGV = ['-y', '-p', PEEKABOO_NPX_PACKAGE, 'peekaboo', '--version'];
112
112
  let peekabooWarmStarted = false;
113
+ const PEEKABOO_ENV_ALLOWLIST = [
114
+ 'HOME',
115
+ 'PATH',
116
+ 'USER',
117
+ 'LOGNAME',
118
+ 'SHELL',
119
+ 'TMPDIR',
120
+ 'TEMP',
121
+ 'TMP',
122
+ 'LANG',
123
+ 'LC_ALL',
124
+ 'LC_CTYPE',
125
+ ];
126
+ const PEEKABOO_DEFAULT_PATH = '/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin';
127
+ function cleanEnvString(value) {
128
+ if (typeof value !== 'string')
129
+ return null;
130
+ const trimmed = value.trim();
131
+ if (!trimmed || trimmed.includes('\0'))
132
+ return null;
133
+ return trimmed;
134
+ }
135
+ /**
136
+ * Peekaboo only needs a normal user shell environment so npx can resolve/cache
137
+ * the package. Do not inherit the full pikiloom/agent environment here: it may
138
+ * contain provider API keys, channel tokens, OAuth bearer values, or database
139
+ * URLs that a GUI MCP server has no reason to see.
140
+ */
141
+ export function buildPeekabooChildEnv(env = process.env) {
142
+ const safe = {};
143
+ for (const key of PEEKABOO_ENV_ALLOWLIST) {
144
+ const value = cleanEnvString(env[key]);
145
+ if (value)
146
+ safe[key] = value;
147
+ }
148
+ safe.PATH ||= PEEKABOO_DEFAULT_PATH;
149
+ safe.HOME ||= os.homedir();
150
+ safe.PIKILOOM_MCP_SERVER = 'peekaboo';
151
+ safe.npm_config_yes = 'true';
152
+ return safe;
153
+ }
154
+ function peekabooEnvArgs(env) {
155
+ return Object.entries(env).map(([key, value]) => `${key}=${value}`);
156
+ }
157
+ function buildPeekabooMcpServer() {
158
+ const safeEnv = buildPeekabooChildEnv();
159
+ return {
160
+ name: 'peekaboo',
161
+ command: '/usr/bin/env',
162
+ args: ['-i', ...peekabooEnvArgs(safeEnv), 'npx', ...PEEKABOO_MCP_ARGV],
163
+ };
164
+ }
113
165
  /**
114
166
  * Pre-warm the Peekaboo npx package so the agent's MCP server connects instantly.
115
167
  *
@@ -132,7 +184,11 @@ export function ensurePeekabooWarm() {
132
184
  return;
133
185
  peekabooWarmStarted = true;
134
186
  try {
135
- const child = spawn('npx', PEEKABOO_WARM_ARGV, { stdio: 'ignore', detached: true });
187
+ const child = spawn('npx', PEEKABOO_WARM_ARGV, {
188
+ stdio: 'ignore',
189
+ detached: true,
190
+ env: buildPeekabooChildEnv(),
191
+ });
136
192
  // npx missing / spawn failure: clear the latch so a later call can retry.
137
193
  child.on('error', () => { peekabooWarmStarted = false; });
138
194
  child.unref();
@@ -159,11 +215,7 @@ export function buildSupplementalMcpServers(gui = resolveGuiIntegrationConfig(),
159
215
  if (gui.peekabooEnabled && process.platform === 'darwin') {
160
216
  // Peekaboo — native macOS GUI automation via Accessibility + ScreenCaptureKit.
161
217
  // Run the dedicated MCP bin from the multi-bin @steipete/peekaboo package.
162
- servers.push({
163
- name: 'peekaboo',
164
- command: 'npx',
165
- args: [...PEEKABOO_MCP_ARGV],
166
- });
218
+ servers.push(buildPeekabooMcpServer());
167
219
  }
168
220
  return servers;
169
221
  }
@@ -235,6 +287,33 @@ function codexBearerEnvName(serverName) {
235
287
  const safe = serverName.toUpperCase().replace(/[^A-Z0-9]+/g, '_').replace(/^_+|_+$/g, '');
236
288
  return `PIKILOOM_MCP_BEARER_${safe || 'UNNAMED'}`;
237
289
  }
290
+ const REDACTED = '[REDACTED]';
291
+ const SENSITIVE_CONFIG_KEY_RE = /(authorization|bearer|token|secret|password|passwd|api[_-]?key|credential|cookie|session|connection[_-]?string|dsn)/i;
292
+ const URL_PASSWORD_RE = /([a-z][a-z0-9+.-]*:\/\/)([^/\s:@]+):([^@\s/]+)@/gi;
293
+ const QUERY_SECRET_RE = /([?&](?:access_token|api[_-]?key|key|token|secret|password|passwd)=)[^&\s]+/gi;
294
+ function redactStringForLog(key, value) {
295
+ if (SENSITIVE_CONFIG_KEY_RE.test(key)) {
296
+ const bearer = /^\s*Bearer\s+/i.test(value);
297
+ return bearer ? `Bearer ${REDACTED}` : REDACTED;
298
+ }
299
+ return value
300
+ .replace(URL_PASSWORD_RE, `$1$2:${REDACTED}@`)
301
+ .replace(QUERY_SECRET_RE, `$1${REDACTED}`);
302
+ }
303
+ function redactForLog(value, key = '') {
304
+ if (typeof value === 'string')
305
+ return redactStringForLog(key, value);
306
+ if (Array.isArray(value))
307
+ return value.map(item => redactForLog(item, key));
308
+ if (!value || typeof value !== 'object')
309
+ return value;
310
+ return Object.fromEntries(Object.entries(value)
311
+ .map(([childKey, childValue]) => [childKey, redactForLog(childValue, childKey)]));
312
+ }
313
+ export function redactMcpConfigForLog(configPath) {
314
+ const parsed = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
315
+ return JSON.stringify(redactForLog(parsed), null, 2);
316
+ }
238
317
  export function buildGeminiMcpConfig(servers) {
239
318
  return {
240
319
  // Session attachments live under .pikiloom/... and should remain readable to
@@ -383,6 +462,116 @@ function reapStalePlaywrightMcpProcesses(cdpEndpoint) {
383
462
  }
384
463
  return { reaped, spared };
385
464
  }
465
+ // ---------------------------------------------------------------------------
466
+ // Stale peekaboo-mcp reaper
467
+ // ---------------------------------------------------------------------------
468
+ function commandTokenBase(token) {
469
+ return path.basename(token.replace(/^"+|"+$/g, '')).replace(/\.(?:cmd|exe)$/i, '').toLowerCase();
470
+ }
471
+ /**
472
+ * Pure matcher for stale-process hygiene. It intentionally targets the
473
+ * long-running MCP server only, not the quick cache warm (`peekaboo --version`).
474
+ */
475
+ export function _matchPeekabooMcpProcessCommand(command) {
476
+ if (!command || !command.includes('peekaboo-mcp'))
477
+ return false;
478
+ const tokens = command.split(/\s+/).filter(Boolean);
479
+ if (!tokens.length)
480
+ return false;
481
+ if (commandTokenBase(tokens[0]) === 'node' && (tokens[1] === '-e' || tokens[1] === '--eval'))
482
+ return false;
483
+ const hasMcpBin = tokens.some(token => token === 'peekaboo-mcp'
484
+ || /(?:^|[\\/])peekaboo-mcp(?:$|\s)/.test(token)
485
+ || /(?:^|[\\/])peekaboo-mcp$/.test(token));
486
+ if (!hasMcpBin)
487
+ return false;
488
+ const hasPackage = command.includes('@steipete/peekaboo')
489
+ || command.includes('@steipete\\peekaboo')
490
+ || command.includes('/@steipete/peekaboo/');
491
+ const launcher = commandTokenBase(tokens[0]);
492
+ const knownLauncher = launcher === 'env' || launcher === 'npx' || launcher === 'npm' || launcher === 'node' || launcher === 'peekaboo-mcp';
493
+ return hasPackage || knownLauncher;
494
+ }
495
+ function commandLooksLikeLiveMcpController(command) {
496
+ if (!command)
497
+ return false;
498
+ const text = command.toLowerCase();
499
+ if (/\bpikiloom\b/.test(text) || text.includes('pikiloom@'))
500
+ return true;
501
+ const first = commandTokenBase(command.split(/\s+/)[0] || '');
502
+ return first === 'claude' || first === 'codex' || first === 'gemini' || first === 'hermes';
503
+ }
504
+ const PEEKABOO_REAP_THROTTLE_MS = 30_000;
505
+ const PEEKABOO_REAP_FORCE_AFTER_MS = 2_000;
506
+ let lastPeekabooReapAt = 0;
507
+ function reapStalePeekabooMcpProcesses() {
508
+ const reaped = [];
509
+ const spared = [];
510
+ if (process.platform !== 'darwin')
511
+ return { reaped, spared };
512
+ if (Date.now() - lastPeekabooReapAt < PEEKABOO_REAP_THROTTLE_MS)
513
+ return { reaped, spared };
514
+ lastPeekabooReapAt = Date.now();
515
+ const result = spawnSync('ps', ['-axo', 'pid=,ppid=,command='], { encoding: 'utf8' });
516
+ if (result.status !== 0)
517
+ return { reaped, spared };
518
+ const ppidByPid = new Map();
519
+ const commandByPid = new Map();
520
+ const candidates = [];
521
+ const lines = String(result.stdout || '').split(/\r?\n/).map(l => l.trim()).filter(Boolean);
522
+ for (const line of lines) {
523
+ const m = line.match(/^(\d+)\s+(\d+)\s+(.*)$/);
524
+ if (!m)
525
+ continue;
526
+ const pid = Number(m[1]);
527
+ const ppid = Number(m[2]);
528
+ if (!Number.isFinite(pid) || !Number.isFinite(ppid))
529
+ continue;
530
+ const command = m[3] || '';
531
+ ppidByPid.set(pid, ppid);
532
+ commandByPid.set(pid, command);
533
+ if (pid === process.pid)
534
+ continue;
535
+ if (_matchPeekabooMcpProcessCommand(command))
536
+ candidates.push(pid);
537
+ }
538
+ const hasProtectedAncestor = (pid) => {
539
+ let cur = pid;
540
+ for (let depth = 0; depth < 40 && cur != null && cur > 1; depth++) {
541
+ if (cur === process.pid)
542
+ return true;
543
+ const command = commandByPid.get(cur) || '';
544
+ if (cur !== pid && commandLooksLikeLiveMcpController(command))
545
+ return true;
546
+ cur = ppidByPid.get(cur);
547
+ }
548
+ return false;
549
+ };
550
+ for (const pid of candidates) {
551
+ if (hasProtectedAncestor(pid)) {
552
+ spared.push(pid);
553
+ continue;
554
+ }
555
+ try {
556
+ process.kill(pid, 'SIGTERM');
557
+ const forceTimer = setTimeout(() => {
558
+ try {
559
+ process.kill(pid, 0);
560
+ process.kill(pid, 'SIGKILL');
561
+ }
562
+ catch {
563
+ // Process already exited or cannot be signalled — no-op.
564
+ }
565
+ }, PEEKABOO_REAP_FORCE_AFTER_MS);
566
+ forceTimer.unref?.();
567
+ reaped.push(pid);
568
+ }
569
+ catch {
570
+ // Already dead — no-op.
571
+ }
572
+ }
573
+ return { reaped, spared };
574
+ }
386
575
  /**
387
576
  * Decide which CDP endpoint the per-session playwright/mcp should attach to.
388
577
  *
@@ -514,8 +703,13 @@ export async function startMcpBridge(opts) {
514
703
  // Peekaboo ships a native binary behind npx; warm its cache out-of-band so the
515
704
  // agent's MCP server connects instantly instead of hanging at "Still
516
705
  // connecting" on a cold first-run download (see ensurePeekabooWarm).
517
- if (gui.peekabooEnabled)
706
+ if (gui.peekabooEnabled) {
518
707
  ensurePeekabooWarm();
708
+ const { reaped, spared } = reapStalePeekabooMcpProcesses();
709
+ if (reaped.length) {
710
+ opts.onLog?.(`reaped ${reaped.length} stale peekaboo-mcp process(es): pid=${reaped.join(',')}${spared.length ? ` (spared active: ${spared.join(',')})` : ''}`);
711
+ }
712
+ }
519
713
  // Lazy browser lifecycle: probe an already-running managed Chrome via
520
714
  // <profileDir>/DevToolsActivePort and attach if reachable; otherwise leave
521
715
  // Chrome unlaunched and let playwright/mcp launch it with `--user-data-dir`