@runfusion/fusion 0.9.0 → 0.9.1

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 (38) hide show
  1. package/dist/bin.js +434 -103
  2. package/dist/client/assets/{AgentDetailView-Ca1euvPo.js → AgentDetailView-khrspqE3.js} +3 -3
  3. package/dist/client/assets/{AgentsView-pile-9ZM.js → AgentsView-DvN5EsoE.js} +11 -11
  4. package/dist/client/assets/AgentsView-MotzGhZJ.css +1 -0
  5. package/dist/client/assets/{ChatView-C4SCF_Hj.js → ChatView-DsETFRQp.js} +1 -1
  6. package/dist/client/assets/{DevServerView-1HvWligZ.js → DevServerView-D1_7SL1h.js} +1 -1
  7. package/dist/client/assets/{DirectoryPicker-B1eztZna.js → DirectoryPicker-BBcm5G9F.js} +1 -1
  8. package/dist/client/assets/{DocumentsView-D4m9s6Ye.js → DocumentsView-OuVpmTPp.js} +1 -1
  9. package/dist/client/assets/InsightsView-4KiUKzbz.css +1 -0
  10. package/dist/client/assets/InsightsView-DMC_bLUc.js +11 -0
  11. package/dist/client/assets/{MemoryView-DEmn8fA2.js → MemoryView-cI4IK-lz.js} +1 -1
  12. package/dist/client/assets/{NodesView-Blg8NHiu.js → NodesView-C_LWLFNr.js} +2 -2
  13. package/dist/client/assets/{PiExtensionsManager-DkXenPK0.js → PiExtensionsManager-DCTHvy2u.js} +1 -1
  14. package/dist/client/assets/{PluginManager-Czso7ZUF.js → PluginManager-BXMpkZx-.js} +1 -1
  15. package/dist/client/assets/{RoadmapsView-DATopkaE.js → RoadmapsView-BHTePn2u.js} +1 -1
  16. package/dist/client/assets/SettingsModal-2s-L1oWD.js +31 -0
  17. package/dist/client/assets/{SettingsModal-D_mcRJO2.js → SettingsModal-BSZIno8y.js} +1 -1
  18. package/dist/client/assets/{SetupWizardModal-JBNr-XIW.js → SetupWizardModal-DVoRhy_V.js} +1 -1
  19. package/dist/client/assets/{SkillsView-CkT6-elZ.js → SkillsView-CK52SRz5.js} +1 -1
  20. package/dist/client/assets/{TodoView-CstzLvjw.js → TodoView-BKqIV8P6.js} +1 -1
  21. package/dist/client/assets/{folder-open-BEDPztlF.js → folder-open-C0SfzRFt.js} +1 -1
  22. package/dist/client/assets/index-DawWARY5.css +1 -0
  23. package/dist/client/assets/index-DiC9GfBH.js +656 -0
  24. package/dist/client/assets/{list-checks-DgZgg3rh.js → list-checks-D5c428sr.js} +1 -1
  25. package/dist/client/assets/{star-DXieIAlP.js → star-GGmbVi2b.js} +1 -1
  26. package/dist/client/assets/{upload-Cbvs_TSB.js → upload-CrJJybRJ.js} +1 -1
  27. package/dist/client/assets/{users-DAMIrlue.js → users-C56SMdh4.js} +1 -1
  28. package/dist/client/index.html +2 -2
  29. package/dist/client/version.json +1 -1
  30. package/dist/extension.js +427 -103
  31. package/dist/pi-claude-cli/package.json +1 -1
  32. package/package.json +1 -1
  33. package/dist/client/assets/AgentsView-Cq-SEhLc.css +0 -1
  34. package/dist/client/assets/InsightsView-6LHF7OdE.css +0 -1
  35. package/dist/client/assets/InsightsView-u535o96R.js +0 -11
  36. package/dist/client/assets/SettingsModal-Cs5qO84M.js +0 -31
  37. package/dist/client/assets/index-CPStj9Az.css +0 -1
  38. package/dist/client/assets/index-DZB5f-Bl.js +0 -656
@@ -1,20 +1,20 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-Ca1euvPo.js","assets/vendor-react-K0fH_qHe.js","assets/index-DZB5f-Bl.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-CPStj9Az.css","assets/star-DXieIAlP.js","assets/list-checks-DgZgg3rh.js","assets/upload-Cbvs_TSB.js","assets/folder-open-BEDPztlF.js","assets/AgentDetailView-DIBOY8V-.css"])))=>i.map(i=>d[i]);
2
- import{c as Ke,s as ut,A as Ce,F as Ve,f as mt,C as _e,Z as ht,B as Ue,g as We,a as it,b as De,d as gt,e as pt,h as ft,i as vt,j as bt,u as Ge,P as xt,k as yt,l as wt,m as jt,n as Qe,G as kt,S as Nt,L as Le,T as ze,R as Pe,X as Je,o as It,p as Ct,q as St,r as Et,t as ge,v as Oe,w as At,x as Tt,y as Mt,z as Rt,D as _t,E as Xe,H as Pt,I as rt,J as $t,K as Ae,M as Ze,N as Ft,O as Dt,Q as Lt,U as Te,V as zt,W as Ye,Y as Ot,_ as qt,$ as Ht,a0 as Vt}from"./index-DZB5f-Bl.js";import{r as n,j as e,a as Wt}from"./vendor-react-K0fH_qHe.js";import{U as lt}from"./upload-Cbvs_TSB.js";import{F as Kt}from"./folder-open-BEDPztlF.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AgentDetailView-khrspqE3.js","assets/vendor-react-K0fH_qHe.js","assets/index-DiC9GfBH.js","assets/vendor-xterm-DzcZoU0P.js","assets/vendor-xterm-LZoznX6r.css","assets/index-DawWARY5.css","assets/star-GGmbVi2b.js","assets/list-checks-D5c428sr.js","assets/upload-CrJJybRJ.js","assets/folder-open-C0SfzRFt.js","assets/AgentDetailView-DIBOY8V-.css"])))=>i.map(i=>d[i]);
2
+ import{c as Be,s as mt,A as Ce,r as We,F as Ke,f as ht,C as _e,Z as gt,B as Ge,g as Ue,a as rt,b as De,d as pt,e as ft,h as vt,i as bt,j as xt,u as Je,P as yt,k as wt,l as jt,m as kt,n as Xe,G as Nt,S as It,L as Le,T as ze,R as Pe,X as Ze,o as Ct,p as St,q as At,t as Et,v as ge,w as Oe,x as Tt,y as Mt,z as Rt,D as _t,E as Pt,H as $t,I as lt,J as Ft,K as Ee,M as Ye,N as Dt,O as Lt,Q as zt,U as Te,V as Ot,W as et,Y as Ht,_ as qt,$ as Vt,a0 as Wt}from"./index-DiC9GfBH.js";import{r as n,j as e,a as Kt}from"./vendor-react-K0fH_qHe.js";import{U as ot}from"./upload-CrJJybRJ.js";import{F as Ut}from"./folder-open-C0SfzRFt.js";/**
3
3
  * @license lucide-react v1.7.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
6
6
  * See the LICENSE file in the root directory of this source tree.
7
- */const Ut=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1",key:"cif1o7"}]],Bt=Ke("list-todo",Ut);/**
7
+ */const Bt=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1",key:"cif1o7"}]],Gt=Be("list-todo",Bt);/**
8
8
  * @license lucide-react v1.7.0 - ISC
9
9
  *
10
10
  * This source code is licensed under the ISC license.
11
11
  * See the LICENSE file in the root directory of this source tree.
