pikiclaw 0.3.39 → 0.3.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dashboard/dist/assets/{AgentTab-DmKQYVz1.js → AgentTab-BFG_wBIC.js} +1 -1
  2. package/dashboard/dist/assets/{BrandIcon-KSnFdk62.js → BrandIcon-CmIkwB4h.js} +1 -1
  3. package/dashboard/dist/assets/{DirBrowser-BqA8ssEC.js → DirBrowser-BzqSOCzY.js} +1 -1
  4. package/dashboard/dist/assets/{ExtensionsTab-B86en9KI.js → ExtensionsTab-GyHiQaZK.js} +1 -1
  5. package/dashboard/dist/assets/{IMAccessTab-6L_l5Y5A.js → IMAccessTab-CO_5ztrR.js} +1 -1
  6. package/dashboard/dist/assets/{Modal-Dk3jQZ_G.js → Modal-Cx6r2XJQ.js} +1 -1
  7. package/dashboard/dist/assets/{Modals-BoS_lRW5.js → Modals-BnORfmhY.js} +1 -1
  8. package/dashboard/dist/assets/{Select-CCtTUA2O.js → Select-DLAvmM_i.js} +1 -1
  9. package/dashboard/dist/assets/{SessionPanel-DA6GsYqZ.js → SessionPanel-D2kHNUr3.js} +1 -1
  10. package/dashboard/dist/assets/{SystemTab-BQV-kjCS.js → SystemTab-BkgF1WI4.js} +1 -1
  11. package/dashboard/dist/assets/index-B_sC2ppg.js +5 -0
  12. package/dashboard/dist/assets/index-DZy1Xu_H.js +19 -0
  13. package/dashboard/dist/assets/{shared-CVa9npgA.js → shared-C-0W57w0.js} +1 -1
  14. package/dashboard/dist/index.html +1 -1
  15. package/dist/agent/drivers/claude.js +57 -0
  16. package/dist/agent/drivers/codex.js +7 -1
  17. package/dist/agent/handover.js +130 -0
  18. package/dist/agent/index.js +3 -1
  19. package/dist/agent/session.js +25 -11
  20. package/dist/bot/bot.js +146 -66
  21. package/dist/bot/commands.js +24 -4
  22. package/dist/dashboard/routes/sessions.js +8 -2
  23. package/dist/dashboard/session-control.js +104 -2
  24. package/package.json +1 -1
  25. package/dashboard/dist/assets/index-BS_RBT-T.js +0 -5
  26. package/dashboard/dist/assets/index-C-Dh421o.js +0 -16
