specrails-desktop 2.26.0 → 2.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/client/dist/assets/{ActivityFeedPage-1eXnoNAo.js → ActivityFeedPage-bDe4VitF.js} +1 -1
  2. package/client/dist/assets/{AgentBrowserCapture-BHW_6Vm0.js → AgentBrowserCapture-DQyeEm2V.js} +1 -1
  3. package/client/dist/assets/{AgentModeCodePane-C89SAJzI.js → AgentModeCodePane-Ci39DcOo.js} +2 -2
  4. package/client/dist/assets/{AgentModeJobsPane-BG_4r4Dm.js → AgentModeJobsPane-C-g1WNVG.js} +1 -1
  5. package/client/dist/assets/{AgentsPage-BrkWfc9s.js → AgentsPage-BWgglK7V.js} +3 -3
  6. package/client/dist/assets/{AnalyticsPage-CMZRUPrT.js → AnalyticsPage-Da21wWWw.js} +1 -1
  7. package/client/dist/assets/{BarChart-BtF3zJHa.js → BarChart-BiLTq3uC.js} +1 -1
  8. package/client/dist/assets/{CodePage-Cime5FRs.js → CodePage-BUcAp7SC.js} +1 -1
  9. package/client/dist/assets/{DesktopAnalyticsPage-CSKHSBBF.js → DesktopAnalyticsPage-COkzgMmd.js} +1 -1
  10. package/client/dist/assets/{DocsDialog-ClTq6Fzj.js → DocsDialog-PZHMN18B.js} +1 -1
  11. package/client/dist/assets/{DocsPage-DTxfOpTu.js → DocsPage-D3fChfkj.js} +1 -1
  12. package/client/dist/assets/{ExportDropdown-Ho9zdPvK.js → ExportDropdown-DDhJH-Jr.js} +1 -1
  13. package/client/dist/assets/{IntegrationsPage-DWNyo6jk.js → IntegrationsPage-F87uxxVH.js} +1 -1
  14. package/client/dist/assets/{InteractiveJobComposer-CYxXOKld.js → InteractiveJobComposer-DqDCiCa0.js} +5 -5
  15. package/client/dist/assets/{JobDetailModal-DrNafHY5.js → JobDetailModal-BWJR60fi.js} +1 -1
  16. package/client/dist/assets/{JobDetailPage-4VKw33GW.js → JobDetailPage-CjWE_jyd.js} +1 -1
  17. package/client/dist/assets/{JobsPage-cFr6wWaH.js → JobsPage-LmnXkyCa.js} +1 -1
  18. package/client/dist/assets/{LoopBuilderPage-Bk8zVvEX.js → LoopBuilderPage-DsLLrtHa.js} +2 -2
  19. package/client/dist/assets/{LoopPreviewModal-XFSO2Vcs.js → LoopPreviewModal-C-fDEgnu.js} +1 -1
  20. package/client/dist/assets/{LoopsPage-DWMwDj9g.js → LoopsPage-DDNO9h9T.js} +1 -1
  21. package/client/dist/assets/{ProjectSettingsDialog-DnSe_yWm.js → ProjectSettingsDialog-CX854C8e.js} +1 -1
  22. package/client/dist/assets/{TemplatePreviewModal-B30-TY_v.js → TemplatePreviewModal-DcHFbLA8.js} +1 -1
  23. package/client/dist/assets/agent-BI6vr-To.js +1 -0
  24. package/client/dist/assets/{agent-D5QNn9np2.js → agent-BUGXI3Ok2.js} +1 -1
  25. package/client/dist/assets/agent-Bph_-xt7.js +1 -0
  26. package/client/dist/assets/agent-Bvy2Csyd.js +1 -0
  27. package/client/dist/assets/{agent-DgFoLgrF2.js → agent-Bwkyg2oX2.js} +1 -1
  28. package/client/dist/assets/agent-CLCyDaZh.js +1 -0
  29. package/client/dist/assets/{agent-6mhkV25_2.js → agent-Cqs14QMr2.js} +1 -1
  30. package/client/dist/assets/{agent-CRYdi9-t.js → agent-DJ0EBUuP.js} +1 -1
  31. package/client/dist/assets/{brain-DcXkQwzO.js → brain-BBNUUrUI.js} +1 -1
  32. package/client/dist/assets/dashboard-BjjS1OrL.js +1 -0
  33. package/client/dist/assets/dashboard-Bk6oSk1H2.js +1 -0
  34. package/client/dist/assets/dashboard-BrH-GdOg2.js +1 -0
  35. package/client/dist/assets/dashboard-BurhUI8_.js +1 -0
  36. package/client/dist/assets/dashboard-C6w0rICe.js +1 -0
  37. package/client/dist/assets/dashboard-CAUnfDQL2.js +1 -0
  38. package/client/dist/assets/dashboard-C_ljpeYO.js +1 -0
  39. package/client/dist/assets/dashboard-D6OqDdj6.js +1 -0
  40. package/client/dist/assets/{dist-js-BAWwLSIj.js → dist-js-BxjTIvdT.js} +1 -1
  41. package/client/dist/assets/{dist-js-6U6hyD6z.js → dist-js-DdP_Gl3p.js} +1 -1
  42. package/client/dist/assets/{index-cvOunQkD.css → index-C695aPdV.css} +1 -1
  43. package/client/dist/assets/index-Dw1N2-ci.js +156 -0
  44. package/client/dist/assets/{lib-Bsny0zZp.js → lib-BviHZ_gK.js} +1 -1
  45. package/client/dist/assets/{settings-DHd1lQ1k.js → settings-BHdPchJP.js} +1 -1
  46. package/client/dist/assets/{settings-FJXpJ3k92.js → settings-BeCczBFS2.js} +1 -1
  47. package/client/dist/assets/{settings-BWIf3vv4.js → settings-BlLi719f.js} +1 -1
  48. package/client/dist/assets/{settings-DTYQ5COE.js → settings-C_nY14Yz.js} +1 -1
  49. package/client/dist/assets/{settings-DE8t6aYv.js → settings-CaZ26a0S.js} +1 -1
  50. package/client/dist/assets/{settings-Dgv_q4qf2.js → settings-D54_cgl12.js} +1 -1
  51. package/client/dist/assets/{settings-DXgPh9-k.js → settings-D9bDDe2O.js} +1 -1
  52. package/client/dist/assets/{settings-BhuXe7ek2.js → settings-cn0tbve62.js} +1 -1
  53. package/client/dist/assets/{setup-iY8vH8pB.js → setup-7J8TjG4O.js} +1 -1
  54. package/client/dist/assets/{setup-D674kWQH.js → setup-BXpw07r-.js} +1 -1
  55. package/client/dist/assets/{setup-B590KsTX.js → setup-BiduSX9d.js} +1 -1
  56. package/client/dist/assets/{setup-cnqZsQSX2.js → setup-BuQNKztt2.js} +1 -1
  57. package/client/dist/assets/{setup-CEj6uY3-2.js → setup-BwMovM9z2.js} +1 -1
  58. package/client/dist/assets/{setup-BkyGoby6.js → setup-D84y3wx-.js} +1 -1
  59. package/client/dist/assets/{setup-CbIerFGf2.js → setup-DU0ULX8q2.js} +1 -1
  60. package/client/dist/assets/{setup-VNqXyB6Y.js → setup-RiUHzq7E.js} +1 -1
  61. package/client/dist/assets/{upload-49vX83IZ.js → upload-CRuuzzvp.js} +1 -1
  62. package/client/dist/assets/{value-Bo8EiTZE.js → value-CIr5hDMt.js} +1 -1
  63. package/client/dist/index.html +21 -8
  64. package/package.json +1 -1
  65. package/server/dist/agent-operator-prompt.js +45 -5
  66. package/server/dist/desktop-router.js +9 -2
  67. package/server/dist/mcp/guide.js +33 -4
  68. package/server/dist/mcp/tools/app-settings.js +18 -2
  69. package/server/dist/mcp/tools/catalog.js +2 -0
  70. package/server/dist/mcp/tools/rails.js +27 -6
  71. package/server/dist/mcp/tools/support.js +324 -0
  72. package/server/dist/pr-publisher.js +17 -15
  73. package/server/dist/project-git.js +57 -0
  74. package/server/dist/rail-isolated-launch.js +27 -3
  75. package/server/dist/rail-pr-decision.js +69 -1
  76. package/server/dist/rail-worktree-release.js +25 -0
  77. package/server/dist/rail-worktrees-store.js +2 -2
  78. package/server/dist/rails-router.js +136 -7
  79. package/client/dist/assets/agent-BZqfQhI_.js +0 -1
  80. package/client/dist/assets/agent-Bjy1SlT5.js +0 -1
  81. package/client/dist/assets/agent-Bn6ZmjHj.js +0 -1
  82. package/client/dist/assets/agent-DgwPsxWQ.js +0 -1
  83. package/client/dist/assets/dashboard-CuGuy2__2.js +0 -1
  84. package/client/dist/assets/dashboard-CxP3TZ3I2.js +0 -1
  85. package/client/dist/assets/dashboard-DWHVfP7U.js +0 -1
  86. package/client/dist/assets/dashboard-D_Pgs6QH2.js +0 -1
  87. package/client/dist/assets/dashboard-Dwnssayh.js +0 -1
  88. package/client/dist/assets/dashboard-S_pT1yxN.js +0 -1
  89. package/client/dist/assets/dashboard-tCxOFOxx.js +0 -1
  90. package/client/dist/assets/dashboard-zefbBNyG.js +0 -1
  91. package/client/dist/assets/index-DnkfABxY.js +0 -156