12
- */const Gt=[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]],Qt=Ke("network",Gt);/**
12
+ */const Qt=[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]],Jt=Be("network",Qt);/**
13
13
  * @license lucide-react v1.7.0 - ISC
14
14
  *
15
15
  * This source code is licensed under the ISC license.
16
16
  * See the LICENSE file in the root directory of this source tree.
17
- */const Jt=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Xt=Ke("sliders-horizontal",Jt),et=200;function Zt(a,l){const[y,d]=n.useState([]),[m,c]=n.useState(!1),r=n.useRef(null),h=n.useRef(0),u=n.useRef(a),v=n.useRef(l);return(u.current!==a||v.current!==l)&&(u.current=a,v.current=l,h.current++,r.current&&(r.current(),r.current=null),d([]),c(!1)),n.useEffect(()=>{if(!a){d([]),c(!1);return}const C=h.current;let b=`/api/tasks/${encodeURIComponent(a)}/logs/stream`;l&&(b+=`?projectId=${encodeURIComponent(l)}`);const E=ut(b,{events:{"agent:log":p=>{if(h.current===C)try{const T=JSON.parse(p.data),f={type:T.type??"text",text:T.text??T.content??"",timestamp:T.timestamp,content:T.content};d(A=>{const M=[f,...A];return M.length>et?M.slice(0,et):M})}catch{}}},onOpen:()=>{h.current===C&&c(!0)},onError:()=>{h.current===C&&c(!1)}});return r.current=E,()=>{E(),r.current=null,h.current===C&&c(!1)}},[a,l]),{entries:y,isConnected:m}}const Yt=5e3;function en({agent:a,projectId:l,onSelect:y,onOpenTaskLogs:d}){const{entries:m,isConnected:c}=Zt(a.taskId,l),[r,h]=n.useState(null);n.useEffect(()=>{if(!a.taskId){h(null);return}let f=!1,A;const M=async()=>{try{const k=await mt(a.taskId,l);f||h(k)}catch{}finally{f||(A=setTimeout(M,Yt))}};return M(),()=>{f=!0,A&&clearTimeout(A)}},[a.taskId,l]);const u=a.lastHeartbeatAt?Math.floor((Date.now()-new Date(a.lastHeartbeatAt).getTime())/1e3):0,v=r?.steps?.[r.currentStep??0],g=r?.steps?.length??0,C=(r?.currentStep??0)+1,b=r?.modelId,E=()=>{y&&y(a.id)},p=f=>{f.stopPropagation(),a.taskId&&d&&d(a.taskId)},T=f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),E())};return e.jsxs("div",{className:"live-agent-card",onClick:E,onKeyDown:T,role:"button",tabIndex:0,"aria-label":`Select agent ${a.name}`,children:[e.jsxs("div",{className:"live-agent-card-header",children:[e.jsxs("div",{className:"live-agent-card-name",children:[e.jsx("span",{className:"live-agent-pulse"}),e.jsx("span",{children:a.name})]}),a.taskId&&e.jsx("span",{className:"live-agent-task badge",children:a.taskId})]}),e.jsx("div",{className:"live-agent-card-transcript",children:m.length===0?e.jsx("div",{className:"live-agent-card-empty",children:v?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"live-agent-card-status",children:["Step ",C,g?`/${g}`:"",": ",v.name]}),b&&e.jsx("div",{className:"live-agent-card-status-sub",children:b}),e.jsx("div",{className:"live-agent-card-status-sub",children:c?"Waiting for output...":"Connecting to log stream..."})]}):e.jsx("span",{children:c?"Waiting for output...":"Connecting..."})}):m.slice(0,20).map((f,A)=>e.jsx("div",{className:"live-agent-card-line",children:f.text},A))}),e.jsxs("div",{className:"live-agent-card-footer",children:[e.jsx("span",{className:"text-secondary",children:tn(u)}),e.jsxs("div",{className:"live-agent-card-footer-actions",children:[a.taskId&&d&&e.jsxs("button",{type:"button",className:"live-agent-card-logs-btn",onClick:p,title:"View live run logs","aria-label":`View live logs for ${a.taskId}`,children:[e.jsx(Ve,{size:12}),e.jsx("span",{children:"Live logs"})]}),c&&e.jsx(Ce,{size:12,className:"live-agent-streaming-dot"})]})]})]})}function tn(a){return a<60?`${a}s`:a<3600?`${Math.floor(a/60)}m ${a%60}s`:`${Math.floor(a/3600)}h ${Math.floor(a%3600/60)}m`}function nn({agents:a,projectId:l,onAgentSelect:y,onOpenTaskLogs:d}){const m=Array.from(new Map(a.map(c=>[c.id,c])).values());return m.length===0?null:e.jsxs("div",{className:"active-agents-panel",children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(Ce,{size:16}),e.jsxs("span",{children:["Active Agents (",m.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:m.map(c=>e.jsx(en,{agent:c,projectId:l,onSelect:y,onOpenTaskLogs:d},c.id))})]})}const sn=[{icon:Ce,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:Bt,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:_e,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:ht,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function an({stats:a}){return a?e.jsx("div",{className:"agent-metrics-bar",children:sn.map(l=>{const y=l.valueKey==="successRate"?`${Math.round(a.successRate*100)}%`:a[l.valueKey];return e.jsxs("div",{className:`agent-metric-card ${l.className}`,children:[e.jsx(l.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:y}),e.jsx("span",{className:"agent-metric-label",children:l.label})]})]},l.label)})}):null}function tt(a){return typeof a=="number"&&Number.isFinite(a)?a:0}function Ie(a){return a.toLocaleString()}function rn({agents:a}){const{rows:l,totalInputTokens:y,totalOutputTokens:d,totalTokens:m}=n.useMemo(()=>{const r=a.map(h=>{const u=tt(h.totalInputTokens),v=tt(h.totalOutputTokens);return{id:h.id,name:h.name,inputTokens:u,outputTokens:v,totalTokens:u+v}}).sort((h,u)=>u.totalTokens-h.totalTokens||h.name.localeCompare(u.name)||h.id.localeCompare(u.id));return{rows:r,totalInputTokens:r.reduce((h,u)=>h+u.inputTokens,0),totalOutputTokens:r.reduce((h,u)=>h+u.outputTokens,0),totalTokens:r.reduce((h,u)=>h+u.totalTokens,0)}},[a]),c=m>0;return e.jsxs("section",{className:"agent-token-stats-panel","aria-label":"Agent token usage statistics",children:[e.jsx("header",{className:"agent-token-stats-panel__header",children:e.jsx("h3",{className:"agent-token-stats-panel__title",children:"Token Usage by Agent"})}),e.jsxs("div",{className:"agent-token-stats-panel__totals",role:"list","aria-label":"Token usage totals",children:[e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Input Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ie(y)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Output Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ie(d)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Combined Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ie(m)})]})]}),c?e.jsx("div",{className:"agent-token-stats-panel__table-wrapper",children:e.jsxs("table",{className:"agent-token-stats-panel__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"Agent"}),e.jsx("th",{scope:"col",children:"Input"}),e.jsx("th",{scope:"col",children:"Output"}),e.jsx("th",{scope:"col",children:"Total"})]})}),e.jsx("tbody",{children:l.map(r=>e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",className:"agent-token-stats-panel__agent-cell",children:[e.jsx("span",{className:"agent-token-stats-panel__agent-name",children:r.name}),e.jsx("span",{className:"agent-token-stats-panel__agent-id",children:r.id})]}),e.jsx("td",{children:Ie(r.inputTokens)}),e.jsx("td",{children:Ie(r.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:Ie(r.totalTokens)})]},r.id))})]})}):e.jsx("div",{className:"agent-token-stats-panel__empty",role:"status",children:"No token usage recorded yet. Token totals appear here once agents run."})]})}function Me({title:a="No agents found",description:l="Create an agent to get started",ctaLabel:y="Create Agent",onCtaClick:d}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(Ue,{size:48,opacity:.3,className:"agent-empty-state__icon"}),e.jsx("p",{className:"agent-empty-state__title",children:a}),e.jsx("p",{className:"agent-empty-state__description text-secondary",children:l}),d?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:d,children:y}):null]})}const ot="fn-agent-tree-expanded";function nt(a){try{const l=We(ot,a);if(l){const y=JSON.parse(l);return new Set(Array.isArray(y)?y:[])}}catch{}return new Set}function ln(a,l){try{it(ot,JSON.stringify([...a]),l)}catch{}}function on(a,l){const y=new Map,d=new Map;for(const c of a)if(y.set(c.id,c),c.reportsTo){const r=d.get(c.reportsTo)??[];r.push(c),d.set(c.reportsTo,r)}function m(c,r){const h=d.get(c.id)??[],u=l.has(c.id)?h.map(v=>m(v,r+1)):[];return{agent:c,children:u,depth:r}}return a.filter(c=>!c.reportsTo||!y.has(c.reportsTo)).map(c=>m(c,0))}function cn(a,l){const[y,d]=n.useState(()=>nt(l));n.useEffect(()=>{d(nt(l))},[l]);const m=n.useMemo(()=>on(a,y),[a,y]),c=n.useCallback(u=>{d(v=>{const g=new Set(v);return g.has(u)?g.delete(u):g.add(u),ln(g,l),g})},[l]),r=n.useCallback(u=>y.has(u),[y]),h=n.useCallback(u=>a.filter(v=>v.reportsTo===u),[a]);return{rootNodes:m,toggleExpand:c,isExpanded:r,getChildren:h,isLoading:!1}}const st=3,qe=1e3;function dn({isOpen:a,onClose:l,onGenerated:y,projectId:d}){const[m,c]=n.useState(""),[r,h]=n.useState({type:"input"}),[u,v]=n.useState(null),[g,C]=n.useState(!1),b=n.useRef(null),E=n.useRef(null);n.useEffect(()=>{a&&r.type==="input"&&E.current?.focus()},[a,r.type]),n.useEffect(()=>{if(!a&&b.current){const k=b.current;b.current=null,De(k,d).catch(()=>{})}},[a,d]),n.useEffect(()=>{if(!a)return;const k=_=>{_.key==="Escape"&&p()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[a]);const p=n.useCallback(()=>{if(b.current){const k=b.current;b.current=null,De(k,d).catch(()=>{})}c(""),h({type:"input"}),v(null),C(!1),l()},[l,d]),T=n.useCallback(async()=>{if(!(!m.trim()||m.trim().length<st)){v(null),h({type:"loading"});try{const{sessionId:k}=await gt(m.trim(),d);b.current=k;const{spec:_}=await pt(k,d);h({type:"preview",spec:_,sessionId:k})}catch(k){const _=k instanceof Error?k.message:"Failed to generate agent specification";_.includes("429")||_.toLowerCase().includes("rate limit")?v("Too many requests. Please wait a moment and try again."):v(_),h({type:"input"}),b.current=null}}},[m,d]),f=n.useCallback(async()=>{if(b.current){const k=b.current;b.current=null;try{await De(k,d)}catch{}}await T()},[T,d]),A=n.useCallback(()=>{r.type==="preview"&&(b.current=null,y(r.spec),c(""),h({type:"input"}),v(null),C(!1),l())},[r,y,l]);if(!a)return null;const M=m.trim().length>=st&&m.trim().length<=qe;return e.jsx("div",{className:"agent-dialog-overlay",onClick:k=>{k.target===k.currentTarget&&p()},children:e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Generate agent with AI",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsxs("span",{className:"agent-dialog-header-title",children:[e.jsx("span",{className:"agent-dialog-header-sparkle",children:"✨"}),"Generate Agent"]}),e.jsx("button",{className:"modal-close",onClick:p,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[u&&e.jsx("div",{className:"agent-dialog-error-banner",children:u}),r.type==="input"&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Describe your agent's role and the AI will generate a complete specification including system prompt, suggested configuration, and more."}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-role-description",children:"Role Description"}),e.jsx("textarea",{ref:E,id:"agent-role-description",className:"input agent-dialog-textarea",rows:4,placeholder:'e.g. "Senior frontend code reviewer who specializes in React accessibility"',value:m,onChange:k=>c(k.target.value),onKeyDown:k=>{k.key==="Enter"&&!k.shiftKey&&M&&(k.preventDefault(),T())},maxLength:qe,"aria-describedby":"role-description-hint"}),e.jsxs("div",{id:"role-description-hint",className:"agent-dialog-hint",children:[e.jsx("span",{children:"Describe what your agent should do"}),e.jsxs("span",{children:[m.length,"/",qe]})]})]})]}),r.type==="loading"&&e.jsxs("div",{className:"agent-dialog-loading-center",children:[e.jsx("div",{className:"agent-dialog-spinner spin"}),e.jsx("p",{className:"agent-dialog-loading-text",children:"Generating agent specification..."})]}),r.type==="preview"&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-summary agent-dialog-summary--spaced",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Title"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[r.spec.icon," ",r.spec.title]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Role"}),e.jsx("span",{children:r.spec.role})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Description"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--body",children:r.spec.description})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--capitalize",children:r.spec.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Max Turns"}),e.jsx("span",{children:r.spec.maxTurns})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{children:["System Prompt",e.jsx("button",{type:"button",className:"agent-dialog-expand-btn",onClick:()=>C(!g),children:g?"Collapse":"Expand"})]}),e.jsxs("div",{className:`agent-generation-prompt-box${g?"":" agent-generation-prompt-box--collapsed"}`,children:[r.spec.systemPrompt,!g&&r.spec.systemPrompt.length>500&&e.jsx("div",{className:"agent-generation-prompt-fade"})]})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[e.jsx("button",{className:"btn",onClick:p,children:"Cancel"}),r.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void T(),disabled:!M,children:"Generate"}),r.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void f(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:A,children:"Use This"})]})]})]})})}const un=`# Soul: Chief Executive Officer
17
+ */const Xt=[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]],Zt=Be("sliders-horizontal",Xt),tt=200;function Yt(a,l){const[y,d]=n.useState([]),[m,c]=n.useState(!1),r=n.useRef(null),h=n.useRef(0),u=n.useRef(a),f=n.useRef(l);return(u.current!==a||f.current!==l)&&(u.current=a,f.current=l,h.current++,r.current&&(r.current(),r.current=null),d([]),c(!1)),n.useEffect(()=>{if(!a){d([]),c(!1);return}const C=h.current;let b=`/api/tasks/${encodeURIComponent(a)}/logs/stream`;l&&(b+=`?projectId=${encodeURIComponent(l)}`);const E=mt(b,{events:{"agent:log":p=>{if(h.current===C)try{const M=JSON.parse(p.data),k={type:M.type??"text",text:M.text??M.content??"",timestamp:M.timestamp,content:M.content};d(N=>{const T=[k,...N];return T.length>tt?T.slice(0,tt):T})}catch{}}},onOpen:()=>{h.current===C&&c(!0)},onError:()=>{h.current===C&&c(!1)}});return r.current=E,()=>{E(),r.current=null,h.current===C&&c(!1)}},[a,l]),{entries:y,isConnected:m}}const en=5e3;function tn({agent:a,projectId:l,onSelect:y,onOpenTaskLogs:d}){const{entries:m,isConnected:c}=Yt(a.taskId,l),[r,h]=n.useState(null);n.useEffect(()=>{if(!a.taskId){h(null);return}let N=!1,T;const x=async()=>{try{const R=await ht(a.taskId,l);N||h(R)}catch{}finally{N||(T=setTimeout(x,en))}};return x(),()=>{N=!0,T&&clearTimeout(T)}},[a.taskId,l]);const u=a.lastHeartbeatAt?Math.floor((Date.now()-new Date(a.lastHeartbeatAt).getTime())/1e3):0,f=(()=>{if(!a.lastHeartbeatAt)return null;const N=We(a.runtimeConfig?.heartbeatIntervalMs),T=new Date(a.lastHeartbeatAt).getTime()+N,x=Math.round((T-Date.now())/1e3);return Number.isFinite(x)?x<=0?`Heartbeat overdue ${He(-x)}`:`Next heartbeat in ${He(x)}`:null})(),g=r?.steps?.[r.currentStep??0],C=r?.steps?.length??0,b=(r?.currentStep??0)+1,E=r?.modelId,p=()=>{y&&y(a.id)},M=N=>{N.stopPropagation(),a.taskId&&d&&d(a.taskId)},k=N=>{(N.key==="Enter"||N.key===" ")&&(N.preventDefault(),p())};return e.jsxs("div",{className:"live-agent-card",onClick:p,onKeyDown:k,role:"button",tabIndex:0,"aria-label":`Select agent ${a.name}`,children:[e.jsxs("div",{className:"live-agent-card-header",children:[e.jsxs("div",{className:"live-agent-card-name",children:[e.jsx("span",{className:"live-agent-pulse"}),e.jsx("span",{children:a.name})]}),a.taskId&&e.jsx("span",{className:"live-agent-task badge",children:a.taskId})]}),e.jsx("div",{className:"live-agent-card-transcript",children:m.length===0?e.jsx("div",{className:"live-agent-card-empty",children:a.taskId?g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"live-agent-card-status",children:["Step ",b,C?`/${C}`:"",": ",g.name]}),E&&e.jsx("div",{className:"live-agent-card-status-sub",children:E}),e.jsx("div",{className:"live-agent-card-status-sub",children:c?"Waiting for output...":"Connecting to log stream..."})]}):e.jsx("span",{children:c?"Waiting for output...":"Connecting..."}):e.jsx("span",{children:a.state==="running"?"Starting...":"Idle — no task assigned"})}):m.slice(0,20).map((N,T)=>e.jsx("div",{className:"live-agent-card-line",children:N.text},T))}),e.jsxs("div",{className:"live-agent-card-footer",children:[e.jsxs("div",{className:"live-agent-card-footer-meta",children:[e.jsx("span",{className:"text-secondary",title:"Time since last heartbeat",children:He(u)}),f&&e.jsx("span",{className:"live-agent-card-next-heartbeat",title:f,children:f})]}),e.jsxs("div",{className:"live-agent-card-footer-actions",children:[a.taskId&&d&&e.jsxs("button",{type:"button",className:"live-agent-card-logs-btn",onClick:M,title:"View live run logs","aria-label":`View live logs for ${a.taskId}`,children:[e.jsx(Ke,{size:12}),e.jsx("span",{children:"Live logs"})]}),c&&e.jsx(Ce,{size:12,className:"live-agent-streaming-dot"})]})]})]})}function He(a){return a<60?`${a}s`:a<3600?`${Math.floor(a/60)}m ${a%60}s`:`${Math.floor(a/3600)}h ${Math.floor(a%3600/60)}m`}function nn({agents:a,projectId:l,onAgentSelect:y,onOpenTaskLogs:d}){const m=Array.from(new Map(a.map(c=>[c.id,c])).values());return m.length===0?null:e.jsxs("div",{className:"active-agents-panel",children:[e.jsxs("div",{className:"active-agents-panel-header",children:[e.jsx(Ce,{size:16}),e.jsxs("span",{children:["Active Agents (",m.length,")"]})]}),e.jsx("div",{className:"active-agents-grid",children:m.map(c=>e.jsx(tn,{agent:c,projectId:l,onSelect:y,onOpenTaskLogs:d},c.id))})]})}const sn=[{icon:Ce,label:"Active Agents",valueKey:"activeCount",className:"agent-metric-card--active"},{icon:Gt,label:"Assigned Tasks",valueKey:"assignedTaskCount",className:"agent-metric-card--tasks"},{icon:_e,label:"Success Rate",valueKey:"successRate",className:"agent-metric-card--success"},{icon:gt,label:"Total Runs",valueKey:"completedRuns",className:"agent-metric-card--runs"}];function an({stats:a}){return a?e.jsx("div",{className:"agent-metrics-bar",children:sn.map(l=>{const y=l.valueKey==="successRate"?`${Math.round(a.successRate*100)}%`:a[l.valueKey];return e.jsxs("div",{className:`agent-metric-card ${l.className}`,children:[e.jsx(l.icon,{size:18}),e.jsxs("div",{className:"agent-metric-info",children:[e.jsx("span",{className:"agent-metric-value",children:y}),e.jsx("span",{className:"agent-metric-label",children:l.label})]})]},l.label)})}):null}function nt(a){return typeof a=="number"&&Number.isFinite(a)?a:0}function Ie(a){return a.toLocaleString()}function rn({agents:a}){const{rows:l,totalInputTokens:y,totalOutputTokens:d,totalTokens:m}=n.useMemo(()=>{const r=a.map(h=>{const u=nt(h.totalInputTokens),f=nt(h.totalOutputTokens);return{id:h.id,name:h.name,inputTokens:u,outputTokens:f,totalTokens:u+f}}).sort((h,u)=>u.totalTokens-h.totalTokens||h.name.localeCompare(u.name)||h.id.localeCompare(u.id));return{rows:r,totalInputTokens:r.reduce((h,u)=>h+u.inputTokens,0),totalOutputTokens:r.reduce((h,u)=>h+u.outputTokens,0),totalTokens:r.reduce((h,u)=>h+u.totalTokens,0)}},[a]),c=m>0;return e.jsxs("section",{className:"agent-token-stats-panel","aria-label":"Agent token usage statistics",children:[e.jsx("header",{className:"agent-token-stats-panel__header",children:e.jsx("h3",{className:"agent-token-stats-panel__title",children:"Token Usage by Agent"})}),e.jsxs("div",{className:"agent-token-stats-panel__totals",role:"list","aria-label":"Token usage totals",children:[e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Input Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ie(y)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Output Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ie(d)})]}),e.jsxs("div",{className:"agent-token-stats-panel__total-card",role:"listitem",children:[e.jsx("span",{className:"agent-token-stats-panel__total-label",children:"Combined Tokens"}),e.jsx("span",{className:"agent-token-stats-panel__total-value",children:Ie(m)})]})]}),c?e.jsx("div",{className:"agent-token-stats-panel__table-wrapper",children:e.jsxs("table",{className:"agent-token-stats-panel__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"Agent"}),e.jsx("th",{scope:"col",children:"Input"}),e.jsx("th",{scope:"col",children:"Output"}),e.jsx("th",{scope:"col",children:"Total"})]})}),e.jsx("tbody",{children:l.map(r=>e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",className:"agent-token-stats-panel__agent-cell",children:[e.jsx("span",{className:"agent-token-stats-panel__agent-name",children:r.name}),e.jsx("span",{className:"agent-token-stats-panel__agent-id",children:r.id})]}),e.jsx("td",{children:Ie(r.inputTokens)}),e.jsx("td",{children:Ie(r.outputTokens)}),e.jsx("td",{className:"agent-token-stats-panel__total-cell",children:Ie(r.totalTokens)})]},r.id))})]})}):e.jsx("div",{className:"agent-token-stats-panel__empty",role:"status",children:"No token usage recorded yet. Token totals appear here once agents run."})]})}function Me({title:a="No agents found",description:l="Create an agent to get started",ctaLabel:y="Create Agent",onCtaClick:d}){return e.jsxs("div",{className:"agent-empty",children:[e.jsx(Ge,{size:48,opacity:.3,className:"agent-empty-state__icon"}),e.jsx("p",{className:"agent-empty-state__title",children:a}),e.jsx("p",{className:"agent-empty-state__description text-secondary",children:l}),d?e.jsx("button",{type:"button",className:"btn btn-task-create btn-sm",onClick:d,children:y}):null]})}const ct="fn-agent-tree-expanded";function st(a){try{const l=Ue(ct,a);if(l){const y=JSON.parse(l);return new Set(Array.isArray(y)?y:[])}}catch{}return new Set}function ln(a,l){try{rt(ct,JSON.stringify([...a]),l)}catch{}}function on(a,l){const y=new Map,d=new Map;for(const c of a)if(y.set(c.id,c),c.reportsTo){const r=d.get(c.reportsTo)??[];r.push(c),d.set(c.reportsTo,r)}function m(c,r){const h=d.get(c.id)??[],u=l.has(c.id)?h.map(f=>m(f,r+1)):[];return{agent:c,children:u,depth:r}}return a.filter(c=>!c.reportsTo||!y.has(c.reportsTo)).map(c=>m(c,0))}function cn(a,l){const[y,d]=n.useState(()=>st(l));n.useEffect(()=>{d(st(l))},[l]);const m=n.useMemo(()=>on(a,y),[a,y]),c=n.useCallback(u=>{d(f=>{const g=new Set(f);return g.has(u)?g.delete(u):g.add(u),ln(g,l),g})},[l]),r=n.useCallback(u=>y.has(u),[y]),h=n.useCallback(u=>a.filter(f=>f.reportsTo===u),[a]);return{rootNodes:m,toggleExpand:c,isExpanded:r,getChildren:h,isLoading:!1}}const at=3,qe=1e3;function dn({isOpen:a,onClose:l,onGenerated:y,projectId:d}){const[m,c]=n.useState(""),[r,h]=n.useState({type:"input"}),[u,f]=n.useState(null),[g,C]=n.useState(!1),b=n.useRef(null),E=n.useRef(null);n.useEffect(()=>{a&&r.type==="input"&&E.current?.focus()},[a,r.type]),n.useEffect(()=>{if(!a&&b.current){const x=b.current;b.current=null,De(x,d).catch(()=>{})}},[a,d]),n.useEffect(()=>{if(!a)return;const x=R=>{R.key==="Escape"&&p()};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[a]);const p=n.useCallback(()=>{if(b.current){const x=b.current;b.current=null,De(x,d).catch(()=>{})}c(""),h({type:"input"}),f(null),C(!1),l()},[l,d]),M=n.useCallback(async()=>{if(!(!m.trim()||m.trim().length<at)){f(null),h({type:"loading"});try{const{sessionId:x}=await pt(m.trim(),d);b.current=x;const{spec:R}=await ft(x,d);h({type:"preview",spec:R,sessionId:x})}catch(x){const R=x instanceof Error?x.message:"Failed to generate agent specification";R.includes("429")||R.toLowerCase().includes("rate limit")?f("Too many requests. Please wait a moment and try again."):f(R),h({type:"input"}),b.current=null}}},[m,d]),k=n.useCallback(async()=>{if(b.current){const x=b.current;b.current=null;try{await De(x,d)}catch{}}await M()},[M,d]),N=n.useCallback(()=>{r.type==="preview"&&(b.current=null,y(r.spec),c(""),h({type:"input"}),f(null),C(!1),l())},[r,y,l]);if(!a)return null;const T=m.trim().length>=at&&m.trim().length<=qe;return e.jsx("div",{className:"agent-dialog-overlay",onClick:x=>{x.target===x.currentTarget&&p()},children:e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Generate agent with AI",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsxs("span",{className:"agent-dialog-header-title",children:[e.jsx("span",{className:"agent-dialog-header-sparkle",children:"✨"}),"Generate Agent"]}),e.jsx("button",{className:"modal-close",onClick:p,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[u&&e.jsx("div",{className:"agent-dialog-error-banner",children:u}),r.type==="input"&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Describe your agent's role and the AI will generate a complete specification including system prompt, suggested configuration, and more."}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-role-description",children:"Role Description"}),e.jsx("textarea",{ref:E,id:"agent-role-description",className:"input agent-dialog-textarea",rows:4,placeholder:'e.g. "Senior frontend code reviewer who specializes in React accessibility"',value:m,onChange:x=>c(x.target.value),onKeyDown:x=>{x.key==="Enter"&&!x.shiftKey&&T&&(x.preventDefault(),M())},maxLength:qe,"aria-describedby":"role-description-hint"}),e.jsxs("div",{id:"role-description-hint",className:"agent-dialog-hint",children:[e.jsx("span",{children:"Describe what your agent should do"}),e.jsxs("span",{children:[m.length,"/",qe]})]})]})]}),r.type==="loading"&&e.jsxs("div",{className:"agent-dialog-loading-center",children:[e.jsx("div",{className:"agent-dialog-spinner spin"}),e.jsx("p",{className:"agent-dialog-loading-text",children:"Generating agent specification..."})]}),r.type==="preview"&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-summary agent-dialog-summary--spaced",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Title"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[r.spec.icon," ",r.spec.title]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Role"}),e.jsx("span",{children:r.spec.role})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Description"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--body",children:r.spec.description})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value agent-dialog-summary-row-value--capitalize",children:r.spec.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label agent-dialog-summary-row-label--fixed",children:"Max Turns"}),e.jsx("span",{children:r.spec.maxTurns})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{children:["System Prompt",e.jsx("button",{type:"button",className:"agent-dialog-expand-btn",onClick:()=>C(!g),children:g?"Collapse":"Expand"})]}),e.jsxs("div",{className:`agent-generation-prompt-box${g?"":" agent-generation-prompt-box--collapsed"}`,children:[r.spec.systemPrompt,!g&&r.spec.systemPrompt.length>500&&e.jsx("div",{className:"agent-generation-prompt-fade"})]})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[e.jsx("button",{className:"btn",onClick:p,children:"Cancel"}),r.type==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void M(),disabled:!T,children:"Generate"}),r.type==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn",onClick:()=>void k(),children:"Regenerate"}),e.jsx("button",{className:"btn btn-task-create",onClick:N,children:"Use This"})]})]})]})})}const un=`# Soul: Chief Executive Officer
18
18
 
19
19
  I am a strategic leader who connects every decision to business outcomes.
20
20
 
@@ -367,7 +367,7 @@ I am a data-driven marketer who tests assumptions and scales what works. I write
367
367
  ## Communication Style
368
368
 
369
369
  I write copy briefs that specify audience, channel, tone, and success criteria. I present campaign results with interpretation, not just numbers. I escalate messaging concerns when they conflict with product positioning.
370
- `,En=`# Soul: Technical Writer
370
+ `,An=`# Soul: Technical Writer
371
371
 
372
372
  I am a clarity-focused writer who makes complex topics accessible. I write for the reader, not for myself, and I verify every instruction by following it myself.
373
373
 
@@ -388,7 +388,7 @@ I am a clarity-focused writer who makes complex topics accessible. I write for t
388
388
  ## Communication Style
389
389
 
390
390
  I write with the reader's expertise level in mind—not my own. I escalate documentation debt when I see discrepancies. I verify docs work by following them myself.
391
- `,An=`# Soul: Task Triage Agent
391
+ `,En=`# Soul: Task Triage Agent
392
392
 
393
393
  I am a precise and thorough triage agent who transforms vague ideas into actionable specifications. I ask clarifying questions when requirements are ambiguous and never assume context.
394
394
 
@@ -500,11 +500,11 @@ Keep component variants minimal — add new variants only when existing ones don
500
500
  Ensure marketing claims are accurate and verifiable by the product.
501
501
  Segment messaging for different audience personas and channels.
502
502
  Include clear calls-to-action in all content.
503
- Track and report campaign performance with actionable insights.`},{id:"technical-writer",name:"Technical Writer",icon:"≡",title:"Technical Writer",role:"custom",description:"Writes and maintains documentation, API references, and guides that help users and developers succeed.",soul:En,instructionsText:`Write procedural docs with numbered steps and expected outcomes.
503
+ Track and report campaign performance with actionable insights.`},{id:"technical-writer",name:"Technical Writer",icon:"≡",title:"Technical Writer",role:"custom",description:"Writes and maintains documentation, API references, and guides that help users and developers succeed.",soul:An,instructionsText:`Write procedural docs with numbered steps and expected outcomes.
504
504
  Include code examples that are complete, runnable, and tested.
505
505
  Use consistent terminology — define terms on first use and stick to them.
506
506
  Update documentation when code behavior changes — treat docs as code.
507
- Structure content with clear headings for easy scanning and navigation.`},{id:"triage",name:"Triage Agent",icon:"⊕",title:"Task Triage Agent",role:"triage",description:"Analyzes incoming tasks, generates detailed specifications, and prepares PROMPT.md files for execution.",soul:An,instructionsText:`Generate detailed PROMPT.md files with clear steps and acceptance criteria.
507
+ Structure content with clear headings for easy scanning and navigation.`},{id:"triage",name:"Triage Agent",icon:"⊕",title:"Task Triage Agent",role:"triage",description:"Analyzes incoming tasks, generates detailed specifications, and prepares PROMPT.md files for execution.",soul:En,instructionsText:`Generate detailed PROMPT.md files with clear steps and acceptance criteria.
508
508
  Identify missing information and flag ambiguities before specification.
509
509
  Break complex tasks into well-defined, sequenced implementation steps.
510
510
  Specify file scope and dependencies for each task.