@@ -0,0 +1,19 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-D2kHNUr3.js","assets/react-vendor-DTcmqLiz.js","assets/index-B_sC2ppg.js","assets/router-Cav8lq-m.js","assets/index-BKX45VMn.css","assets/Modal-Cx6r2XJQ.js","assets/Select-DLAvmM_i.js","assets/BrandIcon-CmIkwB4h.js","assets/DirBrowser-BzqSOCzY.js","assets/markdown-iTdiLvRJ.js","assets/ExtensionsTab-GyHiQaZK.js"])))=>i.map(i=>d[i]);
2
+ import{c as M,a as X,u as ve,s as Wt,S as te,g as Lt,E as Nt,C as Bt,b as Rn,d as _n,n as Wn,e as xt,B as Ue,D as gt,f as Bn,h as on,_ as ln,i as Pn,j as On}from"./index-B_sC2ppg.js";import{j as e,r,b as Pt}from"./react-vendor-DTcmqLiz.js";import{I as $n}from"./Select-DLAvmM_i.js";import{M as Ot,a as $t}from"./Modal-Cx6r2XJQ.js";import{B as Je}from"./BrandIcon-CmIkwB4h.js";import{D as Dn}from"./DirBrowser-BzqSOCzY.js";import{n as Fn,r as Un,M as Dt}from"./markdown-iTdiLvRJ.js";import{WorkspaceExtensionsBody as zn}from"./ExtensionsTab-GyHiQaZK.js";function Kn({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("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 Ke({open:t,onToggle:n,dot:s,label:l,preview:a,badge:c,collapsedContent:h,children:d,className:p}){return e.jsxs("div",{className:M("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",p),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:M("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:l}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:a}),c,e.jsx(Kn,{open:t})]}),!t&&h,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Hn=5e3,Vn=15e3,ft=8,pt=30,Gn=1,Fe=new Map,ue=new Map,St=new Set,an=[];let dt=0;function Ct(t){return typeof t=="number"&&Number.isFinite(t)}function Ee(t,n,s,l){for(t.delete(n),t.set(n,s);t.size>l;){const a=t.keys().next().value;if(!a)break;t.delete(a)}}function cn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(Ee(t,n,s,t===ue?pt:ft),s.value)}function dn(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:Ct(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:Ct(t.turnOffset)?t.turnOffset:void 0,turnLimit:Ct(t.turnLimit)?t.turnLimit:void 0}}function Ft(t){const n=dn(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function un(){for(;dt<Gn;){const t=an.shift();if(!t)return;dt+=1,t().finally(()=>{dt=Math.max(0,dt-1),un()})}}async function Qn(t,n={}){const s=t;if(!n.force){const c=cn(Fe,s);if(c)return c}const l=Fe.get(s);if(l?.promise)return l.promise;const a=X.getWorkspaceSessions(t,n.request).then(c=>(Ee(Fe,s,{value:c,expiresAt:c.ok?Date.now()+Hn:0},ft),c)).finally(()=>{const c=Fe.get(s);c?.promise&&Ee(Fe,s,{value:c.value,expiresAt:c.expiresAt},ft)});return Ee(Fe,s,{value:l?.value,expiresAt:l?.expiresAt??0,promise:a},ft),a}function qn(t,n={}){const s=Ft(t),l=ue.get(s);return l?.value?.ok&&(n.allowStale||l.expiresAt>Date.now())?l.value:null}async function Xn(t,n={}){const s=dn(t),l=Ft(s);if(!n.force){const h=cn(ue,l);if(h?.ok)return h}const a=ue.get(l);if(a?.promise)return a.promise;const c=X.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(h=>(Ee(ue,l,{value:h,expiresAt:h.ok?Date.now()+Vn:0},pt),h)).finally(()=>{const h=ue.get(l);h?.promise&&Ee(ue,l,{value:h.value,expiresAt:h.expiresAt},pt)});return Ee(ue,l,{value:a?.value,expiresAt:a?.expiresAt??0,promise:c},pt),c}function Yn(t){const n=Ft(t);qn(t)||St.has(n)||ue.get(n)?.promise||(St.add(n),an.push(async()=>{try{await Xn(t)}catch{}finally{St.delete(n)}}),un())}const Ze=new Map,At=new Set;let Le=null,je=0,Jt=!1,ze=null,Ye=500;const Jn=8e3;function Zn(t){const n=Ze.get(t.type);if(n)for(const s of n)s(t)}function es(){const t=window.location;return`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}/ws`}function Ut(){if(Le)return;hn();const t=new WebSocket(es());t.onopen=()=>{const n=Jt;if(Jt=!0,Ye=500,n)for(const s of At)s()},t.onmessage=n=>{try{const s=JSON.parse(n.data);if(s.type==="pong")return;Zn(s)}catch{}},t.onclose=()=>{Le=null,je>0&&ns()},t.onerror=()=>{},Le=t}function ts(){hn(),Le&&(Le.close(),Le=null)}function hn(){ze&&(clearTimeout(ze),ze=null)}function ns(){ze||(ze=setTimeout(()=>{ze=null,je>0&&Ut()},Ye),Ye=Math.min(Ye*2,Jn))}function ss(t,n){let s=Ze.get(t);s||(s=new Set,Ze.set(t,s)),s.add(n),je++,je===1&&Ut()}function rs(t,n){const s=Ze.get(t);s&&(s.delete(n),s.size===0&&Ze.delete(t)),je=Math.max(0,je-1),je===0&&ts()}typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&je>0&&!Le&&(Ye=500,Ut())});function Zt(t,n){const s=r.useRef(n);s.current=n,r.useEffect(()=>{if(!t)return;const l=a=>s.current(a);return ss(t,l),()=>rs(t,l)},[t])}function os(t){const n=r.useRef(t);n.current=t,r.useEffect(()=>{const s=()=>n.current();return At.add(s),()=>{At.delete(s)}},[])}function hr(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(h=>({role:h.role,text:h.text,blocks:[{type:"text",content:h.text}]}))||[],s=ls(n),l=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),a=t.window?.endTurn??l,c=t.window?.startTurn??Math.max(0,a-s.length);return{turns:s,startTurn:c,endTurn:a,totalTurns:l,hasOlder:t.window?.hasOlder??c>0}}function xr(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 fr(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 is(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
3
+
4
+ `),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function ls(t){const n=[];let s={user:null,assistant:null};for(const l of t)if(l.role==="user"){if(s.assistant&&xn(l.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=l}else s.assistant?s.assistant=is(s.assistant,l):s.assistant=l;return(s.user||s.assistant)&&n.push(s),n}const as=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"]),cs=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function xn(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&as.has(s[1].toLowerCase())?!0:cs.some(l=>t.includes(l))}function fn(t,n){const s=t.split(`
5
+ `).filter(l=>l.trim());return s.length<=n?s.join(`
6
+ `):s.slice(-n).join(`
7
+ `)}function Tt(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function ds(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function us(t){if(!Number.isFinite(t)||t<=0)return"0 B";if(t<1024)return`${t} B`;const n=t/1024;if(n<1024)return`${n.toFixed(n>=100?0:1)} KB`;const s=n/1024;return`${s.toFixed(s>=100?0:1)} MB`}async function hs(t){if(typeof ClipboardItem>"u"||!navigator.clipboard?.write)return!1;try{return await navigator.clipboard.write([new ClipboardItem({[t.type||"image/png"]:t})]),!0}catch{return!1}}function K(t,n=120){if(t==null)return"";const l=(typeof t=="string"?t:String(t)).replace(/\s+/g," ").trim();return l.length<=n?l:l.slice(0,Math.max(0,n-1))+"…"}function xs(t){if(!t)return null;try{const n=JSON.parse(t);return n&&typeof n=="object"&&!Array.isArray(n)?n:null}catch{return null}}function pn(t){const n=String(t.toolName||"").trim()||"Tool",s=xs(t.content);if(!s)return n;const l=K(s.description,120);switch(n){case"Read":{const a=K(s.file_path||s.path,140);return a?`Read ${a}`:"Read"}case"Edit":{const a=K(s.file_path||s.path,140);return a?`Edit ${a}`:"Edit"}case"Write":{const a=K(s.file_path||s.path,140);return a?`Write ${a}`:"Write"}case"Glob":{const a=K(s.pattern||s.glob,120);return a?`Glob ${a}`:"Glob"}case"Grep":{const a=K(s.pattern||s.query,120);return a?`Grep ${a}`:"Grep"}case"WebFetch":{const a=K(s.url,120);return a?`WebFetch ${a}`:"WebFetch"}case"WebSearch":{const a=K(s.query,120);return a?`WebSearch ${a}`:"WebSearch"}case"TodoWrite":return"Update plan";case"AskUserQuestion":{const c=(Array.isArray(s.questions)?s.questions:[])[0],h=K(c?.question||s.question,120);return h?`Ask user: ${h}`:"Ask user"}case"Task":{const a=K(s.description||s.prompt,120);return a?`Task: ${a}`:"Task"}case"Bash":{if(l)return`Bash: ${l}`;const a=K(s.command,120);return a?`Bash: ${a}`:"Bash"}default:{const a=n.match(/^mcp__[^_]+__(.+)$/),c=a?a[1]:n;if(c==="im_send_file"){const d=K(s.path,120);return d?`Send file: ${d}`:"Send file"}if(c==="im_list_files")return"List workspace files";if(l)return`${n}: ${l}`;const h=K(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return h?`${n}: ${h}`:n}}}function fs(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
8
+ `).map(l=>l.trim()).find(Boolean)||"";return s?K(s,140):"result"}function ps(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),l=t.slice(n+1).trim();return!s||!l?null:{agent:s,sessionId:l}}const Xe=new Map;function gs(t,n){return`${t}:${n}`}const ms=r.memo(function({session:n,workdir:s,onStreamQueued:l,onSendStart:a,onSendTaskAssigned:c,onSessionChange:h,t:d,streamPhase:p,streamTaskId:g,queuedTaskIds:m,queuedTasks:k,pendingPrompt:y,onRecall:j,onSteer:L,onStopAll:A,editDraft:_,onEditDraftConsumed:P}){const[B,H]=r.useState(""),[$,T]=r.useState(!1),[C,V]=r.useState(null),[ne,Ae]=r.useState(()=>new Set),[we,he]=r.useState(()=>new Set),xe=r.useRef({prompt:"",files:[]}),ke=ve(o=>o.agentStatus?.agents??null),[D,se]=r.useState(ke||[]),[fe,Ie]=r.useState(""),[Re,ye]=r.useState(""),[He,re]=r.useState(""),[J,oe]=r.useState([]),[ie,pe]=r.useState(null),[ge,Ne]=r.useState(null),[Se,G]=r.useState(null),[le,I]=r.useState(null),[W,R]=r.useState("closed"),[Ve,et]=r.useState(null),me=r.useRef(null),ae=r.useRef(!1),tt=r.useRef(null),Ce=r.useRef(null),Z=r.useRef(null),ce=r.useRef([]),[_e,nt]=r.useState([]),[Y,We]=r.useState(!1),[Be,Pe]=r.useState(0),Oe=r.useRef(null),st=ve(o=>o.refreshAgentStatus);r.useEffect(()=>{ke?.length&&se(ke)},[ke]),r.useEffect(()=>{ce.current=J},[J]);const Te=gs(n.agent||"",n.sessionId),Me=r.useRef(Te);Me.current=Te,r.useEffect(()=>{const o=Xe.get(Te);return o&&(Xe.delete(Te),o.text&&H(o.text),o.files.length&&oe(o.files.map(Tt))),()=>{const f=me.current?.value||"",w=ce.current.map(E=>E.file);for(const E of ce.current)URL.revokeObjectURL(E.previewUrl);f||w.length?Xe.set(Me.current,{text:f,files:w}):Xe.delete(Me.current)}},[Te]),r.useEffect(()=>{Ie(""),ye(""),re(""),Ne(null),G(null),I(null),R("closed")},[n.agent,n.sessionId]),r.useEffect(()=>{_!=null&&(H(_),P?.(),requestAnimationFrame(()=>{const o=me.current;o&&(o.focus(),o.setSelectionRange(_.length,_.length))}))},[_,P]),r.useEffect(()=>{if(!s)return;let o=!1;return X.getSkills(s).then(f=>{!o&&f.ok&&nt(f.skills)}).catch(()=>{}),()=>{o=!0}},[s]);const Ge=Y?(()=>{const o=B.match(/^\/(\S*)$/);return o?o[1].toLowerCase():null})():null,de=Ge!==null?_e.filter(o=>o.name.toLowerCase().includes(Ge)||o.label&&o.label.toLowerCase().includes(Ge)):[];r.useEffect(()=>{Pe(0)},[Y,B]),r.useEffect(()=>{if(!Y||!Oe.current)return;const o=Oe.current.querySelector(`[data-skill-idx="${Be}"]`);o&&o.scrollIntoView({block:"nearest"})},[Be,Y]),r.useEffect(()=>{if(!Y)return;const o=f=>{Oe.current?.contains(f.target)||me.current?.contains(f.target)||We(!1)};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[Y]),r.useEffect(()=>{if(W==="closed")return;const o=f=>{const w=f.target;Z.current?.contains(w)||document.getElementById("cascade-portal")?.contains(w)||(R("closed"),Ne(null),G(null),I(null))};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[W]),r.useLayoutEffect(()=>{if(W==="closed"||!Z.current){et(null);return}const o=Z.current.getBoundingClientRect();et({left:o.left,bottom:window.innerHeight-o.top+8})},[W]);const rt=m&&m.length?m[0]:null;r.useEffect(()=>{C&&(rt||p!==null&&p!=="queued")&&V(null)},[p,C,rt]),r.useEffect(()=>{const o=me.current;o&&(o.style.height="auto",o.style.height=Math.min(o.scrollHeight,200)+"px")},[B]);const $e=r.useCallback(o=>{const f=Array.from(o||[]).filter(w=>w.type.startsWith("image/"));f.length&&oe(w=>[...w,...f.map(Tt)])},[]),ot=r.useCallback(()=>{pe(null),oe(o=>(ds(o),[]))},[]),it=r.useCallback(o=>{oe(f=>{const w=f.find(E=>E.id===o);return w&&URL.revokeObjectURL(w.previewUrl),f.filter(E=>E.id!==o)}),pe(f=>f===o?null:f)},[]),lt=r.useCallback(()=>{const o=B.trim(),f=J.map(z=>z.file);if(!o&&f.length===0||$)return;const w=fe||n.agent||D.find(z=>z.isDefault)?.agent||"";if(!w)return;const E=D.find(z=>z.agent===w)||null,q=(Re||E?.selectedModel||"").trim()||null,kt=w==="gemini"?null:(He||E?.selectedEffort||"").trim()||null,yt=w!==n.agent,En=yt?"":n.sessionId,Ln=yt&&n.agent?n.agent:null,An=yt&&n.sessionId?n.sessionId:null;T(!0),xe.current={prompt:o,files:f},H(""),Xe.delete(Me.current);const In=f.length?f.map(z=>URL.createObjectURL(z)):void 0;ot(),a(o,In),l(),X.sendSessionMessage(s,w,En,o,{attachments:f,model:q,effort:kt,previousAgent:Ln,previousSessionId:An}).then(z=>{if(z.taskId&&(V(z.taskId),c?.(z.taskId)),!z.ok)return;const qe=typeof z.sessionKey=="string"?ps(z.sessionKey):null;qe&&(qe.agent!==n.agent||qe.sessionId!==n.sessionId)&&qe&&h?.({...qe,workdir:s})}).catch(()=>{}).finally(()=>T(!1))},[D,ot,J,B,a,c,h,l,fe,He,Re,$,n.agent,n.sessionId,s]),at=p==="streaming",ee=(()=>{const o=[];return m&&m.length&&o.push(...m),p==="queued"&&g&&!o.includes(g)&&o.unshift(g),C&&!o.includes(C)&&(p==="queued"||!p)&&o.push(C),o})(),i=ee[ee.length-1]||null,u=ee.length>0,x=u||at;r.useEffect(()=>{const o=f=>ee.includes(f)||f===g;Ae(f=>{let w=!1;const E=new Set;for(const q of f)o(q)?E.add(q):w=!0;return w?E:f}),he(f=>{let w=!1;const E=new Set;for(const q of f)o(q)?E.add(q):w=!0;return w?E:f})},[ee,g]),r.useEffect(()=>{!u&&xe.current.files.length&&(xe.current={prompt:"",files:[]})},[u]);const b=r.useCallback(o=>{if(!ne.has(o)){if(Ae(f=>{const w=new Set(f);return w.add(o),w}),o===i){const f=xe.current;f.prompt&&H(f.prompt),f.files.length&&oe(f.files.map(Tt)),xe.current={prompt:"",files:[]}}j?.(o),o===C&&V(null)}},[ne,i,C,j]),[N,v]=r.useState(!1),S=r.useCallback(async()=>{if(!(N||!A)){v(!0);try{await A()}finally{v(!1)}}},[N,A]),U=r.useCallback(o=>{we.has(o)||(he(f=>{const w=new Set(f);return w.add(o),w}),L?.(o),o===C&&V(null))},[we,C,L]),F=r.useCallback(o=>{H(`/${o.name} `),We(!1),requestAnimationFrame(()=>{const f=me.current;f&&(f.focus(),f.setSelectionRange(f.value.length,f.value.length))})},[]),Q=r.useCallback(o=>{H(o);const f=/^\/\S*$/.test(o)&&_e.length>0;We(f)},[_e.length]),Qe=o=>{if(Y&&de.length>0){if(o.key==="ArrowDown"){o.preventDefault(),Pe(f=>(f+1)%de.length);return}if(o.key==="ArrowUp"){o.preventDefault(),Pe(f=>(f-1+de.length)%de.length);return}if(o.key==="Tab"||o.key==="Enter"&&!o.shiftKey&&!ae.current){o.preventDefault(),F(de[Be]);return}if(o.key==="Escape"){o.preventDefault(),We(!1);return}}o.key==="Enter"&&!o.shiftKey&&!ae.current&&(o.preventDefault(),lt())},yn=r.useCallback(o=>{const f=Array.from(o.clipboardData?.items||[]).filter(w=>w.kind==="file"&&w.type.startsWith("image/")).map(w=>w.getAsFile()).filter(w=>!!w);f.length&&(o.preventDefault(),$e(f))},[$e]),be=fe||n.agent||D.find(o=>o.isDefault)?.agent||D.find(o=>o.installed)?.agent||D[0]?.agent||"",bt=D.find(o=>o.agent===be)||null,Ht=ge||be,De=D.find(o=>o.agent===Ht)||bt,Vt=De?.byokProviderName&&De.byokModels?.length?De.byokModels:De?.models||[],ct=Re||bt?.selectedModel||"",Gt=be==="gemini"?"":He||bt?.selectedEffort||"",Nn=Nt[Ht]||[],Sn=ie&&J.find(o=>o.id===ie)||null,Qt=(!!B.trim()||J.length>0)&&!$&&!!be,vt=()=>{Ne(null),G(null),I(null)},jt=r.useCallback((o,f,w)=>{const E=o==="gemini"?"":w||"";Ie(o),ye(f),re(E),vt(),R("closed")},[]),Cn=()=>{W==="closed"?(vt(),st(),R("agent")):(vt(),R("closed"))},qt=ge||be,Tn=Lt(qt),Xt=Se??ct,wt=le??Gt,Mn=Xt?Wt(Xt):"",Yt=[Tn.shortLabel,Mn||null,wt?wt.charAt(0).toUpperCase()+wt.slice(1):null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:Ce,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[x&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[at&&e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-primary/20 bg-primary/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx(te,{className:"h-3 w-3 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-[12px] font-medium text-fg-3 truncate",children:d("hub.running")}),e.jsxs("button",{onClick:S,disabled:N,title:d("hub.stopHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none shrink-0",children:[N?e.jsx(te,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),d("hub.stop")]})]}),ee.map((o,f)=>{const w=f===ee.length-1,E=ee.length>1?`${d("hub.queued")} #${f+1}`:d("hub.queued"),q=k?.find(kt=>kt.taskId===o)?.prompt||(w?y:null);return e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-warn/25 bg-warn/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-warn animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-warn shrink-0",children:E}),q&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:q})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>U(o),disabled:we.has(o),title:d("hub.steerHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-blue-400 hover:bg-blue-400/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[we.has(o)?e.jsx(te,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),d("hub.steer")]}),e.jsxs("button",{onClick:()=>b(o),disabled:ne.has(o),title:d("hub.recallHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[ne.has(o)?e.jsx(te,{className:"h-2.5 w-2.5"}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]}),d("hub.recall")]})]})]},o)})]}),e.jsxs("div",{className:"relative rounded-xl border border-edge/40 bg-panel shadow-sm transition-[border-color,box-shadow] duration-200 focus-within:border-fg-5/40 focus-within:shadow-md",children:[e.jsx("input",{ref:tt,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:o=>{$e(o.target.files),o.target.value=""}}),J.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:J.map(o=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>pe(o.id),title:d("hub.previewImage"),className:"group relative h-[72px] w-[72px] overflow-hidden rounded-lg border border-edge/30 bg-panel-alt/30",children:[e.jsx("img",{src:o.previewUrl,alt:o.file.name,className:"h-full w-full object-cover transition-transform duration-200 group-hover:scale-[1.03]"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent px-1.5 pb-1 pt-3 text-left",children:e.jsx("div",{className:"truncate text-[8px] font-medium text-white/90 leading-tight",children:o.file.name})})]}),e.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),it(o.id)},title:d("hub.removeImage"),className:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-black/65 text-white/75 transition-colors hover:bg-black/80 hover:text-white",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]},o.id))})}),Y&&de.length>0&&e.jsxs("div",{ref:Oe,className:"absolute bottom-full left-0 right-0 mb-1.5 z-50 max-h-[200px] overflow-y-auto rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg animate-in",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-edge/20",children:e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d("hub.skills")})}),e.jsx("div",{className:"py-1",children:de.map((o,f)=>e.jsxs("button",{"data-skill-idx":f,onMouseDown:w=>{w.preventDefault(),F(o)},onMouseEnter:()=>Pe(f),className:M("flex flex-col w-full px-3 py-1.5 text-left transition-colors",f===Be?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",o.name]}),(o.label||o.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:o.label||o.description})]},o.name))})]}),e.jsx("textarea",{ref:me,value:B,onChange:o=>Q(o.target.value),onPaste:yn,onKeyDown:Qe,onCompositionStart:()=>{ae.current=!0},onCompositionEnd:()=>{ae.current=!1},placeholder:d("hub.inputPlaceholder"),rows:1,className:"w-full resize-none bg-transparent px-4 pt-3 pb-1 text-[13.5px] text-fg outline-none placeholder:text-fg-5/25 leading-[1.6]",style:{maxHeight:200,overflow:B.split(`
9
+ `).length>6?"auto":"hidden"}}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>tt.current?.click(),title:d("hub.addImages"),className:"flex h-7 w-7 items-center justify-center rounded-lg text-fg-5/50 transition-colors hover:bg-panel-h/60 hover:text-fg-3",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})}),e.jsxs("button",{ref:Z,onClick:Cn,disabled:!D.length,title:D.length?Yt:void 0,className:M("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",W!=="closed"?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[D.length?e.jsx(Je,{brand:qt,size:12}):e.jsx(te,{className:"h-3 w-3"}),e.jsx("span",{className:"max-w-[420px] truncate",children:D.length?Yt:d("hub.selectAgent")}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:M("text-fg-5/30 transition-transform duration-200",W!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),W!=="closed"&&Ve&&Pt.createPortal(e.jsxs("div",{id:"cascade-portal",className:"fixed z-[200] w-[300px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in",style:{left:Ve.left,bottom:Ve.bottom},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5 border-b border-edge/20",children:[W!=="agent"&&e.jsx("button",{onClick:()=>{if(W==="effort"){const o=De?.capabilities?.modelSwitch!==!1;R(o?"model":"agent")}else R("agent")},className:"p-0.5 rounded text-fg-5/50 hover:text-fg-3 transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d(W==="agent"?"hub.selectAgent":W==="model"?"hub.selectModel":"hub.selectEffort")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const f=De?.capabilities?.modelSwitch!==!1?["agent","model","effort"]:["agent","effort"],w=f.indexOf(W);return f.map((E,q)=>e.jsx("span",{className:M("w-1.5 h-1.5 rounded-full transition-colors",W===E?"bg-primary":q<w?"bg-primary/40":"bg-fg-5/15")},E))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[W==="agent"&&D.filter(o=>o.installed).map(o=>{const f=Lt(o.agent);return e.jsxs(Mt,{selected:o.agent===(ge||be),onClick:()=>{if(Ne(o.agent),G(o.selectedModel||""),I(o.selectedEffort||""),!(o.capabilities?.modelSwitch!==!1)){(Nt[o.agent]||[]).length?R("effort"):jt(o.agent,o.selectedModel||"",null);return}R("model")},children:[e.jsx(Je,{brand:o.agent,size:14}),e.jsx("span",{style:{color:f.color},children:f.label})]},o.agent)}),W==="model"&&e.jsxs(e.Fragment,{children:[Vt.map(o=>e.jsx(Mt,{selected:o.id===(Se??ct)||o.alias===(Se??ct),onClick:()=>{const f=ge||be;if(G(o.id),Nt[f]?.length){R("effort");return}jt(f,o.id,null)},children:e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[11px]",title:o.id,children:o.id})},o.id)),Vt.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]}),W==="effort"&&Nn.map(o=>e.jsx(Mt,{selected:o===(le||Gt),onClick:()=>{I(o),jt(ge||be,Se??ct,o)},children:o.charAt(0).toUpperCase()+o.slice(1)},o))]})]}),document.body),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:lt,disabled:!Qt,className:M("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",Qt?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:$?e.jsx(te,{className:"h-3.5 w-3.5"}):e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})]}),e.jsx(bs,{attachment:Sn,onClose:()=>pe(null),onRemove:it,t:d})]})});function bs({attachment:t,onClose:n,onRemove:s,t:l}){const[a,c]=r.useState(!1);return r.useEffect(()=>{c(!1)},[t?.id]),r.useEffect(()=>{if(!t)return;const h=d=>{d.key==="Escape"&&n()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[t,n]),t?Pt.createPortal(e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center bg-black/72 px-4 py-6 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[1024px]",onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-[11px] text-white/72",children:[e.jsx("span",{className:"truncate font-medium text-white/90",children:t.file.name}),e.jsx("span",{children:us(t.file.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:async()=>{await hs(t.file)&&(c(!0),window.setTimeout(()=>c(!1),1600))},className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:l(a?"hub.copied":"hub.copyImage")}),e.jsx("button",{type:"button",onClick:()=>s(t.id),className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:l("hub.removeImage")}),e.jsx("button",{type:"button",onClick:n,className:"flex h-9 w-9 items-center justify-center rounded-full border border-white/12 bg-white/10 text-white/88 transition-colors hover:bg-white/14",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-white/10 bg-black/35 shadow-[0_20px_70px_rgba(0,0,0,0.45)]",children:e.jsx("img",{src:t.previewUrl,alt:t.file.name,className:"max-h-[80vh] w-full object-contain"})})]})}),document.body):null}function Mt({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:M("flex items-center gap-2 w-full px-3 py-2 text-[12px] text-left transition-colors",t?"text-fg bg-panel-h font-medium":"text-fg-3 hover:bg-panel-alt/50 hover:text-fg-2"),children:[s,t&&e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"ml-auto text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),!t&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"ml-auto text-fg-5/20",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})})]})}function vs(){return function(t){Fn(t)}}const zt=[Un,vs],js=t=>/^https?:\/\//.test(t),en=t=>/^(\/|~\/|\.\.?\/)/.test(t);function ws({text:t}){const[n,s]=r.useState(!1),l=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:l,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function tn(t){const n=/^[.~/].*\.\w+$/.test(t)||/^[a-z][\w-]*\//.test(t),s=/^(npm |npx |git |python|pip |yarn |pnpm |cargo |go |make )/.test(t);return n?"bg-blue-500/8 border-blue-400/12 text-blue-300/90":s?"bg-amber-500/8 border-amber-400/10 text-amber-300/80":"bg-[rgba(255,255,255,0.06)] border-edge/20 text-fg-3"}const Kt={h1:({children:t})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:t}),h2:({children:t})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:t}),h3:({children:t})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:t}),p:({children:t})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:t}),strong:({children:t})=>e.jsx("strong",{className:"font-semibold text-fg",children:t}),em:({children:t})=>e.jsx("em",{className:"italic text-fg-3",children:t}),a:({href:t,children:n})=>t&&js(t)?e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",children:n}):t&&en(t)?e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",onClick:()=>X.openInEditor(t),children:n}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:n}),ul:({children:t})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:t}),ol:({children:t})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:t}),li:({children:t})=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"shrink-0 mt-[10px] w-[5px] h-[5px] rounded-full bg-fg-5/40"}),e.jsx("span",{className:"flex-1",children:t})]}),blockquote:({children:t})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:t}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:t,children:n,...s})=>{const l=String(n).replace(/\n$/,""),a=/language-(\w+)/.exec(t||"");if(!a&&!t&&!l.includes(`
10
+ `))return en(l)?e.jsx("code",{className:M("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",tn(l)),onClick:()=>X.openInEditor(l),children:l}):e.jsx("code",{className:M("px-1.5 py-[1px] rounded text-[12px] font-mono border",tn(l)),children:l});const c=a?.[1]||"";return e.jsxs("div",{className:"rounded-lg overflow-hidden border border-edge/30 bg-[rgba(0,0,0,0.25)] my-3 not-prose",children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-1.5 border-b border-edge/15 bg-[rgba(0,0,0,0.12)]",children:[e.jsx("span",{className:"text-[10px] font-mono text-fg-5/50",children:c||"text"}),e.jsx(ws,{text:l})]}),e.jsx("pre",{className:"px-3.5 py-3 text-[12px] leading-[1.65] text-fg-3 font-mono whitespace-pre-wrap break-words overflow-x-auto",children:e.jsx("code",{children:l})})]})},pre:({children:t})=>e.jsx(e.Fragment,{children:t}),table:({children:t})=>e.jsx("div",{className:"my-3 overflow-x-auto rounded-lg border border-edge/30",children:e.jsx("table",{className:"w-full text-[12.5px]",children:t})}),thead:({children:t})=>e.jsx("thead",{className:"bg-[rgba(0,0,0,0.1)]",children:t}),th:({children:t})=>e.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-fg-3 border-b border-edge/30",children:t}),td:({children:t})=>e.jsx("td",{className:"px-3 py-1.5 text-fg-4 border-t border-edge/12",children:t}),tr:({children:t})=>e.jsx("tr",{className:"even:bg-[rgba(255,255,255,0.015)]",children:t})};function mt(t){return!!t?.steps?.length}function ks(t,n){let s=t;for(const[l,a]of Object.entries(n))s=s.replace(new RegExp(`\\{${l}\\}`,"g"),a);return s}function ys({status:t}){return t==="completed"?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):t==="inProgress"?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-400 animate-pulse"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/25"})}function gn({plan:t,t:n,className:s}){const[l,a]=r.useState(!1);if(!mt(t))return null;const c=t.steps.length,h=t.steps.filter(g=>g.status==="completed").length,d=c>0&&h===c,p=ks(n("hub.planProgress"),{done:String(h),total:String(c)});return e.jsx(Ke,{open:l,onToggle:()=>a(g=>!g),dot:{color:d?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!d},label:p,preview:t.explanation?e.jsx("span",{className:"text-[11.5px] text-fg-4 truncate",children:t.explanation}):void 0,badge:e.jsx("span",{className:M("rounded-md border px-1.5 py-0.5 text-[10px] font-mono",d?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(d?"hub.planDone":"hub.planInProgress")}),className:s,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-1",children:t.steps.map((g,m)=>{const k=g.status==="completed"?"text-fg-5 line-through decoration-fg-5/40":g.status==="inProgress"?"text-fg-3":"text-fg-4";return e.jsxs("div",{className:"flex items-center gap-2 py-[2px]",children:[e.jsx("span",{className:"shrink-0 flex items-center justify-center w-[10px]",children:e.jsx(ys,{status:g.status})}),e.jsx("span",{className:M("text-[12px] leading-[1.5]",k),children:g.step})]},`${m}:${g.step}`)})})})}function pr({stream:t,t:n}){const s=mt(t.plan),[l,a]=r.useState(!1),[c,h]=r.useState(!1),d=r.useRef(null),p=r.useRef(null),g=r.useMemo(()=>(t.activity||"").split(`
11
+ `).filter(Boolean),[t.activity]),m=g[g.length-1]||"";r.useLayoutEffect(()=>{const y=d.current;y&&l&&(y.scrollTop=y.scrollHeight)},[l,t.activity]),r.useLayoutEffect(()=>{const y=p.current;y&&c&&(y.scrollTop=y.scrollHeight)},[c,t.thinking]);const k=t.subAgents??null;return e.jsxs("div",{className:"space-y-3 animate-in",children:[s&&e.jsx(gn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),k&&k.length>0&&k.map(y=>e.jsx(mn,{sub:y,t:n},y.id)),g.length>0&&e.jsx(Ke,{open:l,onToggle:()=>a(y=>!y),dot:{color:"bg-cyan-400/60",pulse:!0},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[12px] text-fg-4 truncate",children:m}),badge:g.length>1?e.jsx(Bt,{children:g.length}):void 0,children:e.jsx("div",{ref:d,className:"px-3.5 py-2.5 space-y-0.5 max-h-[240px] overflow-y-auto",children:g.map((y,j)=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate",children:y})]},j))})}),t.thinking&&e.jsx(Ke,{open:c,onToggle:()=>h(y=>!y),dot:{color:"bg-violet-400/50",pulse:!0},label:n("hub.thinking"),collapsedContent:e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:fn(t.thinking,3)}),children:e.jsx("div",{ref:p,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[280px] overflow-y-auto",children:t.thinking})}),t.text&&e.jsxs("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:[e.jsx(Dt,{remarkPlugins:zt,components:Kt,children:t.text}),t.phase==="streaming"&&e.jsx(It,{className:"ml-1 inline-flex align-text-bottom text-fg-4"})]}),!t.text&&t.phase==="streaming"&&e.jsx("div",{className:"py-1",children:e.jsx(It,{className:"text-fg-5"})})]})}function It({className:t}){return e.jsxs("span",{className:`thinking-dots inline-flex items-center gap-[3px] ${t||""}`,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}function mn({sub:t,t:n}){const[s,l]=r.useState(!1),a=t.status,c=a==="failed"?"bg-rose-400/60":a==="done"?"bg-emerald-400/55":"bg-amber-400/60",h=a==="running",d=t.tools,p=r.useMemo(()=>{const k=new Set,y=[];for(const j of d)k.has(j.name)||(k.add(j.name),y.push(j.name));return y},[d]),g=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",m=t.model?Wt(t.model):null;return e.jsx(Ke,{open:s,onToggle:()=>l(k=>!k),dot:{color:c,pulse:h},label:g,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),m&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:m}),!t.description&&p.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:p.join(" · ")})]}),badge:d.length>0?e.jsx(Bt,{children:d.length}):void 0,children:e.jsxs("div",{className:"px-3.5 py-2.5 space-y-1 max-h-[260px] overflow-y-auto",children:[t.description&&e.jsx("div",{className:"mb-1.5 text-[12px] text-fg-3 leading-[1.55]",children:t.description}),d.length===0?e.jsxs("div",{className:"text-[11px] font-mono text-fg-5/50",children:["— ",n("hub.subAgentWaiting")||"waiting for first tool…"]}):d.map(k=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/65 truncate",children:k.summary})]},k.id))]})})}function Ns({message:t,t:n}){const{activityBlocks:s,thinkingBlocks:l,planBlocks:a,subAgentBlocks:c,outputBlocks:h}=Ss(t.blocks),d=[...a].reverse().find(p=>mt(p.plan));return e.jsxs("div",{className:"space-y-3",children:[s.length>0&&e.jsx(Cs,{blocks:s,t:n}),c.map(p=>p.subAgent?e.jsx(mn,{sub:p.subAgent,t:n},p.toolId||p.subAgent.id):null),d?.plan&&e.jsx(gn,{plan:d.plan,t:n,className:"max-w-[760px]"}),l.length>0&&e.jsx(Ms,{blocks:l,t:n}),h.length>0&&e.jsx(Ls,{blocks:h})]})}function Ss(t){const n=t.filter(s=>s.type==="plan"||s.type==="tool_use"||s.type==="tool_result"||s.type==="image"||s.type==="sub_agent"||!!s.content.trim());return{activityBlocks:n.filter(s=>s.type==="tool_use"||s.type==="tool_result"),thinkingBlocks:n.filter(s=>s.type==="thinking"),planBlocks:n.filter(s=>s.type==="plan"&&mt(s.plan)),subAgentBlocks:n.filter(s=>s.type==="sub_agent"),outputBlocks:n.filter(s=>s.type==="text"||s.type==="image")}}function Cs({blocks:t,t:n}){const[s,l]=r.useState(!1),a=t.filter(p=>p.type==="tool_use"),c=a.length,h=a[a.length-1],d=h?pn(h):"";return e.jsx(Ke,{open:s,onToggle:()=>l(p=>!p),dot:{color:"bg-cyan-400/60"},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[11.5px] font-mono text-fg-4 truncate",children:d}),badge:c>0?e.jsx(Bt,{children:c}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((p,g)=>e.jsx(Ts,{block:p},g))})})}function Ts({block:t}){const[n,s]=r.useState(!1),l=t.type==="tool_use",a=l?pn(t):fs(t);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&s(c=>!c),className:M("flex items-center gap-2 py-[3px] w-full text-left group rounded-sm transition-colors",t.content&&"hover:bg-panel-h/30"),children:[e.jsx("span",{className:M("h-1.5 w-1.5 rounded-full shrink-0",l?"bg-fg-5/40":"bg-ok/40")}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 group-hover:text-fg-3 transition-colors truncate",children:a})]}),n&&t.content&&e.jsx("pre",{className:"ml-3 mt-1 mb-2 p-3 rounded-md bg-inset border border-edge text-[11px] leading-[1.6] text-fg-4 font-mono whitespace-pre-wrap break-words max-h-[240px] overflow-y-auto",children:t.content.length>3e3?t.content.slice(0,3e3)+`
12
+ …`:t.content})]})}function Ms({blocks:t,t:n}){const[s,l]=r.useState(!1),a=r.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
13
+
14
+ `).trim();if(!c)return null;const h=fn(c,3);return e.jsx(Ke,{open:s,onToggle:()=>l(d=>!d),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:h?e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:h}):void 0,children:e.jsx(Es,{scrollRef:a,text:c})})}function Es({scrollRef:t,text:n}){return r.useLayoutEffect(()=>{const s=t.current;s&&(s.scrollTop=s.scrollHeight)},[t]),e.jsx("div",{ref:t,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[320px] overflow-y-auto",children:n})}function Ls({blocks:t}){const n=t.filter(h=>h.type==="text"),s=t.filter(h=>h.type==="image"),l=n.map(h=>h.content).filter(Boolean).join(`
15
+
16
+ `),[a,c]=r.useState(null);return!l.trim()&&s.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(Dt,{remarkPlugins:zt,components:Kt,children:l})}),s.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:s.map((h,d)=>e.jsx("img",{src:h.content,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>c(h.content)},d))}),a&&e.jsx(bn,{src:a,onClose:()=>c(null)})]})}const gr=r.memo(function({turn:n,turnIndex:s,agent:l,meta:a,model:c,effort:h,providerName:d,t:p,onResend:g,onEdit:m,onFork:k}){const y=n.user&&xn(n.user.text),j=k&&typeof s=="number"?()=>k(s):void 0;return e.jsxs("div",{className:"session-turn",children:[n.user&&!y&&e.jsx(vn,{text:n.user.text,blocks:n.user.blocks,t:p,onResend:g,onEdit:m,onFork:j}),y&&n.user&&!n.assistant&&e.jsx("div",{className:"mb-4 px-4 py-3 rounded-lg bg-[rgba(255,255,255,0.02)] border border-edge/20 text-[12.5px] leading-[1.7] text-fg-4",children:e.jsx(Dt,{remarkPlugins:zt,components:Kt,children:n.user.text})}),n.assistant&&e.jsx(_s,{agent:l,meta:a,model:c,effort:h,providerName:d,previewMeta:n.assistant.usage??null}),n.assistant&&e.jsx("div",{className:"mb-6",children:e.jsx(Ns,{message:n.assistant,t:p})})]})});function bn({src:t,onClose:n}){return r.useEffect(()=>{const s=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),Pt.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 As=1500,Is=16,nn=8;function Rs(t){const n=t.split(`
17
+ `);return n.length<=nn?t:n.slice(0,nn).join(`
18
+ `)}function vn({text:t,blocks:n,t:s,onResend:l,onEdit:a,onFork:c}){const[h,d]=r.useState(!1),[p,g]=r.useState(!1),[m,k]=r.useState(null),y=t?t.split(`
19
+ `).length:0,j=!!t&&(t.length>As||y>Is),[L,A]=r.useState(!1),_=t?j&&!L?Rs(t):t:"",P=!!(l||a||c),B=n?.filter(T=>T.type==="image")||[],H=()=>{navigator.clipboard.writeText(t).then(()=>{g(!0),setTimeout(()=>g(!1),1500)}).catch(()=>{})},$=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(y));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[_,j&&!L&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),j&&e.jsx("button",{type:"button",onClick:()=>A(T=>!T),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:L?s("hub.collapse"):$}),B.length>0&&e.jsx("div",{className:M("flex flex-wrap gap-2",t&&"mt-2"),children:B.map((T,C)=>e.jsx("img",{src:T.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:()=>k(T.content)},C))})]}),m&&e.jsx(bn,{src:m,onClose:()=>k(null)}),P&&e.jsxs("div",{className:M("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",h?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(ut,{label:s(p?"hub.copied":"hub.copy"),onClick:H,children:p?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"})]})}),l&&e.jsx(ut,{label:s("hub.rerun"),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("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),a&&e.jsx(ut,{label:s("hub.edit"),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("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),c&&e.jsx(ut,{label:s("hub.fork"),onClick:c,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]})})]})]})}function ut({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 _s({agent:t,meta:n,model:s,effort:l,providerName:a,previewMeta:c}){const h=c?.contextPercent??null,d=c?.contextUsedTokens??0,p=h!=null||d>0,g=c?.providerName??a??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(Je,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||l)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&l?" · ":"",l||""]}),g&&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 ${g} (BYOK), not the agent CLI's native auth.`,children:["via ",g]}),p&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:Bs(c),children:[h!=null&&e.jsx(Ps,{pct:h}),e.jsx("span",{children:h!=null?`${h.toFixed(1)}%`:""}),d>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",Ws(d)]})]})]})}function Ws(t){return t>=1e6?`${(t/1e6).toFixed(1)}M tok`:t>=1e3?`${(t/1e3).toFixed(1)}k tok`:`${t} tok`}function Bs(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.outputTokens!=null&&n.push(`Output: ${t.outputTokens.toLocaleString()}`),t.cachedInputTokens!=null&&n.push(`Cached: ${t.cachedInputTokens.toLocaleString()}`),n.join(" · ")}function Ps({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 sn(t,n,s){return t==="zh-CN"?n:s}function Os({open:t,onClose:n,workdir:s}){const l=ve(c=>c.locale),a=s.split("/").pop()||s;return e.jsxs(Ot,{open:t,onClose:n,wide:!0,children:[e.jsx($t,{title:sn(l,`${a} — 项目扩展`,`${a} — Project Extensions`),description:sn(l,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiclaw/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiclaw/skills/ in the workspace directory."),onClose:n}),t?e.jsx(zn,{workdir:s}):null]})}let rn=ln(()=>import("./SessionPanel-D2kHNUr3.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));function Rt(){return rn??=ln(()=>import("./SessionPanel-D2kHNUr3.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),rn}const $s=r.lazy(async()=>({default:(await Rt()).SessionPanel})),Et=5,Ds=240,Fs=120,Us=12,zs=900*1e3,O=(t,n)=>`${t}:${n}`;function Ks(t){const n=new Map;for(const d of t)n.set(O(d.agent||"",d.sessionId),d);const s=new Map,l=new Set;for(const d of t){const p=d.migratedFrom;if(!p||p.kind!=="fork"||!p.sessionId)continue;const g=O(p.agent||d.agent||"",p.sessionId);n.has(g)&&(l.add(O(d.agent||"",d.sessionId)),s.has(g)||s.set(g,[]),s.get(g).push(d))}const a=[],c=new Set,h=(d,p)=>{const g=O(d.agent||"",d.sessionId);if(c.has(g))return;c.add(g),a.push(Object.assign({},d,{__forkDepth:p}));const m=s.get(g);if(m)for(const k of m)h(k,p+1)};for(const d of t){const p=O(d.agent||"",d.sessionId);l.has(p)||h(d,0)}for(const d of t)h(d,0);return a}let Hs=0;function ht(){return`mk-${Date.now().toString(36)}-${(++Hs).toString(36)}`}function Vs(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Gs(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function jn(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 Qs=r.memo(function({active:n=!0}){const s=ve(i=>i.locale),l=ve(i=>i.state?.runtimeWorkdir??null),a=r.useMemo(()=>Rn(s),[s]),[c,h]=r.useState([]),[d,p]=r.useState({}),[g,m]=r.useState({}),[k,y]=r.useState(!0),[j,L]=r.useState(()=>{try{const u=sessionStorage.getItem("pikiclaw-layout-mode");if(u==="1"||u==="2"||u==="3"||u==="6")return Number(u)}catch{}const i=window.innerWidth;return i>=1920?3:i>=1280?2:1}),[A,_]=r.useState(()=>{try{const i=sessionStorage.getItem("pikiclaw-open-sessions");if(i){const u=JSON.parse(i);if(Array.isArray(u))return u.map(x=>({...x,mountKey:x.mountKey||ht()}))}}catch{}return[]}),[P,B]=r.useState(()=>{try{const i=sessionStorage.getItem("pikiclaw-active-slot");if(i!=null){const u=Number(i);if(Number.isFinite(u)&&u>=0)return u}}catch{}return 0}),H=r.useCallback(i=>{L(i);try{sessionStorage.setItem("pikiclaw-layout-mode",String(i))}catch{}},[]),$=r.useCallback(i=>{_(u=>{const x=typeof i=="function"?i(u):i;try{sessionStorage.setItem("pikiclaw-open-sessions",JSON.stringify(x))}catch{}return x})},[]),T=r.useCallback(i=>{B(u=>{const x=typeof i=="function"?i(u):i;try{sessionStorage.setItem("pikiclaw-active-slot",String(x))}catch{}return x})},[]);r.useEffect(()=>{$(i=>i.length>j?i.slice(0,j):i),T(i=>i>=j?j-1:i)},[j]);const[C,V]=r.useState(!1),ne=r.useRef(j);ne.current=j;const Ae=r.useRef(P);Ae.current=P;const we=r.useRef(-1),he=A[P]??null,xe=r.useCallback(i=>{if(!i){$([]),T(0);return}const u=i.mountKey?i:{...i,mountKey:ht()};$(x=>{const b=x.findIndex(v=>v.agent===u.agent&&v.sessionId===u.sessionId);if(b>=0)return T(b),x;if(x.length<ne.current){const v=[...x,u];return T(v.length-1),v}const N=[...x];return N[Ae.current]=u,N})},[]),[ke,D]=r.useState(!1),[se,fe]=r.useState(null),[Ie,Re]=r.useState(""),[ye,He]=r.useState("all"),[re,J]=r.useState({}),oe=r.useDeferredValue(Ie),ie=r.useRef(!1),pe=r.useRef({}),ge=r.useRef(d);ge.current=d;const Ne=r.useRef(re);Ne.current=re;const Se=r.useRef(new Set),G=r.useRef({});r.useEffect(()=>()=>{for(const i of Object.values(G.current))clearTimeout(i)},[]);const le=r.useCallback(async()=>{try{const i=await X.getWorkspaces(),u=i.ok?i.workspaces:[];u.length&&h(u),ie.current=!0}catch{ie.current=!0}finally{y(!1)}},[]);r.useEffect(()=>{le()},[le]);const I=r.useCallback(async(i,u={})=>{if(!pe.current[i]){pe.current[i]=!0,u.background||m(x=>({...x,[i]:!0}));try{const x=await Qn(i,{force:u.force});r.startTransition(()=>{p(b=>{const N=x.sessions||[],v=b[i]||[],S=new Set(N.map(F=>O(F.agent||"",F.sessionId))),U=v.filter(F=>{if(F.runState!=="running")return!1;const Q=O(F.agent||"",F.sessionId);if(S.has(Q))return!1;const Qe=Ne.current[Q];return!(Qe?.resolvedKey&&Qe.resolvedKey!==Q)});return{...b,[i]:U.length?[...U,...N]:N}})})}catch{u.background||r.startTransition(()=>{p(x=>({...x,[i]:[]}))})}finally{pe.current[i]=!1,u.background||m(x=>({...x,[i]:!1}))}}},[]),W=r.useRef(l);r.useEffect(()=>{l!==W.current&&(W.current=l,!(!l||!ie.current)&&le().then(()=>{I(l,{force:!0})}))},[l,le,I]);const R=r.useCallback((i,u)=>{const x=i.agent||"";!x||!i.sessionId||(Rt(),Yn({workdir:u,agent:x,sessionId:i.sessionId,rich:!0,turnOffset:0,turnLimit:Us}))},[]),Ve=r.useCallback((i,u,x=Fs)=>{const b=`${u}:${O(i.agent||"",i.sessionId)}`,N=G.current[b];N&&clearTimeout(N),G.current[b]=setTimeout(()=>{delete G.current[b],R(i,u)},x)},[R]),et=r.useCallback((i,u)=>{const x=`${u}:${O(i.agent||"",i.sessionId)}`,b=G.current[x];b&&(clearTimeout(b),delete G.current[x])},[]);r.useEffect(()=>{n&&Rt()},[n]),r.useEffect(()=>{if(!n)return;const i=[];return c.forEach((u,x)=>{if(d[u.path]||g[u.path])return;const b=setTimeout(()=>{I(u.path)},x*90);i.push(b)}),()=>{for(const u of i)clearTimeout(u)}},[n,I,g,d,c]);const me=r.useRef(new Map);Zt(n&&ie.current&&c.length>0?"sessions-changed":null,r.useCallback(i=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const u=i.key,x=u?c.filter(v=>(ge.current[v.path]||[]).some(S=>O(S.agent||"",S.sessionId)===u)):c,b=x.length?x:c,N=me.current;for(const v of b)N.has(v.path)&&clearTimeout(N.get(v.path)),N.set(v.path,setTimeout(()=>{N.delete(v.path),I(v.path,{background:!0,force:!0})},300))},[c,I]));const ae=r.useCallback(i=>{const u=i.agent||"";return!u||!i.sessionId?i:_n(i,re[O(u,i.sessionId)]||null)},[re]);Zt("stream-update",r.useCallback(i=>{const u=i.key;u&&J(x=>{const b={},N=Date.now()-zs;for(const[S,U]of Object.entries(x))U.updatedAt>=N&&(b[S]=U);const v=Wn(u,i.snapshot??null);if(!v){const S=b[u];return S&&S.phase!=="done"&&(b[u]={...S,phase:"done",updatedAt:Date.now()}),b}return b[u]=v,v.resolvedKey!==u&&(b[v.resolvedKey]={...v,key:v.resolvedKey}),b})},[])),os(r.useCallback(()=>{if(!(!n||!ie.current||c.length===0))for(const i of c)I(i.path,{background:!0,force:!0})},[n,c,I])),r.useEffect(()=>{if(!n||!ie.current||c.length===0)return;const i=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const x of c)I(x.path,{background:!0,force:!0})};if(i(),typeof document>"u"||typeof window>"u")return;const u=()=>{document.visibilityState==="visible"&&i()};return document.addEventListener("visibilitychange",u),window.addEventListener("focus",u),()=>{document.removeEventListener("visibilitychange",u),window.removeEventListener("focus",u)}},[n,I,c]),r.useEffect(()=>{if(!n)return;const i=[];return c.forEach((u,x)=>{const b=(d[u.path]||[])[0];if(!b)return;const N=`${u.path}:${O(b.agent||"",b.sessionId)}`;if(Se.current.has(N))return;const v=setTimeout(()=>{Se.current.add(N),R(b,u.path)},Ds+x*120);i.push(v)}),()=>{for(const u of i)clearTimeout(u)}},[n,d,R,c]);const tt=r.useCallback(async i=>{try{(await X.addWorkspace(i)).ok&&(D(!1),await le(),I(i))}catch{}},[le,I]),[Ce,Z]=r.useState(null),[ce,_e]=r.useState(!1),[nt,Y]=r.useState(null),We=r.useCallback(i=>{Z(i)},[]),Be=r.useCallback(async()=>{const i=Ce;if(i){_e(!0);try{await X.removeWorkspace(i),h(u=>u.filter(x=>x.path!==i)),p(u=>{const x={...u};return delete x[i],x}),$(u=>u.filter(x=>x.workdir!==i)),T(0),Z(null)}catch{}finally{_e(!1)}}},[Ce]),Pe=r.useCallback(i=>{I(i,{force:!0})},[I]),[Oe,st]=r.useState(null),[Te,Me]=r.useState([]),Ge=r.useCallback((i,u,x)=>{R({agent:i.agent,sessionId:i.sessionId,runState:"running"},i.workdir),p(v=>{const S=v[i.workdir]||[];if(S.some(Q=>Q.sessionId===i.sessionId&&Q.agent===i.agent))return v;const F={sessionId:i.sessionId,agent:i.agent,runState:"running",lastQuestion:u,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...v,[i.workdir]:[F,...S]}});const b=we.current,N={...i,mountKey:ht()};r.startTransition(()=>{st(u||null),Me(x&&x.length?x:[]),fe(null),$(v=>{if(b>=v.length)return[...v,N];const S=[...v];return S[b]=N,S}),T(b>=0?b:0)}),I(i.workdir,{background:!0,force:!0})},[I,R]),de=r.useCallback((i,u)=>{R(i,u),fe(null),r.startTransition(()=>{xe({agent:i.agent||"",sessionId:i.sessionId,workdir:u})})},[R]),rt=r.useCallback((i,u)=>{R({agent:i.agent,sessionId:i.sessionId,runState:"running"},i.workdir),r.startTransition(()=>{u!=null?($(x=>{if(u>=x.length)return x;const b=[...x];return b[u]={...x[u],agent:i.agent,sessionId:i.sessionId,workdir:i.workdir},b}),T(u)):xe({...i,mountKey:ht()})}),I(i.workdir,{background:!0,force:!0})},[I,R]),$e=r.useCallback(i=>{let u=i;if(ye==="running"?u=u.filter(x=>xt(x)==="running"):ye==="review"&&(u=u.filter(x=>xt(x)==="incomplete")),oe.trim()){const x=oe.toLowerCase();u=u.filter(b=>(b.lastMessageText||"").toLowerCase().includes(x)||(b.lastQuestion||"").toLowerCase().includes(x)||(b.lastAnswer||"").toLowerCase().includes(x)||(b.title||"").toLowerCase().includes(x)||(b.agent||"").toLowerCase().includes(x))}return u},[oe,ye]),ot=r.useMemo(()=>{const i={};for(const u of c){const x=(d[u.path]||[]).map(ae),b=new Map;for(const v of x){const S=O(v.agent||"",v.sessionId),U=re[S],F=U?.resolvedKey&&U.resolvedKey!==S?U.resolvedKey:S,Q=b.get(F);if(!Q){b.set(F,v);continue}O(Q.agent||"",Q.sessionId)!==F&&S===F&&b.set(F,v)}const N=$e([...b.values()]);i[u.path]=Ks(N)}return i},[c,d,re,$e,ae]),it=r.useCallback(i=>{const u=(d[i.workdir]||[]).find(x=>x.sessionId===i.sessionId&&x.agent===i.agent)??{sessionId:i.sessionId,agent:i.agent,runState:"running"};return ae(u)},[ae,d]),lt=r.useMemo(()=>new Set(A.map(i=>O(i.agent,i.sessionId))),[A]),at=he?O(he.agent,he.sessionId):null,ee=r.useCallback(i=>{$(u=>{const x=u.filter((b,N)=>N!==i);return x.length===0?T(0):Ae.current>=x.length&&T(x.length-1),x})},[]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:Ie,onChange:i=>Re(i.target.value),placeholder:a("hub.search"),className:"w-full rounded-lg border border-edge/40 bg-inset/50 pl-8 pr-7 py-1.5 text-[12px] text-fg outline-none placeholder:text-fg-5/30 focus:border-primary/30 focus:bg-inset focus:shadow-[0_0_0_3px_rgba(99,102,241,0.06)] transition-all duration-200"}),Ie&&e.jsx("button",{onClick:()=>Re(""),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(i=>e.jsx("button",{onClick:()=>He(i),className:M("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",ye===i?"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:a(`hub.filter${i[0].toUpperCase()+i.slice(1)}`)},i))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:k?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(te,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!ke?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:a("hub.noWorkspaces")}):c.map(i=>e.jsx(Ys,{workspace:i,sessions:ot[i.path]||[],loading:!!g[i.path]||!(i.path in d),isActive:i.path===l,selectedKey:at,openSessionKeys:lt,onSelectSession:de,onNewSession:fe,onRefresh:Pe,onRemove:We,onExtensions:Y,onWarmSession:Ve,onCancelWarmSession:et,t:a},i.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(i=>e.jsx("button",{onClick:()=>H(i),className:M("flex-1 flex items-center justify-center p-1.5 rounded transition-all",j===i?"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:a(`hub.layout${i}`),children:i===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"})}):i===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"})]}):i===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"})]})},i))}),e.jsxs(Ue,{variant:"ghost",size:"sm",onClick:()=>D(i=>!i),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"})]}),a("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(${j===6?3:j}, 1fr)`,gridTemplateRows:j===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const i=se?A.length<j?A.length:P:-1;return we.current=i,Array.from({length:j},(u,x)=>{if(se&&x===i)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(Xs,{workdir:se,workspaceName:c.find(S=>S.path===se)?.name||se.split("/").pop()||"",onSessionCreated:Ge,onClose:()=>fe(null),t:a},se)},`new-${se}`);const b=A[x]??null;if(!b)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:a("hub.emptySlot")})]})},`empty-${x}`);const N=it(b),v=x===P;return e.jsxs("div",{className:M("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",v?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:v?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>T(x),children:[e.jsxs("div",{className:M("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",v?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const S=xt(N);return e.jsx(gt,{variant:S==="running"?"ok":S==="incomplete"?"warn":"idle",pulse:S==="running"})})(),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:b.workdir.split("/").pop()||b.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:N.title||N.lastQuestion?.slice(0,60)||b.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:a("hub.created"),children:Bn(N.createdAt)}),N.runUpdatedAt&&e.jsx("span",{title:a("hub.updated"),children:on(N.runUpdatedAt)}),!!N.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"})}),N.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:S=>{S.stopPropagation(),V(U=>!U)},className:M("p-0.5 rounded transition-colors",C?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:a("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:S=>{S.stopPropagation(),ee(x)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:a("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($s,{session:N,workdir:b.workdir,active:n&&v,onSessionChange:S=>rt(S,x),initialPendingPrompt:v?Oe:null,initialPendingImageUrls:v?Te:void 0,onPendingPromptConsumed:v?()=>{st(null),Me([])}:void 0},b.mountKey)})})]},O(b.agent,b.sessionId))})})()})}),C&&he&&e.jsx(Zs,{workdir:he.workdir,onClose:()=>V(!1),t:a}),e.jsx(qs,{open:ke,initialPath:l||void 0,onAdd:tt,onClose:()=>D(!1),t:a}),e.jsxs(Ot,{open:!!Ce,onClose:()=>!ce&&Z(null),children:[e.jsx($t,{title:a("hub.removeWorkspace"),onClose:()=>!ce&&Z(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:a("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:a("modal.confirmRemoveWorkspaceHint")}),Ce&&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:Ce}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ue,{variant:"ghost",onClick:()=>Z(null),disabled:ce,children:a("modal.cancel")}),e.jsx(Ue,{variant:"primary",onClick:Be,disabled:ce,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:a(ce?"modal.removing":"modal.remove")})]})]}),e.jsx(Os,{open:!!nt,onClose:()=>Y(null),workdir:nt||""})]})});function qs({open:t,initialPath:n,onAdd:s,onClose:l,t:a}){const[c,h]=r.useState(""),d=r.useCallback(p=>h(p),[]);return r.useEffect(()=>{t&&h("")},[t]),e.jsxs(Ot,{open:t,onClose:l,children:[e.jsx($t,{title:a("hub.addWorkspace"),onClose:l}),e.jsx(Dn,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:a}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ue,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:a("hub.add")}),e.jsx(Ue,{variant:"secondary",onClick:l,className:"flex-1",children:a("hub.cancel")})]})]})}function Xs({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:a}){const[c,h]=r.useState(null),[d,p]=r.useState([]),g=r.useRef(null),m=r.useRef([]),k=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),y=r.useCallback(()=>{},[]),j=r.useCallback((_,P)=>{h(_||null),g.current=_||null;const B=P||[];p(B),m.current=B},[]),L=r.useCallback(_=>{const P=m.current;m.current=[],s(_,g.current||void 0,P.length?P:void 0)},[s]),A=!!c||d.length>0;return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 h-10 border-b border-edge/50 bg-panel/40 backdrop-blur-md z-10",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[13px] font-medium text-fg truncate",children:a("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(gt,{variant:A?"ok":"idle",pulse:A}),!A&&e.jsx("button",{onClick:l,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:A?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(vn,{text:c||"",blocks:d.map(_=>({type:"image",content:_})),t:a}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(It,{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:a("hub.newSessionHint")})})})}),e.jsx(ms,{session:k,workdir:t,onStreamQueued:y,onSendStart:j,onSessionChange:L,t:a,streamPhase:null})]})}const Ys=r.memo(function({workspace:n,sessions:s,loading:l,isActive:a,selectedKey:c,openSessionKeys:h,onSelectSession:d,onNewSession:p,onRefresh:g,onRemove:m,onExtensions:k,onWarmSession:y,onCancelWarmSession:j,t:L}){const[A,_]=r.useState(!0),[P,B]=r.useState(Et);r.useEffect(()=>{B(Et)},[s.length]);const H=s.slice(0,P),$=s.length-P,T=n.path;return 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:()=>_(C=>!C),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:M("shrink-0 text-fg-5 transition-transform duration-150",A&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),e.jsx("span",{className:M("flex-1 min-w-0 truncate text-[12px] font-semibold",a?"text-primary":"text-fg-3"),children:n.name}),a&&e.jsx(gt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:C=>{C.stopPropagation(),p(T)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:L("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:C=>{C.stopPropagation(),k(T)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:L("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:C=>{C.stopPropagation(),g(T)},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"})]})}),!a&&e.jsx("button",{onClick:C=>{C.stopPropagation(),m(T)},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:l?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(te,{className:"h-3 w-3 text-fg-5"})}):s.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:L("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[H.map(C=>{const V=O(C.agent||"",C.sessionId),ne=C.__forkDepth||0;return e.jsx(Js,{session:C,isSelected:c===V,isOpen:h?.has(V)??!1,forkDepth:ne,onClick:()=>d(C,T),onWarm:()=>y(C,T),onCancelWarm:()=>j(C,T)},V)}),$>0&&e.jsxs("button",{onClick:()=>B(C=>C+Et),className:"flex items-center gap-1.5 w-full px-3 py-1.5 text-[11px] text-fg-5 hover:text-fg-3 hover:bg-panel-h/50 transition-colors",children:[e.jsxs("span",{children:["+ ",L("hub.nMore").replace("{n}",String($))]}),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"})})]})]})})]})}),Js=r.memo(function({session:n,isSelected:s,isOpen:l,forkDepth:a=0,onClick:c,onWarm:h,onCancelWarm:d}){const p=Lt(n.agent||""),g=xt(n),m=Pn(n).slice(0,500)||n.sessionId.slice(0,16),k=On(n,m).slice(0,500),y=n.model?Wt(n.model):null,j=a>0?Math.min(a,3)*14:0,L=l?10:12;return e.jsxs("button",{onClick:c,onMouseEnter:h,onFocus:h,onMouseLeave:d,onBlur:d,className:M("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":l?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:L+j,...l?{borderLeft:`2px solid ${s?p.color:`${p.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[a>0&&e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-fg-5/60 shrink-0","aria-label":"Fork",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]}),e.jsx(Je,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:p.color},children:p.shortLabel}),y&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:y}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5 shrink-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:on(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(gt,{variant:g==="running"?"ok":g==="incomplete"?"warn":"idle",pulse:g==="running"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:m})]}),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})})]})}),Zs=r.memo(function({workdir:n,onClose:s,t:l}){const a=ve(m=>m.state?.hostApp??null),c=ve(m=>m.state?.platform??null),h=ve(m=>m.toast),[d,p]=r.useState(()=>Gs(a,c)),g=r.useCallback(async m=>{try{const k=await X.openInEditor(m,d);if(!k.ok)throw new Error(k.error||`Failed to open ${m}`)}catch(k){h(k?.message||String(k),!1)}},[d,h]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:l("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:l("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($n,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(m=>({value:m,label:l(jn(m))})),onChange:m=>{Vs(m)&&p(m)},renderIcon:m=>e.jsx(wn,{target:m,size:14})}),e.jsx(Ue,{size:"sm",variant:"ghost",onClick:()=>g(n),className:"flex-1 min-w-0 text-[11px]",children:l("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(er,{basePath:n,openTarget:d,onOpenPath:g,t:l})})]})});function wn({target:t,size:n=16}){return t==="default"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 16 16",className:"shrink-0 text-fg-4",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 3H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-2"}),e.jsx("path",{d:"M9 2h5v5"}),e.jsx("path",{d:"M14 2L7 9"})]}):e.jsx(Je,{brand:t,size:n})}function er({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:l,t:a}){const[c,h]=r.useState([]),[d,p]=r.useState(!0);r.useEffect(()=>{let m=!1;return p(!0),X.lsDir(t,!0,n).then(k=>{!m&&k.ok&&h(k.dirs.slice(0,50).map(y=>({entry:y,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{m||p(!1)}),()=>{m=!0}},[t,n]);const g=r.useCallback(m=>{const k=y=>y.map(j=>j.entry.path===m?j.expanded?{...j,expanded:!1}:j.children===null?(X.lsDir(m,!0,n).then(L=>{L.ok&&h(A=>_t(A,m,{children:L.dirs.slice(0,50).map(_=>({entry:_,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{h(L=>_t(L,m,{children:[],loading:!1}))}),{...j,loading:!0,expanded:!0}):{...j,expanded:!0}:j.children?{...j,children:k(j.children)}:j);h(y=>k(y))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(te,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(kn,{nodes:c,depth:0,onToggle:g,openTarget:s,onOpenPath:l,t:a})})}function kn({nodes:t,depth:n,onToggle:s,openTarget:l,onOpenPath:a,t:c}){return e.jsx(e.Fragment,{children:t.map(h=>e.jsx(tr,{node:h,depth:n,onToggle:s,openTarget:l,onOpenPath:a,t:c},h.entry.path))})}function tr({node:t,depth:n,onToggle:s,openTarget:l,onOpenPath:a,t:c}){const{entry:h,expanded:d,children:p,loading:g}=t,m=n*14,[k,y]=r.useState(!1),j=c(jn(l)),L=c("hub.openWithTarget").replace("{target}",j);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:h.isDir?()=>s(h.path):void 0,onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),className:M("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",h.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+m,paddingRight:8},children:[h.isDir?g?e.jsx(te,{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:M("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),h.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:h.name}),k&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:A=>{A.stopPropagation(),a(h.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:L,children:e.jsx(wn,{target:l,subtle:!0})}),!h.isDir&&e.jsx(nr,{filePath:h.path,t:c})]})]}),h.isDir&&d&&p&&p.length>0&&e.jsx(kn,{nodes:p,depth:n+1,onToggle:s,openTarget:l,onOpenPath:a,t:c})]})}function nr({filePath:t,t:n}){const[s,l]=r.useState(!1);return e.jsx("button",{onClick:a=>{a.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},className:M("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 _t(t,n,s){return t.map(l=>l.entry.path===n?{...l,...s}:l.children?{...l,children:_t(l.children,n,s)}:l)}const mr=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Qs},Symbol.toStringTag,{value:"Module"}));export{ms as I,pr as L,gr as T,vn as U,xr as a,os as b,It as c,_s as d,mr as i,Xn as l,fr as m,hr as n,qn as p,Zt as u};
@@ -1 +1 @@
1
- import{j as e}from"./react-vendor-DTcmqLiz.js";import{c as n,B as d,S as o}from"./index-BS_RBT-T.js";function x({children:s,className:r,interactive:a,glow:t,...i}){return e.jsx("div",{className:n("glass rounded-md border border-edge p-2.5 shadow-[0_1px_0_rgba(255,255,255,0.02),0_4px_12px_rgba(15,23,42,0.05)]","transition-[border-color,background,transform,box-shadow] duration-200",a&&"cursor-pointer hover:border-edge-h hover:bg-panel-h",t&&"card-glow",r),...i,children:s})}function f({primary:s,secondary:r,tertiary:a}){return e.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s&&e.jsxs(d,{variant:"primary",onClick:s.onClick,disabled:s.disabled,children:[s.loading&&e.jsx(o,{}),s.label]}),r&&e.jsx(d,{variant:"outline",onClick:r.onClick,disabled:r.disabled,children:r.label})]}),a&&e.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:a})]})}function g({children:s,className:r}){return e.jsx(x,{className:n("p-4",r),children:s})}function u({children:s,className:r}){return e.jsx("div",{className:n("glass overflow-hidden rounded-md border border-edge shadow-[0_1px_0_rgba(255,255,255,0.02),0_4px_12px_rgba(15,23,42,0.05)]","transition-[border-color,background,transform,box-shadow] duration-200","grid gap-x-5 gap-y-2 px-4 py-2.5","xl:grid-cols-[minmax(0,205px)_minmax(220px,0.95fr)_minmax(0,1.15fr)_auto] xl:items-center",r),children:s})}function p({icon:s,title:r,subtitle:a,badge:t,className:i,iconWrap:l=!0}){return e.jsxs("div",{className:n("flex items-center gap-2.5",i),children:[l?e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-edge bg-panel-alt text-fg-3",children:s}):e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center",children:s}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-[14px] font-semibold text-fg",children:r}),t]}),a&&e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-fg-5",children:a})]})]})}function b({label:s,children:r,className:a}){return e.jsxs("div",{className:n("min-w-0",a),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s}),e.jsx("div",{className:"mt-1",children:r})]})}function h({children:s,className:r}){return e.jsx("div",{className:n("flex justify-start xl:justify-end",r),children:s})}export{f as A,g as S,u as a,p as b,b as c,h as d};
1
+ import{j as e}from"./react-vendor-DTcmqLiz.js";import{c as n,B as d,S as o}from"./index-B_sC2ppg.js";function x({children:s,className:r,interactive:a,glow:t,...i}){return e.jsx("div",{className:n("glass rounded-md border border-edge p-2.5 shadow-[0_1px_0_rgba(255,255,255,0.02),0_4px_12px_rgba(15,23,42,0.05)]","transition-[border-color,background,transform,box-shadow] duration-200",a&&"cursor-pointer hover:border-edge-h hover:bg-panel-h",t&&"card-glow",r),...i,children:s})}function f({primary:s,secondary:r,tertiary:a}){return e.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s&&e.jsxs(d,{variant:"primary",onClick:s.onClick,disabled:s.disabled,children:[s.loading&&e.jsx(o,{}),s.label]}),r&&e.jsx(d,{variant:"outline",onClick:r.onClick,disabled:r.disabled,children:r.label})]}),a&&e.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:a})]})}function g({children:s,className:r}){return e.jsx(x,{className:n("p-4",r),children:s})}function u({children:s,className:r}){return e.jsx("div",{className:n("glass overflow-hidden rounded-md border border-edge shadow-[0_1px_0_rgba(255,255,255,0.02),0_4px_12px_rgba(15,23,42,0.05)]","transition-[border-color,background,transform,box-shadow] duration-200","grid gap-x-5 gap-y-2 px-4 py-2.5","xl:grid-cols-[minmax(0,205px)_minmax(220px,0.95fr)_minmax(0,1.15fr)_auto] xl:items-center",r),children:s})}function p({icon:s,title:r,subtitle:a,badge:t,className:i,iconWrap:l=!0}){return e.jsxs("div",{className:n("flex items-center gap-2.5",i),children:[l?e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-edge bg-panel-alt text-fg-3",children:s}):e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center",children:s}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-[14px] font-semibold text-fg",children:r}),t]}),a&&e.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-fg-5",children:a})]})]})}function b({label:s,children:r,className:a}){return e.jsxs("div",{className:n("min-w-0",a),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.16em] text-fg-5",children:s}),e.jsx("div",{className:"mt-1",children:r})]})}function h({children:s,className:r}){return e.jsx("div",{className:n("flex justify-start xl:justify-end",r),children:s})}export{f as A,g as S,u as a,p as b,b as c,h as d};
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Pikiclaw</title>
7
7
  <link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
8
- <script type="module" crossorigin src="/assets/index-BS_RBT-T.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-B_sC2ppg.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-DTcmqLiz.js">
10
10
  <link rel="modulepreload" crossorigin href="/assets/router-Cav8lq-m.js">
11
11
  <link rel="stylesheet" crossorigin href="/assets/index-BKX45VMn.css">
@@ -1618,6 +1618,63 @@ function getClaudeUsageFromTelemetry(home, model) {
1618
1618
  const windows = [{ label: ageLabel, usedPercent: null, remainingPercent: null, resetAt, resetAfterSeconds, status }];
1619
1619
  return { ok: true, agent: 'claude', source: 'telemetry', capturedAt: chosen.capturedAt, status, windows, error: null };
1620
1620
  }
1621
+ function claudeSessionTranscriptPath(workdir, sessionId) {
1622
+ const home = getHome();
1623
+ if (!home || !workdir || !sessionId)
1624
+ return '';
1625
+ return path.join(home, '.claude', 'projects', encodePathAsDirName(workdir), `${sessionId}.jsonl`);
1626
+ }
1627
+ /**
1628
+ * Scan a claude session transcript for the latest native /goal state. Returns
1629
+ * null when no `goal_status` attachment is present.
1630
+ */
1631
+ export function getClaudeNativeGoal(workdir, sessionId) {
1632
+ const file = claudeSessionTranscriptPath(workdir, sessionId);
1633
+ if (!file || !fs.existsSync(file))
1634
+ return null;
1635
+ // Goal status lines are tiny attachments. Walk the tail (1 MB) to find the
1636
+ // last one — tail covers all realistic session sizes without parsing every
1637
+ // line of a long transcript.
1638
+ const lines = readTailLines(file, 1024 * 1024);
1639
+ let latest = null;
1640
+ for (const raw of lines) {
1641
+ if (!raw || raw[0] !== '{')
1642
+ continue;
1643
+ // Cheap pre-filter so we only JSON.parse the relevant subset.
1644
+ if (!raw.includes('"goal_status"'))
1645
+ continue;
1646
+ try {
1647
+ const ev = JSON.parse(raw);
1648
+ const att = ev?.attachment;
1649
+ if (!att || att.type !== 'goal_status')
1650
+ continue;
1651
+ const condition = typeof att.condition === 'string' ? att.condition : '';
1652
+ const met = !!att.met;
1653
+ const ts = typeof ev.timestamp === 'string' ? Date.parse(ev.timestamp) : NaN;
1654
+ latest = {
1655
+ condition,
1656
+ met,
1657
+ status: met || !condition ? 'complete' : 'active',
1658
+ updatedAtMs: Number.isFinite(ts) ? ts : Date.now(),
1659
+ };
1660
+ }
1661
+ catch { /* skip */ }
1662
+ }
1663
+ // After auto-clear (met:true) claude still leaves the goal_status line in the
1664
+ // transcript; pikiclaw treats "no active goal" as null so the bridge mirrors
1665
+ // the codex semantics where `goal_get` returns null after a clear.
1666
+ if (latest && latest.met)
1667
+ return null;
1668
+ return latest;
1669
+ }
1670
+ /** Build the user-prompt that triggers claude's native `/goal <condition>` slash command. */
1671
+ export function buildClaudeSetGoalPrompt(objective) {
1672
+ return `/goal ${objective.trim()}`;
1673
+ }
1674
+ /** Build the user-prompt that triggers claude's native `/goal clear` slash command. */
1675
+ export function buildClaudeClearGoalPrompt() {
1676
+ return '/goal clear';
1677
+ }
1621
1678
  // ---------------------------------------------------------------------------
1622
1679
  // Driver
1623
1680
  // ---------------------------------------------------------------------------
@@ -115,7 +115,13 @@ export class CodexAppServer {
115
115
  }
116
116
  this.pending.clear();
117
117
  });
