specrails-hub 1.40.1 → 1.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{n as e,o as t,r as n,t as r}from"./createLucideIcon-Cg9402G2.js";import{B as i,N as a,Q as o,V as s,j as c,lt as l,nt as u,rt as d}from"./index-BNVhP-OE.js";var f=r(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),p=t(n(),1);function m(e){let t=new Set;return e.filter(e=>{let n=`${e.type}:${e.jobId}`;return t.has(n)?!1:(t.add(n),!0)})}function h({activeProjectId:e,limit:t=50}){let[n,r]=(0,p.useState)([]),[o,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(!0),u=(0,p.useRef)(e);(0,p.useEffect)(()=>{u.current=e},[e]);let{registerHandler:d,unregisterHandler:f}=a();(0,p.useEffect)(()=>{if(!e){r([]),l(!0);return}let n=!1;s(!0),r([]),l(!0);async function a(){let e=i();try{let i=await fetch(`${e}/activity?limit=${t}`);if(!i.ok||n)return;let a=await i.json();if(n)return;r(a),l(a.length===t)}catch{}finally{n||s(!1)}}return a(),()=>{n=!0}},[e,t]);let h=(0,p.useCallback)(async()=>{if(o||!c)return;s(!0);let e=i();try{r(n=>{let i=n[n.length-1];if(!i)return n;let a=encodeURIComponent(i.timestamp);return fetch(`${e}/activity?limit=${t}&before=${a}`).then(e=>e.json()).then(e=>{r(t=>m([...t,...e])),l(e.length===t),s(!1)}).catch(()=>s(!1)),n})}catch{s(!1)}},[o,c,t]),g=(0,p.useCallback)(e=>{let t=e,n=u.current;if(!(!t||typeof t.type!=`string`)&&!(t.projectId&&t.projectId!==n)){if(t.type===`queue`&&Array.isArray(t.jobs)){let e=[];for(let n of t.jobs){let t=n.status===`completed`?`job_completed`:n.status===`failed`?`job_failed`:n.status===`canceled`?`job_canceled`:`job_started`;e.push({id:`${t}:${n.id}`,type:t,jobId:n.id,jobCommand:n.command??``,timestamp:n.startedAt??new Date().toISOString(),summary:`${t.replace(`_`,` `)}: ${n.command??``}`,costUsd:null})}e.length>0&&r(t=>m([...e,...t]))}if(t.type===`phase`&&t.phase&&t.state&&t.timestamp){let e={id:`phase:${t.phase}:${t.state}:${t.timestamp}`,type:`job_started`,jobId:`phase-${t.phase}`,jobCommand:`Phase: ${t.phase} → ${t.state}`,timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};r(t=>m([e,...t]))}}},[]);return(0,p.useLayoutEffect)(()=>(d(`activity`,g),()=>f(`activity`)),[g,d,f]),{items:n,loading:o,hasMore:c,loadMore:h}}var g=e();function _(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function v({type:e}){switch(e){case`job_completed`:return(0,g.jsx)(d,{className:`w-4 h-4 text-green-500 flex-shrink-0`});case`job_failed`:return(0,g.jsx)(u,{className:`w-4 h-4 text-red-500 flex-shrink-0`});case`job_canceled`:return(0,g.jsx)(f,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,g.jsx)(s,{className:`w-4 h-4 text-blue-500 flex-shrink-0`})}}function y(e){switch(e){case`job_completed`:return`Completed`;case`job_failed`:return`Failed`;case`job_canceled`:return`Canceled`;default:return`Started`}}function b(e){switch(e){case`job_completed`:return`text-green-500`;case`job_failed`:return`text-red-500`;case`job_canceled`:return`text-muted-foreground`;default:return`text-blue-500`}}function x(){let{activeProjectId:e}=c(),{items:t,loading:n,hasMore:r,loadMore:i}=h({activeProjectId:e}),a=(0,p.useRef)(null);return(0,p.useEffect)(()=>{let e=a.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&r&&!n&&i()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[r,n,i]),(0,g.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,g.jsx)(l,{className:`w-4 h-4 text-muted-foreground`}),(0,g.jsx)(`h1`,{className:`text-sm font-medium`,children:`Activity`})]}),(0,g.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[n&&t.length===0?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,g.jsx)(o,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):t.length===0?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,g.jsx)(l,{className:`w-8 h-8 opacity-40`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No activity yet`}),(0,g.jsx)(`p`,{className:`text-xs opacity-70`,children:`Job events will appear here when jobs run`})]}):(0,g.jsx)(`ul`,{className:`divide-y divide-border/50`,children:t.map(e=>(0,g.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,g.jsx)(v,{type:e.type}),(0,g.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,g.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:e.jobCommand,children:e.jobCommand}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,g.jsx)(`span`,{className:`text-xs font-medium ${b(e.type)}`,children:y(e.type)}),e.costUsd!=null&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,e.costUsd.toFixed(4)]})]})]}),(0,g.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:_(e.timestamp)})]},`${e.type}:${e.jobId}`))}),(0,g.jsx)(`div`,{ref:a,className:`h-1`}),n&&t.length>0&&(0,g.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,g.jsx)(o,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!r&&t.length>0&&(0,g.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:`All activity loaded`})]})]})}export{x as default};
1
+ import{n as e,o as t,r as n,t as r}from"./createLucideIcon-Cg9402G2.js";import{$ as i,B as a,N as o,V as s,it as c,j as l,rt as u,ut as d}from"./index-geDvjEca.js";var f=r(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),p=t(n(),1);function m(e){let t=new Set;return e.filter(e=>{let n=`${e.type}:${e.jobId}`;return t.has(n)?!1:(t.add(n),!0)})}function h({activeProjectId:e,limit:t=50}){let[n,r]=(0,p.useState)([]),[i,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(!0),u=(0,p.useRef)(e);(0,p.useEffect)(()=>{u.current=e},[e]);let{registerHandler:d,unregisterHandler:f}=o();(0,p.useEffect)(()=>{if(!e){r([]),l(!0);return}let n=!1;s(!0),r([]),l(!0);async function i(){let e=a();try{let i=await fetch(`${e}/activity?limit=${t}`);if(!i.ok||n)return;let a=await i.json();if(n)return;r(a),l(a.length===t)}catch{}finally{n||s(!1)}}return i(),()=>{n=!0}},[e,t]);let h=(0,p.useCallback)(async()=>{if(i||!c)return;s(!0);let e=a();try{r(n=>{let i=n[n.length-1];if(!i)return n;let a=encodeURIComponent(i.timestamp);return fetch(`${e}/activity?limit=${t}&before=${a}`).then(e=>e.json()).then(e=>{r(t=>m([...t,...e])),l(e.length===t),s(!1)}).catch(()=>s(!1)),n})}catch{s(!1)}},[i,c,t]),g=(0,p.useCallback)(e=>{let t=e,n=u.current;if(!(!t||typeof t.type!=`string`)&&!(t.projectId&&t.projectId!==n)){if(t.type===`queue`&&Array.isArray(t.jobs)){let e=[];for(let n of t.jobs){let t=n.status===`completed`?`job_completed`:n.status===`failed`?`job_failed`:n.status===`canceled`?`job_canceled`:`job_started`;e.push({id:`${t}:${n.id}`,type:t,jobId:n.id,jobCommand:n.command??``,timestamp:n.startedAt??new Date().toISOString(),summary:`${t.replace(`_`,` `)}: ${n.command??``}`,costUsd:null})}e.length>0&&r(t=>m([...e,...t]))}if(t.type===`phase`&&t.phase&&t.state&&t.timestamp){let e={id:`phase:${t.phase}:${t.state}:${t.timestamp}`,type:`job_started`,jobId:`phase-${t.phase}`,jobCommand:`Phase: ${t.phase} → ${t.state}`,timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};r(t=>m([e,...t]))}}},[]);return(0,p.useLayoutEffect)(()=>(d(`activity`,g),()=>f(`activity`)),[g,d,f]),{items:n,loading:i,hasMore:c,loadMore:h}}var g=e();function _(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function v({type:e}){switch(e){case`job_completed`:return(0,g.jsx)(c,{className:`w-4 h-4 text-green-500 flex-shrink-0`});case`job_failed`:return(0,g.jsx)(u,{className:`w-4 h-4 text-red-500 flex-shrink-0`});case`job_canceled`:return(0,g.jsx)(f,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,g.jsx)(s,{className:`w-4 h-4 text-blue-500 flex-shrink-0`})}}function y(e){switch(e){case`job_completed`:return`Completed`;case`job_failed`:return`Failed`;case`job_canceled`:return`Canceled`;default:return`Started`}}function b(e){switch(e){case`job_completed`:return`text-green-500`;case`job_failed`:return`text-red-500`;case`job_canceled`:return`text-muted-foreground`;default:return`text-blue-500`}}function x(){let{activeProjectId:e}=l(),{items:t,loading:n,hasMore:r,loadMore:a}=h({activeProjectId:e}),o=(0,p.useRef)(null);return(0,p.useEffect)(()=>{let e=o.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&r&&!n&&a()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[r,n,a]),(0,g.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,g.jsx)(d,{className:`w-4 h-4 text-muted-foreground`}),(0,g.jsx)(`h1`,{className:`text-sm font-medium`,children:`Activity`})]}),(0,g.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[n&&t.length===0?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,g.jsx)(i,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):t.length===0?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,g.jsx)(d,{className:`w-8 h-8 opacity-40`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No activity yet`}),(0,g.jsx)(`p`,{className:`text-xs opacity-70`,children:`Job events will appear here when jobs run`})]}):(0,g.jsx)(`ul`,{className:`divide-y divide-border/50`,children:t.map(e=>(0,g.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,g.jsx)(v,{type:e.type}),(0,g.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,g.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:e.jobCommand,children:e.jobCommand}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,g.jsx)(`span`,{className:`text-xs font-medium ${b(e.type)}`,children:y(e.type)}),e.costUsd!=null&&(0,g.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,e.costUsd.toFixed(4)]})]})]}),(0,g.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:_(e.timestamp)})]},`${e.type}:${e.jobId}`))}),(0,g.jsx)(`div`,{ref:o,className:`h-1`}),n&&t.length>0&&(0,g.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,g.jsx)(i,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!r&&t.length>0&&(0,g.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:`All activity loaded`})]})]})}export{x as default};
@@ -1,4 +1,4 @@
1
- import{n as e,o as t,r as n,t as r}from"./createLucideIcon-Cg9402G2.js";import{t as i}from"./copy-C1m2IjcW.js";import{$ as a,A as o,B as s,C as c,D as l,E as u,G as d,H as f,K as p,O as m,Q as h,S as g,T as _,U as v,W as y,X as b,Z as x,_ as S,b as C,ct as w,et as T,f as E,g as D,h as O,k,m as A,n as j,p as M,pt as N,q as P,w as F,x as I,y as L,z as R}from"./index-BNVhP-OE.js";var z=r(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),B=r(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),ee=r(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),V=r(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),te=r(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),H=r(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),ne=r(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),U=r(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),W=t(n(),1),G=e(),re=/^[a-z0-9][a-z0-9-]*$/;function K({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:i,onCancel:a}){let[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(r[0]??``);(0,W.useEffect)(()=>{e&&(t===`edit`&&n?(s(n.tags.join(`, `)),l(r.includes(n.agent)?n.agent:r[0]??``)):(s(``),l(r[0]??``)))},[e,t,n,r]);let u=o.split(`,`).map(e=>e.trim()).filter(Boolean),d=u.filter(e=>!re.test(e)),f=u.length>0&&d.length===0&&r.includes(c);return(0,G.jsx)(E,{open:e,onOpenChange:e=>{e||a()},children:(0,G.jsxs)(M,{className:`max-w-md`,children:[(0,G.jsxs)(D,{children:[(0,G.jsx)(S,{children:t===`edit`?`Edit routing rule`:`Add routing rule`}),(0,G.jsx)(A,{children:t===`edit`?`Update the tags or target agent for this rule.`:`Add a tag-matched routing rule using lowercase kebab-case tags.`})]}),(0,G.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Tags`}),(0,G.jsx)(j,{autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:`frontend, ui`,"aria-label":`Tags`,className:`text-sm font-mono`}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Comma-separated. Use lowercase kebab-case like `,(0,G.jsx)(`code`,{children:`frontend`}),` or `,(0,G.jsx)(`code`,{children:`api-design`}),`.`]}),d.length>0&&(0,G.jsxs)(`p`,{className:`text-[11px] text-red-400 mt-1`,children:[`Invalid tag`,d.length===1?``:`s`,`: `,d.join(`, `),`. Tags must use lowercase letters, digits, and hyphens only.`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Route to`}),(0,G.jsx)(`select`,{value:c,onChange:e=>l(e.target.value),"aria-label":`Route to`,className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:`Only agents in this profile's chain can be routing targets.`})]})]}),(0,G.jsxs)(O,{children:[(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,G.jsx)(R,{size:`sm`,onClick:()=>i(u,c),disabled:!f,children:t===`edit`?`Save changes`:`Add rule`})]})]})})}var q=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),J=[`sonnet`,`opus`,`haiku`],Y=/^[a-z0-9][a-z0-9-]*$/;function ie({profile:e,onChange:t,footer:n,onValidityChange:r,onSoftWarningsChange:i}){let[a,o]=(0,W.useState)([]),[d,p]=(0,W.useState)(!1),[h,g]=(0,W.useState)(!1),[v,y]=(0,W.useState)(null);(0,W.useEffect)(()=>{let e=!1;return fetch(`${s()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||o(t.agents)}).catch(()=>{e||o([])}),()=>{e=!0}},[]);let x=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},S=new Set(e.agents.map(e=>e.id)),w=a.filter(e=>!S.has(e.id)),T=(0,W.useMemo)(()=>{let t=[];for(let n of q)e.agents.some(e=>e.id===n)||t.push(`Missing required baseline agent: ${n}`);let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(`Routing may have at most one default rule (found ${n.length})`),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(`The default routing rule must be the last entry`)}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(`Routing references agent not in the chain: ${n.agent}`),`tags`in n){let e=n.tags.filter(e=>!Y.test(e));e.length>0&&t.push(`Routing rule ${n.agent} has invalid tags: ${e.join(`, `)} (use lowercase kebab-case)`)}return t},[e]),E=(0,W.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!q.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e]),D=(0,W.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,W.useEffect)(()=>{r&&r(T)},[T,r]),(0,W.useEffect)(()=>{i&&i({agentsMissingRouting:E})},[E,i]);let O=e=>{x(t=>{let n={id:e,model:`sonnet`},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),p(!1)},A=t=>{let n=e.agents[t];q.has(n.id)||x(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},M=(t,n)=>{if(t===n)return;let r=e.agents.findIndex(e=>e.id===t),i=e.agents.findIndex(e=>e.id===n);if(r<0||i<0)return;let a=C(e.agents,r,i),o=a.findIndex(e=>e.id===`sr-architect`);if(o>0){let[e]=a.splice(o,1);a.unshift(e)}let s=a.findIndex(e=>e.id===`sr-merge-resolver`);if(s>=0&&s!==a.length-1){let[e]=a.splice(s,1);a.push(e)}x(e=>{e.agents=a})},N=k(m(u,{activationConstraint:{distance:4}}),m(_,{coordinateGetter:I})),P=e=>{let{active:t,over:n}=e;n&&M(String(t.id),String(n.id))},z=(e,t)=>{x(n=>{n.agents[e].model=t})},B=(e,t)=>{x(n=>{let r={tags:e,agent:t},i=n.routing.findIndex(e=>`default`in e&&e.default===!0);i>=0?n.routing.splice(i,0,r):n.routing.push(r)}),g(!1)},ee=()=>{x(e=>{e.routing.some(e=>`default`in e&&e.default===!0)||e.agents.some(e=>e.id===`sr-developer`)&&e.routing.push({default:!0,agent:`sr-developer`})})},V=e=>`default`in e&&e.default===!0,te=(e,t)=>{x(n=>{let r=n.routing[e];r&&(V(r)||(r.agent=t))})},H=(e,t,n)=>{x(r=>{let i=r.routing[e];i&&(V(i)||(i.tags=t,i.agent=n))})},ne=e=>{x(t=>{let n=t.routing[e];n&&(V(n)||t.routing.splice(e,1))})},U=(t,n)=>{let r=t+n;if(r<0||r>=e.routing.length)return;let i=e.routing[t],a=e.routing[r];V(i)||V(a)||x(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,G.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,G.jsx)(K,{open:h,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:B,onCancel:()=>g(!1)}),(0,G.jsx)(K,{open:v!==null,mode:`edit`,initial:v!==null&&e.routing[v]&&!(`default`in e.routing[v])?{tags:e.routing[v].tags,agent:e.routing[v].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{v!==null&&(H(v,e,t),y(null))},onCancel:()=>y(null)}),T.length>0&&(0,G.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[(0,G.jsxs)(`div`,{className:`font-medium mb-1`,children:[T.length,` validation `,T.length===1?`issue`:`issues`]}),(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:T.map((e,t)=>(0,G.jsx)(`li`,{children:e},t))})]}),(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Name`}),(0,G.jsx)(j,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Description`}),(0,G.jsx)(j,{value:e.description??``,onChange:e=>x(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:`What is this profile for?`})]})]}),(0,G.jsxs)(`section`,{children:[(0,G.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:`Orchestrator`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:`Top-level model for both commands. batch-implement delegates to implement per feature, so every rail it spawns inherits this profile's agent chain.`})]}),(0,G.jsx)(oe,{value:e.orchestrator.model,onChange:e=>x(t=>{t.orchestrator.model=e})})]})]}),(0,G.jsxs)(`section`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[`Agent chain (`,e.agents.length,`)`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>p(e=>!e),disabled:w.length===0,title:w.length===0?`All catalog agents are already in the chain`:`Add an agent from the catalog`,children:[(0,G.jsx)(b,{className:`w-3.5 h-3.5 mr-1`}),` Add`]})]}),d&&(0,G.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,G.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`Pick from catalog (`,w.length,` available)`]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>p(!1),title:`Close`,children:(0,G.jsx)(f,{className:`w-3 h-3`})})]}),w.length===0?(0,G.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:`No more agents in the catalog. Add custom agents from the Agents Catalog tab.`}):(0,G.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:w.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>O(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,G.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 text-purple-400`:`bg-muted text-muted-foreground`),children:e.kind})]},e.id))})]}),(0,G.jsx)(F,{sensors:N,collisionDetection:l,onDragEnd:P,children:(0,G.jsx)(L,{items:e.agents.map(e=>e.id),strategy:c,children:(0,G.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,G.jsx)(X,{agent:e,canRemove:!q.has(e.id),onModel:e=>z(t,e),onRemove:()=>A(t)},e.id))})})})]}),(0,G.jsxs)(`section`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[`Routing (`,e.routing.length,`)`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!D&&(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:ee,disabled:e.agents.length===0,title:e.agents.length===0?`Add at least one agent before creating routing rules`:void 0,children:[(0,G.jsx)(b,{className:`w-3.5 h-3.5 mr-1`}),` Add default`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>g(!0),disabled:e.agents.length===0,title:e.agents.length===0?`Add at least one agent before creating routing rules`:void 0,children:[(0,G.jsx)(b,{className:`w-3.5 h-3.5 mr-1`}),` Add rule`]})]})]}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:`First matching rule wins. Rules are editable and removable, and the default catch-all stays last when present. If you leave routing empty, the pipeline falls back to the first developer-shaped agent in the chain.`}),E.length>0&&(0,G.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[(0,G.jsx)(`div`,{className:`font-medium mb-1`,children:`Untargeted agents in the chain`}),(0,G.jsxs)(`div`,{children:[`No routing rule points to: `,(0,G.jsx)(`span`,{className:`font-mono`,children:E.join(`, `)}),`. Add a tag rule or retarget the default rule if you want them to run.`]})]}),(0,G.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,G.jsx)(ae,{rule:t,ordinal:n+1,isLast:n===e.routing.length-1,canMove:!r,canRemove:!r,canEdit:!r,chainAgents:e.agents.map(e=>e.id),onAgentChange:e=>te(n,e),onEdit:()=>y(n),onUp:()=>U(n,-1),onDown:()=>U(n,1),onRemove:()=>ne(n)},n)})})]}),n&&(0,G.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function X({agent:e,canRemove:t,onModel:n,onRemove:r}){let i=q.has(e.id),s=e.id===`sr-architect`,c=e.id===`sr-merge-resolver`,{attributes:l,listeners:u,setNodeRef:d,transform:p,transition:m,isDragging:h}=g({id:e.id});return(0,G.jsxs)(`div`,{ref:d,style:{transform:o.Transform.toString(p),transition:m,opacity:h?.5:void 0,zIndex:h?10:void 0},className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors bg-background`,children:[(0,G.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:`Drag to reorder`,"aria-label":`Drag handle`,...l,...u,children:(0,G.jsx)(a,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),s&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-dracula-purple/15 text-dracula-purple`,title:`Pinned to first position — pipeline always starts with sr-architect`,children:[(0,G.jsx)(H,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` first`]}),c&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-dracula-purple/15 text-dracula-purple`,title:`Pinned to last position — merge phase always runs last`,children:[(0,G.jsx)(H,{className:`w-2.5 h-2.5 rotate-45`}),` last`]}),i&&!s&&!c&&(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:`required`}),(0,G.jsx)(oe,{value:e.model??`sonnet`,onChange:n}),(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:r,disabled:!t,title:t?`Remove`:`Required baseline agent — the pipeline depends on this row`,children:(0,G.jsx)(f,{className:`w-3 h-3`})})]})}function ae({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:s,onEdit:c,onUp:l,onDown:u,onRemove:d}){let p=`default`in e&&e.default===!0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),p?(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:`everything else`}):(0,G.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),p?(0,G.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":`Default routing target (core, read-only)`,title:`Core fallback — not editable`,children:e.agent}):(0,G.jsx)(`select`,{value:e.agent,onChange:e=>s(e.target.value),"aria-label":`Routing target for rule ${t}`,className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:c,title:`Edit rule`,"aria-label":`Edit rule ${t}`,children:(0,G.jsx)(x,{className:`w-3 h-3`})}),r&&!n&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:`Move down`,children:(0,G.jsx)(z,{className:`w-3 h-3`})}),r&&t>1&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:`Move up`,children:(0,G.jsx)(B,{className:`w-3 h-3`})}),i&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded`,onClick:d,title:`Remove`,children:(0,G.jsx)(f,{className:`w-3 h-3`})})]}),p&&(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:`Core fallback — the pipeline's last-resort rule, pinned to sr-developer`,children:`core · default`})]})}function oe({value:e,onChange:t}){return(0,G.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:J.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))})}function se({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a=`Confirm`,inputPattern:o,inputInvalidHint:s,onConfirm:c,onCancel:l}){let[u,d]=(0,W.useState)(i);(0,W.useEffect)(()=>{e&&d(i)},[e,i]);let f=u.trim(),p=!o||o.test(f),m=f.length>0&&p;return(0,G.jsx)(E,{open:e,onOpenChange:e=>{e||l()},children:(0,G.jsxs)(M,{className:`max-w-md`,children:[(0,G.jsx)(D,{children:(0,G.jsx)(S,{children:t})}),(0,G.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,G.jsx)(j,{autoFocus:!0,value:u,placeholder:r,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m&&c(f)},className:`text-sm font-mono`}),f.length>0&&!p&&s&&(0,G.jsx)(`p`,{className:`text-[11px] text-yellow-500`,children:s})]}),(0,G.jsxs)(O,{children:[(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:l,children:`Cancel`}),(0,G.jsx)(R,{size:`sm`,onClick:()=>c(f),disabled:!m,children:a})]})]})})}function ce({open:e,title:t,description:n,confirmLabel:r=`Confirm`,destructive:i=!1,onConfirm:a,onCancel:o}){return(0,G.jsx)(E,{open:e,onOpenChange:e=>{e||o()},children:(0,G.jsxs)(M,{className:`max-w-md`,children:[(0,G.jsx)(D,{children:(0,G.jsx)(S,{children:t})}),n&&(0,G.jsx)(`div`,{className:`py-2`,children:(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,G.jsxs)(O,{children:[(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:o,children:`Cancel`}),(0,G.jsx)(R,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r})]})]})})}function le(){let[e,t]=(0,W.useState)([]),[n,r]=(0,W.useState)(null),[a,o]=(0,W.useState)(null),[c,l]=(0,W.useState)(!0),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)([]),[g,_]=(0,W.useState)([]),[v,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)(null),E=(0,W.useCallback)(async()=>{l(!0),d(null);try{let e=await fetch(`${s()}/profiles`);if(!e.ok)throw Error(`List failed: ${e.status}`);let i=await e.json();t(i.profiles),i.profiles.length>0&&!n&&r(i.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[n]);(0,W.useEffect)(()=>{E()},[E]),(0,W.useEffect)(()=>{if(!n){o(null);return}let e=!1;return fetch(`${s()}/profiles/${encodeURIComponent(n)}`).then(e=>{if(!e.ok)throw Error(`Load failed: ${e.status}`);return e.json()}).then(t=>{e||o(t.profile)}).catch(t=>{e||d(t.message)}),()=>{e=!0}},[n]);let D=(0,W.useCallback)(async()=>{p(!0),d(null);try{let e=await fetch(`${s()}/profiles/migrate-from-settings`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Migration failed: ${e.status}`)}await E(),r(`default`),N.success(`Profile migrated`,{description:`default profile created from your current agents`})}catch(e){let t=e.message;d(t),N.error(`Migration failed`,{description:t})}finally{p(!1)}},[E]),O=(0,W.useCallback)(async e=>{x(!1),p(!0),d(null);try{let t={schemaVersion:1,name:e,description:``,orchestrator:{model:`sonnet`},agents:[{id:`sr-architect`,model:`sonnet`,required:!0},{id:`sr-developer`,model:`sonnet`,required:!0},{id:`sr-reviewer`,model:`sonnet`,required:!0},{id:`sr-merge-resolver`,model:`sonnet`,required:!0}],routing:[{default:!0,agent:`sr-developer`}]},n=await fetch(`${s()}/profiles`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Create failed: ${n.status}`)}await E(),r(e),N.success(`Profile created`,{description:e})}catch(e){let t=e.message;d(t),N.error(`Failed to create profile`,{description:t})}finally{p(!1)}},[E]),k=(0,W.useCallback)(async(e,t)=>{C(null),p(!0),d(null);try{let n=await fetch(`${s()}/profiles/${encodeURIComponent(e)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Duplicate failed: ${n.status}`)}await E(),r(t),N.success(`Profile duplicated`,{description:`${e} → ${t}`})}catch(e){let t=e.message;d(t),N.error(`Failed to duplicate profile`,{description:t})}finally{p(!1)}},[E]),A=(0,W.useCallback)(async e=>{T(null),p(!0),d(null);try{let t=await fetch(`${s()}/profiles/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Delete failed: ${t.status}`)}r(t=>t===e?null:t),await E(),N.success(`Profile deleted`,{description:e})}catch(e){let t=e.message;d(t),N.error(`Failed to delete profile`,{description:t})}finally{p(!1)}},[E]),j=(0,W.useCallback)(()=>x(!0),[]),M=(0,W.useCallback)(e=>C({from:e}),[]),F=(0,W.useCallback)(e=>T({name:e}),[]),I=(0,W.useCallback)(async(e,t)=>{p(!0),d(null);try{let n=await fetch(`${s()}/profiles/${encodeURIComponent(e.name)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Save failed: ${n.status}`)}o(e),t.length>0?N.warning(`Profile saved with untargeted agents`,{description:`No routing rule points to: ${t.join(`, `)}. Add a tag rule or retarget the default rule if you want them to run.`,duration:6e3}):N.success(`Profile saved`,{description:e.name})}catch(e){let t=e.message;d(t),N.error(`Failed to save profile`,{description:t})}finally{p(!1)}},[]),L=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(se,{open:v,title:`New profile`,description:`Pick a lowercase kebab-case name (letters, digits, and hyphens).`,placeholder:`my-profile`,confirmLabel:`Create`,inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:`Must start with a letter or digit and contain only lowercase letters, digits, and hyphens.`,onConfirm:e=>void O(e),onCancel:()=>x(!1)}),S&&(0,G.jsx)(se,{open:!0,title:`Duplicate "${S.from}"`,description:`Name for the new profile.`,placeholder:`${S.from}-copy`,initialValue:`${S.from}-copy`,confirmLabel:`Duplicate`,inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:`Lowercase kebab-case only.`,onConfirm:e=>void k(S.from,e),onCancel:()=>C(null)}),w&&(0,G.jsx)(ce,{open:!0,title:`Delete profile "${w.name}"?`,description:`This cannot be undone. Jobs already launched with this profile keep their snapshot; future launches will fall back to the resolution order.`,confirmLabel:`Delete`,destructive:!0,onConfirm:()=>void A(w.name),onCancel:()=>T(null)})]});return c?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading profiles…`})}):e.length===0?(0,G.jsxs)(G.Fragment,{children:[L,(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No profiles yet`}),(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:`Profiles let you save orchestrator + agent + routing combinations and pick one per rail.`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,G.jsxs)(R,{size:`sm`,onClick:D,disabled:f,children:[(0,G.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),` Migrate from current agents`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:j,disabled:f,children:[(0,G.jsx)(b,{className:`w-3.5 h-3.5 mr-1.5`}),` Blank profile`]})]}),(0,G.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:[`"Migrate" reads your existing `,(0,G.jsx)(`code`,{className:`text-foreground`,children:`.claude/agents/`}),` `,`frontmatter models and creates a `,(0,G.jsx)(`code`,{className:`text-foreground`,children:`default`}),` profile mirroring today's behavior — zero-loss.`]}),u&&(0,G.jsx)(`div`,{className:`mt-3 text-xs text-red-400`,children:u})]})})]}):(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[L,(0,G.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,G.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Profiles`}),(0,G.jsx)(R,{size:`sm`,variant:`ghost`,onClick:j,disabled:f,children:(0,G.jsx)(b,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:e.map(e=>(0,G.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(e.name===n?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>r(e.name),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&r(e.name)},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),e.isDefault&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`(team default)`})]}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:`Duplicate`,onClick:t=>{t.stopPropagation(),M(e.name)},children:(0,G.jsx)(i,{className:`w-3 h-3`})}),!e.isDefault&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded`,title:`Delete`,onClick:t=>{t.stopPropagation(),F(e.name)},children:(0,G.jsx)(y,{className:`w-3 h-3`})})]})]},e.name))})]}),(0,G.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,G.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:u}),a?(0,G.jsx)(ie,{profile:a,onChange:o,onValidityChange:h,onSoftWarningsChange:e=>_(e.agentsMissingRouting),footer:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(R,{size:`sm`,onClick:()=>void I(a,g),disabled:f||m.length>0,title:m.length>0?`Fix validation issues before saving`:void 0,children:[(0,G.jsx)(P,{className:`w-3.5 h-3.5 mr-1.5`}),`Save`]}),f&&(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Saving…`}),m.length>0&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-500`,children:[m.length,` `,m.length===1?`issue`:`issues`,` to resolve`]})]})},a.name):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select a profile to edit`})})]})]})]})}function Z(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
1
+ import{n as e,o as t,r as n,t as r}from"./createLucideIcon-Cg9402G2.js";import{t as i}from"./copy-C1m2IjcW.js";import{$ as a,A as o,B as s,C as c,D as l,E as u,G as d,H as f,K as p,O as m,S as h,T as g,U as _,W as v,X as y,Z as b,_ as x,b as S,et as C,f as w,g as T,h as E,k as D,lt as O,m as k,mt as A,n as j,p as M,q as N,tt as P,w as F,x as I,y as L,z as R}from"./index-geDvjEca.js";var z=r(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),B=r(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),ee=r(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),V=r(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),te=r(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),H=r(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]),ne=r(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]),U=r(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),W=t(n(),1),G=e(),re=/^[a-z0-9][a-z0-9-]*$/;function K({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:i,onCancel:a}){let[o,s]=(0,W.useState)(``),[c,l]=(0,W.useState)(r[0]??``);(0,W.useEffect)(()=>{e&&(t===`edit`&&n?(s(n.tags.join(`, `)),l(r.includes(n.agent)?n.agent:r[0]??``)):(s(``),l(r[0]??``)))},[e,t,n,r]);let u=o.split(`,`).map(e=>e.trim()).filter(Boolean),d=u.filter(e=>!re.test(e)),f=u.length>0&&d.length===0&&r.includes(c);return(0,G.jsx)(w,{open:e,onOpenChange:e=>{e||a()},children:(0,G.jsxs)(M,{className:`max-w-md`,children:[(0,G.jsxs)(T,{children:[(0,G.jsx)(x,{children:t===`edit`?`Edit routing rule`:`Add routing rule`}),(0,G.jsx)(k,{children:t===`edit`?`Update the tags or target agent for this rule.`:`Add a tag-matched routing rule using lowercase kebab-case tags.`})]}),(0,G.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Tags`}),(0,G.jsx)(j,{autoFocus:!0,value:o,onChange:e=>s(e.target.value),placeholder:`frontend, ui`,"aria-label":`Tags`,className:`text-sm font-mono`}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Comma-separated. Use lowercase kebab-case like `,(0,G.jsx)(`code`,{children:`frontend`}),` or `,(0,G.jsx)(`code`,{children:`api-design`}),`.`]}),d.length>0&&(0,G.jsxs)(`p`,{className:`text-[11px] text-red-400 mt-1`,children:[`Invalid tag`,d.length===1?``:`s`,`: `,d.join(`, `),`. Tags must use lowercase letters, digits, and hyphens only.`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Route to`}),(0,G.jsx)(`select`,{value:c,onChange:e=>l(e.target.value),"aria-label":`Route to`,className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:`Only agents in this profile's chain can be routing targets.`})]})]}),(0,G.jsxs)(E,{children:[(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,G.jsx)(R,{size:`sm`,onClick:()=>i(u,c),disabled:!f,children:t===`edit`?`Save changes`:`Add rule`})]})]})})}var q=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),J=[`sonnet`,`opus`,`haiku`],Y=/^[a-z0-9][a-z0-9-]*$/;function ie({profile:e,onChange:t,footer:n,onValidityChange:r,onSoftWarningsChange:i}){let[a,o]=(0,W.useState)([]),[d,p]=(0,W.useState)(!1),[h,_]=(0,W.useState)(!1),[v,b]=(0,W.useState)(null);(0,W.useEffect)(()=>{let e=!1;return fetch(`${s()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||o(t.agents)}).catch(()=>{e||o([])}),()=>{e=!0}},[]);let x=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},C=new Set(e.agents.map(e=>e.id)),w=a.filter(e=>!C.has(e.id)),T=(0,W.useMemo)(()=>{let t=[];for(let n of q)e.agents.some(e=>e.id===n)||t.push(`Missing required baseline agent: ${n}`);let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(`Routing may have at most one default rule (found ${n.length})`),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(`The default routing rule must be the last entry`)}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(`Routing references agent not in the chain: ${n.agent}`),`tags`in n){let e=n.tags.filter(e=>!Y.test(e));e.length>0&&t.push(`Routing rule ${n.agent} has invalid tags: ${e.join(`, `)} (use lowercase kebab-case)`)}return t},[e]),E=(0,W.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!q.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e]),O=(0,W.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,W.useEffect)(()=>{r&&r(T)},[T,r]),(0,W.useEffect)(()=>{i&&i({agentsMissingRouting:E})},[E,i]);let k=e=>{x(t=>{let n={id:e,model:`sonnet`},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),p(!1)},A=t=>{let n=e.agents[t];q.has(n.id)||x(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},M=(t,n)=>{if(t===n)return;let r=e.agents.findIndex(e=>e.id===t),i=e.agents.findIndex(e=>e.id===n);if(r<0||i<0)return;let a=S(e.agents,r,i),o=a.findIndex(e=>e.id===`sr-architect`);if(o>0){let[e]=a.splice(o,1);a.unshift(e)}let s=a.findIndex(e=>e.id===`sr-merge-resolver`);if(s>=0&&s!==a.length-1){let[e]=a.splice(s,1);a.push(e)}x(e=>{e.agents=a})},N=D(m(u,{activationConstraint:{distance:4}}),m(g,{coordinateGetter:I})),P=e=>{let{active:t,over:n}=e;n&&M(String(t.id),String(n.id))},z=(e,t)=>{x(n=>{n.agents[e].model=t})},B=(e,t)=>{x(n=>{let r={tags:e,agent:t},i=n.routing.findIndex(e=>`default`in e&&e.default===!0);i>=0?n.routing.splice(i,0,r):n.routing.push(r)}),_(!1)},ee=()=>{x(e=>{e.routing.some(e=>`default`in e&&e.default===!0)||e.agents.some(e=>e.id===`sr-developer`)&&e.routing.push({default:!0,agent:`sr-developer`})})},V=e=>`default`in e&&e.default===!0,te=(e,t)=>{x(n=>{let r=n.routing[e];r&&(V(r)||(r.agent=t))})},H=(e,t,n)=>{x(r=>{let i=r.routing[e];i&&(V(i)||(i.tags=t,i.agent=n))})},ne=e=>{x(t=>{let n=t.routing[e];n&&(V(n)||t.routing.splice(e,1))})},U=(t,n)=>{let r=t+n;if(r<0||r>=e.routing.length)return;let i=e.routing[t],a=e.routing[r];V(i)||V(a)||x(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,G.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,G.jsx)(K,{open:h,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:B,onCancel:()=>_(!1)}),(0,G.jsx)(K,{open:v!==null,mode:`edit`,initial:v!==null&&e.routing[v]&&!(`default`in e.routing[v])?{tags:e.routing[v].tags,agent:e.routing[v].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{v!==null&&(H(v,e,t),b(null))},onCancel:()=>b(null)}),T.length>0&&(0,G.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[(0,G.jsxs)(`div`,{className:`font-medium mb-1`,children:[T.length,` validation `,T.length===1?`issue`:`issues`]}),(0,G.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:T.map((e,t)=>(0,G.jsx)(`li`,{children:e},t))})]}),(0,G.jsxs)(`section`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Name`}),(0,G.jsx)(j,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Description`}),(0,G.jsx)(j,{value:e.description??``,onChange:e=>x(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:`What is this profile for?`})]})]}),(0,G.jsxs)(`section`,{children:[(0,G.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:`Orchestrator`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:`Top-level model for both commands. batch-implement delegates to implement per feature, so every rail it spawns inherits this profile's agent chain.`})]}),(0,G.jsx)(oe,{value:e.orchestrator.model,onChange:e=>x(t=>{t.orchestrator.model=e})})]})]}),(0,G.jsxs)(`section`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[`Agent chain (`,e.agents.length,`)`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>p(e=>!e),disabled:w.length===0,title:w.length===0?`All catalog agents are already in the chain`:`Add an agent from the catalog`,children:[(0,G.jsx)(y,{className:`w-3.5 h-3.5 mr-1`}),` Add`]})]}),d&&(0,G.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,G.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`Pick from catalog (`,w.length,` available)`]}),(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>p(!1),title:`Close`,children:(0,G.jsx)(f,{className:`w-3 h-3`})})]}),w.length===0?(0,G.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:`No more agents in the catalog. Add custom agents from the Agents Catalog tab.`}):(0,G.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:w.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>k(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,G.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 text-purple-400`:`bg-muted text-muted-foreground`),children:e.kind})]},e.id))})]}),(0,G.jsx)(F,{sensors:N,collisionDetection:l,onDragEnd:P,children:(0,G.jsx)(L,{items:e.agents.map(e=>e.id),strategy:c,children:(0,G.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,G.jsx)(X,{agent:e,canRemove:!q.has(e.id),onModel:e=>z(t,e),onRemove:()=>A(t)},e.id))})})})]}),(0,G.jsxs)(`section`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:[`Routing (`,e.routing.length,`)`]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!O&&(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:ee,disabled:e.agents.length===0,title:e.agents.length===0?`Add at least one agent before creating routing rules`:void 0,children:[(0,G.jsx)(y,{className:`w-3.5 h-3.5 mr-1`}),` Add default`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>_(!0),disabled:e.agents.length===0,title:e.agents.length===0?`Add at least one agent before creating routing rules`:void 0,children:[(0,G.jsx)(y,{className:`w-3.5 h-3.5 mr-1`}),` Add rule`]})]})]}),(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:`First matching rule wins. Rules are editable and removable, and the default catch-all stays last when present. If you leave routing empty, the pipeline falls back to the first developer-shaped agent in the chain.`}),E.length>0&&(0,G.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[(0,G.jsx)(`div`,{className:`font-medium mb-1`,children:`Untargeted agents in the chain`}),(0,G.jsxs)(`div`,{children:[`No routing rule points to: `,(0,G.jsx)(`span`,{className:`font-mono`,children:E.join(`, `)}),`. Add a tag rule or retarget the default rule if you want them to run.`]})]}),(0,G.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,G.jsx)(ae,{rule:t,ordinal:n+1,isLast:n===e.routing.length-1,canMove:!r,canRemove:!r,canEdit:!r,chainAgents:e.agents.map(e=>e.id),onAgentChange:e=>te(n,e),onEdit:()=>b(n),onUp:()=>U(n,-1),onDown:()=>U(n,1),onRemove:()=>ne(n)},n)})})]}),n&&(0,G.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function X({agent:e,canRemove:t,onModel:n,onRemove:r}){let i=q.has(e.id),a=e.id===`sr-architect`,s=e.id===`sr-merge-resolver`,{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:p,isDragging:m}=h({id:e.id});return(0,G.jsxs)(`div`,{ref:u,style:{transform:o.Transform.toString(d),transition:p,opacity:m?.5:void 0,zIndex:m?10:void 0},className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors bg-background`,children:[(0,G.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:`Drag to reorder`,"aria-label":`Drag handle`,...c,...l,children:(0,G.jsx)(C,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),a&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-dracula-purple/15 text-dracula-purple`,title:`Pinned to first position — pipeline always starts with sr-architect`,children:[(0,G.jsx)(H,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` first`]}),s&&(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-dracula-purple/15 text-dracula-purple`,title:`Pinned to last position — merge phase always runs last`,children:[(0,G.jsx)(H,{className:`w-2.5 h-2.5 rotate-45`}),` last`]}),i&&!a&&!s&&(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:`required`}),(0,G.jsx)(oe,{value:e.model??`sonnet`,onChange:n}),(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:r,disabled:!t,title:t?`Remove`:`Required baseline agent — the pipeline depends on this row`,children:(0,G.jsx)(f,{className:`w-3 h-3`})})]})}function ae({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:s,onEdit:c,onUp:l,onDown:u,onRemove:d}){let p=`default`in e&&e.default===!0;return(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,G.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),p?(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:`everything else`}):(0,G.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),p?(0,G.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":`Default routing target (core, read-only)`,title:`Core fallback — not editable`,children:e.agent}):(0,G.jsx)(`select`,{value:e.agent,onChange:e=>s(e.target.value),"aria-label":`Routing target for rule ${t}`,className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:c,title:`Edit rule`,"aria-label":`Edit rule ${t}`,children:(0,G.jsx)(b,{className:`w-3 h-3`})}),r&&!n&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:`Move down`,children:(0,G.jsx)(z,{className:`w-3 h-3`})}),r&&t>1&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:`Move up`,children:(0,G.jsx)(B,{className:`w-3 h-3`})}),i&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded`,onClick:d,title:`Remove`,children:(0,G.jsx)(f,{className:`w-3 h-3`})})]}),p&&(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:`Core fallback — the pipeline's last-resort rule, pinned to sr-developer`,children:`core · default`})]})}function oe({value:e,onChange:t}){return(0,G.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:J.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e))})}function se({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a=`Confirm`,inputPattern:o,inputInvalidHint:s,onConfirm:c,onCancel:l}){let[u,d]=(0,W.useState)(i);(0,W.useEffect)(()=>{e&&d(i)},[e,i]);let f=u.trim(),p=!o||o.test(f),m=f.length>0&&p;return(0,G.jsx)(w,{open:e,onOpenChange:e=>{e||l()},children:(0,G.jsxs)(M,{className:`max-w-md`,children:[(0,G.jsx)(T,{children:(0,G.jsx)(x,{children:t})}),(0,G.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,G.jsx)(j,{autoFocus:!0,value:u,placeholder:r,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m&&c(f)},className:`text-sm font-mono`}),f.length>0&&!p&&s&&(0,G.jsx)(`p`,{className:`text-[11px] text-yellow-500`,children:s})]}),(0,G.jsxs)(E,{children:[(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:l,children:`Cancel`}),(0,G.jsx)(R,{size:`sm`,onClick:()=>c(f),disabled:!m,children:a})]})]})})}function ce({open:e,title:t,description:n,confirmLabel:r=`Confirm`,destructive:i=!1,onConfirm:a,onCancel:o}){return(0,G.jsx)(w,{open:e,onOpenChange:e=>{e||o()},children:(0,G.jsxs)(M,{className:`max-w-md`,children:[(0,G.jsx)(T,{children:(0,G.jsx)(x,{children:t})}),n&&(0,G.jsx)(`div`,{className:`py-2`,children:(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,G.jsxs)(E,{children:[(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:o,children:`Cancel`}),(0,G.jsx)(R,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r})]})]})})}function le(){let[e,t]=(0,W.useState)([]),[n,r]=(0,W.useState)(null),[a,o]=(0,W.useState)(null),[c,l]=(0,W.useState)(!0),[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(!1),[m,h]=(0,W.useState)([]),[g,_]=(0,W.useState)([]),[b,x]=(0,W.useState)(!1),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)(null),E=(0,W.useCallback)(async()=>{l(!0),d(null);try{let e=await fetch(`${s()}/profiles`);if(!e.ok)throw Error(`List failed: ${e.status}`);let i=await e.json();t(i.profiles),i.profiles.length>0&&!n&&r(i.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[n]);(0,W.useEffect)(()=>{E()},[E]),(0,W.useEffect)(()=>{if(!n){o(null);return}let e=!1;return fetch(`${s()}/profiles/${encodeURIComponent(n)}`).then(e=>{if(!e.ok)throw Error(`Load failed: ${e.status}`);return e.json()}).then(t=>{e||o(t.profile)}).catch(t=>{e||d(t.message)}),()=>{e=!0}},[n]);let D=(0,W.useCallback)(async()=>{p(!0),d(null);try{let e=await fetch(`${s()}/profiles/migrate-from-settings`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Migration failed: ${e.status}`)}await E(),r(`default`),A.success(`Profile migrated`,{description:`default profile created from your current agents`})}catch(e){let t=e.message;d(t),A.error(`Migration failed`,{description:t})}finally{p(!1)}},[E]),O=(0,W.useCallback)(async e=>{x(!1),p(!0),d(null);try{let t={schemaVersion:1,name:e,description:``,orchestrator:{model:`sonnet`},agents:[{id:`sr-architect`,model:`sonnet`,required:!0},{id:`sr-developer`,model:`sonnet`,required:!0},{id:`sr-reviewer`,model:`sonnet`,required:!0},{id:`sr-merge-resolver`,model:`sonnet`,required:!0}],routing:[{default:!0,agent:`sr-developer`}]},n=await fetch(`${s()}/profiles`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Create failed: ${n.status}`)}await E(),r(e),A.success(`Profile created`,{description:e})}catch(e){let t=e.message;d(t),A.error(`Failed to create profile`,{description:t})}finally{p(!1)}},[E]),k=(0,W.useCallback)(async(e,t)=>{C(null),p(!0),d(null);try{let n=await fetch(`${s()}/profiles/${encodeURIComponent(e)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Duplicate failed: ${n.status}`)}await E(),r(t),A.success(`Profile duplicated`,{description:`${e} → ${t}`})}catch(e){let t=e.message;d(t),A.error(`Failed to duplicate profile`,{description:t})}finally{p(!1)}},[E]),j=(0,W.useCallback)(async e=>{T(null),p(!0),d(null);try{let t=await fetch(`${s()}/profiles/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Delete failed: ${t.status}`)}r(t=>t===e?null:t),await E(),A.success(`Profile deleted`,{description:e})}catch(e){let t=e.message;d(t),A.error(`Failed to delete profile`,{description:t})}finally{p(!1)}},[E]),M=(0,W.useCallback)(()=>x(!0),[]),P=(0,W.useCallback)(e=>C({from:e}),[]),F=(0,W.useCallback)(e=>T({name:e}),[]),I=(0,W.useCallback)(async(e,t)=>{p(!0),d(null);try{let n=await fetch(`${s()}/profiles/${encodeURIComponent(e.name)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`Save failed: ${n.status}`)}o(e),t.length>0?A.warning(`Profile saved with untargeted agents`,{description:`No routing rule points to: ${t.join(`, `)}. Add a tag rule or retarget the default rule if you want them to run.`,duration:6e3}):A.success(`Profile saved`,{description:e.name})}catch(e){let t=e.message;d(t),A.error(`Failed to save profile`,{description:t})}finally{p(!1)}},[]),L=(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(se,{open:b,title:`New profile`,description:`Pick a lowercase kebab-case name (letters, digits, and hyphens).`,placeholder:`my-profile`,confirmLabel:`Create`,inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:`Must start with a letter or digit and contain only lowercase letters, digits, and hyphens.`,onConfirm:e=>void O(e),onCancel:()=>x(!1)}),S&&(0,G.jsx)(se,{open:!0,title:`Duplicate "${S.from}"`,description:`Name for the new profile.`,placeholder:`${S.from}-copy`,initialValue:`${S.from}-copy`,confirmLabel:`Duplicate`,inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:`Lowercase kebab-case only.`,onConfirm:e=>void k(S.from,e),onCancel:()=>C(null)}),w&&(0,G.jsx)(ce,{open:!0,title:`Delete profile "${w.name}"?`,description:`This cannot be undone. Jobs already launched with this profile keep their snapshot; future launches will fall back to the resolution order.`,confirmLabel:`Delete`,destructive:!0,onConfirm:()=>void j(w.name),onCancel:()=>T(null)})]});return c?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading profiles…`})}):e.length===0?(0,G.jsxs)(G.Fragment,{children:[L,(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No profiles yet`}),(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:`Profiles let you save orchestrator + agent + routing combinations and pick one per rail.`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,G.jsxs)(R,{size:`sm`,onClick:D,disabled:f,children:[(0,G.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),` Migrate from current agents`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:[(0,G.jsx)(y,{className:`w-3.5 h-3.5 mr-1.5`}),` Blank profile`]})]}),(0,G.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:[`"Migrate" reads your existing `,(0,G.jsx)(`code`,{className:`text-foreground`,children:`.claude/agents/`}),` `,`frontmatter models and creates a `,(0,G.jsx)(`code`,{className:`text-foreground`,children:`default`}),` profile mirroring today's behavior — zero-loss.`]}),u&&(0,G.jsx)(`div`,{className:`mt-3 text-xs text-red-400`,children:u})]})})]}):(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[L,(0,G.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,G.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Profiles`}),(0,G.jsx)(R,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:(0,G.jsx)(y,{className:`w-3.5 h-3.5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:e.map(e=>(0,G.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(e.name===n?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>r(e.name),role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&r(e.name)},children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,G.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),e.isDefault&&(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`(team default)`})]}),(0,G.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:`Duplicate`,onClick:t=>{t.stopPropagation(),P(e.name)},children:(0,G.jsx)(i,{className:`w-3 h-3`})}),!e.isDefault&&(0,G.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 rounded`,title:`Delete`,onClick:t=>{t.stopPropagation(),F(e.name)},children:(0,G.jsx)(v,{className:`w-3 h-3`})})]})]},e.name))})]}),(0,G.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,G.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:u}),a?(0,G.jsx)(ie,{profile:a,onChange:o,onValidityChange:h,onSoftWarningsChange:e=>_(e.agentsMissingRouting),footer:(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(R,{size:`sm`,onClick:()=>void I(a,g),disabled:f||m.length>0,title:m.length>0?`Fix validation issues before saving`:void 0,children:[(0,G.jsx)(N,{className:`w-3.5 h-3.5 mr-1.5`}),`Save`]}),f&&(0,G.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Saving…`}),m.length>0&&(0,G.jsxs)(`span`,{className:`text-xs text-yellow-500`,children:[m.length,` `,m.length===1?`issue`:`issues`,` to resolve`]})]})},a.name):(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select a profile to edit`})})]})]})]})}function Z(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
2
2
  `);return`---
3
3
  name: ${e.id}
4
4
  description: "${e.descriptionOneLine}"
@@ -76,4 +76,4 @@ You are ...
76
76
  - **risk_tolerance**: conservative
77
77
  - **detail_level**: full
78
78
  - **focus_areas**: ...
79
- `;function fe({agentId:e,initialBody:t,initialName:n,onClose:r,onSaved:i}){let a=!e,[o,c]=(0,W.useState)(e??n??``),[l,u]=(0,W.useState)(t??de),[d,f]=(0,W.useState)(!a&&!t),[p,m]=(0,W.useState)(!1),[g,_]=(0,W.useState)(null),[v,b]=(0,W.useState)([]),[x,S]=(0,W.useState)(!1),[C,T]=(0,W.useState)(!!t&&a),[E,D]=(0,W.useState)(!1),[O,k]=(0,W.useState)(``),[A,M]=(0,W.useState)(!1),[F,I]=(0,W.useState)(null),[L,z]=(0,W.useState)(null),[B,H]=(0,W.useState)(!1);(0,W.useEffect)(()=>{if(a||t!==void 0)return;let n=!1;return fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`).then(e=>{if(!e.ok)throw Error(`Load failed: ${e.status}`);return e.json()}).then(e=>{n||u(e.body)}).catch(e=>{n||_(e.message)}).finally(()=>{n||f(!1)}),()=>{n=!0}},[e,a,t]);let ne=(0,W.useCallback)(()=>{a||fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}/versions`).then(e=>e.ok?e.json():{versions:[]}).then(e=>b(e.versions)).catch(()=>b([]))},[e,a]);(0,W.useEffect)(()=>{x&&ne()},[x,ne]);let U=/^custom-[a-z0-9][a-z0-9-]*$/.test(o),re=l.trim().length>0,K=/^---\s*\n[\s\S]*?\n---/.test(l),q=re&&K&&(a?U:!0)&&C,J=(0,W.useCallback)(async()=>{m(!0),_(null);try{let t;if(t=a?await fetch(`${s()}/profiles/catalog`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:o,body:l})}):await fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:l})}),!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Save failed: ${t.status}`)}T(!1),N.success(a?`Agent created`:`Agent saved`,{description:a?o:e}),i&&i(a?o:e)}catch(e){let t=e.message;_(t),N.error(a?`Failed to create agent`:`Failed to save agent`,{description:t})}finally{m(!1)}},[e,l,o,a,i]),Y=(0,W.useCallback)(async()=>{if(!a){H(!1),m(!0),_(null);try{let t=await fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Delete failed: ${t.status}`)}N.success(`Agent deleted`,{description:e}),i&&i(e),r()}catch(e){let t=e.message;_(t),N.error(`Failed to delete agent`,{description:t})}finally{m(!1)}}},[e,a,r,i]),ie=(0,W.useCallback)(e=>{u(e.body),T(!0),S(!1)},[]),X=(0,W.useCallback)(async()=>{M(!0),z(null),I(null);try{let t=await fetch(`${s()}/profiles/catalog/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:a?o||`draft`:e,draftBody:l,sampleTask:O})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Test failed: ${t.status}`)}I(await t.json())}catch(e){z(e.message)}finally{M(!1)}},[e,l,o,a,O]);return d?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading agent…`})}):(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!a&&(0,G.jsx)(ce,{open:B,title:`Delete agent "${e}"?`,description:`This removes the .md from disk. Version history stays in the DB — use a fresh custom agent if you want to recover the body later.`,confirmLabel:`Delete`,destructive:!0,onConfirm:Y,onCancel:()=>H(!1)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 border-b border-border`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground`,title:`Back`,children:(0,G.jsx)(w,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground uppercase tracking-wide`,children:a?`New custom agent`:`Edit custom agent`}),a?(0,G.jsx)(j,{value:o,onChange:e=>{c(e.target.value),T(!0)},placeholder:`custom-my-agent`,className:`text-sm font-mono mt-1 max-w-sm`}):(0,G.jsx)(`div`,{className:`text-sm font-mono`,children:e})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>{D(e=>!e),E||S(!1)},title:`Test this agent against a sample task`,children:[(0,G.jsx)(V,{className:`w-3.5 h-3.5 mr-1`}),`Test`]}),!a&&(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>{S(e=>!e),x||D(!1)},title:`Version history`,children:[(0,G.jsx)(te,{className:`w-3.5 h-3.5 mr-1`}),`History`]}),!a&&(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>H(!0),disabled:p,className:`text-red-400 hover:text-red-300`,children:[(0,G.jsx)(y,{className:`w-3.5 h-3.5 mr-1`}),`Delete`]}),(0,G.jsxs)(R,{size:`sm`,onClick:J,disabled:!q||p,children:[(0,G.jsx)(P,{className:`w-3.5 h-3.5 mr-1`}),p?`Saving…`:a?`Create`:`Save`]})]})]}),g&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 text-xs border-b border-red-500/30 bg-red-500/10 text-red-400`,children:[(0,G.jsx)(ee,{className:`w-3.5 h-3.5 flex-shrink-0`}),g]}),a&&o.length>0&&!U&&(0,G.jsxs)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[`Name must start with `,(0,G.jsx)(`code`,{children:`custom-`}),` and contain only lowercase letters, digits, and hyphens.`]}),!K&&(0,G.jsxs)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[`Missing YAML frontmatter (needs opening `,(0,G.jsx)(`code`,{children:`---`}),` on the first line).`]}),(0,G.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`px-4 py-1.5 border-b border-border text-[11px] font-mono text-muted-foreground flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{children:[`.claude/agents/`,a?o||`custom-…`:e,`.md`]}),C&&(0,G.jsx)(`span`,{className:`text-yellow-500`,children:`● unsaved`})]}),(0,G.jsx)(`textarea`,{value:l,onChange:e=>{u(e.target.value),T(!0)},spellCheck:!1,className:`flex-1 w-full p-4 text-xs font-mono bg-background text-foreground outline-none resize-none leading-relaxed`})]}),E&&(0,G.jsxs)(`aside`,{className:`w-96 flex-shrink-0 border-l border-border flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-2`,children:[(0,G.jsx)(V,{className:`w-3.5 h-3.5`}),` Test agent`]}),(0,G.jsxs)(`div`,{className:`p-3 border-b border-border`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,children:`Sample task`}),(0,G.jsx)(`select`,{className:`h-6 text-[11px] rounded border border-border bg-background px-1`,value:``,onChange:e=>{let t=parseInt(e.target.value,10);!isNaN(t)&&t>0&&k($[t].prompt)},disabled:A,children:$.map((e,t)=>(0,G.jsx)(`option`,{value:t,children:e.label},t))})]}),(0,G.jsx)(`textarea`,{value:O,onChange:e=>k(e.target.value),placeholder:`Describe what the agent should do, or pick a sample above.`,className:`w-full text-xs p-2 rounded border border-border bg-background min-h-[80px] resize-y font-mono`,disabled:A}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(R,{size:`sm`,onClick:X,disabled:A||!O.trim()||!l.trim(),children:A?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(h,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` Running…`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(V,{className:`w-3.5 h-3.5 mr-1.5`}),` Run`]})}),(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Sandboxed; no files written.`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 min-h-0`,children:[L&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400 mb-2`,children:L}),F&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground mb-2`,children:[(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{className:`text-foreground font-mono`,children:F.tokens}),` tokens`]}),(0,G.jsx)(`span`,{children:(0,G.jsxs)(`span`,{className:`text-foreground font-mono`,children:[(F.durationMs/1e3).toFixed(1),`s`]})})]}),(0,G.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed rounded border border-border bg-background p-3`,children:F.output})]}),!A&&!F&&!L&&(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic`,children:`Run a sample task against the current draft. Output appears here.`})]})]}),x&&!a&&(0,G.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-l border-border flex flex-col`,children:[(0,G.jsx)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Version history`}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:v.length===0?(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic px-2 py-2`,children:`No prior versions recorded for this agent.`}):v.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>ie(e),className:`w-full text-left px-2 py-1.5 rounded hover:bg-accent/50 transition-colors`,children:[(0,G.jsxs)(`div`,{className:`text-xs font-mono text-foreground`,children:[`v`,e.version]}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.version))}),(0,G.jsx)(`div`,{className:`px-3 py-2 border-t border-border text-[11px] text-muted-foreground`,children:`Click a version to restore its body into the editor (you still need to Save).`})]})]})]})}function pe(){let[e,t]=(0,W.useState)([]),[n,r]=(0,W.useState)(null),[a,o]=(0,W.useState)(null),[c,l]=(0,W.useState)(!0),[u,m]=(0,W.useState)(!1),[g,_]=(0,W.useState)(null),[v,y]=(0,W.useState)({kind:`closed`}),[C,w]=(0,W.useState)(!1),[k,A]=(0,W.useState)(``),[N,P]=(0,W.useState)(`all`),[F,I]=(0,W.useState)(null),[L,z]=(0,W.useState)(!1),[B,ee]=(0,W.useState)(``),[V,te]=(0,W.useState)(``),[H,U]=(0,W.useState)(!1),[re,K]=(0,W.useState)(null),q=(0,W.useCallback)(()=>{let e=!1;return l(!0),fetch(`${s()}/profiles/catalog`).then(e=>{if(!e.ok)throw Error(`Catalog load failed: ${e.status}`);return e.json()}).then(i=>{e||(t(i.agents),i.agents.length>0&&!n&&r(i.agents[0].id))}).catch(t=>{e||_(t.message)}).finally(()=>{e||l(!1)}),()=>{e=!0}},[n]);(0,W.useEffect)(()=>q(),[q]);let J=(0,W.useCallback)(e=>{let t=!1;return m(!0),o(null),fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`).then(e=>{if(!e.ok)throw Error(`Agent body load failed: ${e.status}`);return e.json()}).then(e=>{t||o(e.body)}).catch(e=>{t||_(e.message)}).finally(()=>{t||m(!1)}),()=>{t=!0}},[]);if((0,W.useEffect)(()=>{if(n)return J(n)},[n,J]),c)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading catalog…`})});if(v.kind!==`closed`)return(0,G.jsx)(fe,{agentId:v.kind===`edit`?v.agentId:void 0,initialBody:v.kind===`duplicate`||v.kind===`create`?v.initialBody:void 0,initialName:v.kind===`create`?v.initialName:void 0,onClose:()=>y({kind:`closed`}),onSaved:e=>{r(e),y({kind:`closed`}),q()}});let Y=(()=>{let e=k.trim().toLowerCase();return Q.filter(t=>!(N!==`all`&&t.category!==N||F&&!t.tags.includes(F)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),ie=(()=>{let e=new Map;for(let t of Q)e.set(t.category,(e.get(t.category)??0)+1);return e})(),X=()=>{w(!1),A(``),P(`all`),I(null)},ae=()=>(0,G.jsx)(E,{open:C,onOpenChange:e=>{e||X()},children:(0,G.jsxs)(M,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,G.jsxs)(D,{children:[(0,G.jsxs)(S,{className:`flex items-center gap-2 text-base`,children:[(0,G.jsx)(T,{className:`w-4 h-4 text-dracula-purple`}),` Agent template library`,(0,G.jsxs)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:[Y.length,` of `,Q.length]})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Start from a curated template across engineering, product, science, health, legal, and more. Pick one and open it in the Studio for review and editing before saving.`})]}),(0,G.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,G.jsx)(p,{className:`w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none`}),(0,G.jsx)(`input`,{value:k,onChange:e=>A(e.target.value),placeholder:`Search by name, description, tag, or category…`,className:`w-full h-9 pl-8 pr-8 text-sm rounded-md border border-border bg-background focus:outline-none focus:ring-1 focus:ring-primary/40`,autoFocus:!0}),k&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>A(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,G.jsx)(f,{className:`w-3.5 h-3.5`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,G.jsx)(me,{label:`All`,count:Q.length,active:N===`all`,onClick:()=>P(`all`)}),ue.map(e=>(0,G.jsx)(me,{label:e,count:ie.get(e)??0,active:N===e,onClick:()=>P(e)},e))]}),F&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Tag filter:`}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>I(null),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full bg-dracula-purple/20 text-dracula-purple hover:bg-dracula-purple/30`,children:[(0,G.jsx)(ne,{className:`w-3 h-3`}),` `,F,(0,G.jsx)(f,{className:`w-3 h-3`})]})]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:Y.length===0?(0,G.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,G.jsxs)(`div`,{className:`max-w-sm`,children:[(0,G.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No templates match your filters.`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{A(``),P(`all`),I(null)},className:`text-xs text-dracula-purple hover:underline mt-2`,children:`Clear filters`})]})}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:Y.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{X(),y({kind:`create`,initialBody:e.body,initialName:e.nameHint})},className:`group text-left p-4 rounded-lg border border-border bg-card/40 hover:border-dracula-purple/50 hover:bg-accent/40 hover:shadow-sm transition-all`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:e.emoji}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-dracula-purple truncate`,children:e.label}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:e.category})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:e.blurb}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:e.tags.slice(0,5).map(e=>(0,G.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),I(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),I(e))},className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/50 text-muted-foreground hover:bg-dracula-purple/20 hover:text-dracula-purple cursor-pointer transition-colors `+(F===e?`bg-dracula-purple/20 text-dracula-purple`:``),children:e},e))}),(0,G.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,G.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:e.nameHint}),(0,G.jsx)(`span`,{className:`text-[10px] text-dracula-purple opacity-0 group-hover:opacity-100 transition-opacity`,children:`Open in Studio →`})]})]},e.id))})}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Tip: click a tag pill on any card to filter by that tag.`}),(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:X,children:`Cancel`})]})]})}),oe=()=>(0,G.jsx)(E,{open:L,onOpenChange:e=>{!e&&!H&&(z(!1),K(null))},children:(0,G.jsxs)(M,{className:`max-w-lg`,children:[(0,G.jsx)(D,{children:(0,G.jsxs)(S,{className:`flex items-center gap-2`,children:[(0,G.jsx)(d,{className:`w-4 h-4 text-dracula-purple`}),` Generate a custom agent`]})}),(0,G.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Agent id`}),(0,G.jsx)(j,{value:B,onChange:e=>ee(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:H}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Must start with `,(0,G.jsx)(`code`,{children:`custom-`}),`.`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Describe what this agent should do`}),(0,G.jsx)(`textarea`,{value:V,onChange:e=>te(e.target.value),placeholder:`e.g. Review Terraform/IaC changes and flag security misconfigurations, excessive IAM permissions, and public S3 buckets before merging. Conservative and terse.`,className:`w-full text-sm p-2 rounded border border-border bg-background min-h-[120px] resize-y`,disabled:H})]}),re&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:re}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Claude will draft a full `,(0,G.jsx)(`code`,{children:`.md`}),` body. You'll review it in the Studio and can edit before saving. This spawns a one-shot claude invocation and can take up to 90 seconds.`]})]}),(0,G.jsxs)(O,{children:[(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>z(!1),disabled:H,children:`Cancel`}),(0,G.jsx)(R,{size:`sm`,onClick:se,disabled:H||!B.trim()||!V.trim(),children:H?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(h,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` Generating…`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(d,{className:`w-3.5 h-3.5 mr-1.5`}),` Generate`]})})]})]})}),se=async()=>{U(!0),K(null);try{let e=await fetch(`${s()}/profiles/catalog/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:B.trim(),description:V.trim()})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Generate failed: ${e.status}`)}let t=await e.json();z(!1),y({kind:`create`,initialBody:t.draft,initialName:B.trim()})}catch(e){K(e.message)}finally{U(!1)}},ce=async e=>{try{let t=await fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Load failed: ${t.status}`);y({kind:`duplicate`,from:e,initialBody:(await t.json()).body})}catch(e){_(e.message)}};if(e.length===0)return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No agents installed`}),(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:[`Run `,(0,G.jsx)(`code`,{className:`text-foreground`,children:`npx specrails-core@latest update`}),` in this project to install the upstream agents, or create a custom agent now.`]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[(0,G.jsxs)(R,{size:`sm`,onClick:()=>z(!0),children:[(0,G.jsx)(d,{className:`w-3.5 h-3.5 mr-1.5`}),` Generate with Claude`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>w(!0),children:[(0,G.jsx)(T,{className:`w-3.5 h-3.5 mr-1.5`}),` Template`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>y({kind:`create`}),children:[(0,G.jsx)(b,{className:`w-3.5 h-3.5 mr-1.5`}),` Blank`]})]})]})}),ae(),oe()]});let le=e.filter(e=>e.kind===`upstream`),Z=e.filter(e=>e.kind===`custom`),$=e.find(e=>e.id===n);return(0,G.jsxs)(G.Fragment,{children:[ae(),oe(),(0,G.jsxs)(`div`,{className:`flex h-full`,children:[(0,G.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:`Catalog`}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:`Create a custom agent:`}),(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>w(!0),title:`Start from a template`,children:[(0,G.jsx)(T,{className:`w-3 h-3 mr-1`}),` Template`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>z(!0),title:`Generate with Claude`,children:[(0,G.jsx)(d,{className:`w-3 h-3 mr-1`}),` Generate`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>y({kind:`create`}),title:`Start from a blank template`,children:[(0,G.jsx)(b,{className:`w-3 h-3 mr-1`}),` Blank`]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,G.jsx)(he,{title:`Upstream (${le.length})`,description:`Shipped by specrails-core; read-only.`,children:le.map(e=>(0,G.jsx)(ge,{agent:e,selected:e.id===n,onSelect:()=>r(e.id)},e.id))}),(0,G.jsx)(he,{title:`Custom (${Z.length})`,description:`Your project's custom-*.md files. Use Template / Generate / Blank above to create one.`,children:Z.length===0?(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:`No custom agents yet.`}):Z.map(e=>(0,G.jsx)(ge,{agent:e,selected:e.id===n,onSelect:()=>r(e.id)},e.id))})]})]}),(0,G.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[g&&(0,G.jsx)(`div`,{className:`m-4 px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:g}),$&&(0,G.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:$.id}),(0,G.jsx)(_e,{kind:$.kind}),$.model&&(0,G.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[`default model: `,$.model]})]}),$.description&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:$.description})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>void ce($.id),children:[(0,G.jsx)(i,{className:`w-3.5 h-3.5 mr-1`}),` Duplicate`]}),$.kind===`custom`&&(0,G.jsxs)(R,{size:`sm`,onClick:()=>y({kind:`edit`,agentId:$.id}),children:[(0,G.jsx)(x,{className:`w-3.5 h-3.5 mr-1`}),` Edit`]})]})]}),(0,G.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,G.jsxs)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:[`.claude/agents/`,$.id,`.md`]}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:$.kind===`upstream`?`read-only`:`editable — use Edit above`})]}),(0,G.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:u?`Loading…`:a??``})]})]})]})]})]})}function me({label:e,count:t,active:n,onClick:r}){return(0,G.jsxs)(`button`,{type:`button`,onClick:r,className:`flex-shrink-0 inline-flex items-center gap-1 h-7 px-2.5 text-[11px] rounded-full border transition-colors whitespace-nowrap `+(n?`bg-dracula-purple/20 border-dracula-purple/50 text-dracula-purple`:`bg-transparent border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[e,(0,G.jsx)(`span`,{className:`text-[9px] px-1 rounded `+(n?`bg-dracula-purple/30`:`bg-muted/60`),children:t})]})}function he({title:e,description:t,children:n}){return(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,G.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,G.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function ge({agent:e,selected:t,onSelect:n}){return(0,G.jsxs)(`button`,{type:`button`,onClick:n,className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded transition-colors `+(t?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[(0,G.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,G.jsx)(_e,{kind:e.kind})]})}function _e({kind:e}){return(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 `+(e===`custom`?`bg-purple-500/15 text-purple-400`:`bg-muted text-muted-foreground`),children:e})}var ve=[{label:`7d`,days:7},{label:`30d`,days:30},{label:`90d`,days:90}];function ye(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(30),[i,a]=(0,W.useState)(!0);if((0,W.useEffect)(()=>{let e=!1;return a(!0),fetch(`${s()}/profiles/analytics?windowDays=${n}`).then(e=>e.ok?e.json():null).then(n=>{!e&&n&&t(n)}).catch(()=>{}).finally(()=>{e||a(!1)}),()=>{e=!0}},[n]),i&&!e)return null;if(!e||e.rows.length===0)return(0,G.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:`Profile usage`}),(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:`Jobs launched per profile in the selected window.`})]}),(0,G.jsx)(`div`,{className:`flex gap-0.5`,children:ve.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(e.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(n===e.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e.label},e.days))})]}),(0,G.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:`No profile-scoped jobs yet.`})]});let o=Math.max(...e.rows.map(e=>e.jobs),1);return(0,G.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:`Profile usage`}),(0,G.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[`Jobs launched per profile in the last `,e.windowDays,` days.`]})]}),(0,G.jsx)(`div`,{className:`flex gap-0.5`,children:ve.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(e.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(n===e.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e.label},e.days))})]}),(0,G.jsx)(`div`,{className:`p-4 space-y-2`,children:e.rows.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:e.profileName}),(0,G.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full bg-dracula-purple/70`,style:{width:`${Math.max(6,Math.round(e.jobs/o*100))}%`}})}),(0,G.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,G.jsxs)(`span`,{title:`jobs`,children:[(0,G.jsx)(`span`,{className:`text-foreground font-mono`,children:e.jobs}),` jobs`]}),(0,G.jsxs)(`span`,{title:`success rate`,children:[(0,G.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(e.successRate*100),`%`]}),` `,`ok`]}),e.avgDurationMs!=null&&(0,G.jsx)(`span`,{title:`avg duration`,children:(0,G.jsx)(`span`,{className:`text-foreground font-mono`,children:be(e.avgDurationMs)})}),e.avgTokens!=null&&(0,G.jsxs)(`span`,{title:`avg tokens`,children:[(0,G.jsx)(`span`,{className:`text-foreground font-mono`,children:xe(e.avgTokens)}),` `,`tok`]})]})]},e.profileName))})]})}function be(e){let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h${n%60}m`}function xe(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var Se=`specrails-hub:agents-tab`;function Ce(){try{let e=localStorage.getItem(Se);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function we(){let[e,t]=(0,W.useState)(()=>Ce()),n=e=>{t(e);try{localStorage.setItem(Se,e)}catch{}},[r,i]=(0,W.useState)(null);return(0,W.useEffect)(()=>{let e=!1;return fetch(`${s()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&i(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,G.jsxs)(`div`,{className:`flex flex-col h-full bg-background`,children:[r!==null&&!r.profileAware&&(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start gap-3 px-6 py-3 border-b border-yellow-500/30 bg-yellow-500/10`,children:[(0,G.jsx)(v,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-xs`,children:[(0,G.jsxs)(`div`,{className:`font-medium text-yellow-500`,children:[`Profile-aware pipeline requires specrails-core `,r.required,`+`]}),(0,G.jsxs)(`div`,{className:`text-yellow-500/80 mt-0.5`,children:[`This project has`,` `,(0,G.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20`,children:r.version??`unknown`}),`. Run`,` `,(0,G.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20`,children:`npx specrails-core@latest update`}),` `,`inside the project to unlock profile mode. Profiles you create here will still save; they just won't affect the pipeline until core is updated.`]})]})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,G.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,G.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Agents`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:`Manage agent profiles and the catalog (upstream + custom) for this project.`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,G.jsx)(Ee,{active:e===`profiles`,onClick:()=>n(`profiles`),children:`Profiles`}),(0,G.jsx)(Ee,{active:e===`usage`,onClick:()=>n(`usage`),children:`Usage`}),(0,G.jsx)(Ee,{active:e===`catalog`,onClick:()=>n(`catalog`),children:`Catalog`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[e===`profiles`&&(0,G.jsx)(le,{}),e===`usage`&&(0,G.jsx)(Te,{}),e===`catalog`&&(0,G.jsx)(pe,{})]})]})}function Te(){return(0,G.jsx)(`div`,{className:`min-h-full`,children:(0,G.jsx)(ye,{})})}function Ee({active:e,children:t,onClick:n}){return(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`h-8 px-3 text-xs font-medium rounded-t-md border-b-2 transition-colors `+(e?`text-foreground border-foreground`:`text-muted-foreground border-transparent hover:text-foreground hover:border-border`),children:t})}export{we as default};
79
+ `;function fe({agentId:e,initialBody:t,initialName:n,onClose:r,onSaved:i}){let o=!e,[c,l]=(0,W.useState)(e??n??``),[u,d]=(0,W.useState)(t??de),[f,p]=(0,W.useState)(!o&&!t),[m,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(null),[y,b]=(0,W.useState)([]),[x,S]=(0,W.useState)(!1),[C,w]=(0,W.useState)(!!t&&o),[T,E]=(0,W.useState)(!1),[D,k]=(0,W.useState)(``),[M,P]=(0,W.useState)(!1),[F,I]=(0,W.useState)(null),[L,z]=(0,W.useState)(null),[B,H]=(0,W.useState)(!1);(0,W.useEffect)(()=>{if(o||t!==void 0)return;let n=!1;return fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`).then(e=>{if(!e.ok)throw Error(`Load failed: ${e.status}`);return e.json()}).then(e=>{n||d(e.body)}).catch(e=>{n||_(e.message)}).finally(()=>{n||p(!1)}),()=>{n=!0}},[e,o,t]);let ne=(0,W.useCallback)(()=>{o||fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}/versions`).then(e=>e.ok?e.json():{versions:[]}).then(e=>b(e.versions)).catch(()=>b([]))},[e,o]);(0,W.useEffect)(()=>{x&&ne()},[x,ne]);let U=/^custom-[a-z0-9][a-z0-9-]*$/.test(c),re=u.trim().length>0,K=/^---\s*\n[\s\S]*?\n---/.test(u),q=re&&K&&(o?U:!0)&&C,J=(0,W.useCallback)(async()=>{h(!0),_(null);try{let t;if(t=o?await fetch(`${s()}/profiles/catalog`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:c,body:u})}):await fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:u})}),!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Save failed: ${t.status}`)}w(!1),A.success(o?`Agent created`:`Agent saved`,{description:o?c:e}),i&&i(o?c:e)}catch(e){let t=e.message;_(t),A.error(o?`Failed to create agent`:`Failed to save agent`,{description:t})}finally{h(!1)}},[e,u,c,o,i]),Y=(0,W.useCallback)(async()=>{if(!o){H(!1),h(!0),_(null);try{let t=await fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Delete failed: ${t.status}`)}A.success(`Agent deleted`,{description:e}),i&&i(e),r()}catch(e){let t=e.message;_(t),A.error(`Failed to delete agent`,{description:t})}finally{h(!1)}}},[e,o,r,i]),ie=(0,W.useCallback)(e=>{d(e.body),w(!0),S(!1)},[]),X=(0,W.useCallback)(async()=>{P(!0),z(null),I(null);try{let t=await fetch(`${s()}/profiles/catalog/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:o?c||`draft`:e,draftBody:u,sampleTask:D})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`Test failed: ${t.status}`)}I(await t.json())}catch(e){z(e.message)}finally{P(!1)}},[e,u,c,o,D]);return f?(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading agent…`})}):(0,G.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!o&&(0,G.jsx)(ce,{open:B,title:`Delete agent "${e}"?`,description:`This removes the .md from disk. Version history stays in the DB — use a fresh custom agent if you want to recover the body later.`,confirmLabel:`Delete`,destructive:!0,onConfirm:Y,onCancel:()=>H(!1)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 border-b border-border`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:r,className:`p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground`,title:`Back`,children:(0,G.jsx)(O,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`div`,{className:`text-xs text-muted-foreground uppercase tracking-wide`,children:o?`New custom agent`:`Edit custom agent`}),o?(0,G.jsx)(j,{value:c,onChange:e=>{l(e.target.value),w(!0)},placeholder:`custom-my-agent`,className:`text-sm font-mono mt-1 max-w-sm`}):(0,G.jsx)(`div`,{className:`text-sm font-mono`,children:e})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>{E(e=>!e),T||S(!1)},title:`Test this agent against a sample task`,children:[(0,G.jsx)(V,{className:`w-3.5 h-3.5 mr-1`}),`Test`]}),!o&&(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>{S(e=>!e),x||E(!1)},title:`Version history`,children:[(0,G.jsx)(te,{className:`w-3.5 h-3.5 mr-1`}),`History`]}),!o&&(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>H(!0),disabled:m,className:`text-red-400 hover:text-red-300`,children:[(0,G.jsx)(v,{className:`w-3.5 h-3.5 mr-1`}),`Delete`]}),(0,G.jsxs)(R,{size:`sm`,onClick:J,disabled:!q||m,children:[(0,G.jsx)(N,{className:`w-3.5 h-3.5 mr-1`}),m?`Saving…`:o?`Create`:`Save`]})]})]}),g&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 text-xs border-b border-red-500/30 bg-red-500/10 text-red-400`,children:[(0,G.jsx)(ee,{className:`w-3.5 h-3.5 flex-shrink-0`}),g]}),o&&c.length>0&&!U&&(0,G.jsxs)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[`Name must start with `,(0,G.jsx)(`code`,{children:`custom-`}),` and contain only lowercase letters, digits, and hyphens.`]}),!K&&(0,G.jsxs)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 bg-yellow-500/10 text-yellow-500`,children:[`Missing YAML frontmatter (needs opening `,(0,G.jsx)(`code`,{children:`---`}),` on the first line).`]}),(0,G.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,G.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`px-4 py-1.5 border-b border-border text-[11px] font-mono text-muted-foreground flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{children:[`.claude/agents/`,o?c||`custom-…`:e,`.md`]}),C&&(0,G.jsx)(`span`,{className:`text-yellow-500`,children:`● unsaved`})]}),(0,G.jsx)(`textarea`,{value:u,onChange:e=>{d(e.target.value),w(!0)},spellCheck:!1,className:`flex-1 w-full p-4 text-xs font-mono bg-background text-foreground outline-none resize-none leading-relaxed`})]}),T&&(0,G.jsxs)(`aside`,{className:`w-96 flex-shrink-0 border-l border-border flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-2`,children:[(0,G.jsx)(V,{className:`w-3.5 h-3.5`}),` Test agent`]}),(0,G.jsxs)(`div`,{className:`p-3 border-b border-border`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,children:`Sample task`}),(0,G.jsx)(`select`,{className:`h-6 text-[11px] rounded border border-border bg-background px-1`,value:``,onChange:e=>{let t=parseInt(e.target.value,10);!isNaN(t)&&t>0&&k($[t].prompt)},disabled:M,children:$.map((e,t)=>(0,G.jsx)(`option`,{value:t,children:e.label},t))})]}),(0,G.jsx)(`textarea`,{value:D,onChange:e=>k(e.target.value),placeholder:`Describe what the agent should do, or pick a sample above.`,className:`w-full text-xs p-2 rounded border border-border bg-background min-h-[80px] resize-y font-mono`,disabled:M}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(R,{size:`sm`,onClick:X,disabled:M||!D.trim()||!u.trim(),children:M?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(a,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` Running…`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(V,{className:`w-3.5 h-3.5 mr-1.5`}),` Run`]})}),(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Sandboxed; no files written.`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 min-h-0`,children:[L&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400 mb-2`,children:L}),F&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground mb-2`,children:[(0,G.jsxs)(`span`,{children:[(0,G.jsx)(`span`,{className:`text-foreground font-mono`,children:F.tokens}),` tokens`]}),(0,G.jsx)(`span`,{children:(0,G.jsxs)(`span`,{className:`text-foreground font-mono`,children:[(F.durationMs/1e3).toFixed(1),`s`]})})]}),(0,G.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed rounded border border-border bg-background p-3`,children:F.output})]}),!M&&!F&&!L&&(0,G.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic`,children:`Run a sample task against the current draft. Output appears here.`})]})]}),x&&!o&&(0,G.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-l border-border flex flex-col`,children:[(0,G.jsx)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:`Version history`}),(0,G.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:y.length===0?(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic px-2 py-2`,children:`No prior versions recorded for this agent.`}):y.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>ie(e),className:`w-full text-left px-2 py-1.5 rounded hover:bg-accent/50 transition-colors`,children:[(0,G.jsxs)(`div`,{className:`text-xs font-mono text-foreground`,children:[`v`,e.version]}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.version))}),(0,G.jsx)(`div`,{className:`px-3 py-2 border-t border-border text-[11px] text-muted-foreground`,children:`Click a version to restore its body into the editor (you still need to Save).`})]})]})]})}function pe(){let[e,t]=(0,W.useState)([]),[n,r]=(0,W.useState)(null),[o,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(!0),[m,h]=(0,W.useState)(!1),[g,_]=(0,W.useState)(null),[v,S]=(0,W.useState)({kind:`closed`}),[C,D]=(0,W.useState)(!1),[O,k]=(0,W.useState)(``),[A,N]=(0,W.useState)(`all`),[F,I]=(0,W.useState)(null),[L,z]=(0,W.useState)(!1),[B,ee]=(0,W.useState)(``),[V,te]=(0,W.useState)(``),[H,U]=(0,W.useState)(!1),[re,K]=(0,W.useState)(null),q=(0,W.useCallback)(()=>{let e=!1;return u(!0),fetch(`${s()}/profiles/catalog`).then(e=>{if(!e.ok)throw Error(`Catalog load failed: ${e.status}`);return e.json()}).then(i=>{e||(t(i.agents),i.agents.length>0&&!n&&r(i.agents[0].id))}).catch(t=>{e||_(t.message)}).finally(()=>{e||u(!1)}),()=>{e=!0}},[n]);(0,W.useEffect)(()=>q(),[q]);let J=(0,W.useCallback)(e=>{let t=!1;return h(!0),c(null),fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`).then(e=>{if(!e.ok)throw Error(`Agent body load failed: ${e.status}`);return e.json()}).then(e=>{t||c(e.body)}).catch(e=>{t||_(e.message)}).finally(()=>{t||h(!1)}),()=>{t=!0}},[]);if((0,W.useEffect)(()=>{if(n)return J(n)},[n,J]),l)return(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading catalog…`})});if(v.kind!==`closed`)return(0,G.jsx)(fe,{agentId:v.kind===`edit`?v.agentId:void 0,initialBody:v.kind===`duplicate`||v.kind===`create`?v.initialBody:void 0,initialName:v.kind===`create`?v.initialName:void 0,onClose:()=>S({kind:`closed`}),onSaved:e=>{r(e),S({kind:`closed`}),q()}});let Y=(()=>{let e=O.trim().toLowerCase();return Q.filter(t=>!(A!==`all`&&t.category!==A||F&&!t.tags.includes(F)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),ie=(()=>{let e=new Map;for(let t of Q)e.set(t.category,(e.get(t.category)??0)+1);return e})(),X=()=>{D(!1),k(``),N(`all`),I(null)},ae=()=>(0,G.jsx)(w,{open:C,onOpenChange:e=>{e||X()},children:(0,G.jsxs)(M,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,G.jsxs)(T,{children:[(0,G.jsxs)(x,{className:`flex items-center gap-2 text-base`,children:[(0,G.jsx)(P,{className:`w-4 h-4 text-dracula-purple`}),` Agent template library`,(0,G.jsxs)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:[Y.length,` of `,Q.length]})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`Start from a curated template across engineering, product, science, health, legal, and more. Pick one and open it in the Studio for review and editing before saving.`})]}),(0,G.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,G.jsx)(p,{className:`w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none`}),(0,G.jsx)(`input`,{value:O,onChange:e=>k(e.target.value),placeholder:`Search by name, description, tag, or category…`,className:`w-full h-9 pl-8 pr-8 text-sm rounded-md border border-border bg-background focus:outline-none focus:ring-1 focus:ring-primary/40`,autoFocus:!0}),O&&(0,G.jsx)(`button`,{type:`button`,onClick:()=>k(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,G.jsx)(f,{className:`w-3.5 h-3.5`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,G.jsx)(me,{label:`All`,count:Q.length,active:A===`all`,onClick:()=>N(`all`)}),ue.map(e=>(0,G.jsx)(me,{label:e,count:ie.get(e)??0,active:A===e,onClick:()=>N(e)},e))]}),F&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Tag filter:`}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>I(null),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full bg-dracula-purple/20 text-dracula-purple hover:bg-dracula-purple/30`,children:[(0,G.jsx)(ne,{className:`w-3 h-3`}),` `,F,(0,G.jsx)(f,{className:`w-3 h-3`})]})]})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:Y.length===0?(0,G.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,G.jsxs)(`div`,{className:`max-w-sm`,children:[(0,G.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No templates match your filters.`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{k(``),N(`all`),I(null)},className:`text-xs text-dracula-purple hover:underline mt-2`,children:`Clear filters`})]})}):(0,G.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:Y.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{X(),S({kind:`create`,initialBody:e.body,initialName:e.nameHint})},className:`group text-left p-4 rounded-lg border border-border bg-card/40 hover:border-dracula-purple/50 hover:bg-accent/40 hover:shadow-sm transition-all`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:e.emoji}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-dracula-purple truncate`,children:e.label}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:e.category})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:e.blurb}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:e.tags.slice(0,5).map(e=>(0,G.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),I(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),I(e))},className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/50 text-muted-foreground hover:bg-dracula-purple/20 hover:text-dracula-purple cursor-pointer transition-colors `+(F===e?`bg-dracula-purple/20 text-dracula-purple`:``),children:e},e))}),(0,G.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,G.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:e.nameHint}),(0,G.jsx)(`span`,{className:`text-[10px] text-dracula-purple opacity-0 group-hover:opacity-100 transition-opacity`,children:`Open in Studio →`})]})]},e.id))})}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:`Tip: click a tag pill on any card to filter by that tag.`}),(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:X,children:`Cancel`})]})]})}),oe=()=>(0,G.jsx)(w,{open:L,onOpenChange:e=>{!e&&!H&&(z(!1),K(null))},children:(0,G.jsxs)(M,{className:`max-w-lg`,children:[(0,G.jsx)(T,{children:(0,G.jsxs)(x,{className:`flex items-center gap-2`,children:[(0,G.jsx)(d,{className:`w-4 h-4 text-dracula-purple`}),` Generate a custom agent`]})}),(0,G.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Agent id`}),(0,G.jsx)(j,{value:B,onChange:e=>ee(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:H}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:[`Must start with `,(0,G.jsx)(`code`,{children:`custom-`}),`.`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Describe what this agent should do`}),(0,G.jsx)(`textarea`,{value:V,onChange:e=>te(e.target.value),placeholder:`e.g. Review Terraform/IaC changes and flag security misconfigurations, excessive IAM permissions, and public S3 buckets before merging. Conservative and terse.`,className:`w-full text-sm p-2 rounded border border-border bg-background min-h-[120px] resize-y`,disabled:H})]}),re&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:re}),(0,G.jsxs)(`p`,{className:`text-[11px] text-muted-foreground`,children:[`Claude will draft a full `,(0,G.jsx)(`code`,{children:`.md`}),` body. You'll review it in the Studio and can edit before saving. This spawns a one-shot claude invocation and can take up to 90 seconds.`]})]}),(0,G.jsxs)(E,{children:[(0,G.jsx)(R,{variant:`ghost`,size:`sm`,onClick:()=>z(!1),disabled:H,children:`Cancel`}),(0,G.jsx)(R,{size:`sm`,onClick:se,disabled:H||!B.trim()||!V.trim(),children:H?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(a,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` Generating…`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(d,{className:`w-3.5 h-3.5 mr-1.5`}),` Generate`]})})]})]})}),se=async()=>{U(!0),K(null);try{let e=await fetch(`${s()}/profiles/catalog/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:B.trim(),description:V.trim()})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error??`Generate failed: ${e.status}`)}let t=await e.json();z(!1),S({kind:`create`,initialBody:t.draft,initialName:B.trim()})}catch(e){K(e.message)}finally{U(!1)}},ce=async e=>{try{let t=await fetch(`${s()}/profiles/catalog/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Load failed: ${t.status}`);S({kind:`duplicate`,from:e,initialBody:(await t.json()).body})}catch(e){_(e.message)}};if(e.length===0)return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,G.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:`No agents installed`}),(0,G.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:[`Run `,(0,G.jsx)(`code`,{className:`text-foreground`,children:`npx specrails-core@latest update`}),` in this project to install the upstream agents, or create a custom agent now.`]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[(0,G.jsxs)(R,{size:`sm`,onClick:()=>z(!0),children:[(0,G.jsx)(d,{className:`w-3.5 h-3.5 mr-1.5`}),` Generate with Claude`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>D(!0),children:[(0,G.jsx)(P,{className:`w-3.5 h-3.5 mr-1.5`}),` Template`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>S({kind:`create`}),children:[(0,G.jsx)(y,{className:`w-3.5 h-3.5 mr-1.5`}),` Blank`]})]})]})}),ae(),oe()]});let le=e.filter(e=>e.kind===`upstream`),Z=e.filter(e=>e.kind===`custom`),$=e.find(e=>e.id===n);return(0,G.jsxs)(G.Fragment,{children:[ae(),oe(),(0,G.jsxs)(`div`,{className:`flex h-full`,children:[(0,G.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,G.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:`Catalog`}),(0,G.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:`Create a custom agent:`}),(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>D(!0),title:`Start from a template`,children:[(0,G.jsx)(P,{className:`w-3 h-3 mr-1`}),` Template`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>z(!0),title:`Generate with Claude`,children:[(0,G.jsx)(d,{className:`w-3 h-3 mr-1`}),` Generate`]}),(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>S({kind:`create`}),title:`Start from a blank template`,children:[(0,G.jsx)(y,{className:`w-3 h-3 mr-1`}),` Blank`]})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,G.jsx)(he,{title:`Upstream (${le.length})`,description:`Shipped by specrails-core; read-only.`,children:le.map(e=>(0,G.jsx)(ge,{agent:e,selected:e.id===n,onSelect:()=>r(e.id)},e.id))}),(0,G.jsx)(he,{title:`Custom (${Z.length})`,description:`Your project's custom-*.md files. Use Template / Generate / Blank above to create one.`,children:Z.length===0?(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:`No custom agents yet.`}):Z.map(e=>(0,G.jsx)(ge,{agent:e,selected:e.id===n,onSelect:()=>r(e.id)},e.id))})]})]}),(0,G.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[g&&(0,G.jsx)(`div`,{className:`m-4 px-3 py-2 text-xs rounded border border-red-500/30 bg-red-500/10 text-red-400`,children:g}),$&&(0,G.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,G.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:$.id}),(0,G.jsx)(_e,{kind:$.kind}),$.model&&(0,G.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[`default model: `,$.model]})]}),$.description&&(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:$.description})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,G.jsxs)(R,{size:`sm`,variant:`ghost`,onClick:()=>void ce($.id),children:[(0,G.jsx)(i,{className:`w-3.5 h-3.5 mr-1`}),` Duplicate`]}),$.kind===`custom`&&(0,G.jsxs)(R,{size:`sm`,onClick:()=>S({kind:`edit`,agentId:$.id}),children:[(0,G.jsx)(b,{className:`w-3.5 h-3.5 mr-1`}),` Edit`]})]})]}),(0,G.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,G.jsxs)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:[`.claude/agents/`,$.id,`.md`]}),(0,G.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:$.kind===`upstream`?`read-only`:`editable — use Edit above`})]}),(0,G.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:m?`Loading…`:o??``})]})]})]})]})]})}function me({label:e,count:t,active:n,onClick:r}){return(0,G.jsxs)(`button`,{type:`button`,onClick:r,className:`flex-shrink-0 inline-flex items-center gap-1 h-7 px-2.5 text-[11px] rounded-full border transition-colors whitespace-nowrap `+(n?`bg-dracula-purple/20 border-dracula-purple/50 text-dracula-purple`:`bg-transparent border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[e,(0,G.jsx)(`span`,{className:`text-[9px] px-1 rounded `+(n?`bg-dracula-purple/30`:`bg-muted/60`),children:t})]})}function he({title:e,description:t,children:n}){return(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,G.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,G.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function ge({agent:e,selected:t,onSelect:n}){return(0,G.jsxs)(`button`,{type:`button`,onClick:n,className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded transition-colors `+(t?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[(0,G.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,G.jsx)(_e,{kind:e.kind})]})}function _e({kind:e}){return(0,G.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 `+(e===`custom`?`bg-purple-500/15 text-purple-400`:`bg-muted text-muted-foreground`),children:e})}var ve=[{label:`7d`,days:7},{label:`30d`,days:30},{label:`90d`,days:90}];function ye(){let[e,t]=(0,W.useState)(null),[n,r]=(0,W.useState)(30),[i,a]=(0,W.useState)(!0);if((0,W.useEffect)(()=>{let e=!1;return a(!0),fetch(`${s()}/profiles/analytics?windowDays=${n}`).then(e=>e.ok?e.json():null).then(n=>{!e&&n&&t(n)}).catch(()=>{}).finally(()=>{e||a(!1)}),()=>{e=!0}},[n]),i&&!e)return null;if(!e||e.rows.length===0)return(0,G.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:`Profile usage`}),(0,G.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:`Jobs launched per profile in the selected window.`})]}),(0,G.jsx)(`div`,{className:`flex gap-0.5`,children:ve.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(e.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(n===e.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e.label},e.days))})]}),(0,G.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:`No profile-scoped jobs yet.`})]});let o=Math.max(...e.rows.map(e=>e.jobs),1);return(0,G.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:`Profile usage`}),(0,G.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[`Jobs launched per profile in the last `,e.windowDays,` days.`]})]}),(0,G.jsx)(`div`,{className:`flex gap-0.5`,children:ve.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>r(e.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(n===e.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e.label},e.days))})]}),(0,G.jsx)(`div`,{className:`p-4 space-y-2`,children:e.rows.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:e.profileName}),(0,G.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full bg-dracula-purple/70`,style:{width:`${Math.max(6,Math.round(e.jobs/o*100))}%`}})}),(0,G.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,G.jsxs)(`span`,{title:`jobs`,children:[(0,G.jsx)(`span`,{className:`text-foreground font-mono`,children:e.jobs}),` jobs`]}),(0,G.jsxs)(`span`,{title:`success rate`,children:[(0,G.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(e.successRate*100),`%`]}),` `,`ok`]}),e.avgDurationMs!=null&&(0,G.jsx)(`span`,{title:`avg duration`,children:(0,G.jsx)(`span`,{className:`text-foreground font-mono`,children:be(e.avgDurationMs)})}),e.avgTokens!=null&&(0,G.jsxs)(`span`,{title:`avg tokens`,children:[(0,G.jsx)(`span`,{className:`text-foreground font-mono`,children:xe(e.avgTokens)}),` `,`tok`]})]})]},e.profileName))})]})}function be(e){let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h${n%60}m`}function xe(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var Se=`specrails-hub:agents-tab`;function Ce(){try{let e=localStorage.getItem(Se);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function we(){let[e,t]=(0,W.useState)(()=>Ce()),n=e=>{t(e);try{localStorage.setItem(Se,e)}catch{}},[r,i]=(0,W.useState)(null);return(0,W.useEffect)(()=>{let e=!1;return fetch(`${s()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&i(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,G.jsxs)(`div`,{className:`flex flex-col h-full bg-background`,children:[r!==null&&!r.profileAware&&(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start gap-3 px-6 py-3 border-b border-yellow-500/30 bg-yellow-500/10`,children:[(0,G.jsx)(_,{className:`w-4 h-4 text-yellow-500 mt-0.5 flex-shrink-0`}),(0,G.jsxs)(`div`,{className:`text-xs`,children:[(0,G.jsxs)(`div`,{className:`font-medium text-yellow-500`,children:[`Profile-aware pipeline requires specrails-core `,r.required,`+`]}),(0,G.jsxs)(`div`,{className:`text-yellow-500/80 mt-0.5`,children:[`This project has`,` `,(0,G.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20`,children:r.version??`unknown`}),`. Run`,` `,(0,G.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20`,children:`npx specrails-core@latest update`}),` `,`inside the project to unlock profile mode. Profiles you create here will still save; they just won't affect the pipeline until core is updated.`]})]})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,G.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,G.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Agents`}),(0,G.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:`Manage agent profiles and the catalog (upstream + custom) for this project.`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,G.jsx)(Ee,{active:e===`profiles`,onClick:()=>n(`profiles`),children:`Profiles`}),(0,G.jsx)(Ee,{active:e===`usage`,onClick:()=>n(`usage`),children:`Usage`}),(0,G.jsx)(Ee,{active:e===`catalog`,onClick:()=>n(`catalog`),children:`Catalog`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[e===`profiles`&&(0,G.jsx)(le,{}),e===`usage`&&(0,G.jsx)(Te,{}),e===`catalog`&&(0,G.jsx)(pe,{})]})]})}function Te(){return(0,G.jsx)(`div`,{className:`min-h-full`,children:(0,G.jsx)(ye,{})})}function Ee({active:e,children:t,onClick:n}){return(0,G.jsx)(`button`,{type:`button`,onClick:n,className:`h-8 px-3 text-xs font-medium rounded-t-md border-b-2 transition-colors `+(e?`text-foreground border-foreground`:`text-muted-foreground border-transparent hover:text-foreground hover:border-border`),children:t})}export{we as default};