@@ -512,11 +512,11 @@ Include relevant context files for the executor to read first.`},{id:"reviewer",
512
512
  Verify error handling is explicit and informative, not silent failures.
513
513
  Ensure new code follows existing patterns and conventions in the codebase.
514
514
  Look for missing tests on new logic paths, especially edge cases.
515
- Flag performance concerns only when they have measurable impact.`}];function Rn({value:a,onChange:l,projectId:y,disabled:d=!1,id:m,label:c="Skills"}){const[r,h]=n.useState([]),[u,v]=n.useState(!0);n.useEffect(()=>{let p=!1;return v(!0),ft(y).then(T=>{p||h(T)}).catch(()=>{p||h([])}).finally(()=>{p||v(!1)}),()=>{p=!0}},[y]);const g=p=>{a.includes(p)||l([...a,p])},C=p=>{l(a.filter(T=>T!==p))},b=p=>r.find(f=>f.id===p)?.name??p,E=r.filter(p=>!a.includes(p.id));return e.jsxs("div",{className:"skill-multiselect","data-testid":"skill-multiselect",children:[c&&e.jsx("label",{htmlFor:m?`${m}-select`:void 0,className:"skill-multiselect-label",children:c}),a.length>0&&e.jsx("div",{className:"skill-multiselect-chips","data-testid":"skill-chips",children:a.map(p=>e.jsxs("span",{className:"skill-chip","data-testid":`skill-chip-${p}`,children:[e.jsx("span",{className:"skill-chip-name",children:b(p)}),e.jsx("button",{type:"button",className:"skill-chip-remove",onClick:()=>C(p),disabled:d,"aria-label":`Remove ${b(p)}`,"data-testid":`remove-skill-${p}`,children:"×"})]},p))}),e.jsx("div",{className:"skill-multiselect-add",children:u?e.jsx("span",{className:"skill-multiselect-loading","data-testid":"skills-loading",children:"Loading skills…"}):E.length===0?e.jsx("span",{className:"skill-multiselect-empty","data-testid":"skills-empty",children:a.length===0?"No skills discovered":"All skills selected"}):e.jsxs("select",{id:m?`${m}-select`:void 0,className:"select skill-multiselect-dropdown",value:"",onChange:p=>{p.target.value&&(g(p.target.value),p.target.value="")},disabled:d,"data-testid":"skill-dropdown",children:[e.jsx("option",{value:"",children:"Add a skill…"}),E.map(p=>e.jsx("option",{value:p.id,children:p.name},p.id))]})})]})}const at=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],_n=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Pn({isOpen:a,onClose:l,onCreated:y,projectId:d}){const[m,c]=n.useState(0),[r,h]=n.useState("presets"),[u,v]=n.useState(""),[g,C]=n.useState(""),[b,E]=n.useState(""),[p,T]=n.useState("custom"),[f,A]=n.useState(""),[M,k]=n.useState(""),[_,te]=n.useState(""),[ae,X]=n.useState(""),[Q,ce]=n.useState(""),[q,P]=n.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[I,xe]=n.useState(null),[H,pe]=n.useState([]),[de,ne]=n.useState(!1),[fe,B]=n.useState(null),[Z,G]=n.useState(!1),[L,ie]=n.useState([]),[ue,re]=n.useState(!1),[O,V]=n.useState([]),[J,me]=n.useState([]),[W,he]=n.useState("model"),[Y,oe]=n.useState(""),[ee,ve]=n.useState([]),[we,D]=n.useState(!1),[K,be]=n.useState([]),[je,ke]=n.useState(!1);n.useEffect(()=>{a&&(re(!0),vt().then(s=>{ie(s.models),V(s.favoriteProviders),me(s.favoriteModels)}).catch(()=>{}).finally(()=>re(!1)))},[a]),n.useEffect(()=>{a&&(ke(!0),be([]),bt(void 0,d).then(s=>{be(s)}).catch(()=>{be([])}).finally(()=>ke(!1)))},[a,d]),n.useEffect(()=>{if(!a)return;const s=yt;if(typeof s!="function"){ve([]),D(!1);return}D(!0),ve([]),s(d).then(N=>{ve(N)}).catch(()=>{ve([])}).finally(()=>D(!1))},[a,d]);const se=q.model.includes("/")?q.model:"",Se=n.useCallback(s=>{const N=_n.has(s.role)?s.role:"custom";v(s.title),C(s.description),E(s.icon),T(N),te(s.systemPrompt),P(le=>({...le,thinkingLevel:s.thinkingLevel,maxTurns:s.maxTurns})),G(!1),c(1)},[]),Ee=n.useCallback(s=>{P(N=>({...N,model:s}))},[]),i=n.useCallback(s=>{he(s),s==="model"&&oe("")},[]),w=n.useCallback(async s=>{const N=O,x=N.includes(s)?N.filter(F=>F!==s):[s,...N];V(x);try{await Ge({favoriteProviders:x,favoriteModels:J})}catch{V(N)}},[O,J]),R=n.useCallback(async s=>{const N=J,x=N.includes(s)?N.filter(F=>F!==s):[s,...N];me(x);try{await Ge({favoriteProviders:O,favoriteModels:x})}catch{me(N)}},[O,J]),U=n.useCallback(s=>{xe(s.id),v(s.name),E(s.icon),C(s.description??s.title),T(s.role),X(s.soul??""),te(s.instructionsText??""),c(1)},[]);if(!a)return null;const $=()=>{c(0),h("presets"),v(""),C(""),E(""),T("custom"),A(""),k(""),te(""),X(""),ce(""),P({model:"",thinkingLevel:"off",maxTurns:1e3}),he("model"),oe(""),xe(null),pe([]),B(null),G(!1),l()},z=async()=>{if(u.trim()){ne(!0),B(null);try{const s={};W==="runtime"?Y.trim()&&(s.runtimeHint=Y.trim()):q.model.trim()&&(s.model=q.model.trim()),q.thinkingLevel!=="off"&&(s.thinkingLevel=q.thinkingLevel),q.maxTurns!==1e3&&(s.maxTurns=q.maxTurns),await jt({name:u.trim(),role:p,...g.trim()?{title:g.trim()}:{},...b.trim()?{icon:b.trim()}:{},...f.trim()?{reportsTo:f.trim()}:{},...M.trim()?{instructionsPath:M.trim()}:{},..._.trim()?{instructionsText:_.trim()}:{},...ae.trim()?{soul:ae.trim()}:{},...Q.trim()?{memory:Q.trim()}:{},...Object.keys(s).length>0?{runtimeConfig:s}:{},...H.length>0?{metadata:{skills:H}}:{}},d),$(),y()}catch(s){B(s instanceof Error?s.message:"Failed to create agent")}finally{ne(!1)}}},Ne=at.find(s=>s.value===p),t=f.trim(),o=t?K.find(s=>s.id===t):void 0,j=Y?ee.find(s=>s.runtimeId===Y):void 0,S=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:s,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":s,children:[e.jsxs("label",{className:`agent-runtime-mode-option${W==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"model",checked:W==="model",onChange:()=>i("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${W==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"runtime",checked:W==="runtime",onChange:()=>i("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),W==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),ue?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(wt,{id:"agent-model",label:"Model",value:se,onChange:Ee,models:L,placeholder:"Select a model…",favoriteProviders:O,onToggleFavorite:w,favoriteModels:J,onToggleModelFavorite:R})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),we?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:Y,onChange:N=>oe(N.target.value),children:[e.jsx("option",{value:"",children:ee.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),ee.map(N=>e.jsx("option",{value:N.runtimeId,children:N.description?`${N.name} — ${N.description}`:N.name},`${N.pluginId}:${N.runtimeId}`))]})]})]});return Wt.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:s=>{s.target===s.currentTarget&&$()},children:[e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Create new agent",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"New Agent"}),e.jsx("button",{className:"btn-icon",onClick:$,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(s=>e.jsx("div",{className:`agent-dialog-step${s===m?" active":s<m?" completed":""}`,"aria-label":`Step ${s+1}`},s))}),e.jsxs("div",{className:"agent-dialog-body",children:[m===0&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-tabs",role:"tablist","aria-label":"Agent setup mode",children:[e.jsx("button",{id:"agent-dialog-tab-presets",type:"button",role:"tab","aria-controls":"agent-dialog-panel-presets","aria-selected":r==="presets",tabIndex:r==="presets"?0:-1,className:`agent-dialog-tab${r==="presets"?" active":""}`,onClick:()=>h("presets"),"data-testid":"agent-dialog-tab-presets",children:"Preset personas"}),e.jsx("button",{id:"agent-dialog-tab-custom",type:"button",role:"tab","aria-controls":"agent-dialog-panel-custom","aria-selected":r==="custom",tabIndex:r==="custom"?0:-1,className:`agent-dialog-tab${r==="custom"?" active":""}`,onClick:()=>h("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),r==="presets"&&e.jsx("div",{id:"agent-dialog-panel-presets",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-presets",children:e.jsxs("div",{className:"agent-presets",children:[e.jsx("div",{className:"agent-presets-header",children:"Choose a preset persona to prefill role, identity, soul, and instructions"}),e.jsx("div",{className:"agent-presets-grid",children:Mn.map(s=>e.jsxs("button",{type:"button",className:`agent-preset-card${I===s.id?" selected":""}`,"data-testid":`preset-${s.id}`,onClick:()=>U(s),title:s.title,children:[e.jsx("span",{className:"agent-preset-icon",children:s.icon}),e.jsx("span",{className:"agent-preset-name",children:s.name}),e.jsx("span",{className:"agent-preset-role",children:s.role}),s.description&&e.jsx("span",{className:"agent-preset-description",children:s.description})]},s.id))})]})}),r==="custom"&&e.jsxs("div",{id:"agent-dialog-panel-custom",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-custom",children:[e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Identity"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-name",children:["Name ",!I&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:u,onChange:s=>v(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-title",children:["Title ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:g,onChange:s=>C(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-icon",children:["Icon ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:b,onChange:s=>E(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:at.map(s=>e.jsxs("button",{type:"button",className:`agent-role-option${p===s.value?" selected":""}`,onClick:()=>T(s.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:s.icon}),e.jsx("span",{className:"agent-role-option-label",children:s.label})]},s.value))})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Configuration"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-reports-to",children:["Reports To ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:f,onChange:s=>A(s.target.value),disabled:je,children:[e.jsx("option",{value:"",children:"No manager"}),K.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.id,")"]},s.id))]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-soul",children:["Soul ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:ae,onChange:s=>X(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-memory",children:["Agent Memory ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-memory",className:"input",rows:2,placeholder:"Private to this agent — durable preferences, operating habits, and context it should carry across tasks...",value:Q,onChange:s=>ce(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-path",children:["Instructions Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:M,onChange:s=>k(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-text",children:["Inline Instructions ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:_,onChange:s=>te(s.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),S("agent-runtime-source-step-0")]}),e.jsxs("div",{className:"agent-dialog-ai-generate",children:[e.jsxs("button",{type:"button",className:"btn btn--ai-generate",onClick:()=>G(!0),children:[e.jsx("span",{children:"✨"}),"Generate with AI"]}),e.jsx("p",{className:"agent-dialog-ai-hint",children:"Describe your agent's role and let AI generate a specification"})]})]})]}),m===1&&e.jsxs("div",{children:[S("agent-runtime-source-step-1"),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-thinking",children:"Thinking Level"}),e.jsxs("select",{id:"agent-thinking",className:"select",value:q.thinkingLevel,onChange:s=>P(N=>({...N,thinkingLevel:s.target.value})),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"minimal",children:"Minimal"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-max-turns",children:"Max Turns"}),e.jsx("input",{id:"agent-max-turns",type:"number",className:"input",min:1,max:2e3,value:q.maxTurns,onChange:s=>P(N=>({...N,maxTurns:Math.max(1,parseInt(s.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(Rn,{id:"agent-skills",label:"Skills",value:H,onChange:pe,projectId:d}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),m===2&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Review your agent configuration before creating."}),e.jsxs("div",{className:"agent-dialog-summary",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Name"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[b&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:b}),u]})]}),g&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Title"}),e.jsx("span",{children:g})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Role"}),e.jsxs("span",{children:[Ne?.icon," ",Ne?.label]})]}),t&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Reports To"}),e.jsx("span",{children:o?`${o.name} (${o.id})`:t})]}),M.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Instructions File"}),e.jsx("span",{children:M.trim()})]}),_.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Inline Instructions"}),e.jsxs("span",{children:[_.trim().length," chars"]})]}),ae.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Soul"}),e.jsxs("span",{children:[ae.trim().length," chars"]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:W==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:W==="runtime"?j?j.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):se?e.jsxs(e.Fragment,{children:[e.jsx(xt,{provider:se.split("/")[0],size:"sm"})," ",(()=>{const s=se.indexOf("/"),N=se.slice(0,s),le=se.slice(s+1);return L.find(F=>F.provider===N&&F.id===le)?.name||se})()]}):e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"default"})})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value--capitalize",children:q.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Max Turns"}),e.jsx("span",{children:q.maxTurns})]}),H.length>0&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Skills"}),e.jsxs("span",{children:[H.length," skill",H.length!==1?"s":""," selected"]})]})]}),fe&&e.jsx("p",{className:"agent-dialog-error",children:fe})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[m>0&&e.jsx("button",{className:"btn",onClick:()=>c(s=>s-1),disabled:de,children:"Back"}),e.jsx("button",{className:"btn",onClick:$,disabled:de,children:"Cancel"}),m<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>c(s=>s+1),disabled:m===0&&!u.trim()&&!I,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void z(),disabled:de||!u.trim(),children:de?"Creating...":"Create"})]})]}),e.jsx(dn,{isOpen:Z,onClose:()=>G(!1),onGenerated:Se,projectId:d})]}),document.body)}function $n(a){const l=a.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!l)throw new Error("Missing YAML frontmatter delimiters (---)");const y=l[1].split(/\r?\n/),d=l[2]??"",m={name:""},c=[];let r=!1;for(const h of y){const v=h.trimEnd().trim();if(!v)continue;if(v.startsWith("skills:")){r=!0;continue}if(r&&v.startsWith("- ")){c.push(v.slice(2).trim());continue}r=!1;const[g,...C]=v.split(":"),E=C.join(":").trim().replace(/^['"]|['"]$/g,"");g==="name"&&(m.name=E),g==="title"&&(m.title=E),g==="icon"&&(m.icon=E),g==="role"&&(m.role=E),g==="reportsTo"&&(m.reportsTo=E)}if(!m.name)throw new Error("Missing required field: name");return c.length>0&&(m.skills=c),d.trim().length>0&&(m.instructionBody=d),m}function Fn({isOpen:a,onClose:l,onImported:y,projectId:d}){const[m,c]=n.useState("input"),[r,h]=n.useState("paste"),[u,v]=n.useState(""),[g,C]=n.useState([]),[b,E]=n.useState("Unknown"),[p,T]=n.useState([]),[f,A]=n.useState([]),[M,k]=n.useState([]),[_,te]=n.useState([]),[ae,X]=n.useState(!1),[Q,ce]=n.useState(!1),[q,P]=n.useState(null),[I,xe]=n.useState(null),[H,pe]=n.useState(null),de=n.useRef(null),ne=n.useRef(null),[fe,B]=n.useState([]),[Z,G]=n.useState(""),[L,ie]=n.useState(null),[ue,re]=n.useState(!1),[O,V]=n.useState(null),J=n.useRef(!1);n.useEffect(()=>{r==="browse"&&!J.current&&!ue&&(J.current=!0,re(!0),V(null),Qe().then(i=>{i.error?V(i.error):i.companies.length>0?B(i.companies):V("No companies available")}).catch(i=>{V(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{re(!1)}))},[r,ue]);const me=n.useCallback(()=>{J.current=!0,V(null),B([]),ie(null),re(!0),Qe().then(i=>{i.error?V(i.error):i.companies.length>0?B(i.companies):V("No companies available")}).catch(i=>{V(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{re(!1)})},[]),W=n.useCallback(()=>{c("input"),h("paste"),v(""),C([]),E("Unknown"),T([]),A([]),k([]),te([]),X(!1),ce(!1),P(null),xe(null),pe(null),B([]),G(""),ie(null),re(!1),V(null),J.current=!1},[]),he=n.useCallback(()=>{W(),l()},[W,l]),Y=n.useCallback(i=>{const w=i.target.files?.[0];if(!w)return;const R=new FileReader;R.onload=U=>{const $=U.target?.result;h("file"),C([]),v($),P(null)},R.onerror=()=>{P("Failed to read file")},R.readAsText(w),i.target.value=""},[]),oe=n.useCallback(async i=>{const w=Array.from(i.target.files??[]);if(w.length!==0)try{const R=w.filter($=>($.webkitRelativePath||$.name).toLowerCase().endsWith("agents.md")).sort(($,z)=>{const Ne=$.webkitRelativePath||$.name,t=z.webkitRelativePath||z.name;return Ne.localeCompare(t)});if(R.length===0){P("Selected directory has no AGENTS.md files");return}const U=[];for(const $ of R){const z=await $.text();U.push($n(z))}h("directory"),C(U),v(""),P(null)}catch{P("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function ee(i){if(!d)return`/api${i}`;const w=i.includes("?")?"&":"?";return`/api${i}${w}projectId=${encodeURIComponent(d)}`}const ve=n.useCallback(async()=>{if(r==="directory"&&g.length===0){P("Please select a directory containing AGENTS.md files");return}if(r==="browse"&&!L){P("Please select a company from the catalog");return}if(r!=="directory"&&r!=="browse"&&!u.trim()){P("Please provide manifest content");return}X(!0),P(null);try{let i;r==="directory"?i={agents:g,dryRun:!0}:r==="browse"&&L?i={importSource:"companies.sh",companySlug:L.slug,dryRun:!0}:i={manifest:u,dryRun:!0};const w=await fetch(ee("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!w.ok){const z=await w.json();throw new Error(z.error??`Parse failed (${w.status})`)}const R=await w.json(),U=R.agents&&R.agents.length>0?R.agents:R.created.map(z=>({name:z,role:"custom"})),$=Array.isArray(R.skills)?R.skills:[];E(R.companyName??"Unknown"),T(U),A($),k(U.map(z=>z.name)),te($.map(z=>z.name)),c("preview")}catch(i){P(i instanceof Error?i.message:"Failed to parse manifest")}finally{X(!1)}},[r,g,u,L,d]),we=n.useCallback(async()=>{ce(!0),pe(null);try{let i;r==="directory"?i={agents:g,skipExisting:!0,selectedAgents:M,selectedSkills:_}:r==="browse"&&L?i={importSource:"companies.sh",companySlug:L.slug,skipExisting:!0,selectedAgents:M,selectedSkills:_}:i={manifest:u,skipExisting:!0,selectedAgents:M,selectedSkills:_};const w=await fetch(ee("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!w.ok){const U=await w.json();throw new Error(U.error??`Import failed (${w.status})`)}const R=await w.json();xe(R),c("result"),y()}catch(i){pe(i instanceof Error?i.message:"Failed to import agents")}finally{ce(!1)}},[r,g,u,L,M,_,d,y]),D=M.length,K=_.length,be=`${D} Agent${D!==1?"s":""}`,je=`${K} Skill${K!==1?"s":""}`,ke=D>0&&K>0?`${be} + ${je}`:K>0?je:be,se=D>0&&K>0?`Importing ${D} agent${D!==1?"s":""} and ${K} skill${K!==1?"s":""}...`:K>0?`Importing ${K} skill${K!==1?"s":""}...`:`Importing ${D} agent${D!==1?"s":""}...`,Se=i=>{k(w=>w.includes(i)?w.filter(R=>R!==i):[...w,i])},Ee=i=>{te(w=>w.includes(i)?w.filter(R=>R!==i):[...w,i])};return a?e.jsx("div",{className:"agent-dialog-overlay",onClick:i=>{i.target===i.currentTarget&&he()},children:e.jsxs("div",{className:"agent-dialog agent-import-dialog",role:"dialog","aria-modal":"true","aria-label":"Import agents",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"Import Agents"}),e.jsx("button",{className:"modal-close",onClick:he,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[m==="input"&&e.jsxs("div",{className:"agent-import-input",children:[e.jsx("p",{className:"agent-import-description",children:"Import agents from an Agent Companies package. Browse the companies.sh catalog to discover published agents, upload an AGENTS.md file, select a directory, or paste manifest content."}),e.jsxs("div",{className:"agent-import-file-upload",children:[e.jsx("input",{ref:de,type:"file",accept:".md,.txt",onChange:Y,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:ne,type:"file",webkitdirectory:"",multiple:!0,onChange:oe,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>de.current?.click(),children:[e.jsx(lt,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>ne.current?.click(),children:[e.jsx(Kt,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{h("browse"),C([]),v(""),ie(null),P(null)},children:[e.jsx(kt,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),r==="browse"&&e.jsxs("div",{className:"agent-import-browse",children:[e.jsxs("div",{className:"agent-import-browse-header",children:[e.jsxs("div",{className:"agent-import-browse-search",children:[e.jsx(Nt,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:Z,onChange:i=>G(i.target.value),"aria-label":"Search companies"})]}),L&&e.jsxs("div",{className:"agent-import-browse-selected",children:[e.jsx("span",{className:"agent-import-browse-selected-label",children:"Selected:"}),e.jsx("span",{className:"agent-import-browse-selected-name",children:L.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>ie(null),children:"Change"})]})]}),ue&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(Le,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),O&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(ze,{size:16}),e.jsx("span",{children:O}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:me,children:[e.jsx(Pe,{size:14}),"Retry"]})]}),!ue&&!O&&e.jsxs("div",{className:"agent-import-browse-list",children:[fe.filter(i=>Z===""||i.name.toLowerCase().includes(Z.toLowerCase())||(i.tagline?.toLowerCase().includes(Z.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${L?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>ie(i),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&ie(i)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:i.name}),i.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[i.installs.toLocaleString()," installs"]})]}),i.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:i.tagline}),i.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:i.repo})]},i.slug)),fe.filter(i=>Z===""||i.name.toLowerCase().includes(Z.toLowerCase())||(i.tagline?.toLowerCase().includes(Z.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:Z?"No companies match your search":"No companies available"})]})]}),r!=="browse"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-divider",children:e.jsx("span",{children:"or paste manifest content"})}),e.jsx("textarea",{className:"agent-import-textarea",placeholder:`---
515
+ Flag performance concerns only when they have measurable impact.`}];function Rn({value:a,onChange:l,projectId:y,disabled:d=!1,id:m,label:c="Skills"}){const[r,h]=n.useState([]),[u,f]=n.useState(!0);n.useEffect(()=>{let p=!1;return f(!0),vt(y).then(M=>{p||h(M)}).catch(()=>{p||h([])}).finally(()=>{p||f(!1)}),()=>{p=!0}},[y]);const g=p=>{a.includes(p)||l([...a,p])},C=p=>{l(a.filter(M=>M!==p))},b=p=>r.find(k=>k.id===p)?.name??p,E=r.filter(p=>!a.includes(p.id));return e.jsxs("div",{className:"skill-multiselect","data-testid":"skill-multiselect",children:[c&&e.jsx("label",{htmlFor:m?`${m}-select`:void 0,className:"skill-multiselect-label",children:c}),a.length>0&&e.jsx("div",{className:"skill-multiselect-chips","data-testid":"skill-chips",children:a.map(p=>e.jsxs("span",{className:"skill-chip","data-testid":`skill-chip-${p}`,children:[e.jsx("span",{className:"skill-chip-name",children:b(p)}),e.jsx("button",{type:"button",className:"skill-chip-remove",onClick:()=>C(p),disabled:d,"aria-label":`Remove ${b(p)}`,"data-testid":`remove-skill-${p}`,children:"×"})]},p))}),e.jsx("div",{className:"skill-multiselect-add",children:u?e.jsx("span",{className:"skill-multiselect-loading","data-testid":"skills-loading",children:"Loading skills…"}):E.length===0?e.jsx("span",{className:"skill-multiselect-empty","data-testid":"skills-empty",children:a.length===0?"No skills discovered":"All skills selected"}):e.jsxs("select",{id:m?`${m}-select`:void 0,className:"select skill-multiselect-dropdown",value:"",onChange:p=>{p.target.value&&(g(p.target.value),p.target.value="")},disabled:d,"data-testid":"skill-dropdown",children:[e.jsx("option",{value:"",children:"Add a skill…"}),E.map(p=>e.jsx("option",{value:p.id,children:p.name},p.id))]})})]})}const it=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],_n=new Set(["triage","executor","reviewer","merger","scheduler","engineer","custom"]);function Pn({isOpen:a,onClose:l,onCreated:y,projectId:d}){const[m,c]=n.useState(0),[r,h]=n.useState("presets"),[u,f]=n.useState(""),[g,C]=n.useState(""),[b,E]=n.useState(""),[p,M]=n.useState("custom"),[k,N]=n.useState(""),[T,x]=n.useState(""),[R,te]=n.useState(""),[ae,X]=n.useState(""),[Q,ce]=n.useState(""),[H,P]=n.useState({model:"",thinkingLevel:"off",maxTurns:1e3}),[S,xe]=n.useState(null),[q,pe]=n.useState([]),[de,ne]=n.useState(!1),[fe,B]=n.useState(null),[Z,G]=n.useState(!1),[L,ie]=n.useState([]),[ue,re]=n.useState(!1),[O,V]=n.useState([]),[J,me]=n.useState([]),[W,he]=n.useState("model"),[Y,oe]=n.useState(""),[ee,ve]=n.useState([]),[we,D]=n.useState(!1),[K,be]=n.useState([]),[je,ke]=n.useState(!1);n.useEffect(()=>{a&&(re(!0),bt().then(s=>{ie(s.models),V(s.favoriteProviders),me(s.favoriteModels)}).catch(()=>{}).finally(()=>re(!1)))},[a]),n.useEffect(()=>{a&&(ke(!0),be([]),xt(void 0,d).then(s=>{be(s)}).catch(()=>{be([])}).finally(()=>ke(!1)))},[a,d]),n.useEffect(()=>{if(!a)return;const s=wt;if(typeof s!="function"){ve([]),D(!1);return}D(!0),ve([]),s(d).then(I=>{ve(I)}).catch(()=>{ve([])}).finally(()=>D(!1))},[a,d]);const se=H.model.includes("/")?H.model:"",Se=n.useCallback(s=>{const I=_n.has(s.role)?s.role:"custom";f(s.title),C(s.description),E(s.icon),M(I),te(s.systemPrompt),P(le=>({...le,thinkingLevel:s.thinkingLevel,maxTurns:s.maxTurns})),G(!1),c(1)},[]),Ae=n.useCallback(s=>{P(I=>({...I,model:s}))},[]),i=n.useCallback(s=>{he(s),s==="model"&&oe("")},[]),w=n.useCallback(async s=>{const I=O,v=I.includes(s)?I.filter(F=>F!==s):[s,...I];V(v);try{await Je({favoriteProviders:v,favoriteModels:J})}catch{V(I)}},[O,J]),_=n.useCallback(async s=>{const I=J,v=I.includes(s)?I.filter(F=>F!==s):[s,...I];me(v);try{await Je({favoriteProviders:O,favoriteModels:v})}catch{me(I)}},[O,J]),U=n.useCallback(s=>{xe(s.id),f(s.name),E(s.icon),C(s.description??s.title),M(s.role),X(s.soul??""),te(s.instructionsText??""),c(1)},[]);if(!a)return null;const $=()=>{c(0),h("presets"),f(""),C(""),E(""),M("custom"),N(""),x(""),te(""),X(""),ce(""),P({model:"",thinkingLevel:"off",maxTurns:1e3}),he("model"),oe(""),xe(null),pe([]),B(null),G(!1),l()},z=async()=>{if(u.trim()){ne(!0),B(null);try{const s={};W==="runtime"?Y.trim()&&(s.runtimeHint=Y.trim()):H.model.trim()&&(s.model=H.model.trim()),H.thinkingLevel!=="off"&&(s.thinkingLevel=H.thinkingLevel),H.maxTurns!==1e3&&(s.maxTurns=H.maxTurns),await kt({name:u.trim(),role:p,...g.trim()?{title:g.trim()}:{},...b.trim()?{icon:b.trim()}:{},...k.trim()?{reportsTo:k.trim()}:{},...T.trim()?{instructionsPath:T.trim()}:{},...R.trim()?{instructionsText:R.trim()}:{},...ae.trim()?{soul:ae.trim()}:{},...Q.trim()?{memory:Q.trim()}:{},...Object.keys(s).length>0?{runtimeConfig:s}:{},...q.length>0?{metadata:{skills:q}}:{}},d),$(),y()}catch(s){B(s instanceof Error?s.message:"Failed to create agent")}finally{ne(!1)}}},Ne=it.find(s=>s.value===p),t=k.trim(),o=t?K.find(s=>s.id===t):void 0,j=Y?ee.find(s=>s.runtimeId===Y):void 0,A=s=>e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{id:s,children:"Runtime Source"}),e.jsxs("div",{className:"agent-runtime-mode-toggle",role:"radiogroup","aria-labelledby":s,children:[e.jsxs("label",{className:`agent-runtime-mode-option${W==="model"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"model",checked:W==="model",onChange:()=>i("model")}),e.jsx("span",{children:"Built-in Model"})]}),e.jsxs("label",{className:`agent-runtime-mode-option${W==="runtime"?" agent-runtime-mode-option--active":""}`,children:[e.jsx("input",{type:"radio",name:s,value:"runtime",checked:W==="runtime",onChange:()=>i("runtime")}),e.jsx("span",{children:"Plugin Runtime"})]})]})]}),W==="model"?e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Model"}),ue?e.jsx("div",{className:"agent-dialog-loading",children:"Loading models…"}):e.jsx(jt,{id:"agent-model",label:"Model",value:se,onChange:Ae,models:L,placeholder:"Select a model…",favoriteProviders:O,onToggleFavorite:w,favoriteModels:J,onToggleModelFavorite:_})]}):e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-runtime-hint",children:"Runtime"}),we?e.jsx("div",{className:"agent-dialog-loading",children:"Loading runtimes…"}):e.jsxs("select",{id:"agent-runtime-hint",className:"select",value:Y,onChange:I=>oe(I.target.value),children:[e.jsx("option",{value:"",children:ee.length>0?"Select a plugin runtime…":"No plugin runtimes available"}),ee.map(I=>e.jsx("option",{value:I.runtimeId,children:I.description?`${I.name} — ${I.description}`:I.name},`${I.pluginId}:${I.runtimeId}`))]})]})]});return Kt.createPortal(e.jsxs("div",{className:"agent-dialog-overlay",onClick:s=>{s.target===s.currentTarget&&$()},children:[e.jsxs("div",{className:"agent-dialog",role:"dialog","aria-modal":"true","aria-label":"Create new agent",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"New Agent"}),e.jsx("button",{className:"btn-icon",onClick:$,"aria-label":"Close",children:"×"})]}),e.jsx("div",{className:"agent-dialog-steps",children:[0,1,2].map(s=>e.jsx("div",{className:`agent-dialog-step${s===m?" active":s<m?" completed":""}`,"aria-label":`Step ${s+1}`},s))}),e.jsxs("div",{className:"agent-dialog-body",children:[m===0&&e.jsxs("div",{children:[e.jsxs("div",{className:"agent-dialog-tabs",role:"tablist","aria-label":"Agent setup mode",children:[e.jsx("button",{id:"agent-dialog-tab-presets",type:"button",role:"tab","aria-controls":"agent-dialog-panel-presets","aria-selected":r==="presets",tabIndex:r==="presets"?0:-1,className:`agent-dialog-tab${r==="presets"?" active":""}`,onClick:()=>h("presets"),"data-testid":"agent-dialog-tab-presets",children:"Preset personas"}),e.jsx("button",{id:"agent-dialog-tab-custom",type:"button",role:"tab","aria-controls":"agent-dialog-panel-custom","aria-selected":r==="custom",tabIndex:r==="custom"?0:-1,className:`agent-dialog-tab${r==="custom"?" active":""}`,onClick:()=>h("custom"),"data-testid":"agent-dialog-tab-custom",children:"Custom agent"})]}),r==="presets"&&e.jsx("div",{id:"agent-dialog-panel-presets",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-presets",children:e.jsxs("div",{className:"agent-presets",children:[e.jsx("div",{className:"agent-presets-header",children:"Choose a preset persona to prefill role, identity, soul, and instructions"}),e.jsx("div",{className:"agent-presets-grid",children:Mn.map(s=>e.jsxs("button",{type:"button",className:`agent-preset-card${S===s.id?" selected":""}`,"data-testid":`preset-${s.id}`,onClick:()=>U(s),title:s.title,children:[e.jsx("span",{className:"agent-preset-icon",children:s.icon}),e.jsx("span",{className:"agent-preset-name",children:s.name}),e.jsx("span",{className:"agent-preset-role",children:s.role}),s.description&&e.jsx("span",{className:"agent-preset-description",children:s.description})]},s.id))})]})}),r==="custom"&&e.jsxs("div",{id:"agent-dialog-panel-custom",className:"agent-dialog-tab-panel",role:"tabpanel","aria-labelledby":"agent-dialog-tab-custom",children:[e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Identity"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-name",children:["Name ",!S&&e.jsx("span",{className:"agent-dialog-required",children:"*"})]}),e.jsx("input",{id:"agent-name",type:"text",className:"input",placeholder:"e.g. Frontend Reviewer",value:u,onChange:s=>f(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-title",children:["Title ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-title",type:"text",className:"input",placeholder:"e.g. Senior Code Reviewer",value:g,onChange:s=>C(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-icon",children:["Icon ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-icon",type:"text",className:"input",placeholder:"e.g. 🤖",value:b,onChange:s=>E(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{children:"Role"}),e.jsx("div",{className:"agent-role-grid",children:it.map(s=>e.jsxs("button",{type:"button",className:`agent-role-option${p===s.value?" selected":""}`,onClick:()=>M(s.value),children:[e.jsx("span",{className:"agent-role-option-icon",children:s.icon}),e.jsx("span",{className:"agent-role-option-label",children:s.label})]},s.value))})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Configuration"}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-reports-to",children:["Reports To ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsxs("select",{id:"agent-reports-to",className:"select",value:k,onChange:s=>N(s.target.value),disabled:je,children:[e.jsx("option",{value:"",children:"No manager"}),K.map(s=>e.jsxs("option",{value:s.id,children:[s.name," (",s.id,")"]},s.id))]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-soul",children:["Soul ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-soul",className:"input",rows:2,placeholder:"Describe the agent's personality and communication style...",value:ae,onChange:s=>X(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-memory",children:["Agent Memory ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-memory",className:"input",rows:2,placeholder:"Private to this agent — durable preferences, operating habits, and context it should carry across tasks...",value:Q,onChange:s=>ce(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-path",children:["Instructions Path ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("input",{id:"agent-instructions-path",type:"text",className:"input",placeholder:"e.g. .fusion/agents/reviewer.md",value:T,onChange:s=>x(s.target.value)})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsxs("label",{htmlFor:"agent-instructions-text",children:["Inline Instructions ",e.jsx("span",{className:"agent-dialog-optional",children:"(optional)"})]}),e.jsx("textarea",{id:"agent-instructions-text",className:"input",rows:4,placeholder:"Add custom behavior instructions...",value:R,onChange:s=>te(s.target.value)})]})]}),e.jsxs("div",{className:"agent-dialog-section",children:[e.jsx("div",{className:"agent-dialog-section-header",children:"Runtime"}),A("agent-runtime-source-step-0")]}),e.jsxs("div",{className:"agent-dialog-ai-generate",children:[e.jsxs("button",{type:"button",className:"btn btn--ai-generate",onClick:()=>G(!0),children:[e.jsx("span",{children:"✨"}),"Generate with AI"]}),e.jsx("p",{className:"agent-dialog-ai-hint",children:"Describe your agent's role and let AI generate a specification"})]})]})]}),m===1&&e.jsxs("div",{children:[A("agent-runtime-source-step-1"),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-thinking",children:"Thinking Level"}),e.jsxs("select",{id:"agent-thinking",className:"select",value:H.thinkingLevel,onChange:s=>P(I=>({...I,thinkingLevel:s.target.value})),children:[e.jsx("option",{value:"off",children:"Off"}),e.jsx("option",{value:"minimal",children:"Minimal"}),e.jsx("option",{value:"low",children:"Low"}),e.jsx("option",{value:"medium",children:"Medium"}),e.jsx("option",{value:"high",children:"High"})]})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx("label",{htmlFor:"agent-max-turns",children:"Max Turns"}),e.jsx("input",{id:"agent-max-turns",type:"number",className:"input",min:1,max:2e3,value:H.maxTurns,onChange:s=>P(I=>({...I,maxTurns:Math.max(1,parseInt(s.target.value,10)||1)}))})]}),e.jsxs("div",{className:"agent-dialog-field",children:[e.jsx(Rn,{id:"agent-skills",label:"Skills",value:q,onChange:pe,projectId:d}),e.jsx("p",{className:"agent-dialog-optional agent-dialog-skills-hint",children:"Optional skills to assign to this agent"})]})]}),m===2&&e.jsxs("div",{children:[e.jsx("p",{className:"agent-dialog-info",children:"Review your agent configuration before creating."}),e.jsxs("div",{className:"agent-dialog-summary",children:[e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Name"}),e.jsxs("span",{className:"agent-dialog-summary-row-value",children:[b&&e.jsx("span",{className:"agent-dialog-icon-prefix",children:b}),u]})]}),g&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Title"}),e.jsx("span",{children:g})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Role"}),e.jsxs("span",{children:[Ne?.icon," ",Ne?.label]})]}),t&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Reports To"}),e.jsx("span",{children:o?`${o.name} (${o.id})`:t})]}),T.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Instructions File"}),e.jsx("span",{children:T.trim()})]}),R.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Inline Instructions"}),e.jsxs("span",{children:[R.trim().length," chars"]})]}),ae.trim()&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Soul"}),e.jsxs("span",{children:[ae.trim().length," chars"]})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:W==="runtime"?"Runtime":"Model"}),e.jsx("span",{children:W==="runtime"?j?j.name:e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"Not selected"}):se?e.jsxs(e.Fragment,{children:[e.jsx(yt,{provider:se.split("/")[0],size:"sm"})," ",(()=>{const s=se.indexOf("/"),I=se.slice(0,s),le=se.slice(s+1);return L.find(F=>F.provider===I&&F.id===le)?.name||se})()]}):e.jsx("em",{className:"agent-dialog-summary-row-value--muted",children:"default"})})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Thinking"}),e.jsx("span",{className:"agent-dialog-summary-row-value--capitalize",children:H.thinkingLevel})]}),e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Max Turns"}),e.jsx("span",{children:H.maxTurns})]}),q.length>0&&e.jsxs("div",{className:"agent-dialog-summary-row",children:[e.jsx("span",{className:"agent-dialog-summary-row-label",children:"Skills"}),e.jsxs("span",{children:[q.length," skill",q.length!==1?"s":""," selected"]})]})]}),fe&&e.jsx("p",{className:"agent-dialog-error",children:fe})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[m>0&&e.jsx("button",{className:"btn",onClick:()=>c(s=>s-1),disabled:de,children:"Back"}),e.jsx("button",{className:"btn",onClick:$,disabled:de,children:"Cancel"}),m<2?e.jsx("button",{className:"btn btn--primary",onClick:()=>c(s=>s+1),disabled:m===0&&!u.trim()&&!S,children:"Next"}):e.jsx("button",{className:"btn btn--primary",onClick:()=>void z(),disabled:de||!u.trim(),children:de?"Creating...":"Create"})]})]}),e.jsx(dn,{isOpen:Z,onClose:()=>G(!1),onGenerated:Se,projectId:d})]}),document.body)}function $n(a){const l=a.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);if(!l)throw new Error("Missing YAML frontmatter delimiters (---)");const y=l[1].split(/\r?\n/),d=l[2]??"",m={name:""},c=[];let r=!1;for(const h of y){const f=h.trimEnd().trim();if(!f)continue;if(f.startsWith("skills:")){r=!0;continue}if(r&&f.startsWith("- ")){c.push(f.slice(2).trim());continue}r=!1;const[g,...C]=f.split(":"),E=C.join(":").trim().replace(/^['"]|['"]$/g,"");g==="name"&&(m.name=E),g==="title"&&(m.title=E),g==="icon"&&(m.icon=E),g==="role"&&(m.role=E),g==="reportsTo"&&(m.reportsTo=E)}if(!m.name)throw new Error("Missing required field: name");return c.length>0&&(m.skills=c),d.trim().length>0&&(m.instructionBody=d),m}function Fn({isOpen:a,onClose:l,onImported:y,projectId:d}){const[m,c]=n.useState("input"),[r,h]=n.useState("paste"),[u,f]=n.useState(""),[g,C]=n.useState([]),[b,E]=n.useState("Unknown"),[p,M]=n.useState([]),[k,N]=n.useState([]),[T,x]=n.useState([]),[R,te]=n.useState([]),[ae,X]=n.useState(!1),[Q,ce]=n.useState(!1),[H,P]=n.useState(null),[S,xe]=n.useState(null),[q,pe]=n.useState(null),de=n.useRef(null),ne=n.useRef(null),[fe,B]=n.useState([]),[Z,G]=n.useState(""),[L,ie]=n.useState(null),[ue,re]=n.useState(!1),[O,V]=n.useState(null),J=n.useRef(!1);n.useEffect(()=>{r==="browse"&&!J.current&&!ue&&(J.current=!0,re(!0),V(null),Xe().then(i=>{i.error?V(i.error):i.companies.length>0?B(i.companies):V("No companies available")}).catch(i=>{V(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{re(!1)}))},[r,ue]);const me=n.useCallback(()=>{J.current=!0,V(null),B([]),ie(null),re(!0),Xe().then(i=>{i.error?V(i.error):i.companies.length>0?B(i.companies):V("No companies available")}).catch(i=>{V(i instanceof Error?i.message:"Failed to load companies")}).finally(()=>{re(!1)})},[]),W=n.useCallback(()=>{c("input"),h("paste"),f(""),C([]),E("Unknown"),M([]),N([]),x([]),te([]),X(!1),ce(!1),P(null),xe(null),pe(null),B([]),G(""),ie(null),re(!1),V(null),J.current=!1},[]),he=n.useCallback(()=>{W(),l()},[W,l]),Y=n.useCallback(i=>{const w=i.target.files?.[0];if(!w)return;const _=new FileReader;_.onload=U=>{const $=U.target?.result;h("file"),C([]),f($),P(null)},_.onerror=()=>{P("Failed to read file")},_.readAsText(w),i.target.value=""},[]),oe=n.useCallback(async i=>{const w=Array.from(i.target.files??[]);if(w.length!==0)try{const _=w.filter($=>($.webkitRelativePath||$.name).toLowerCase().endsWith("agents.md")).sort(($,z)=>{const Ne=$.webkitRelativePath||$.name,t=z.webkitRelativePath||z.name;return Ne.localeCompare(t)});if(_.length===0){P("Selected directory has no AGENTS.md files");return}const U=[];for(const $ of _){const z=await $.text();U.push($n(z))}h("directory"),C(U),f(""),P(null)}catch{P("Failed to parse AGENTS.md files from selected directory")}finally{i.target.value=""}},[]);function ee(i){if(!d)return`/api${i}`;const w=i.includes("?")?"&":"?";return`/api${i}${w}projectId=${encodeURIComponent(d)}`}const ve=n.useCallback(async()=>{if(r==="directory"&&g.length===0){P("Please select a directory containing AGENTS.md files");return}if(r==="browse"&&!L){P("Please select a company from the catalog");return}if(r!=="directory"&&r!=="browse"&&!u.trim()){P("Please provide manifest content");return}X(!0),P(null);try{let i;r==="directory"?i={agents:g,dryRun:!0}:r==="browse"&&L?i={importSource:"companies.sh",companySlug:L.slug,dryRun:!0}:i={manifest:u,dryRun:!0};const w=await fetch(ee("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!w.ok){const z=await w.json();throw new Error(z.error??`Parse failed (${w.status})`)}const _=await w.json(),U=_.agents&&_.agents.length>0?_.agents:_.created.map(z=>({name:z,role:"custom"})),$=Array.isArray(_.skills)?_.skills:[];E(_.companyName??"Unknown"),M(U),N($),x(U.map(z=>z.name)),te($.map(z=>z.name)),c("preview")}catch(i){P(i instanceof Error?i.message:"Failed to parse manifest")}finally{X(!1)}},[r,g,u,L,d]),we=n.useCallback(async()=>{ce(!0),pe(null);try{let i;r==="directory"?i={agents:g,skipExisting:!0,selectedAgents:T,selectedSkills:R}:r==="browse"&&L?i={importSource:"companies.sh",companySlug:L.slug,skipExisting:!0,selectedAgents:T,selectedSkills:R}:i={manifest:u,skipExisting:!0,selectedAgents:T,selectedSkills:R};const w=await fetch(ee("/agents/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!w.ok){const U=await w.json();throw new Error(U.error??`Import failed (${w.status})`)}const _=await w.json();xe(_),c("result"),y()}catch(i){pe(i instanceof Error?i.message:"Failed to import agents")}finally{ce(!1)}},[r,g,u,L,T,R,d,y]),D=T.length,K=R.length,be=`${D} Agent${D!==1?"s":""}`,je=`${K} Skill${K!==1?"s":""}`,ke=D>0&&K>0?`${be} + ${je}`:K>0?je:be,se=D>0&&K>0?`Importing ${D} agent${D!==1?"s":""} and ${K} skill${K!==1?"s":""}...`:K>0?`Importing ${K} skill${K!==1?"s":""}...`:`Importing ${D} agent${D!==1?"s":""}...`,Se=i=>{x(w=>w.includes(i)?w.filter(_=>_!==i):[...w,i])},Ae=i=>{te(w=>w.includes(i)?w.filter(_=>_!==i):[...w,i])};return a?e.jsx("div",{className:"agent-dialog-overlay",onClick:i=>{i.target===i.currentTarget&&he()},children:e.jsxs("div",{className:"agent-dialog agent-import-dialog",role:"dialog","aria-modal":"true","aria-label":"Import agents",children:[e.jsxs("div",{className:"agent-dialog-header",children:[e.jsx("span",{className:"agent-dialog-header-title",children:"Import Agents"}),e.jsx("button",{className:"modal-close",onClick:he,"aria-label":"Close",children:"×"})]}),e.jsxs("div",{className:"agent-dialog-body",children:[m==="input"&&e.jsxs("div",{className:"agent-import-input",children:[e.jsx("p",{className:"agent-import-description",children:"Import agents from an Agent Companies package. Browse the companies.sh catalog to discover published agents, upload an AGENTS.md file, select a directory, or paste manifest content."}),e.jsxs("div",{className:"agent-import-file-upload",children:[e.jsx("input",{ref:de,type:"file",accept:".md,.txt",onChange:Y,className:"agent-import-file-input","aria-label":"Upload agent manifest file"}),e.jsx("input",{ref:ne,type:"file",webkitdirectory:"",multiple:!0,onChange:oe,className:"agent-import-file-input","aria-label":"Select directory"}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>de.current?.click(),children:[e.jsx(ot,{size:16}),"Choose File"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>ne.current?.click(),children:[e.jsx(Ut,{size:16}),"Select Directory"]}),e.jsxs("button",{type:"button",className:"btn agent-import-upload-btn",onClick:()=>{h("browse"),C([]),f(""),ie(null),P(null)},children:[e.jsx(Nt,{size:16}),"Browse Catalog"]}),e.jsx("span",{className:"agent-import-file-hint",children:".md and .txt files supported"})]}),r==="browse"&&e.jsxs("div",{className:"agent-import-browse",children:[e.jsxs("div",{className:"agent-import-browse-header",children:[e.jsxs("div",{className:"agent-import-browse-search",children:[e.jsx(It,{size:16,className:"agent-import-browse-search-icon"}),e.jsx("input",{type:"text",className:"agent-import-browse-search-input",placeholder:"Search companies...",value:Z,onChange:i=>G(i.target.value),"aria-label":"Search companies"})]}),L&&e.jsxs("div",{className:"agent-import-browse-selected",children:[e.jsx("span",{className:"agent-import-browse-selected-label",children:"Selected:"}),e.jsx("span",{className:"agent-import-browse-selected-name",children:L.name}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>ie(null),children:"Change"})]})]}),ue&&e.jsxs("div",{className:"agent-import-browse-loading",children:[e.jsx(Le,{size:20,className:"spin"}),e.jsx("span",{children:"Loading companies..."})]}),O&&e.jsxs("div",{className:"agent-import-browse-error",children:[e.jsx(ze,{size:16}),e.jsx("span",{children:O}),e.jsxs("button",{type:"button",className:"btn btn-sm",onClick:me,children:[e.jsx(Pe,{size:14}),"Retry"]})]}),!ue&&!O&&e.jsxs("div",{className:"agent-import-browse-list",children:[fe.filter(i=>Z===""||i.name.toLowerCase().includes(Z.toLowerCase())||(i.tagline?.toLowerCase().includes(Z.toLowerCase())??!1)).map(i=>e.jsxs("div",{className:`agent-import-browse-item ${L?.slug===i.slug?"agent-import-browse-item--selected":""}`,onClick:()=>ie(i),role:"button",tabIndex:0,onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&ie(i)},children:[e.jsxs("div",{className:"agent-import-browse-item-header",children:[e.jsx("span",{className:"agent-import-browse-item-name",children:i.name}),i.installs!==void 0&&e.jsxs("span",{className:"agent-import-browse-item-installs",children:[i.installs.toLocaleString()," installs"]})]}),i.tagline&&e.jsx("span",{className:"agent-import-browse-item-tagline",children:i.tagline}),i.repo&&e.jsx("span",{className:"agent-import-browse-item-repo",children:i.repo})]},i.slug)),fe.filter(i=>Z===""||i.name.toLowerCase().includes(Z.toLowerCase())||(i.tagline?.toLowerCase().includes(Z.toLowerCase())??!1)).length===0&&e.jsx("p",{className:"agent-import-browse-empty",children:Z?"No companies match your search":"No companies available"})]})]}),r!=="browse"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-divider",children:e.jsx("span",{children:"or paste manifest content"})}),e.jsx("textarea",{className:"agent-import-textarea",placeholder:`---
516
516
  name: CEO
517
517
  title: Chief Executive Officer
518
518
  reportsTo: null
519
519
  skills:
520
520
  - review
521
521
  ---
522
- Agent instructions go here...`,value:u,onChange:i=>{h("paste"),C([]),v(i.target.value),P(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),q&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(ze,{size:14}),q]})]}),m==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:b})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Ve,{size:14}),e.jsxs("span",{children:[p.length," agent",p.length!==1?"s":""," found"]})]}),p.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>k(p.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>k([]),children:"Clear agents"})]}),p.length>0?e.jsx("div",{className:"agent-import-agent-list",children:p.map((i,w)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:M.includes(i.name),onChange:()=>Se(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},w))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),f.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Ve,{size:14}),e.jsxs("span",{children:[f.length," skill",f.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>te(f.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>te([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:f.map((i,w)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:_.includes(i.name),onChange:()=>Ee(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${w}`))})]}),H&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(ze,{size:14}),H]})]}),m==="result"&&I&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(_e,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:I.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[I.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[I.created.length," created"]})}),I.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[I.skipped.length," skipped (already exist)"]})}),I.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[I.errors.length," error",I.errors.length!==1?"s":""]})})]}),I.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:I.created.map((i,w)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(_e,{size:12}),e.jsx("span",{children:i.name})]},w))}),I.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:I.errors.map((i,w)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Je,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},w))}),I.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[I.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[I.skills.imported.length," skill",I.skills.imported.length!==1?"s":""," imported"]})}),I.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[I.skills.skipped.length," skill",I.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),I.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[I.skills.errors.length," skill",I.skills.errors.length!==1?"s":""," error",I.skills.errors.length!==1?"s":""]})}),I.skills.imported.length===0&&I.skills.skipped.length===0&&I.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),I.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:I.skills.imported.map((i,w)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(_e,{size:12}),e.jsx("span",{children:i.name})]},w))}),I.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:I.skills.errors.map((i,w)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Je,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},w))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[m==="preview"&&e.jsx("button",{className:"btn",onClick:()=>c("input"),disabled:Q,children:"Back"}),e.jsx("button",{className:"btn",onClick:he,disabled:Q,children:m==="result"?"Close":"Cancel"}),m==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ve(),disabled:ae||(r==="directory"?g.length===0:r==="browse"?!L:!u.trim()),children:ae?e.jsxs(e.Fragment,{children:[e.jsx(Le,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),m==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void we(),disabled:Q||D===0&&K===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(Le,{size:14,className:"spin"}),se]}):`Import ${ke}`})]})]})}):null}const Dn=n.lazy(()=>Vt(()=>import("./AgentDetailView-Ca1euvPo.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(a=>({default:a.AgentDetailView}))),Re=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],He=[.1,.25,.5,1,2,3,5,10];function $e(a){switch(a){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function Fe(a,l){switch(l){case"running":return`${a}--running`;case"active":return`${a}--active`;case"paused":return`${a}--paused`;case"error":return`${a}--error`;case"terminated":return`${a}--terminated`;case"idle":default:return`${a}--idle`}}function ct({node:a,onSelect:l,onToggle:y,isExpanded:d,getChildCount:m,getHealthStatus:c,getRoleIcon:r,getSkillBadges:h}){const{agent:u,children:v,depth:g}=a,C=m(u.id),b=d(u.id),E=c(u),p=$e(u.state),T=Fe("agent-tree__node",u.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${T}${u.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(g,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${C===0?" agent-tree__toggle--leaf":""}`,onClick:()=>C>0&&y(u.id),title:C>0?b?"Collapse":"Expand":"No employees","aria-label":C>0?b?"Collapse":"Expand":"No employees",children:C>0?b?e.jsx(Dt,{size:16}):e.jsx(rt,{size:16}):e.jsx(Ue,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:f=>f.key==="Enter"&&l(u.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(u.role)}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:`agent-tree__badge ${p}`,children:u.state}),e.jsx("span",{className:"agent-tree__health",style:{color:E.color},title:E.label,children:E.icon}),C>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",C,")"]}),(()=>{const f=h(u);return f.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:f.join(", "),children:[f[0],f.length>1&&` +${f.length-1}`]})})()]})]}),b&&v.length>0&&e.jsx("div",{className:"agent-tree__children",children:v.map(f=>e.jsx(ct,{node:f,onSelect:l,onToggle:y,isExpanded:d,getChildCount:m,getHealthStatus:c,getRoleIcon:r,getSkillBadges:h},f.agent.id))})]})}function dt({node:a,onSelect:l,getHealthStatus:y,getRoleIcon:d,getSkillBadges:m}){const{agent:c,children:r}=a,h=y(c),u=$e(c.state),v=Fe("org-chart-node-card",c.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:v,onClick:()=>l(c.id),role:"button",tabIndex:0,onKeyDown:g=>g.key==="Enter"&&l(c.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:d(c.role)}),e.jsx("span",{className:"org-chart-node__name",children:c.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${u}`,children:c.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:h.color},title:h.label,children:[h.icon,!h.stateDerived&&e.jsx("span",{className:"text-secondary",children:h.label})]}),(()=>{const g=m(c);if(g.length===0)return null;const C=g.slice(0,2),b=g.length-2;return e.jsxs(e.Fragment,{children:[C.map(E=>e.jsx("span",{className:"org-chart-node__skill",children:E},E)),b>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",b]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${c.name} employees`,children:r.map(g=>e.jsx(dt,{node:g,onSelect:l,getHealthStatus:y,getRoleIcon:d,getSkillBadges:m},g.agent.id))})]})}function Ln({addToast:a,projectId:l,onOpenTaskLogs:y}){const[d,m]=n.useState(!1),[c,r]=n.useState("all"),{agents:h,stats:u,isLoading:v,loadAgents:g}=It(l,{filterState:c,showSystemAgents:d}),[C,b]=n.useState(!1),[E,p]=n.useState(!1),[T,f]=n.useState(null),[A,M]=n.useState(()=>{if(typeof window>"u")return"list";const t=We("fn-agent-view",l);return t==="list"||t==="board"||t==="tree"||t==="org"?t:"list"}),[k,_]=n.useState([]),[te,ae]=n.useState(!1),[X,Q]=n.useState(!1),ce=n.useRef(null),{confirm:q}=Ct(),P=n.useRef(null),I=n.useId();n.useEffect(()=>{const t=We("fn-agent-view",l);if(t==="list"||t==="board"||t==="tree"||t==="org"){M(t);return}M("list")},[l]),n.useEffect(()=>{it("fn-agent-view",A,l)},[A,l]);const[xe,H]=n.useState(null),pe=n.useRef(null),[de,ne]=n.useState(null),[fe,B]=n.useState(null),[Z,G]=n.useState({}),[L,ie]=n.useState(1),[ue,re]=n.useState(!1),[O,V]=n.useState(new Set),[J,me]=n.useState(new Map),W=n.useRef(!0);n.useEffect(()=>(W.current=!0,()=>{W.current=!1}),[]),n.useEffect(()=>{St(l).then(t=>{W.current&&ie(t.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const he=n.useCallback(async t=>{const o=Number.isFinite(t)&&t>0?t:1;ie(o),re(!0);try{await Et({heartbeatMultiplier:o},l),a(`Heartbeat speed set to ×${o.toFixed(1)}`,"success")}catch(j){a(`Failed to save heartbeat multiplier: ${ge(j)}`,"error")}finally{W.current&&re(!1)}},[l,a]),Y=n.useMemo(()=>J.size===0?h:h.map(t=>{const o=J.get(t.id);return o?{...t,state:o}:t}),[h,J]),oe=cn(Y,l),ee=n.useMemo(()=>Y.filter(t=>d||!Oe(t)),[Y,d]),ve=n.useMemo(()=>Y.filter(t=>t.state!=="active"&&t.state!=="running"?!1:d||!Oe(t)),[Y,d]),we=n.useMemo(()=>{if(d)return k;const t=o=>Oe(o.agent)?null:{...o,children:o.children.map(t).filter(j=>j!==null)};return k.map(t).filter(o=>o!==null)},[k,d]);n.useEffect(()=>{if(A!=="org")return;let t=!1;return ae(!0),At(l,{includeEphemeral:d}).then(o=>{t||_(o)}).catch(o=>{t||(a(`Failed to load org chart: ${ge(o)}`,"error"),_([]))}).finally(()=>{t||ae(!1)}),()=>{t=!0}},[A,l,d,a]),n.useEffect(()=>{const t=setInterval(()=>{g()},3e4);return()=>{clearInterval(t)}},[g]),n.useEffect(()=>{if(!X)return;const t=j=>{const S=j.target;S&&(ce.current?.contains(S)||P.current?.contains(S)||Q(!1))},o=j=>{j.key==="Escape"&&(Q(!1),P.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",o)}},[X]);const D=async(t,o)=>{if(!O.has(t)){V(j=>new Set(j).add(t)),me(j=>{const S=new Map(j);return S.set(t,o),S});try{await Ot(t,o,l),a(`Agent state updated to ${o}`,"success"),await g(),me(j=>{const S=new Map(j);return S.delete(t),S})}catch(j){me(S=>{const s=new Map(S);return s.delete(t),s}),a(`Failed to update state: ${ge(j)}`,"error")}finally{V(j=>{const S=new Set(j);return S.delete(t),S})}}},K=async(t,o)=>{if(await q({title:"Delete Agent",message:`Delete agent "${o}"? This cannot be undone.`,danger:!0}))try{await Ht(t,l),a(`Agent "${o}" deleted`,"success"),g()}catch(S){a(`Failed to delete agent: ${ge(S)}`,"error")}},be=async(t,o)=>{const j=h.find(S=>S.id===t);if(j){if(j.role===o){H(null);return}try{await Te(t,{role:o},l),a(`Agent role updated to ${Re.find(S=>S.value===o)?.label??o}`,"success"),H(null),g()}catch(S){a(`Failed to update role: ${ge(S)}`,"error")}}},je=(t,o)=>{t.key==="Escape"&&H(null)},ke=async(t,o)=>{fe===t.id&&(B(null),G(j=>{const S={...j};return delete S[t.id],S})),ne(t.id);try{await Te(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:o}},l),a(`Heartbeat interval updated to ${Ye(o)} for ${t.name}`,"success"),g()}catch(j){a(`Failed to update heartbeat interval: ${ge(j)}`,"error")}finally{ne(null)}},se=async t=>{const o=Z[t.id]??"";if(o.trim()===""){a("Please enter a heartbeat interval in minutes","error");return}const j=Number(o);if(isNaN(j)){a("Heartbeat interval must be a valid number","error");return}if(j<=0){a("Heartbeat interval must be greater than 0","error");return}if(j>=1&&j<5){ne(t.id);try{await Te(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:zt}},l),a(`Heartbeat interval set to 5 minutes (minimum). ${j} minute${j!==1?"s":""} was below the 5-minute minimum.`,"success"),B(null),G(s=>{const N={...s};return delete N[t.id],N}),g()}catch(s){a(`Failed to update heartbeat interval: ${ge(s)}`,"error")}finally{ne(null)}return}const S=Math.round(j*6e4);ne(t.id);try{await Te(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:S}},l),a(`Heartbeat interval updated to ${Ye(S)} for ${t.name}`,"success"),B(null),G(s=>{const N={...s};return delete N[t.id],N}),g()}catch(s){a(`Failed to update heartbeat interval: ${ge(s)}`,"error")}finally{ne(null)}},Se=t=>{const o=Xe(t.runtimeConfig?.heartbeatIntervalMs),j=Math.round(o/6e4);B(t.id),G(S=>({...S,[t.id]:String(j)}))},Ee=n.useCallback(()=>{f(null)},[]),i=n.useCallback(t=>{f(t)},[]),w=async(t,o)=>{try{await qt(t,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),a(`Heartbeat run started for ${o}`,"success"),g()}catch(j){a(`Failed to start heartbeat run: ${ge(j)}`,"error")}},R=t=>Re.find(o=>o.value===t)?.label??t,U=t=>Re.find(o=>o.value===t)?.icon??"◆",$=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],z=t=>Lt(t),Ne=v&&h.length===0;return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(Ue,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${A==="list"?" active":""}`,onClick:()=>M("list"),title:"List view","aria-label":"List view","aria-pressed":A==="list",children:e.jsx(Tt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="board"?" active":""}`,onClick:()=>M("board"),title:"Board view","aria-label":"Board view","aria-pressed":A==="board",children:e.jsx(Ce,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="tree"?" active":""}`,onClick:()=>M("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":A==="tree",children:e.jsx(Mt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${A==="org"?" active":""}`,onClick:()=>M("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":A==="org",children:e.jsx(Qt,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:P,className:`btn-icon agent-controls-trigger${X?" agent-controls-trigger--active":""}`,onClick:()=>Q(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":X,"aria-controls":I,children:e.jsx(Xt,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void g(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Pe,{size:16,className:v?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{b(!0),Q(!1)},children:[e.jsx(Rt,{size:16}),"New Agent"]})]})]})]}),X&&e.jsxs("div",{ref:ce,id:I,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(_t,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:c,onChange:t=>r(t.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"}),e.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:t=>m(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{p(!0),Q(!1)},children:[e.jsx(lt,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:L,onChange:t=>{const o=Number(t.target.value);he(Number.isFinite(o)&&o>0?o:1)},disabled:ue}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",L.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(He.reduce((t,o)=>Math.abs(o-L)<Math.abs(t-L)?o:t,He[0])),onChange:t=>{const o=Number(t.target.value);he(Number.isFinite(o)&&o>0?o:1)},disabled:ue,"aria-label":"Heartbeat speed preset",children:He.map(t=>e.jsxs("option",{value:String(t),children:["×",t]},t))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(rn,{agents:ee})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(an,{stats:u}),e.jsx(Pn,{isOpen:C,onClose:()=>b(!1),onCreated:()=>{b(!1),g()},projectId:l}),e.jsx(Fn,{isOpen:E,onClose:()=>p(!1),onImported:()=>void g(),projectId:l}),Ne?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Pe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):A==="tree"?e.jsx("div",{className:"agent-tree__view",children:ee.length===0?e.jsx(Me,{onCtaClick:()=>b(!0)}):oe.rootNodes.map(t=>e.jsx(ct,{node:t,onSelect:f,onToggle:oe.toggleExpand,isExpanded:oe.isExpanded,getChildCount:o=>oe.getChildren(o).length,getHealthStatus:z,getRoleIcon:U,getSkillBadges:$},t.agent.id))}):A==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:te?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Pe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):we.length===0?e.jsx(Me,{onCtaClick:()=>b(!0)}):we.map(t=>e.jsx(dt,{node:t,onSelect:f,getHealthStatus:z,getRoleIcon:U,getSkillBadges:$},t.agent.id))}):A==="board"?e.jsx("div",{className:"agent-board",children:ee.length===0?e.jsx(Me,{onCtaClick:()=>b(!0)}):ee.map(t=>{const o=z(t),j=$e(t.state),S=Fe("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${S}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>f(t.id),role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&f(t.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:U(t.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:R(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${j}`,children:t.state})]}),e.jsx("div",{className:"agent-board-name",children:t.name}),e.jsx("div",{className:"agent-board-id",children:t.id}),e.jsxs("div",{className:"agent-board-health",style:{color:o.color},title:o.label,children:[o.icon,!o.stateDerived&&` ${o.label}`]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:ee.length===0?e.jsx(Me,{onCtaClick:()=>b(!0)}):ee.map(t=>{const o=z(t),j=$e(t.state),S=Fe("agent-card",t.state),s=Xe(t.runtimeConfig?.heartbeatIntervalMs),N=Pt(s),le=de===t.id;return e.jsxs("div",{className:`agent-card ${S}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>f(t.id),role:"button",tabIndex:0,onKeyDown:x=>x.key==="Enter"&&f(t.id),children:[xe===t.id?e.jsx("select",{ref:pe,className:"select agent-role-select",value:t.role,onChange:x=>void be(t.id,x.target.value),onKeyDown:x=>je(x,t.id),onBlur:()=>H(null),autoFocus:!0,children:Re.map(x=>e.jsxs("option",{value:x.value,children:[x.icon," ",x.label]},x.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:x=>{x.stopPropagation(),H(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.stopPropagation(),H(t.id))},children:U(t.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:t.name}),e.jsx("span",{className:"agent-id text-secondary",children:t.id})]}),e.jsx(rt,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${j}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:o.color},title:o.label,children:[o.icon,!o.stateDerived&&` ${o.label}`]}),e.jsx("span",{className:"badge text-secondary",children:R(t.role)}),(()=>{const x=$(t);if(x.length===0)return null;const F=x.slice(0,2),ye=x.length-2;return e.jsxs(e.Fragment,{children:[F.map(Be=>e.jsx("span",{className:"badge badge-skill",children:Be},Be)),ye>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",ye]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:t.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),fe===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Z[t.id]??"",onChange:x=>G(F=>({...F,[t.id]:x.target.value})),onKeyDown:x=>{x.key==="Enter"?se(t):x.key==="Escape"&&(B(null),G(F=>{const ye={...F};return delete ye[t.id],ye}))},disabled:le,"aria-label":`Custom heartbeat interval in minutes for ${t.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void se(t),disabled:le,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{B(null),G(x=>{const F={...x};return delete F[t.id],F})},disabled:le,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:s,onChange:x=>{const F=x.target.value;F==="__custom__"?Se(t):ke(t,Number(F))},disabled:le,"aria-label":`Set heartbeat interval for ${t.name}`,children:[N.map(x=>e.jsx("option",{value:x.value,children:x.label},x.value)),$t.some(x=>x.value===s)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),le&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const x=new Date(t.lastHeartbeatAt),F=new Date(x.getTime()+s),ye=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:x.toLocaleString(),children:["Last: ",x.toLocaleTimeString()]}),ye&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:F.toLocaleString(),children:["Next: ",F.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"active"),disabled:O.has(t.id),title:"Activate",children:[e.jsx(Ae,{size:14})," Start"]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void w(t.id,t.name),disabled:O.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(Ce,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"paused"),disabled:O.has(t.id),title:"Pause",children:[e.jsx(Ze,{size:14})," Pause"]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"active"),disabled:O.has(t.id),title:"Resume",children:[e.jsx(Ae,{size:14})," Resume"]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${t.name}`,children:[e.jsx(Ce,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"paused"),disabled:O.has(t.id),title:"Pause",children:[e.jsx(Ze,{size:14})," Pause"]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"active"),disabled:O.has(t.id),title:"Retry",children:[e.jsx(Ae,{size:14})," Retry"]}),t.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"active"),disabled:O.has(t.id),title:"Start",children:[e.jsx(Ae,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>f(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void K(t.id,t.name),title:"Delete",children:[e.jsx(Ft,{size:14})," Delete"]})]})]},t.id)})}),e.jsx(nn,{agents:ve,projectId:l,onAgentSelect:f,onOpenTaskLogs:y})]}),T&&e.jsx(n.Suspense,{fallback:null,children:e.jsx(Dn,{agentId:T,projectId:l,onClose:Ee,addToast:a,onChildClick:i})})]})}const Vn=Object.freeze(Object.defineProperty({__proto__:null,AgentsView:Ln},Symbol.toStringTag,{value:"Module"}));export{Vn as A,Rn as S};
522
+ Agent instructions go here...`,value:u,onChange:i=>{h("paste"),C([]),f(i.target.value),P(null)},rows:8,"aria-label":"Manifest content"})]}),e.jsxs("p",{className:"agent-import-file-hint",children:["Current input: ",r]}),H&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(ze,{size:14}),H]})]}),m==="preview"&&e.jsxs("div",{className:"agent-import-preview",children:[e.jsxs("div",{className:"agent-import-company",children:[e.jsx("span",{className:"agent-import-company-label",children:"Company"}),e.jsx("span",{className:"agent-import-company-name",children:b})]}),e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Ke,{size:14}),e.jsxs("span",{children:[p.length," agent",p.length!==1?"s":""," found"]})]}),p.length>0&&e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>x(p.map(i=>i.name)),children:"Select all agents"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>x([]),children:"Clear agents"})]}),p.length>0?e.jsx("div",{className:"agent-import-agent-list",children:p.map((i,w)=>e.jsxs("div",{className:"agent-import-agent-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select agent ${i.name}`,checked:T.includes(i.name),onChange:()=>Se(i.name)})}),e.jsx("span",{className:"agent-import-agent-icon",children:i.icon||"🤖"}),e.jsxs("div",{className:"agent-import-agent-details",children:[e.jsx("span",{className:"agent-import-agent-name",children:i.name}),e.jsxs("span",{className:"agent-import-agent-meta",children:[i.title&&e.jsxs("span",{className:"agent-import-agent-title",children:[i.title," · "]}),e.jsx("span",{className:"agent-import-agent-role",children:i.role}),i.reportsTo&&e.jsxs("span",{className:"agent-import-agent-reports",children:[" · reports to ",i.reportsTo]}),i.skills&&i.skills.length>0&&e.jsxs("span",{className:"agent-import-agent-model",children:[" · skills: ",i.skills.join(", ")]})]}),i.instructionsText&&e.jsxs("span",{className:"agent-import-agent-instructions",children:[i.instructionsText.slice(0,100),i.instructionsText.length>100?"...":""]})]})]},w))}):e.jsx("p",{className:"agent-import-empty",children:"No agents found in the manifest."}),k.length>0&&e.jsxs("div",{className:"agent-import-skills-section",children:[e.jsxs("div",{className:"agent-import-count",children:[e.jsx(Ke,{size:14}),e.jsxs("span",{children:[k.length," skill",k.length!==1?"s":""," found"]})]}),e.jsxs("div",{className:"agent-import-selection-controls",children:[e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>te(k.map(i=>i.name)),children:"Select all skills"}),e.jsx("button",{type:"button",className:"btn btn-sm",onClick:()=>te([]),children:"Clear skills"})]}),e.jsx("div",{className:"agent-import-skill-list",children:k.map((i,w)=>e.jsxs("div",{className:"agent-import-skill-item",children:[e.jsx("label",{className:"checkbox-label",children:e.jsx("input",{type:"checkbox","aria-label":`Select skill ${i.name}`,checked:R.includes(i.name),onChange:()=>Ae(i.name)})}),e.jsx("span",{className:"agent-import-skill-icon",children:"⚡"}),e.jsxs("div",{className:"agent-import-skill-details",children:[e.jsx("span",{className:"agent-import-skill-name",children:i.name}),i.description&&e.jsx("span",{className:"agent-import-skill-description",children:i.description})]})]},`${i.name}-${w}`))})]}),q&&e.jsxs("p",{className:"agent-dialog-error",children:[e.jsx(ze,{size:14}),q]})]}),m==="result"&&S&&e.jsxs("div",{className:"agent-import-result",children:[e.jsx("div",{className:"agent-import-result-icon",children:e.jsx(_e,{size:32})}),e.jsx("h3",{className:"agent-import-result-title",children:"Import Complete"}),e.jsxs("p",{className:"agent-import-result-company",children:["From ",e.jsx("strong",{children:S.companyName??"Unknown"})]}),e.jsxs("div",{className:"agent-import-result-stats",children:[S.created.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[S.created.length," created"]})}),S.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[S.skipped.length," skipped (already exist)"]})}),S.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[S.errors.length," error",S.errors.length!==1?"s":""]})})]}),S.created.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:S.created.map((i,w)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(_e,{size:12}),e.jsx("span",{children:i.name})]},w))}),S.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:S.errors.map((i,w)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Ze,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},w))}),S.skills&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"agent-import-result-divider"}),e.jsx("h4",{className:"agent-import-result-section-title",children:"Skills"}),e.jsxs("div",{className:"agent-import-result-stats",children:[S.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--success",children:e.jsxs("span",{children:[S.skills.imported.length," skill",S.skills.imported.length!==1?"s":""," imported"]})}),S.skills.skipped.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsxs("span",{children:[S.skills.skipped.length," skill",S.skills.skipped.length!==1?"s":""," skipped (already exist)"]})}),S.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--error",children:e.jsxs("span",{children:[S.skills.errors.length," skill",S.skills.errors.length!==1?"s":""," error",S.skills.errors.length!==1?"s":""]})}),S.skills.imported.length===0&&S.skills.skipped.length===0&&S.skills.errors.length===0&&e.jsx("div",{className:"agent-import-result-stat agent-import-result-stat--skipped",children:e.jsx("span",{children:"No skills in package"})})]}),S.skills.imported.length>0&&e.jsx("div",{className:"agent-import-result-agents",children:S.skills.imported.map((i,w)=>e.jsxs("div",{className:"agent-import-result-agent",children:[e.jsx(_e,{size:12}),e.jsx("span",{children:i.name})]},w))}),S.skills.errors.length>0&&e.jsx("div",{className:"agent-import-result-errors",children:S.skills.errors.map((i,w)=>e.jsxs("div",{className:"agent-import-result-error",children:[e.jsx(Ze,{size:12}),e.jsxs("span",{children:[i.name,": ",i.error]})]},w))})]})]})]}),e.jsxs("div",{className:"agent-dialog-footer",children:[m==="preview"&&e.jsx("button",{className:"btn",onClick:()=>c("input"),disabled:Q,children:"Back"}),e.jsx("button",{className:"btn",onClick:he,disabled:Q,children:m==="result"?"Close":"Cancel"}),m==="input"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void ve(),disabled:ae||(r==="directory"?g.length===0:r==="browse"?!L:!u.trim()),children:ae?e.jsxs(e.Fragment,{children:[e.jsx(Le,{size:14,className:"spin"}),"Parsing..."]}):"Preview"}),m==="preview"&&e.jsx("button",{className:"btn btn-task-create",onClick:()=>void we(),disabled:Q||D===0&&K===0,children:Q?e.jsxs(e.Fragment,{children:[e.jsx(Le,{size:14,className:"spin"}),se]}):`Import ${ke}`})]})]})}):null}const Dn=n.lazy(()=>Wt(()=>import("./AgentDetailView-khrspqE3.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])).then(a=>({default:a.AgentDetailView}))),Re=[{value:"triage",label:"Triage",icon:"⊕"},{value:"executor",label:"Executor",icon:"▶"},{value:"reviewer",label:"Reviewer",icon:"⊙"},{value:"merger",label:"Merger",icon:"⊞"},{value:"scheduler",label:"Scheduler",icon:"◷"},{value:"engineer",label:"Engineer",icon:"⎔"},{value:"custom",label:"Custom",icon:"✦"}],Ve=[.1,.25,.5,1,2,3,5,10];function $e(a){switch(a){case"running":return"agent-badge--running";case"active":return"agent-badge--active";case"paused":return"agent-badge--paused";case"error":return"agent-badge--error";case"terminated":return"agent-badge--terminated";case"idle":default:return"agent-badge--idle"}}function Fe(a,l){switch(l){case"running":return`${a}--running`;case"active":return`${a}--active`;case"paused":return`${a}--paused`;case"error":return`${a}--error`;case"terminated":return`${a}--terminated`;case"idle":default:return`${a}--idle`}}function dt({node:a,onSelect:l,onToggle:y,isExpanded:d,getChildCount:m,getHealthStatus:c,getRoleIcon:r,getSkillBadges:h}){const{agent:u,children:f,depth:g}=a,C=m(u.id),b=d(u.id),E=c(u),p=$e(u.state),M=Fe("agent-tree__node",u.state);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`${M}${u.reportsTo?" agent-is-child":""} agent-tree__indent--${Math.min(g,4)}`,children:[e.jsx("button",{className:`agent-tree__toggle${C===0?" agent-tree__toggle--leaf":""}`,onClick:()=>C>0&&y(u.id),title:C>0?b?"Collapse":"Expand":"No employees","aria-label":C>0?b?"Collapse":"Expand":"No employees",children:C>0?b?e.jsx(Lt,{size:16}):e.jsx(lt,{size:16}):e.jsx(Ge,{size:14})}),e.jsxs("div",{className:"agent-tree__content",onClick:()=>l(u.id),role:"button",tabIndex:0,onKeyDown:k=>k.key==="Enter"&&l(u.id),children:[e.jsx("span",{className:"agent-tree__icon",children:r(u.role)}),e.jsx("span",{className:"agent-tree__name",children:u.name}),e.jsx("span",{className:`agent-tree__badge ${p}`,children:u.state}),e.jsx("span",{className:"agent-tree__health",style:{color:E.color},title:E.label,children:E.icon}),C>0&&e.jsxs("span",{className:"agent-tree__count text-secondary",children:["(",C,")"]}),(()=>{const k=h(u);return k.length===0?null:e.jsxs("span",{className:"agent-tree__skill",title:k.join(", "),children:[k[0],k.length>1&&` +${k.length-1}`]})})()]})]}),b&&f.length>0&&e.jsx("div",{className:"agent-tree__children",children:f.map(k=>e.jsx(dt,{node:k,onSelect:l,onToggle:y,isExpanded:d,getChildCount:m,getHealthStatus:c,getRoleIcon:r,getSkillBadges:h},k.agent.id))})]})}function ut({node:a,onSelect:l,getHealthStatus:y,getRoleIcon:d,getSkillBadges:m}){const{agent:c,children:r}=a,h=y(c),u=$e(c.state),f=Fe("org-chart-node-card",c.state);return e.jsxs("div",{className:`org-chart-node${r.length>0?" org-chart-node--has-children":""}`,children:[e.jsxs("div",{className:f,onClick:()=>l(c.id),role:"button",tabIndex:0,onKeyDown:g=>g.key==="Enter"&&l(c.id),children:[e.jsxs("div",{className:"org-chart-node__header",children:[e.jsx("span",{className:"org-chart-node__icon",children:d(c.role)}),e.jsx("span",{className:"org-chart-node__name",children:c.name})]}),e.jsxs("div",{className:"org-chart-node__meta",children:[e.jsx("span",{className:`org-chart-node__badge ${u}`,children:c.state}),e.jsxs("span",{className:"org-chart-node__health",style:{color:h.color},title:h.label,children:[h.icon,!h.stateDerived&&e.jsx("span",{className:"text-secondary",children:h.label})]}),(()=>{const g=m(c);if(g.length===0)return null;const C=g.slice(0,2),b=g.length-2;return e.jsxs(e.Fragment,{children:[C.map(E=>e.jsx("span",{className:"org-chart-node__skill",children:E},E)),b>0&&e.jsxs("span",{className:"org-chart-node__skill",children:["+",b]})]})})()]})]}),r.length>0&&e.jsx("div",{className:"org-chart-children",role:"group","aria-label":`${c.name} employees`,children:r.map(g=>e.jsx(ut,{node:g,onSelect:l,getHealthStatus:y,getRoleIcon:d,getSkillBadges:m},g.agent.id))})]})}function Ln({addToast:a,projectId:l,onOpenTaskLogs:y}){const[d,m]=n.useState(!1),[c,r]=n.useState("all"),{agents:h,stats:u,isLoading:f,loadAgents:g}=Ct(l,{filterState:c,showSystemAgents:d}),[C,b]=n.useState(!1),[E,p]=n.useState(!1),[M,k]=n.useState(null),[N,T]=n.useState(()=>{if(typeof window>"u")return"list";const t=Ue("fn-agent-view",l);return t==="list"||t==="board"||t==="tree"||t==="org"?t:"list"}),[x,R]=n.useState([]),[te,ae]=n.useState(!1),[X,Q]=n.useState(!1),ce=n.useRef(null),{confirm:H}=St(),P=n.useRef(null),S=n.useId();n.useEffect(()=>{const t=Ue("fn-agent-view",l);if(t==="list"||t==="board"||t==="tree"||t==="org"){T(t);return}T("list")},[l]),n.useEffect(()=>{rt("fn-agent-view",N,l)},[N,l]);const[xe,q]=n.useState(null),pe=n.useRef(null),[de,ne]=n.useState(null),[fe,B]=n.useState(null),[Z,G]=n.useState({}),[L,ie]=n.useState(1),[ue,re]=n.useState(!1),[O,V]=n.useState(new Set),[J,me]=n.useState(new Map),W=n.useRef(!0);n.useEffect(()=>(W.current=!0,()=>{W.current=!1}),[]),n.useEffect(()=>{At(l).then(t=>{W.current&&ie(t.heartbeatMultiplier??1)}).catch(()=>{})},[l]);const he=n.useCallback(async t=>{const o=Number.isFinite(t)&&t>0?t:1;ie(o),re(!0);try{await Et({heartbeatMultiplier:o},l),a(`Heartbeat speed set to ×${o.toFixed(1)}`,"success")}catch(j){a(`Failed to save heartbeat multiplier: ${ge(j)}`,"error")}finally{W.current&&re(!1)}},[l,a]),Y=n.useMemo(()=>J.size===0?h:h.map(t=>{const o=J.get(t.id);return o?{...t,state:o}:t}),[h,J]),oe=cn(Y,l),ee=n.useMemo(()=>Y.filter(t=>d||!Oe(t)),[Y,d]),ve=n.useMemo(()=>Y.filter(t=>t.state!=="active"&&t.state!=="running"?!1:d||!Oe(t)),[Y,d]),we=n.useMemo(()=>{if(d)return x;const t=o=>Oe(o.agent)?null:{...o,children:o.children.map(t).filter(j=>j!==null)};return x.map(t).filter(o=>o!==null)},[x,d]);n.useEffect(()=>{if(N!=="org")return;let t=!1;return ae(!0),Tt(l,{includeEphemeral:d}).then(o=>{t||R(o)}).catch(o=>{t||(a(`Failed to load org chart: ${ge(o)}`,"error"),R([]))}).finally(()=>{t||ae(!1)}),()=>{t=!0}},[N,l,d,a]),n.useEffect(()=>{const t=setInterval(()=>{g()},3e4);return()=>{clearInterval(t)}},[g]),n.useEffect(()=>{if(!X)return;const t=j=>{const A=j.target;A&&(ce.current?.contains(A)||P.current?.contains(A)||Q(!1))},o=j=>{j.key==="Escape"&&(Q(!1),P.current?.focus())};return document.addEventListener("mousedown",t),document.addEventListener("touchstart",t),document.addEventListener("keydown",o),()=>{document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t),document.removeEventListener("keydown",o)}},[X]);const D=async(t,o)=>{if(!O.has(t)){V(j=>new Set(j).add(t)),me(j=>{const A=new Map(j);return A.set(t,o),A});try{await Ht(t,o,l),a(`Agent state updated to ${o}`,"success"),await g(),me(j=>{const A=new Map(j);return A.delete(t),A})}catch(j){me(A=>{const s=new Map(A);return s.delete(t),s}),a(`Failed to update state: ${ge(j)}`,"error")}finally{V(j=>{const A=new Set(j);return A.delete(t),A})}}},K=async(t,o)=>{if(await H({title:"Delete Agent",message:`Delete agent "${o}"? This cannot be undone.`,danger:!0}))try{await Vt(t,l),a(`Agent "${o}" deleted`,"success"),g()}catch(A){a(`Failed to delete agent: ${ge(A)}`,"error")}},be=async(t,o)=>{const j=h.find(A=>A.id===t);if(j){if(j.role===o){q(null);return}try{await Te(t,{role:o},l),a(`Agent role updated to ${Re.find(A=>A.value===o)?.label??o}`,"success"),q(null),g()}catch(A){a(`Failed to update role: ${ge(A)}`,"error")}}},je=(t,o)=>{t.key==="Escape"&&q(null)},ke=async(t,o)=>{fe===t.id&&(B(null),G(j=>{const A={...j};return delete A[t.id],A})),ne(t.id);try{await Te(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:o}},l),a(`Heartbeat interval updated to ${et(o)} for ${t.name}`,"success"),g()}catch(j){a(`Failed to update heartbeat interval: ${ge(j)}`,"error")}finally{ne(null)}},se=async t=>{const o=Z[t.id]??"";if(o.trim()===""){a("Please enter a heartbeat interval in minutes","error");return}const j=Number(o);if(isNaN(j)){a("Heartbeat interval must be a valid number","error");return}if(j<=0){a("Heartbeat interval must be greater than 0","error");return}if(j>=1&&j<5){ne(t.id);try{await Te(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:Ot}},l),a(`Heartbeat interval set to 5 minutes (minimum). ${j} minute${j!==1?"s":""} was below the 5-minute minimum.`,"success"),B(null),G(s=>{const I={...s};return delete I[t.id],I}),g()}catch(s){a(`Failed to update heartbeat interval: ${ge(s)}`,"error")}finally{ne(null)}return}const A=Math.round(j*6e4);ne(t.id);try{await Te(t.id,{runtimeConfig:{...t.runtimeConfig??{},heartbeatIntervalMs:A}},l),a(`Heartbeat interval updated to ${et(A)} for ${t.name}`,"success"),B(null),G(s=>{const I={...s};return delete I[t.id],I}),g()}catch(s){a(`Failed to update heartbeat interval: ${ge(s)}`,"error")}finally{ne(null)}},Se=t=>{const o=We(t.runtimeConfig?.heartbeatIntervalMs),j=Math.round(o/6e4);B(t.id),G(A=>({...A,[t.id]:String(j)}))},Ae=n.useCallback(()=>{k(null)},[]),i=n.useCallback(t=>{k(t)},[]),w=async(t,o)=>{try{await qt(t,l,{source:"on_demand",triggerDetail:"Triggered from dashboard"}),a(`Heartbeat run started for ${o}`,"success"),g()}catch(j){a(`Failed to start heartbeat run: ${ge(j)}`,"error")}},_=t=>Re.find(o=>o.value===t)?.label??t,U=t=>Re.find(o=>o.value===t)?.icon??"◆",$=t=>Array.isArray(t.metadata?.skills)?t.metadata.skills:[],z=t=>zt(t),Ne=f&&h.length===0;return e.jsxs("div",{className:"agents-view",children:[e.jsxs("div",{className:"agents-view-header",children:[e.jsxs("div",{className:"agents-view-title",children:[e.jsx(Ge,{size:24}),e.jsx("h2",{children:"Agents"})]}),e.jsxs("div",{className:"agents-view-controls",children:[e.jsxs("div",{className:"view-toggle",children:[e.jsx("button",{className:`view-toggle-btn${N==="list"?" active":""}`,onClick:()=>T("list"),title:"List view","aria-label":"List view","aria-pressed":N==="list",children:e.jsx(Mt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${N==="board"?" active":""}`,onClick:()=>T("board"),title:"Board view","aria-label":"Board view","aria-pressed":N==="board",children:e.jsx(Ce,{size:16})}),e.jsx("button",{className:`view-toggle-btn${N==="tree"?" active":""}`,onClick:()=>T("tree"),title:"Tree view","aria-label":"Tree view","aria-pressed":N==="tree",children:e.jsx(Rt,{size:16})}),e.jsx("button",{className:`view-toggle-btn${N==="org"?" active":""}`,onClick:()=>T("org"),title:"Org Chart view","aria-label":"Org Chart view","aria-pressed":N==="org",children:e.jsx(Jt,{size:16})})]}),e.jsxs("div",{className:"agents-view-primary-actions",children:[e.jsx("button",{ref:P,className:`btn-icon agent-controls-trigger${X?" agent-controls-trigger--active":""}`,onClick:()=>Q(t=>!t),title:"Controls","aria-label":"Controls","aria-haspopup":"dialog","aria-expanded":X,"aria-controls":S,children:e.jsx(Zt,{size:16})}),e.jsx("button",{className:"btn-icon",onClick:()=>void g(),title:"Refresh","aria-label":"Refresh",children:e.jsx(Pe,{size:16,className:f?"spin":void 0})}),e.jsxs("button",{className:"btn btn-task-create btn-sm",onClick:()=>{b(!0),Q(!1)},children:[e.jsx(_t,{size:16}),"New Agent"]})]})]})]}),X&&e.jsxs("div",{ref:ce,id:S,className:"agent-controls-panel agent-controls-panel--scrollable",role:"dialog","aria-label":"Agent controls","aria-modal":"false",children:[e.jsxs("div",{className:"agent-controls",children:[e.jsxs("div",{className:"agent-controls-filters",children:[e.jsxs("div",{className:"agent-state-filter",children:[e.jsx(Pt,{size:14}),e.jsxs("select",{className:"agent-state-filter-select",value:c,onChange:t=>r(t.target.value),"aria-label":"Filter agents by state",children:[e.jsx("option",{value:"all",children:"All States"}),e.jsx("option",{value:"idle",children:"Idle"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"running",children:"Running"}),e.jsx("option",{value:"paused",children:"Paused"}),e.jsx("option",{value:"error",children:"Error"}),e.jsx("option",{value:"terminated",children:"Terminated"})]})]}),e.jsxs("label",{className:"checkbox-label agent-system-filter",children:[e.jsx("input",{type:"checkbox",checked:d,onChange:t=>m(t.target.checked),"aria-label":"Show system agents"}),"Show system agents"]})]}),e.jsx("div",{className:"agent-controls-actions",children:e.jsxs("button",{className:"btn",onClick:()=>{p(!0),Q(!1)},children:[e.jsx(ot,{size:16}),"Import"]})})]}),e.jsx("div",{className:"agent-global-controls",children:e.jsxs("div",{className:"heartbeat-multiplier-group",children:[e.jsxs("div",{className:"heartbeat-multiplier-controls",children:[e.jsx("label",{htmlFor:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-label",children:"Heartbeat Speed"}),e.jsx("input",{id:"globalHeartbeatMultiplier",className:"heartbeat-multiplier-slider touch-target",type:"range",min:.1,max:10,step:.1,value:L,onChange:t=>{const o=Number(t.target.value);he(Number.isFinite(o)&&o>0?o:1)},disabled:ue}),e.jsxs("span",{className:"heartbeat-multiplier-value",children:["×",L.toFixed(1)]}),e.jsx("select",{className:"heartbeat-multiplier-preset",value:String(Ve.reduce((t,o)=>Math.abs(o-L)<Math.abs(t-L)?o:t,Ve[0])),onChange:t=>{const o=Number(t.target.value);he(Number.isFinite(o)&&o>0?o:1)},disabled:ue,"aria-label":"Heartbeat speed preset",children:Ve.map(t=>e.jsxs("option",{value:String(t),children:["×",t]},t))})]}),e.jsx("small",{className:"text-secondary",children:"Scales all agent heartbeat intervals. ×0.5 = twice as fast, ×2.0 = twice as slow. Default: ×1.0"})]})}),e.jsx(rn,{agents:ee})]}),e.jsxs("div",{className:"agents-view-content",children:[e.jsx(an,{stats:u}),e.jsx(nn,{agents:ve,projectId:l,onAgentSelect:k,onOpenTaskLogs:y}),e.jsx(Pn,{isOpen:C,onClose:()=>b(!1),onCreated:()=>{b(!1),g()},projectId:l}),e.jsx(Fn,{isOpen:E,onClose:()=>p(!1),onImported:()=>void g(),projectId:l}),Ne?e.jsxs("div",{className:"agents-view-loading",role:"status","aria-live":"polite",children:[e.jsx(Pe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading agents..."})]}):N==="tree"?e.jsx("div",{className:"agent-tree__view",children:ee.length===0?e.jsx(Me,{onCtaClick:()=>b(!0)}):oe.rootNodes.map(t=>e.jsx(dt,{node:t,onSelect:k,onToggle:oe.toggleExpand,isExpanded:oe.isExpanded,getChildCount:o=>oe.getChildren(o).length,getHealthStatus:z,getRoleIcon:U,getSkillBadges:$},t.agent.id))}):N==="org"?e.jsx("div",{className:"agent-org-chart","data-testid":"agent-org-chart",children:te?e.jsxs("div",{className:"agent-org-chart__loading",role:"status","aria-live":"polite",children:[e.jsx(Pe,{size:18,className:"spin"}),e.jsx("span",{children:"Loading org chart..."})]}):we.length===0?e.jsx(Me,{onCtaClick:()=>b(!0)}):we.map(t=>e.jsx(ut,{node:t,onSelect:k,getHealthStatus:z,getRoleIcon:U,getSkillBadges:$},t.agent.id))}):N==="board"?e.jsx("div",{className:"agent-board",children:ee.length===0?e.jsx(Me,{onCtaClick:()=>b(!0)}):ee.map(t=>{const o=z(t),j=$e(t.state),A=Fe("agent-board-card",t.state);return e.jsx("div",{className:`agent-board-card ${A}`,children:e.jsxs("div",{className:"agent-board-clickable",onClick:()=>k(t.id),role:"button",tabIndex:0,onKeyDown:s=>s.key==="Enter"&&k(t.id),children:[e.jsxs("div",{className:"agent-board-header",children:[e.jsx("span",{className:"agent-board-icon",children:U(t.role)}),e.jsx("span",{className:"agent-board-badge badge text-secondary",children:_(t.role)}),e.jsx("span",{className:`agent-board-badge badge ${j}`,children:t.state})]}),e.jsx("div",{className:"agent-board-name",children:t.name}),e.jsx("div",{className:"agent-board-id",children:t.id}),e.jsxs("div",{className:"agent-board-health",style:{color:o.color},title:o.label,children:[o.icon,!o.stateDerived&&` ${o.label}`]})]})},t.id)})}):e.jsx("div",{className:"agent-list",children:ee.length===0?e.jsx(Me,{onCtaClick:()=>b(!0)}):ee.map(t=>{const o=z(t),j=$e(t.state),A=Fe("agent-card",t.state),s=We(t.runtimeConfig?.heartbeatIntervalMs),I=$t(s),le=de===t.id;return e.jsxs("div",{className:`agent-card ${A}`,children:[e.jsxs("div",{className:"agent-card-header",children:[e.jsxs("div",{className:"agent-info agent-info--clickable",onClick:()=>k(t.id),role:"button",tabIndex:0,onKeyDown:v=>v.key==="Enter"&&k(t.id),children:[xe===t.id?e.jsx("select",{ref:pe,className:"select agent-role-select",value:t.role,onChange:v=>void be(t.id,v.target.value),onKeyDown:v=>je(v,t.id),onBlur:()=>q(null),autoFocus:!0,children:Re.map(v=>e.jsxs("option",{value:v.value,children:[v.icon," ",v.label]},v.value))}):e.jsx("span",{className:"agent-icon agent-icon--clickable",onClick:v=>{v.stopPropagation(),q(t.id)},title:"Click to change role",role:"button",tabIndex:0,onKeyDown:v=>{(v.key==="Enter"||v.key===" ")&&(v.stopPropagation(),q(t.id))},children:U(t.role)}),e.jsxs("div",{className:"agent-meta",children:[e.jsx("span",{className:"agent-name",children:t.name}),e.jsx("span",{className:"agent-id text-secondary",children:t.id})]}),e.jsx(lt,{size:20,className:"agent-card-chevron"})]}),e.jsxs("div",{className:"agent-badges",children:[e.jsx("span",{className:`badge ${j}`,children:t.state}),e.jsxs("span",{className:"badge",style:{color:o.color},title:o.label,children:[o.icon,!o.stateDerived&&` ${o.label}`]}),e.jsx("span",{className:"badge text-secondary",children:_(t.role)}),(()=>{const v=$(t);if(v.length===0)return null;const F=v.slice(0,2),ye=v.length-2;return e.jsxs(e.Fragment,{children:[F.map(Qe=>e.jsx("span",{className:"badge badge-skill",children:Qe},Qe)),ye>0&&e.jsxs("span",{className:"badge badge-skill",children:["+",ye]})]})})()]})]}),e.jsxs("div",{className:"agent-card-body",children:[t.taskId&&e.jsxs("div",{className:"agent-task",children:[e.jsx("span",{className:"text-secondary",children:"Working on:"}),e.jsx("span",{className:"badge",children:t.taskId})]}),e.jsxs("div",{className:"agent-heartbeat-control",children:[e.jsx("span",{className:"text-secondary",children:"Heartbeat:"}),fe===t.id?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",inputMode:"numeric",pattern:"[0-9]*",className:"input agent-heartbeat-custom-input",value:Z[t.id]??"",onChange:v=>G(F=>({...F,[t.id]:v.target.value})),onKeyDown:v=>{v.key==="Enter"?se(t):v.key==="Escape"&&(B(null),G(F=>{const ye={...F};return delete ye[t.id],ye}))},disabled:le,"aria-label":`Custom heartbeat interval in minutes for ${t.name}`}),e.jsx("span",{className:"text-secondary",children:"min"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>void se(t),disabled:le,title:"Save custom interval",children:"Save"}),e.jsx("button",{className:"btn btn--sm",onClick:()=>{B(null),G(v=>{const F={...v};return delete F[t.id],F})},disabled:le,title:"Cancel custom interval",children:"Cancel"})]}):e.jsx(e.Fragment,{children:e.jsxs("select",{className:"select agent-heartbeat-select",value:s,onChange:v=>{const F=v.target.value;F==="__custom__"?Se(t):ke(t,Number(F))},disabled:le,"aria-label":`Set heartbeat interval for ${t.name}`,children:[I.map(v=>e.jsx("option",{value:v.value,children:v.label},v.value)),Ft.some(v=>v.value===s)&&e.jsx("option",{value:"__custom__",children:"Custom..."})]})}),le&&e.jsx("span",{className:"agent-heartbeat-saving text-secondary",children:"Saving…"}),t.lastHeartbeatAt&&(()=>{const v=new Date(t.lastHeartbeatAt),F=new Date(v.getTime()+s),ye=t.state==="active"||t.state==="running";return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"agent-heartbeat-last text-secondary",title:v.toLocaleString(),children:["Last: ",v.toLocaleTimeString()]}),ye&&e.jsxs("span",{className:"agent-heartbeat-next text-secondary",title:F.toLocaleString(),children:["Next: ",F.toLocaleTimeString()]})]})})()]})]}),e.jsxs("div",{className:"agent-card-actions",children:[t.state==="idle"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"active"),disabled:O.has(t.id),title:"Activate",children:[e.jsx(Ee,{size:14})," Start"]}),t.state==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",onClick:()=>void w(t.id,t.name),disabled:O.has(t.id),title:"Run Now","aria-label":`Run now for ${t.name}`,children:[e.jsx(Ce,{size:14})," Run Now"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"paused"),disabled:O.has(t.id),title:"Pause",children:[e.jsx(Ye,{size:14})," Pause"]})]}),t.state==="paused"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"active"),disabled:O.has(t.id),title:"Resume",children:[e.jsx(Ee,{size:14})," Resume"]}),t.state==="running"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"btn btn--sm",disabled:!0,title:"Run in progress","aria-label":`Heartbeat run in progress for ${t.name}`,children:[e.jsx(Ce,{size:14})," Running"]}),e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"paused"),disabled:O.has(t.id),title:"Pause",children:[e.jsx(Ye,{size:14})," Pause"]})]}),t.state==="error"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"active"),disabled:O.has(t.id),title:"Retry",children:[e.jsx(Ee,{size:14})," Retry"]}),t.state==="terminated"&&e.jsxs("button",{className:"btn btn--sm",onClick:()=>void D(t.id,"active"),disabled:O.has(t.id),title:"Start",children:[e.jsx(Ee,{size:14})," Start"]}),e.jsx("button",{className:"btn btn--sm agent-card-details-btn",onClick:()=>k(t.id),title:`View details for ${t.name}`,"aria-label":`View details for ${t.name}`,children:"View Details"}),e.jsxs("button",{className:"btn btn--sm btn--danger",onClick:()=>void K(t.id,t.name),title:"Delete",children:[e.jsx(Dt,{size:14})," Delete"]})]})]},t.id)})})]}),M&&e.jsx(n.Suspense,{fallback:null,children:e.jsx(Dn,{agentId:M,projectId:l,onClose:Ae,addToast:a,onChildClick:i})})]})}const Vn=Object.freeze(Object.defineProperty({__proto__:null,AgentsView:Ln},Symbol.toStringTag,{value:"Module"}));export{Vn as A,Rn as S};
@@ -0,0 +1 @@
1
+ .active-agents-panel{margin-top:var(--space-xl);margin-bottom:var(--space-lg)}.active-agents-panel-header{display:flex;align-items:center;gap:var(--space-sm);font-size:13px;font-weight:600;color:var(--text-muted);margin-bottom:var(--space-md)}.active-agents-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:var(--space-md)}.live-agent-card{display:flex;flex-direction:column;gap:var(--space-sm);padding:var(--space-md);background:var(--card);border:1px solid var(--border);border-radius:var(--radius-md);cursor:pointer;transition:background .15s,border-color .15s}.live-agent-card:hover{background:var(--bg-hover);border-color:var(--border-strong, var(--border))}.live-agent-card:focus-visible{outline:2px solid var(--accent, var(--color-primary));outline-offset:2px}.live-agent-card-header{display:flex;align-items:center;justify-content:space-between;gap:var(--space-sm)}.live-agent-card-name{display:flex;align-items:center;gap:var(--space-sm);font-weight:600;font-size:13px}.live-agent-pulse{width:8px;height:8px;background:var(--color-success);border-radius:50%;animation:pulse 1.5s infinite}.live-agent-task{font-family:var(--font-mono)}.live-agent-card-transcript{font-family:var(--font-mono);font-size:11px;line-height:1.5;color:var(--text-muted);max-height:120px;overflow-y:auto}.live-agent-card-empty{display:flex;flex-direction:column;gap:var(--space-xs)}.live-agent-card-status{font-style:normal;font-weight:500;color:var(--text-primary);opacity:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.live-agent-card-status-sub{font-style:italic;opacity:.6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.live-agent-card-line{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.live-agent-card-footer{display:flex;align-items:center;justify-content:space-between;font-size:calc(var(--space-sm) + var(--space-xs) * .75);color:var(--text-muted);padding-top:var(--space-sm);border-top:1px solid var(--border)}.live-agent-streaming-dot{color:var(--color-success);animation:pulse 1.5s infinite}.live-agent-card-footer-actions{display:flex;align-items:center;gap:var(--space-sm)}.live-agent-card-footer-meta{display:flex;align-items:center;gap:var(--space-sm);flex-wrap:wrap;min-width:0}.live-agent-card-next-heartbeat{color:var(--text-muted);font-size:11px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.live-agent-card-logs-btn{display:inline-flex;align-items:center;gap:var(--space-xs);padding:var(--space-xs) var(--space-sm);font-size:11px;color:var(--text-secondary);background:transparent;border:1px solid var(--border);border-radius:var(--radius-sm);cursor:pointer;transition:background .15s,color .15s,border-color .15s}.live-agent-card-logs-btn:hover{background:var(--bg-hover);color:var(--text-primary);border-color:var(--border-strong, var(--border))}@media(max-width:768px){.active-agents-grid{grid-template-columns:1fr}.live-agent-card{min-width:0;overflow:hidden}}.agent-token-stats-panel{margin-bottom:var(--space-lg);padding:var(--space-md);border:1px solid var(--border);border-radius:var(--radius-md);background:var(--card);box-shadow:var(--shadow-sm)}.agent-token-stats-panel__header{margin-bottom:var(--space-md)}.agent-token-stats-panel__title{margin:0;font-size:calc(var(--space-md) + var(--space-xs));font-weight:600;color:var(--text)}.agent-token-stats-panel__totals{display:grid;grid-template-columns:repeat(auto-fit,minmax(calc(var(--space-2xl) * 4),1fr));gap:var(--space-sm);margin-bottom:var(--space-md)}.agent-token-stats-panel__total-card{display:flex;flex-direction:column;gap:var(--space-xs);padding:var(--space-sm) var(--space-md);border:1px solid var(--border);border-radius:var(--radius-sm);background:var(--surface)}.agent-token-stats-panel__total-label{color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs));text-transform:uppercase;letter-spacing:calc(var(--space-xs) / 8)}.agent-token-stats-panel__total-value{color:var(--text);font-size:calc(var(--space-lg) + var(--space-xs));line-height:1.2;font-family:var(--font-mono);font-weight:700}.agent-token-stats-panel__table-wrapper{overflow-x:auto}.agent-token-stats-panel__table{width:100%;border-collapse:collapse}.agent-token-stats-panel__table th,.agent-token-stats-panel__table td{padding:var(--space-sm);border-bottom:1px solid var(--border);color:var(--text);text-align:right;font-size:calc(var(--space-sm) + var(--space-xs))}.agent-token-stats-panel__table thead th{text-transform:uppercase;letter-spacing:calc(var(--space-xs) / 8);color:var(--text-muted);font-weight:600}.agent-token-stats-panel__table th:first-child,.agent-token-stats-panel__table td:first-child{text-align:left}.agent-token-stats-panel__agent-cell{display:flex;flex-direction:column;gap:calc(var(--space-xs) * .5)}.agent-token-stats-panel__agent-name{color:var(--text)}.agent-token-stats-panel__agent-id{color:var(--text-muted);font-family:var(--font-mono);font-size:calc(var(--space-sm) + var(--space-xs) * .75);text-transform:none;letter-spacing:normal}.agent-token-stats-panel__total-cell{font-family:var(--font-mono);font-weight:700}.agent-token-stats-panel__empty{padding:var(--space-md);border:1px dashed var(--border);border-radius:var(--radius-sm);color:var(--text-muted);background:color-mix(in srgb,var(--surface) 85%,transparent);font-size:calc(var(--space-sm) + var(--space-xs))}@media(max-width:768px){.agent-token-stats-panel{padding:var(--space-sm)}.agent-token-stats-panel__totals{grid-template-columns:1fr}.agent-token-stats-panel__table th,.agent-token-stats-panel__table td{padding:var(--space-xs) var(--space-sm)}}.agent-dialog-overlay{position:fixed;inset:0;background:color-mix(in srgb,var(--bg) 60%,transparent);backdrop-filter:blur(var(--space-xs));display:flex;align-items:center;justify-content:center;z-index:100;padding:calc(var(--space-lg) + var(--space-xs))}.agent-dialog{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);width:100%;max-width:calc(var(--space-xl) * 21 + var(--space-md));max-height:calc(100vh - (var(--space-xl) + var(--space-lg)));max-height:calc(100dvh - (var(--space-xl) + var(--space-lg)));display:flex;flex-direction:column;overflow:hidden;box-shadow:var(--shadow-lg)}.agent-dialog-header{display:flex;align-items:center;justify-content:space-between;padding:var(--space-lg) calc(var(--space-lg) + var(--space-xs));border-bottom:1px solid var(--border)}.agent-dialog-header-title{font-weight:600;font-size:calc(var(--space-md) + var(--space-xs) * .75)}.agent-dialog-body{flex:1;overflow-y:auto;padding:calc(var(--space-lg) + var(--space-xs))}.agent-dialog-footer{display:flex;align-items:center;justify-content:flex-end;gap:var(--space-sm);padding:var(--space-lg) calc(var(--space-lg) + var(--space-xs));border-top:1px solid var(--border)}.agent-dialog-steps{display:flex;gap:calc(var(--space-sm) - var(--space-xs) * .5);padding:var(--space-md) calc(var(--space-lg) + var(--space-xs));justify-content:center}.agent-dialog-step{width:calc(var(--space-2xl) + var(--space-sm));height:var(--space-xs);border-radius:calc(var(--space-xs) * .5);background:var(--border);transition:background var(--transition-fast)}.agent-dialog-step.active{background:var(--todo)}.agent-dialog-step.completed{background:var(--color-success)}.agent-dialog-field{margin-bottom:var(--space-lg)}.agent-dialog-field label{display:block;font-size:calc(var(--space-md) + var(--space-xs) * .25);font-weight:500;margin-bottom:calc(var(--space-sm) - var(--space-xs) * .5)}.agent-dialog-field .input,.agent-dialog-field .select{width:100%;box-sizing:border-box}.agent-dialog-section{margin-bottom:var(--space-lg)}.agent-dialog-section-header{font-size:calc(var(--space-sm) + var(--space-xs));font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:var(--text-muted);margin-bottom:var(--space-md);padding-bottom:var(--space-xs);border-bottom:1px solid var(--border)}.agent-dialog-tabs{display:grid;grid-template-columns:1fr 1fr;gap:var(--space-sm);margin-bottom:var(--space-lg)}.agent-dialog-tab{border:1px solid var(--border);border-radius:var(--radius-md);background:var(--card);color:var(--text-muted);padding:var(--space-sm) var(--space-md);font-size:calc(var(--space-sm) + var(--space-xs));font-weight:600;cursor:pointer;transition:border-color var(--transition-fast),background var(--transition-fast),color var(--transition-fast),box-shadow var(--transition-fast)}.agent-dialog-tab:hover{border-color:var(--todo);color:var(--text);background:var(--card-hover)}.agent-dialog-tab:focus-visible{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring-strong)}.agent-dialog-tab.active{border-color:var(--todo);color:var(--text);background:color-mix(in srgb,var(--todo) 12%,transparent)}.agent-dialog-tab-panel{display:flex;flex-direction:column;gap:var(--space-sm)}.agent-runtime-mode-toggle{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:var(--space-sm)}.agent-runtime-mode-option{position:relative;margin:0}.agent-runtime-mode-option input{position:absolute;opacity:0;pointer-events:none}.agent-runtime-mode-option span{display:flex;align-items:center;justify-content:center;min-height:calc(var(--space-xl) + var(--space-lg));border:1px solid var(--border);border-radius:var(--radius-md);background:var(--card);color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs));font-weight:600;padding:var(--space-sm) var(--space-md);cursor:pointer;transition:border-color var(--transition-fast),background var(--transition-fast),color var(--transition-fast),box-shadow var(--transition-fast)}.agent-runtime-mode-option span:hover{border-color:var(--todo);color:var(--text);background:var(--card-hover)}.agent-runtime-mode-option input:focus-visible+span{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring-strong)}.agent-runtime-mode-option--active span{border-color:var(--todo);color:var(--text);background:color-mix(in srgb,var(--todo) 12%,transparent)}.agent-role-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(calc(var(--space-xl) * 3 + var(--space-sm)),1fr));gap:var(--space-sm)}.agent-role-option{display:flex;flex-direction:column;align-items:center;padding:var(--space-md) var(--space-sm);background:var(--card);border:1px solid var(--border);border-radius:var(--radius-md);cursor:pointer;transition:border-color var(--transition-fast),background var(--transition-fast);font-family:var(--font-primary);color:var(--text)}.agent-role-option:hover{border-color:var(--text-muted);background:var(--card-hover)}.agent-role-option:focus-visible{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring-strong)}.agent-role-option.selected{border-color:var(--todo);background:color-mix(in srgb,var(--todo) 12%,transparent);box-shadow:var(--focus-ring)}.agent-role-option-icon{font-size:calc(var(--space-lg) + var(--space-xs));line-height:1}.agent-role-option-label{font-size:calc(var(--space-sm) + var(--space-xs));margin-top:var(--space-xs)}.agent-dialog-icon-prefix{margin-right:calc(var(--space-sm) - var(--space-xs) * .5)}.agent-dialog-ai-generate{margin-top:var(--space-sm);border-top:1px solid var(--border);padding-top:var(--space-md)}.btn--ai-generate{width:100%;display:flex;align-items:center;justify-content:center;gap:calc(var(--space-sm) - var(--space-xs) * .5);background:var(--cta-bg, var(--todo));color:var(--cta-text, var(--text));font-weight:600;border:1px solid transparent}.btn--ai-generate:hover{opacity:.9;filter:brightness(1.1)}.agent-dialog-ai-hint{color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs) * .75);text-align:center;margin:calc(var(--space-sm) - var(--space-xs) * .5) 0 0}.agent-dialog-summary{display:flex;flex-direction:column;gap:var(--space-sm)}.agent-dialog-summary-row{display:flex;justify-content:space-between;align-items:center;padding:var(--space-sm) 0;border-bottom:1px solid color-mix(in srgb,var(--border) 50%,transparent)}.agent-dialog-summary-row:last-child{border-bottom:none}.agent-dialog-summary-row-label{color:var(--text-muted);font-size:13px}.agent-dialog-summary-row-label--fixed{flex:0 0 calc(var(--space-xl) * 4 - var(--space-xs) * 1.5)}.agent-dialog-summary-row-value{font-weight:600}.agent-dialog-summary-row-value--body{font-weight:400}.agent-dialog-summary--spaced{margin-bottom:var(--space-md)}.agent-dialog-summary-row-value--muted{font-style:italic;color:var(--text-muted)}.agent-dialog-summary-row-value--capitalize{text-transform:capitalize}.agent-presets{margin-bottom:var(--space-lg)}.agent-presets-header{font-size:calc(var(--space-md) + var(--space-xs) * .5);font-weight:600;color:var(--text-muted);margin-bottom:var(--space-md);display:flex;align-items:center;gap:var(--space-sm)}.agent-presets-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(calc(var(--space-xl) * 5 + var(--space-lg) + var(--space-xs)),1fr));gap:var(--space-sm);margin-bottom:var(--space-lg);max-height:calc(var(--space-xl) * 16 + var(--space-lg));overflow-y:auto}.agent-preset-card{display:flex;flex-direction:column;align-items:center;padding:var(--space-md);border:1px solid var(--border);border-radius:var(--radius-md);cursor:pointer;transition:border-color var(--transition-fast),background var(--transition-fast),box-shadow var(--transition-fast),transform var(--transition-fast);background:var(--bg-secondary);font-family:var(--font-primary);color:var(--text)}.agent-preset-card:hover{border-color:var(--todo);background:var(--bg-tertiary)}.agent-preset-card:focus-visible{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring-strong)}.agent-preset-card.selected{border-color:var(--todo);background:color-mix(in srgb,var(--todo) 12%,transparent)}.agent-preset-icon{font-size:var(--space-xl);margin-bottom:var(--space-xs)}.agent-preset-name{font-size:calc(var(--space-md) + var(--space-xs) * .25);font-weight:500;text-align:center;margin-bottom:var(--space-xs)}.agent-preset-role{font-size:calc(var(--space-sm) + var(--space-xs) * .75);color:var(--text-muted);text-transform:capitalize}.agent-preset-description{font-size:calc(var(--space-sm) + var(--space-xs) * .75);color:var(--text-muted);line-height:1.3;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;margin-top:calc(var(--space-xs) * .5)}.agent-dialog-header-sparkle{margin-right:var(--space-sm)}.agent-dialog-error-banner{color:var(--color-error);font-size:calc(var(--space-md) + var(--space-xs) * .25);padding:var(--space-sm) var(--space-md);background:color-mix(in srgb,var(--color-error) 10%,transparent);border-radius:var(--radius-md);margin-bottom:var(--space-md)}.agent-dialog-textarea{resize:vertical}.agent-dialog-hint{font-size:calc(var(--space-sm) + var(--space-xs) * .75);color:var(--text-muted);margin-top:var(--space-xs);display:flex;justify-content:space-between;gap:var(--space-sm)}.agent-dialog-loading-center{display:flex;flex-direction:column;align-items:center;padding:var(--space-2xl) var(--space-lg);gap:var(--space-md)}.agent-dialog-spinner{width:var(--space-2xl);height:var(--space-2xl);border:calc(var(--space-xs) * .75) solid var(--border);border-top-color:var(--todo);border-radius:50%}.agent-dialog-loading-text{color:var(--text-muted);font-size:calc(var(--space-md) + var(--space-xs) * .25);margin:0}.agent-dialog-expand-btn{background:none;border:none;color:var(--todo);cursor:pointer;font-size:calc(var(--space-sm) + var(--space-xs));margin-left:var(--space-sm);padding:0}.agent-dialog-expand-btn:focus-visible{outline:none;box-shadow:var(--focus-ring-strong);border-radius:var(--radius-sm)}.agent-generation-prompt-box{background:var(--bg-secondary);border:1px solid var(--border);border-radius:var(--radius-md);padding:var(--space-md);font-size:calc(var(--space-sm) + var(--space-xs));font-family:var(--font-mono);line-height:1.5;white-space:pre-wrap;word-break:break-word;overflow:auto;position:relative}.agent-generation-prompt-box--collapsed{max-height:calc(var(--space-xl) * 6 + var(--space-sm) + var(--space-xs) * .5);overflow:hidden}.agent-generation-prompt-fade{position:absolute;bottom:0;left:0;right:0;height:calc(var(--space-lg) + var(--space-xl));background:linear-gradient(transparent,var(--bg-secondary));pointer-events:none}.agent-dialog-required{color:var(--color-error)}.agent-dialog-optional{color:var(--text-muted);font-weight:400}.agent-dialog-error{color:var(--color-error);font-size:calc(var(--space-md) + var(--space-xs) * .25);margin-top:var(--space-md)}.agent-dialog-info{color:var(--text-muted);font-size:calc(var(--space-md) + var(--space-xs) * .25);margin-top:0;margin-bottom:var(--space-md)}.agent-dialog-loading{color:var(--text-muted);font-size:calc(var(--space-md) + var(--space-xs) * .25);padding:var(--space-sm) 0}@media(max-width:768px){.agent-dialog-overlay{padding:0;align-items:stretch;justify-content:stretch}.agent-dialog{width:100vw;max-width:100vw;height:100dvh;max-height:100dvh;border-radius:0;border-left:0;border-right:0}.agent-dialog-header{padding:calc(var(--space-md) + env(safe-area-inset-top)) var(--space-md) var(--space-md)}.agent-dialog-footer{padding:var(--space-md) var(--space-md) calc(var(--space-md) + env(safe-area-inset-bottom))}.agent-dialog-steps{padding:var(--space-sm) var(--space-md);overflow-x:auto;flex-wrap:nowrap;flex-shrink:0}.agent-dialog-header,.agent-dialog-footer{flex-shrink:0}.agent-dialog-body{padding:var(--space-md);flex:1 1 auto;min-height:0;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}.agent-dialog-footer{flex-wrap:wrap;gap:var(--space-xs)}.agent-dialog-footer>.btn{flex:1 1 auto;min-width:0}}.skill-multiselect{display:flex;flex-direction:column;gap:var(--space-sm)}.skill-multiselect-label{font-size:13px;font-weight:500;color:var(--text-secondary)}.skill-multiselect-chips{display:flex;flex-wrap:wrap;gap:4px}.skill-chip{display:inline-flex;align-items:center;gap:4px;padding:2px 6px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:4px;font-size:12px;line-height:1.4}.skill-chip-name{max-width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.skill-chip-remove{display:inline-flex;align-items:center;justify-content:center;width:14px;height:14px;padding:0;background:transparent;border:none;border-radius:2px;color:var(--text-muted);font-size:14px;line-height:1;cursor:pointer;transition:color .15s,background .15s}.skill-chip-remove:hover:not(:disabled){color:var(--text-primary);background:var(--bg-hover)}.skill-chip-remove:disabled{opacity:.5;cursor:not-allowed}.skill-multiselect-add{min-height:32px}.skill-multiselect-loading,.skill-multiselect-empty{font-size:13px;color:var(--text-muted);padding:4px 0}.skill-multiselect-dropdown{width:100%;font-size:13px}.agent-dialog-skills-hint{margin-top:4px;font-size:12px}.skill-badge-row{display:flex;flex-wrap:wrap;gap:4px}.skill-badge{display:inline-block;padding:2px 6px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:4px;font-size:11px;line-height:1.4}.badge-skill{background:var(--bg-tertiary);color:var(--text-secondary)}.agent-board-skills{display:flex;flex-wrap:wrap;gap:4px;padding:4px 8px}.skill-badge-sm{display:inline-block;padding:1px 5px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:3px;font-size:10px;line-height:1.4}.skill-badge-extra{background:var(--bg-secondary)}.agent-tree__skill{display:inline-block;padding:1px 5px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:3px;font-size:10px;line-height:1.4;margin-left:6px}.org-chart-node__skill{display:inline-block;padding:1px 5px;background:var(--bg-tertiary);color:var(--text-secondary);border-radius:3px;font-size:10px;line-height:1.4}.divider{color:var(--border)}.text-muted{color:var(--text-muted)}.link{display:inline-flex;align-items:center;gap:4px;color:var(--todo);text-decoration:none}.link:hover{text-decoration:underline}.text-secondary{color:var(--text-muted)}.agent-import-skills-section{margin-top:var(--space-lg)}.agent-import-skill-list{display:flex;flex-direction:column;gap:var(--space-xs);max-height:calc(var(--space-2xl) * 6);overflow-y:auto}.agent-import-skill-item{display:flex;align-items:flex-start;gap:var(--space-sm);padding:var(--space-sm) var(--space-md);border-radius:var(--radius-sm);background:var(--surface);border:1px solid var(--border)}.agent-import-skill-icon{flex-shrink:0}.agent-import-skill-details{display:flex;flex-direction:column;gap:var(--space-xs);min-width:0}.agent-import-skill-name{font-weight:500;color:var(--text)}.agent-import-skill-description{color:var(--text-muted)}.agent-import-empty{color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs) * 1.25);text-align:center;padding:var(--space-lg)}.agent-import-result{display:flex;flex-direction:column;align-items:center;text-align:center;gap:var(--space-sm)}.agent-import-result-icon{color:var(--color-success);margin-bottom:var(--space-xs)}.agent-import-result-title{margin:0;font-size:calc(var(--space-md) + var(--space-xs));font-weight:600}.agent-import-result-company{color:var(--text-muted);font-size:calc(var(--space-md) + var(--space-xs) * .25);margin:0 0 var(--space-md) 0}.agent-import-result-stats{display:flex;gap:var(--space-lg);margin-bottom:var(--space-md);padding:var(--space-md);background:var(--bg-secondary);border-radius:var(--radius-md)}.agent-import-result-stat{display:flex;align-items:center;gap:var(--space-sm);font-size:calc(var(--space-sm) + var(--space-xs) * 1.25);padding:var(--space-xs) var(--space-sm)}.agent-import-result-stat--success{color:var(--color-success)}.agent-import-result-stat--skipped{color:var(--color-warning)}.agent-import-result-stat--error{color:var(--color-error)}.agent-import-result-stat--success:before,.agent-import-result-stat--skipped:before,.agent-import-result-stat--error:before{content:"";width:var(--space-sm);height:var(--space-sm);border-radius:50%;flex-shrink:0}.agent-import-result-stat--success:before{background:var(--color-success)}.agent-import-result-stat--skipped:before{background:var(--color-warning)}.agent-import-result-stat--error:before{background:var(--color-error)}.agent-import-result-agents{display:flex;flex-direction:column;gap:var(--space-xs);width:100%;text-align:left}.agent-import-result-agent{display:flex;align-items:center;gap:calc(var(--space-sm) - var(--space-xs) * .5);font-size:calc(var(--space-md) + var(--space-xs) * .25);color:var(--color-success);padding:var(--space-xs) var(--space-sm);background:color-mix(in srgb,var(--color-success) 8%,transparent);border-radius:var(--radius-sm)}.agent-import-result-errors{display:flex;flex-direction:column;gap:var(--space-xs);width:100%;text-align:left;margin-top:var(--space-sm)}.agent-import-result-error{display:flex;align-items:center;gap:calc(var(--space-sm) - var(--space-xs) * .5);font-size:calc(var(--space-sm) + var(--space-xs));color:var(--color-error);padding:var(--space-xs) var(--space-sm);background:color-mix(in srgb,var(--color-error) 8%,transparent);border-radius:var(--radius-sm)}.agent-import-result-divider{align-self:stretch;height:1px;background:var(--border);margin:var(--space-md) 0}.agent-import-result-section-title{font-size:calc(var(--space-sm) + var(--space-xs));font-weight:600;color:var(--text-muted);text-transform:uppercase;letter-spacing:.04em;margin:0 0 var(--space-sm) 0}.agent-import-browse{margin-bottom:var(--space-md)}.agent-import-browse-header{display:flex;flex-direction:column;gap:var(--space-sm);margin-bottom:var(--space-md)}.agent-import-browse-search{position:relative;display:flex;align-items:center}.agent-import-browse-search-icon{position:absolute;left:var(--space-sm);color:var(--text-muted);pointer-events:none}.agent-import-browse-search-input{width:100%;padding:var(--space-sm) var(--space-sm) var(--space-sm) calc(var(--space-sm) + var(--space-lg));border:1px solid var(--border);border-radius:var(--radius-md);background:var(--surface);color:var(--text);font-size:calc(var(--space-md) + var(--space-xs) * .5)}.agent-import-browse-search-input:focus{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring)}.agent-import-browse-selected{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-sm);background:color-mix(in srgb,var(--todo) 10%,transparent);border:1px solid color-mix(in srgb,var(--todo) 30%,transparent);border-radius:var(--radius-md)}.agent-import-browse-selected-label{color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs))}.agent-import-browse-selected-name{flex:1;font-weight:500;color:var(--todo)}.agent-import-browse-loading{display:flex;align-items:center;justify-content:center;gap:var(--space-sm);padding:var(--space-xl) 0;color:var(--text-muted)}.agent-import-browse-error{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-md);background:color-mix(in srgb,var(--color-error) 8%,transparent);border-radius:var(--radius-md);color:var(--color-error);font-size:calc(var(--space-md) + var(--space-xs) * .25)}.agent-import-browse-list{display:flex;flex-direction:column;gap:var(--space-xs);max-height:calc(var(--space-xl) * 12 + var(--space-md));overflow-y:auto;border:1px solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.agent-import-browse-item{display:flex;flex-direction:column;gap:calc(var(--space-xs) * .5);padding:var(--space-sm);cursor:pointer;border-bottom:1px solid var(--border);transition:background-color var(--transition-fast)}.agent-import-browse-item:last-child{border-bottom:none}.agent-import-browse-item:hover{background:var(--surface-hover)}.agent-import-browse-item:focus-visible{outline:none;background:var(--surface-hover);box-shadow:var(--focus-ring)}.agent-import-browse-item--selected{background:color-mix(in srgb,var(--todo) 10%,transparent);border-color:var(--todo)}.agent-import-browse-item-header{display:flex;align-items:center;justify-content:space-between;gap:var(--space-sm)}.agent-import-browse-item-name{font-weight:500;color:var(--text)}.agent-import-browse-item-installs{font-size:calc(var(--space-sm) + var(--space-xs) * .75);color:var(--text-muted);white-space:nowrap}.agent-import-browse-item-tagline{font-size:calc(var(--space-sm) + var(--space-xs));color:var(--text-muted);line-height:1.4}.agent-import-browse-item-repo{font-size:calc(var(--space-sm) + var(--space-xs) * .75);color:var(--text-muted);font-family:var(--font-mono)}.agent-import-browse-empty{padding:var(--space-lg);text-align:center;color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs) * 1.25)}.agent-controls-actions{display:flex;gap:var(--space-sm)}.agent-global-controls{display:flex;align-items:center;padding:var(--space-md) var(--space-lg);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-md);margin-bottom:var(--space-lg)}.heartbeat-multiplier-label{font-weight:500;color:var(--text);white-space:nowrap}.agent-import-dialog{max-width:calc(var(--space-xl) * 23 + var(--space-sm))}.agent-import-description{color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs) * 1.25);margin:0 0 var(--space-md) 0;line-height:1.5}.agent-import-description code{background:var(--surface-hover);padding:calc(var(--space-xs) * .25) var(--space-xs);border-radius:calc(var(--radius-sm) - var(--space-xs) * .25);font-size:calc(var(--space-sm) + var(--space-xs))}.agent-import-file-upload{display:flex;align-items:center;gap:var(--space-sm);margin-bottom:var(--space-md)}.agent-import-file-input{display:none}.agent-import-upload-btn{display:inline-flex;align-items:center;gap:calc(var(--space-sm) - var(--space-xs) * .5)}.agent-import-file-hint{color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs))}.agent-import-divider{display:flex;align-items:center;gap:var(--space-md);margin-bottom:var(--space-md);color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs))}.agent-import-divider:before,.agent-import-divider:after{content:"";flex:1;height:1px;background:var(--border)}.agent-import-textarea{width:100%;min-height:calc(var(--space-xl) * 5);padding:var(--space-sm);border:1px solid var(--border);border-radius:var(--radius-md);background:var(--surface);color:var(--text);font-family:var(--font-mono);font-size:calc(var(--space-sm) + var(--space-xs));line-height:1.5;resize:vertical}.agent-import-textarea:focus{outline:none;border-color:var(--todo);box-shadow:var(--focus-ring)}.agent-import-company{display:flex;align-items:center;gap:var(--space-sm);margin-bottom:var(--space-md)}.agent-import-company-label{color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs));text-transform:uppercase;letter-spacing:.04em}.agent-import-company-name{font-weight:600;font-size:calc(var(--space-md) + var(--space-xs) * .5)}.agent-import-count{display:flex;align-items:center;gap:calc(var(--space-sm) - var(--space-xs) * .5);color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs) * 1.25);margin-bottom:var(--space-md)}.agent-import-selection-controls{display:flex;gap:var(--space-sm);flex-wrap:wrap;margin-bottom:var(--space-md)}.agent-import-agent-list{display:flex;flex-direction:column;gap:calc(var(--space-sm) - var(--space-xs) * .5);max-height:calc(var(--space-xl) * 11 + var(--space-lg));overflow-y:auto}.agent-import-agent-item{display:flex;align-items:center;gap:var(--space-sm);padding:var(--space-sm);border:1px solid var(--border);border-radius:var(--radius-md);background:var(--surface)}.agent-import-agent-icon{font-size:calc(var(--space-md) + var(--space-xs) * 1.5);line-height:1;flex-shrink:0}.agent-import-agent-details{display:flex;flex-direction:column;min-width:0}.agent-import-agent-name{font-weight:500;font-size:calc(var(--space-sm) + var(--space-xs) * 1.25)}.agent-import-agent-meta{color:var(--text-muted);font-size:calc(var(--space-sm) + var(--space-xs) * .75)}.agent-import-agent-title{color:var(--text-muted)}.agent-import-agent-role{text-transform:capitalize}.agent-import-agent-model{color:var(--text-muted)}