118
- this.call('initialize', { clientInfo: { name: 'pikiclaw', version: '0.2.0' } })
118
+ // Declare experimentalApi so `thread/goal/*` is reachable. Codex 0.130+
119
+ // gates these RPCs behind that capability — without it, every goal call
120
+ // returns "requires experimentalApi capability".
121
+ this.call('initialize', {
122
+ clientInfo: { name: 'pikiclaw', version: '0.2.0' },
123
+ capabilities: { experimentalApi: true },
124
+ })
119
125
  .then(resp => {
120
126
  clearTimeout(timer);
121
127
  if (resp.error) {
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Cross-agent conversation handover.
3
+ *
4
+ * When the user switches agent mid-thread (Claude → Gemini, Codex → Claude, …)
5
+ * the new session has no shared state with the source. Rather than maintain a
6
+ * parallel "thread transcript" inside pikiclaw — which would force us to track
7
+ * every agent's evolving session format — we let each agent own its session
8
+ * file and bridge across the gap with a one-shot compaction at the switch.
9
+ *
10
+ * `compactForHandover` reads the source agent's session, formats its turns into
11
+ * a `<handover>` envelope, and returns a seed string that callers prepend to
12
+ * the new agent's first user prompt. After that first turn the new agent's own
13
+ * session file is the canonical context — handover never fires again for that
14
+ * session.
15
+ */
16
+ import { getSessionMessages } from './session.js';
17
+ // ---------------------------------------------------------------------------
18
+ // Budget heuristics
19
+ // ---------------------------------------------------------------------------
20
+ /**
21
+ * Rough per-agent default context window (tokens). Used only to size the
22
+ * handover budget — driver-side accurate windows still flow into usage reporting
23
+ * via each driver's own contextWindow logic. Conservative: when in doubt,
24
+ * underestimate so we don't pack the new turn into a window the model can't
25
+ * handle.
26
+ */
27
+ const DEFAULT_AGENT_WINDOW_TOKENS = {
28
+ claude: 200_000,
29
+ codex: 256_000,
30
+ gemini: 1_000_000,
31
+ hermes: 128_000,
32
+ };
33
+ function agentWindowTokens(agent, model) {
34
+ const m = (model || '').toLowerCase();
35
+ if (agent === 'gemini' && /(^|-)(2\.5|3|3\.1)/.test(m))
36
+ return 1_000_000;
37
+ if (agent === 'claude' && /(opus|sonnet|haiku).*?-?(4|4\.\d)/.test(m))
38
+ return 200_000;
39
+ return DEFAULT_AGENT_WINDOW_TOKENS[agent] ?? 128_000;
40
+ }
41
+ /**
42
+ * Fraction of the target agent's window that the handover is allowed to
43
+ * consume. Leaves headroom for the user's own prompt and the model's response.
44
+ */
45
+ const HANDOVER_WINDOW_FRACTION = 0.5;
46
+ /** Rough chars-per-token estimate; agnostic, fine for budgeting. */
47
+ const CHARS_PER_TOKEN = 4;
48
+ export function makeEmptyHandoverResult(error = null) {
49
+ return { ok: false, seed: '', mode: 'empty', messagesIncluded: 0, messagesTotal: 0, turnsTotal: 0, charsIncluded: 0, budgetChars: 0, error };
50
+ }
51
+ export function describeHandoverRef(ref) {
52
+ if (!ref)
53
+ return '(none)';
54
+ return `${ref.agent}:${ref.sessionId}`;
55
+ }
56
+ /**
57
+ * Read the source agent's session and produce a seed string suitable for
58
+ * prepending to the new agent's first user prompt.
59
+ *
60
+ * Strategy: pack as many turns as the target window allows, from newest to
61
+ * oldest. If everything fits — verbatim mode. If we had to drop older turns —
62
+ * tail mode (we still keep recent context, just less than the full history).
63
+ * If we couldn't read the source session at all — empty mode (seed is '').
64
+ *
65
+ * Never throws: read failures degrade to `mode: 'empty'` so the caller can
66
+ * proceed with the user's prompt alone.
67
+ */
68
+ export async function compactForHandover(opts) {
69
+ const windowTokens = agentWindowTokens(opts.toAgent, opts.toModel);
70
+ const budgetChars = Math.floor(windowTokens * HANDOVER_WINDOW_FRACTION * CHARS_PER_TOKEN);
71
+ let messages = [];
72
+ let turnsTotal = 0;
73
+ try {
74
+ const result = await getSessionMessages({
75
+ agent: opts.fromAgent,
76
+ sessionId: opts.fromSessionId,
77
+ workdir: opts.workdir,
78
+ });
79
+ if (!result.ok) {
80
+ return { ...makeEmptyHandoverResult(result.error || 'read failed'), budgetChars };
81
+ }
82
+ messages = result.messages || [];
83
+ turnsTotal = result.totalTurns ?? Math.ceil(messages.length / 2);
84
+ }
85
+ catch (e) {
86
+ return { ...makeEmptyHandoverResult(e?.message || String(e)), budgetChars };
87
+ }
88
+ if (!messages.length) {
89
+ return { ...makeEmptyHandoverResult('no messages'), budgetChars };
90
+ }
91
+ const messagesTotal = messages.length;
92
+ // Open the envelope first so its overhead is part of the budget calculation.
93
+ const envelopeOpen = `<handover from="${opts.fromAgent}" to="${opts.toAgent}" turns="${turnsTotal}">`;
94
+ const envelopeClose = `</handover>`;
95
+ const trailerText = `\n[Continuing this conversation. The previous turns above ran under ${opts.fromAgent}; you are now ${opts.toAgent} picking up where it left off. Your next user message follows.]`;
96
+ const overhead = envelopeOpen.length + envelopeClose.length + trailerText.length + 8 /* newlines */;
97
+ const messageBudget = Math.max(0, budgetChars - overhead);
98
+ // Pack newest-to-oldest so the most recent context is preserved when we run
99
+ // out of budget. Reverse back to chronological for the seed text.
100
+ const lines = [];
101
+ let used = 0;
102
+ let kept = 0;
103
+ for (let i = messages.length - 1; i >= 0; i--) {
104
+ const msg = messages[i];
105
+ const label = msg.role === 'user' ? 'User' : 'Assistant';
106
+ const line = `${label}: ${msg.text}`;
107
+ if (used + line.length + 1 > messageBudget)
108
+ break;
109
+ lines.push(line);
110
+ used += line.length + 1;
111
+ kept += 1;
112
+ }
113
+ lines.reverse();
114
+ if (!lines.length) {
115
+ return { ...makeEmptyHandoverResult('budget too small'), budgetChars };
116
+ }
117
+ const seed = [envelopeOpen, ...lines, envelopeClose, trailerText].join('\n');
118
+ const mode = kept >= messages.length ? 'verbatim' : 'tail';
119
+ return {
120
+ ok: true,
121
+ seed,
122
+ mode,
123
+ messagesIncluded: kept,
124
+ messagesTotal,
125
+ turnsTotal,
126
+ charsIncluded: used,
127
+ budgetChars,
128
+ error: null,
129
+ };
130
+ }
@@ -21,7 +21,7 @@ export { IMAGE_EXTS } from './types.js';
21
21
  // ── Re-export: utilities ────────────────────────────────────────────────────
22
22
  export { Q, agentLog, agentWarn, agentError, dedupeStrings, numberOrNull, normalizeStreamPreviewPlan, parseTodoWriteAsPlan, normalizeActivityLine, pushRecentActivity, firstNonEmptyLine, shortValue, normalizeErrorMessage, joinErrorMessages, appendSystemPrompt, mimeForExt, computeContext, buildStreamPreviewMeta, summarizeClaudeToolUse, summarizeClaudeToolResult, roundPercent, toIsoFromEpochSeconds, normalizeUsageStatus, labelFromWindowMinutes, usageWindowFromRateLimit, parseJsonTail, modelFamily, normalizeClaudeModelId, emptyUsage, readTailLines, stripInjectedPrompts, sanitizeSessionUserPreviewText, SESSION_PREVIEW_IMAGE_PLACEHOLDER_RE, isPendingSessionId, emitSessionIdUpdate, sessionListDisplayTitle, } from './utils.js';
23
23
  // ── Re-export: session management ───────────────────────────────────────────
24
- export { updateSessionMeta, promoteSessionId, recordFork, listPikiclawSessions, findPikiclawSession, getSessionStoredConfig, ensureManagedSession, findManagedThreadSession, findThreadSessionAcrossAgents, stageSessionFiles, mergeManagedAndNativeSessions, getSessions, getSessionTail, getSessionMessages, applyTurnWindow, applyTurnFilter, classifySession, deriveUserStatus, exportSession, importSession, isProcessAlive, isRunningSessionStale, reconcileOrphanedRunningSessions, } from './session.js';
24
+ export { updateSessionMeta, promoteSessionId, recordFork, listPikiclawSessions, findPikiclawSession, getSessionStoredConfig, ensureManagedSession, findManagedThreadSession, stageSessionFiles, mergeManagedAndNativeSessions, getSessions, getSessionTail, getSessionMessages, applyTurnWindow, applyTurnFilter, classifySession, deriveUserStatus, exportSession, importSession, isProcessAlive, isRunningSessionStale, reconcileOrphanedRunningSessions, } from './session.js';
25
25
  // ── Re-export: stream & detection ───────────────────────────────────────────
26
26
  export { detectAgentBin, listAgents, run, doStream, listModels, resolveAgentModels, getUsage, getAgentBoundModelId, setAgentBoundModelId, } from './stream.js';
27
27
  // ── Re-export: driver registry ──────────────────────────────────────────────
@@ -32,6 +32,8 @@ export { getProjectSkillPaths, initializeProjectSkills, listSkills, getGlobalSki
32
32
  export { readGoal, writeGoal, clearGoal, setGoal, pauseGoal, resumeGoal, completeGoal, accountTurn, bumpContinuationCount, shouldContinueAfterTurn, renderContinuationPrompt, renderBudgetLimitPrompt, sessionGoalPath, DEFAULT_MAX_CONTINUATIONS, } from './goal.js';
33
33
  // ── Re-export: native codex goal bridge ──────────────────────────────────────
34
34
  export { setCodexGoal, getCodexGoal, clearCodexGoal, pauseCodexGoal, resumeCodexGoal, } from './drivers/codex.js';
35
+ // ── Re-export: native claude goal bridge ─────────────────────────────────────
36
+ export { getClaudeNativeGoal, buildClaudeSetGoalPrompt, buildClaudeClearGoalPrompt, } from './drivers/claude.js';
35
37
  // ── Re-export: MCP extensions ───────────────────────────────────────────────
36
38
  export { listAllMcpExtensions, addGlobalMcpExtension, removeGlobalMcpExtension, updateGlobalMcpExtension, addWorkspaceMcpExtension, removeWorkspaceMcpExtension, updateWorkspaceMcpExtension, loadGlobalMcpExtensions, loadWorkspaceMcpExtensions, getCatalogItems, getCatalogItem, buildInstalledConfigFromRecommended, checkMcpHealth, getCachedHealth, cacheHealth, } from './mcp/extensions.js';
37
39
  export { getRecommendedMcpServers, getRecommendedMcpServer, getRecommendedSkillRepos, searchMcpServers, searchSkills as searchSkillRepos, } from './mcp/registry.js';
@@ -190,6 +190,16 @@ export function applySessionRunResult(record, result) {
190
190
  record.userStatus = deriveUserStatus(classification.outcome);
191
191
  }
192
192
  }
193
+ function normalizeHandoverRef(value) {
194
+ if (!value || typeof value !== 'object')
195
+ return null;
196
+ const v = value;
197
+ const agent = typeof v.agent === 'string' ? v.agent.trim() : '';
198
+ const sessionId = typeof v.sessionId === 'string' ? v.sessionId.trim() : '';
199
+ if (!agent || !sessionId)
200
+ return null;
201
+ return { agent: agent, sessionId };
202
+ }
193
203
  function normalizeSessionRecord(raw, workdir) {
194
204
  // Support both new format (sessionId) and legacy format (localSessionId + engineSessionId)
195
205
  const sessionId = typeof raw?.sessionId === 'string' ? raw.sessionId.trim()
@@ -227,6 +237,7 @@ function normalizeSessionRecord(raw, workdir) {
227
237
  migratedFrom: raw?.migratedFrom ?? null,
228
238
  migratedTo: raw?.migratedTo ?? null,
229
239
  linkedSessions: Array.isArray(raw?.linkedSessions) ? raw.linkedSessions : [],
240
+ handoverFrom: normalizeHandoverRef(raw?.handoverFrom),
230
241
  };
231
242
  }
232
243
  // ---------------------------------------------------------------------------
@@ -266,6 +277,7 @@ function writeSessionMeta(record) {
266
277
  migratedFrom: record.migratedFrom,
267
278
  migratedTo: record.migratedTo,
268
279
  linkedSessions: record.linkedSessions,
280
+ handoverFrom: record.handoverFrom ?? null,
269
281
  });
270
282
  }
271
283
  // ---------------------------------------------------------------------------
@@ -542,10 +554,14 @@ export function ensureSessionWorkspace(opts) {
542
554
  lastQuestion: null, lastAnswer: null, lastMessageText: null,
543
555
  lastThinking: null, lastPlan: null,
544
556
  migratedFrom: null, migratedTo: null, linkedSessions: [],
557
+ handoverFrom: normalizeHandoverRef(opts.handoverFrom),
545
558
  };
546
559
  }