@@ -1 +1 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Pt as r,Rn as i,Sn as a,gn as o,hn as s,it as c,nn as l,tn as u,vn as d,wn as f,xn as p}from"./index-DnkfABxY.js";var m=o(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),h=e(n(),1);function g(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 _({activeProjectId:e,limit:t=50}){let[n,r]=(0,h.useState)([]),[i,o]=(0,h.useState)(!1),[s,c]=(0,h.useState)(!0),l=(0,h.useRef)(e);(0,h.useEffect)(()=>{l.current=e},[e]);let{registerHandler:u,unregisterHandler:d}=a();(0,h.useEffect)(()=>{if(!e){r([]),c(!0);return}let n=!1;o(!0),r([]),c(!0);async function i(){let e=f();try{let i=await fetch(`${e}/activity?limit=${t}`);if(!i.ok||n)return;let a=await i.json();if(n)return;r(a),c(a.length===t)}catch{}finally{n||o(!1)}}return i(),()=>{n=!0}},[e,t]);let m=(0,h.useCallback)(async()=>{if(i||!s)return;o(!0);let e=f(),n=l.current;try{r(i=>{let a=i[i.length-1];if(!a)return i;let s=encodeURIComponent(a.timestamp);return fetch(`${e}/activity?limit=${t}&before=${s}`).then(e=>e.json()).then(e=>{if(l.current!==n){o(!1);return}r(t=>g([...t,...e])),c(e.length===t),o(!1)}).catch(()=>o(!1)),i})}catch{o(!1)}},[i,s,t]),_=(0,h.useCallback)(e=>{let t=e,n=l.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=>g([...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:p.t(`activity:feed.phaseCommand`,{phase:t.phase,state:t.state}),timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};r(t=>g([e,...t]))}}},[]);return(0,h.useLayoutEffect)(()=>(u(`activity`,_),()=>d(`activity`)),[_,u,d]),{items:n,loading:i,hasMore:s,loadMore:m}}var v=t();function y(e,t){let n=Date.now()-new Date(e).getTime(),r=Math.floor(n/1e3);if(r<60)return t(`feed.relativeTime.seconds`,{value:r});let i=Math.floor(r/60);if(i<60)return t(`feed.relativeTime.minutes`,{value:i});let a=Math.floor(i/60);return a<24?t(`feed.relativeTime.hours`,{value:a}):t(`feed.relativeTime.days`,{value:Math.floor(a/24)})}function b({type:e}){switch(e){case`job_completed`:return(0,v.jsx)(l,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,v.jsx)(u,{className:`w-4 h-4 text-red-500 aurora-light:text-destructive flex-shrink-0`});case`job_canceled`:return(0,v.jsx)(m,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,v.jsx)(c,{className:`w-4 h-4 text-blue-500 aurora-light:text-accent-info flex-shrink-0`})}}function x(e,t){switch(e){case`job_completed`:return t(`common:status.completed`);case`job_failed`:return t(`common:status.failed`);case`job_canceled`:return t(`common:status.canceled`);default:return t(`feed.typeStarted`)}}function S(e){switch(e){case`job_completed`:return`text-green-500 aurora-light:text-accent-success`;case`job_failed`:return`text-red-500 aurora-light:text-destructive`;case`job_canceled`:return`text-muted-foreground`;default:return`text-blue-500 aurora-light:text-accent-info`}}function C(){let{t:e}=i(`activity`),{activeProjectId:t}=d(),{items:n,loading:a,hasMore:o,loadMore:c}=_({activeProjectId:t}),l=(0,h.useRef)(null);return(0,h.useEffect)(()=>{let e=l.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&o&&!a&&c()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[o,a,c]),(0,v.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,v.jsx)(s,{className:`w-4 h-4 text-muted-foreground`}),(0,v.jsx)(`h1`,{className:`text-sm font-medium`,children:e(`feed.title`)})]}),(0,v.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[a&&n.length===0?(0,v.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,v.jsx)(r,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):n.length===0?(0,v.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,v.jsx)(s,{className:`w-8 h-8 opacity-40`}),(0,v.jsx)(`p`,{className:`text-sm`,children:e(`feed.emptyTitle`)}),(0,v.jsx)(`p`,{className:`text-xs opacity-70`,children:e(`feed.emptyHint`)})]}):(0,v.jsx)(`ul`,{className:`divide-y divide-border/50`,children:n.map(t=>(0,v.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,v.jsx)(b,{type:t.type}),(0,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:t.jobCommand,children:t.jobCommand}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,v.jsx)(`span`,{className:`text-xs font-medium ${S(t.type)}`,children:x(t.type,e)}),t.costUsd!=null&&(0,v.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,t.costUsd.toFixed(4)]})]})]}),(0,v.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:y(t.timestamp,e)})]},`${t.type}:${t.jobId}`))}),(0,v.jsx)(`div`,{ref:l,className:`h-1`}),a&&n.length>0&&(0,v.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,v.jsx)(r,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!o&&n.length>0&&(0,v.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{C as default};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Pt as r,Rn as i,Sn as a,gn as o,hn as s,it as c,nn as l,tn as u,vn as d,wn as f,xn as p}from"./index-Dw1N2-ci.js";var m=o(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),h=e(n(),1);function g(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 _({activeProjectId:e,limit:t=50}){let[n,r]=(0,h.useState)([]),[i,o]=(0,h.useState)(!1),[s,c]=(0,h.useState)(!0),l=(0,h.useRef)(e);(0,h.useEffect)(()=>{l.current=e},[e]);let{registerHandler:u,unregisterHandler:d}=a();(0,h.useEffect)(()=>{if(!e){r([]),c(!0);return}let n=!1;o(!0),r([]),c(!0);async function i(){let e=f();try{let i=await fetch(`${e}/activity?limit=${t}`);if(!i.ok||n)return;let a=await i.json();if(n)return;r(a),c(a.length===t)}catch{}finally{n||o(!1)}}return i(),()=>{n=!0}},[e,t]);let m=(0,h.useCallback)(async()=>{if(i||!s)return;o(!0);let e=f(),n=l.current;try{r(i=>{let a=i[i.length-1];if(!a)return i;let s=encodeURIComponent(a.timestamp);return fetch(`${e}/activity?limit=${t}&before=${s}`).then(e=>e.json()).then(e=>{if(l.current!==n){o(!1);return}r(t=>g([...t,...e])),c(e.length===t),o(!1)}).catch(()=>o(!1)),i})}catch{o(!1)}},[i,s,t]),_=(0,h.useCallback)(e=>{let t=e,n=l.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=>g([...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:p.t(`activity:feed.phaseCommand`,{phase:t.phase,state:t.state}),timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};r(t=>g([e,...t]))}}},[]);return(0,h.useLayoutEffect)(()=>(u(`activity`,_),()=>d(`activity`)),[_,u,d]),{items:n,loading:i,hasMore:s,loadMore:m}}var v=t();function y(e,t){let n=Date.now()-new Date(e).getTime(),r=Math.floor(n/1e3);if(r<60)return t(`feed.relativeTime.seconds`,{value:r});let i=Math.floor(r/60);if(i<60)return t(`feed.relativeTime.minutes`,{value:i});let a=Math.floor(i/60);return a<24?t(`feed.relativeTime.hours`,{value:a}):t(`feed.relativeTime.days`,{value:Math.floor(a/24)})}function b({type:e}){switch(e){case`job_completed`:return(0,v.jsx)(l,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,v.jsx)(u,{className:`w-4 h-4 text-red-500 aurora-light:text-destructive flex-shrink-0`});case`job_canceled`:return(0,v.jsx)(m,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,v.jsx)(c,{className:`w-4 h-4 text-blue-500 aurora-light:text-accent-info flex-shrink-0`})}}function x(e,t){switch(e){case`job_completed`:return t(`common:status.completed`);case`job_failed`:return t(`common:status.failed`);case`job_canceled`:return t(`common:status.canceled`);default:return t(`feed.typeStarted`)}}function S(e){switch(e){case`job_completed`:return`text-green-500 aurora-light:text-accent-success`;case`job_failed`:return`text-red-500 aurora-light:text-destructive`;case`job_canceled`:return`text-muted-foreground`;default:return`text-blue-500 aurora-light:text-accent-info`}}function C(){let{t:e}=i(`activity`),{activeProjectId:t}=d(),{items:n,loading:a,hasMore:o,loadMore:c}=_({activeProjectId:t}),l=(0,h.useRef)(null);return(0,h.useEffect)(()=>{let e=l.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&o&&!a&&c()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[o,a,c]),(0,v.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,v.jsx)(s,{className:`w-4 h-4 text-muted-foreground`}),(0,v.jsx)(`h1`,{className:`text-sm font-medium`,children:e(`feed.title`)})]}),(0,v.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[a&&n.length===0?(0,v.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,v.jsx)(r,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):n.length===0?(0,v.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,v.jsx)(s,{className:`w-8 h-8 opacity-40`}),(0,v.jsx)(`p`,{className:`text-sm`,children:e(`feed.emptyTitle`)}),(0,v.jsx)(`p`,{className:`text-xs opacity-70`,children:e(`feed.emptyHint`)})]}):(0,v.jsx)(`ul`,{className:`divide-y divide-border/50`,children:n.map(t=>(0,v.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,v.jsx)(b,{type:t.type}),(0,v.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,v.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:t.jobCommand,children:t.jobCommand}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,v.jsx)(`span`,{className:`text-xs font-medium ${S(t.type)}`,children:x(t.type,e)}),t.costUsd!=null&&(0,v.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,t.costUsd.toFixed(4)]})]})]}),(0,v.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:y(t.timestamp,e)})]},`${t.type}:${t.jobId}`))}),(0,v.jsx)(`div`,{ref:l,className:`h-1`}),a&&n.length>0&&(0,v.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,v.jsx)(r,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!o&&n.length>0&&(0,v.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{C as default};
@@ -1 +1 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,F as n,Kn as r,Ln as i,Rn as a,n as o,s}from"./index-DnkfABxY.js";var c=e(r(),1);function l(e,t){let n=e.indexOf(`,`);if(!e.startsWith(`data:`)||n===-1)throw Error(`dataUrlToFile: not a data URL`);let r=e.slice(0,n),i=/^data:([^;,]+)/.exec(r)?.[1]||`application/octet-stream`,a=e.slice(n+1);if(/;base64$/i.test(r)){let e=atob(a),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return new File([n],t,{type:i})}return new File([decodeURIComponent(a)],t,{type:i})}var u=t();function d({projectId:e,conversationId:t}){let{t:r}=a(`agent`),{closeBrowser:d,queueCapture:f}=o(),p=(0,c.useMemo)(()=>`agent-${t??`home`}-${Math.round(performance.now())}`,[t]),m=async e=>{if(!t){i.error(r(`workspace.requiresConversation`));return}try{f(await s(t,l(e.screenshotDataUrl,`capture-${Date.now()}.png`))),i.success(r(`workspace.browserCaptured`)),d()}catch(e){i.error(r(`workspace.uploadFailed`),{description:e instanceof Error?e.message:void 0})}};return(0,u.jsx)(n,{open:!0,onClose:d,projectId:e,pendingSpecId:p,confirmLabel:r(`workspace.browserConfirm`),onCaptured:e=>{m(e)}})}export{d as AgentBrowserCapture};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,F as n,Kn as r,Ln as i,Rn as a,n as o,s}from"./index-Dw1N2-ci.js";var c=e(r(),1);function l(e,t){let n=e.indexOf(`,`);if(!e.startsWith(`data:`)||n===-1)throw Error(`dataUrlToFile: not a data URL`);let r=e.slice(0,n),i=/^data:([^;,]+)/.exec(r)?.[1]||`application/octet-stream`,a=e.slice(n+1);if(/;base64$/i.test(r)){let e=atob(a),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return new File([n],t,{type:i})}return new File([decodeURIComponent(a)],t,{type:i})}var u=t();function d({projectId:e,conversationId:t}){let{t:r}=a(`agent`),{closeBrowser:d,queueCapture:f}=o(),p=(0,c.useMemo)(()=>`agent-${t??`home`}-${Math.round(performance.now())}`,[t]),m=async e=>{if(!t){i.error(r(`workspace.requiresConversation`));return}try{f(await s(t,l(e.screenshotDataUrl,`capture-${Date.now()}.png`))),i.success(r(`workspace.browserCaptured`)),d()}catch(e){i.error(r(`workspace.uploadFailed`),{description:e instanceof Error?e.message:void 0})}};return(0,u.jsx)(n,{open:!0,onClose:d,projectId:e,pendingSpecId:p,confirmLabel:r(`workspace.browserConfirm`),onCaptured:e=>{m(e)}})}export{d as AgentBrowserCapture};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-Cime5FRs.js","assets/chunk-BNv3lrIs.js","assets/index-DnkfABxY.js","assets/preload-helper-DSXbuxSR.js","assets/clsx-CNmW0Nip.js","assets/auth-Cvsb7-Ek.js","assets/activity-D8vQJrpW.js","assets/addspec-DxW6oPsk.js","assets/agent-Bn6ZmjHj.js","assets/agents-Cev2oFfX.js","assets/agentstudio-CZm2rOzt.js","assets/aiedit-DYtnZU9H.js","assets/analytics-Ce-sPORu.js","assets/attachments-Ci6_42Kh.js","assets/browser-CdS6O1Qb.js","assets/chat-VMflhzxn.js","assets/code-thSEptMx.js","assets/commands-CckaBWdV.js","assets/common-CYaT2yHp.js","assets/dashboard-Dwnssayh.js","assets/explore-BKVV5JSu.js","assets/integrations-CuWnMR5L.js","assets/jira-B3613-gj.js","assets/jobs-D5sZzgLs.js","assets/loops-Brnx4Fji.js","assets/mcp-CIH0pH1K.js","assets/nav-CzKzuwH8.js","assets/settings-DXgPh9-k.js","assets/setup-VNqXyB6Y.js","assets/specs-CmEZY57v.js","assets/terminal-DFPNRLKp.js","assets/tickets-CkfbISuK.js","assets/index-cvOunQkD.css"])))=>i.map(i=>d[i]);
2
- import{a as e}from"./chunk-BNv3lrIs.js";import{t}from"./preload-helper-DSXbuxSR.js";import{Cn as n,Kn as r,Mt as i,Rn as a,at as o,jt as s,n as c}from"./index-DnkfABxY.js";var l=e(r(),1),u=n(),d=(0,l.lazy)(()=>t(()=>import(`./CodePage-Cime5FRs.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]))),f=new Map,p=420,m=560;function h({projectId:e,conversationId:t}){let{t:n}=a(`agent`),{closeCodePane:r}=c(),[h,g]=(0,l.useState)(m),[_,v]=(0,l.useState)(!1),y=(0,l.useRef)(null),b=`${e}:${t}`,x=(0,l.useCallback)(e=>{f.set(b,e)},[b]),S=(0,l.useCallback)(e=>{let t=e.clientX,n=h,r=window.innerWidth-p;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{g(Math.min(Math.max(n+(t-e.clientX),p),r))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[h]);return(0,u.jsxs)(`div`,{ref:y,className:`flex h-full flex-col overflow-hidden border-l border-border bg-background${_?` absolute inset-0 z-30 border-l-0`:``}`,style:_?void 0:{width:h,flexShrink:0},children:[(0,u.jsx)(`div`,{className:`relative flex items-center`,children:!_&&(0,u.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:S,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:n(`workspace.resizeCode`)})}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:n(`workspace.files`)}),(0,u.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,u.jsx)(`button`,{type:`button`,onClick:()=>v(e=>!e),"aria-label":n(_?`restore`:`maximize`),title:n(_?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:_?(0,u.jsx)(s,{className:`h-4 w-4`}):(0,u.jsx)(i,{className:`h-4 w-4`})}),(0,u.jsx)(`button`,{type:`button`,onClick:r,"aria-label":n(`workspace.closeFiles`),title:n(`workspace.closeFiles`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,u.jsx)(o,{className:`h-4 w-4`})})]})]}),(0,u.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,u.jsx)(l.Suspense,{fallback:(0,u.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:`…`}),children:(0,u.jsx)(d,{embedded:!0,initialPath:f.get(b)??null,onSelectedPathChange:x})})})]},b)}export{h as AgentModeCodePane};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-BUcAp7SC.js","assets/chunk-BNv3lrIs.js","assets/index-Dw1N2-ci.js","assets/preload-helper-DSXbuxSR.js","assets/clsx-CNmW0Nip.js","assets/auth-Cvsb7-Ek.js","assets/activity-D8vQJrpW.js","assets/addspec-DxW6oPsk.js","assets/agent-CLCyDaZh.js","assets/agents-Cev2oFfX.js","assets/agentstudio-CZm2rOzt.js","assets/aiedit-DYtnZU9H.js","assets/analytics-Ce-sPORu.js","assets/attachments-Ci6_42Kh.js","assets/browser-CdS6O1Qb.js","assets/chat-VMflhzxn.js","assets/code-thSEptMx.js","assets/commands-CckaBWdV.js","assets/common-CYaT2yHp.js","assets/dashboard-BurhUI8_.js","assets/explore-BKVV5JSu.js","assets/integrations-CuWnMR5L.js","assets/jira-B3613-gj.js","assets/jobs-D5sZzgLs.js","assets/loops-Brnx4Fji.js","assets/mcp-CIH0pH1K.js","assets/nav-CzKzuwH8.js","assets/settings-D9bDDe2O.js","assets/setup-RiUHzq7E.js","assets/specs-CmEZY57v.js","assets/terminal-DFPNRLKp.js","assets/tickets-CkfbISuK.js","assets/index-C695aPdV.css"])))=>i.map(i=>d[i]);
2
+ import{a as e}from"./chunk-BNv3lrIs.js";import{t}from"./preload-helper-DSXbuxSR.js";import{Cn as n,Kn as r,Mt as i,Rn as a,at as o,jt as s,n as c}from"./index-Dw1N2-ci.js";var l=e(r(),1),u=n(),d=(0,l.lazy)(()=>t(()=>import(`./CodePage-BUcAp7SC.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]))),f=new Map,p=420,m=560;function h({projectId:e,conversationId:t}){let{t:n}=a(`agent`),{closeCodePane:r}=c(),[h,g]=(0,l.useState)(m),[_,v]=(0,l.useState)(!1),y=(0,l.useRef)(null),b=`${e}:${t}`,x=(0,l.useCallback)(e=>{f.set(b,e)},[b]),S=(0,l.useCallback)(e=>{let t=e.clientX,n=h,r=window.innerWidth-p;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{g(Math.min(Math.max(n+(t-e.clientX),p),r))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[h]);return(0,u.jsxs)(`div`,{ref:y,className:`flex h-full flex-col overflow-hidden border-l border-border bg-background${_?` absolute inset-0 z-30 border-l-0`:``}`,style:_?void 0:{width:h,flexShrink:0},children:[(0,u.jsx)(`div`,{className:`relative flex items-center`,children:!_&&(0,u.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:S,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:n(`workspace.resizeCode`)})}),(0,u.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,u.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:n(`workspace.files`)}),(0,u.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,u.jsx)(`button`,{type:`button`,onClick:()=>v(e=>!e),"aria-label":n(_?`restore`:`maximize`),title:n(_?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:_?(0,u.jsx)(s,{className:`h-4 w-4`}):(0,u.jsx)(i,{className:`h-4 w-4`})}),(0,u.jsx)(`button`,{type:`button`,onClick:r,"aria-label":n(`workspace.closeFiles`),title:n(`workspace.closeFiles`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,u.jsx)(o,{className:`h-4 w-4`})})]})]}),(0,u.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,u.jsx)(l.Suspense,{fallback:(0,u.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:`…`}),children:(0,u.jsx)(d,{embedded:!0,initialPath:f.get(b)??null,onSelectedPathChange:x})})})]},b)}export{h as AgentModeCodePane};
@@ -1 +1 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Mt as r,Pt as i,Rn as a,Sn as o,at as s,b as c,bn as l,cn as u,jt as d,n as f,rt as p,tt as m,vn as h,wn as g,yn as _}from"./index-DnkfABxY.js";import{JobDetailModal as v}from"./JobDetailModal-DrNafHY5.js";import{t as y}from"./format-command-CuWuRvka.js";var b=e(n(),1),x=t(),S=360,C=480,w={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function T({projectId:e}){let{t}=a(`agent`),{t:n}=a(`jobs`),{closeJobsPane:T}=f(),{projects:E}=h(),D=E.find(t=>t.id===e)?.provider,[O,k]=(0,b.useState)(C),[A,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(null),{data:P,isFirstLoad:F,refresh:I}=_({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let e=await fetch(`${g()}/jobs?limit=50`);return e.ok?(await e.json()).jobs:[]},pollInterval:5e3}),{registerHandler:L,unregisterHandler:R}=o(),z=(0,b.useRef)(e);z.current=e;let B=(0,b.useRef)(I);B.current=I,(0,b.useEffect)(()=>(L(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==z.current||B.current())}),()=>R(`agent-jobs-pane`)),[L,R]);let V=(0,b.useCallback)(e=>{let t=e.clientX,n=O,r=window.innerWidth-S;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{k(Math.min(Math.max(n+(t-e.clientX),S),r))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[O]);return(0,x.jsxs)(`div`,{className:p(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,A&&`absolute inset-0 z-30 border-l-0`),style:A?void 0:{width:O,flexShrink:0},children:[(0,x.jsx)(`div`,{className:`relative flex items-center`,children:!A&&(0,x.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:V,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:t(`workspace.resizeJobs`)})}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,x.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:()=>j(e=>!e),"aria-label":t(A?`restore`:`maximize`),title:t(A?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:A?(0,x.jsx)(d,{className:`h-4 w-4`}):(0,x.jsx)(r,{className:`h-4 w-4`})}),(0,x.jsx)(`button`,{type:`button`,onClick:T,"aria-label":t(`workspace.closeJobs`),title:t(`workspace.closeJobs`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,x.jsx)(s,{className:`h-4 w-4`})})]})]}),(0,x.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:F?(0,x.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,x.jsx)(i,{className:`h-4 w-4 animate-spin`})}):P.length===0?(0,x.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,x.jsx)(u,{className:`h-6 w-6 opacity-40`}),(0,x.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,x.jsx)(`ul`,{className:`space-y-1`,children:P.map(e=>(0,x.jsx)(`li`,{children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>N(e.id),className:p(`flex w-full flex-col gap-1 rounded-lg border border-border/50 bg-surface/30 px-2.5 py-2 text-left transition-colors`,`hover:border-accent-primary/40 hover:bg-surface/60`),children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(m,{variant:w[e.status]??`queued`,children:n(`statusLabel.${e.status in w?e.status:`queued`}`)}),e.status===`running`&&(0,x.jsx)(i,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,x.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:c(new Date(e.started_at),{addSuffix:!0,locale:l()})})]}),(0,x.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:y(e.command,D)})]})},e.id))})}),M&&(0,x.jsx)(v,{jobId:M,onClose:()=>N(null)})]})}export{T as AgentModeJobsPane};
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{Cn as t,Kn as n,Mt as r,Pt as i,Rn as a,Sn as o,at as s,b as c,bn as l,cn as u,jt as d,n as f,rt as p,tt as m,vn as h,wn as g,yn as _}from"./index-Dw1N2-ci.js";import{JobDetailModal as v}from"./JobDetailModal-BWJR60fi.js";import{t as y}from"./format-command-CuWuRvka.js";var b=e(n(),1),x=t(),S=360,C=480,w={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function T({projectId:e}){let{t}=a(`agent`),{t:n}=a(`jobs`),{closeJobsPane:T}=f(),{projects:E}=h(),D=E.find(t=>t.id===e)?.provider,[O,k]=(0,b.useState)(C),[A,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(null),{data:P,isFirstLoad:F,refresh:I}=_({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let e=await fetch(`${g()}/jobs?limit=50`);return e.ok?(await e.json()).jobs:[]},pollInterval:5e3}),{registerHandler:L,unregisterHandler:R}=o(),z=(0,b.useRef)(e);z.current=e;let B=(0,b.useRef)(I);B.current=I,(0,b.useEffect)(()=>(L(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==z.current||B.current())}),()=>R(`agent-jobs-pane`)),[L,R]);let V=(0,b.useCallback)(e=>{let t=e.clientX,n=O,r=window.innerWidth-S;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{k(Math.min(Math.max(n+(t-e.clientX),S),r))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a),window.removeEventListener(`pointercancel`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a),window.addEventListener(`pointercancel`,a)},[O]);return(0,x.jsxs)(`div`,{className:p(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,A&&`absolute inset-0 z-30 border-l-0`),style:A?void 0:{width:O,flexShrink:0},children:[(0,x.jsx)(`div`,{className:`relative flex items-center`,children:!A&&(0,x.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:V,className:`absolute left-0 top-0 h-full w-1.5 -translate-x-full cursor-col-resize select-none touch-none hover:bg-accent-primary/20`,title:t(`workspace.resizeJobs`)})}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,x.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,x.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,x.jsx)(`button`,{type:`button`,onClick:()=>j(e=>!e),"aria-label":t(A?`restore`:`maximize`),title:t(A?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:A?(0,x.jsx)(d,{className:`h-4 w-4`}):(0,x.jsx)(r,{className:`h-4 w-4`})}),(0,x.jsx)(`button`,{type:`button`,onClick:T,"aria-label":t(`workspace.closeJobs`),title:t(`workspace.closeJobs`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,x.jsx)(s,{className:`h-4 w-4`})})]})]}),(0,x.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:F?(0,x.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,x.jsx)(i,{className:`h-4 w-4 animate-spin`})}):P.length===0?(0,x.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,x.jsx)(u,{className:`h-6 w-6 opacity-40`}),(0,x.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,x.jsx)(`ul`,{className:`space-y-1`,children:P.map(e=>(0,x.jsx)(`li`,{children:(0,x.jsxs)(`button`,{type:`button`,onClick:()=>N(e.id),className:p(`flex w-full flex-col gap-1 rounded-lg border border-border/50 bg-surface/30 px-2.5 py-2 text-left transition-colors`,`hover:border-accent-primary/40 hover:bg-surface/60`),children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsx)(m,{variant:w[e.status]??`queued`,children:n(`statusLabel.${e.status in w?e.status:`queued`}`)}),e.status===`running`&&(0,x.jsx)(i,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,x.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:c(new Date(e.started_at),{addSuffix:!0,locale:l()})})]}),(0,x.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:y(e.command,D)})]})},e.id))})}),M&&(0,x.jsx)(v,{jobId:M,onClose:()=>N(null)})]})}export{T as AgentModeJobsPane};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./chunk-BNv3lrIs.js";import{$ as t,An as n,At as r,Bn as i,Cn as a,Ct as o,Dn as s,En as c,Fn as l,G as u,Gt as d,In as f,J as p,K as m,Kn as h,Ln as g,Mn as _,Nn as v,On as y,Ot as b,Pn as x,Pt as S,Q as C,Rn as w,Rt as T,Sn as E,Tn as D,Tt as O,X as k,Y as A,Yt as j,Z as M,Zt as ee,an as N,at as P,ct as F,dt as I,et as L,g as te,gn as R,jn as ne,k as z,kn as B,kt as V,lt as H,mn as re,mt as U,nt as W,on as ie,pn as ae,q as G,rn as oe,sn as se,un as ce,vn as le,vt as ue,wn as K,xn as q,yt as de,zt as J}from"./index-DnkfABxY.js";var fe=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`}]]),pe=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`}]]),Y=e(h(),1),X=a(),me=/^[a-z0-9][a-z0-9-]*$/;function Z({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:a,onCancel:o}){let{t:s}=w(`agents`),[c,l]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(r[0]??``);(0,Y.useEffect)(()=>{e&&(t===`edit`&&n?(l(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(l(``),f(r[0]??``)))},[e,t,n,r]);let h=c.split(`,`).map(e=>e.trim()).filter(Boolean),g=h.filter(e=>!me.test(e)),_=h.length>0&&g.length===0&&r.includes(d);return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||o()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsxs)(A,{children:[(0,X.jsx)(k,{children:s(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,X.jsx)(G,{children:s(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,X.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.tagsLabel`)}),(0,X.jsx)(te,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),placeholder:`frontend, ui`,"aria-label":s(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,X.jsx)(i,{t:s,i18nKey:`routingRule.tagsHint`,components:{code:(0,X.jsx)(`code`,{})}})}),g.length>0&&(0,X.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:s(`routingRule.invalidTags`,{count:g.length,tags:g.join(`, `)})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.routeToLabel`)}),(0,X.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),"aria-label":s(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:s(`routingRule.routeToHint`)})]})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`common:actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:()=>a(h,d),disabled:!_,children:s(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Q=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),he=[`sonnet`,`fable`,`opus`,`haiku`],ge=/^[a-z0-9][a-z0-9-]*$/;function _e({profile:e,onChange:t,footer:r,onValidityChange:a,onSoftWarningsChange:o}){let{t:u}=w(`agentstudio`),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let e=!1;return fetch(`${K()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||f(t.agents)}).catch(()=>{e||f([])}),()=>{e=!0}},[]);let S=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},C=new Set(e.agents.map(e=>e.id)),T=d.filter(e=>!C.has(e.id)),E=(0,Y.useMemo)(()=>{let t=[];for(let n of Q)e.agents.some(e=>e.id===n)||t.push(u(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(u(`profileEditor.validation.multipleDefaultRules`,{found:n.length})),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(u(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(u(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!ge.test(e));e.length>0&&t.push(u(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,u]),k=(0,Y.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]),A=(0,Y.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,Y.useEffect)(()=>{a&&a(E)},[E,a]),(0,Y.useEffect)(()=>{o&&o({agentsMissingRouting:k})},[k,o]);let j=e=>{S(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)}),m(!1)},M=t=>{let n=e.agents[t];Q.has(n.id)||S(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},ee=(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)}S(e=>{e.agents=a})},N=l(x(_,{activationConstraint:{distance:4}}),x(ne,{coordinateGetter:s})),F=e=>{let{active:t,over:n}=e;n&&ee(String(t.id),String(n.id))},I=(e,t)=>{S(n=>{n.agents[e].model=t})},L=(e,t)=>{S(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)},R=()=>{S(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`})})},z=e=>`default`in e&&e.default===!0,V=(e,t)=>{S(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},H=(e,t,n)=>{S(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},re=e=>{S(t=>{let n=t.routing[e];n&&(z(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];z(i)||z(a)||S(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,X.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,X.jsx)(Z,{open:h,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:L,onCancel:()=>g(!1)}),(0,X.jsx)(Z,{open:y!==null,mode:`edit`,initial:y!==null&&e.routing[y]&&!(`default`in e.routing[y])?{tags:e.routing[y].tags,agent:e.routing[y].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{y!==null&&(H(y,e,t),b(null))},onCancel:()=>b(null)}),E.length>0&&(0,X.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,X.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.validationSummary`,{count:E.length})}),(0,X.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,X.jsx)(`li`,{children:e},t))})]}),(0,X.jsxs)(`section`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.nameLabel`)}),(0,X.jsx)(te,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.descriptionLabel`)}),(0,X.jsx)(te,{value:e.description??``,onChange:e=>S(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:u(`profileEditor.descriptionPlaceholder`)})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:u(`profileEditor.orchestrator.heading`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:u(`profileEditor.orchestrator.description`)})]}),(0,X.jsx)(be,{value:e.orchestrator.model,onChange:e=>S(t=>{t.orchestrator.model=e})})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>m(e=>!e),disabled:T.length===0,title:T.length===0?u(`profileEditor.agentChain.addDisabledTitle`):u(`profileEditor.agentChain.addTitle`),children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`common:actions.add`)]})]}),p&&(0,X.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:u(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>m(!1),title:u(`common:actions.close`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]}),T.length===0?(0,X.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:u(`profileEditor.agentChain.emptyCatalog`)}):(0,X.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>j(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,X.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:u(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,X.jsx)(n,{sensors:N,collisionDetection:v,onDragEnd:F,children:(0,X.jsx)(D,{items:e.agents.map(e=>e.id),strategy:B,children:(0,X.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,X.jsx)(ve,{agent:e,canRemove:!Q.has(e.id),onModel:e=>I(t,e),onRemove:()=>M(t)},e.id))})})})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!A&&(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:R,disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addDefault`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>g(!0),disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addRule`)]})]})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:u(`profileEditor.routing.explainer`)}),k.length>0&&(0,X.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,X.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.routing.untargetedTitle`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(i,{t:u,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:k.join(`, `)},components:{mono:(0,X.jsx)(`span`,{className:`font-mono`})}})})]}),(0,X.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,X.jsx)(ye,{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=>V(n,e),onEdit:()=>b(n),onUp:()=>U(n,-1),onDown:()=>U(n,1),onRemove:()=>re(n)},n)})})]}),r&&(0,X.jsx)(`div`,{className:`pt-3 border-t border-border`,children:r})]})}function ve({agent:e,canRemove:t,onModel:n,onRemove:r}){let{t:i}=w(`agentstudio`),a=Q.has(e.id),o=e.id===`sr-architect`,s=e.id===`sr-merge-resolver`,{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:p,isDragging:m}=y({id:e.id});return(0,X.jsxs)(`div`,{ref:u,style:{transform:f.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,X.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:i(`profileEditor.agentRow.dragTitle`),"aria-label":i(`profileEditor.agentRow.dragHandleAria`),...c,...l,children:(0,X.jsx)(J,{className:`w-3.5 h-3.5`})}),(0,X.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),o&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:i(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,X.jsx)(b,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,i(`profileEditor.agentRow.pinnedFirst`)]}),s&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:i(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,X.jsx)(b,{className:`w-2.5 h-2.5 rotate-45`}),` `,i(`profileEditor.agentRow.pinnedLast`)]}),a&&!o&&!s&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:i(`profileEditor.agentRow.required`)}),(0,X.jsx)(be,{value:e.model??`sonnet`,onChange:n}),(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:r,disabled:!t,title:i(t?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]})}function ye({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{t:f}=w(`agentstudio`),p=`default`in e&&e.default===!0;return(0,X.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,X.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),p?(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:f(`profileEditor.routingRow.everythingElse`)}):(0,X.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),p?(0,X.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":f(`profileEditor.routingRow.defaultTargetAria`),title:f(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,X.jsx)(`select`,{value:e.agent,onChange:e=>s(e.target.value),"aria-label":f(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:c,title:f(`profileEditor.routingRow.editTitle`),"aria-label":f(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,X.jsx)(V,{className:`w-3 h-3`})}),r&&!n&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:f(`profileEditor.routingRow.moveDown`),children:(0,X.jsx)(re,{className:`w-3 h-3`})}),r&&t>1&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:f(`profileEditor.routingRow.moveUp`),children:(0,X.jsx)(ce,{className:`w-3 h-3`})}),i&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded`,onClick:d,title:f(`common:actions.remove`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]}),p&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:f(`profileEditor.routingRow.coreDefaultTitle`),children:f(`profileEditor.routingRow.coreDefaultBadge`)})]})}function be({value:e,onChange:t}){return(0,X.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:he.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})}function xe({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:s,onConfirm:c,onCancel:l}){let{t:d}=w(),[f,h]=(0,Y.useState)(i);(0,Y.useEffect)(()=>{e&&h(i)},[e,i]);let g=f.trim(),_=!o||o.test(g),v=g.length>0&&_;return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||l()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsx)(A,{children:(0,X.jsx)(k,{children:t})}),(0,X.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,X.jsx)(te,{autoFocus:!0,value:f,placeholder:r,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v&&c(g)},className:`text-sm font-mono`}),g.length>0&&!_&&s&&(0,X.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:s})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:l,children:d(`actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:()=>c(g),disabled:!v,children:a??d(`actions.confirm`)})]})]})})}function Se({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:s}=w();return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||o()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsx)(A,{children:(0,X.jsx)(k,{children:t})}),n&&(0,X.jsx)(`div`,{className:`py-2`,children:(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??s(`actions.confirm`)})]})]})})}function Ce(){let{t:e}=w(`agents`),[t,n]=(0,Y.useState)([]),[r,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(!0),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)([]),[_,v]=(0,Y.useState)([]),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(null),[C,T]=(0,Y.useState)(null),E=(0,Y.useCallback)(async()=>{l(!0),d(null);try{let t=await fetch(`${K()}/profiles`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let i=await t.json();n(i.profiles),i.profiles.length>0&&!r&&a(i.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[r]);(0,Y.useEffect)(()=>{E()},[E]),(0,Y.useEffect)(()=>{if(!r){s(null);return}let t=!1;return fetch(`${K()}/profiles/${encodeURIComponent(r)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||s(e.profile)}).catch(e=>{t||d(e.message)}),()=>{t=!0}},[r]);let D=(0,Y.useCallback)(async()=>{p(!0),d(null);try{let t=await fetch(`${K()}/profiles/migrate-from-settings`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await E(),a(`default`),g.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{p(!1)}},[E]),k=(0,Y.useCallback)(async t=>{b(!1),p(!0),d(null);try{let n={schemaVersion:1,name:t,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`}]},r=await fetch(`${K()}/profiles`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.createFailed`,{status:r.status}))}await E(),a(t),g.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.createFailed`),{description:n})}finally{p(!1)}},[E]),A=(0,Y.useCallback)(async(t,n)=>{S(null),p(!0),d(null);try{let r=await fetch(`${K()}/profiles/${encodeURIComponent(t)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await E(),a(n),g.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{p(!1)}},[E]),j=(0,Y.useCallback)(async t=>{T(null),p(!0),d(null);try{let n=await fetch(`${K()}/profiles/${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}a(e=>e===t?null:e),await E(),g.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{p(!1)}},[E]),M=(0,Y.useCallback)(()=>b(!0),[]),N=(0,Y.useCallback)(e=>S({from:e}),[]),P=(0,Y.useCallback)(e=>T({name:e}),[]),F=(0,Y.useCallback)(async(t,n)=>{p(!0),d(null);try{let r=await fetch(`${K()}/profiles/${encodeURIComponent(t.name)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}s(t),n.length>0?g.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):g.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{p(!1)}},[e]),I=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(xe,{open:y,title:e(`profiles.createDialog.title`),description:e(`profiles.createDialog.description`),placeholder:`my-profile`,confirmLabel:e(`profiles.createDialog.confirmLabel`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.createDialog.invalidHint`),onConfirm:e=>void k(e),onCancel:()=>b(!1)}),x&&(0,X.jsx)(xe,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:x.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${x.from}-copy`,initialValue:`${x.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void A(x.from,e),onCancel:()=>S(null)}),C&&(0,X.jsx)(Se,{open:!0,title:e(`profiles.deleteDialog.title`,{name:C.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void j(C.name),onCancel:()=>T(null)})]});return c?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,X.jsxs)(X.Fragment,{children:[I,(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:D,disabled:f,children:[(0,X.jsx)(pe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,X.jsx)(i,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,X.jsx)(`code`,{className:`text-foreground`})}})}),u&&(0,X.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:u})]})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[I,(0,X.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,X.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,X.jsx)(W,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:(0,X.jsx)(O,{className:`w-3.5 h-3.5`})})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,X.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(t.name===r?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>a(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&a(t.name)},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),N(t.name)},children:(0,X.jsx)(ee,{className:`w-3 h-3`})}),!t.isDefault&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 aurora-light:text-destructive rounded`,title:e(`common:actions.delete`),onClick:e=>{e.stopPropagation(),P(t.name)},children:(0,X.jsx)(H,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,X.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,X.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:u}),o?(0,X.jsx)(_e,{profile:o,onChange:s,onValidityChange:h,onSoftWarningsChange:e=>v(e.agentsMissingRouting),footer:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:()=>void F(o,_),disabled:f||m.length>0,title:m.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,X.jsx)(de,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),f&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),m.length>0&&(0,X.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:m.length})})]})},o.name):(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function $(e){let t=e.workflow.map((e,t)=>`${t+1}. ${e}`).join(`
1
+ import{a as e}from"./chunk-BNv3lrIs.js";import{$ as t,An as n,At as r,Bn as i,Cn as a,Ct as o,Dn as s,En as c,Fn as l,G as u,Gt as d,In as f,J as p,K as m,Kn as h,Ln as g,Mn as _,Nn as v,On as y,Ot as b,Pn as x,Pt as S,Q as C,Rn as w,Rt as T,Sn as E,Tn as D,Tt as O,X as k,Y as A,Yt as j,Z as M,Zt as ee,an as N,at as P,ct as F,dt as I,et as L,gn as R,h as z,jn as te,k as B,kn as V,kt as ne,lt as H,mn as re,mt as U,nt as W,on as ie,pn as ae,q as G,rn as oe,sn as se,un as ce,vn as le,vt as ue,wn as K,xn as q,yt as de,zt as J}from"./index-Dw1N2-ci.js";var fe=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`}]]),pe=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`}]]),Y=e(h(),1),X=a(),me=/^[a-z0-9][a-z0-9-]*$/;function Z({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:a,onCancel:o}){let{t:s}=w(`agents`),[c,l]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(r[0]??``);(0,Y.useEffect)(()=>{e&&(t===`edit`&&n?(l(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(l(``),f(r[0]??``)))},[e,t,n,r]);let h=c.split(`,`).map(e=>e.trim()).filter(Boolean),g=h.filter(e=>!me.test(e)),_=h.length>0&&g.length===0&&r.includes(d);return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||o()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsxs)(A,{children:[(0,X.jsx)(k,{children:s(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,X.jsx)(G,{children:s(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,X.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.tagsLabel`)}),(0,X.jsx)(z,{autoFocus:!0,value:c,onChange:e=>l(e.target.value),placeholder:`frontend, ui`,"aria-label":s(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,X.jsx)(i,{t:s,i18nKey:`routingRule.tagsHint`,components:{code:(0,X.jsx)(`code`,{})}})}),g.length>0&&(0,X.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:s(`routingRule.invalidTags`,{count:g.length,tags:g.join(`, `)})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:s(`routingRule.routeToLabel`)}),(0,X.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),"aria-label":s(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:s(`routingRule.routeToHint`)})]})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`common:actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:()=>a(h,d),disabled:!_,children:s(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Q=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),he=[`sonnet`,`fable`,`opus`,`haiku`],ge=/^[a-z0-9][a-z0-9-]*$/;function _e({profile:e,onChange:t,footer:r,onValidityChange:a,onSoftWarningsChange:o}){let{t:u}=w(`agentstudio`),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{let e=!1;return fetch(`${K()}/profiles/catalog`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||f(t.agents)}).catch(()=>{e||f([])}),()=>{e=!0}},[]);let S=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},C=new Set(e.agents.map(e=>e.id)),T=d.filter(e=>!C.has(e.id)),E=(0,Y.useMemo)(()=>{let t=[];for(let n of Q)e.agents.some(e=>e.id===n)||t.push(u(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(u(`profileEditor.validation.multipleDefaultRules`,{found:n.length})),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(u(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(u(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!ge.test(e));e.length>0&&t.push(u(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,u]),k=(0,Y.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]),A=(0,Y.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,Y.useEffect)(()=>{a&&a(E)},[E,a]),(0,Y.useEffect)(()=>{o&&o({agentsMissingRouting:k})},[k,o]);let j=e=>{S(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)}),m(!1)},M=t=>{let n=e.agents[t];Q.has(n.id)||S(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},ee=(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)}S(e=>{e.agents=a})},N=l(x(_,{activationConstraint:{distance:4}}),x(te,{coordinateGetter:s})),F=e=>{let{active:t,over:n}=e;n&&ee(String(t.id),String(n.id))},I=(e,t)=>{S(n=>{n.agents[e].model=t})},L=(e,t)=>{S(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)},R=()=>{S(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`})})},B=e=>`default`in e&&e.default===!0,ne=(e,t)=>{S(n=>{let r=n.routing[e];r&&(B(r)||(r.agent=t))})},H=(e,t,n)=>{S(r=>{let i=r.routing[e];i&&(B(i)||(i.tags=t,i.agent=n))})},re=e=>{S(t=>{let n=t.routing[e];n&&(B(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];B(i)||B(a)||S(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,X.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,X.jsx)(Z,{open:h,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:L,onCancel:()=>g(!1)}),(0,X.jsx)(Z,{open:y!==null,mode:`edit`,initial:y!==null&&e.routing[y]&&!(`default`in e.routing[y])?{tags:e.routing[y].tags,agent:e.routing[y].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{y!==null&&(H(y,e,t),b(null))},onCancel:()=>b(null)}),E.length>0&&(0,X.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,X.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.validationSummary`,{count:E.length})}),(0,X.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,X.jsx)(`li`,{children:e},t))})]}),(0,X.jsxs)(`section`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.nameLabel`)}),(0,X.jsx)(z,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:u(`profileEditor.descriptionLabel`)}),(0,X.jsx)(z,{value:e.description??``,onChange:e=>S(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:u(`profileEditor.descriptionPlaceholder`)})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:u(`profileEditor.orchestrator.heading`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:`/specrails:implement · /specrails:batch-implement`}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:u(`profileEditor.orchestrator.description`)})]}),(0,X.jsx)(be,{value:e.orchestrator.model,onChange:e=>S(t=>{t.orchestrator.model=e})})]})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>m(e=>!e),disabled:T.length===0,title:T.length===0?u(`profileEditor.agentChain.addDisabledTitle`):u(`profileEditor.agentChain.addTitle`),children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`common:actions.add`)]})]}),p&&(0,X.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:u(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>m(!1),title:u(`common:actions.close`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]}),T.length===0?(0,X.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:u(`profileEditor.agentChain.emptyCatalog`)}):(0,X.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>j(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,X.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:u(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,X.jsx)(n,{sensors:N,collisionDetection:v,onDragEnd:F,children:(0,X.jsx)(D,{items:e.agents.map(e=>e.id),strategy:V,children:(0,X.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,X.jsx)(ve,{agent:e,canRemove:!Q.has(e.id),onModel:e=>I(t,e),onRemove:()=>M(t)},e.id))})})})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,X.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:u(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!A&&(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:R,disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addDefault`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>g(!0),disabled:e.agents.length===0,title:e.agents.length===0?u(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1`}),` `,u(`profileEditor.routing.addRule`)]})]})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:u(`profileEditor.routing.explainer`)}),k.length>0&&(0,X.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,X.jsx)(`div`,{className:`font-medium mb-1`,children:u(`profileEditor.routing.untargetedTitle`)}),(0,X.jsx)(`div`,{children:(0,X.jsx)(i,{t:u,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:k.join(`, `)},components:{mono:(0,X.jsx)(`span`,{className:`font-mono`})}})})]}),(0,X.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,X.jsx)(ye,{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=>ne(n,e),onEdit:()=>b(n),onUp:()=>U(n,-1),onDown:()=>U(n,1),onRemove:()=>re(n)},n)})})]}),r&&(0,X.jsx)(`div`,{className:`pt-3 border-t border-border`,children:r})]})}function ve({agent:e,canRemove:t,onModel:n,onRemove:r}){let{t:i}=w(`agentstudio`),a=Q.has(e.id),o=e.id===`sr-architect`,s=e.id===`sr-merge-resolver`,{attributes:c,listeners:l,setNodeRef:u,transform:d,transition:p,isDragging:m}=y({id:e.id});return(0,X.jsxs)(`div`,{ref:u,style:{transform:f.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,X.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:i(`profileEditor.agentRow.dragTitle`),"aria-label":i(`profileEditor.agentRow.dragHandleAria`),...c,...l,children:(0,X.jsx)(J,{className:`w-3.5 h-3.5`})}),(0,X.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),o&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:i(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,X.jsx)(b,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,i(`profileEditor.agentRow.pinnedFirst`)]}),s&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:i(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,X.jsx)(b,{className:`w-2.5 h-2.5 rotate-45`}),` `,i(`profileEditor.agentRow.pinnedLast`)]}),a&&!o&&!s&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:i(`profileEditor.agentRow.required`)}),(0,X.jsx)(be,{value:e.model??`sonnet`,onChange:n}),(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:r,disabled:!t,title:i(t?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]})}function ye({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{t:f}=w(`agentstudio`),p=`default`in e&&e.default===!0;return(0,X.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,X.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),p?(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:f(`profileEditor.routingRow.everythingElse`)}):(0,X.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),p?(0,X.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":f(`profileEditor.routingRow.defaultTargetAria`),title:f(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,X.jsx)(`select`,{value:e.agent,onChange:e=>s(e.target.value),"aria-label":f(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:c,title:f(`profileEditor.routingRow.editTitle`),"aria-label":f(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,X.jsx)(ne,{className:`w-3 h-3`})}),r&&!n&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:f(`profileEditor.routingRow.moveDown`),children:(0,X.jsx)(re,{className:`w-3 h-3`})}),r&&t>1&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:f(`profileEditor.routingRow.moveUp`),children:(0,X.jsx)(ce,{className:`w-3 h-3`})}),i&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded`,onClick:d,title:f(`common:actions.remove`),children:(0,X.jsx)(P,{className:`w-3 h-3`})})]}),p&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:f(`profileEditor.routingRow.coreDefaultTitle`),children:f(`profileEditor.routingRow.coreDefaultBadge`)})]})}function be({value:e,onChange:t}){return(0,X.jsx)(`select`,{value:e,onChange:e=>t(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:he.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))})}function xe({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:s,onConfirm:c,onCancel:l}){let{t:d}=w(),[f,h]=(0,Y.useState)(i);(0,Y.useEffect)(()=>{e&&h(i)},[e,i]);let g=f.trim(),_=!o||o.test(g),v=g.length>0&&_;return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||l()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsx)(A,{children:(0,X.jsx)(k,{children:t})}),(0,X.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,X.jsx)(z,{autoFocus:!0,value:f,placeholder:r,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&v&&c(g)},className:`text-sm font-mono`}),g.length>0&&!_&&s&&(0,X.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:s})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:l,children:d(`actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:()=>c(g),disabled:!v,children:a??d(`actions.confirm`)})]})]})})}function Se({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:s}=w();return(0,X.jsx)(u,{open:e,onOpenChange:e=>{e||o()},children:(0,X.jsxs)(m,{movableResizable:!0,className:`max-w-md`,children:[(0,X.jsx)(A,{children:(0,X.jsx)(k,{children:t})}),n&&(0,X.jsx)(`div`,{className:`py-2`,children:(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:o,children:s(`actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??s(`actions.confirm`)})]})]})})}function Ce(){let{t:e}=w(`agents`),[t,n]=(0,Y.useState)([]),[r,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(!0),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)([]),[_,v]=(0,Y.useState)([]),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(null),[C,T]=(0,Y.useState)(null),E=(0,Y.useCallback)(async()=>{l(!0),d(null);try{let t=await fetch(`${K()}/profiles`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let i=await t.json();n(i.profiles),i.profiles.length>0&&!r&&a(i.profiles[0].name)}catch(e){d(e.message)}finally{l(!1)}},[r]);(0,Y.useEffect)(()=>{E()},[E]),(0,Y.useEffect)(()=>{if(!r){s(null);return}let t=!1;return fetch(`${K()}/profiles/${encodeURIComponent(r)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||s(e.profile)}).catch(e=>{t||d(e.message)}),()=>{t=!0}},[r]);let D=(0,Y.useCallback)(async()=>{p(!0),d(null);try{let t=await fetch(`${K()}/profiles/migrate-from-settings`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await E(),a(`default`),g.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{p(!1)}},[E]),k=(0,Y.useCallback)(async t=>{b(!1),p(!0),d(null);try{let n={schemaVersion:1,name:t,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`}]},r=await fetch(`${K()}/profiles`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.createFailed`,{status:r.status}))}await E(),a(t),g.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.createFailed`),{description:n})}finally{p(!1)}},[E]),A=(0,Y.useCallback)(async(t,n)=>{S(null),p(!0),d(null);try{let r=await fetch(`${K()}/profiles/${encodeURIComponent(t)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await E(),a(n),g.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{p(!1)}},[E]),j=(0,Y.useCallback)(async t=>{T(null),p(!0),d(null);try{let n=await fetch(`${K()}/profiles/${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}a(e=>e===t?null:e),await E(),g.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{p(!1)}},[E]),M=(0,Y.useCallback)(()=>b(!0),[]),N=(0,Y.useCallback)(e=>S({from:e}),[]),P=(0,Y.useCallback)(e=>T({name:e}),[]),F=(0,Y.useCallback)(async(t,n)=>{p(!0),d(null);try{let r=await fetch(`${K()}/profiles/${encodeURIComponent(t.name)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}s(t),n.length>0?g.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):g.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;d(n),g.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{p(!1)}},[e]),I=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(xe,{open:y,title:e(`profiles.createDialog.title`),description:e(`profiles.createDialog.description`),placeholder:`my-profile`,confirmLabel:e(`profiles.createDialog.confirmLabel`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.createDialog.invalidHint`),onConfirm:e=>void k(e),onCancel:()=>b(!1)}),x&&(0,X.jsx)(xe,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:x.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${x.from}-copy`,initialValue:`${x.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void A(x.from,e),onCancel:()=>S(null)}),C&&(0,X.jsx)(Se,{open:!0,title:e(`profiles.deleteDialog.title`,{name:C.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void j(C.name),onCancel:()=>T(null)})]});return c?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,X.jsxs)(X.Fragment,{children:[I,(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:D,disabled:f,children:[(0,X.jsx)(pe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,X.jsx)(i,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,X.jsx)(`code`,{className:`text-foreground`})}})}),u&&(0,X.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:u})]})})]}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[I,(0,X.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,X.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`p-3 flex items-center justify-between`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,X.jsx)(W,{size:`sm`,variant:`ghost`,onClick:M,disabled:f,children:(0,X.jsx)(O,{className:`w-3.5 h-3.5`})})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,X.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(t.name===r?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>a(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&a(t.name)},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,X.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),N(t.name)},children:(0,X.jsx)(ee,{className:`w-3 h-3`})}),!t.isDefault&&(0,X.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 aurora-light:text-destructive rounded`,title:e(`common:actions.delete`),onClick:e=>{e.stopPropagation(),P(t.name)},children:(0,X.jsx)(H,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,X.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[u&&(0,X.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:u}),o?(0,X.jsx)(_e,{profile:o,onChange:s,onValidityChange:h,onSoftWarningsChange:e=>v(e.agentsMissingRouting),footer:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:()=>void F(o,_),disabled:f||m.length>0,title:m.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,X.jsx)(de,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),f&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),m.length>0&&(0,X.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:m.length})})]})},o.name):(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function $(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,11 +76,11 @@ You are ...
76
76
  - **risk_tolerance**: conservative
77
77
  - **detail_level**: full
78
78
  - **focus_areas**: ...
79
- `;function Oe({agentId:e,initialBody:t,initialName:n,draftFromRefine:r,onClose:a,onSaved:o,onResumeRefine:s}){let{t:c}=w(`agentstudio`),l=!e,[u,d]=(0,Y.useState)(e??n??``),[f,p]=(0,Y.useState)(t??De),[m,h]=(0,Y.useState)(!l&&!t&&!r),[_,v]=(0,Y.useState)(!!r&&!l),[y,b]=(0,Y.useState)(!1),[x,C]=(0,Y.useState)(null),[E,D]=(0,Y.useState)([]),[O,k]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(!!t&&l),[M,ee]=(0,Y.useState)(!1),[N,P]=(0,Y.useState)(``),[F,I]=(0,Y.useState)(!1),[L,R]=(0,Y.useState)(null),[ne,z]=(0,Y.useState)(null),[B,V]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(l||t!==void 0)return;if(r){let t=!1;return fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}/refine/${r}`).then(e=>{if(!e.ok)throw Error(c(`studio.errors.loadDraftFailed`,{status:e.status}));return e.json()}).then(e=>{!t&&e.draftBody&&(p(e.draftBody),j(!0))}).catch(e=>{t||C(e.message)}).finally(()=>{t||v(!1)}),()=>{t=!0}}let n=!1;return fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}`).then(e=>{if(!e.ok)throw Error(c(`studio.errors.loadFailed`,{status:e.status}));return e.json()}).then(e=>{n||p(e.body)}).catch(e=>{n||C(e.message)}).finally(()=>{n||h(!1)}),()=>{n=!0}},[e,l,t,r]);let re=(0,Y.useCallback)(()=>{l||fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}/versions`).then(e=>e.ok?e.json():{versions:[]}).then(e=>D(e.versions)).catch(()=>D([]))},[e,l]);(0,Y.useEffect)(()=>{O&&re()},[O,re]);let U=/^custom-[a-z0-9][a-z0-9-]*$/.test(u),ie=f.trim().length>0,G=/^---\s*\n[\s\S]*?\n---/.test(f),se=ie&&G&&(l?U:!0)&&A,ce=(0,Y.useCallback)(async()=>{b(!0),C(null);try{let t;if(t=l?await fetch(`${K()}/profiles/catalog`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:u,body:f})}):await fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:f})}),!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??c(`studio.errors.saveFailed`,{status:t.status}))}j(!1),g.success(c(l?`studio.toasts.agentCreated`:`studio.toasts.agentSaved`),{description:l?u:e}),o&&o(l?u:e)}catch(e){let t=e.message;C(t),g.error(c(l?`studio.toasts.createFailed`:`studio.toasts.saveFailed`),{description:t})}finally{b(!1)}},[e,f,u,l,o,c]),le=(0,Y.useCallback)(async()=>{if(!l){V(!1),b(!0),C(null);try{let t=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??c(`studio.errors.deleteFailed`,{status:t.status}))}g.success(c(`studio.toasts.agentDeleted`),{description:e}),o&&o(e),a()}catch(e){let t=e.message;C(t),g.error(c(`studio.toasts.deleteFailed`),{description:t})}finally{b(!1)}}},[e,l,a,o,c]),ue=(0,Y.useCallback)(e=>{p(e.body),j(!0),k(!1)},[]),q=(0,Y.useCallback)(async()=>{I(!0),z(null),R(null);try{let t=await fetch(`${K()}/profiles/catalog/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:l?u||`draft`:e,draftBody:f,sampleTask:N})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??c(`studio.errors.testFailed`,{status:t.status}))}R(await t.json())}catch(e){z(e.message)}finally{I(!1)}},[e,f,u,l,N,c]);return m?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`studio.loadingAgent`)})}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!l&&(0,X.jsx)(Se,{open:B,title:c(`studio.deleteConfirm.title`,{agentId:e}),description:c(`studio.deleteConfirm.description`),confirmLabel:c(`common:actions.delete`),destructive:!0,onConfirm:le,onCancel:()=>V(!1)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 border-b border-border`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground`,title:c(`common:actions.back`),children:(0,X.jsx)(ae,{className:`w-4 h-4`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground uppercase tracking-wide`,children:c(l?`studio.modeCreate`:`studio.modeEdit`)}),l?(0,X.jsx)(te,{value:u,onChange:e=>{d(e.target.value),j(!0)},placeholder:`custom-my-agent`,className:`text-sm font-mono mt-1 max-w-sm`}):(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`text-sm font-mono`,children:e}),r&&(0,X.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!s||!e))try{let t=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}`);if(!t.ok)return;s(r,e,(await t.json()).body)}catch{}},className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full border border-accent-primary/40 bg-accent-primary/15 text-accent-primary hover:bg-accent-primary/25 focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,title:c(`studio.resumeAiEditTitle`),children:[(0,X.jsx)(pe,{className:`w-3 h-3`}),` `,c(`studio.resumeAiEdit`)]}),_&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(S,{className:`w-3 h-3 animate-spin`}),` `,c(`studio.loadingAiDraft`)]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>{ee(e=>!e),M||k(!1)},title:c(`studio.testButtonTitle`),children:[(0,X.jsx)(fe,{className:`w-3.5 h-3.5 mr-1`}),c(`studio.testButton`)]}),!l&&(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>{k(e=>!e),O||ee(!1)},title:c(`studio.historyButtonTitle`),children:[(0,X.jsx)(T,{className:`w-3.5 h-3.5 mr-1`}),c(`studio.historyButton`)]}),!l&&(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>V(!0),disabled:y,className:`text-red-400 hover:text-red-300 aurora-light:text-destructive aurora-light:hover:text-destructive`,children:[(0,X.jsx)(H,{className:`w-3.5 h-3.5 mr-1`}),c(`common:actions.delete`)]}),(0,X.jsxs)(W,{size:`sm`,onClick:ce,disabled:!se||y,children:[(0,X.jsx)(de,{className:`w-3.5 h-3.5 mr-1`}),c(y?`common:states.saving`:l?`studio.create`:`common:actions.save`)]})]})]}),x&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 text-xs border-b border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:[(0,X.jsx)(oe,{className:`w-3.5 h-3.5 flex-shrink-0`}),x]}),l&&u.length>0&&!U&&(0,X.jsx)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:(0,X.jsx)(i,{t:c,i18nKey:`studio.validation.namePattern`,components:{code:(0,X.jsx)(`code`,{})}})}),!G&&(0,X.jsx)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:(0,X.jsx)(i,{t:c,i18nKey:`studio.validation.missingFrontmatter`,components:{code:(0,X.jsx)(`code`,{})}})}),(0,X.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:[(0,X.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,X.jsxs)(`span`,{children:[`.claude/agents/`,l?u||`custom-…`:e,`.md`]}),A&&(0,X.jsx)(`span`,{className:`text-yellow-500 aurora-light:text-accent-warning`,children:c(`studio.unsaved`)})]}),(0,X.jsx)(`textarea`,{value:f,onChange:e=>{p(e.target.value),j(!0)},spellCheck:!1,className:`flex-1 w-full p-4 text-xs font-mono bg-background text-foreground outline-none resize-none leading-relaxed`})]}),M&&(0,X.jsxs)(`aside`,{className:`w-96 flex-shrink-0 border-l border-border flex flex-col min-h-0`,children:[(0,X.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,X.jsx)(fe,{className:`w-3.5 h-3.5`}),` `,c(`studio.testPane.header`)]}),(0,X.jsxs)(`div`,{className:`p-3 border-b border-border`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,X.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,children:c(`studio.testPane.sampleTaskLabel`)}),(0,X.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&&P(Ee[t].prompt)},disabled:F,children:Ee.map((e,t)=>(0,X.jsx)(`option`,{value:t,children:c(e.labelKey)},t))})]}),(0,X.jsx)(`textarea`,{value:N,onChange:e=>P(e.target.value),placeholder:c(`studio.testPane.placeholder`),className:`w-full text-xs p-2 rounded border border-border bg-background min-h-[80px] resize-y font-mono`,disabled:F}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,X.jsx)(W,{size:`sm`,onClick:q,disabled:F||!N.trim()||!f.trim(),children:F?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,c(`studio.testPane.running`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,c(`studio.testPane.run`)]})}),(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:c(`studio.testPane.sandboxNote`)})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 min-h-0`,children:[ne&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive mb-2`,children:ne}),L&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground mb-2`,children:[(0,X.jsx)(`span`,{children:(0,X.jsx)(i,{t:c,i18nKey:`studio.testPane.tokens`,count:L.tokens,components:{mono:(0,X.jsx)(`span`,{className:`text-foreground font-mono`})}})}),(0,X.jsx)(`span`,{children:(0,X.jsxs)(`span`,{className:`text-foreground font-mono`,children:[(L.durationMs/1e3).toFixed(1),`s`]})})]}),(0,X.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed rounded border border-border bg-background p-3`,children:L.output})]}),!F&&!L&&!ne&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic`,children:c(`studio.testPane.emptyHint`)})]})]}),O&&!l&&(0,X.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-l border-border flex flex-col`,children:[(0,X.jsx)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:c(`studio.versions.header`)}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:E.length===0?(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic px-2 py-2`,children:c(`studio.versions.empty`)}):E.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>ue(e),className:`w-full text-left px-2 py-1.5 rounded hover:bg-accent/50 transition-colors`,children:[(0,X.jsxs)(`div`,{className:`text-xs font-mono text-foreground`,children:[`v`,e.version]}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.version))}),(0,X.jsx)(`div`,{className:`px-3 py-2 border-t border-border text-[11px] text-muted-foreground`,children:c(`studio.versions.restoreHint`)})]})]})]})}var ke={refineId:null,agentId:null,uiState:`closed`,phase:`idle`,history:[],streamingText:``,draftBody:null,baseBody:null,autoTest:!1,testResult:null,appliedVersion:null,errorMessage:null,applyConflict:null};function Ae(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function je(e,t){switch(t.type){case`OPEN`:return{...ke,agentId:t.agentId,baseBody:t.baseBody,uiState:`composing`};case`START_TURN`:return{...e,refineId:t.refineId,uiState:`streaming`,phase:`reading`,streamingText:``,errorMessage:null,applyConflict:null,history:[...e.history,t.userTurn]};case`STREAM_DELTA`:return e.refineId===t.refineId?{...e,streamingText:e.streamingText+t.delta}:e;case`PHASE`:return e.refineId===t.refineId?{...e,phase:t.phase}:e;case`READY`:return e.refineId===t.refineId?{...e,uiState:`reviewing`,phase:`done`,draftBody:t.draftBody,streamingText:``,history:[...e.history,{role:`assistant`,content:Ae(t.draftBody),timestamp:Date.now()}]}:e;case`TEST_RESULT`:return e.refineId===t.refineId?{...e,testResult:t.result,history:[...e.history,{role:`system`,kind:`test_result`,content:t.result.output,timestamp:Date.now()}]}:e;case`APPLIED`:return e.refineId===t.refineId?{...e,uiState:`applied`,appliedVersion:t.version}:e;case`CANCELLED`:return{...e,uiState:`cancelled`};case`ERROR`:return t.refineId!==null&&e.refineId!==t.refineId?e:{...e,uiState:`error`,errorMessage:t.message};case`CONFLICT`:return e.refineId===t.refineId?{...e,applyConflict:t.reason}:e;case`TOGGLE_AUTO_TEST`:return{...e,autoTest:t.enabled};case`REHYDRATE`:return{...e,...t.payload};case`CLOSE`:return ke;default:return e}}function Me(e){switch(e.status){case`streaming`:return`streaming`;case`ready`:return`reviewing`;case`applied`:return`applied`;case`cancelled`:return`cancelled`;case`error`:return`error`;default:return e.draftBody?`reviewing`:`composing`}}function Ne(e){let[t,n]=(0,Y.useReducer)(je,ke),{t:r}=w(`aiedit`),{registerHandler:i,unregisterHandler:a}=E(),o=(0,Y.useRef)(null);o.current=t.refineId;let s=(0,Y.useRef)(null);s.current=t.agentId;let c=(0,Y.useRef)(e);c.current=e;let l=(0,Y.useRef)(e);(0,Y.useEffect)(()=>{e!==l.current&&(l.current=e,n({type:`CLOSE`}))},[e]),(0,Y.useEffect)(()=>{let e=`agent-refine-${Math.random().toString(36).slice(2,9)}`;return i(e,e=>{let t=e;if(typeof t.type!=`string`||t.projectId!==c.current||t.refineId!==o.current)return;let r=t.refineId;switch(t.type){case`agent_refine_stream`:n({type:`STREAM_DELTA`,refineId:r,delta:t.delta});break;case`agent_refine_phase`:n({type:`PHASE`,refineId:r,phase:t.phase});break;case`agent_refine_ready`:n({type:`READY`,refineId:r,draftBody:t.draftBody});break;case`agent_refine_test`:n({type:`TEST_RESULT`,refineId:r,result:t.result});break;case`agent_refine_applied`:n({type:`APPLIED`,refineId:r,version:t.version});break;case`agent_refine_cancelled`:n({type:`CANCELLED`,refineId:r});break;case`agent_refine_error`:n({type:`ERROR`,refineId:r,message:t.error});break}}),()=>a(e)},[i,a]);let u=(0,Y.useCallback)((e,t)=>{n({type:`OPEN`,agentId:e,baseBody:t})},[]),d=(0,Y.useCallback)(()=>{n({type:`CLOSE`})},[]);return{state:t,open:u,start:(0,Y.useCallback)(async e=>{let i=s.current;if(i)try{let a=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(i)}/refine`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e,autoTest:t.autoTest})});if(!a.ok){n({type:`ERROR`,refineId:null,message:(await a.json().catch(()=>({}))).error??r(`refine.serverError`,{status:a.status})});return}let s=await a.json();o.current=s.refineId,n({type:`START_TURN`,refineId:s.refineId,userTurn:{role:`user`,content:e,timestamp:Date.now()}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.connectionFailed`,{message:e.message})})}},[t.autoTest,r]),sendTurn:(0,Y.useCallback)(async e=>{let t=o.current,i=s.current;if(!(!t||!i)){n({type:`START_TURN`,refineId:t,userTurn:{role:`user`,content:e,timestamp:Date.now()}});try{let a=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/turn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e})});a.ok||n({type:`ERROR`,refineId:t,message:(await a.json().catch(()=>({}))).error??r(`refine.serverError`,{status:a.status})})}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}}},[r]),cancel:(0,Y.useCallback)(async()=>{let e=o.current,t=s.current;if(!(!e||!t))try{await fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`,{method:`DELETE`})}catch{}},[]),apply:(0,Y.useCallback)(async e=>{let t=o.current,i=s.current;if(!(!t||!i))try{let a=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/apply`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({force:!!e})});if(a.status===409){let e=await a.json().catch(()=>({}));if(e.reason===`disk_changed`||e.reason===`name_changed`){n({type:`CONFLICT`,refineId:t,reason:e.reason});return}}if(!a.ok){n({type:`ERROR`,refineId:t,message:(await a.json().catch(()=>({}))).error??r(`refine.applyFailed`,{status:a.status})});return}n({type:`APPLIED`,refineId:t,version:(await a.json()).version})}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}},[r]),toggleAutoTest:(0,Y.useCallback)(async e=>{let t=o.current,r=s.current;if(n({type:`TOGGLE_AUTO_TEST`,enabled:e}),!(!t||!r))try{await fetch(`${K()}/profiles/catalog/${encodeURIComponent(r)}/refine/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({autoTest:e})})}catch{}},[]),rehydrate:(0,Y.useCallback)(async(e,t)=>{try{let i=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}`);if(!i.ok)throw Error(r(`refine.loadAgentFailed`,{status:i.status}));let a=await i.json(),c=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`);if(!c.ok)throw Error(r(`refine.loadSessionFailed`,{status:c.status}));let l=await c.json();o.current=e,s.current=t,n({type:`REHYDRATE`,payload:{refineId:e,agentId:t,baseBody:a.body,draftBody:l.draftBody,history:l.history,autoTest:l.autoTest,phase:l.phase,uiState:Me(l),streamingText:``}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.rehydrateFailed`,{message:e.message})})}},[r]),close:d}}function Pe(){return typeof window>`u`||!(`__TAURI_INTERNALS__`in window)?!1:/mac/i.test(navigator.platform)}function Fe(e){let[t,n]=(0,Y.useState)(!1),r=(0,Y.useRef)(null),{panelRef:i,panelStyle:a,headerHandleProps:o,resizeHandles:s,isFloating:c}=C();(0,Y.useEffect)(()=>(r.current=document.activeElement,()=>{let e=r.current;e&&e instanceof HTMLElement&&e.focus()}),[]);let l=(0,Y.useCallback)(()=>{e.uiPhase===`streaming`||e.uiPhase===`reviewing`?n(!0):e.onClose()},[e]),u=(0,Y.useCallback)(()=>{n(!1),e.onDiscard()},[e]);(0,Y.useEffect)(()=>{let t=t=>{if(t.key===`Escape`){t.preventDefault(),l();return}if((t.metaKey||t.ctrlKey)&&t.key===`Enter`&&e.uiPhase===`reviewing`&&e.canApply&&!e.applyConflict){t.preventDefault(),e.onApply();return}e.onKeyDown?.(t)};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,l]);let d=e.uiPhase===`composing`||e.uiPhase===`streaming`||e.uiPhase===`error`,f=e.uiPhase===`reviewing`||e.uiPhase===`applied`;return(0,X.jsxs)(`div`,{className:`fixed inset-0 z-50 flex p-3 pt-10 sm:p-6 sm:pt-12 bg-black/40 backdrop-blur-sm animate-in fade-in duration-150`,"data-testid":`ai-edit-backdrop`,children:[(0,X.jsxs)(`div`,{ref:i,role:`dialog`,"aria-modal":`true`,"aria-label":`${e.eyebrow} · ${e.targetLabel}`,className:`m-auto w-full h-full max-w-[1600px] flex flex-col bg-background rounded-xl border border-border/40 shadow-2xl overflow-hidden`,style:a,children:[(0,X.jsx)(Ie,{eyebrow:e.eyebrow,targetLabel:e.targetLabel,targetLabelMono:e.targetLabelMono??!0,showApply:e.uiPhase===`reviewing`&&e.canApply&&!e.applyConflict,showDiscard:e.uiPhase!==`applied`,onApply:e.onApply,onDiscard:l,onMinimize:e.onMinimize,headerHandleProps:o,isFloating:c}),d&&(0,X.jsx)(Le,{uiPhase:e.uiPhase,headline:e.uiPhase===`streaming`?e.streamingHeadline:e.headline,description:e.description,chips:e.chips,onChipSubmit:e.onChipSubmit,streamingText:e.streamingText,composer:e.composer,composerAccessory:e.composerAccessory,history:e.history??[],baseBody:e.baseBody,baseBodyDisclosureLabel:e.baseBodyDisclosureLabel,errorMessage:e.errorMessage}),f&&(0,X.jsx)(He,{state:e,appliedNotice:e.appliedNotice}),t&&(0,X.jsx)(Je,{onCancel:()=>n(!1),onConfirm:u})]}),(0,X.jsx)(M,{handles:s})]})}function Ie({eyebrow:e,targetLabel:t,targetLabelMono:n,showApply:i,showDiscard:a,onApply:o,onDiscard:s,onMinimize:c,headerHandleProps:l,isFloating:u}){let{t:d}=w(`aiedit`),f=Pe()?`pl-[88px]`:`pl-4`;return(0,X.jsxs)(`div`,{...l,className:`flex-shrink-0 flex items-center justify-between ${f} pr-4 h-14 border-b border-border bg-card/60 backdrop-blur-sm${u?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:s,className:`flex items-center gap-2 group p-1 -ml-1 rounded hover:bg-accent focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none max-w-[60vw]`,"aria-label":d(`shell.backAriaLabel`),children:[(0,X.jsx)(ae,{className:`w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/70 leading-none`,children:e}),n?(0,X.jsx)(`code`,{className:`text-sm font-mono font-medium text-foreground truncate block`,children:t}):(0,X.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate block`,children:t})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:c,"aria-label":d(`common:actions.minimize`),"data-testid":`ai-edit-minimize`,children:(0,X.jsx)(r,{className:`w-4 h-4`})}),a&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:s,children:d(`common:actions.discard`)}),i&&(0,X.jsxs)(W,{size:`sm`,onClick:o,className:`gap-1.5`,children:[(0,X.jsx)(se,{className:`w-3.5 h-3.5`}),` `,d(`shell.apply`),(0,X.jsx)(`span`,{className:`text-[10px] opacity-70 ml-1`,children:`⌘⏎`})]})]})]})}function Le({uiPhase:e,headline:t,description:n,chips:r,onChipSubmit:i,streamingText:a,composer:o,composerAccessory:s,history:c,baseBody:l,baseBodyDisclosureLabel:u,errorMessage:d}){let{t:f}=w(`aiedit`),p=e===`composing`&&(r?.length??0)>0&&c.length===0,m=e===`error`,h=c.filter(e=>e.role===`user`||e.role===`system`&&e.kind===`test_result`);return(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,X.jsxs)(`div`,{className:`mx-auto max-w-2xl px-6 py-12 pb-32 flex flex-col gap-6`,children:[(0,X.jsxs)(`header`,{className:`text-center space-y-2`,children:[(0,X.jsx)(`div`,{className:`inline-flex items-center justify-center w-10 h-10 rounded-full ring-1 mx-auto `+(m?`bg-red-500/10 aurora-light:bg-destructive/10 ring-red-500/30 aurora-light:ring-destructive/30`:`bg-accent-primary/15 ring-accent-primary/30`),children:m?(0,X.jsx)(F,{className:`w-5 h-5 text-red-400 aurora-light:text-destructive`}):(0,X.jsx)(U,{className:`w-5 h-5 text-accent-primary`})}),(0,X.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:m?f(`shell.somethingWentWrong`):t}),m&&d&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto font-mono break-words`,children:d}),!m&&n&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto leading-relaxed`,children:n})]}),e===`streaming`&&(0,X.jsx)(ze,{streamingText:a}),p&&r&&i&&(0,X.jsx)(Re,{chips:r,onPick:i}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[o,s&&(0,X.jsx)(`div`,{children:s})]}),h.length>0&&(0,X.jsx)(Be,{history:h}),l&&(0,X.jsx)(Ve,{body:l,label:u??f(`shell.viewCurrentContent`)})]})})}function Re({chips:e,onPick:t}){let{t:n}=w(`aiedit`);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:n(`shell.quickPrompts`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(e),className:`text-xs px-3 py-1.5 rounded-full border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent-primary/10 hover:text-accent-primary text-foreground/80 transition-colors focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,children:e},e))})]})}function ze({streamingText:e}){let{t}=w(`aiedit`);return(0,X.jsx)(`div`,{className:`rounded-xl border border-accent-primary/30 bg-accent-primary/5 p-4`,children:e?(0,X.jsxs)(`div`,{className:`text-xs font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-64 overflow-y-auto leading-relaxed`,children:[Xe(e),(0,X.jsx)(`span`,{className:`inline-block w-1.5 h-3 bg-accent-primary animate-pulse align-middle ml-0.5`})]}):(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground italic flex items-center gap-1.5`,children:[(0,X.jsx)(S,{className:`w-3 h-3 animate-spin`}),t(`shell.workingOnRefinement`)]})})}function Be({history:e}){let{t}=w(`aiedit`);return e.length===0?null:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:t(`shell.history`)}),(0,X.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,X.jsx)(Ge,{turn:e},t))})]})}function Ve({body:e,label:t}){let[n,r]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{className:`border-t border-border/60 pt-4`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none rounded px-1 -ml-1`,children:[n?(0,X.jsx)(ie,{className:`w-3.5 h-3.5`}):(0,X.jsx)(N,{className:`w-3.5 h-3.5`}),t]}),n&&(0,X.jsx)(`pre`,{className:`mt-2 p-3 rounded-md bg-muted/40 border border-border text-[11px] font-mono whitespace-pre-wrap break-words max-h-72 overflow-y-auto text-foreground/80`,children:e})]})}function He({state:e,appliedNotice:t}){return(0,X.jsxs)(`div`,{className:`flex-1 min-h-0 grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[(0,X.jsx)(Ue,{history:e.history??[],composer:e.composer,composerAccessory:e.composerAccessory,secondaryAction:e.secondaryAction,appliedNotice:t,uiPhase:e.uiPhase}),(0,X.jsx)(Ke,{diff:e.diff,label:e.diffHeaderLabel,applyConflict:e.applyConflict??null,onForceApply:e.onForceApply})]})}function Ue({history:e,composer:t,composerAccessory:n,secondaryAction:r,appliedNotice:i,uiPhase:a}){let{t:o}=w(`aiedit`);return(0,X.jsxs)(`section`,{"aria-label":o(`shell.conversation`),className:`flex flex-col min-h-0 border-r border-border bg-card/20`,children:[(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 pb-32 space-y-3`,"aria-live":`polite`,children:[e.map((e,t)=>(0,X.jsx)(Ge,{turn:e},t)),a===`applied`&&(i??(0,X.jsx)(We,{}))]}),(0,X.jsxs)(`div`,{className:`flex-shrink-0 border-t border-border p-3 space-y-2`,children:[t,n,r&&(0,X.jsxs)(`button`,{type:`button`,onClick:r.onClick,className:`w-full inline-flex items-center justify-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground py-1.5 rounded hover:bg-accent/50 focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,children:[r.icon??(0,X.jsx)(j,{className:`w-3 h-3`}),r.label]})]})]})}function We(){let{t:e}=w(`aiedit`);return(0,X.jsxs)(`div`,{className:`rounded-md border border-green-500/40 aurora-light:border-accent-success/40 bg-green-500/10 aurora-light:bg-accent-success/10 p-3 text-xs text-green-300 aurora-light:text-accent-success flex items-center gap-2`,children:[(0,X.jsx)(se,{className:`w-3.5 h-3.5`}),e(`shell.applied`)]})}function Ge({turn:e}){let{t}=w(`aiedit`);return e.role===`user`?(0,X.jsxs)(`div`,{className:`flex flex-col items-end`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1`,children:t(`shell.you`)}),(0,X.jsx)(`div`,{className:`max-w-[90%] rounded-2xl rounded-br-sm bg-accent-primary/15 text-foreground text-sm px-3 py-2 whitespace-pre-wrap break-words`,children:e.content})]}):e.role===`system`&&e.kind===`test_result`?(0,X.jsxs)(`div`,{className:`rounded-md border border-accent-info/30 bg-accent-info/5 p-3 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium mb-1 text-accent-info`,children:[(0,X.jsx)(U,{className:`w-3 h-3`}),` `,t(`shell.autoTestResult`)]}),(0,X.jsx)(`pre`,{className:`text-[11px] font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-48 overflow-y-auto`,children:e.content})]}):(0,X.jsxs)(`div`,{className:`flex flex-col items-start`,children:[(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 inline-flex items-center gap-1`,children:[(0,X.jsx)(U,{className:`w-3 h-3 text-accent-primary`}),` `,t(`shell.ai`)]}),(0,X.jsx)(`div`,{className:`max-w-[90%] rounded-2xl rounded-bl-sm border border-border bg-muted/30 text-xs px-3 py-2 text-muted-foreground italic`,children:t(`shell.refinementReady`)})]})}function Ke({diff:e,label:t,applyConflict:n,onForceApply:r}){let{t:i}=w(`aiedit`);return(0,X.jsxs)(`section`,{"aria-label":i(`shell.diffPreview`),className:`flex flex-col min-h-0`,children:[(0,X.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between px-4 h-9 border-b border-border bg-card/40`,children:[(0,X.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:t??i(`shell.proposedChanges`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`shell.wordLevelDiff`)})]}),n===`disk_changed`&&(0,X.jsx)(qe,{kind:`disk_changed`,action:r&&(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:r,children:[(0,X.jsx)(o,{className:`w-3 h-3 mr-1`}),` `,i(`shell.forceApply`)]})}),n===`name_changed`&&(0,X.jsx)(qe,{kind:`name_changed`}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-4 pb-32`,children:e})]})}function qe({kind:e,action:t}){let{t:n}=w(`aiedit`),r=n(e===`disk_changed`?`shell.conflict.diskChanged`:`shell.conflict.nameChanged`);return(0,X.jsxs)(`div`,{role:`alert`,className:`flex items-start justify-between gap-3 px-4 py-2 border-b border-yellow-500/40 aurora-light:border-accent-warning/40 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-200 aurora-light:text-accent-warning text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,X.jsx)(F,{className:`w-3.5 h-3.5 mt-0.5 flex-shrink-0`}),(0,X.jsx)(`span`,{children:r})]}),t]})}function Je({onCancel:e,onConfirm:t}){let{t:n}=w(`aiedit`);return(0,X.jsx)(`div`,{role:`alertdialog`,"aria-modal":`true`,"aria-label":n(`shell.discardDialog.ariaLabel`),className:`absolute inset-0 z-10 flex items-center justify-center bg-black/40`,children:(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-5 max-w-sm shadow-xl`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(F,{className:`w-4 h-4 text-yellow-400 aurora-light:text-accent-warning`}),(0,X.jsx)(`h2`,{className:`text-sm font-medium`,children:n(`shell.discardDialog.title`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mb-4`,children:n(`shell.discardDialog.body`)}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:e,children:n(`shell.discardDialog.keepEditing`)}),(0,X.jsx)(W,{size:`sm`,onClick:t,children:n(`common:actions.discard`)})]})]})})}function Ye({hunks:e}){return(0,X.jsx)(`pre`,{className:`font-mono text-xs leading-5 whitespace-pre-wrap break-words`,children:e.map((e,t)=>e.type===`eq`?(0,X.jsx)(`span`,{className:`text-foreground/70`,children:e.text},t):e.type===`add`?(0,X.jsxs)(`span`,{"data-hunk":`add`,className:`bg-green-500/20 aurora-light:bg-accent-success/15 text-green-200 aurora-light:text-accent-success rounded px-0.5 ring-1 ring-green-500/30 aurora-light:ring-accent-success/30`,children:[(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`+ `}),e.text]},t):(0,X.jsxs)(`span`,{"data-hunk":`del`,className:`bg-red-500/20 aurora-light:bg-destructive/15 text-red-200 aurora-light:text-destructive line-through rounded px-0.5 ring-1 ring-red-500/30 aurora-light:ring-destructive/30`,children:[(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`− `}),e.text]},t))})}function Xe(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function Ze(e,t){let n=/(\s+)/,r=e.split(n),i=t.split(n);if(r.length>2e4||i.length>2e4)return Qe(e,t);let a=r.length,o=i.length,s=new Uint16Array((a+1)*(o+1)),c=o+1;for(let e=a-1;e>=0;e--)for(let t=o-1;t>=0;t--)r[e]===i[t]?s[e*c+t]=s[(e+1)*c+(t+1)]+1:s[e*c+t]=Math.max(s[(e+1)*c+t],s[e*c+(t+1)]);let l=[],u=0,d=0,f=null,p=``,m=()=>{f!==null&&p&&l.push({type:f,text:p}),f=null,p=``},h=(e,t)=>{f===e?p+=t:(m(),f=e,p=t)};for(;u<a&&d<o;)r[u]===i[d]?(h(`eq`,r[u]),u++,d++):s[(u+1)*c+d]>=s[u*c+(d+1)]?(h(`del`,r[u]),u++):(h(`add`,i[d]),d++);for(;u<a;)h(`del`,r[u++]);for(;d<o;)h(`add`,i[d++]);return m(),l}function Qe(e,t){let n=e.split(`
79
+ `;function Oe({agentId:e,initialBody:t,initialName:n,draftFromRefine:r,onClose:a,onSaved:o,onResumeRefine:s}){let{t:c}=w(`agentstudio`),l=!e,[u,d]=(0,Y.useState)(e??n??``),[f,p]=(0,Y.useState)(t??De),[m,h]=(0,Y.useState)(!l&&!t&&!r),[_,v]=(0,Y.useState)(!!r&&!l),[y,b]=(0,Y.useState)(!1),[x,C]=(0,Y.useState)(null),[E,D]=(0,Y.useState)([]),[O,k]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(!!t&&l),[M,ee]=(0,Y.useState)(!1),[N,P]=(0,Y.useState)(``),[F,I]=(0,Y.useState)(!1),[L,R]=(0,Y.useState)(null),[te,B]=(0,Y.useState)(null),[V,ne]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(l||t!==void 0)return;if(r){let t=!1;return fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}/refine/${r}`).then(e=>{if(!e.ok)throw Error(c(`studio.errors.loadDraftFailed`,{status:e.status}));return e.json()}).then(e=>{!t&&e.draftBody&&(p(e.draftBody),j(!0))}).catch(e=>{t||C(e.message)}).finally(()=>{t||v(!1)}),()=>{t=!0}}let n=!1;return fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}`).then(e=>{if(!e.ok)throw Error(c(`studio.errors.loadFailed`,{status:e.status}));return e.json()}).then(e=>{n||p(e.body)}).catch(e=>{n||C(e.message)}).finally(()=>{n||h(!1)}),()=>{n=!0}},[e,l,t,r]);let re=(0,Y.useCallback)(()=>{l||fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}/versions`).then(e=>e.ok?e.json():{versions:[]}).then(e=>D(e.versions)).catch(()=>D([]))},[e,l]);(0,Y.useEffect)(()=>{O&&re()},[O,re]);let U=/^custom-[a-z0-9][a-z0-9-]*$/.test(u),ie=f.trim().length>0,G=/^---\s*\n[\s\S]*?\n---/.test(f),se=ie&&G&&(l?U:!0)&&A,ce=(0,Y.useCallback)(async()=>{b(!0),C(null);try{let t;if(t=l?await fetch(`${K()}/profiles/catalog`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:u,body:f})}):await fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:f})}),!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??c(`studio.errors.saveFailed`,{status:t.status}))}j(!1),g.success(c(l?`studio.toasts.agentCreated`:`studio.toasts.agentSaved`),{description:l?u:e}),o&&o(l?u:e)}catch(e){let t=e.message;C(t),g.error(c(l?`studio.toasts.createFailed`:`studio.toasts.saveFailed`),{description:t})}finally{b(!1)}},[e,f,u,l,o,c]),le=(0,Y.useCallback)(async()=>{if(!l){ne(!1),b(!0),C(null);try{let t=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??c(`studio.errors.deleteFailed`,{status:t.status}))}g.success(c(`studio.toasts.agentDeleted`),{description:e}),o&&o(e),a()}catch(e){let t=e.message;C(t),g.error(c(`studio.toasts.deleteFailed`),{description:t})}finally{b(!1)}}},[e,l,a,o,c]),ue=(0,Y.useCallback)(e=>{p(e.body),j(!0),k(!1)},[]),q=(0,Y.useCallback)(async()=>{I(!0),B(null),R(null);try{let t=await fetch(`${K()}/profiles/catalog/test`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:l?u||`draft`:e,draftBody:f,sampleTask:N})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??c(`studio.errors.testFailed`,{status:t.status}))}R(await t.json())}catch(e){B(e.message)}finally{I(!1)}},[e,f,u,l,N,c]);return m?(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:c(`studio.loadingAgent`)})}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!l&&(0,X.jsx)(Se,{open:V,title:c(`studio.deleteConfirm.title`,{agentId:e}),description:c(`studio.deleteConfirm.description`),confirmLabel:c(`common:actions.delete`),destructive:!0,onConfirm:le,onCancel:()=>ne(!1)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 border-b border-border`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:a,className:`p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground`,title:c(`common:actions.back`),children:(0,X.jsx)(ae,{className:`w-4 h-4`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground uppercase tracking-wide`,children:c(l?`studio.modeCreate`:`studio.modeEdit`)}),l?(0,X.jsx)(z,{value:u,onChange:e=>{d(e.target.value),j(!0)},placeholder:`custom-my-agent`,className:`text-sm font-mono mt-1 max-w-sm`}):(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`text-sm font-mono`,children:e}),r&&(0,X.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!s||!e))try{let t=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(e)}`);if(!t.ok)return;s(r,e,(await t.json()).body)}catch{}},className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full border border-accent-primary/40 bg-accent-primary/15 text-accent-primary hover:bg-accent-primary/25 focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,title:c(`studio.resumeAiEditTitle`),children:[(0,X.jsx)(pe,{className:`w-3 h-3`}),` `,c(`studio.resumeAiEdit`)]}),_&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(S,{className:`w-3 h-3 animate-spin`}),` `,c(`studio.loadingAiDraft`)]})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>{ee(e=>!e),M||k(!1)},title:c(`studio.testButtonTitle`),children:[(0,X.jsx)(fe,{className:`w-3.5 h-3.5 mr-1`}),c(`studio.testButton`)]}),!l&&(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>{k(e=>!e),O||ee(!1)},title:c(`studio.historyButtonTitle`),children:[(0,X.jsx)(T,{className:`w-3.5 h-3.5 mr-1`}),c(`studio.historyButton`)]}),!l&&(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>ne(!0),disabled:y,className:`text-red-400 hover:text-red-300 aurora-light:text-destructive aurora-light:hover:text-destructive`,children:[(0,X.jsx)(H,{className:`w-3.5 h-3.5 mr-1`}),c(`common:actions.delete`)]}),(0,X.jsxs)(W,{size:`sm`,onClick:ce,disabled:!se||y,children:[(0,X.jsx)(de,{className:`w-3.5 h-3.5 mr-1`}),c(y?`common:states.saving`:l?`studio.create`:`common:actions.save`)]})]})]}),x&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 text-xs border-b border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:[(0,X.jsx)(oe,{className:`w-3.5 h-3.5 flex-shrink-0`}),x]}),l&&u.length>0&&!U&&(0,X.jsx)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:(0,X.jsx)(i,{t:c,i18nKey:`studio.validation.namePattern`,components:{code:(0,X.jsx)(`code`,{})}})}),!G&&(0,X.jsx)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:(0,X.jsx)(i,{t:c,i18nKey:`studio.validation.missingFrontmatter`,components:{code:(0,X.jsx)(`code`,{})}})}),(0,X.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:[(0,X.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,X.jsxs)(`span`,{children:[`.claude/agents/`,l?u||`custom-…`:e,`.md`]}),A&&(0,X.jsx)(`span`,{className:`text-yellow-500 aurora-light:text-accent-warning`,children:c(`studio.unsaved`)})]}),(0,X.jsx)(`textarea`,{value:f,onChange:e=>{p(e.target.value),j(!0)},spellCheck:!1,className:`flex-1 w-full p-4 text-xs font-mono bg-background text-foreground outline-none resize-none leading-relaxed`})]}),M&&(0,X.jsxs)(`aside`,{className:`w-96 flex-shrink-0 border-l border-border flex flex-col min-h-0`,children:[(0,X.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,X.jsx)(fe,{className:`w-3.5 h-3.5`}),` `,c(`studio.testPane.header`)]}),(0,X.jsxs)(`div`,{className:`p-3 border-b border-border`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,X.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,children:c(`studio.testPane.sampleTaskLabel`)}),(0,X.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&&P(Ee[t].prompt)},disabled:F,children:Ee.map((e,t)=>(0,X.jsx)(`option`,{value:t,children:c(e.labelKey)},t))})]}),(0,X.jsx)(`textarea`,{value:N,onChange:e=>P(e.target.value),placeholder:c(`studio.testPane.placeholder`),className:`w-full text-xs p-2 rounded border border-border bg-background min-h-[80px] resize-y font-mono`,disabled:F}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,X.jsx)(W,{size:`sm`,onClick:q,disabled:F||!N.trim()||!f.trim(),children:F?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,c(`studio.testPane.running`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,c(`studio.testPane.run`)]})}),(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:c(`studio.testPane.sandboxNote`)})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 min-h-0`,children:[te&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive mb-2`,children:te}),L&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground mb-2`,children:[(0,X.jsx)(`span`,{children:(0,X.jsx)(i,{t:c,i18nKey:`studio.testPane.tokens`,count:L.tokens,components:{mono:(0,X.jsx)(`span`,{className:`text-foreground font-mono`})}})}),(0,X.jsx)(`span`,{children:(0,X.jsxs)(`span`,{className:`text-foreground font-mono`,children:[(L.durationMs/1e3).toFixed(1),`s`]})})]}),(0,X.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed rounded border border-border bg-background p-3`,children:L.output})]}),!F&&!L&&!te&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic`,children:c(`studio.testPane.emptyHint`)})]})]}),O&&!l&&(0,X.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-l border-border flex flex-col`,children:[(0,X.jsx)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:c(`studio.versions.header`)}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:E.length===0?(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic px-2 py-2`,children:c(`studio.versions.empty`)}):E.map(e=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>ue(e),className:`w-full text-left px-2 py-1.5 rounded hover:bg-accent/50 transition-colors`,children:[(0,X.jsxs)(`div`,{className:`text-xs font-mono text-foreground`,children:[`v`,e.version]}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.version))}),(0,X.jsx)(`div`,{className:`px-3 py-2 border-t border-border text-[11px] text-muted-foreground`,children:c(`studio.versions.restoreHint`)})]})]})]})}var ke={refineId:null,agentId:null,uiState:`closed`,phase:`idle`,history:[],streamingText:``,draftBody:null,baseBody:null,autoTest:!1,testResult:null,appliedVersion:null,errorMessage:null,applyConflict:null};function Ae(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function je(e,t){switch(t.type){case`OPEN`:return{...ke,agentId:t.agentId,baseBody:t.baseBody,uiState:`composing`};case`START_TURN`:return{...e,refineId:t.refineId,uiState:`streaming`,phase:`reading`,streamingText:``,errorMessage:null,applyConflict:null,history:[...e.history,t.userTurn]};case`STREAM_DELTA`:return e.refineId===t.refineId?{...e,streamingText:e.streamingText+t.delta}:e;case`PHASE`:return e.refineId===t.refineId?{...e,phase:t.phase}:e;case`READY`:return e.refineId===t.refineId?{...e,uiState:`reviewing`,phase:`done`,draftBody:t.draftBody,streamingText:``,history:[...e.history,{role:`assistant`,content:Ae(t.draftBody),timestamp:Date.now()}]}:e;case`TEST_RESULT`:return e.refineId===t.refineId?{...e,testResult:t.result,history:[...e.history,{role:`system`,kind:`test_result`,content:t.result.output,timestamp:Date.now()}]}:e;case`APPLIED`:return e.refineId===t.refineId?{...e,uiState:`applied`,appliedVersion:t.version}:e;case`CANCELLED`:return{...e,uiState:`cancelled`};case`ERROR`:return t.refineId!==null&&e.refineId!==t.refineId?e:{...e,uiState:`error`,errorMessage:t.message};case`CONFLICT`:return e.refineId===t.refineId?{...e,applyConflict:t.reason}:e;case`TOGGLE_AUTO_TEST`:return{...e,autoTest:t.enabled};case`REHYDRATE`:return{...e,...t.payload};case`CLOSE`:return ke;default:return e}}function Me(e){switch(e.status){case`streaming`:return`streaming`;case`ready`:return`reviewing`;case`applied`:return`applied`;case`cancelled`:return`cancelled`;case`error`:return`error`;default:return e.draftBody?`reviewing`:`composing`}}function Ne(e){let[t,n]=(0,Y.useReducer)(je,ke),{t:r}=w(`aiedit`),{registerHandler:i,unregisterHandler:a}=E(),o=(0,Y.useRef)(null);o.current=t.refineId;let s=(0,Y.useRef)(null);s.current=t.agentId;let c=(0,Y.useRef)(e);c.current=e;let l=(0,Y.useRef)(e);(0,Y.useEffect)(()=>{e!==l.current&&(l.current=e,n({type:`CLOSE`}))},[e]),(0,Y.useEffect)(()=>{let e=`agent-refine-${Math.random().toString(36).slice(2,9)}`;return i(e,e=>{let t=e;if(typeof t.type!=`string`||t.projectId!==c.current||t.refineId!==o.current)return;let r=t.refineId;switch(t.type){case`agent_refine_stream`:n({type:`STREAM_DELTA`,refineId:r,delta:t.delta});break;case`agent_refine_phase`:n({type:`PHASE`,refineId:r,phase:t.phase});break;case`agent_refine_ready`:n({type:`READY`,refineId:r,draftBody:t.draftBody});break;case`agent_refine_test`:n({type:`TEST_RESULT`,refineId:r,result:t.result});break;case`agent_refine_applied`:n({type:`APPLIED`,refineId:r,version:t.version});break;case`agent_refine_cancelled`:n({type:`CANCELLED`,refineId:r});break;case`agent_refine_error`:n({type:`ERROR`,refineId:r,message:t.error});break}}),()=>a(e)},[i,a]);let u=(0,Y.useCallback)((e,t)=>{n({type:`OPEN`,agentId:e,baseBody:t})},[]),d=(0,Y.useCallback)(()=>{n({type:`CLOSE`})},[]);return{state:t,open:u,start:(0,Y.useCallback)(async e=>{let i=s.current;if(i)try{let a=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(i)}/refine`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e,autoTest:t.autoTest})});if(!a.ok){n({type:`ERROR`,refineId:null,message:(await a.json().catch(()=>({}))).error??r(`refine.serverError`,{status:a.status})});return}let s=await a.json();o.current=s.refineId,n({type:`START_TURN`,refineId:s.refineId,userTurn:{role:`user`,content:e,timestamp:Date.now()}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.connectionFailed`,{message:e.message})})}},[t.autoTest,r]),sendTurn:(0,Y.useCallback)(async e=>{let t=o.current,i=s.current;if(!(!t||!i)){n({type:`START_TURN`,refineId:t,userTurn:{role:`user`,content:e,timestamp:Date.now()}});try{let a=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/turn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e})});a.ok||n({type:`ERROR`,refineId:t,message:(await a.json().catch(()=>({}))).error??r(`refine.serverError`,{status:a.status})})}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}}},[r]),cancel:(0,Y.useCallback)(async()=>{let e=o.current,t=s.current;if(!(!e||!t))try{await fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`,{method:`DELETE`})}catch{}},[]),apply:(0,Y.useCallback)(async e=>{let t=o.current,i=s.current;if(!(!t||!i))try{let a=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/apply`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({force:!!e})});if(a.status===409){let e=await a.json().catch(()=>({}));if(e.reason===`disk_changed`||e.reason===`name_changed`){n({type:`CONFLICT`,refineId:t,reason:e.reason});return}}if(!a.ok){n({type:`ERROR`,refineId:t,message:(await a.json().catch(()=>({}))).error??r(`refine.applyFailed`,{status:a.status})});return}n({type:`APPLIED`,refineId:t,version:(await a.json()).version})}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}},[r]),toggleAutoTest:(0,Y.useCallback)(async e=>{let t=o.current,r=s.current;if(n({type:`TOGGLE_AUTO_TEST`,enabled:e}),!(!t||!r))try{await fetch(`${K()}/profiles/catalog/${encodeURIComponent(r)}/refine/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({autoTest:e})})}catch{}},[]),rehydrate:(0,Y.useCallback)(async(e,t)=>{try{let i=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}`);if(!i.ok)throw Error(r(`refine.loadAgentFailed`,{status:i.status}));let a=await i.json(),c=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`);if(!c.ok)throw Error(r(`refine.loadSessionFailed`,{status:c.status}));let l=await c.json();o.current=e,s.current=t,n({type:`REHYDRATE`,payload:{refineId:e,agentId:t,baseBody:a.body,draftBody:l.draftBody,history:l.history,autoTest:l.autoTest,phase:l.phase,uiState:Me(l),streamingText:``}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.rehydrateFailed`,{message:e.message})})}},[r]),close:d}}function Pe(){return typeof window>`u`||!(`__TAURI_INTERNALS__`in window)?!1:/mac/i.test(navigator.platform)}function Fe(e){let[t,n]=(0,Y.useState)(!1),r=(0,Y.useRef)(null),{panelRef:i,panelStyle:a,headerHandleProps:o,resizeHandles:s,isFloating:c}=C();(0,Y.useEffect)(()=>(r.current=document.activeElement,()=>{let e=r.current;e&&e instanceof HTMLElement&&e.focus()}),[]);let l=(0,Y.useCallback)(()=>{e.uiPhase===`streaming`||e.uiPhase===`reviewing`?n(!0):e.onClose()},[e]),u=(0,Y.useCallback)(()=>{n(!1),e.onDiscard()},[e]);(0,Y.useEffect)(()=>{let t=t=>{if(t.key===`Escape`){t.preventDefault(),l();return}if((t.metaKey||t.ctrlKey)&&t.key===`Enter`&&e.uiPhase===`reviewing`&&e.canApply&&!e.applyConflict){t.preventDefault(),e.onApply();return}e.onKeyDown?.(t)};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,l]);let d=e.uiPhase===`composing`||e.uiPhase===`streaming`||e.uiPhase===`error`,f=e.uiPhase===`reviewing`||e.uiPhase===`applied`;return(0,X.jsxs)(`div`,{className:`fixed inset-0 z-50 flex p-3 pt-10 sm:p-6 sm:pt-12 bg-black/40 backdrop-blur-sm animate-in fade-in duration-150`,"data-testid":`ai-edit-backdrop`,children:[(0,X.jsxs)(`div`,{ref:i,role:`dialog`,"aria-modal":`true`,"aria-label":`${e.eyebrow} · ${e.targetLabel}`,className:`m-auto w-full h-full max-w-[1600px] flex flex-col bg-background rounded-xl border border-border/40 shadow-2xl overflow-hidden`,style:a,children:[(0,X.jsx)(Ie,{eyebrow:e.eyebrow,targetLabel:e.targetLabel,targetLabelMono:e.targetLabelMono??!0,showApply:e.uiPhase===`reviewing`&&e.canApply&&!e.applyConflict,showDiscard:e.uiPhase!==`applied`,onApply:e.onApply,onDiscard:l,onMinimize:e.onMinimize,headerHandleProps:o,isFloating:c}),d&&(0,X.jsx)(Le,{uiPhase:e.uiPhase,headline:e.uiPhase===`streaming`?e.streamingHeadline:e.headline,description:e.description,chips:e.chips,onChipSubmit:e.onChipSubmit,streamingText:e.streamingText,composer:e.composer,composerAccessory:e.composerAccessory,history:e.history??[],baseBody:e.baseBody,baseBodyDisclosureLabel:e.baseBodyDisclosureLabel,errorMessage:e.errorMessage}),f&&(0,X.jsx)(He,{state:e,appliedNotice:e.appliedNotice}),t&&(0,X.jsx)(Je,{onCancel:()=>n(!1),onConfirm:u})]}),(0,X.jsx)(M,{handles:s})]})}function Ie({eyebrow:e,targetLabel:t,targetLabelMono:n,showApply:i,showDiscard:a,onApply:o,onDiscard:s,onMinimize:c,headerHandleProps:l,isFloating:u}){let{t:d}=w(`aiedit`),f=Pe()?`pl-[88px]`:`pl-4`;return(0,X.jsxs)(`div`,{...l,className:`flex-shrink-0 flex items-center justify-between ${f} pr-4 h-14 border-b border-border bg-card/60 backdrop-blur-sm${u?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:s,className:`flex items-center gap-2 group p-1 -ml-1 rounded hover:bg-accent focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none max-w-[60vw]`,"aria-label":d(`shell.backAriaLabel`),children:[(0,X.jsx)(ae,{className:`w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/70 leading-none`,children:e}),n?(0,X.jsx)(`code`,{className:`text-sm font-mono font-medium text-foreground truncate block`,children:t}):(0,X.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate block`,children:t})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:c,"aria-label":d(`common:actions.minimize`),"data-testid":`ai-edit-minimize`,children:(0,X.jsx)(r,{className:`w-4 h-4`})}),a&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:s,children:d(`common:actions.discard`)}),i&&(0,X.jsxs)(W,{size:`sm`,onClick:o,className:`gap-1.5`,children:[(0,X.jsx)(se,{className:`w-3.5 h-3.5`}),` `,d(`shell.apply`),(0,X.jsx)(`span`,{className:`text-[10px] opacity-70 ml-1`,children:`⌘⏎`})]})]})]})}function Le({uiPhase:e,headline:t,description:n,chips:r,onChipSubmit:i,streamingText:a,composer:o,composerAccessory:s,history:c,baseBody:l,baseBodyDisclosureLabel:u,errorMessage:d}){let{t:f}=w(`aiedit`),p=e===`composing`&&(r?.length??0)>0&&c.length===0,m=e===`error`,h=c.filter(e=>e.role===`user`||e.role===`system`&&e.kind===`test_result`);return(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,X.jsxs)(`div`,{className:`mx-auto max-w-2xl px-6 py-12 pb-32 flex flex-col gap-6`,children:[(0,X.jsxs)(`header`,{className:`text-center space-y-2`,children:[(0,X.jsx)(`div`,{className:`inline-flex items-center justify-center w-10 h-10 rounded-full ring-1 mx-auto `+(m?`bg-red-500/10 aurora-light:bg-destructive/10 ring-red-500/30 aurora-light:ring-destructive/30`:`bg-accent-primary/15 ring-accent-primary/30`),children:m?(0,X.jsx)(F,{className:`w-5 h-5 text-red-400 aurora-light:text-destructive`}):(0,X.jsx)(U,{className:`w-5 h-5 text-accent-primary`})}),(0,X.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:m?f(`shell.somethingWentWrong`):t}),m&&d&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto font-mono break-words`,children:d}),!m&&n&&(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto leading-relaxed`,children:n})]}),e===`streaming`&&(0,X.jsx)(ze,{streamingText:a}),p&&r&&i&&(0,X.jsx)(Re,{chips:r,onPick:i}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[o,s&&(0,X.jsx)(`div`,{children:s})]}),h.length>0&&(0,X.jsx)(Be,{history:h}),l&&(0,X.jsx)(Ve,{body:l,label:u??f(`shell.viewCurrentContent`)})]})})}function Re({chips:e,onPick:t}){let{t:n}=w(`aiedit`);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:n(`shell.quickPrompts`)}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>t(e),className:`text-xs px-3 py-1.5 rounded-full border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent-primary/10 hover:text-accent-primary text-foreground/80 transition-colors focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,children:e},e))})]})}function ze({streamingText:e}){let{t}=w(`aiedit`);return(0,X.jsx)(`div`,{className:`rounded-xl border border-accent-primary/30 bg-accent-primary/5 p-4`,children:e?(0,X.jsxs)(`div`,{className:`text-xs font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-64 overflow-y-auto leading-relaxed`,children:[Xe(e),(0,X.jsx)(`span`,{className:`inline-block w-1.5 h-3 bg-accent-primary animate-pulse align-middle ml-0.5`})]}):(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground italic flex items-center gap-1.5`,children:[(0,X.jsx)(S,{className:`w-3 h-3 animate-spin`}),t(`shell.workingOnRefinement`)]})})}function Be({history:e}){let{t}=w(`aiedit`);return e.length===0?null:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:t(`shell.history`)}),(0,X.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,X.jsx)(Ge,{turn:e},t))})]})}function Ve({body:e,label:t}){let[n,r]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{className:`border-t border-border/60 pt-4`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none rounded px-1 -ml-1`,children:[n?(0,X.jsx)(ie,{className:`w-3.5 h-3.5`}):(0,X.jsx)(N,{className:`w-3.5 h-3.5`}),t]}),n&&(0,X.jsx)(`pre`,{className:`mt-2 p-3 rounded-md bg-muted/40 border border-border text-[11px] font-mono whitespace-pre-wrap break-words max-h-72 overflow-y-auto text-foreground/80`,children:e})]})}function He({state:e,appliedNotice:t}){return(0,X.jsxs)(`div`,{className:`flex-1 min-h-0 grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[(0,X.jsx)(Ue,{history:e.history??[],composer:e.composer,composerAccessory:e.composerAccessory,secondaryAction:e.secondaryAction,appliedNotice:t,uiPhase:e.uiPhase}),(0,X.jsx)(Ke,{diff:e.diff,label:e.diffHeaderLabel,applyConflict:e.applyConflict??null,onForceApply:e.onForceApply})]})}function Ue({history:e,composer:t,composerAccessory:n,secondaryAction:r,appliedNotice:i,uiPhase:a}){let{t:o}=w(`aiedit`);return(0,X.jsxs)(`section`,{"aria-label":o(`shell.conversation`),className:`flex flex-col min-h-0 border-r border-border bg-card/20`,children:[(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 pb-32 space-y-3`,"aria-live":`polite`,children:[e.map((e,t)=>(0,X.jsx)(Ge,{turn:e},t)),a===`applied`&&(i??(0,X.jsx)(We,{}))]}),(0,X.jsxs)(`div`,{className:`flex-shrink-0 border-t border-border p-3 space-y-2`,children:[t,n,r&&(0,X.jsxs)(`button`,{type:`button`,onClick:r.onClick,className:`w-full inline-flex items-center justify-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground py-1.5 rounded hover:bg-accent/50 focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,children:[r.icon??(0,X.jsx)(j,{className:`w-3 h-3`}),r.label]})]})]})}function We(){let{t:e}=w(`aiedit`);return(0,X.jsxs)(`div`,{className:`rounded-md border border-green-500/40 aurora-light:border-accent-success/40 bg-green-500/10 aurora-light:bg-accent-success/10 p-3 text-xs text-green-300 aurora-light:text-accent-success flex items-center gap-2`,children:[(0,X.jsx)(se,{className:`w-3.5 h-3.5`}),e(`shell.applied`)]})}function Ge({turn:e}){let{t}=w(`aiedit`);return e.role===`user`?(0,X.jsxs)(`div`,{className:`flex flex-col items-end`,children:[(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1`,children:t(`shell.you`)}),(0,X.jsx)(`div`,{className:`max-w-[90%] rounded-2xl rounded-br-sm bg-accent-primary/15 text-foreground text-sm px-3 py-2 whitespace-pre-wrap break-words`,children:e.content})]}):e.role===`system`&&e.kind===`test_result`?(0,X.jsxs)(`div`,{className:`rounded-md border border-accent-info/30 bg-accent-info/5 p-3 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium mb-1 text-accent-info`,children:[(0,X.jsx)(U,{className:`w-3 h-3`}),` `,t(`shell.autoTestResult`)]}),(0,X.jsx)(`pre`,{className:`text-[11px] font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-48 overflow-y-auto`,children:e.content})]}):(0,X.jsxs)(`div`,{className:`flex flex-col items-start`,children:[(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 inline-flex items-center gap-1`,children:[(0,X.jsx)(U,{className:`w-3 h-3 text-accent-primary`}),` `,t(`shell.ai`)]}),(0,X.jsx)(`div`,{className:`max-w-[90%] rounded-2xl rounded-bl-sm border border-border bg-muted/30 text-xs px-3 py-2 text-muted-foreground italic`,children:t(`shell.refinementReady`)})]})}function Ke({diff:e,label:t,applyConflict:n,onForceApply:r}){let{t:i}=w(`aiedit`);return(0,X.jsxs)(`section`,{"aria-label":i(`shell.diffPreview`),className:`flex flex-col min-h-0`,children:[(0,X.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between px-4 h-9 border-b border-border bg-card/40`,children:[(0,X.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:t??i(`shell.proposedChanges`)}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`shell.wordLevelDiff`)})]}),n===`disk_changed`&&(0,X.jsx)(qe,{kind:`disk_changed`,action:r&&(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:r,children:[(0,X.jsx)(o,{className:`w-3 h-3 mr-1`}),` `,i(`shell.forceApply`)]})}),n===`name_changed`&&(0,X.jsx)(qe,{kind:`name_changed`}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto p-4 pb-32`,children:e})]})}function qe({kind:e,action:t}){let{t:n}=w(`aiedit`),r=n(e===`disk_changed`?`shell.conflict.diskChanged`:`shell.conflict.nameChanged`);return(0,X.jsxs)(`div`,{role:`alert`,className:`flex items-start justify-between gap-3 px-4 py-2 border-b border-yellow-500/40 aurora-light:border-accent-warning/40 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-200 aurora-light:text-accent-warning text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,X.jsx)(F,{className:`w-3.5 h-3.5 mt-0.5 flex-shrink-0`}),(0,X.jsx)(`span`,{children:r})]}),t]})}function Je({onCancel:e,onConfirm:t}){let{t:n}=w(`aiedit`);return(0,X.jsx)(`div`,{role:`alertdialog`,"aria-modal":`true`,"aria-label":n(`shell.discardDialog.ariaLabel`),className:`absolute inset-0 z-10 flex items-center justify-center bg-black/40`,children:(0,X.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-5 max-w-sm shadow-xl`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,X.jsx)(F,{className:`w-4 h-4 text-yellow-400 aurora-light:text-accent-warning`}),(0,X.jsx)(`h2`,{className:`text-sm font-medium`,children:n(`shell.discardDialog.title`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mb-4`,children:n(`shell.discardDialog.body`)}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:e,children:n(`shell.discardDialog.keepEditing`)}),(0,X.jsx)(W,{size:`sm`,onClick:t,children:n(`common:actions.discard`)})]})]})})}function Ye({hunks:e}){return(0,X.jsx)(`pre`,{className:`font-mono text-xs leading-5 whitespace-pre-wrap break-words`,children:e.map((e,t)=>e.type===`eq`?(0,X.jsx)(`span`,{className:`text-foreground/70`,children:e.text},t):e.type===`add`?(0,X.jsxs)(`span`,{"data-hunk":`add`,className:`bg-green-500/20 aurora-light:bg-accent-success/15 text-green-200 aurora-light:text-accent-success rounded px-0.5 ring-1 ring-green-500/30 aurora-light:ring-accent-success/30`,children:[(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`+ `}),e.text]},t):(0,X.jsxs)(`span`,{"data-hunk":`del`,className:`bg-red-500/20 aurora-light:bg-destructive/15 text-red-200 aurora-light:text-destructive line-through rounded px-0.5 ring-1 ring-red-500/30 aurora-light:ring-destructive/30`,children:[(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`− `}),e.text]},t))})}function Xe(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function Ze(e,t){let n=/(\s+)/,r=e.split(n),i=t.split(n);if(r.length>2e4||i.length>2e4)return Qe(e,t);let a=r.length,o=i.length,s=new Uint16Array((a+1)*(o+1)),c=o+1;for(let e=a-1;e>=0;e--)for(let t=o-1;t>=0;t--)r[e]===i[t]?s[e*c+t]=s[(e+1)*c+(t+1)]+1:s[e*c+t]=Math.max(s[(e+1)*c+t],s[e*c+(t+1)]);let l=[],u=0,d=0,f=null,p=``,m=()=>{f!==null&&p&&l.push({type:f,text:p}),f=null,p=``},h=(e,t)=>{f===e?p+=t:(m(),f=e,p=t)};for(;u<a&&d<o;)r[u]===i[d]?(h(`eq`,r[u]),u++,d++):s[(u+1)*c+d]>=s[u*c+(d+1)]?(h(`del`,r[u]),u++):(h(`add`,i[d]),d++);for(;u<a;)h(`del`,r[u++]);for(;d<o;)h(`add`,i[d++]);return m(),l}function Qe(e,t){let n=e.split(`
80
80
  `),r=t.split(`
81
81
  `),i=[],a=0,o=0;for(;a<n.length&&o<r.length;)if(n[a]===r[o])i.push({type:`eq`,text:n[a]+`
82
82
  `}),a++,o++;else{let e=r.indexOf(n[a],o),t=n.indexOf(r[o],a);e!==-1&&(t===-1||e-o<=t-a)?(i.push({type:`add`,text:r[o]+`
83
83
  `}),o++):(i.push({type:`del`,text:n[a]+`
84
84
  `}),a++)}for(;a<n.length;)i.push({type:`del`,text:n[a++]+`
85
85
  `});for(;o<r.length;)i.push({type:`add`,text:r[o++]+`
86
- `});return i}function $e({value:e,onChange:t,onSubmit:n,disabled:r,placeholder:i,autoFocus:a,inputRef:o}){let{t:s}=w(`aiedit`);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`relative rounded-xl border border-border bg-card/40 focus-within:border-accent-primary/40 focus-within:ring-2 focus-within:ring-accent-primary/20 transition-all`,children:[(0,X.jsx)(`textarea`,{ref:o,value:e,onChange:e=>t(e.target.value),placeholder:i,rows:3,disabled:r,autoFocus:a,className:`w-full text-sm p-3 pr-14 bg-transparent resize-none focus:outline-none disabled:opacity-50 placeholder:text-muted-foreground/60`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),n())}}),(0,X.jsx)(`button`,{type:`button`,onClick:n,disabled:!e.trim()||r,"aria-label":s(`shell.composer.sendAriaLabel`),className:`absolute bottom-2.5 right-2.5 p-2 rounded-md bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-30 disabled:cursor-not-allowed focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none transition-opacity`,children:r?(0,X.jsx)(S,{className:`w-3.5 h-3.5 animate-spin`}):(0,X.jsx)(et,{})})]}),(0,X.jsx)(`div`,{className:`flex items-center justify-end text-[11px] text-muted-foreground/70`,children:(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`⌘⏎`}),` `,s(`shell.composer.kbdSubmit`),(0,X.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`Esc`}),` `,s(`shell.composer.kbdCancel`)]})})]})}function et(){return(0,X.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-3.5 h-3.5`,children:[(0,X.jsx)(`path`,{d:`M22 2 11 13`}),(0,X.jsx)(`path`,{d:`M22 2 15 22l-4-9-9-4Z`})]})}var tt=[`refine.chips.tightenTools`,`refine.chips.stricterPersonality`,`refine.chips.workflowSection`,`refine.chips.sharpenDescription`,`refine.chips.matchDeveloperStyle`];function nt({agentId:e,baseBody:t,resumeRefineId:n,onClose:r,onMinimize:i,onStateChange:a,onOpenInStudio:o,onApplied:s}){let{t:c}=w(`agentstudio`),{activeProjectId:l}=le(),u=Ne(l),[d,f]=(0,Y.useState)(``),p=(0,Y.useRef)(null),m=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{m.current||(m.current=!0,n?u.rehydrate(n,e):u.open(e,t))},[e,t,n,u]),(0,Y.useEffect)(()=>{let e=setTimeout(()=>p.current?.focus(),50);return()=>clearTimeout(e)},[]);let h=(0,Y.useRef)(a);h.current=a,(0,Y.useEffect)(()=>{h.current?.({refineId:u.state.refineId??null})},[u.state.refineId]);let g=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{u.state.uiState===`applied`&&u.state.appliedVersion!==null&&u.state.appliedVersion!==g.current&&(g.current=u.state.appliedVersion,s&&u.state.agentId&&s(u.state.agentId,u.state.appliedVersion))},[u.state.uiState,u.state.appliedVersion,u.state.agentId,s]);let _=(0,Y.useCallback)(async e=>{let t=e.trim();t&&(f(``),u.state.refineId?await u.sendTurn(t):await u.start(t))},[u]),v=(0,Y.useCallback)(()=>{_(d)},[d,_]),y=(0,Y.useCallback)(async()=>{u.state.refineId&&(u.state.uiState===`streaming`||u.state.uiState===`reviewing`)&&await u.cancel(),r()},[u,r]),b=rt(u.state),x=(0,Y.useMemo)(()=>!u.state.draftBody||!u.state.baseBody?null:(0,X.jsx)(Ye,{hunks:Ze(u.state.baseBody,u.state.draftBody)}),[u.state.baseBody,u.state.draftBody]);return(0,X.jsx)(Fe,{uiPhase:b,errorMessage:u.state.errorMessage,applyConflict:u.state.applyConflict,eyebrow:c(`refine.eyebrow`),targetLabel:e,targetLabelMono:!0,headline:c(`refine.headline`),streamingHeadline:c(`refine.streamingHeadline`),description:it(t),chips:tt.map(e=>c(e)),onChipSubmit:e=>void _(e),composer:(0,X.jsx)($e,{value:d,onChange:f,onSubmit:v,disabled:b===`streaming`||b===`applied`,placeholder:u.state.refineId?c(`refine.placeholderFollowUp`):c(`refine.placeholderInitial`),inputRef:p}),streamingText:u.state.streamingText,history:u.state.history,diff:x,diffHeaderLabel:`.claude/agents/${e}.md`,baseBody:t,baseBodyDisclosureLabel:c(`refine.viewCurrentBody`),appliedNotice:u.state.appliedVersion===null?void 0:(0,X.jsx)(`div`,{className:`rounded-md border border-green-500/40 aurora-light:border-accent-success/40 bg-green-500/10 aurora-light:bg-accent-success/10 p-3 text-xs text-green-300 aurora-light:text-accent-success`,children:c(`refine.appliedAsVersion`,{version:u.state.appliedVersion})}),canApply:u.state.uiState===`reviewing`&&!!u.state.draftBody&&!u.state.applyConflict,onApply:()=>void u.apply(),onForceApply:()=>void u.apply(!0),onDiscard:()=>void y(),onClose:()=>void y(),onMinimize:i?()=>i(u.state.refineId??null):void 0,secondaryAction:o&&u.state.draftBody&&u.state.refineId?{label:c(`refine.openInStudio`),icon:(0,X.jsx)(j,{className:`w-3 h-3`}),onClick:()=>{u.state.refineId&&u.state.draftBody&&o&&o(u.state.refineId,u.state.draftBody)}}:void 0})}function rt(e){switch(e.uiState){case`streaming`:return`streaming`;case`reviewing`:return`reviewing`;case`applied`:return`applied`;case`error`:return`error`;default:return`composing`}}function it(e){let t=e.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!t)return null;let n=t[1].match(/^description:\s*([\s\S]*?)(?=^[a-z_]+:\s|\Z)/m);if(!n)return null;let r=n[1].trim();return(r.startsWith(`"`)&&r.endsWith(`"`)||r.startsWith(`'`)&&r.endsWith(`'`))&&(r=r.slice(1,-1)),r=r.replace(/\\n/g,` `).replace(/\\t/g,` `).replace(/\\"/g,`"`).replace(/\\'/g,`'`).replace(/\\\\/g,`\\`).replace(/\s+/g,` `).trim(),r.length>240&&(r=r.slice(0,237)+`…`),r||null}function at(){let{t:e}=w(`agents`),[n,r]=(0,Y.useState)([]),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),[l,f]=(0,Y.useState)(!0),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)({kind:`closed`}),[x,C]=(0,Y.useState)({kind:`closed`}),[T,E]=(0,Y.useState)(!1),[D,j]=(0,Y.useState)(``),[M,N]=(0,Y.useState)(`all`),[F,R]=(0,Y.useState)(null),[ne,B]=(0,Y.useState)(!1),[H,re]=(0,Y.useState)(``),[ie,ae]=(0,Y.useState)(``),[G,oe]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(null),{activeProjectId:q}=le(),{minimize:de}=t(),J=(0,Y.useRef)({refineId:null}),fe=(0,Y.useRef)(x);fe.current=x;let me=(0,Y.useCallback)(()=>{let t=fe.current;t.kind!==`open`||!t.projectId||de({kind:`ai-edit`,projectId:t.projectId,label:e(`catalog.aiEditChipLabel`,{agentId:t.agentId}),restoreRoute:`/agents`,params:{agentId:t.agentId,baseBody:t.baseBody,resumeRefineId:J.current.refineId??t.resumeRefineId}})},[de,e]);L(`ai-edit`,q,e=>{e.kind===`ai-edit`&&(me(),J.current={refineId:e.params.resumeRefineId??null},C({kind:`open`,projectId:e.projectId,agentId:e.params.agentId,baseBody:e.params.baseBody,resumeRefineId:e.params.resumeRefineId}))});let Z=(0,Y.useCallback)(()=>{let t=!1;return f(!0),fetch(`${K()}/profiles/catalog`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||(r(e.agents),e.agents.length>0&&!a&&o(e.agents[0].id))}).catch(e=>{t||v(e.message)}).finally(()=>{t||f(!1)}),()=>{t=!0}},[a]);(0,Y.useEffect)(()=>Z(),[Z]);let Q=(0,Y.useCallback)(t=>{let n=!1;return g(!0),c(null),fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.bodyLoadFailed`,{status:t.status}));return t.json()}).then(e=>{n||c(e.body)}).catch(e=>{n||v(e.message)}).finally(()=>{n||g(!1)}),()=>{n=!0}},[]);if((0,Y.useEffect)(()=>{if(a)return Q(a)},[a,Q]),l)return(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`catalog.loading`)})});if(y.kind!==`closed`)return(0,X.jsx)(Oe,{agentId:y.kind===`edit`?y.agentId:void 0,initialBody:y.kind===`duplicate`||y.kind===`create`?y.initialBody:void 0,initialName:y.kind===`create`?y.initialName:void 0,draftFromRefine:y.kind===`edit`?y.draftFromRefine:void 0,onClose:()=>b({kind:`closed`}),onSaved:e=>{o(e),b({kind:`closed`}),Z()},onResumeRefine:(e,t,n)=>{b({kind:`closed`}),q&&(me(),J.current={refineId:e},C({kind:`open`,projectId:q,agentId:t,baseBody:n,resumeRefineId:e}))}});if(x.kind===`open`)return(0,X.jsx)(z,{onClose:()=>C({kind:`closed`}),children:(0,X.jsx)(nt,{agentId:x.agentId,baseBody:x.baseBody,resumeRefineId:x.resumeRefineId,onStateChange:e=>{J.current=e},onClose:()=>C({kind:`closed`}),onMinimize:t=>{let n=x.kind===`open`?x.projectId:q;if(!n){C({kind:`closed`});return}let r=x.kind===`open`?x.agentId:``,i=x.kind===`open`?x.baseBody:``;de({kind:`ai-edit`,projectId:n,label:e(`catalog.aiEditChipLabel`,{agentId:r}),restoreRoute:`/agents`,params:{agentId:r,baseBody:i,resumeRefineId:t??void 0}}),C({kind:`closed`})},onApplied:e=>{C({kind:`closed`}),o(e),Z()},onOpenInStudio:(e,t)=>{C({kind:`closed`}),b({kind:`edit`,agentId:x.agentId,draftFromRefine:e})}},`${x.agentId}:${x.resumeRefineId??`fresh`}`)});let he=(()=>{let e=D.trim().toLowerCase();return we.filter(t=>!(M!==`all`&&t.category!==M||F&&!t.tags.includes(F)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),ge=(()=>{let e=new Map;for(let t of we)e.set(t.category,(e.get(t.category)??0)+1);return e})(),_e=()=>{E(!1),j(``),N(`all`),R(null)},ve=()=>(0,X.jsx)(u,{open:T,onOpenChange:e=>{e||_e()},children:(0,X.jsxs)(m,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,X.jsxs)(A,{children:[(0,X.jsxs)(k,{className:`flex items-center gap-2 text-base`,children:[(0,X.jsx)(d,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.templates.title`),(0,X.jsx)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:e(`catalog.templates.countOf`,{shown:he.length,total:we.length})})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e(`catalog.templates.description`)})]}),(0,X.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,X.jsx)(ue,{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,X.jsx)(`input`,{value:D,onChange:e=>j(e.target.value),placeholder:e(`catalog.templates.searchPlaceholder`),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}),D&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>j(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,X.jsx)(P,{className:`w-3.5 h-3.5`})})]}),(0,X.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,X.jsx)(ot,{label:e(`catalog.templates.allCategories`),count:we.length,active:M===`all`,onClick:()=>N(`all`)}),Te.map(e=>(0,X.jsx)(ot,{label:e,count:ge.get(e)??0,active:M===e,onClick:()=>N(e)},e))]}),F&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tagFilter`)}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>R(null),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30`,children:[(0,X.jsx)(I,{className:`w-3 h-3`}),` `,F,(0,X.jsx)(P,{className:`w-3 h-3`})]})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:he.length===0?(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,X.jsxs)(`div`,{className:`max-w-sm`,children:[(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e(`catalog.templates.noMatch`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{j(``),N(`all`),R(null)},className:`text-xs text-accent-primary hover:underline mt-2`,children:e(`catalog.templates.clearFilters`)})]})}):(0,X.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:he.map(t=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{_e(),b({kind:`create`,initialBody:t.body,initialName:t.nameHint})},className:`group text-left p-4 rounded-lg border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent/40 hover:shadow-sm transition-all`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,X.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:t.emoji}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-accent-primary truncate`,children:t.label}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:t.category})]})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:t.blurb}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:t.tags.slice(0,5).map(e=>(0,X.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),R(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),R(e))},className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/50 text-muted-foreground hover:bg-accent-primary/20 hover:text-accent-primary cursor-pointer transition-colors `+(F===e?`bg-accent-primary/20 text-accent-primary`:``),children:e},e))}),(0,X.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,X.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:t.nameHint}),(0,X.jsx)(`span`,{className:`text-[10px] text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity`,children:e(`catalog.templates.openInStudio`)})]})]},t.id))})}),(0,X.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tip`)}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:_e,children:e(`common:actions.cancel`)})]})]})}),ye=()=>(0,X.jsx)(u,{open:ne,onOpenChange:e=>{!e&&!G&&(B(!1),ce(null))},children:(0,X.jsxs)(m,{className:`max-w-lg`,children:[(0,X.jsx)(A,{children:(0,X.jsxs)(k,{className:`flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.generate.title`)]})}),(0,X.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.agentIdLabel`)}),(0,X.jsx)(te,{value:H,onChange:e=>re(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:G}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,X.jsx)(i,{t:e,i18nKey:`catalog.generate.agentIdHint`,components:{code:(0,X.jsx)(`code`,{})}})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.descriptionLabel`)}),(0,X.jsx)(`textarea`,{value:ie,onChange:e=>ae(e.target.value),placeholder:e(`catalog.generate.descriptionPlaceholder`),className:`w-full text-sm p-2 rounded border border-border bg-background min-h-[120px] resize-y`,disabled:G})]}),se&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:se}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:(0,X.jsx)(i,{t:e,i18nKey:`catalog.generate.note`,components:{code:(0,X.jsx)(`code`,{})}})})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>B(!1),disabled:G,children:e(`common:actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:be,disabled:G||!H.trim()||!ie.trim(),children:G?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,e(`catalog.generate.generating`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.generate.generateButton`)]})})]})]})}),be=async()=>{oe(!0),ce(null);try{let t=await fetch(`${K()}/profiles/catalog/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:H.trim(),description:ie.trim()})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`catalog.errors.generateFailed`,{status:t.status}))}let n=await t.json();B(!1),b({kind:`create`,initialBody:n.draft,initialName:H.trim()})}catch(e){ce(e.message)}finally{oe(!1)}},xe=async t=>{try{let n=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}`);if(!n.ok)throw Error(e(`catalog.errors.agentLoadFailed`,{status:n.status}));b({kind:`duplicate`,from:t,initialBody:(await n.json()).body})}catch(e){v(e.message)}};if(n.length===0)return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`catalog.empty.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:(0,X.jsx)(i,{t:e,i18nKey:`catalog.empty.body`,values:{command:`npx specrails-core@latest update`},components:{code:(0,X.jsx)(`code`,{className:`text-foreground`})}})}),(0,X.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:()=>B(!0),children:[(0,X.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.generateWithClaude`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>E(!0),children:[(0,X.jsx)(d,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.template`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>b({kind:`create`}),children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.blank`)]})]})]})}),ve(),ye()]});let Se=n.filter(e=>e.kind===`upstream`),Ce=n.filter(e=>e.kind===`custom`),$=n.find(e=>e.id===a);return(0,X.jsxs)(X.Fragment,{children:[ve(),ye(),(0,X.jsxs)(`div`,{className:`flex h-full`,children:[(0,X.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:e(`catalog.sidebar.title`)}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:e(`catalog.sidebar.createLabel`)}),(0,X.jsxs)(`div`,{className:`flex gap-1`,children:[(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>E(!0),title:e(`catalog.actions.templateTitle`),children:[(0,X.jsx)(d,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.template`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>B(!0),title:e(`catalog.actions.generateWithClaude`),children:[(0,X.jsx)(U,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.generate`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>b({kind:`create`}),title:e(`catalog.actions.blankTitle`),children:[(0,X.jsx)(O,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.blank`)]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,X.jsx)(st,{title:e(`catalog.sections.upstream`,{count:Se.length}),description:e(`catalog.sections.upstreamDescription`),children:Se.map(e=>(0,X.jsx)(ct,{agent:e,selected:e.id===a,onSelect:()=>o(e.id)},e.id))}),(0,X.jsx)(st,{title:e(`catalog.sections.custom`,{count:Ce.length}),description:e(`catalog.sections.customDescription`),children:Ce.length===0?(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:e(`catalog.sections.noCustomAgents`)}):Ce.map(e=>(0,X.jsx)(ct,{agent:e,selected:e.id===a,onSelect:()=>o(e.id)},e.id))})]})]}),(0,X.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[_&&(0,X.jsx)(`div`,{className:`m-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:_}),$&&(0,X.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:$.id}),(0,X.jsx)(lt,{kind:$.kind}),$.model&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:e(`catalog.detail.defaultModel`,{model:$.model})})]}),$.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:$.description})]}),(0,X.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>void xe($.id),children:[(0,X.jsx)(ee,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.duplicate`)]}),$.kind===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>b({kind:`edit`,agentId:$.id}),children:[(0,X.jsx)(V,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.edit`)]}),(0,X.jsxs)(W,{size:`sm`,onClick:async()=>{if(q)try{let e=await fetch(`${K()}/profiles/catalog/${encodeURIComponent($.id)}`);if(!e.ok)throw Error(`Load failed: ${e.status}`);let t=await e.json();me(),J.current={refineId:null},C({kind:`open`,projectId:q,agentId:$.id,baseBody:t.body})}catch(e){v(e.message)}},title:e(`catalog.detail.aiEditTitle`),children:[(0,X.jsx)(pe,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`catalog.detail.aiEdit`)]})]})]})]}),(0,X.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,X.jsxs)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:[`.claude/agents/`,$.id,`.md`]}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:$.kind===`upstream`?e(`catalog.detail.readOnly`):e(`catalog.detail.editableHint`)})]}),(0,X.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:h?e(`common:states.loading`):s??``})]})]})]})]})]})}function ot({label:e,count:t,active:n,onClick:r}){return(0,X.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-accent-primary/20 border-accent-primary/50 text-accent-primary`:`bg-transparent border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[e,(0,X.jsx)(`span`,{className:`text-[9px] px-1 rounded `+(n?`bg-accent-primary/30`:`bg-muted/60`),children:t})]})}function st({title:e,description:t,children:n}){return(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,X.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function ct({agent:e,selected:t,onSelect:n}){return(0,X.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,X.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,X.jsx)(lt,{kind:e.kind})]})}function lt({kind:e}){let{t}=w(`agents`);return(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 `+(e===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:t(e===`custom`?`catalog.kind.custom`:`catalog.kind.upstream`)})}var ut=[{days:7},{days:30},{days:90}];function dt(){let{t:e}=w(`agents`),[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(30),[a,o]=(0,Y.useState)(!0);if((0,Y.useEffect)(()=>{let e=!1;return o(!0),fetch(`${K()}/profiles/analytics?windowDays=${r}`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&n(t)}).catch(()=>{}).finally(()=>{e||o(!1)}),()=>{e=!0}},[r]),a&&!t)return null;if(!t||t.rows.length===0)return(0,X.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitleEmpty`)})]}),(0,X.jsx)(`div`,{className:`flex gap-0.5`,children:ut.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>i(t.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(r===t.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e(`usage.windowLabel`,{days:t.days})},t.days))})]}),(0,X.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:e(`usage.empty`)})]});let s=Math.max(...t.rows.map(e=>e.jobs),1);return(0,X.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitle`,{count:t.windowDays})})]}),(0,X.jsx)(`div`,{className:`flex gap-0.5`,children:ut.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>i(t.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(r===t.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e(`usage.windowLabel`,{days:t.days})},t.days))})]}),(0,X.jsx)(`div`,{className:`p-4 space-y-2`,children:t.rows.map(t=>(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:t.profileName}),(0,X.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-accent-primary/70`,style:{width:`${Math.max(6,Math.round(t.jobs/s*100))}%`}})}),(0,X.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,X.jsxs)(`span`,{title:e(`usage.jobsTooltip`),children:[(0,X.jsx)(`span`,{className:`text-foreground font-mono`,children:t.jobs}),` `,e(`usage.jobsLabel`,{count:t.jobs})]}),(0,X.jsxs)(`span`,{title:e(`usage.successRateTooltip`),children:[(0,X.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(t.successRate*100),`%`]}),` `,e(`usage.okSuffix`)]}),t.avgDurationMs!=null&&(0,X.jsx)(`span`,{title:e(`usage.avgDurationTooltip`),children:(0,X.jsx)(`span`,{className:`text-foreground font-mono`,children:ft(t.avgDurationMs)})}),t.avgTokens!=null&&(0,X.jsxs)(`span`,{title:e(`usage.avgTokensTooltip`),children:[(0,X.jsx)(`span`,{className:`text-foreground font-mono`,children:pt(t.avgTokens)}),` `,e(`usage.tokensSuffix`)]})]})]},t.profileName))})]})}function ft(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 pt(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var mt=`specrails-desktop:agents-tab`;function ht(){try{let e=localStorage.getItem(mt);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function gt(){let{t:e}=w(`agents`),[n,r]=(0,Y.useState)(()=>ht()),a=e=>{r(e);try{localStorage.setItem(mt,e)}catch{}},[o,s]=(0,Y.useState)(null),{activeProjectId:c}=le(),{pendingRestores:l}=t(),u=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{if(!c)return;let e=l.some(e=>e.kind===`ai-edit`&&e.projectId===c);e&&!u.current&&n!==`catalog`&&a(`catalog`),u.current=e},[l,c,n]),(0,Y.useEffect)(()=>{let e=!1;return fetch(`${K()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&s(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[o!==null&&!o.profileAware&&(0,X.jsxs)(`div`,{className:`flex-shrink-0 flex items-start gap-3 px-6 py-3 border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10`,children:[(0,X.jsx)(F,{className:`w-4 h-4 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`text-xs`,children:[(0,X.jsx)(`div`,{className:`font-medium text-yellow-500 aurora-light:text-accent-warning`,children:e(`page.banner.title`,{required:o.required})}),(0,X.jsx)(`div`,{className:`text-yellow-500/80 aurora-light:text-accent-warning mt-0.5`,children:(0,X.jsx)(i,{t:e,i18nKey:`page.banner.body`,values:{version:o.version??e(`page.banner.unknownVersion`),command:`npx specrails-core@latest update`},components:{code:(0,X.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20 aurora-light:bg-accent-warning/20`})}})})]})]}),(0,X.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,X.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`page.title`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`page.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,X.jsx)(vt,{active:n===`profiles`,onClick:()=>a(`profiles`),children:e(`page.tabs.profiles`)}),(0,X.jsx)(vt,{active:n===`usage`,onClick:()=>a(`usage`),children:e(`page.tabs.usage`)}),(0,X.jsx)(vt,{active:n===`catalog`,onClick:()=>a(`catalog`),children:e(`page.tabs.catalog`)})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[n===`profiles`&&(0,X.jsx)(Ce,{}),n===`usage`&&(0,X.jsx)(_t,{}),n===`catalog`&&(0,X.jsx)(at,{})]})]})}function _t(){return(0,X.jsx)(`div`,{className:`min-h-full`,children:(0,X.jsx)(dt,{})})}function vt({active:e,children:t,onClick:n}){return(0,X.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{gt as default};
86
+ `});return i}function $e({value:e,onChange:t,onSubmit:n,disabled:r,placeholder:i,autoFocus:a,inputRef:o}){let{t:s}=w(`aiedit`);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`relative rounded-xl border border-border bg-card/40 focus-within:border-accent-primary/40 focus-within:ring-2 focus-within:ring-accent-primary/20 transition-all`,children:[(0,X.jsx)(`textarea`,{ref:o,value:e,onChange:e=>t(e.target.value),placeholder:i,rows:3,disabled:r,autoFocus:a,className:`w-full text-sm p-3 pr-14 bg-transparent resize-none focus:outline-none disabled:opacity-50 placeholder:text-muted-foreground/60`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),n())}}),(0,X.jsx)(`button`,{type:`button`,onClick:n,disabled:!e.trim()||r,"aria-label":s(`shell.composer.sendAriaLabel`),className:`absolute bottom-2.5 right-2.5 p-2 rounded-md bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-30 disabled:cursor-not-allowed focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none transition-opacity`,children:r?(0,X.jsx)(S,{className:`w-3.5 h-3.5 animate-spin`}):(0,X.jsx)(et,{})})]}),(0,X.jsx)(`div`,{className:`flex items-center justify-end text-[11px] text-muted-foreground/70`,children:(0,X.jsxs)(`span`,{children:[(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`⌘⏎`}),` `,s(`shell.composer.kbdSubmit`),(0,X.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,X.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`Esc`}),` `,s(`shell.composer.kbdCancel`)]})})]})}function et(){return(0,X.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-3.5 h-3.5`,children:[(0,X.jsx)(`path`,{d:`M22 2 11 13`}),(0,X.jsx)(`path`,{d:`M22 2 15 22l-4-9-9-4Z`})]})}var tt=[`refine.chips.tightenTools`,`refine.chips.stricterPersonality`,`refine.chips.workflowSection`,`refine.chips.sharpenDescription`,`refine.chips.matchDeveloperStyle`];function nt({agentId:e,baseBody:t,resumeRefineId:n,onClose:r,onMinimize:i,onStateChange:a,onOpenInStudio:o,onApplied:s}){let{t:c}=w(`agentstudio`),{activeProjectId:l}=le(),u=Ne(l),[d,f]=(0,Y.useState)(``),p=(0,Y.useRef)(null),m=(0,Y.useRef)(!1);(0,Y.useEffect)(()=>{m.current||(m.current=!0,n?u.rehydrate(n,e):u.open(e,t))},[e,t,n,u]),(0,Y.useEffect)(()=>{let e=setTimeout(()=>p.current?.focus(),50);return()=>clearTimeout(e)},[]);let h=(0,Y.useRef)(a);h.current=a,(0,Y.useEffect)(()=>{h.current?.({refineId:u.state.refineId??null})},[u.state.refineId]);let g=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{u.state.uiState===`applied`&&u.state.appliedVersion!==null&&u.state.appliedVersion!==g.current&&(g.current=u.state.appliedVersion,s&&u.state.agentId&&s(u.state.agentId,u.state.appliedVersion))},[u.state.uiState,u.state.appliedVersion,u.state.agentId,s]);let _=(0,Y.useCallback)(async e=>{let t=e.trim();t&&(f(``),u.state.refineId?await u.sendTurn(t):await u.start(t))},[u]),v=(0,Y.useCallback)(()=>{_(d)},[d,_]),y=(0,Y.useCallback)(async()=>{u.state.refineId&&(u.state.uiState===`streaming`||u.state.uiState===`reviewing`)&&await u.cancel(),r()},[u,r]),b=rt(u.state),x=(0,Y.useMemo)(()=>!u.state.draftBody||!u.state.baseBody?null:(0,X.jsx)(Ye,{hunks:Ze(u.state.baseBody,u.state.draftBody)}),[u.state.baseBody,u.state.draftBody]);return(0,X.jsx)(Fe,{uiPhase:b,errorMessage:u.state.errorMessage,applyConflict:u.state.applyConflict,eyebrow:c(`refine.eyebrow`),targetLabel:e,targetLabelMono:!0,headline:c(`refine.headline`),streamingHeadline:c(`refine.streamingHeadline`),description:it(t),chips:tt.map(e=>c(e)),onChipSubmit:e=>void _(e),composer:(0,X.jsx)($e,{value:d,onChange:f,onSubmit:v,disabled:b===`streaming`||b===`applied`,placeholder:u.state.refineId?c(`refine.placeholderFollowUp`):c(`refine.placeholderInitial`),inputRef:p}),streamingText:u.state.streamingText,history:u.state.history,diff:x,diffHeaderLabel:`.claude/agents/${e}.md`,baseBody:t,baseBodyDisclosureLabel:c(`refine.viewCurrentBody`),appliedNotice:u.state.appliedVersion===null?void 0:(0,X.jsx)(`div`,{className:`rounded-md border border-green-500/40 aurora-light:border-accent-success/40 bg-green-500/10 aurora-light:bg-accent-success/10 p-3 text-xs text-green-300 aurora-light:text-accent-success`,children:c(`refine.appliedAsVersion`,{version:u.state.appliedVersion})}),canApply:u.state.uiState===`reviewing`&&!!u.state.draftBody&&!u.state.applyConflict,onApply:()=>void u.apply(),onForceApply:()=>void u.apply(!0),onDiscard:()=>void y(),onClose:()=>void y(),onMinimize:i?()=>i(u.state.refineId??null):void 0,secondaryAction:o&&u.state.draftBody&&u.state.refineId?{label:c(`refine.openInStudio`),icon:(0,X.jsx)(j,{className:`w-3 h-3`}),onClick:()=>{u.state.refineId&&u.state.draftBody&&o&&o(u.state.refineId,u.state.draftBody)}}:void 0})}function rt(e){switch(e.uiState){case`streaming`:return`streaming`;case`reviewing`:return`reviewing`;case`applied`:return`applied`;case`error`:return`error`;default:return`composing`}}function it(e){let t=e.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!t)return null;let n=t[1].match(/^description:\s*([\s\S]*?)(?=^[a-z_]+:\s|\Z)/m);if(!n)return null;let r=n[1].trim();return(r.startsWith(`"`)&&r.endsWith(`"`)||r.startsWith(`'`)&&r.endsWith(`'`))&&(r=r.slice(1,-1)),r=r.replace(/\\n/g,` `).replace(/\\t/g,` `).replace(/\\"/g,`"`).replace(/\\'/g,`'`).replace(/\\\\/g,`\\`).replace(/\s+/g,` `).trim(),r.length>240&&(r=r.slice(0,237)+`…`),r||null}function at(){let{t:e}=w(`agents`),[n,r]=(0,Y.useState)([]),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),[l,f]=(0,Y.useState)(!0),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)({kind:`closed`}),[x,C]=(0,Y.useState)({kind:`closed`}),[T,E]=(0,Y.useState)(!1),[D,j]=(0,Y.useState)(``),[M,N]=(0,Y.useState)(`all`),[F,R]=(0,Y.useState)(null),[te,V]=(0,Y.useState)(!1),[H,re]=(0,Y.useState)(``),[ie,ae]=(0,Y.useState)(``),[G,oe]=(0,Y.useState)(!1),[se,ce]=(0,Y.useState)(null),{activeProjectId:q}=le(),{minimize:de}=t(),J=(0,Y.useRef)({refineId:null}),fe=(0,Y.useRef)(x);fe.current=x;let me=(0,Y.useCallback)(()=>{let t=fe.current;t.kind!==`open`||!t.projectId||de({kind:`ai-edit`,projectId:t.projectId,label:e(`catalog.aiEditChipLabel`,{agentId:t.agentId}),restoreRoute:`/agents`,params:{agentId:t.agentId,baseBody:t.baseBody,resumeRefineId:J.current.refineId??t.resumeRefineId}})},[de,e]);L(`ai-edit`,q,e=>{e.kind===`ai-edit`&&(me(),J.current={refineId:e.params.resumeRefineId??null},C({kind:`open`,projectId:e.projectId,agentId:e.params.agentId,baseBody:e.params.baseBody,resumeRefineId:e.params.resumeRefineId}))});let Z=(0,Y.useCallback)(()=>{let t=!1;return f(!0),fetch(`${K()}/profiles/catalog`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||(r(e.agents),e.agents.length>0&&!a&&o(e.agents[0].id))}).catch(e=>{t||v(e.message)}).finally(()=>{t||f(!1)}),()=>{t=!0}},[a]);(0,Y.useEffect)(()=>Z(),[Z]);let Q=(0,Y.useCallback)(t=>{let n=!1;return g(!0),c(null),fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.bodyLoadFailed`,{status:t.status}));return t.json()}).then(e=>{n||c(e.body)}).catch(e=>{n||v(e.message)}).finally(()=>{n||g(!1)}),()=>{n=!0}},[]);if((0,Y.useEffect)(()=>{if(a)return Q(a)},[a,Q]),l)return(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`catalog.loading`)})});if(y.kind!==`closed`)return(0,X.jsx)(Oe,{agentId:y.kind===`edit`?y.agentId:void 0,initialBody:y.kind===`duplicate`||y.kind===`create`?y.initialBody:void 0,initialName:y.kind===`create`?y.initialName:void 0,draftFromRefine:y.kind===`edit`?y.draftFromRefine:void 0,onClose:()=>b({kind:`closed`}),onSaved:e=>{o(e),b({kind:`closed`}),Z()},onResumeRefine:(e,t,n)=>{b({kind:`closed`}),q&&(me(),J.current={refineId:e},C({kind:`open`,projectId:q,agentId:t,baseBody:n,resumeRefineId:e}))}});if(x.kind===`open`)return(0,X.jsx)(B,{onClose:()=>C({kind:`closed`}),children:(0,X.jsx)(nt,{agentId:x.agentId,baseBody:x.baseBody,resumeRefineId:x.resumeRefineId,onStateChange:e=>{J.current=e},onClose:()=>C({kind:`closed`}),onMinimize:t=>{let n=x.kind===`open`?x.projectId:q;if(!n){C({kind:`closed`});return}let r=x.kind===`open`?x.agentId:``,i=x.kind===`open`?x.baseBody:``;de({kind:`ai-edit`,projectId:n,label:e(`catalog.aiEditChipLabel`,{agentId:r}),restoreRoute:`/agents`,params:{agentId:r,baseBody:i,resumeRefineId:t??void 0}}),C({kind:`closed`})},onApplied:e=>{C({kind:`closed`}),o(e),Z()},onOpenInStudio:(e,t)=>{C({kind:`closed`}),b({kind:`edit`,agentId:x.agentId,draftFromRefine:e})}},`${x.agentId}:${x.resumeRefineId??`fresh`}`)});let he=(()=>{let e=D.trim().toLowerCase();return we.filter(t=>!(M!==`all`&&t.category!==M||F&&!t.tags.includes(F)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),ge=(()=>{let e=new Map;for(let t of we)e.set(t.category,(e.get(t.category)??0)+1);return e})(),_e=()=>{E(!1),j(``),N(`all`),R(null)},ve=()=>(0,X.jsx)(u,{open:T,onOpenChange:e=>{e||_e()},children:(0,X.jsxs)(m,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,X.jsxs)(A,{children:[(0,X.jsxs)(k,{className:`flex items-center gap-2 text-base`,children:[(0,X.jsx)(d,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.templates.title`),(0,X.jsx)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:e(`catalog.templates.countOf`,{shown:he.length,total:we.length})})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e(`catalog.templates.description`)})]}),(0,X.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,X.jsx)(ue,{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,X.jsx)(`input`,{value:D,onChange:e=>j(e.target.value),placeholder:e(`catalog.templates.searchPlaceholder`),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}),D&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>j(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,X.jsx)(P,{className:`w-3.5 h-3.5`})})]}),(0,X.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,X.jsx)(ot,{label:e(`catalog.templates.allCategories`),count:we.length,active:M===`all`,onClick:()=>N(`all`)}),Te.map(e=>(0,X.jsx)(ot,{label:e,count:ge.get(e)??0,active:M===e,onClick:()=>N(e)},e))]}),F&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tagFilter`)}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>R(null),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30`,children:[(0,X.jsx)(I,{className:`w-3 h-3`}),` `,F,(0,X.jsx)(P,{className:`w-3 h-3`})]})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:he.length===0?(0,X.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,X.jsxs)(`div`,{className:`max-w-sm`,children:[(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e(`catalog.templates.noMatch`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{j(``),N(`all`),R(null)},className:`text-xs text-accent-primary hover:underline mt-2`,children:e(`catalog.templates.clearFilters`)})]})}):(0,X.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:he.map(t=>(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{_e(),b({kind:`create`,initialBody:t.body,initialName:t.nameHint})},className:`group text-left p-4 rounded-lg border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent/40 hover:shadow-sm transition-all`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,X.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:t.emoji}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-accent-primary truncate`,children:t.label}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:t.category})]})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:t.blurb}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:t.tags.slice(0,5).map(e=>(0,X.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),R(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),R(e))},className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/50 text-muted-foreground hover:bg-accent-primary/20 hover:text-accent-primary cursor-pointer transition-colors `+(F===e?`bg-accent-primary/20 text-accent-primary`:``),children:e},e))}),(0,X.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,X.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:t.nameHint}),(0,X.jsx)(`span`,{className:`text-[10px] text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity`,children:e(`catalog.templates.openInStudio`)})]})]},t.id))})}),(0,X.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tip`)}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:_e,children:e(`common:actions.cancel`)})]})]})}),ye=()=>(0,X.jsx)(u,{open:te,onOpenChange:e=>{!e&&!G&&(V(!1),ce(null))},children:(0,X.jsxs)(m,{className:`max-w-lg`,children:[(0,X.jsx)(A,{children:(0,X.jsxs)(k,{className:`flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.generate.title`)]})}),(0,X.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.agentIdLabel`)}),(0,X.jsx)(z,{value:H,onChange:e=>re(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:G}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,X.jsx)(i,{t:e,i18nKey:`catalog.generate.agentIdHint`,components:{code:(0,X.jsx)(`code`,{})}})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.descriptionLabel`)}),(0,X.jsx)(`textarea`,{value:ie,onChange:e=>ae(e.target.value),placeholder:e(`catalog.generate.descriptionPlaceholder`),className:`w-full text-sm p-2 rounded border border-border bg-background min-h-[120px] resize-y`,disabled:G})]}),se&&(0,X.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:se}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:(0,X.jsx)(i,{t:e,i18nKey:`catalog.generate.note`,components:{code:(0,X.jsx)(`code`,{})}})})]}),(0,X.jsxs)(p,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>V(!1),disabled:G,children:e(`common:actions.cancel`)}),(0,X.jsx)(W,{size:`sm`,onClick:be,disabled:G||!H.trim()||!ie.trim(),children:G?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,e(`catalog.generate.generating`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.generate.generateButton`)]})})]})]})}),be=async()=>{oe(!0),ce(null);try{let t=await fetch(`${K()}/profiles/catalog/generate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:H.trim(),description:ie.trim()})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`catalog.errors.generateFailed`,{status:t.status}))}let n=await t.json();V(!1),b({kind:`create`,initialBody:n.draft,initialName:H.trim()})}catch(e){ce(e.message)}finally{oe(!1)}},xe=async t=>{try{let n=await fetch(`${K()}/profiles/catalog/${encodeURIComponent(t)}`);if(!n.ok)throw Error(e(`catalog.errors.agentLoadFailed`,{status:n.status}));b({kind:`duplicate`,from:t,initialBody:(await n.json()).body})}catch(e){v(e.message)}};if(n.length===0)return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,X.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`catalog.empty.title`)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:(0,X.jsx)(i,{t:e,i18nKey:`catalog.empty.body`,values:{command:`npx specrails-core@latest update`},components:{code:(0,X.jsx)(`code`,{className:`text-foreground`})}})}),(0,X.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:()=>V(!0),children:[(0,X.jsx)(U,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.generateWithClaude`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>E(!0),children:[(0,X.jsx)(d,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.template`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>b({kind:`create`}),children:[(0,X.jsx)(O,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.blank`)]})]})]})}),ve(),ye()]});let Se=n.filter(e=>e.kind===`upstream`),Ce=n.filter(e=>e.kind===`custom`),$=n.find(e=>e.id===a);return(0,X.jsxs)(X.Fragment,{children:[ve(),ye(),(0,X.jsxs)(`div`,{className:`flex h-full`,children:[(0,X.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,X.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:e(`catalog.sidebar.title`)}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:e(`catalog.sidebar.createLabel`)}),(0,X.jsxs)(`div`,{className:`flex gap-1`,children:[(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>E(!0),title:e(`catalog.actions.templateTitle`),children:[(0,X.jsx)(d,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.template`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>V(!0),title:e(`catalog.actions.generateWithClaude`),children:[(0,X.jsx)(U,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.generate`)]}),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>b({kind:`create`}),title:e(`catalog.actions.blankTitle`),children:[(0,X.jsx)(O,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.blank`)]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,X.jsx)(st,{title:e(`catalog.sections.upstream`,{count:Se.length}),description:e(`catalog.sections.upstreamDescription`),children:Se.map(e=>(0,X.jsx)(ct,{agent:e,selected:e.id===a,onSelect:()=>o(e.id)},e.id))}),(0,X.jsx)(st,{title:e(`catalog.sections.custom`,{count:Ce.length}),description:e(`catalog.sections.customDescription`),children:Ce.length===0?(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:e(`catalog.sections.noCustomAgents`)}):Ce.map(e=>(0,X.jsx)(ct,{agent:e,selected:e.id===a,onSelect:()=>o(e.id)},e.id))})]})]}),(0,X.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[_&&(0,X.jsx)(`div`,{className:`m-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:_}),$&&(0,X.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:$.id}),(0,X.jsx)(lt,{kind:$.kind}),$.model&&(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:e(`catalog.detail.defaultModel`,{model:$.model})})]}),$.description&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:$.description})]}),(0,X.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>void xe($.id),children:[(0,X.jsx)(ee,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.duplicate`)]}),$.kind===`custom`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,onClick:()=>b({kind:`edit`,agentId:$.id}),children:[(0,X.jsx)(ne,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.edit`)]}),(0,X.jsxs)(W,{size:`sm`,onClick:async()=>{if(q)try{let e=await fetch(`${K()}/profiles/catalog/${encodeURIComponent($.id)}`);if(!e.ok)throw Error(`Load failed: ${e.status}`);let t=await e.json();me(),J.current={refineId:null},C({kind:`open`,projectId:q,agentId:$.id,baseBody:t.body})}catch(e){v(e.message)}},title:e(`catalog.detail.aiEditTitle`),children:[(0,X.jsx)(pe,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`catalog.detail.aiEdit`)]})]})]})]}),(0,X.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,X.jsxs)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:[`.claude/agents/`,$.id,`.md`]}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:$.kind===`upstream`?e(`catalog.detail.readOnly`):e(`catalog.detail.editableHint`)})]}),(0,X.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:h?e(`common:states.loading`):s??``})]})]})]})]})]})}function ot({label:e,count:t,active:n,onClick:r}){return(0,X.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-accent-primary/20 border-accent-primary/50 text-accent-primary`:`bg-transparent border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[e,(0,X.jsx)(`span`,{className:`text-[9px] px-1 rounded `+(n?`bg-accent-primary/30`:`bg-muted/60`),children:t})]})}function st({title:e,description:t,children:n}){return(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,X.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function ct({agent:e,selected:t,onSelect:n}){return(0,X.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,X.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,X.jsx)(lt,{kind:e.kind})]})}function lt({kind:e}){let{t}=w(`agents`);return(0,X.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 `+(e===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:t(e===`custom`?`catalog.kind.custom`:`catalog.kind.upstream`)})}var ut=[{days:7},{days:30},{days:90}];function dt(){let{t:e}=w(`agents`),[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(30),[a,o]=(0,Y.useState)(!0);if((0,Y.useEffect)(()=>{let e=!1;return o(!0),fetch(`${K()}/profiles/analytics?windowDays=${r}`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&n(t)}).catch(()=>{}).finally(()=>{e||o(!1)}),()=>{e=!0}},[r]),a&&!t)return null;if(!t||t.rows.length===0)return(0,X.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitleEmpty`)})]}),(0,X.jsx)(`div`,{className:`flex gap-0.5`,children:ut.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>i(t.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(r===t.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e(`usage.windowLabel`,{days:t.days})},t.days))})]}),(0,X.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:e(`usage.empty`)})]});let s=Math.max(...t.rows.map(e=>e.jobs),1);return(0,X.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitle`,{count:t.windowDays})})]}),(0,X.jsx)(`div`,{className:`flex gap-0.5`,children:ut.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>i(t.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(r===t.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e(`usage.windowLabel`,{days:t.days})},t.days))})]}),(0,X.jsx)(`div`,{className:`p-4 space-y-2`,children:t.rows.map(t=>(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:t.profileName}),(0,X.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-accent-primary/70`,style:{width:`${Math.max(6,Math.round(t.jobs/s*100))}%`}})}),(0,X.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,X.jsxs)(`span`,{title:e(`usage.jobsTooltip`),children:[(0,X.jsx)(`span`,{className:`text-foreground font-mono`,children:t.jobs}),` `,e(`usage.jobsLabel`,{count:t.jobs})]}),(0,X.jsxs)(`span`,{title:e(`usage.successRateTooltip`),children:[(0,X.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(t.successRate*100),`%`]}),` `,e(`usage.okSuffix`)]}),t.avgDurationMs!=null&&(0,X.jsx)(`span`,{title:e(`usage.avgDurationTooltip`),children:(0,X.jsx)(`span`,{className:`text-foreground font-mono`,children:ft(t.avgDurationMs)})}),t.avgTokens!=null&&(0,X.jsxs)(`span`,{title:e(`usage.avgTokensTooltip`),children:[(0,X.jsx)(`span`,{className:`text-foreground font-mono`,children:pt(t.avgTokens)}),` `,e(`usage.tokensSuffix`)]})]})]},t.profileName))})]})}function ft(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 pt(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var mt=`specrails-desktop:agents-tab`;function ht(){try{let e=localStorage.getItem(mt);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function gt(){let{t:e}=w(`agents`),[n,r]=(0,Y.useState)(()=>ht()),a=e=>{r(e);try{localStorage.setItem(mt,e)}catch{}},[o,s]=(0,Y.useState)(null),{activeProjectId:c}=le(),{pendingRestores:l}=t(),u=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{if(!c)return;let e=l.some(e=>e.kind===`ai-edit`&&e.projectId===c);e&&!u.current&&n!==`catalog`&&a(`catalog`),u.current=e},[l,c,n]),(0,Y.useEffect)(()=>{let e=!1;return fetch(`${K()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&s(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,X.jsxs)(`div`,{className:`flex flex-col h-full`,children:[o!==null&&!o.profileAware&&(0,X.jsxs)(`div`,{className:`flex-shrink-0 flex items-start gap-3 px-6 py-3 border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10`,children:[(0,X.jsx)(F,{className:`w-4 h-4 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`text-xs`,children:[(0,X.jsx)(`div`,{className:`font-medium text-yellow-500 aurora-light:text-accent-warning`,children:e(`page.banner.title`,{required:o.required})}),(0,X.jsx)(`div`,{className:`text-yellow-500/80 aurora-light:text-accent-warning mt-0.5`,children:(0,X.jsx)(i,{t:e,i18nKey:`page.banner.body`,values:{version:o.version??e(`page.banner.unknownVersion`),command:`npx specrails-core@latest update`},components:{code:(0,X.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20 aurora-light:bg-accent-warning/20`})}})})]})]}),(0,X.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,X.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`page.title`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`page.subtitle`)})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,X.jsx)(vt,{active:n===`profiles`,onClick:()=>a(`profiles`),children:e(`page.tabs.profiles`)}),(0,X.jsx)(vt,{active:n===`usage`,onClick:()=>a(`usage`),children:e(`page.tabs.usage`)}),(0,X.jsx)(vt,{active:n===`catalog`,onClick:()=>a(`catalog`),children:e(`page.tabs.catalog`)})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[n===`profiles`&&(0,X.jsx)(Ce,{}),n===`usage`&&(0,X.jsx)(_t,{}),n===`catalog`&&(0,X.jsx)(at,{})]})]})}function _t(){return(0,X.jsx)(`div`,{className:`min-h-full`,children:(0,X.jsx)(dt,{})})}function vt({active:e,children:t,onClick:n}){return(0,X.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{gt as default};