pikiloom 0.4.8 → 0.4.10

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.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-DXdnwcvU.js","assets/react-vendor-C7Sl8SE7.js","assets/index-gXOsku2L.js","assets/router-DHISdpPk.js","assets/index-FD86DEDF.css","assets/Modal-ZOB1qJrT.js","assets/Select-DMKejUbS.js","assets/DirBrowser-MOD5cAPf.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-B9X_3L3B.js"])))=>i.map(i=>d[i]);
2
- import{c as L,a as J,u as je,A as rs,s as sn,S as he,B as Xe,g as Yt,w as os,b as is,E as Vt,C as rn,d as as,e as ls,n as cs,f as yn,h as It,i as Ee,D as Wt,j as ds,k as Nn,_ as Sn,T as us,l as hs}from"./index-gXOsku2L.js";import{j as e,r,a as on}from"./react-vendor-C7Sl8SE7.js";import{I as xs}from"./Select-DMKejUbS.js";import{M as _t,a as Pt}from"./Modal-ZOB1qJrT.js";import{D as ps}from"./DirBrowser-MOD5cAPf.js";import{n as fs,r as gs,M as an}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as ms}from"./ExtensionsTab-B9X_3L3B.js";function bs({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:L("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 Ze({open:t,onToggle:n,dot:s,label:a,preview:l,badge:d,collapsedContent:x,children:c,className:m}){return e.jsxs("div",{className:L("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",m),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:L("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:l}),d,e.jsx(bs,{open:t})]}),!t&&x,t&&c&&e.jsx("div",{className:"border-t border-edge",children:c})]})}const vs=5e3,js=15e3,At=8,Rt=30,ws=1,Je=new Map,ve=new Map,Gt=new Set,Cn=[];let Lt=0;function qt(t){return typeof t=="number"&&Number.isFinite(t)}function Oe(t,n,s,a){for(t.delete(n),t.set(n,s);t.size>a;){const l=t.keys().next().value;if(!l)break;t.delete(l)}}function En(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(Oe(t,n,s,t===ve?Rt:At),s.value)}function Ln(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:qt(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:qt(t.turnOffset)?t.turnOffset:void 0,turnLimit:qt(t.turnLimit)?t.turnLimit:void 0}}function ln(t){const n=Ln(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function Mn(){for(;Lt<ws;){const t=Cn.shift();if(!t)return;Lt+=1,t().finally(()=>{Lt=Math.max(0,Lt-1),Mn()})}}async function ks(t,n={}){const s=t;if(!n.force){const d=En(Je,s);if(d)return d}const a=Je.get(s);if(a?.promise)return a.promise;const l=J.getWorkspaceSessions(t,n.request).then(d=>(Oe(Je,s,{value:d,expiresAt:d.ok?Date.now()+vs:0},At),d)).finally(()=>{const d=Je.get(s);d?.promise&&Oe(Je,s,{value:d.value,expiresAt:d.expiresAt},At)});return Oe(Je,s,{value:a?.value,expiresAt:a?.expiresAt??0,promise:l},At),l}function ys(t,n={}){const s=ln(t),a=ve.get(s);return a?.value?.ok&&(n.allowStale||a.expiresAt>Date.now())?a.value:null}async function Ns(t,n={}){const s=Ln(t),a=ln(s);if(!n.force){const x=En(ve,a);if(x?.ok)return x}const l=ve.get(a);if(l?.promise)return l.promise;const d=J.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(Oe(ve,a,{value:x,expiresAt:x.ok?Date.now()+js:0},Rt),x)).finally(()=>{const x=ve.get(a);x?.promise&&Oe(ve,a,{value:x.value,expiresAt:x.expiresAt},Rt)});return Oe(ve,a,{value:l?.value,expiresAt:l?.expiresAt??0,promise:d},Rt),d}function Ss(t){const n=ln(t);ys(t)||Gt.has(n)||ve.get(n)?.promise||(Gt.add(n),Cn.push(async()=>{try{await Ns(t)}catch{}finally{Gt.delete(n)}}),Mn())}const mt=new Map,Zt=new Set;let De=null,Le=0,gn=!1,Ye=null,gt=500;const Cs=8e3;function Es(t){const n=mt.get(t.type);if(n)for(const s of n)s(t)}function Ls(){const t=window.location;return`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}/ws`}function cn(){if(De)return;Tn();const t=new WebSocket(Ls());t.onopen=()=>{const n=gn;if(gn=!0,gt=500,n)for(const s of Zt)s()},t.onmessage=n=>{try{const s=JSON.parse(n.data);if(s.type==="pong")return;Es(s)}catch{}},t.onclose=()=>{De=null,Le>0&&Ts()},t.onerror=()=>{},De=t}function Ms(){Tn(),De&&(De.close(),De=null)}function Tn(){Ye&&(clearTimeout(Ye),Ye=null)}function Ts(){Ye||(Ye=setTimeout(()=>{Ye=null,Le>0&&cn()},gt),gt=Math.min(gt*2,Cs))}function Is(t,n){let s=mt.get(t);s||(s=new Set,mt.set(t,s)),s.add(n),Le++,Le===1&&cn()}function As(t,n){const s=mt.get(t);s&&(s.delete(n),s.size===0&&mt.delete(t)),Le=Math.max(0,Le-1),Le===0&&Ms()}typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Le>0&&!De&&(gt=500,cn())});function mn(t,n){const s=r.useRef(n);s.current=n,r.useEffect(()=>{if(!t)return;const a=l=>s.current(l);return Is(t,a),()=>As(t,a)},[t])}function Rs(t){const n=r.useRef(t);n.current=t,r.useEffect(()=>{const s=()=>n.current();return Zt.add(s),()=>{Zt.delete(s)}},[])}function Qr(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(x=>({role:x.role,text:x.text,blocks:[{type:"text",content:x.text}]}))||[],s=Ps(n),a=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),l=t.window?.endTurn??a,d=t.window?.startTurn??Math.max(0,l-s.length);return{turns:s,startTurn:d,endTurn:l,totalTurns:a,hasOlder:t.window?.hasOlder??d>0}}function Jr(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 Xr(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 _s(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-b2PrnaOi.js","assets/react-vendor-C7Sl8SE7.js","assets/index-BJL-XxHY.js","assets/router-DHISdpPk.js","assets/index-FD86DEDF.css","assets/Modal-e5zVwIox.js","assets/Select-BBP3aON8.js","assets/DirBrowser-DP0PmqYk.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-CAsex0fD.js"])))=>i.map(i=>d[i]);
2
+ import{c as L,a as J,u as je,A as rs,s as sn,S as he,B as Xe,g as Yt,w as os,b as is,E as Vt,C as rn,d as as,e as ls,n as cs,f as yn,h as It,i as Ee,D as Wt,j as ds,k as Nn,_ as Sn,T as us,l as hs}from"./index-BJL-XxHY.js";import{j as e,r,a as on}from"./react-vendor-C7Sl8SE7.js";import{I as xs}from"./Select-BBP3aON8.js";import{M as _t,a as Pt}from"./Modal-e5zVwIox.js";import{D as ps}from"./DirBrowser-DP0PmqYk.js";import{n as fs,r as gs,M as an}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as ms}from"./ExtensionsTab-CAsex0fD.js";function bs({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:L("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 Ze({open:t,onToggle:n,dot:s,label:a,preview:l,badge:d,collapsedContent:x,children:c,className:m}){return e.jsxs("div",{className:L("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",m),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:L("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:l}),d,e.jsx(bs,{open:t})]}),!t&&x,t&&c&&e.jsx("div",{className:"border-t border-edge",children:c})]})}const vs=5e3,js=15e3,At=8,Rt=30,ws=1,Je=new Map,ve=new Map,Gt=new Set,Cn=[];let Lt=0;function qt(t){return typeof t=="number"&&Number.isFinite(t)}function Oe(t,n,s,a){for(t.delete(n),t.set(n,s);t.size>a;){const l=t.keys().next().value;if(!l)break;t.delete(l)}}function En(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(Oe(t,n,s,t===ve?Rt:At),s.value)}function Ln(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:qt(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:qt(t.turnOffset)?t.turnOffset:void 0,turnLimit:qt(t.turnLimit)?t.turnLimit:void 0}}function ln(t){const n=Ln(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function Mn(){for(;Lt<ws;){const t=Cn.shift();if(!t)return;Lt+=1,t().finally(()=>{Lt=Math.max(0,Lt-1),Mn()})}}async function ks(t,n={}){const s=t;if(!n.force){const d=En(Je,s);if(d)return d}const a=Je.get(s);if(a?.promise)return a.promise;const l=J.getWorkspaceSessions(t,n.request).then(d=>(Oe(Je,s,{value:d,expiresAt:d.ok?Date.now()+vs:0},At),d)).finally(()=>{const d=Je.get(s);d?.promise&&Oe(Je,s,{value:d.value,expiresAt:d.expiresAt},At)});return Oe(Je,s,{value:a?.value,expiresAt:a?.expiresAt??0,promise:l},At),l}function ys(t,n={}){const s=ln(t),a=ve.get(s);return a?.value?.ok&&(n.allowStale||a.expiresAt>Date.now())?a.value:null}async function Ns(t,n={}){const s=Ln(t),a=ln(s);if(!n.force){const x=En(ve,a);if(x?.ok)return x}const l=ve.get(a);if(l?.promise)return l.promise;const d=J.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(Oe(ve,a,{value:x,expiresAt:x.ok?Date.now()+js:0},Rt),x)).finally(()=>{const x=ve.get(a);x?.promise&&Oe(ve,a,{value:x.value,expiresAt:x.expiresAt},Rt)});return Oe(ve,a,{value:l?.value,expiresAt:l?.expiresAt??0,promise:d},Rt),d}function Ss(t){const n=ln(t);ys(t)||Gt.has(n)||ve.get(n)?.promise||(Gt.add(n),Cn.push(async()=>{try{await Ns(t)}catch{}finally{Gt.delete(n)}}),Mn())}const mt=new Map,Zt=new Set;let De=null,Le=0,gn=!1,Ye=null,gt=500;const Cs=8e3;function Es(t){const n=mt.get(t.type);if(n)for(const s of n)s(t)}function Ls(){const t=window.location;return`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}/ws`}function cn(){if(De)return;Tn();const t=new WebSocket(Ls());t.onopen=()=>{const n=gn;if(gn=!0,gt=500,n)for(const s of Zt)s()},t.onmessage=n=>{try{const s=JSON.parse(n.data);if(s.type==="pong")return;Es(s)}catch{}},t.onclose=()=>{De=null,Le>0&&Ts()},t.onerror=()=>{},De=t}function Ms(){Tn(),De&&(De.close(),De=null)}function Tn(){Ye&&(clearTimeout(Ye),Ye=null)}function Ts(){Ye||(Ye=setTimeout(()=>{Ye=null,Le>0&&cn()},gt),gt=Math.min(gt*2,Cs))}function Is(t,n){let s=mt.get(t);s||(s=new Set,mt.set(t,s)),s.add(n),Le++,Le===1&&cn()}function As(t,n){const s=mt.get(t);s&&(s.delete(n),s.size===0&&mt.delete(t)),Le=Math.max(0,Le-1),Le===0&&Ms()}typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Le>0&&!De&&(gt=500,cn())});function mn(t,n){const s=r.useRef(n);s.current=n,r.useEffect(()=>{if(!t)return;const a=l=>s.current(l);return Is(t,a),()=>As(t,a)},[t])}function Rs(t){const n=r.useRef(t);n.current=t,r.useEffect(()=>{const s=()=>n.current();return Zt.add(s),()=>{Zt.delete(s)}},[])}function Qr(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(x=>({role:x.role,text:x.text,blocks:[{type:"text",content:x.text}]}))||[],s=Ps(n),a=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),l=t.window?.endTurn??a,d=t.window?.startTurn??Math.max(0,l-s.length);return{turns:s,startTurn:d,endTurn:l,totalTurns:a,hasOlder:t.window?.hasOlder??d>0}}function Jr(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 Xr(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 _s(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
3
3
 
4
4
  `),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function Ps(t){const n=[];let s={user:null,assistant:null};for(const a of t)if(a.role==="user"){if(s.assistant&&In(a.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=a}else s.assistant?s.assistant=_s(s.assistant,a):s.assistant=a;return(s.user||s.assistant)&&n.push(s),n}const Ws=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"]),Bs=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function In(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Ws.has(s[1].toLowerCase())?!0:Bs.some(a=>t.includes(a))}function An(t,n){const s=t.split(`
5
5
  `).filter(a=>a.trim());return s.length<=n?s.join(`
@@ -19,5 +19,5 @@ import{c as L,a as J,u as je,A as rs,s as sn,S as he,B as Xe,g as Yt,w as os,b a
19
19
  `),[d,x]=r.useState(null);return!l.trim()&&a.length===0?null:e.jsxs(e.Fragment,{children:[l.trim()&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:e.jsx(an,{remarkPlugins:dn,components:un,children:l})}),a.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:a.map((c,m)=>e.jsx(dr,{block:c,onLightbox:x,t:n},m))}),d&&e.jsx($n,{src:d,onClose:()=>x(null)})]})}const eo=r.memo(function({turn:n,turnIndex:s,agent:a,meta:l,model:d,effort:x,providerName:c,t:m,onResend:v,onEdit:g,onFork:j}){const E=n.user&&In(n.user.text),k=j&&typeof s=="number"?()=>j(s):void 0,N=!!n.assistant&&rr(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!E&&e.jsx(On,{text:n.user.text,blocks:n.user.blocks,t:m,onResend:v,onEdit:g,onFork:k}),E&&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(an,{remarkPlugins:dn,components:un,children:n.user.text})}),N&&e.jsxs(e.Fragment,{children:[e.jsx(fr,{agent:a,meta:l,model:d,effort:x,providerName:c,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(sr,{message:n.assistant,t:m})})]})]})});function $n({src:t,onClose:n}){return r.useEffect(()=>{const s=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),on.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 hr=1500,xr=16,jn=8;function pr(t){const n=t.split(`
20
20
  `);return n.length<=jn?t:n.slice(0,jn).join(`
21
21
  `)}function On({text:t,blocks:n,t:s,onResend:a,onEdit:l,onFork:d}){const[x,c]=r.useState(!1),[m,v]=r.useState(!1),[g,j]=r.useState(null),E=t?t.split(`
22
- `).length:0,k=!!t&&(t.length>hr||E>xr),[N,M]=r.useState(!1),A=t?k&&!N?pr(t):t:"",B=!!(a||l||d),O=n?.filter(I=>I.type==="image")||[],H=()=>{navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),1500)}).catch(()=>{})},_=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(E));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!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:[A,k&&!N&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),k&&e.jsx("button",{type:"button",onClick:()=>M(I=>!I),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:N?s("hub.collapse"):_}),O.length>0&&e.jsx("div",{className:L("flex flex-wrap gap-2",t&&"mt-2"),children:O.map((I,D)=>e.jsx("img",{src:I.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(I.content)},D))})]}),g&&e.jsx($n,{src:g,onClose:()=>j(null)}),B&&e.jsxs("div",{className:L("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(Mt,{label:s(m?"hub.copied":"hub.copy"),onClick:H,children:m?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(Mt,{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"})]})}),l&&e.jsx(Mt,{label:s("hub.edit"),onClick:()=>l(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"})]})}),d&&e.jsx(Mt,{label:s("hub.fork"),onClick:d,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 Mt({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 fr({agent:t,meta:n,model:s,effort:a,providerName:l,previewMeta:d,liveStartedAt:x}){const c=d?.contextPercent??null,m=d?.contextUsedTokens??0,v=d?.turnOutputTokens??0,g=c!=null||m>0||v>0,j=x!=null&&x>0,E=d?.providerName??l??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(Xe,{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||""]}),E&&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 ${E} (BYOK), not the agent CLI's native auth.`,children:["via ",E]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:vr(d),children:[c!=null&&e.jsx(jr,{pct:c}),e.jsx("span",{children:c!=null?`${c.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",br(m)]}),v>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Dn(v)]}),j&&e.jsx(gr,{startedAt:x,leadingDot:g})]})]})}function gr({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const l=setInterval(()=>s(d=>d+1),1e3);return()=>clearInterval(l)},[]);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?"· ":"",mr(a)]})}function mr(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 br(t){return`${Dn(t)} tok`}function Dn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function vr(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 jr({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 wn(t,n,s){return t==="zh-CN"?n:s}function wr({open:t,onClose:n,workdir:s}){const a=je(d=>d.locale),l=s.split("/").pop()||s;return e.jsxs(_t,{open:t,onClose:n,wide:!0,children:[e.jsx(Pt,{title:wn(a,`${l} — 项目扩展`,`${l} — Project Extensions`),description:wn(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(ms,{workdir:s}):null]})}let kn=Sn(()=>import("./SessionPanel-DXdnwcvU.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function tn(){return kn??=Sn(()=>import("./SessionPanel-DXdnwcvU.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),kn}const kr=r.lazy(async()=>({default:(await tn()).SessionPanel})),Xt=5,yr=240,Nr=120,Sr=12,Cr=900*1e3,F=(t,n)=>`${t}:${n}`;function Er(t){const n=new Map;for(const c of t)n.set(F(c.agent||"",c.sessionId),c);const s=new Map,a=new Set;for(const c of t){const m=c.migratedFrom;if(!m||m.kind!=="fork"||!m.sessionId)continue;const v=F(m.agent||c.agent||"",m.sessionId);n.has(v)&&(a.add(F(c.agent||"",c.sessionId)),s.has(v)||s.set(v,[]),s.get(v).push(c))}const l=[],d=new Set,x=(c,m)=>{const v=F(c.agent||"",c.sessionId);if(d.has(v))return;d.add(v),l.push(Object.assign({},c,{__forkDepth:m}));const g=s.get(v);if(g)for(const j of g)x(j,m+1)};for(const c of t){const m=F(c.agent||"",c.sessionId);a.has(m)||x(c,0)}for(const c of t)x(c,0);return l}let Lr=0;function Tt(){return`mk-${Date.now().toString(36)}-${(++Lr).toString(36)}`}function Mr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Tr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function Fn(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 Ir=r.memo(function({active:n=!0}){const s=je(o=>o.locale),a=je(o=>o.state?.runtimeWorkdir??null),l=r.useMemo(()=>as(s),[s]),[d,x]=r.useState([]),[c,m]=r.useState({}),[v,g]=r.useState({}),[j,E]=r.useState(!0),[k,N]=r.useState(()=>{try{const u=sessionStorage.getItem("pikiloom-layout-mode");if(u==="1"||u==="2"||u==="3"||u==="6")return Number(u)}catch{}const o=window.innerWidth;return o>=1920?3:o>=1280?2:1}),[M,A]=r.useState(()=>{try{const o=sessionStorage.getItem("pikiloom-open-sessions");if(o){const u=JSON.parse(o);if(Array.isArray(u))return u.map(h=>({...h,mountKey:h.mountKey||Tt()}))}}catch{}return[]}),[B,O]=r.useState(()=>{try{const o=sessionStorage.getItem("pikiloom-active-slot");if(o!=null){const u=Number(o);if(Number.isFinite(u)&&u>=0)return u}}catch{}return 0}),H=r.useCallback(o=>{N(o);try{sessionStorage.setItem("pikiloom-layout-mode",String(o))}catch{}},[]),_=r.useCallback(o=>{A(u=>{const h=typeof o=="function"?o(u):o;try{const f=h.map(({pendingPrompt:w,pendingImageUrls:y,...C})=>C);sessionStorage.setItem("pikiloom-open-sessions",JSON.stringify(f))}catch{}return h})},[]),I=r.useCallback(o=>{O(u=>{const h=typeof o=="function"?o(u):o;try{sessionStorage.setItem("pikiloom-active-slot",String(h))}catch{}return h})},[]);r.useEffect(()=>{_(o=>o.length>k?o.slice(0,k):o),I(o=>o>=k?k-1:o)},[k]);const[D,K]=r.useState(!1),ae=r.useRef(k);ae.current=k;const Z=r.useRef(B);Z.current=B;const T=r.useRef(-1),V=M[B]??null,Me=r.useCallback(o=>{if(!o){_([]),I(0);return}const u=o.mountKey?o:{...o,mountKey:Tt()};_(h=>{const f=h.findIndex(y=>y.agent===u.agent&&y.sessionId===u.sessionId);if(f>=0)return I(f),h;if(h.length<ae.current){const y=[...h,u];return I(y.length-1),y}const w=[...h];return w[Z.current]=u,w})},[]),[ce,we]=r.useState(!1),[$,Fe]=r.useState(null),[Te,tt]=r.useState(""),[ke,bt]=r.useState("all"),[de,vt]=r.useState({}),ee=r.useDeferredValue(Te),te=r.useRef(!1),Ue=r.useRef({}),Ie=r.useRef(c);Ie.current=c;const ze=r.useRef(de);ze.current=de;const nt=r.useRef(new Set),ne=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values(ne.current))clearTimeout(o)},[]);const le=r.useCallback(async()=>{try{const o=await J.getWorkspaces(),u=o.ok?o.workspaces:[];u.length&&x(h=>h.length===u.length&&h.every((f,w)=>f.path===u[w].path&&f.name===u[w].name)?h:u),te.current=!0}catch{te.current=!0}finally{E(!1)}},[]);r.useEffect(()=>{le()},[le]);const P=r.useCallback(async(o,u={})=>{if(!Ue.current[o]){Ue.current[o]=!0,u.background||g(h=>({...h,[o]:!0}));try{const h=await ks(o,{force:u.force});r.startTransition(()=>{m(f=>{const w=h.sessions||[],y=f[o]||[],C=new Set(w.map(z=>F(z.agent||"",z.sessionId))),U=y.filter(z=>{if(z.runState!=="running")return!1;const ie=F(z.agent||"",z.sessionId);if(C.has(ie))return!1;const dt=ze.current[ie];return!(dt?.resolvedKey&&dt.resolvedKey!==ie)});return{...f,[o]:U.length?[...U,...w]:w}})})}catch{u.background||r.startTransition(()=>{m(h=>({...h,[o]:[]}))})}finally{Ue.current[o]=!1,u.background||g(h=>({...h,[o]:!1}))}}},[]),ye=r.useRef(a);r.useEffect(()=>{a!==ye.current&&(ye.current=a,!(!a||!te.current)&&le().then(()=>{P(a,{force:!0})}))},[a,le,P]);const X=r.useCallback((o,u)=>{const h=o.agent||"";!h||!o.sessionId||(tn(),Ss({workdir:u,agent:h,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Sr}))},[]),Ae=r.useCallback((o,u,h=Nr)=>{const f=`${u}:${F(o.agent||"",o.sessionId)}`,w=ne.current[f];w&&clearTimeout(w),ne.current[f]=setTimeout(()=>{delete ne.current[f],X(o,u)},h)},[X]),Re=r.useCallback((o,u)=>{const h=`${u}:${F(o.agent||"",o.sessionId)}`,f=ne.current[h];f&&(clearTimeout(f),delete ne.current[h])},[]);r.useEffect(()=>{n&&tn()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return d.forEach((u,h)=>{if(c[u.path]||v[u.path])return;const f=setTimeout(()=>{P(u.path)},h*90);o.push(f)}),()=>{for(const u of o)clearTimeout(u)}},[n,P,v,c,d]);const jt=r.useRef(new Map);mn(n&&te.current&&d.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const u=o.key,h=u?d.filter(y=>(Ie.current[y.path]||[]).some(C=>F(C.agent||"",C.sessionId)===u)):d,f=h.length?h:d,w=jt.current;for(const y of f)w.has(y.path)&&clearTimeout(w.get(y.path)),w.set(y.path,setTimeout(()=>{w.delete(y.path),P(y.path,{background:!0,force:!0})},300))},[d,P]));const W=r.useCallback(o=>{const u=o.agent||"";return!u||!o.sessionId?o:ls(o,de[F(u,o.sessionId)]||null)},[de]);mn("stream-update",r.useCallback(o=>{const u=o.key;u&&vt(h=>{const f={},w=Date.now()-Cr;for(const[C,U]of Object.entries(h))U.updatedAt>=w&&(f[C]=U);const y=cs(u,o.snapshot??null);if(!y){const C=f[u];return C&&C.phase!=="done"&&(f[u]={...C,phase:"done",updatedAt:Date.now()}),f}return f[u]=y,y.resolvedKey!==u&&(f[y.resolvedKey]={...y,key:y.resolvedKey}),f})},[])),Rs(r.useCallback(()=>{if(!(!n||!te.current||d.length===0))for(const o of d)P(o.path,{background:!0,force:!0})},[n,d,P])),r.useEffect(()=>{if(!n||!te.current||d.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const h of d)P(h.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const u=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",u),window.addEventListener("focus",u),()=>{document.removeEventListener("visibilitychange",u),window.removeEventListener("focus",u)}},[n,P,d]),r.useEffect(()=>{if(!n)return;const o=[];return d.forEach((u,h)=>{const f=(c[u.path]||[])[0];if(!f)return;const w=`${u.path}:${F(f.agent||"",f.sessionId)}`;if(nt.current.has(w))return;const y=setTimeout(()=>{nt.current.add(w),X(f,u.path)},yr+h*120);o.push(y)}),()=>{for(const u of o)clearTimeout(u)}},[n,c,X,d]);const se=r.useCallback(async o=>{try{(await J.addWorkspace(o)).ok&&(we(!1),await le(),P(o))}catch{}},[le,P]),[xe,Ne]=r.useState(null),[re,_e]=r.useState(!1),[st,wt]=r.useState(null),He=r.useCallback(o=>{Ne(o)},[]),rt=r.useCallback(async()=>{const o=xe;if(o){_e(!0);try{await J.removeWorkspace(o),x(u=>u.filter(h=>h.path!==o)),m(u=>{const h={...u};return delete h[o],h}),_(u=>u.filter(h=>h.workdir!==o)),I(0),Ne(null)}catch{}finally{_e(!1)}}},[xe]),ot=r.useCallback(o=>{P(o,{force:!0})},[P]),[Se,G]=r.useState(null),[pe,Ce]=r.useState(!1),[oe,Pe]=r.useState(!1),We=je(o=>o.toast),[ue,it]=r.useState(null),at=r.useCallback((o,u,h)=>{it({anchor:{right:o.right,bottom:o.bottom},target:{workdir:h,agent:u.agent||"",sessionId:u.sessionId,title:yn(u).slice(0,120)||u.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!ue)return;const o=()=>it(null),u=h=>{h.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",u),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",u)}},[ue]);const Bt=r.useCallback(o=>{Ce(!1),G(o),it(null)},[]),kt=r.useCallback(async()=>{const o=Se;if(o){Pe(!0);try{const u=await J.deleteSession(o.workdir,o.agent,o.sessionId,pe);if(!u.ok){const h=u.error?.includes("still running")?l("session.deleteRunningError"):u.error||l("session.deleteFailed");We(h,!1);return}m(h=>{const f=h[o.workdir];if(!f)return h;const w=f.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return w.length===f.length?h:{...h,[o.workdir]:w}}),_(h=>h.filter(f=>!(f.workdir===o.workdir&&f.agent===o.agent&&f.sessionId===o.sessionId))),G(null)}catch(u){We(u?.message||l("session.deleteFailed"),!1)}finally{Pe(!1)}}},[Se,pe,l,We]),$t=r.useCallback(o=>{_(u=>{let h=!1;const f=u.map(w=>w.mountKey===o&&(w.pendingPrompt!=null||w.pendingImageUrls)?(h=!0,{...w,pendingPrompt:null,pendingImageUrls:void 0}):w);return h?f:u})},[_]),lt=r.useCallback((o,u,h)=>{X({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),m(y=>{const C=y[o.workdir]||[];if(C.some(ie=>ie.sessionId===o.sessionId&&ie.agent===o.agent))return y;const z={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:u,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[z,...C]}});const f=T.current,w={...o,mountKey:Tt(),pendingPrompt:u||null,pendingImageUrls:h&&h.length?h:void 0};r.startTransition(()=>{Fe(null),_(y=>{if(f>=y.length)return[...y,w];const C=[...y];return C[f]=w,C}),I(f>=0?f:0)}),P(o.workdir,{background:!0,force:!0})},[P,X,_,I]),Be=r.useCallback((o,u)=>{X(o,u),Fe(null),r.startTransition(()=>{Me({agent:o.agent||"",sessionId:o.sessionId,workdir:u})})},[X]),Ke=r.useCallback((o,u)=>{X({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{u!=null?(_(h=>{if(u>=h.length)return h;const f=[...h];return f[u]={...h[u],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},f}),I(u)):Me({...o,mountKey:Tt()})}),P(o.workdir,{background:!0,force:!0})},[P,X]),Ve=r.useCallback(o=>{let u=o;if(ke==="running"?u=u.filter(h=>It(h)==="running"):ke==="review"&&(u=u.filter(h=>It(h)==="incomplete")),ee.trim()){const h=ee.toLowerCase();u=u.filter(f=>(f.lastMessageText||"").toLowerCase().includes(h)||(f.lastQuestion||"").toLowerCase().includes(h)||(f.lastAnswer||"").toLowerCase().includes(h)||(f.title||"").toLowerCase().includes(h)||(f.agent||"").toLowerCase().includes(h))}return u},[ee,ke]),fe=r.useMemo(()=>{const o={};for(const u of d){const h=(c[u.path]||[]).map(W),f=new Map;for(const y of h){const C=F(y.agent||"",y.sessionId),U=de[C],z=U?.resolvedKey&&U.resolvedKey!==C?U.resolvedKey:C,ie=f.get(z);if(!ie){f.set(z,y);continue}F(ie.agent||"",ie.sessionId)!==z&&C===z&&f.set(z,y)}const w=Ve([...f.values()]);o[u.path]=Er(w)}return o},[d,c,de,Ve,W]),yt=r.useCallback(o=>{const u=(c[o.workdir]||[]).find(h=>h.sessionId===o.sessionId&&h.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return W(u)},[W,c]),ct=r.useMemo(()=>new Set(M.map(o=>F(o.agent,o.sessionId))),[M]),Nt=V?F(V.agent,V.sessionId):null,St=r.useCallback(o=>{_(u=>{const h=u.filter((f,w)=>w!==o);return h.length===0?I(0):Z.current>=h.length&&I(h.length-1),h})},[]);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:Te,onChange:o=>tt(o.target.value),placeholder:l("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"}),Te&&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(o=>e.jsx("button",{onClick:()=>bt(o),className:L("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",ke===o?"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:l(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),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(he,{className:"h-4 w-4 text-fg-5"})}):d.length===0&&!ce?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:l("hub.noWorkspaces")}):d.map(o=>e.jsx(Pr,{workspace:o,sessions:fe[o.path]||[],loading:!!v[o.path]||!(o.path in c),isActive:o.path===a,selectedKey:Nt,openSessionKeys:ct,onSelectSession:Be,onNewSession:Fe,onRefresh:ot,onRemove:He,onExtensions:wt,onWarmSession:Ae,onCancelWarmSession:Re,onSessionMenuOpen:at,t:l},o.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(o=>e.jsx("button",{onClick:()=>H(o),className:L("flex-1 flex items-center justify-center p-1.5 rounded transition-all",k===o?"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:l(`hub.layout${o}`),children:o===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"})}):o===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"})]}):o===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"})]})},o))}),e.jsxs(Ee,{variant:"ghost",size:"sm",onClick:()=>we(o=>!o),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"})]}),l("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(${k===6?3:k}, 1fr)`,gridTemplateRows:k===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=$?M.length<k?M.length:B:-1;return T.current=o,Array.from({length:k},(u,h)=>{if($&&h===o)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(Rr,{workdir:$,workspaceName:d.find(C=>C.path===$)?.name||$.split("/").pop()||"",onSessionCreated:lt,onClose:()=>Fe(null),t:l},$)},`new-${$}`);const f=M[h]??null;if(!f)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:l("hub.emptySlot")})]})},`empty-${h}`);const w=yt(f),y=h===B;return e.jsxs("div",{className:L("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>I(h),children:[e.jsxs("div",{className:L("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const C=It(w);return e.jsx(Wt,{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:f.workdir.split("/").pop()||f.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)||f.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:l("hub.created"),children:ds(w.createdAt)}),w.runUpdatedAt&&e.jsx("span",{title:l("hub.updated"),children:Nn(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(U=>!U)},className:L("p-0.5 rounded transition-colors",D?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:l("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(),St(h)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:l("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(kr,{session:w,workdir:f.workdir,active:n&&y,onSessionChange:C=>Ke(C,h),initialPendingPrompt:f.pendingPrompt??null,initialPendingImageUrls:f.pendingImageUrls,onPendingPromptConsumed:()=>$t(f.mountKey)},f.mountKey)})})]},f.mountKey||F(f.agent,f.sessionId))})})()})}),D&&V&&e.jsx(Br,{workdir:V.workdir,onClose:()=>K(!1),t:l}),e.jsx(Ar,{open:ce,initialPath:a||void 0,onAdd:se,onClose:()=>we(!1),t:l}),e.jsxs(_t,{open:!!xe,onClose:()=>!re&&Ne(null),children:[e.jsx(Pt,{title:l("hub.removeWorkspace"),onClose:()=>!re&&Ne(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:l("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(Ee,{variant:"ghost",onClick:()=>Ne(null),disabled:re,children:l("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:rt,disabled:re,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(re?"modal.removing":"modal.remove")})]})]}),ue&&(()=>{const u=Math.max(8,Math.min(ue.anchor.right-160,window.innerWidth-160-8)),h=Math.min(ue.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:h,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:f=>f.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>Bt(ue.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"})]}),l("session.delete")]})})})(),e.jsxs(_t,{open:!!Se,onClose:()=>!oe&&G(null),children:[e.jsx(Pt,{title:l("session.deleteTitle"),onClose:()=>!oe&&G(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("session.deleteHint")}),Se&&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:Se.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Se.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:()=>Ce(!1),disabled:oe,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:l("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:l("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:()=>Ce(!0),disabled:oe,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:l("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:l("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ee,{variant:"ghost",onClick:()=>G(null),disabled:oe,children:l("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:kt,disabled:oe,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(oe?"session.deleting":"modal.remove")})]})]}),e.jsx(wr,{open:!!st,onClose:()=>wt(null),workdir:st||""})]})});function Ar({open:t,initialPath:n,onAdd:s,onClose:a,t:l}){const[d,x]=r.useState(""),c=r.useCallback(m=>x(m),[]);return r.useEffect(()=>{t&&x("")},[t]),e.jsxs(_t,{open:t,onClose:a,children:[e.jsx(Pt,{title:l("hub.addWorkspace"),onClose:a}),e.jsx(ps,{initialPath:n,maxHeight:360,minHeight:200,onSelect:c,t:l}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ee,{disabled:!d,onClick:()=>d&&s(d),className:"flex-1",children:l("hub.add")}),e.jsx(Ee,{variant:"secondary",onClick:a,className:"flex-1",children:l("hub.cancel")})]})]})}function Rr({workdir:t,workspaceName:n,onSessionCreated:s,onClose:a,t:l}){const[d,x]=r.useState(null),[c,m]=r.useState([]),v=r.useRef(null),g=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),E=r.useCallback(()=>{},[]),k=r.useCallback((A,B)=>{x(A||null),v.current=A||null;const O=B||[];m(O),g.current=O},[]),N=r.useCallback(A=>{const B=g.current;g.current=[],s(A,v.current||void 0,B.length?B:void 0)},[s]),M=!!d||c.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:l("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(Wt,{variant:M?"ok":"idle",pulse:M}),!M&&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:M?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(On,{text:d||"",blocks:c.map(A=>({type:"image",content:A})),t:l}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(en,{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:l("hub.newSessionHint")})})})}),e.jsx(Gs,{session:j,workdir:t,onStreamQueued:E,onSendStart:k,onSessionChange:N,t:l,streamPhase:null})]})}function _r({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(`
22
+ `).length:0,k=!!t&&(t.length>hr||E>xr),[N,M]=r.useState(!1),A=t?k&&!N?pr(t):t:"",B=!!(a||l||d),O=n?.filter(I=>I.type==="image")||[],H=()=>{navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),1500)}).catch(()=>{})},_=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(E));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!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:[A,k&&!N&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),k&&e.jsx("button",{type:"button",onClick:()=>M(I=>!I),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:N?s("hub.collapse"):_}),O.length>0&&e.jsx("div",{className:L("flex flex-wrap gap-2",t&&"mt-2"),children:O.map((I,D)=>e.jsx("img",{src:I.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(I.content)},D))})]}),g&&e.jsx($n,{src:g,onClose:()=>j(null)}),B&&e.jsxs("div",{className:L("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(Mt,{label:s(m?"hub.copied":"hub.copy"),onClick:H,children:m?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(Mt,{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"})]})}),l&&e.jsx(Mt,{label:s("hub.edit"),onClick:()=>l(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"})]})}),d&&e.jsx(Mt,{label:s("hub.fork"),onClick:d,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 Mt({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 fr({agent:t,meta:n,model:s,effort:a,providerName:l,previewMeta:d,liveStartedAt:x}){const c=d?.contextPercent??null,m=d?.contextUsedTokens??0,v=d?.turnOutputTokens??0,g=c!=null||m>0||v>0,j=x!=null&&x>0,E=d?.providerName??l??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(Xe,{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||""]}),E&&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 ${E} (BYOK), not the agent CLI's native auth.`,children:["via ",E]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:vr(d),children:[c!=null&&e.jsx(jr,{pct:c}),e.jsx("span",{children:c!=null?`${c.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",br(m)]}),v>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Dn(v)]}),j&&e.jsx(gr,{startedAt:x,leadingDot:g})]})]})}function gr({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const l=setInterval(()=>s(d=>d+1),1e3);return()=>clearInterval(l)},[]);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?"· ":"",mr(a)]})}function mr(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 br(t){return`${Dn(t)} tok`}function Dn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function vr(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 jr({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 wn(t,n,s){return t==="zh-CN"?n:s}function wr({open:t,onClose:n,workdir:s}){const a=je(d=>d.locale),l=s.split("/").pop()||s;return e.jsxs(_t,{open:t,onClose:n,wide:!0,children:[e.jsx(Pt,{title:wn(a,`${l} — 项目扩展`,`${l} — Project Extensions`),description:wn(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(ms,{workdir:s}):null]})}let kn=Sn(()=>import("./SessionPanel-b2PrnaOi.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function tn(){return kn??=Sn(()=>import("./SessionPanel-b2PrnaOi.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),kn}const kr=r.lazy(async()=>({default:(await tn()).SessionPanel})),Xt=5,yr=240,Nr=120,Sr=12,Cr=900*1e3,F=(t,n)=>`${t}:${n}`;function Er(t){const n=new Map;for(const c of t)n.set(F(c.agent||"",c.sessionId),c);const s=new Map,a=new Set;for(const c of t){const m=c.migratedFrom;if(!m||m.kind!=="fork"||!m.sessionId)continue;const v=F(m.agent||c.agent||"",m.sessionId);n.has(v)&&(a.add(F(c.agent||"",c.sessionId)),s.has(v)||s.set(v,[]),s.get(v).push(c))}const l=[],d=new Set,x=(c,m)=>{const v=F(c.agent||"",c.sessionId);if(d.has(v))return;d.add(v),l.push(Object.assign({},c,{__forkDepth:m}));const g=s.get(v);if(g)for(const j of g)x(j,m+1)};for(const c of t){const m=F(c.agent||"",c.sessionId);a.has(m)||x(c,0)}for(const c of t)x(c,0);return l}let Lr=0;function Tt(){return`mk-${Date.now().toString(36)}-${(++Lr).toString(36)}`}function Mr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Tr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function Fn(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 Ir=r.memo(function({active:n=!0}){const s=je(o=>o.locale),a=je(o=>o.state?.runtimeWorkdir??null),l=r.useMemo(()=>as(s),[s]),[d,x]=r.useState([]),[c,m]=r.useState({}),[v,g]=r.useState({}),[j,E]=r.useState(!0),[k,N]=r.useState(()=>{try{const u=sessionStorage.getItem("pikiloom-layout-mode");if(u==="1"||u==="2"||u==="3"||u==="6")return Number(u)}catch{}const o=window.innerWidth;return o>=1920?3:o>=1280?2:1}),[M,A]=r.useState(()=>{try{const o=sessionStorage.getItem("pikiloom-open-sessions");if(o){const u=JSON.parse(o);if(Array.isArray(u))return u.map(h=>({...h,mountKey:h.mountKey||Tt()}))}}catch{}return[]}),[B,O]=r.useState(()=>{try{const o=sessionStorage.getItem("pikiloom-active-slot");if(o!=null){const u=Number(o);if(Number.isFinite(u)&&u>=0)return u}}catch{}return 0}),H=r.useCallback(o=>{N(o);try{sessionStorage.setItem("pikiloom-layout-mode",String(o))}catch{}},[]),_=r.useCallback(o=>{A(u=>{const h=typeof o=="function"?o(u):o;try{const f=h.map(({pendingPrompt:w,pendingImageUrls:y,...C})=>C);sessionStorage.setItem("pikiloom-open-sessions",JSON.stringify(f))}catch{}return h})},[]),I=r.useCallback(o=>{O(u=>{const h=typeof o=="function"?o(u):o;try{sessionStorage.setItem("pikiloom-active-slot",String(h))}catch{}return h})},[]);r.useEffect(()=>{_(o=>o.length>k?o.slice(0,k):o),I(o=>o>=k?k-1:o)},[k]);const[D,K]=r.useState(!1),ae=r.useRef(k);ae.current=k;const Z=r.useRef(B);Z.current=B;const T=r.useRef(-1),V=M[B]??null,Me=r.useCallback(o=>{if(!o){_([]),I(0);return}const u=o.mountKey?o:{...o,mountKey:Tt()};_(h=>{const f=h.findIndex(y=>y.agent===u.agent&&y.sessionId===u.sessionId);if(f>=0)return I(f),h;if(h.length<ae.current){const y=[...h,u];return I(y.length-1),y}const w=[...h];return w[Z.current]=u,w})},[]),[ce,we]=r.useState(!1),[$,Fe]=r.useState(null),[Te,tt]=r.useState(""),[ke,bt]=r.useState("all"),[de,vt]=r.useState({}),ee=r.useDeferredValue(Te),te=r.useRef(!1),Ue=r.useRef({}),Ie=r.useRef(c);Ie.current=c;const ze=r.useRef(de);ze.current=de;const nt=r.useRef(new Set),ne=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values(ne.current))clearTimeout(o)},[]);const le=r.useCallback(async()=>{try{const o=await J.getWorkspaces(),u=o.ok?o.workspaces:[];u.length&&x(h=>h.length===u.length&&h.every((f,w)=>f.path===u[w].path&&f.name===u[w].name)?h:u),te.current=!0}catch{te.current=!0}finally{E(!1)}},[]);r.useEffect(()=>{le()},[le]);const P=r.useCallback(async(o,u={})=>{if(!Ue.current[o]){Ue.current[o]=!0,u.background||g(h=>({...h,[o]:!0}));try{const h=await ks(o,{force:u.force});r.startTransition(()=>{m(f=>{const w=h.sessions||[],y=f[o]||[],C=new Set(w.map(z=>F(z.agent||"",z.sessionId))),U=y.filter(z=>{if(z.runState!=="running")return!1;const ie=F(z.agent||"",z.sessionId);if(C.has(ie))return!1;const dt=ze.current[ie];return!(dt?.resolvedKey&&dt.resolvedKey!==ie)});return{...f,[o]:U.length?[...U,...w]:w}})})}catch{u.background||r.startTransition(()=>{m(h=>({...h,[o]:[]}))})}finally{Ue.current[o]=!1,u.background||g(h=>({...h,[o]:!1}))}}},[]),ye=r.useRef(a);r.useEffect(()=>{a!==ye.current&&(ye.current=a,!(!a||!te.current)&&le().then(()=>{P(a,{force:!0})}))},[a,le,P]);const X=r.useCallback((o,u)=>{const h=o.agent||"";!h||!o.sessionId||(tn(),Ss({workdir:u,agent:h,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Sr}))},[]),Ae=r.useCallback((o,u,h=Nr)=>{const f=`${u}:${F(o.agent||"",o.sessionId)}`,w=ne.current[f];w&&clearTimeout(w),ne.current[f]=setTimeout(()=>{delete ne.current[f],X(o,u)},h)},[X]),Re=r.useCallback((o,u)=>{const h=`${u}:${F(o.agent||"",o.sessionId)}`,f=ne.current[h];f&&(clearTimeout(f),delete ne.current[h])},[]);r.useEffect(()=>{n&&tn()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return d.forEach((u,h)=>{if(c[u.path]||v[u.path])return;const f=setTimeout(()=>{P(u.path)},h*90);o.push(f)}),()=>{for(const u of o)clearTimeout(u)}},[n,P,v,c,d]);const jt=r.useRef(new Map);mn(n&&te.current&&d.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const u=o.key,h=u?d.filter(y=>(Ie.current[y.path]||[]).some(C=>F(C.agent||"",C.sessionId)===u)):d,f=h.length?h:d,w=jt.current;for(const y of f)w.has(y.path)&&clearTimeout(w.get(y.path)),w.set(y.path,setTimeout(()=>{w.delete(y.path),P(y.path,{background:!0,force:!0})},300))},[d,P]));const W=r.useCallback(o=>{const u=o.agent||"";return!u||!o.sessionId?o:ls(o,de[F(u,o.sessionId)]||null)},[de]);mn("stream-update",r.useCallback(o=>{const u=o.key;u&&vt(h=>{const f={},w=Date.now()-Cr;for(const[C,U]of Object.entries(h))U.updatedAt>=w&&(f[C]=U);const y=cs(u,o.snapshot??null);if(!y){const C=f[u];return C&&C.phase!=="done"&&(f[u]={...C,phase:"done",updatedAt:Date.now()}),f}return f[u]=y,y.resolvedKey!==u&&(f[y.resolvedKey]={...y,key:y.resolvedKey}),f})},[])),Rs(r.useCallback(()=>{if(!(!n||!te.current||d.length===0))for(const o of d)P(o.path,{background:!0,force:!0})},[n,d,P])),r.useEffect(()=>{if(!n||!te.current||d.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const h of d)P(h.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const u=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",u),window.addEventListener("focus",u),()=>{document.removeEventListener("visibilitychange",u),window.removeEventListener("focus",u)}},[n,P,d]),r.useEffect(()=>{if(!n)return;const o=[];return d.forEach((u,h)=>{const f=(c[u.path]||[])[0];if(!f)return;const w=`${u.path}:${F(f.agent||"",f.sessionId)}`;if(nt.current.has(w))return;const y=setTimeout(()=>{nt.current.add(w),X(f,u.path)},yr+h*120);o.push(y)}),()=>{for(const u of o)clearTimeout(u)}},[n,c,X,d]);const se=r.useCallback(async o=>{try{(await J.addWorkspace(o)).ok&&(we(!1),await le(),P(o))}catch{}},[le,P]),[xe,Ne]=r.useState(null),[re,_e]=r.useState(!1),[st,wt]=r.useState(null),He=r.useCallback(o=>{Ne(o)},[]),rt=r.useCallback(async()=>{const o=xe;if(o){_e(!0);try{await J.removeWorkspace(o),x(u=>u.filter(h=>h.path!==o)),m(u=>{const h={...u};return delete h[o],h}),_(u=>u.filter(h=>h.workdir!==o)),I(0),Ne(null)}catch{}finally{_e(!1)}}},[xe]),ot=r.useCallback(o=>{P(o,{force:!0})},[P]),[Se,G]=r.useState(null),[pe,Ce]=r.useState(!1),[oe,Pe]=r.useState(!1),We=je(o=>o.toast),[ue,it]=r.useState(null),at=r.useCallback((o,u,h)=>{it({anchor:{right:o.right,bottom:o.bottom},target:{workdir:h,agent:u.agent||"",sessionId:u.sessionId,title:yn(u).slice(0,120)||u.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!ue)return;const o=()=>it(null),u=h=>{h.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",u),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",u)}},[ue]);const Bt=r.useCallback(o=>{Ce(!1),G(o),it(null)},[]),kt=r.useCallback(async()=>{const o=Se;if(o){Pe(!0);try{const u=await J.deleteSession(o.workdir,o.agent,o.sessionId,pe);if(!u.ok){const h=u.error?.includes("still running")?l("session.deleteRunningError"):u.error||l("session.deleteFailed");We(h,!1);return}m(h=>{const f=h[o.workdir];if(!f)return h;const w=f.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return w.length===f.length?h:{...h,[o.workdir]:w}}),_(h=>h.filter(f=>!(f.workdir===o.workdir&&f.agent===o.agent&&f.sessionId===o.sessionId))),G(null)}catch(u){We(u?.message||l("session.deleteFailed"),!1)}finally{Pe(!1)}}},[Se,pe,l,We]),$t=r.useCallback(o=>{_(u=>{let h=!1;const f=u.map(w=>w.mountKey===o&&(w.pendingPrompt!=null||w.pendingImageUrls)?(h=!0,{...w,pendingPrompt:null,pendingImageUrls:void 0}):w);return h?f:u})},[_]),lt=r.useCallback((o,u,h)=>{X({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),m(y=>{const C=y[o.workdir]||[];if(C.some(ie=>ie.sessionId===o.sessionId&&ie.agent===o.agent))return y;const z={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:u,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[z,...C]}});const f=T.current,w={...o,mountKey:Tt(),pendingPrompt:u||null,pendingImageUrls:h&&h.length?h:void 0};r.startTransition(()=>{Fe(null),_(y=>{if(f>=y.length)return[...y,w];const C=[...y];return C[f]=w,C}),I(f>=0?f:0)}),P(o.workdir,{background:!0,force:!0})},[P,X,_,I]),Be=r.useCallback((o,u)=>{X(o,u),Fe(null),r.startTransition(()=>{Me({agent:o.agent||"",sessionId:o.sessionId,workdir:u})})},[X]),Ke=r.useCallback((o,u)=>{X({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{u!=null?(_(h=>{if(u>=h.length)return h;const f=[...h];return f[u]={...h[u],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},f}),I(u)):Me({...o,mountKey:Tt()})}),P(o.workdir,{background:!0,force:!0})},[P,X]),Ve=r.useCallback(o=>{let u=o;if(ke==="running"?u=u.filter(h=>It(h)==="running"):ke==="review"&&(u=u.filter(h=>It(h)==="incomplete")),ee.trim()){const h=ee.toLowerCase();u=u.filter(f=>(f.lastMessageText||"").toLowerCase().includes(h)||(f.lastQuestion||"").toLowerCase().includes(h)||(f.lastAnswer||"").toLowerCase().includes(h)||(f.title||"").toLowerCase().includes(h)||(f.agent||"").toLowerCase().includes(h))}return u},[ee,ke]),fe=r.useMemo(()=>{const o={};for(const u of d){const h=(c[u.path]||[]).map(W),f=new Map;for(const y of h){const C=F(y.agent||"",y.sessionId),U=de[C],z=U?.resolvedKey&&U.resolvedKey!==C?U.resolvedKey:C,ie=f.get(z);if(!ie){f.set(z,y);continue}F(ie.agent||"",ie.sessionId)!==z&&C===z&&f.set(z,y)}const w=Ve([...f.values()]);o[u.path]=Er(w)}return o},[d,c,de,Ve,W]),yt=r.useCallback(o=>{const u=(c[o.workdir]||[]).find(h=>h.sessionId===o.sessionId&&h.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return W(u)},[W,c]),ct=r.useMemo(()=>new Set(M.map(o=>F(o.agent,o.sessionId))),[M]),Nt=V?F(V.agent,V.sessionId):null,St=r.useCallback(o=>{_(u=>{const h=u.filter((f,w)=>w!==o);return h.length===0?I(0):Z.current>=h.length&&I(h.length-1),h})},[]);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:Te,onChange:o=>tt(o.target.value),placeholder:l("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"}),Te&&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(o=>e.jsx("button",{onClick:()=>bt(o),className:L("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",ke===o?"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:l(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),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(he,{className:"h-4 w-4 text-fg-5"})}):d.length===0&&!ce?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:l("hub.noWorkspaces")}):d.map(o=>e.jsx(Pr,{workspace:o,sessions:fe[o.path]||[],loading:!!v[o.path]||!(o.path in c),isActive:o.path===a,selectedKey:Nt,openSessionKeys:ct,onSelectSession:Be,onNewSession:Fe,onRefresh:ot,onRemove:He,onExtensions:wt,onWarmSession:Ae,onCancelWarmSession:Re,onSessionMenuOpen:at,t:l},o.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(o=>e.jsx("button",{onClick:()=>H(o),className:L("flex-1 flex items-center justify-center p-1.5 rounded transition-all",k===o?"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:l(`hub.layout${o}`),children:o===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"})}):o===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"})]}):o===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"})]})},o))}),e.jsxs(Ee,{variant:"ghost",size:"sm",onClick:()=>we(o=>!o),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"})]}),l("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(${k===6?3:k}, 1fr)`,gridTemplateRows:k===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=$?M.length<k?M.length:B:-1;return T.current=o,Array.from({length:k},(u,h)=>{if($&&h===o)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(Rr,{workdir:$,workspaceName:d.find(C=>C.path===$)?.name||$.split("/").pop()||"",onSessionCreated:lt,onClose:()=>Fe(null),t:l},$)},`new-${$}`);const f=M[h]??null;if(!f)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:l("hub.emptySlot")})]})},`empty-${h}`);const w=yt(f),y=h===B;return e.jsxs("div",{className:L("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>I(h),children:[e.jsxs("div",{className:L("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const C=It(w);return e.jsx(Wt,{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:f.workdir.split("/").pop()||f.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)||f.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:l("hub.created"),children:ds(w.createdAt)}),w.runUpdatedAt&&e.jsx("span",{title:l("hub.updated"),children:Nn(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(U=>!U)},className:L("p-0.5 rounded transition-colors",D?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:l("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(),St(h)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:l("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(kr,{session:w,workdir:f.workdir,active:n&&y,onSessionChange:C=>Ke(C,h),initialPendingPrompt:f.pendingPrompt??null,initialPendingImageUrls:f.pendingImageUrls,onPendingPromptConsumed:()=>$t(f.mountKey)},f.mountKey)})})]},f.mountKey||F(f.agent,f.sessionId))})})()})}),D&&V&&e.jsx(Br,{workdir:V.workdir,onClose:()=>K(!1),t:l}),e.jsx(Ar,{open:ce,initialPath:a||void 0,onAdd:se,onClose:()=>we(!1),t:l}),e.jsxs(_t,{open:!!xe,onClose:()=>!re&&Ne(null),children:[e.jsx(Pt,{title:l("hub.removeWorkspace"),onClose:()=>!re&&Ne(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:l("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(Ee,{variant:"ghost",onClick:()=>Ne(null),disabled:re,children:l("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:rt,disabled:re,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(re?"modal.removing":"modal.remove")})]})]}),ue&&(()=>{const u=Math.max(8,Math.min(ue.anchor.right-160,window.innerWidth-160-8)),h=Math.min(ue.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:h,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:f=>f.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>Bt(ue.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"})]}),l("session.delete")]})})})(),e.jsxs(_t,{open:!!Se,onClose:()=>!oe&&G(null),children:[e.jsx(Pt,{title:l("session.deleteTitle"),onClose:()=>!oe&&G(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("session.deleteHint")}),Se&&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:Se.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Se.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:()=>Ce(!1),disabled:oe,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:l("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:l("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:()=>Ce(!0),disabled:oe,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:l("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:l("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ee,{variant:"ghost",onClick:()=>G(null),disabled:oe,children:l("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:kt,disabled:oe,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(oe?"session.deleting":"modal.remove")})]})]}),e.jsx(wr,{open:!!st,onClose:()=>wt(null),workdir:st||""})]})});function Ar({open:t,initialPath:n,onAdd:s,onClose:a,t:l}){const[d,x]=r.useState(""),c=r.useCallback(m=>x(m),[]);return r.useEffect(()=>{t&&x("")},[t]),e.jsxs(_t,{open:t,onClose:a,children:[e.jsx(Pt,{title:l("hub.addWorkspace"),onClose:a}),e.jsx(ps,{initialPath:n,maxHeight:360,minHeight:200,onSelect:c,t:l}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ee,{disabled:!d,onClick:()=>d&&s(d),className:"flex-1",children:l("hub.add")}),e.jsx(Ee,{variant:"secondary",onClick:a,className:"flex-1",children:l("hub.cancel")})]})]})}function Rr({workdir:t,workspaceName:n,onSessionCreated:s,onClose:a,t:l}){const[d,x]=r.useState(null),[c,m]=r.useState([]),v=r.useRef(null),g=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),E=r.useCallback(()=>{},[]),k=r.useCallback((A,B)=>{x(A||null),v.current=A||null;const O=B||[];m(O),g.current=O},[]),N=r.useCallback(A=>{const B=g.current;g.current=[],s(A,v.current||void 0,B.length?B:void 0)},[s]),M=!!d||c.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:l("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(Wt,{variant:M?"ok":"idle",pulse:M}),!M&&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:M?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(On,{text:d||"",blocks:c.map(A=>({type:"image",content:A})),t:l}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(en,{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:l("hub.newSessionHint")})})})}),e.jsx(Gs,{session:j,workdir:t,onStreamQueued:E,onSendStart:k,onSessionChange:N,t:l,streamPhase:null})]})}function _r({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
23
  `);return e.jsx(us,{content:n,className:L("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 Pr=r.memo(function({workspace:n,sessions:s,loading:a,isActive:l,selectedKey:d,openSessionKeys:x,onSelectSession:c,onNewSession:m,onRefresh:v,onRemove:g,onExtensions:j,onWarmSession:E,onCancelWarmSession:k,onSessionMenuOpen:N,t:M}){const[A,B]=r.useState(!0),[O,H]=r.useState(Xt);r.useEffect(()=>{H(Xt)},[s.length]);const _=s.slice(0,O),I=s.length-O,D=n.path,[K,ae]=r.useState(null),Z=r.useCallback(()=>{J.getWorkspaceGit(D).then(T=>ae(T.git)).catch(()=>ae(null))},[D]);return r.useEffect(()=>{Z()},[Z]),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:()=>B(T=>!T),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:L("shrink-0 text-fg-5 transition-transform duration-150",A&&"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:L("min-w-0 truncate text-[12px] font-semibold",l?"text-primary":"text-fg-3"),children:n.name}),e.jsx(_r,{git:K})]}),l&&e.jsx(Wt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:T=>{T.stopPropagation(),m(D)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:M("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:T=>{T.stopPropagation(),j(D)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:M("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:T=>{T.stopPropagation(),v(D),Z()},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"})]})}),!l&&e.jsx("button",{onClick:T=>{T.stopPropagation(),g(D)},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"})]})})]})]}),A&&e.jsx("div",{className:"pb-1",children:a?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(he,{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:M("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[_.map(T=>{const V=F(T.agent||"",T.sessionId),Me=T.__forkDepth||0;return e.jsx(Wr,{session:T,isSelected:d===V,isOpen:x?.has(V)??!1,forkDepth:Me,onClick:()=>c(T,D),onWarm:()=>E(T,D),onCancelWarm:()=>k(T,D),onShowMenu:ce=>N(ce,T,D),menuLabel:M("session.openActions")},V)}),I>0&&e.jsxs("button",{onClick:()=>H(T=>T+Xt),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:["+ ",M("hub.nMore").replace("{n}",String(I))]}),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"})})]})]})})]})}),Wr=r.memo(function({session:n,isSelected:s,isOpen:a,forkDepth:l=0,onClick:d,onWarm:x,onCancelWarm:c,onShowMenu:m,menuLabel:v}){const g=Yt(n.agent||""),j=It(n),E=yn(n).slice(0,500)||n.sessionId.slice(0,16),k=hs(n,E).slice(0,500),N=n.model?sn(n.model):null,M=l>0?Math.min(l,3)*14:0,A=a?10:12,B=r.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:d,onMouseEnter:x,onFocus:x,onMouseLeave:c,onBlur:c,className:L("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:A+M,...a?{borderLeft:`2px solid ${s?g.color:`${g.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[l>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(Xe,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),N&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:N}),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:Nn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Wt,{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:E})]}),k&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:k})})]}),e.jsx("button",{ref:B,type:"button","aria-label":v,"aria-haspopup":"menu",onMouseDown:O=>{O.stopPropagation()},onClick:O=>{O.stopPropagation(),O.preventDefault(),B.current&&m(B.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"})]})})]})}),Br=r.memo(function({workdir:n,onClose:s,t:a}){const l=je(g=>g.state?.hostApp??null),d=je(g=>g.state?.platform??null),x=je(g=>g.toast),[c,m]=r.useState(()=>Tr(l,d)),v=r.useCallback(async g=>{try{const j=await J.openInEditor(g,c);if(!j.ok)throw new Error(j.error||`Failed to open ${g}`)}catch(j){x(j?.message||String(j),!1)}},[c,x]);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(xs,{value:c,options:(d==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:a(Fn(g))})),onChange:g=>{Mr(g)&&m(g)},renderIcon:g=>e.jsx(Un,{target:g,size:14})}),e.jsx(Ee,{size:"sm",variant:"ghost",onClick:()=>v(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($r,{basePath:n,openTarget:c,onOpenPath:v,t:a})})]})});function Un({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(Xe,{brand:t,size:n})}function $r({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:a,t:l}){const[d,x]=r.useState([]),[c,m]=r.useState(!0);r.useEffect(()=>{let g=!1;return m(!0),J.lsDir(t,!0,n).then(j=>{!g&&j.ok&&x(j.dirs.slice(0,50).map(E=>({entry:E,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||m(!1)}),()=>{g=!0}},[t,n]);const v=r.useCallback(g=>{const j=E=>E.map(k=>k.entry.path===g?k.expanded?{...k,expanded:!1}:k.children===null?(J.lsDir(g,!0,n).then(N=>{N.ok&&x(M=>nn(M,g,{children:N.dirs.slice(0,50).map(A=>({entry:A,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(N=>nn(N,g,{children:[],loading:!1}))}),{...k,loading:!0,expanded:!0}):{...k,expanded:!0}:k.children?{...k,children:j(k.children)}:k);x(E=>j(E))},[n]);return c?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(he,{className:"h-3 w-3 text-fg-5"})}):d.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(zn,{nodes:d,depth:0,onToggle:v,openTarget:s,onOpenPath:a,t:l})})}function zn({nodes:t,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:d}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(Or,{node:x,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:d},x.entry.path))})}function Or({node:t,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:d}){const{entry:x,expanded:c,children:m,loading:v}=t,g=n*14,[j,E]=r.useState(!1),k=d(Fn(a)),N=d("hub.openWithTarget").replace("{target}",k);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>E(!0),onMouseLeave:()=>E(!1),className:L("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",x.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+g,paddingRight:8},children:[x.isDir?v?e.jsx(he,{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:L("shrink-0 text-fg-5/40 transition-transform duration-150",c&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),x.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:x.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:M=>{M.stopPropagation(),l(x.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:N,children:e.jsx(Un,{target:a,subtle:!0})}),!x.isDir&&e.jsx(Dr,{filePath:x.path,t:d})]})]}),x.isDir&&c&&m&&m.length>0&&e.jsx(zn,{nodes:m,depth:n+1,onToggle:s,openTarget:a,onOpenPath:l,t:d})]})}function Dr({filePath:t,t:n}){const[s,a]=r.useState(!1);return e.jsx("button",{onClick:l=>{l.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{a(!0),setTimeout(()=>a(!1),1500)}).catch(()=>{})},className:L("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 nn(t,n,s){return t.map(a=>a.entry.path===n?{...a,...s}:a.children?{...a,children:nn(a.children,n,s)}:a)}const to=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Ir},Symbol.toStringTag,{value:"Module"}));export{Gs as I,Zr as L,tr as R,eo as T,On as U,Jr as a,Pn as b,Rs as c,en as d,Yr as e,fr as f,to as i,Ns as l,Xr as m,Qr as n,ys as p,mn as u};
@@ -1 +1 @@
1
- import{j as s}from"./react-vendor-C7Sl8SE7.js";import{J as t,i as n,S as a}from"./index-gXOsku2L.js";function o({primary:e,secondary:l,tertiary:i}){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(n,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(n,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),i&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:i})]})}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{J as t,i as n,S as a}from"./index-BJL-XxHY.js";function o({primary:e,secondary:l,tertiary:i}){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(n,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(n,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),i&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:i})]})}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-gXOsku2L.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-BJL-XxHY.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">
@@ -916,6 +916,20 @@ export function decideClaudeTuiStop(input) {
916
916
  }
917
917
  return 'terminate';
918
918
  }
919
+ /**
920
+ * True for the `im_ask_user` MCP tool in any form — Claude Code names MCP tools
921
+ * `mcp__<server>__<tool>` (here `mcp__pikiloom__im_ask_user`), so match the
922
+ * namespaced suffix as well as the bare name (robust to the server name
923
+ * changing). The driver tails Pre/PostToolUse hooks by id but must also know
924
+ * *which* pending tool is the one that blocks on the user, so the stall
925
+ * watchdog can stay armed for every other tool and disarm only for a live
926
+ * question. See decideClaudeTuiStall(`awaitingUserReply`).
927
+ */
928
+ export function isAskUserToolName(name) {
929
+ if (typeof name !== 'string' || !name)
930
+ return false;
931
+ return name === 'im_ask_user' || name.endsWith('__im_ask_user');
932
+ }
919
933
  /**
920
934
  * Decide whether the turn has gone dead. claude CLI is known to freeze
921
935
  * mid-turn (observed 2026-06-02 on 2.1.160): after a tool_result lands the
@@ -937,8 +951,20 @@ export function decideClaudeTuiStop(input) {
937
951
  * past `ptyDeadMs`, declare the stall immediately instead of waiting out the
938
952
  * 10/30-minute quiet thresholds. Long thinking and long foreground commands
939
953
  * keep painting frames, which routes them to the slow thresholds as before.
954
+ *
955
+ * `awaitingUserReply` is the one state that is quiet BY DESIGN, not because the
956
+ * process froze: an `im_ask_user` MCP call is in flight (PreToolUse seen, no
957
+ * PostToolUse) and the turn is blocked on the user's reply — the `/ask-user`
958
+ * callback never times out. Every signal (JSONL, hooks, PTY) goes silent while
959
+ * the user thinks, which is indistinguishable by timing alone from a freeze, so
960
+ * the watchdog must never stall here. The hard turn deadline remains the
961
+ * backstop if the user never answers; PostToolUse re-arms the watchdog the
962
+ * instant the answer lands. Without this, the last question regularly gets
963
+ * SIGTERMed mid-wait and mislabelled a "CLI freeze".
940
964
  */
941
965
  export function decideClaudeTuiStall(input) {
966
+ if (input.awaitingUserReply)
967
+ return 'wait';
942
968
  const ptyAt = input.lastPtyDataAt ?? 0;
943
969
  if (ptyAt > 0) {
944
970
  const ptyDeadMs = input.ptyDeadMs ?? CLAUDE_TUI_STALL_PTY_DEAD_MS;
@@ -1557,6 +1583,13 @@ export async function doClaudeTuiStream(opts) {
1557
1583
  let lastClearedStopAt = 0;
1558
1584
  /** Hook-reported tools still executing: PreToolUse seen, no PostToolUse. */
1559
1585
  const pendingHookToolIds = new Set();
1586
+ /** Subset of pendingHookToolIds that are `im_ask_user` calls — the turn is
1587
+ * intentionally blocked on the user's reply (the /ask-user callback never
1588
+ * times out), so the stall watchdog must stay disarmed while any are in
1589
+ * flight. Cleared by the answer (PostToolUse) or the turn ending (Stop). */
1590
+ const pendingAskUserToolIds = new Set();
1591
+ /** Edge-logged so the "watchdog disarmed" line fires on transitions only. */
1592
+ let loggedAwaitingUser = false;
1560
1593
  // Incremental main-JSONL drain — the canonical text/thinking/usage feed.
1561
1594
  // Used by both the 200ms poll tick and the post-exit final drain. Returns
1562
1595
  // true when any line was consumed so callers can emit().
@@ -1643,10 +1676,17 @@ export async function doClaudeTuiStream(opts) {
1643
1676
  lastToolEventAt = Date.now();
1644
1677
  const hookToolId = typeof ev?.tool_use_id === 'string' ? ev.tool_use_id : '';
1645
1678
  if (hookToolId) {
1646
- if (ev?.event === 'PreToolUse')
1679
+ if (ev?.event === 'PreToolUse') {
1647
1680
  pendingHookToolIds.add(hookToolId);
1648
- else if (ev?.event === 'PostToolUse')
1681
+ // im_ask_user blocks the turn on the user — track it separately so the
1682
+ // stall watchdog can tell an intentional question-wait from a freeze.
1683
+ if (isAskUserToolName(ev?.tool_name))
1684
+ pendingAskUserToolIds.add(hookToolId);
1685
+ }
1686
+ else if (ev?.event === 'PostToolUse') {
1649
1687
  pendingHookToolIds.delete(hookToolId);
1688
+ pendingAskUserToolIds.delete(hookToolId);
1689
+ }
1650
1690
  }
1651
1691
  // A Task PreToolUse and the first sub-agent tool PreToolUse can land in
1652
1692
  // the same tick batch. If the sub-agent's hook arrives before we've
@@ -1866,6 +1906,8 @@ export async function doClaudeTuiStream(opts) {
1866
1906
  agentWarn(`[claude-tui] Stop fired with ${pendingHookToolIds.size} unmatched PreToolUse event(s) — clearing (lost PostToolUse hooks)`);
1867
1907
  pendingHookToolIds.clear();
1868
1908
  }
1909
+ // A fired Stop ends the turn — any tracked ask-user is moot.
1910
+ pendingAskUserToolIds.clear();
1869
1911
  }
1870
1912
  const pendingBg = pendingClaudeBackgroundAgentCount(s);
1871
1913
  const decision = decideClaudeTuiStop({
@@ -1925,6 +1967,19 @@ export async function doClaudeTuiStream(opts) {
1925
1967
  // exactly that hold state → disarm the fast path (0 = unavailable).
1926
1968
  const nonStopProgressAt = Math.max(start, lastMainJsonlEventAt, lastToolEventAt, lastSidecarEventAt, state.promptSubmittedAt || 0);
1927
1969
  const inPostStopHold = !!state.stoppedAt && state.stoppedAt >= nonStopProgressAt;
1970
+ // An im_ask_user call is in flight → the turn is blocked on the user's
1971
+ // reply, not frozen (the /ask-user callback never times out). Disarm the
1972
+ // stall watchdog AND the freeze diagnostics until the user answers
1973
+ // (PostToolUse clears the id). Otherwise the quiet wait trips
1974
+ // decideClaudeTuiStall, classifies 'unknown', and gets SIGTERMed +
1975
+ // mislabelled a "CLI freeze" — the last-question hang the user reported.
1976
+ const awaitingUserReply = pendingAskUserToolIds.size > 0;
1977
+ if (awaitingUserReply !== loggedAwaitingUser) {
1978
+ loggedAwaitingUser = awaitingUserReply;
1979
+ if (awaitingUserReply) {
1980
+ agentLog(`[claude-tui] im_ask_user in flight — stall watchdog disarmed until the user replies pid=${proc.pid}`);
1981
+ }
1982
+ }
1928
1983
  // Chokepoint answer-retry grace. We sent the affirmative key at a stuck dialog; give it time
1929
1984
  // to clear. If the screen is no longer a blocking dialog, the answer took — disarm and re-arm
1930
1985
  // so a later prompt in the same turn can also get a chokepoint retry. If it is STILL a dialog
@@ -1948,7 +2003,7 @@ export async function doClaudeTuiStream(opts) {
1948
2003
  if (!stallKilled) {
1949
2004
  const nowMs = Date.now();
1950
2005
  const quietMs = nowMs - lastProgressAt;
1951
- if (quietMs >= STALL_DIAG_QUIET_THRESHOLD_MS && !inPostStopHold) {
2006
+ if (quietMs >= STALL_DIAG_QUIET_THRESHOLD_MS && !inPostStopHold && !awaitingUserReply) {
1952
2007
  const ptyQuietMs = nowMs - lastPtyDataAt;
1953
2008
  stallDiagWentQuiet = true;
1954
2009
  if (quietMs > stallDiagMaxQuietMs)
@@ -1992,6 +2047,7 @@ export async function doClaudeTuiStream(opts) {
1992
2047
  now: Date.now(),
1993
2048
  lastProgressAt,
1994
2049
  pendingToolCount: pendingHookToolIds.size + pendingBgForStall,
2050
+ awaitingUserReply,
1995
2051
  lastPtyDataAt: inPostStopHold ? 0 : lastPtyDataAt,
1996
2052
  });
1997
2053
  if (stallDecision === 'stall') {
@@ -121,7 +121,10 @@ export function setAgentWorkflowEnv(agent, value, env = process.env) {
121
121
  break;
122
122
  }
123
123
  }
124
- export const DEFAULT_CLAUDE_ACCESS_MODE = 'subscription';
124
+ // Default `api` = headless `claude -p`, the standard integration path. The
125
+ // interactive TUI ('subscription', Pro/Max quota) is opt-in via the dashboard
126
+ // 接入模式 toggle or PIKILOOM_CLAUDE_TUI=1.
127
+ export const DEFAULT_CLAUDE_ACCESS_MODE = 'api';
125
128
  /**
126
129
  * Access mode implied by env, or null when neither var has an opinion.
127
130
  * PIKILOOM_CLAUDE_PRINT takes precedence over the legacy PIKILOOM_CLAUDE_TUI so
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pikiloom",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "description": "Put the world's smartest AI agents in your pocket. Command local Claude & Gemini via IM. | 让最好用的 IM 变成你电脑上的顶级 Agent 控制台",
5
5
  "type": "module",
6
6
  "bin": {