547
560
  if (!record.threadId)
548
561
  record.threadId = normalizeThreadId(opts.threadId) || legacyThreadId(record.agent, record.sessionId);
562
+ // Backfill handoverFrom on first staging only — never overwrite an existing one.
563
+ if (!record.handoverFrom)
564
+ record.handoverFrom = normalizeHandoverRef(opts.handoverFrom);
549
565
  if (!record.title && opts.title)
550
566
  record.title = summarizePromptTitle(opts.title);
551
567
  record.workspacePath = path.resolve(record.workspacePath);
@@ -588,6 +604,7 @@ function managedRecordToSessionInfo(record) {
588
604
  migratedTo: record.migratedTo,
589
605
  linkedSessions: record.linkedSessions,
590
606
  numTurns: record.numTurns ?? null,
607
+ handoverFrom: record.handoverFrom ?? null,
591
608
  };
592
609
  }
593
610
  // ---------------------------------------------------------------------------
@@ -632,16 +649,6 @@ export function findManagedThreadSession(workdir, threadId, agent) {
632
649
  .sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt))[0] || null;
633
650
  return record ? managedRecordToSessionInfo(record) : null;
634
651
  }
635
- /**
636
- * Find the most recently updated session sharing a threadId but from a *different* agent.
637
- * Used to carry conversation context across agent switches.
638
- */
639
- export function findThreadSessionAcrossAgents(workdir, threadId, excludeAgent) {
640
- const record = loadSessionIndex(path.resolve(workdir)).sessions
641
- .filter(entry => entry.threadId === threadId && entry.agent !== excludeAgent)
642
- .sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt))[0] || null;
643
- return record ? managedRecordToSessionInfo(record) : null;
644
- }
645
652
  export function stageSessionFiles(opts) {
646
653
  const session = ensureSessionWorkspace({
647
654
  agent: opts.agent,
@@ -649,6 +656,7 @@ export function stageSessionFiles(opts) {
649
656
  sessionId: opts.sessionId,
650
657
  title: opts.title,
651
658
  threadId: opts.threadId,
659
+ handoverFrom: opts.handoverFrom,
652
660
  });
653
661
  const importedFiles = importFilesIntoWorkspace(session.workspacePath, opts.files);
654
662
  if (importedFiles.length) {
@@ -656,7 +664,13 @@ export function stageSessionFiles(opts) {
656
664
  /* title will be set when the first text prompt arrives */
657
665
  saveSessionRecord(opts.workdir, session.record);
658
666
  }
659
- return { sessionId: session.sessionId, workspacePath: session.workspacePath, threadId: session.record.threadId, importedFiles };
667
+ return {
668
+ sessionId: session.sessionId,
669
+ workspacePath: session.workspacePath,
670
+ threadId: session.record.threadId,
671
+ importedFiles,
672
+ handoverFrom: session.record.handoverFrom ?? null,
673
+ };
660
674
  }
661
675
  // ---------------------------------------------------------------------------
662
676
  // Merge managed and native sessions