specrails-desktop 2.44.2 → 2.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/README.md +2 -0
  2. package/client/dist/assets/{ActivityFeedPage-CL1BUXoj.js → ActivityFeedPage-CsHQPpvl.js} +1 -1
  3. package/client/dist/assets/AgentBrowserCapture-BVcCK7x0.js +1 -0
  4. package/client/dist/assets/AgentModeAnalyticsPane-C5F3m29G.js +2 -0
  5. package/client/dist/assets/AgentModeCodePane-C5QuKsu0.js +2 -0
  6. package/client/dist/assets/AgentModeJobsPane-rnD-EPMd.js +1 -0
  7. package/client/dist/assets/{AgentsPage-DbLezyI6.js → AgentsPage-DiyJWZcU.js} +3 -3
  8. package/client/dist/assets/{AnalyticsPage-DTsg-N5z.js → AnalyticsPage-Dkmb0dnd.js} +1 -1
  9. package/client/dist/assets/CodePage-C0dH99-t.js +3 -0
  10. package/client/dist/assets/{DesktopAnalyticsPage-Y0Z1ryQr.js → DesktopAnalyticsPage-DuTjr2n8.js} +1 -1
  11. package/client/dist/assets/{DocsDialog-KeCOxvGH.js → DocsDialog-BVZJZHVR.js} +1 -1
  12. package/client/dist/assets/{DocsPage-Bt1PgYPO.js → DocsPage-D6KHTv8V.js} +1 -1
  13. package/client/dist/assets/{ExportDropdown-DczgU4at.js → ExportDropdown-pWZGYCv3.js} +1 -1
  14. package/client/dist/assets/InteractiveJobComposer-Ck3PQxjN.js +19 -0
  15. package/client/dist/assets/JobDetailModal-DkoMH3ie.js +1 -0
  16. package/client/dist/assets/JobDetailPage-CBVivcl2.js +1 -0
  17. package/client/dist/assets/JobsPage-CzxEeca9.js +1 -0
  18. package/client/dist/assets/{LoopBuilderPage-CqC4hbXb.js → LoopBuilderPage-CtmOE4-b.js} +2 -2
  19. package/client/dist/assets/{LoopPreviewModal-T0zuFv6y.js → LoopPreviewModal-BYeLjQbr.js} +1 -1
  20. package/client/dist/assets/{LoopsPage-DrQGcZv2.js → LoopsPage-6iW7g25k.js} +1 -1
  21. package/client/dist/assets/{MinimizedChatsContext-C843Y13h.js → MinimizedChatsContext-B6wVevPq.js} +1 -1
  22. package/client/dist/assets/PluginsPage-Bf1z3WPF.js +2 -0
  23. package/client/dist/assets/ProjectSettingsDialog-DsCRIc4v.js +1 -0
  24. package/client/dist/assets/{RepositoryDeliveries-bgIHE8ep.js → RepositoryDeliveries-BQm_3TO8.js} +1 -1
  25. package/client/dist/assets/{RepositoryScopeSelector-CZ_U_R3U.js → RepositoryScopeSelector-DnAFtjTz.js} +1 -1
  26. package/client/dist/assets/{ReviewPacketPage-DbKO6pT8.js → ReviewPacketPage-CaXAwtR7.js} +1 -1
  27. package/client/dist/assets/TemplatePreviewModal-9aRFpJ_J.js +1 -0
  28. package/client/dist/assets/{TicketDetailModalContext-BbRA6cb7.js → TicketDetailModalContext-B1X5glzV.js} +1 -1
  29. package/client/dist/assets/{Trans-mjFZpHw1.js → Trans-BwLgX6n7.js} +1 -1
  30. package/client/dist/assets/agentRuntime-BUagD2I_.js +1 -0
  31. package/client/dist/assets/agentRuntime-BkL70WtX.js +1 -0
  32. package/client/dist/assets/agentRuntime-CWXVqgqE.js +1 -0
  33. package/client/dist/assets/agentRuntime-CvNBdUAe.js +1 -0
  34. package/client/dist/assets/agentRuntime-D4RmeuNY.js +1 -0
  35. package/client/dist/assets/agentRuntime-DTidBWKg.js +1 -0
  36. package/client/dist/assets/agentRuntime-DhKYfyaU.js +1 -0
  37. package/client/dist/assets/agentRuntime-LL8_GLx9.js +1 -0
  38. package/client/dist/assets/format-duration-NJVPOPBG.js +1 -0
  39. package/client/dist/assets/{formatDistanceToNow-BIL-HxGy.js → formatDistanceToNow-CeZv93iR.js} +1 -1
  40. package/client/dist/assets/{getTimezoneOffsetInMilliseconds-Cs9z2sdO.js → getTimezoneOffsetInMilliseconds-DxAkjvJb.js} +1 -1
  41. package/client/dist/assets/index-Cfh9aaep.css +2 -0
  42. package/client/dist/assets/index-DYoyDWim.js +76 -0
  43. package/client/dist/assets/{jira-api-B2BBZQTx.js → jira-api-ChjVGJx_.js} +1 -1
  44. package/client/dist/assets/narration-4OSg0b5-.js +1 -0
  45. package/client/dist/assets/narration-BPMOQPFe.js +1 -0
  46. package/client/dist/assets/narration-BSldQfjd.js +1 -0
  47. package/client/dist/assets/narration-CvQdWdR5.js +1 -0
  48. package/client/dist/assets/narration-D-e9ssxA.js +1 -0
  49. package/client/dist/assets/narration-DKLjXIFI.js +1 -0
  50. package/client/dist/assets/narration-DnrKC3mF.js +1 -0
  51. package/client/dist/assets/narration-Dypjxeel.js +1 -0
  52. package/client/dist/assets/{project-repositories-xSqimlaj.js → project-repositories-BvBj9XH9.js} +1 -1
  53. package/client/dist/assets/{provider-capabilities-B-wOHfLP.js → provider-capabilities-CXipwrXJ.js} +1 -1
  54. package/client/dist/assets/{settings-2Yx_9yJM.js → settings-B3rWEwOx.js} +1 -1
  55. package/client/dist/assets/{settings-BLOsrXEw.js → settings-BcVoiMyw.js} +1 -1
  56. package/client/dist/assets/settings-BlYvaQ7w.js +1 -0
  57. package/client/dist/assets/{settings-DPjNiUsS.js → settings-CD5uEBiL.js} +1 -1
  58. package/client/dist/assets/{settings-CpKwTew1.js → settings-CyhS0DLJ.js} +1 -1
  59. package/client/dist/assets/{settings-FIqwhTup.js → settings-DCMFUGDs.js} +1 -1
  60. package/client/dist/assets/{settings-C6s9PtRD.js → settings-DEgcA0jd.js} +1 -1
  61. package/client/dist/assets/{settings-NSWQjY5B.js → settings-DmbYKyMJ.js} +1 -1
  62. package/client/dist/assets/{spending-DXOcv1tn.js → spending-DNM6NAoA.js} +1 -1
  63. package/client/dist/assets/{useDesktop-gVGoWWiY.js → useDesktop-mxHVQOdx.js} +1 -1
  64. package/client/dist/assets/useSharedWebSocket-DnxHj8jP.js +2 -0
  65. package/client/dist/index.html +19 -17
  66. package/docs/README.md +1 -0
  67. package/docs/internals/README.md +2 -0
  68. package/docs/internals/agent-runtime-framework-evaluation.md +208 -0
  69. package/docs/internals/programmatic-agent-runtime-validation.md +72 -0
  70. package/docs/internals/programmatic-agent-runtime.md +140 -0
  71. package/package.json +1 -1
  72. package/server/dist/agent-mcp-config.js +5 -0
  73. package/server/dist/agent-operator-prompt.js +2 -2
  74. package/server/dist/agent-runtime-accounting.js +73 -0
  75. package/server/dist/agent-runtime-bridge.js +231 -0
  76. package/server/dist/agent-runtime-controls-router.js +86 -0
  77. package/server/dist/agent-runtime-controls.js +341 -0
  78. package/server/dist/agent-runtime-loader.js +91 -0
  79. package/server/dist/agent-runtime-metrics.js +46 -0
  80. package/server/dist/agent-runtime-paths.js +12 -0
  81. package/server/dist/agent-runtime-repositories.js +37 -0
  82. package/server/dist/agent-runtime-settings-router.js +61 -0
  83. package/server/dist/agent-runtime-settings.js +239 -0
  84. package/server/dist/agent-runtime-settlement.js +133 -0
  85. package/server/dist/agent-runtime-verification-suggestions.js +119 -0
  86. package/server/dist/contract-refine-runner.js +7 -7
  87. package/server/dist/core-completion.js +8 -5
  88. package/server/dist/core-execution.js +17 -8
  89. package/server/dist/core-node-runtime.js +12 -0
  90. package/server/dist/desktop-router.js +26 -0
  91. package/server/dist/job-listing.js +7 -3
  92. package/server/dist/loop-command-catalog.js +2 -2
  93. package/server/dist/loop-executors.js +44 -2
  94. package/server/dist/loop-factory.js +1 -1
  95. package/server/dist/loop-run-manager.js +62 -28
  96. package/server/dist/mcp/tools/specs.js +7 -4
  97. package/server/dist/multi-repo-execution.js +1 -0
  98. package/server/dist/project-registry.js +9 -0
  99. package/server/dist/project-router-jobs.js +8 -2
  100. package/server/dist/project-router-settings.js +4 -0
  101. package/server/dist/project-router-tickets.js +4 -4
  102. package/server/dist/providers/runtime.js +6 -0
  103. package/server/dist/rail-isolated-launch.js +18 -0
  104. package/server/dist/rails-router.js +4 -1
  105. package/server/dist/runtime-role-prompts-router.js +25 -0
  106. package/server/dist/schemas/agent-runtime.schema.json +60 -0
  107. package/server/dist/worktree-overlay.js +32 -1
  108. package/client/dist/assets/AgentBrowserCapture-BQem50z4.js +0 -1
  109. package/client/dist/assets/AgentModeAnalyticsPane-BC_xbT_l.js +0 -2
  110. package/client/dist/assets/AgentModeCodePane-DK-q3K6Y.js +0 -2
  111. package/client/dist/assets/AgentModeJobsPane-C7ELTPC1.js +0 -1
  112. package/client/dist/assets/CodePage-DwgbeqQ_.js +0 -3
  113. package/client/dist/assets/InteractiveJobComposer-BcR6xlHU.js +0 -19
  114. package/client/dist/assets/JobDetailModal-DKA_DUHe.js +0 -1
  115. package/client/dist/assets/JobDetailPage-vaOcE-cI.js +0 -1
  116. package/client/dist/assets/JobsPage-Bwoe-Fb0.js +0 -1
  117. package/client/dist/assets/PluginsPage-CTUHX_Lu.js +0 -2
  118. package/client/dist/assets/ProjectSettingsDialog-DeL8md1s.js +0 -1
  119. package/client/dist/assets/TemplatePreviewModal-_CgCCV7L.js +0 -1
  120. package/client/dist/assets/index-Bfj8HvX1.css +0 -2
  121. package/client/dist/assets/index-UnaJTMIy.js +0 -76
  122. package/client/dist/assets/narration-B-ynWTpn.js +0 -1
  123. package/client/dist/assets/narration-Bj_laZwg.js +0 -1
  124. package/client/dist/assets/narration-BxHpmMv_.js +0 -1
  125. package/client/dist/assets/narration-C1Px0-0j.js +0 -1
  126. package/client/dist/assets/narration-CAXhGbzM.js +0 -1
  127. package/client/dist/assets/narration-DQ1l_Kq6.js +0 -1
  128. package/client/dist/assets/narration-XISXwqZd.js +0 -1
  129. package/client/dist/assets/narration-kwzfglQo.js +0 -1
  130. package/client/dist/assets/settings-CCNZN5Q-.js +0 -1
  131. package/client/dist/assets/useSharedWebSocket-DbGL_YOt.js +0 -2
package/README.md CHANGED
@@ -8,6 +8,8 @@ Specrails Desktop is a local application for turning software specifications int
8
8
 
9
9
  [specrails-core](https://github.com/fjpulidop/specrails-core) supplies the provider workflows and agents. Desktop adds the interface, execution lifecycle, history and project management.
10
10
 
11
+ Projects can opt into the [programmatic agent runtime](docs/internals/programmatic-agent-runtime.md) to run Core's explicit phases with per-role Claude, Codex, Gemini, Kimi or local/API providers. The source feature requires a paired Core build; the guide covers setup, recovery and delivery ownership.
12
+
11
13
  This README describes the current source tree. Published packages do not include unmerged changes; check the [release notes](https://github.com/fjpulidop/specrails-desktop/releases) for the features in your installed version.
12
14
 
13
15
  ## Start using Specrails
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{h as r,r as i}from"./useSharedWebSocket-DbGL_YOt.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{a as o,r as s}from"./useDesktop-gVGoWWiY.js";import{t as c}from"./circle-x-CMYsN4ZH.js";import{t as l}from"./loader-circle-DcygOQpC.js";import{t as u}from"./zap-CHo3aCD1.js";import{Lt as d,jt as f,zt as p}from"./index-UnaJTMIy.js";var m=e(t(),1);function h(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 g({activeProjectId:e,limit:t=50}){let[n,a]=(0,m.useState)([]),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(!0),d=(0,m.useRef)(e);(0,m.useEffect)(()=>{d.current=e},[e]);let{registerHandler:f,unregisterHandler:p}=i();(0,m.useEffect)(()=>{if(!e){a([]),u(!0);return}let n=!1;c(!0),a([]),u(!0);async function r(){let e=o();try{let r=await fetch(`${e}/activity?limit=${t}`);if(!r.ok||n)return;let i=await r.json();if(n)return;a(i),u(i.length===t)}catch{}finally{n||c(!1)}}return r(),()=>{n=!0}},[e,t]);let g=(0,m.useCallback)(async()=>{if(s||!l)return;c(!0);let e=o(),n=d.current;try{a(r=>{let i=r[r.length-1];if(!i)return r;let o=encodeURIComponent(i.timestamp);return fetch(`${e}/activity?limit=${t}&before=${o}`).then(e=>e.json()).then(e=>{if(d.current!==n){c(!1);return}a(t=>h([...t,...e])),u(e.length===t),c(!1)}).catch(()=>c(!1)),r})}catch{c(!1)}},[s,l,t]),_=(0,m.useCallback)(e=>{let t=e,n=d.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&&a(t=>h([...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:r.t(`activity:feed.phaseCommand`,{phase:t.phase,state:t.state}),timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};a(t=>h([e,...t]))}}},[]);return(0,m.useLayoutEffect)(()=>(f(`activity`,_),()=>p(`activity`)),[_,f,p]),{items:n,loading:s,hasMore:l,loadMore:g}}var _=n();function v(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 y({type:e}){switch(e){case`job_completed`:return(0,_.jsx)(f,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,_.jsx)(c,{className:`w-4 h-4 text-red-500 aurora-light:text-destructive flex-shrink-0`});case`job_canceled`:return(0,_.jsx)(d,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,_.jsx)(u,{className:`w-4 h-4 text-blue-500 aurora-light:text-accent-info flex-shrink-0`})}}function b(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 x(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 S(){let{t:e}=a(`activity`),{activeProjectId:t}=s(),{items:n,loading:r,hasMore:i,loadMore:o}=g({activeProjectId:t}),c=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&i&&!r&&o()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[i,r,o]),(0,_.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,_.jsx)(p,{className:`w-4 h-4 text-muted-foreground`}),(0,_.jsx)(`h1`,{className:`text-sm font-medium`,children:e(`feed.title`)})]}),(0,_.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[r&&n.length===0?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):n.length===0?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,_.jsx)(p,{className:`w-8 h-8 opacity-40`}),(0,_.jsx)(`p`,{className:`text-sm`,children:e(`feed.emptyTitle`)}),(0,_.jsx)(`p`,{className:`text-xs opacity-70`,children:e(`feed.emptyHint`)})]}):(0,_.jsx)(`ul`,{className:`divide-y divide-border/50`,children:n.map(t=>(0,_.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,_.jsx)(y,{type:t.type}),(0,_.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,_.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:t.jobCommand,children:t.jobCommand}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,_.jsx)(`span`,{className:`text-xs font-medium ${x(t.type)}`,children:b(t.type,e)}),t.costUsd!=null&&(0,_.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,t.costUsd.toFixed(4)]})]})]}),(0,_.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:v(t.timestamp,e)})]},`${t.type}:${t.jobId}`))}),(0,_.jsx)(`div`,{ref:c,className:`h-1`}),r&&n.length>0&&(0,_.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!i&&n.length>0&&(0,_.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{S as default};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{h as r,r as i}from"./useSharedWebSocket-DnxHj8jP.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{a as o,r as s}from"./useDesktop-mxHVQOdx.js";import{t as c}from"./circle-x-CMYsN4ZH.js";import{t as l}from"./loader-circle-DcygOQpC.js";import{t as u}from"./zap-CHo3aCD1.js";import{Nt as d,Vt as f,zt as p}from"./index-DYoyDWim.js";var m=e(t(),1);function h(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 g({activeProjectId:e,limit:t=50}){let[n,a]=(0,m.useState)([]),[s,c]=(0,m.useState)(!1),[l,u]=(0,m.useState)(!0),d=(0,m.useRef)(e);(0,m.useEffect)(()=>{d.current=e},[e]);let{registerHandler:f,unregisterHandler:p}=i();(0,m.useEffect)(()=>{if(!e){a([]),u(!0);return}let n=!1;c(!0),a([]),u(!0);async function r(){let e=o();try{let r=await fetch(`${e}/activity?limit=${t}`);if(!r.ok||n)return;let i=await r.json();if(n)return;a(i),u(i.length===t)}catch{}finally{n||c(!1)}}return r(),()=>{n=!0}},[e,t]);let g=(0,m.useCallback)(async()=>{if(s||!l)return;c(!0);let e=o(),n=d.current;try{a(r=>{let i=r[r.length-1];if(!i)return r;let o=encodeURIComponent(i.timestamp);return fetch(`${e}/activity?limit=${t}&before=${o}`).then(e=>e.json()).then(e=>{if(d.current!==n){c(!1);return}a(t=>h([...t,...e])),u(e.length===t),c(!1)}).catch(()=>c(!1)),r})}catch{c(!1)}},[s,l,t]),_=(0,m.useCallback)(e=>{let t=e,n=d.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&&a(t=>h([...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:r.t(`activity:feed.phaseCommand`,{phase:t.phase,state:t.state}),timestamp:t.timestamp,summary:`Phase ${t.phase} is ${t.state}`,costUsd:null};a(t=>h([e,...t]))}}},[]);return(0,m.useLayoutEffect)(()=>(f(`activity`,_),()=>p(`activity`)),[_,f,p]),{items:n,loading:s,hasMore:l,loadMore:g}}var _=n();function v(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 y({type:e}){switch(e){case`job_completed`:return(0,_.jsx)(d,{className:`w-4 h-4 text-green-500 aurora-light:text-accent-success flex-shrink-0`});case`job_failed`:return(0,_.jsx)(c,{className:`w-4 h-4 text-red-500 aurora-light:text-destructive flex-shrink-0`});case`job_canceled`:return(0,_.jsx)(p,{className:`w-4 h-4 text-muted-foreground flex-shrink-0`});default:return(0,_.jsx)(u,{className:`w-4 h-4 text-blue-500 aurora-light:text-accent-info flex-shrink-0`})}}function b(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 x(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 S(){let{t:e}=a(`activity`),{activeProjectId:t}=s(),{items:n,loading:r,hasMore:i,loadMore:o}=g({activeProjectId:t}),c=(0,m.useRef)(null);return(0,m.useEffect)(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0].isIntersecting&&i&&!r&&o()},{threshold:.1});return t.observe(e),()=>t.disconnect()},[i,r,o]),(0,_.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b border-border bg-background/50`,children:[(0,_.jsx)(f,{className:`w-4 h-4 text-muted-foreground`}),(0,_.jsx)(`h1`,{className:`text-sm font-medium`,children:e(`feed.title`)})]}),(0,_.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[r&&n.length===0?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-32`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}):n.length===0?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-48 gap-2 text-muted-foreground`,children:[(0,_.jsx)(f,{className:`w-8 h-8 opacity-40`}),(0,_.jsx)(`p`,{className:`text-sm`,children:e(`feed.emptyTitle`)}),(0,_.jsx)(`p`,{className:`text-xs opacity-70`,children:e(`feed.emptyHint`)})]}):(0,_.jsx)(`ul`,{className:`divide-y divide-border/50`,children:n.map(t=>(0,_.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-accent/30 transition-colors`,children:[(0,_.jsx)(y,{type:t.type}),(0,_.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,_.jsx)(`p`,{className:`text-xs text-foreground truncate`,title:t.jobCommand,children:t.jobCommand}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,_.jsx)(`span`,{className:`text-xs font-medium ${x(t.type)}`,children:b(t.type,e)}),t.costUsd!=null&&(0,_.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`$`,t.costUsd.toFixed(4)]})]})]}),(0,_.jsx)(`span`,{className:`text-xs text-muted-foreground flex-shrink-0 tabular-nums`,children:v(t.timestamp,e)})]},`${t.type}:${t.jobId}`))}),(0,_.jsx)(`div`,{ref:c,className:`h-1`}),r&&n.length>0&&(0,_.jsx)(`div`,{className:`flex justify-center py-3`,children:(0,_.jsx)(l,{className:`w-4 h-4 animate-spin text-muted-foreground`})}),!i&&n.length>0&&(0,_.jsx)(`p`,{className:`text-center text-xs text-muted-foreground py-3`,children:e(`feed.allLoaded`)})]})]})}export{S as default};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{d as r,f as i,m as a,u as o}from"./TicketDetailModalContext-B1X5glzV.js";import{n as s}from"./createLucideIcon-Bjbbp_KS.js";import{s as c}from"./useDesktop-mxHVQOdx.js";import{Ht as l,I as u,K as d,Q as f,Wt as p,b as m,tt as h}from"./index-DYoyDWim.js";var g=e(t(),1),_=n();function v({projectId:e,conversationId:t}){let{t:n}=s(`agent`),{error:v}=p(),y=h(t??`__new-mission__`),{closeBrowser:b,queueCapture:x,browserOwnerId:S,browserUrl:C,setBrowserUrl:w}=d(),{materializeDraftConversation:T}=u(),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!1),[A,j]=(0,g.useState)(`probing`);(0,g.useEffect)(()=>{if(t&&(E||O||A===`screencast`))return f(t)},[t,E,O,A]);let M=(0,g.useMemo)(()=>{if(C)return C;try{return i(localStorage.getItem(`specrails-desktop:agent-browser-url:${e}`)??``)??`about:blank`}catch{return`about:blank`}},[e]);(0,g.useEffect)(()=>{let e=!0;return r().then(t=>{e&&j(t?`native`:`screencast`)}),()=>{e=!1}},[]);let N=(0,g.useMemo)(()=>`agent-${t??`home`}-${Math.round(performance.now())}`,[t]),P=async e=>{k(!0);try{let r=await l(t??(await T()).id,a(e.screenshotDataUrl,`capture-${Date.now()}.png`));x(r),c.success(n(`workspace.browserCaptured`)),b()}catch(e){throw c.error(n(`workspace.uploadFailed`),{description:e instanceof Error?e.message:void 0}),e}finally{k(!1)}};return A===`probing`?null:A===`native`?(0,_.jsx)(o,{ownerId:S??void 0,leaseRevision:y,onBusyChange:D,transferError:v,url:M,onClose:b,onFallback:()=>j(`screencast`),onUrlChange:t=>{if(w(t),i(t)&&t!==`about:blank`)try{localStorage.setItem(`specrails-desktop:agent-browser-url:${e}`,t)}catch{}},confirmLabel:n(`workspace.browserConfirm`),selectLabel:n(`workspace.browserSelectStart`),onCaptured:P}):(0,_.jsx)(m,{open:!0,onClose:b,projectId:e,pendingSpecId:N,confirmLabel:n(`workspace.browserConfirm`),selectLabel:n(`workspace.browserSelectStart`),onCaptured:P})}export{v as AgentBrowserCapture};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/AnalyticsPage-Dkmb0dnd.js","assets/rolldown-runtime-CNC7AqOf.js","assets/jsx-runtime-zu2_FqZY.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/preload-helper-Czpn1I53.js","assets/useSharedWebSocket-DnxHj8jP.js","assets/activity-DiyjsgQV.js","assets/addspec-D2YIQ0GU.js","assets/agent-Bh9K7iEt.js","assets/agentRuntime-D4RmeuNY.js","assets/agents-ms7TwG16.js","assets/agentstudio-CN2pokQu.js","assets/aiedit-iIjz2_Qk.js","assets/analytics-BMzCvrCU.js","assets/attachments-B53PG733.js","assets/browser-CG0PE1j_.js","assets/builder-BTiGnPT0.js","assets/chat-BGD7MXAy.js","assets/code-DaZ-ZwCT.js","assets/commands-BAWSYHjQ.js","assets/common-BrlwEnL7.js","assets/dashboard-BfBir_6o.js","assets/explore-DgBACn39.js","assets/integrations-mB-7zoyT.js","assets/jira-CKJg3HZd.js","assets/jobs-DMPU64ms.js","assets/loops-B7YpGizO.js","assets/mcp-CUAN6ORK.js","assets/narration-Dypjxeel.js","assets/nav-Ch-zHBG5.js","assets/packet-Cx-zRuWn.js","assets/settings-BlYvaQ7w.js","assets/setup-Ba11l2JA.js","assets/specs-DII0C8gw.js","assets/terminal-BAzpHtpY.js","assets/tickets-W6pBmbrX.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-BwLgX6n7.js","assets/useDesktop-mxHVQOdx.js","assets/react-dom-DiWzBDP9.js","assets/spending-DNM6NAoA.js","assets/clsx-CjueKrWZ.js","assets/formatDistanceToNow-CeZv93iR.js","assets/getTimezoneOffsetInMilliseconds-DxAkjvJb.js","assets/provider-capabilities-CXipwrXJ.js","assets/index-DYoyDWim.js","assets/TicketDetailModalContext-B1X5glzV.js","assets/save-B6wGWwBR.js","assets/MinimizedChatsContext-B6wVevPq.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/file-text-BcLCfcWZ.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/git-branch-BRM0F5GN.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/jira-api-ChjVGJx_.js","assets/zap-CHo3aCD1.js","assets/dialog-xXB2q5HJ.js","assets/utils-BC4DHlz2.js","assets/lib-CGdyxIWg.js","assets/button-Ccc9Dc-D.js","assets/RepositoryScopeSelector-DnAFtjTz.js","assets/project-repositories-BvBj9XH9.js","assets/core-B3mKBIh5.js","assets/RepositoryDeliveries-BQm_3TO8.js","assets/format-duration-NJVPOPBG.js","assets/event-Bt7f3wXe.js","assets/index-Cfh9aaep.css","assets/ExportDropdown-pWZGYCv3.js","assets/BarChart-nBOMNfiy.js","assets/value-s-gzBeyF.js"])))=>i.map(i=>d[i]);
2
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./preload-helper-Czpn1I53.js";import{n as i}from"./createLucideIcon-Bjbbp_KS.js";import{t as a}from"./loader-circle-DcygOQpC.js";import{t as o}from"./x-CBMI9ejn.js";import{t as s}from"./utils-BC4DHlz2.js";import{K as c,vt as l,yt as u}from"./index-DYoyDWim.js";var d=e(t(),1),f=n(),p=(0,d.lazy)(()=>r(()=>import(`./AnalyticsPage-Dkmb0dnd.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,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77]))),m=420,h=560;function g(){let{t:e}=i(`agent`),{closeAnalyticsPane:t}=c(),[n,r]=(0,d.useState)(h),[g,_]=(0,d.useState)(!1),v=(0,d.useCallback)(e=>{let t=e.clientX,i=n,a=window.innerWidth-m;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let o=e=>{let n=Math.min(Math.max(i+(t-e.clientX),m),a);r(n)},s=()=>{window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s)},[n]);return(0,f.jsxs)(`div`,{className:s(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,g&&`absolute inset-0 z-30 border-l-0`),style:g?void 0:{width:n,flexShrink:0},"data-testid":`agent-analytics-pane`,children:[(0,f.jsx)(`div`,{className:`relative flex items-center`,children:!g&&(0,f.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:e(`workspace.resizeAnalytics`)})}),(0,f.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:e(`workspace.analytics`)}),(0,f.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>_(e=>!e),"aria-label":e(g?`restore`:`maximize`),title:e(g?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:g?(0,f.jsx)(l,{className:`h-4 w-4`}):(0,f.jsx)(u,{className:`h-4 w-4`})}),(0,f.jsx)(`button`,{type:`button`,onClick:t,"aria-label":e(`workspace.closeAnalytics`),title:e(`workspace.closeAnalytics`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:(0,f.jsx)(o,{className:`h-4 w-4`})})]})]}),(0,f.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,f.jsx)(a,{className:`h-4 w-4 animate-spin`})}),children:(0,f.jsx)(p,{})})})]})}export{g as AgentModeAnalyticsPane};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/CodePage-C0dH99-t.js","assets/rolldown-runtime-CNC7AqOf.js","assets/jsx-runtime-zu2_FqZY.js","assets/react-dom-DiWzBDP9.js","assets/preload-helper-Czpn1I53.js","assets/chunk-KS7C4IRE-DEKu087k.js","assets/TicketDetailModalContext-B1X5glzV.js","assets/useSharedWebSocket-DnxHj8jP.js","assets/activity-DiyjsgQV.js","assets/addspec-D2YIQ0GU.js","assets/agent-Bh9K7iEt.js","assets/agentRuntime-D4RmeuNY.js","assets/agents-ms7TwG16.js","assets/agentstudio-CN2pokQu.js","assets/aiedit-iIjz2_Qk.js","assets/analytics-BMzCvrCU.js","assets/attachments-B53PG733.js","assets/browser-CG0PE1j_.js","assets/builder-BTiGnPT0.js","assets/chat-BGD7MXAy.js","assets/code-DaZ-ZwCT.js","assets/commands-BAWSYHjQ.js","assets/common-BrlwEnL7.js","assets/dashboard-BfBir_6o.js","assets/explore-DgBACn39.js","assets/integrations-mB-7zoyT.js","assets/jira-CKJg3HZd.js","assets/jobs-DMPU64ms.js","assets/loops-B7YpGizO.js","assets/mcp-CUAN6ORK.js","assets/narration-Dypjxeel.js","assets/nav-Ch-zHBG5.js","assets/packet-Cx-zRuWn.js","assets/settings-BlYvaQ7w.js","assets/setup-Ba11l2JA.js","assets/specs-DII0C8gw.js","assets/terminal-BAzpHtpY.js","assets/tickets-W6pBmbrX.js","assets/createLucideIcon-Bjbbp_KS.js","assets/Trans-BwLgX6n7.js","assets/useDesktop-mxHVQOdx.js","assets/save-B6wGWwBR.js","assets/spending-DNM6NAoA.js","assets/MinimizedChatsContext-B6wVevPq.js","assets/sparkles-DrY8hb0X.js","assets/x-CBMI9ejn.js","assets/file-text-BcLCfcWZ.js","assets/circle-x-CMYsN4ZH.js","assets/download-CFHyyHcw.js","assets/git-branch-BRM0F5GN.js","assets/loader-circle-DcygOQpC.js","assets/pencil-C9RkrIPZ.js","assets/square-Ci-PFcFe.js","assets/plus-CsnjfkmX.js","assets/search-Cq_gE3Ik.js","assets/trash-2-BOU3WdZZ.js","assets/triangle-alert-H9T4jAmh.js","assets/jira-api-ChjVGJx_.js","assets/zap-CHo3aCD1.js","assets/dialog-xXB2q5HJ.js","assets/utils-BC4DHlz2.js","assets/clsx-CjueKrWZ.js","assets/lib-CGdyxIWg.js","assets/formatDistanceToNow-CeZv93iR.js","assets/getTimezoneOffsetInMilliseconds-DxAkjvJb.js","assets/button-Ccc9Dc-D.js","assets/RepositoryScopeSelector-DnAFtjTz.js","assets/project-repositories-BvBj9XH9.js","assets/provider-capabilities-CXipwrXJ.js","assets/index-DYoyDWim.js","assets/core-B3mKBIh5.js","assets/RepositoryDeliveries-BQm_3TO8.js","assets/format-duration-NJVPOPBG.js","assets/event-Bt7f3wXe.js","assets/index-Cfh9aaep.css"])))=>i.map(i=>d[i]);
2
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./preload-helper-Czpn1I53.js";import{n as i}from"./createLucideIcon-Bjbbp_KS.js";import{t as a}from"./x-CBMI9ejn.js";import{$ as o,K as s,et as c,vt as l,yt as u}from"./index-DYoyDWim.js";var d=e(t(),1),f=n(),p=(0,d.lazy)(()=>r(()=>import(`./CodePage-C0dH99-t.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,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74]))),m=420,h=560;function g({projectId:e,conversationId:t}){let{t:n}=i(`agent`),{closeCodePane:r}=s(),[g,_]=(0,d.useState)(h),[v,y]=(0,d.useState)(()=>window.innerWidth),[b,x]=(0,d.useState)(!1),S=(0,d.useRef)(null),C=(0,d.useRef)(null),w=Math.max(0,v-Math.min(m,v/2)),T=Math.min(m,w),E=Math.min(w,Math.max(T,g)),D=(0,d.useCallback)(e=>Math.min(w,Math.max(T,e)),[w,T]),O=`${e}:${t}`,k=(0,d.useCallback)(n=>{c(e,t,{path:n})},[e,t]);(0,d.useLayoutEffect)(()=>{let e=S.current,t=e?.parentElement;if(!e||!t)return;let n=()=>{let n=t.getBoundingClientRect().width||t.clientWidth||window.innerWidth,r=0;for(let n of t.children){if(n===e||!(n instanceof HTMLElement))continue;let t=getComputedStyle(n);t.display===`none`||t.position===`absolute`||t.position===`fixed`||Number(t.flexGrow)>0||(r+=n.getBoundingClientRect().width)}y(Math.max(0,n-r))},r=new ResizeObserver(n),i=()=>{r.disconnect(),r.observe(t);for(let n of t.children)n!==e&&r.observe(n);n()},a=new MutationObserver(i);return a.observe(t,{childList:!0}),i(),window.addEventListener(`resize`,n),()=>{r.disconnect(),a.disconnect(),window.removeEventListener(`resize`,n)}},[O]),(0,d.useEffect)(()=>()=>{C.current?.()},[O,b,w]);let A=(0,d.useCallback)(e=>{if(e.button!==0)return;e.preventDefault(),C.current?.();let t=e.clientX,n=E,r=e.pointerId,i=e.currentTarget;try{i.setPointerCapture(r)}catch{}let a=e=>{e.pointerId===r&&_(D(n+t-e.clientX))},o=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,s),window.removeEventListener(`pointercancel`,s),window.removeEventListener(`blur`,o),i.removeEventListener(`lostpointercapture`,o);try{i.hasPointerCapture(r)&&i.releasePointerCapture(r)}catch{}C.current=null},s=e=>{e.pointerId===r&&o()};C.current=o,window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,s),window.addEventListener(`pointercancel`,s),window.addEventListener(`blur`,o),i.addEventListener(`lostpointercapture`,o)},[E,D]);return(0,f.jsxs)(`div`,{ref:S,className:`flex h-full min-w-0 flex-col overflow-hidden border-l border-border bg-background${b?` absolute inset-0 z-30 border-l-0`:` relative`}`,style:b?void 0:{width:E,maxWidth:`100%`,flexShrink:0},"data-testid":`agent-code-pane`,children:[!b&&(0,f.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:A,tabIndex:0,"aria-label":n(`workspace.resizeCode`),"aria-valuemin":Math.round(T),"aria-valuemax":Math.round(w),"aria-valuenow":Math.round(E),onKeyDown:e=>{let t=e.key===`ArrowLeft`?E+32:e.key===`ArrowRight`?E-32:e.key===`Home`?T:e.key===`End`?w:null;t!==null&&(e.preventDefault(),_(D(t)))},className:`absolute inset-y-0 left-0 z-20 w-1.5 cursor-col-resize select-none touch-none hover:bg-accent-primary/20 focus-visible:bg-accent-primary/30 focus-visible:outline-none`,title:n(`workspace.resizeCode`)}),(0,f.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,f.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:n(`workspace.files`)}),(0,f.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,f.jsx)(`button`,{type:`button`,onClick:()=>{C.current?.(),x(e=>!e)},"aria-label":n(b?`restore`:`maximize`),title:n(b?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:b?(0,f.jsx)(l,{className:`h-4 w-4`}):(0,f.jsx)(u,{className:`h-4 w-4`})}),(0,f.jsx)(`button`,{type:`button`,onClick:()=>{C.current?.(),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,f.jsx)(a,{className:`h-4 w-4`})})]})]}),(0,f.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:(0,f.jsx)(d.Suspense,{fallback:(0,f.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:`…`}),children:(0,f.jsx)(p,{embedded:!0,initialRepositoryId:o(e,t).repositoryId,onRepositoryChange:n=>c(e,t,{repositoryId:n}),initialPath:o(e,t).path,onSelectedPathChange:k},O)})})]},O)}export{g as AgentModeCodePane};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{m as r,r as i}from"./useSharedWebSocket-DnxHj8jP.js";import{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{i as o,r as s}from"./useDesktop-mxHVQOdx.js";import{t as c}from"./loader-circle-DcygOQpC.js";import{t as l}from"./x-CBMI9ejn.js";import{t as u}from"./utils-BC4DHlz2.js";import{t as d}from"./formatDistanceToNow-CeZv93iR.js";import{n as f}from"./project-repositories-BvBj9XH9.js";import{C as p,It as m,K as h,vt as g,yt as _}from"./index-DYoyDWim.js";import{n as v,t as y}from"./job-time-BCL7wee9.js";import{JobDetailModal as b}from"./JobDetailModal-DkoMH3ie.js";import{t as x}from"./format-command-C0D9IPmV.js";var S=e(t(),1),C=n(),w=360,T=480,E={running:`running`,completed:`success`,failed:`failed`,canceled:`canceled`,queued:`queued`};function D({projectId:e}){let{t}=a(`agent`),{t:n}=a(`jobs`),{closeJobsPane:D}=h(),{projects:O}=s(),k=O.find(t=>t.id===e)?.provider,[A,j]=(0,S.useState)(T),[M,N]=(0,S.useState)(!1),[P,F]=(0,S.useState)(null),{data:I,isFirstLoad:L,refresh:R}=o({namespace:`agent-jobs`,projectId:e,initialValue:[],fetcher:async()=>{let t=await fetch(`${f(e)}/jobs?limit=50`);return t.ok?(await t.json()).jobs:[]},pollInterval:5e3}),{registerHandler:z,unregisterHandler:B}=i(),V=(0,S.useRef)(e);V.current=e;let H=(0,S.useRef)(R);H.current=R,(0,S.useEffect)(()=>(z(`agent-jobs-pane`,e=>{let t=e;t.type===`queue`&&(t.projectId&&t.projectId!==V.current||H.current())}),()=>B(`agent-jobs-pane`)),[z,B]);let U=(0,S.useCallback)(e=>{let t=e.clientX,n=A,r=window.innerWidth-w;try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}let i=e=>{let i=Math.min(Math.max(n+(t-e.clientX),w),r);j(i)},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)},[A]);return(0,C.jsxs)(`div`,{className:u(`flex h-full flex-col overflow-hidden border-l border-border bg-background`,M&&`absolute inset-0 z-30 border-l-0`),style:M?void 0:{width:A,flexShrink:0},children:[(0,C.jsx)(`div`,{className:`relative flex items-center`,children:!M&&(0,C.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,onPointerDown:U,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,C.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 bg-surface/40 px-3 py-1.5`,children:[(0,C.jsx)(`span`,{className:`text-xs font-medium text-foreground/70`,children:t(`workspace.jobs`)}),(0,C.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,C.jsx)(`button`,{type:`button`,onClick:()=>N(e=>!e),"aria-label":t(M?`restore`:`maximize`),title:t(M?`restore`:`maximize`),className:`rounded-md p-1 text-foreground/60 hover:bg-surface hover:text-foreground`,children:M?(0,C.jsx)(g,{className:`h-4 w-4`}):(0,C.jsx)(_,{className:`h-4 w-4`})}),(0,C.jsx)(`button`,{type:`button`,onClick:D,"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,C.jsx)(l,{className:`h-4 w-4`})})]})]}),(0,C.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:L?(0,C.jsx)(`div`,{className:`flex h-24 items-center justify-center text-muted-foreground`,children:(0,C.jsx)(c,{className:`h-4 w-4 animate-spin`})}):I.length===0?(0,C.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-2 text-center text-muted-foreground`,children:[(0,C.jsx)(m,{className:`h-6 w-6 opacity-40`}),(0,C.jsx)(`p`,{className:`text-xs`,children:t(`workspace.noJobs`)})]}):(0,C.jsx)(`ul`,{className:`space-y-1`,children:I.map(e=>(0,C.jsx)(`li`,{children:(0,C.jsxs)(`button`,{type:`button`,onClick:()=>F(e.id),className:u(`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,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(p,{variant:E[e.status]??`queued`,children:n(`statusLabel.${e.status in E?e.status:`queued`}`)}),e.status===`running`&&(0,C.jsx)(c,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,C.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:(()=>{let t=v(y(e));return t?d(t,{addSuffix:!0,locale:r()}):`—`})()})]}),(0,C.jsx)(`code`,{className:`truncate font-mono text-xs text-foreground/85`,children:x(e.command,k)})]})},e.id))})}),P&&(0,C.jsx)(b,{jobId:P,projectId:e,onClose:()=>F(null)})]})}export{D as AgentModeJobsPane};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{h as i,r as a}from"./useSharedWebSocket-DbGL_YOt.js";import{t as o}from"./Trans-mjFZpHw1.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,r as u,s as d}from"./useDesktop-gVGoWWiY.js";import{n as f,t as p}from"./save-B6wGWwBR.js";import{c as m,d as h,f as g,n as _,r as v,u as y}from"./MinimizedChatsContext-C843Y13h.js";import{n as b,t as x}from"./file-text-BcLCfcWZ.js";import{t as S}from"./loader-circle-DcygOQpC.js";import{t as C}from"./pencil-C9RkrIPZ.js";import{t as w}from"./plus-CsnjfkmX.js";import{t as ee}from"./search-Cq_gE3Ik.js";import{t as T}from"./sparkles-DrY8hb0X.js";import{t as E}from"./trash-2-BOU3WdZZ.js";import{t as D}from"./triangle-alert-H9T4jAmh.js";import{t as O}from"./x-CBMI9ejn.js";import{M as k,a as A,i as j,j as M,l as N,o as P,r as F,t as I}from"./dialog-xXB2q5HJ.js";import{t as L}from"./button-Ccc9Dc-D.js";import{i as R,r as z}from"./provider-capabilities-B-wOHfLP.js";import{A as B,C as V,Ct as H,D as U,E as te,F as ne,H as W,M as re,Mt as ie,N as G,O as ae,Rt as K,S as oe,St as se,T as ce,_ as le,ft as q,ht as ue,it as de,j as J,k as Y,kt as fe,l as pe,mt as me,tt as he,w as ge,y as _e}from"./index-UnaJTMIy.js";import{t as ve}from"./format-command-C0D9IPmV.js";var ye=c(`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`}]]),X=e(t(),1),Z=n(),be=/^[a-z0-9][a-z0-9-]*$/;function xe({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:i,onCancel:a}){let{t:c}=s(`agents`),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(r[0]??``);(0,X.useEffect)(()=>{e&&(t===`edit`&&n?(u(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(u(``),f(r[0]??``)))},[e,t,n,r]);let p=l.split(`,`).map(e=>e.trim()).filter(Boolean),m=p.filter(e=>!be.test(e)),h=p.length>0&&m.length===0&&r.includes(d);return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||a()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsxs)(P,{children:[(0,Z.jsx)(N,{children:c(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,Z.jsx)(j,{children:c(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.tagsLabel`)}),(0,Z.jsx)(ne,{autoFocus:!0,value:l,onChange:e=>u(e.target.value),placeholder:`frontend, ui`,"aria-label":c(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Z.jsx)(o,{t:c,i18nKey:`routingRule.tagsHint`,components:{code:(0,Z.jsx)(`code`,{})}})}),m.length>0&&(0,Z.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:c(`routingRule.invalidTags`,{count:m.length,tags:m.join(`, `)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.routeToLabel`)}),(0,Z.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),"aria-label":c(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:c(`routingRule.routeToHint`)})]})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:a,children:c(`common:actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:()=>i(p,d),disabled:!h,children:c(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Se=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),Ce=[`sonnet`,`fable`,`opus`,`haiku`],we=/^[a-z0-9][a-z0-9-]*$/,Te=Ce.map(e=>({value:e,label:e})),Ee=[...Se];function De({profile:e,onChange:t,footer:n,provider:r=e.provider??`claude`,modelCatalog:i=Te,defaultModel:a=i[0]?.value??``,customModelAliases:c=!1,baselineAgents:u=Ee,onValidityChange:d,onSoftWarningsChange:f}){let{t:p}=s(`agentstudio`),[m,h]=(0,X.useState)([]),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(null),S=(0,X.useMemo)(()=>new Set(u),[u]);(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(r)}`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||h(t.agents)}).catch(()=>{e||h([])}),()=>{e=!0}},[r]);let C=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},ee=new Set(e.agents.map(e=>e.id)),T=m.filter(e=>!ee.has(e.id)),E=(0,X.useMemo)(()=>{let t=[];for(let n of S)e.agents.some(e=>e.id===n)||t.push(p(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(p(`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(p(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(p(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!we.test(e));e.length>0&&t.push(p(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,S,p]),D=(0,X.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!S.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e,S]),k=(0,X.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,X.useEffect)(()=>{d&&d(E)},[E,d]),(0,X.useEffect)(()=>{f&&f({agentsMissingRouting:D})},[D,f]);let A=e=>{C(t=>{let n={id:e,model:a},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),_(!1)},j=t=>{let n=e.agents[t];S.has(n.id)||C(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},M=(t,n)=>{if(t===n)return;let r=e.agents.findIndex(e=>e.id===t),i=e.agents.findIndex(e=>e.id===n);if(r<0||i<0)return;let a=V(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)}C(e=>{e.agents=a})},N=re(J(Y,{activationConstraint:{distance:4}}),J(ae,{coordinateGetter:ge})),P=e=>{let{active:t,over:n}=e;n&&M(String(t.id),String(n.id))},F=(e,t)=>{C(n=>{n.agents[e].model=t})},I=(e,t)=>{C(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)}),y(!1)},R=()=>{C(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,H=(e,t)=>{C(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},W=(e,t,n)=>{C(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},ie=e=>{C(t=>{let n=t.routing[e];n&&(z(n)||t.routing.splice(e,1))})},G=(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)||C(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,Z.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Z.jsx)(xe,{open:v,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:I,onCancel:()=>y(!1)}),(0,Z.jsx)(xe,{open:b!==null,mode:`edit`,initial:b!==null&&e.routing[b]&&!(`default`in e.routing[b])?{tags:e.routing[b].tags,agent:e.routing[b].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{b!==null&&(W(b,e,t),x(null))},onCancel:()=>x(null)}),E.length>0&&(0,Z.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,Z.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.validationSummary`,{count:E.length})}),(0,Z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})]}),(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.nameLabel`)}),(0,Z.jsx)(ne,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.descriptionLabel`)}),(0,Z.jsx)(ne,{value:e.description??``,onChange:e=>C(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:p(`profileEditor.descriptionPlaceholder`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:p(`profileEditor.orchestrator.heading`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:[ve(`/specrails:implement`,r),` ·`,` `,ve(`/specrails:batch-implement`,r)]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:p(`profileEditor.orchestrator.description`)})]}),(0,Z.jsx)(Q,{value:e.orchestrator.model,models:i,customModelAliases:c,testId:`profile-orchestrator-model`,onChange:e=>C(t=>{t.orchestrator.model=e})})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>_(e=>!e),disabled:T.length===0,title:T.length===0?p(`profileEditor.agentChain.addDisabledTitle`):p(`profileEditor.agentChain.addTitle`),children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`common:actions.add`)]})]}),g&&(0,Z.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>_(!1),title:p(`common:actions.close`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]}),T.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:p(`profileEditor.agentChain.emptyCatalog`)}):(0,Z.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(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,Z.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Z.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:p(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,Z.jsx)(U,{sensors:N,collisionDetection:B,onDragEnd:P,children:(0,Z.jsx)(oe,{items:e.agents.map(e=>e.id),strategy:te,children:(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Z.jsx)(Oe,{agent:e,required:S.has(e.id),canRemove:!S.has(e.id),models:i,defaultModel:a,customModelAliases:c,onModel:e=>F(t,e),onRemove:()=>j(t)},e.id))})})})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!k&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:R,disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addDefault`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>y(!0),disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addRule`)]})]})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:p(`profileEditor.routing.explainer`)}),D.length>0&&(0,Z.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,Z.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.routing.untargetedTitle`)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(o,{t:p,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:D.join(`, `)},components:{mono:(0,Z.jsx)(`span`,{className:`font-mono`})}})})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Z.jsx)(ke,{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=>H(n,e),onEdit:()=>x(n),onUp:()=>G(n,-1),onDown:()=>G(n,1),onRemove:()=>ie(n)},n)})})]}),n&&(0,Z.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function Oe({agent:e,required:t,canRemove:n,models:r,defaultModel:i,customModelAliases:a,onModel:o,onRemove:c}){let{t:l}=s(`agentstudio`),u=t,d=e.id===`sr-architect`,f=e.id===`sr-merge-resolver`,{attributes:p,listeners:m,setNodeRef:h,transform:g,transition:_,isDragging:v}=ce({id:e.id});return(0,Z.jsxs)(`div`,{ref:h,style:{transform:G.Transform.toString(g),transition:_,opacity:v?.5:void 0,zIndex:v?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,Z.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:l(`profileEditor.agentRow.dragTitle`),"aria-label":l(`profileEditor.agentRow.dragHandleAria`),...p,...m,children:(0,Z.jsx)(H,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),d&&(0,Z.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:l(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,Z.jsx)(me,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,l(`profileEditor.agentRow.pinnedFirst`)]}),f&&(0,Z.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:l(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,Z.jsx)(me,{className:`w-2.5 h-2.5 rotate-45`}),` `,l(`profileEditor.agentRow.pinnedLast`)]}),u&&!d&&!f&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:l(`profileEditor.agentRow.required`)}),(0,Z.jsx)(Q,{value:e.model??i,models:r,customModelAliases:a,testId:`profile-agent-model-${e.id}`,onChange:o}),(0,Z.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:c,disabled:!n,title:l(n?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]})}function ke({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:c,onEdit:l,onUp:u,onDown:d,onRemove:f}){let{t:p}=s(`agentstudio`),m=`default`in e&&e.default===!0;return(0,Z.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,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),m?(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:p(`profileEditor.routingRow.everythingElse`)}):(0,Z.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),m?(0,Z.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":p(`profileEditor.routingRow.defaultTargetAria`),title:p(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,Z.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":p(`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,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:p(`profileEditor.routingRow.editTitle`),"aria-label":p(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,Z.jsx)(C,{className:`w-3 h-3`})}),r&&!n&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:d,title:p(`profileEditor.routingRow.moveDown`),children:(0,Z.jsx)(K,{className:`w-3 h-3`})}),r&&t>1&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:p(`profileEditor.routingRow.moveUp`),children:(0,Z.jsx)(g,{className:`w-3 h-3`})}),i&&(0,Z.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:f,title:p(`common:actions.remove`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]}),m&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:p(`profileEditor.routingRow.coreDefaultTitle`),children:p(`profileEditor.routingRow.coreDefaultBadge`)})]})}function Q({value:e,models:t,customModelAliases:n,testId:r,onChange:i}){return n?(0,Z.jsx)(W,{value:e,options:t,ariaLabel:`Model alias`,testId:r,className:`h-7 w-52 bg-background px-2 text-xs`,onCommit:i}):(0,Z.jsx)(`select`,{value:e,onChange:e=>i(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:(t.some(t=>t.value===e)?t:[...t,{value:e,label:e}]).map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})}function Ae({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:c,onConfirm:l,onCancel:u}){let{t:d}=s(),[f,p]=(0,X.useState)(i);(0,X.useEffect)(()=>{e&&p(i)},[e,i]);let m=f.trim(),h=!o||o.test(m),g=m.length>0&&h;return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||u()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(N,{children:t})}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,Z.jsx)(ne,{autoFocus:!0,value:f,placeholder:r,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g&&l(m)},className:`text-sm font-mono`}),m.length>0&&!h&&c&&(0,Z.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:c})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:u,children:d(`actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:()=>l(m),disabled:!g,children:a??d(`actions.confirm`)})]})]})})}function je({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:c}=s();return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||o()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(N,{children:t})}),n&&(0,Z.jsx)(`div`,{className:`py-2`,children:(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:o,children:c(`actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??c(`actions.confirm`)})]})]})})}var Me={models:Ce.map(e=>({value:e,label:e})),defaultModel:`sonnet`,baselineAgents:[...Se],customModelAliases:!1},Ne={primaryProvider:`claude`,providers:[`claude`],catalogs:{claude:Me}};function Pe(e,t,n){return{schemaVersion:1,name:e,description:``,provider:t,orchestrator:{model:n.defaultModel},agents:n.baselineAgents.map(e=>({id:e,model:n.defaultModel,required:!0})),routing:[{default:!0,agent:`sr-developer`}]}}function Fe(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(Ne),[a,c]=(0,X.useState)(``),[u,f]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!0),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)([]),[ee,T]=(0,X.useState)([]),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),N=a,P=r.catalogs[N]??Me;(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/context`).then(e=>{if(!e.ok)throw Error(`profile context unavailable`);return e.json()}).then(t=>{if(e)return;let n=Array.isArray(t.providers)&&t.providers.length>0?t.providers:[t.primaryProvider||`claude`],r=n.includes(t.primaryProvider)?t.primaryProvider:n[0];i({...t,providers:n,primaryProvider:r}),c(r)}).catch(()=>{e||(i(Ne),c(Ne.primaryProvider))}),()=>{e=!0}},[]);let F=(0,X.useCallback)(async()=>{if(N){_(!0),y(null);try{let t=await fetch(`${l()}/profiles?provider=${encodeURIComponent(N)}`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let r=await t.json();n(r.profiles),f(e=>e&&r.profiles.some(t=>t.name===e)?e:r.profiles[0]?.name??null)}catch(e){y(e.message)}finally{_(!1)}}},[N,e]);(0,X.useEffect)(()=>{N&&F()},[N,F]),(0,X.useEffect)(()=>{if(!u){h(null);return}let t=!1;return fetch(`${l()}/profiles/${encodeURIComponent(u)}?provider=${encodeURIComponent(N)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||h(e.profile)}).catch(e=>{t||y(e.message)}),()=>{t=!0}},[N,u,e]);let I=(0,X.useCallback)(async()=>{x(!0),y(null);try{let t=await fetch(`${l()}/profiles/migrate-from-settings?provider=${encodeURIComponent(N)}`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await F(),f(`default`),d.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{x(!1)}},[N,F,e]),R=(0,X.useCallback)(async t=>{O(!1),x(!0),y(null);try{let n=Pe(t,N,P),r=await fetch(`${l()}/profiles?provider=${encodeURIComponent(N)}`,{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 F(),f(t),d.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.createFailed`),{description:n})}finally{x(!1)}},[P,N,F,e]),B=(0,X.useCallback)(async(t,n)=>{A(null),x(!0),y(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t)}/duplicate?provider=${encodeURIComponent(N)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,provider:N})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await F(),f(n),d.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{x(!1)}},[N,F,e]),V=(0,X.useCallback)(async t=>{M(null),x(!0),y(null);try{let n=await fetch(`${l()}/profiles/${encodeURIComponent(t)}?provider=${encodeURIComponent(N)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}f(e=>e===t?null:e),await F(),d.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{x(!1)}},[N,F,e]),H=(0,X.useCallback)(()=>O(!0),[]),U=(0,X.useCallback)(e=>A({from:e}),[]),te=(0,X.useCallback)(e=>M({name:e}),[]),ne=(0,X.useCallback)(async(t,n)=>{x(!0),y(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t.name)}?provider=${encodeURIComponent(N)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t,provider:N})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}h(t),n.length>0?d.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):d.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{x(!1)}},[N,e]),W=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ae,{open:D,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 R(e),onCancel:()=>O(!1)}),k&&(0,Z.jsx)(Ae,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:k.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${k.from}-copy`,initialValue:`${k.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void B(k.from,e),onCancel:()=>A(null)}),j&&(0,Z.jsx)(je,{open:!0,title:e(`profiles.deleteDialog.title`,{name:j.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void V(j.name),onCancel:()=>M(null)})]});return g?(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,Z.jsxs)(Z.Fragment,{children:[W,(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),r.providers.length>1&&(0,Z.jsx)(`select`,{value:N,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`mb-4 h-8 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,Z.jsx)(`option`,{value:e,children:z(e)},e))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Z.jsxs)(L,{size:`sm`,onClick:I,disabled:b,children:[(0,Z.jsx)(he,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:H,disabled:b,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,Z.jsx)(o,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,Z.jsx)(`code`,{className:`text-foreground`})}})}),v&&(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:v})]})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[W,(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Z.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,Z.jsx)(L,{size:`sm`,variant:`ghost`,onClick:H,disabled:b,children:(0,Z.jsx)(w,{className:`w-3.5 h-3.5`})})]}),r.providers.length>1&&(0,Z.jsx)(`select`,{value:N,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`h-7 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,Z.jsx)(`option`,{value:e,children:z(e)},e))})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,Z.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===u?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>f(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&f(t.name)},children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),U(t.name)},children:(0,Z.jsx)(fe,{className:`w-3 h-3`})}),!t.isDefault&&(0,Z.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(),te(t.name)},children:(0,Z.jsx)(E,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[v&&(0,Z.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:v}),m?(0,Z.jsx)(De,{profile:m,provider:N,modelCatalog:P.models,defaultModel:P.defaultModel,customModelAliases:P.customModelAliases===!0,baselineAgents:P.baselineAgents,onChange:h,onValidityChange:C,onSoftWarningsChange:e=>T(e.agentsMissingRouting),footer:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(L,{size:`sm`,onClick:()=>void ne(m,ee),disabled:b||S.length>0,title:S.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,Z.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),b&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),S.length>0&&(0,Z.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:S.length})})]})},`${N}:${m.name}`):(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.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"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{h as i,r as a}from"./useSharedWebSocket-DnxHj8jP.js";import{t as o}from"./Trans-BwLgX6n7.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,r as u,s as d}from"./useDesktop-mxHVQOdx.js";import{n as f,t as p}from"./save-B6wGWwBR.js";import{c as m,d as h,f as g,n as _,r as v,u as y}from"./MinimizedChatsContext-B6wVevPq.js";import{n as b,t as x}from"./file-text-BcLCfcWZ.js";import{t as S}from"./loader-circle-DcygOQpC.js";import{t as C}from"./pencil-C9RkrIPZ.js";import{t as w}from"./plus-CsnjfkmX.js";import{t as ee}from"./search-Cq_gE3Ik.js";import{t as T}from"./sparkles-DrY8hb0X.js";import{t as E}from"./trash-2-BOU3WdZZ.js";import{t as D}from"./triangle-alert-H9T4jAmh.js";import{t as O}from"./x-CBMI9ejn.js";import{M as k,a as A,i as j,j as M,l as N,o as P,r as F,t as I}from"./dialog-xXB2q5HJ.js";import{t as L}from"./button-Ccc9Dc-D.js";import{i as R,r as z}from"./provider-capabilities-CXipwrXJ.js";import{A as B,Bt as V,D as H,E as U,F as te,L as ne,M as W,N as G,O as re,P as ie,Pt as ae,T as K,Tt as oe,W as se,_t as ce,gt as q,j as le,jt as ue,k as J,mt as Y,ot as de,rt as fe,u as pe,w as me,wt as he,x as ge,y as _e}from"./index-DYoyDWim.js";import{t as ve}from"./format-command-C0D9IPmV.js";var ye=c(`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`}]]),X=e(t(),1),Z=n(),be=/^[a-z0-9][a-z0-9-]*$/;function xe({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:i,onCancel:a}){let{t:c}=s(`agents`),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(r[0]??``);(0,X.useEffect)(()=>{e&&(t===`edit`&&n?(u(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(u(``),f(r[0]??``)))},[e,t,n,r]);let p=l.split(`,`).map(e=>e.trim()).filter(Boolean),m=p.filter(e=>!be.test(e)),h=p.length>0&&m.length===0&&r.includes(d);return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||a()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsxs)(P,{children:[(0,Z.jsx)(N,{children:c(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,Z.jsx)(j,{children:c(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.tagsLabel`)}),(0,Z.jsx)(ne,{autoFocus:!0,value:l,onChange:e=>u(e.target.value),placeholder:`frontend, ui`,"aria-label":c(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Z.jsx)(o,{t:c,i18nKey:`routingRule.tagsHint`,components:{code:(0,Z.jsx)(`code`,{})}})}),m.length>0&&(0,Z.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:c(`routingRule.invalidTags`,{count:m.length,tags:m.join(`, `)})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.routeToLabel`)}),(0,Z.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),"aria-label":c(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:c(`routingRule.routeToHint`)})]})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:a,children:c(`common:actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:()=>i(p,d),disabled:!h,children:c(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var Se=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),Ce=[`sonnet`,`fable`,`opus`,`haiku`],we=/^[a-z0-9][a-z0-9-]*$/,Te=Ce.map(e=>({value:e,label:e})),Ee=[...Se];function De({profile:e,onChange:t,footer:n,provider:r=e.provider??`claude`,modelCatalog:i=Te,defaultModel:a=i[0]?.value??``,customModelAliases:c=!1,baselineAgents:u=Ee,onValidityChange:d,onSoftWarningsChange:f}){let{t:p}=s(`agentstudio`),[m,h]=(0,X.useState)([]),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(null),S=(0,X.useMemo)(()=>new Set(u),[u]);(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(r)}`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||h(t.agents)}).catch(()=>{e||h([])}),()=>{e=!0}},[r]);let C=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},ee=new Set(e.agents.map(e=>e.id)),T=m.filter(e=>!ee.has(e.id)),E=(0,X.useMemo)(()=>{let t=[];for(let n of S)e.agents.some(e=>e.id===n)||t.push(p(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(p(`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(p(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(p(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!we.test(e));e.length>0&&t.push(p(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,S,p]),D=(0,X.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!S.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e,S]),k=(0,X.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,X.useEffect)(()=>{d&&d(E)},[E,d]),(0,X.useEffect)(()=>{f&&f({agentsMissingRouting:D})},[D,f]);let A=e=>{C(t=>{let n={id:e,model:a},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),_(!1)},j=t=>{let n=e.agents[t];S.has(n.id)||C(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},M=(t,n)=>{if(t===n)return;let r=e.agents.findIndex(e=>e.id===t),i=e.agents.findIndex(e=>e.id===n);if(r<0||i<0)return;let a=K(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)}C(e=>{e.agents=a})},N=ie(G(le,{activationConstraint:{distance:4}}),G(B,{coordinateGetter:U})),P=e=>{let{active:t,over:n}=e;n&&M(String(t.id),String(n.id))},F=(e,t)=>{C(n=>{n.agents[e].model=t})},I=(e,t)=>{C(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)}),y(!1)},R=()=>{C(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)=>{C(n=>{let r=n.routing[e];r&&(z(r)||(r.agent=t))})},H=(e,t,n)=>{C(r=>{let i=r.routing[e];i&&(z(i)||(i.tags=t,i.agent=n))})},te=e=>{C(t=>{let n=t.routing[e];n&&(z(n)||t.routing.splice(e,1))})},ae=(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)||C(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,Z.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,Z.jsx)(xe,{open:v,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:I,onCancel:()=>y(!1)}),(0,Z.jsx)(xe,{open:b!==null,mode:`edit`,initial:b!==null&&e.routing[b]&&!(`default`in e.routing[b])?{tags:e.routing[b].tags,agent:e.routing[b].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{b!==null&&(H(b,e,t),x(null))},onCancel:()=>x(null)}),E.length>0&&(0,Z.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,Z.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.validationSummary`,{count:E.length})}),(0,Z.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:E.map((e,t)=>(0,Z.jsx)(`li`,{children:e},t))})]}),(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.nameLabel`)}),(0,Z.jsx)(ne,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.descriptionLabel`)}),(0,Z.jsx)(ne,{value:e.description??``,onChange:e=>C(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:p(`profileEditor.descriptionPlaceholder`)})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:p(`profileEditor.orchestrator.heading`)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:[ve(`/specrails:implement`,r),` ·`,` `,ve(`/specrails:batch-implement`,r)]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:p(`profileEditor.orchestrator.description`)})]}),(0,Z.jsx)(Q,{value:e.orchestrator.model,models:i,customModelAliases:c,testId:`profile-orchestrator-model`,onChange:e=>C(t=>{t.orchestrator.model=e})})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>_(e=>!e),disabled:T.length===0,title:T.length===0?p(`profileEditor.agentChain.addDisabledTitle`):p(`profileEditor.agentChain.addTitle`),children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`common:actions.add`)]})]}),g&&(0,Z.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p(`profileEditor.agentChain.pickFromCatalog`,{n:T.length})}),(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>_(!1),title:p(`common:actions.close`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]}),T.length===0?(0,Z.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:p(`profileEditor.agentChain.emptyCatalog`)}):(0,Z.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:T.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>A(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,Z.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,Z.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:p(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,Z.jsx)(J,{sensors:N,collisionDetection:W,onDragEnd:P,children:(0,Z.jsx)(me,{items:e.agents.map(e=>e.id),strategy:re,children:(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,Z.jsx)(Oe,{agent:e,required:S.has(e.id),canRemove:!S.has(e.id),models:i,defaultModel:a,customModelAliases:c,onModel:e=>F(t,e),onRemove:()=>j(t)},e.id))})})})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Z.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!k&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:R,disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addDefault`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>y(!0),disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addRule`)]})]})]}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:p(`profileEditor.routing.explainer`)}),D.length>0&&(0,Z.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,Z.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.routing.untargetedTitle`)}),(0,Z.jsx)(`div`,{children:(0,Z.jsx)(o,{t:p,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:D.join(`, `)},components:{mono:(0,Z.jsx)(`span`,{className:`font-mono`})}})})]}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,Z.jsx)(ke,{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:()=>x(n),onUp:()=>ae(n,-1),onDown:()=>ae(n,1),onRemove:()=>te(n)},n)})})]}),n&&(0,Z.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function Oe({agent:e,required:t,canRemove:n,models:r,defaultModel:i,customModelAliases:a,onModel:o,onRemove:c}){let{t:l}=s(`agentstudio`),u=t,d=e.id===`sr-architect`,f=e.id===`sr-merge-resolver`,{attributes:p,listeners:m,setNodeRef:h,transform:g,transition:_,isDragging:v}=H({id:e.id});return(0,Z.jsxs)(`div`,{ref:h,style:{transform:te.Transform.toString(g),transition:_,opacity:v?.5:void 0,zIndex:v?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,Z.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:l(`profileEditor.agentRow.dragTitle`),"aria-label":l(`profileEditor.agentRow.dragHandleAria`),...p,...m,children:(0,Z.jsx)(oe,{className:`w-3.5 h-3.5`})}),(0,Z.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),d&&(0,Z.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:l(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,Z.jsx)(q,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,l(`profileEditor.agentRow.pinnedFirst`)]}),f&&(0,Z.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:l(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,Z.jsx)(q,{className:`w-2.5 h-2.5 rotate-45`}),` `,l(`profileEditor.agentRow.pinnedLast`)]}),u&&!d&&!f&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:l(`profileEditor.agentRow.required`)}),(0,Z.jsx)(Q,{value:e.model??i,models:r,customModelAliases:a,testId:`profile-agent-model-${e.id}`,onChange:o}),(0,Z.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:c,disabled:!n,title:l(n?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]})}function ke({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:c,onEdit:l,onUp:u,onDown:d,onRemove:f}){let{t:p}=s(`agentstudio`),m=`default`in e&&e.default===!0;return(0,Z.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,Z.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),m?(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:p(`profileEditor.routingRow.everythingElse`)}):(0,Z.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,Z.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),m?(0,Z.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":p(`profileEditor.routingRow.defaultTargetAria`),title:p(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,Z.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":p(`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,Z.jsx)(`option`,{value:e,children:e},e))}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:p(`profileEditor.routingRow.editTitle`),"aria-label":p(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,Z.jsx)(C,{className:`w-3 h-3`})}),r&&!n&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:d,title:p(`profileEditor.routingRow.moveDown`),children:(0,Z.jsx)(V,{className:`w-3 h-3`})}),r&&t>1&&(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:p(`profileEditor.routingRow.moveUp`),children:(0,Z.jsx)(g,{className:`w-3 h-3`})}),i&&(0,Z.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:f,title:p(`common:actions.remove`),children:(0,Z.jsx)(O,{className:`w-3 h-3`})})]}),m&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:p(`profileEditor.routingRow.coreDefaultTitle`),children:p(`profileEditor.routingRow.coreDefaultBadge`)})]})}function Q({value:e,models:t,customModelAliases:n,testId:r,onChange:i}){return n?(0,Z.jsx)(se,{value:e,options:t,ariaLabel:`Model alias`,testId:r,className:`h-7 w-52 bg-background px-2 text-xs`,onCommit:i}):(0,Z.jsx)(`select`,{value:e,onChange:e=>i(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:(t.some(t=>t.value===e)?t:[...t,{value:e,label:e}]).map(e=>(0,Z.jsx)(`option`,{value:e.value,children:e.label},e.value))})}function Ae({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:c,onConfirm:l,onCancel:u}){let{t:d}=s(),[f,p]=(0,X.useState)(i);(0,X.useEffect)(()=>{e&&p(i)},[e,i]);let m=f.trim(),h=!o||o.test(m),g=m.length>0&&h;return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||u()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(N,{children:t})}),(0,Z.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,Z.jsx)(ne,{autoFocus:!0,value:f,placeholder:r,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g&&l(m)},className:`text-sm font-mono`}),m.length>0&&!h&&c&&(0,Z.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:c})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:u,children:d(`actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:()=>l(m),disabled:!g,children:a??d(`actions.confirm`)})]})]})})}function je({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:c}=s();return(0,Z.jsx)(I,{open:e,onOpenChange:e=>{e||o()},children:(0,Z.jsxs)(F,{movableResizable:!0,className:`max-w-md`,children:[(0,Z.jsx)(P,{children:(0,Z.jsx)(N,{children:t})}),n&&(0,Z.jsx)(`div`,{className:`py-2`,children:(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:o,children:c(`actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??c(`actions.confirm`)})]})]})})}var Me={models:Ce.map(e=>({value:e,label:e})),defaultModel:`sonnet`,baselineAgents:[...Se],customModelAliases:!1},Ne={primaryProvider:`claude`,providers:[`claude`],catalogs:{claude:Me}};function Pe(e,t,n){return{schemaVersion:1,name:e,description:``,provider:t,orchestrator:{model:n.defaultModel},agents:n.baselineAgents.map(e=>({id:e,model:n.defaultModel,required:!0})),routing:[{default:!0,agent:`sr-developer`}]}}function Fe(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(Ne),[a,c]=(0,X.useState)(``),[u,f]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!0),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)([]),[ee,T]=(0,X.useState)([]),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(null),N=a,P=r.catalogs[N]??Me;(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/context`).then(e=>{if(!e.ok)throw Error(`profile context unavailable`);return e.json()}).then(t=>{if(e)return;let n=Array.isArray(t.providers)&&t.providers.length>0?t.providers:[t.primaryProvider||`claude`],r=n.includes(t.primaryProvider)?t.primaryProvider:n[0];i({...t,providers:n,primaryProvider:r}),c(r)}).catch(()=>{e||(i(Ne),c(Ne.primaryProvider))}),()=>{e=!0}},[]);let F=(0,X.useCallback)(async()=>{if(N){_(!0),y(null);try{let t=await fetch(`${l()}/profiles?provider=${encodeURIComponent(N)}`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let r=await t.json();n(r.profiles),f(e=>e&&r.profiles.some(t=>t.name===e)?e:r.profiles[0]?.name??null)}catch(e){y(e.message)}finally{_(!1)}}},[N,e]);(0,X.useEffect)(()=>{N&&F()},[N,F]),(0,X.useEffect)(()=>{if(!u){h(null);return}let t=!1;return fetch(`${l()}/profiles/${encodeURIComponent(u)}?provider=${encodeURIComponent(N)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||h(e.profile)}).catch(e=>{t||y(e.message)}),()=>{t=!0}},[N,u,e]);let I=(0,X.useCallback)(async()=>{x(!0),y(null);try{let t=await fetch(`${l()}/profiles/migrate-from-settings?provider=${encodeURIComponent(N)}`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await F(),f(`default`),d.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{x(!1)}},[N,F,e]),R=(0,X.useCallback)(async t=>{O(!1),x(!0),y(null);try{let n=Pe(t,N,P),r=await fetch(`${l()}/profiles?provider=${encodeURIComponent(N)}`,{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 F(),f(t),d.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.createFailed`),{description:n})}finally{x(!1)}},[P,N,F,e]),B=(0,X.useCallback)(async(t,n)=>{A(null),x(!0),y(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t)}/duplicate?provider=${encodeURIComponent(N)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,provider:N})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await F(),f(n),d.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{x(!1)}},[N,F,e]),V=(0,X.useCallback)(async t=>{M(null),x(!0),y(null);try{let n=await fetch(`${l()}/profiles/${encodeURIComponent(t)}?provider=${encodeURIComponent(N)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}f(e=>e===t?null:e),await F(),d.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{x(!1)}},[N,F,e]),H=(0,X.useCallback)(()=>O(!0),[]),U=(0,X.useCallback)(e=>A({from:e}),[]),te=(0,X.useCallback)(e=>M({name:e}),[]),ne=(0,X.useCallback)(async(t,n)=>{x(!0),y(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t.name)}?provider=${encodeURIComponent(N)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t,provider:N})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}h(t),n.length>0?d.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):d.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;y(n),d.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{x(!1)}},[N,e]),W=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Ae,{open:D,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 R(e),onCancel:()=>O(!1)}),k&&(0,Z.jsx)(Ae,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:k.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${k.from}-copy`,initialValue:`${k.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void B(k.from,e),onCancel:()=>A(null)}),j&&(0,Z.jsx)(je,{open:!0,title:e(`profiles.deleteDialog.title`,{name:j.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void V(j.name),onCancel:()=>M(null)})]});return g?(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,Z.jsxs)(Z.Fragment,{children:[W,(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),r.providers.length>1&&(0,Z.jsx)(`select`,{value:N,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`mb-4 h-8 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,Z.jsx)(`option`,{value:e,children:z(e)},e))}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,Z.jsxs)(L,{size:`sm`,onClick:I,disabled:b,children:[(0,Z.jsx)(fe,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:H,disabled:b,children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,Z.jsx)(o,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,Z.jsx)(`code`,{className:`text-foreground`})}})}),v&&(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:v})]})})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[W,(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Z.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,Z.jsx)(L,{size:`sm`,variant:`ghost`,onClick:H,disabled:b,children:(0,Z.jsx)(w,{className:`w-3.5 h-3.5`})})]}),r.providers.length>1&&(0,Z.jsx)(`select`,{value:N,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`h-7 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,Z.jsx)(`option`,{value:e,children:z(e)},e))})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,Z.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===u?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>f(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&f(t.name)},children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,Z.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),U(t.name)},children:(0,Z.jsx)(ue,{className:`w-3 h-3`})}),!t.isDefault&&(0,Z.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(),te(t.name)},children:(0,Z.jsx)(E,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,Z.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[v&&(0,Z.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:v}),m?(0,Z.jsx)(De,{profile:m,provider:N,modelCatalog:P.models,defaultModel:P.defaultModel,customModelAliases:P.customModelAliases===!0,baselineAgents:P.baselineAgents,onChange:h,onValidityChange:C,onSoftWarningsChange:e=>T(e.agentsMissingRouting),footer:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsxs)(L,{size:`sm`,onClick:()=>void ne(m,ee),disabled:b||S.length>0,title:S.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,Z.jsx)(p,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),b&&(0,Z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),S.length>0&&(0,Z.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:S.length})})]})},`${N}:${m.name}`):(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.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}"
@@ -77,11 +77,11 @@ You are ...
77
77
  - **risk_tolerance**: conservative
78
78
  - **detail_level**: full
79
79
  - **focus_areas**: ...
80
- `}function Be(e,t){let n=e.match(/^---(\r?\n)([\s\S]*?)\r?\n---/);if(!n)return e;let r=n[1],i=/^name:\s*.*$/m.test(n[2])?n[2].replace(/^name:\s*.*$/m,`name: ${t}`):`name: ${t}${r}${n[2]}`;return e.replace(n[0],`---${r}${i}${r}---`)}function Ve(e,t){return e===`kimi`?`.kimi-code/skills/${t}/SKILL.md`:e===`codex`?`.codex/skills/rails/${t}/SKILL.md`:e===`gemini`?`.gemini/agents/${t}.md`:`.claude/agents/${t}.md`}function He({agentId:e,initialBody:t,initialName:n,draftFromRefine:r,provider:i=`claude`,defaultModel:a=`sonnet`,onClose:c,onSaved:u,onResumeRefine:m,automationEnabled:h=!0}){let{t:g}=s(`agentstudio`),_=!e,v=e??n??``,[y,b]=(0,X.useState)(v),[x,C]=(0,X.useState)(t??ze(i,a,v||void 0)),[w,ee]=(0,X.useState)(!_&&!t&&!r),[T,D]=(0,X.useState)(!!r&&!_),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)([]),[P,F]=(0,X.useState)(!1),[I,R]=(0,X.useState)(!!t&&_),[z,B]=(0,X.useState)(!1),[V,H]=(0,X.useState)(``),[U,te]=(0,X.useState)(!1),[W,re]=(0,X.useState)(null),[G,ae]=(0,X.useState)(null),[K,oe]=(0,X.useState)(!1);(0,X.useEffect)(()=>{if(_||t!==void 0)return;if(r){let t=!1;return fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}/refine/${r}?provider=${encodeURIComponent(i)}`).then(e=>{if(!e.ok)throw Error(g(`studio.errors.loadDraftFailed`,{status:e.status}));return e.json()}).then(e=>{!t&&e.draftBody&&(C(e.draftBody),R(!0))}).catch(e=>{t||j(e.message)}).finally(()=>{t||D(!1)}),()=>{t=!0}}let n=!1;return fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`).then(e=>{if(!e.ok)throw Error(g(`studio.errors.loadFailed`,{status:e.status}));return e.json()}).then(e=>{n||C(e.body)}).catch(e=>{n||j(e.message)}).finally(()=>{n||ee(!1)}),()=>{n=!0}},[e,r,t,_,i,g]);let ce=(0,X.useCallback)(()=>{_||fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}/versions?provider=${encodeURIComponent(i)}`).then(e=>e.ok?e.json():{versions:[]}).then(e=>N(e.versions)).catch(()=>N([]))},[e,_,i]);(0,X.useEffect)(()=>{P&&ce()},[P,ce]);let le=/^custom-[a-z0-9][a-z0-9-]*$/.test(y),q=x.trim().length>0,ue=/^---\s*\n[\s\S]*?\n---/.test(x),de=q&&ue&&(!_||le)&&I,J=(0,X.useCallback)(async()=>{k(!0),j(null);try{let t,n=_&&i===`kimi`?Be(x,y):x;if(t=_?await fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(i)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:y,body:n,provider:i})}):await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:x})}),!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??g(`studio.errors.saveFailed`,{status:t.status}))}R(!1),n!==x&&C(n),d.success(g(_?`studio.toasts.agentCreated`:`studio.toasts.agentSaved`),{description:_?y:e}),u&&u(_?y:e)}catch(e){let t=e.message;j(t),d.error(g(_?`studio.toasts.createFailed`:`studio.toasts.saveFailed`),{description:t})}finally{k(!1)}},[e,x,y,_,u,i,g]),Y=(0,X.useCallback)(async()=>{if(!_){oe(!1),k(!0),j(null);try{let t=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??g(`studio.errors.deleteFailed`,{status:t.status}))}d.success(g(`studio.toasts.agentDeleted`),{description:e}),u&&u(e),c()}catch(e){let t=e.message;j(t),d.error(g(`studio.toasts.deleteFailed`),{description:t})}finally{k(!1)}}},[e,_,c,u,i,g]),fe=(0,X.useCallback)(e=>{C(e.body),R(!0),F(!1)},[]),pe=(0,X.useCallback)(async()=>{if(h){te(!0),ae(null),re(null);try{let t=await fetch(`${l()}/profiles/catalog/test?provider=${encodeURIComponent(i)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:_?y||`draft`:e,draftBody:x,sampleTask:V})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??g(`studio.errors.testFailed`,{status:t.status}))}let n=await t.json();re(n)}catch(e){ae(e.message)}finally{te(!1)}}},[e,h,x,y,_,i,V,g]);return w?(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:g(`studio.loadingAgent`)})}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!_&&(0,Z.jsx)(je,{open:K,title:g(`studio.deleteConfirm.title`,{agentId:e}),description:g(`studio.deleteConfirm.description`),confirmLabel:g(`common:actions.delete`),destructive:!0,onConfirm:Y,onCancel:()=>oe(!1)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 border-b border-border`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:c,className:`p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground`,title:g(`common:actions.back`),children:(0,Z.jsx)(f,{className:`w-4 h-4`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground uppercase tracking-wide`,children:g(_?`studio.modeCreate`:`studio.modeEdit`)}),_?(0,Z.jsx)(ne,{value:y,onChange:e=>{let t=e.target.value;b(t),i===`kimi`&&C(e=>Be(e,t||`custom-<name>`)),R(!0)},placeholder:`custom-my-agent`,className:`text-sm font-mono mt-1 max-w-sm`}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-mono`,children:e}),h&&r&&(0,Z.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!m||!e))try{let t=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`);if(!t.ok)return;m(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:g(`studio.resumeAiEditTitle`),children:[(0,Z.jsx)(he,{className:`w-3 h-3`}),` `,g(`studio.resumeAiEdit`)]}),T&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(S,{className:`w-3 h-3 animate-spin`}),` `,g(`studio.loadingAiDraft`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>{B(e=>!e),z||F(!1)},title:g(`studio.testButtonTitle`),children:[(0,Z.jsx)(ye,{className:`w-3.5 h-3.5 mr-1`}),g(`studio.testButton`)]}),!_&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>{F(e=>!e),P||B(!1)},title:g(`studio.historyButtonTitle`),children:[(0,Z.jsx)(se,{className:`w-3.5 h-3.5 mr-1`}),g(`studio.historyButton`)]}),!_&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>oe(!0),disabled:O,className:`text-red-400 hover:text-red-300 aurora-light:text-destructive aurora-light:hover:text-destructive`,children:[(0,Z.jsx)(E,{className:`w-3.5 h-3.5 mr-1`}),g(`common:actions.delete`)]}),(0,Z.jsxs)(L,{size:`sm`,onClick:J,disabled:!de||O,children:[(0,Z.jsx)(p,{className:`w-3.5 h-3.5 mr-1`}),g(O?`common:states.saving`:_?`studio.create`:`common:actions.save`)]})]})]}),A&&(0,Z.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,Z.jsx)(ie,{className:`w-3.5 h-3.5 flex-shrink-0`}),A]}),_&&y.length>0&&!le&&(0,Z.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,Z.jsx)(o,{t:g,i18nKey:`studio.validation.namePattern`,components:{code:(0,Z.jsx)(`code`,{})}})}),!ue&&(0,Z.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,Z.jsx)(o,{t:g,i18nKey:`studio.validation.missingFrontmatter`,components:{code:(0,Z.jsx)(`code`,{})}})}),(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:[(0,Z.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,Z.jsx)(`span`,{children:Ve(i,_?y||`custom-…`:e)}),I&&(0,Z.jsx)(`span`,{className:`text-yellow-500 aurora-light:text-accent-warning`,children:g(`studio.unsaved`)})]}),(0,Z.jsx)(`textarea`,{value:x,onChange:e=>{C(e.target.value),R(!0)},spellCheck:!1,className:`flex-1 w-full p-4 text-xs font-mono bg-background text-foreground outline-none resize-none leading-relaxed`})]}),h&&z&&(0,Z.jsxs)(`aside`,{className:`w-96 flex-shrink-0 border-l border-border flex flex-col min-h-0`,children:[(0,Z.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,Z.jsx)(ye,{className:`w-3.5 h-3.5`}),` `,g(`studio.testPane.header`)]}),(0,Z.jsxs)(`div`,{className:`p-3 border-b border-border`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,Z.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,children:g(`studio.testPane.sampleTaskLabel`)}),(0,Z.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&&H(Re[t].prompt)},disabled:U,children:Re.map((e,t)=>(0,Z.jsx)(`option`,{value:t,children:g(e.labelKey)},t))})]}),(0,Z.jsx)(`textarea`,{value:V,onChange:e=>H(e.target.value),placeholder:g(`studio.testPane.placeholder`),className:`w-full text-xs p-2 rounded border border-border bg-background min-h-[80px] resize-y font-mono`,disabled:U}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,Z.jsx)(L,{size:`sm`,onClick:pe,disabled:U||!V.trim()||!x.trim(),children:U?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,g(`studio.testPane.running`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ye,{className:`w-3.5 h-3.5 mr-1.5`}),` `,g(`studio.testPane.run`)]})}),(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:g(`studio.testPane.sandboxNote`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 min-h-0`,children:[G&&(0,Z.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:G}),W&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground mb-2`,children:[(0,Z.jsx)(`span`,{children:W.tokens===null?(0,Z.jsx)(`span`,{className:`text-foreground font-mono`,title:g(`studio.testPane.tokensUnavailable`),"aria-label":g(`studio.testPane.tokensUnavailable`),children:`—`}):(0,Z.jsx)(o,{t:g,i18nKey:`studio.testPane.tokens`,count:W.tokens,components:{mono:(0,Z.jsx)(`span`,{className:`text-foreground font-mono`})}})}),(0,Z.jsx)(`span`,{children:(0,Z.jsxs)(`span`,{className:`text-foreground font-mono`,children:[(W.durationMs/1e3).toFixed(1),`s`]})})]}),(0,Z.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed rounded border border-border bg-background p-3`,children:W.output})]}),!U&&!W&&!G&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic`,children:g(`studio.testPane.emptyHint`)})]})]}),P&&!_&&(0,Z.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-l border-border flex flex-col`,children:[(0,Z.jsx)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:g(`studio.versions.header`)}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:M.length===0?(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic px-2 py-2`,children:g(`studio.versions.empty`)}):M.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>fe(e),className:`w-full text-left px-2 py-1.5 rounded hover:bg-accent/50 transition-colors`,children:[(0,Z.jsxs)(`div`,{className:`text-xs font-mono text-foreground`,children:[`v`,e.version]}),(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.version))}),(0,Z.jsx)(`div`,{className:`px-3 py-2 border-t border-border text-[11px] text-muted-foreground`,children:g(`studio.versions.restoreHint`)})]})]})]})}var Ue={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 We(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function Ge(e,t){switch(t.type){case`OPEN`:return{...Ue,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:We(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 Ue;default:return e}}function Ke(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 qe(e){let[t,n]=(0,X.useReducer)(Ge,Ue),{t:r}=s(`aiedit`),{registerHandler:i,unregisterHandler:o}=a(),c=(0,X.useRef)(null);c.current=t.refineId;let u=(0,X.useRef)(null);u.current=t.agentId;let d=(0,X.useRef)(e);d.current=e;let f=(0,X.useRef)(e);(0,X.useEffect)(()=>{e!==f.current&&(f.current=e,n({type:`CLOSE`}))},[e]),(0,X.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!==d.current||t.refineId!==c.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}}),()=>o(e)},[i,o]);let p=(0,X.useCallback)((e,t)=>{n({type:`OPEN`,agentId:e,baseBody:t})},[]),m=(0,X.useCallback)(()=>{n({type:`CLOSE`})},[]);return{state:t,open:p,start:(0,X.useCallback)(async e=>{let i=u.current;if(i)try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e,autoTest:t.autoTest})});if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:null,message:e.error??r(`refine.serverError`,{status:a.status})});return}let o=await a.json();c.current=o.refineId,n({type:`START_TURN`,refineId:o.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,X.useCallback)(async e=>{let t=c.current,i=u.current;if(!(!t||!i)){n({type:`START_TURN`,refineId:t,userTurn:{role:`user`,content:e,timestamp:Date.now()}});try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/turn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e})});if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:t,message:e.error??r(`refine.serverError`,{status:a.status})})}}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}}},[r]),cancel:(0,X.useCallback)(async()=>{let e=c.current,t=u.current;if(!(!e||!t))try{await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`,{method:`DELETE`})}catch{}},[]),apply:(0,X.useCallback)(async e=>{let t=c.current,i=u.current;if(!(!t||!i))try{let a=await fetch(`${l()}/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){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:t,message:e.error??r(`refine.applyFailed`,{status:a.status})});return}let o=await a.json();n({type:`APPLIED`,refineId:t,version:o.version})}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}},[r]),toggleAutoTest:(0,X.useCallback)(async e=>{let t=c.current,r=u.current;if(n({type:`TOGGLE_AUTO_TEST`,enabled:e}),!(!t||!r))try{await fetch(`${l()}/profiles/catalog/${encodeURIComponent(r)}/refine/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({autoTest:e})})}catch{}},[]),rehydrate:(0,X.useCallback)(async(e,t)=>{try{let i=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}`);if(!i.ok)throw Error(r(`refine.loadAgentFailed`,{status:i.status}));let a=await i.json(),o=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`);if(!o.ok)throw Error(r(`refine.loadSessionFailed`,{status:o.status}));let s=await o.json();c.current=e,u.current=t,n({type:`REHYDRATE`,payload:{refineId:e,agentId:t,baseBody:a.body,draftBody:s.draftBody,history:s.history,autoTest:s.autoTest,phase:s.phase,uiState:Ke(s),streamingText:``}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.rehydrateFailed`,{message:e.message})})}},[r]),close:m}}var Je=e(r(),1);function Ye(){return typeof window>`u`||!(`__TAURI_INTERNALS__`in window)?!1:/mac/i.test(navigator.platform)}function Xe(e){let[t,n]=(0,X.useState)(!1),r=(0,X.useRef)(null),{panelRef:i,panelStyle:a,headerHandleProps:o,resizeHandles:s,isFloating:c}=k();(0,X.useEffect)(()=>(r.current=document.activeElement,()=>{let e=r.current;e&&e instanceof HTMLElement&&e.focus()}),[]);let l=(0,X.useCallback)(()=>{e.uiPhase===`streaming`||e.uiPhase===`reviewing`?n(!0):e.onClose()},[e]),u=(0,X.useCallback)(()=>{n(!1),e.onDiscard()},[e]);(0,X.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,Je.createPortal)((0,Z.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,Z.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,Z.jsx)(Ze,{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,Z.jsx)(Qe,{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,Z.jsx)(rt,{state:e,appliedNotice:e.appliedNotice}),t&&(0,Z.jsx)(lt,{onCancel:()=>n(!1),onConfirm:u})]}),(0,Z.jsx)(M,{handles:s})]}),document.body)}function Ze({eyebrow:e,targetLabel:t,targetLabelMono:n,showApply:r,showDiscard:i,onApply:a,onDiscard:o,onMinimize:c,headerHandleProps:l,isFloating:u}){let{t:d}=s(`aiedit`),p=Ye()?`pl-[88px]`:`pl-4`;return(0,Z.jsxs)(`div`,{...l,className:`flex-shrink-0 flex items-center justify-between ${p} pr-4 h-14 border-b border-border bg-card/60 backdrop-blur-sm${u?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:o,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,Z.jsx)(f,{className:`w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors flex-shrink-0`}),(0,Z.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/70 leading-none`,children:e}),n?(0,Z.jsx)(`code`,{className:`text-sm font-mono font-medium text-foreground truncate block`,children:t}):(0,Z.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate block`,children:t})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c&&(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:c,"aria-label":d(`common:actions.minimize`),"data-testid":`ai-edit-minimize`,children:(0,Z.jsx)(ue,{className:`w-4 h-4`})}),i&&(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:o,children:d(`common:actions.discard`)}),r&&(0,Z.jsxs)(L,{size:`sm`,onClick:a,className:`gap-1.5`,children:[(0,Z.jsx)(h,{className:`w-3.5 h-3.5`}),` `,d(`shell.apply`),(0,Z.jsx)(`span`,{className:`text-[10px] opacity-70 ml-1`,children:pe(`⌘⏎`)})]})]})]})}function Qe({uiPhase:e,headline:t,description:n,chips:r,onChipSubmit:i,streamingText:a,composer:o,composerAccessory:c,history:l,baseBody:u,baseBodyDisclosureLabel:d,errorMessage:f}){let{t:p}=s(`aiedit`),m=e===`composing`&&(r?.length??0)>0&&l.length===0,h=e===`error`,g=l.filter(e=>e.role===`user`||e.role===`system`&&e.kind===`test_result`);return(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,Z.jsxs)(`div`,{className:`mx-auto max-w-2xl px-6 py-12 pb-32 flex flex-col gap-6`,children:[(0,Z.jsxs)(`header`,{className:`text-center space-y-2`,children:[(0,Z.jsx)(`div`,{className:`inline-flex items-center justify-center w-10 h-10 rounded-full ring-1 mx-auto `+(h?`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:h?(0,Z.jsx)(D,{className:`w-5 h-5 text-red-400 aurora-light:text-destructive`}):(0,Z.jsx)(T,{className:`w-5 h-5 text-accent-primary`})}),(0,Z.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:h?p(`shell.somethingWentWrong`):t}),h&&f&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto font-mono break-words`,children:f}),!h&&n&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto leading-relaxed`,children:n})]}),e===`streaming`&&(0,Z.jsx)(et,{streamingText:a}),m&&r&&i&&(0,Z.jsx)($e,{chips:r,onPick:i}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[o,c&&(0,Z.jsx)(`div`,{children:c})]}),g.length>0&&(0,Z.jsx)(tt,{history:g}),u&&(0,Z.jsx)(nt,{body:u,label:d??p(`shell.viewCurrentContent`)})]})})}function $e({chips:e,onPick:t}){let{t:n}=s(`aiedit`);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:n(`shell.quickPrompts`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,Z.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 et({streamingText:e}){let{t}=s(`aiedit`);return(0,Z.jsx)(`div`,{className:`rounded-xl border border-accent-primary/30 bg-accent-primary/5 p-4`,children:e?(0,Z.jsxs)(`div`,{className:`text-xs font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-64 overflow-y-auto leading-relaxed`,children:[dt(e),(0,Z.jsx)(`span`,{className:`inline-block w-1.5 h-3 bg-accent-primary animate-pulse align-middle ml-0.5`})]}):(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground italic flex items-center gap-1.5`,children:[(0,Z.jsx)(S,{className:`w-3 h-3 animate-spin`}),t(`shell.workingOnRefinement`)]})})}function tt({history:e}){let{t}=s(`aiedit`);return e.length===0?null:(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:t(`shell.history`)}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Z.jsx)(ot,{turn:e},t))})]})}function nt({body:e,label:t}){let[n,r]=(0,X.useState)(!1);return(0,Z.jsxs)(`div`,{className:`border-t border-border/60 pt-4`,children:[(0,Z.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,Z.jsx)(y,{className:`w-3.5 h-3.5`}):(0,Z.jsx)(b,{className:`w-3.5 h-3.5`}),t]}),n&&(0,Z.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 rt({state:e,appliedNotice:t}){return(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[(0,Z.jsx)(it,{history:e.history??[],composer:e.composer,composerAccessory:e.composerAccessory,secondaryAction:e.secondaryAction,appliedNotice:t,uiPhase:e.uiPhase}),(0,Z.jsx)(st,{diff:e.diff,label:e.diffHeaderLabel,applyConflict:e.applyConflict??null,onForceApply:e.onForceApply})]})}function it({history:e,composer:t,composerAccessory:n,secondaryAction:r,appliedNotice:i,uiPhase:a}){let{t:o}=s(`aiedit`);return(0,Z.jsxs)(`section`,{"aria-label":o(`shell.conversation`),className:`flex flex-col min-h-0 border-r border-border bg-card/20`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 pb-32 space-y-3`,"aria-live":`polite`,children:[e.map((e,t)=>(0,Z.jsx)(ot,{turn:e},t)),a===`applied`&&(i??(0,Z.jsx)(at,{}))]}),(0,Z.jsxs)(`div`,{className:`flex-shrink-0 border-t border-border p-3 space-y-2`,children:[t,n,r&&(0,Z.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,Z.jsx)(m,{className:`w-3 h-3`}),r.label]})]})]})}function at(){let{t:e}=s(`aiedit`);return(0,Z.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,Z.jsx)(h,{className:`w-3.5 h-3.5`}),e(`shell.applied`)]})}function ot({turn:e}){let{t}=s(`aiedit`);return e.role===`user`?(0,Z.jsxs)(`div`,{className:`flex flex-col items-end`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1`,children:t(`shell.you`)}),(0,Z.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,Z.jsxs)(`div`,{className:`rounded-md border border-accent-info/30 bg-accent-info/5 p-3 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium mb-1 text-accent-info`,children:[(0,Z.jsx)(T,{className:`w-3 h-3`}),` `,t(`shell.autoTestResult`)]}),(0,Z.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,Z.jsxs)(`div`,{className:`flex flex-col items-start`,children:[(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 inline-flex items-center gap-1`,children:[(0,Z.jsx)(T,{className:`w-3 h-3 text-accent-primary`}),` `,t(`shell.ai`)]}),(0,Z.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 st({diff:e,label:t,applyConflict:n,onForceApply:r}){let{t:i}=s(`aiedit`);return(0,Z.jsxs)(`section`,{"aria-label":i(`shell.diffPreview`),className:`flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between px-4 h-9 border-b border-border bg-card/40`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:t??i(`shell.proposedChanges`)}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`shell.wordLevelDiff`)})]}),n===`disk_changed`&&(0,Z.jsx)(ct,{kind:`disk_changed`,action:r&&(0,Z.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:r,children:[(0,Z.jsx)(q,{className:`w-3 h-3 mr-1`}),` `,i(`shell.forceApply`)]})}),n===`name_changed`&&(0,Z.jsx)(ct,{kind:`name_changed`}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-4 pb-32`,children:e})]})}function ct({kind:e,action:t}){let{t:n}=s(`aiedit`),r=n(e===`disk_changed`?`shell.conflict.diskChanged`:`shell.conflict.nameChanged`);return(0,Z.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,Z.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,Z.jsx)(D,{className:`w-3.5 h-3.5 mt-0.5 flex-shrink-0`}),(0,Z.jsx)(`span`,{children:r})]}),t]})}function lt({onCancel:e,onConfirm:t}){let{t:n}=s(`aiedit`);return(0,Z.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,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-5 max-w-sm shadow-xl`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Z.jsx)(D,{className:`w-4 h-4 text-yellow-400 aurora-light:text-accent-warning`}),(0,Z.jsx)(`h2`,{className:`text-sm font-medium`,children:n(`shell.discardDialog.title`)})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mb-4`,children:n(`shell.discardDialog.body`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:e,children:n(`shell.discardDialog.keepEditing`)}),(0,Z.jsx)(L,{size:`sm`,onClick:t,children:n(`common:actions.discard`)})]})]})})}function ut({hunks:e}){return(0,Z.jsx)(`pre`,{className:`font-mono text-xs leading-5 whitespace-pre-wrap break-words`,children:e.map((e,t)=>e.type===`eq`?(0,Z.jsx)(`span`,{className:`text-foreground/70`,children:e.text},t):e.type===`add`?(0,Z.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,Z.jsx)(`span`,{"aria-hidden":`true`,children:`+ `}),e.text]},t):(0,Z.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,Z.jsx)(`span`,{"aria-hidden":`true`,children:`− `}),e.text]},t))})}function dt(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function ft(e,t){let n=/(\s+)/,r=e.split(n),i=t.split(n);if(r.length>2e4||i.length>2e4)return pt(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 pt(e,t){let n=e.split(`
80
+ `}function Be(e,t){let n=e.match(/^---(\r?\n)([\s\S]*?)\r?\n---/);if(!n)return e;let r=n[1],i=/^name:\s*.*$/m.test(n[2])?n[2].replace(/^name:\s*.*$/m,`name: ${t}`):`name: ${t}${r}${n[2]}`;return e.replace(n[0],`---${r}${i}${r}---`)}function Ve(e,t){return e===`kimi`?`.kimi-code/skills/${t}/SKILL.md`:e===`codex`?`.codex/skills/rails/${t}/SKILL.md`:e===`gemini`?`.gemini/agents/${t}.md`:`.claude/agents/${t}.md`}function He({agentId:e,initialBody:t,initialName:n,draftFromRefine:r,provider:i=`claude`,defaultModel:a=`sonnet`,onClose:c,onSaved:u,onResumeRefine:m,automationEnabled:h=!0}){let{t:g}=s(`agentstudio`),_=!e,v=e??n??``,[y,b]=(0,X.useState)(v),[x,C]=(0,X.useState)(t??ze(i,a,v||void 0)),[w,ee]=(0,X.useState)(!_&&!t&&!r),[T,D]=(0,X.useState)(!!r&&!_),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(null),[M,N]=(0,X.useState)([]),[P,F]=(0,X.useState)(!1),[I,R]=(0,X.useState)(!!t&&_),[z,B]=(0,X.useState)(!1),[V,H]=(0,X.useState)(``),[U,te]=(0,X.useState)(!1),[W,G]=(0,X.useState)(null),[re,ie]=(0,X.useState)(null),[K,oe]=(0,X.useState)(!1);(0,X.useEffect)(()=>{if(_||t!==void 0)return;if(r){let t=!1;return fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}/refine/${r}?provider=${encodeURIComponent(i)}`).then(e=>{if(!e.ok)throw Error(g(`studio.errors.loadDraftFailed`,{status:e.status}));return e.json()}).then(e=>{!t&&e.draftBody&&(C(e.draftBody),R(!0))}).catch(e=>{t||j(e.message)}).finally(()=>{t||D(!1)}),()=>{t=!0}}let n=!1;return fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`).then(e=>{if(!e.ok)throw Error(g(`studio.errors.loadFailed`,{status:e.status}));return e.json()}).then(e=>{n||C(e.body)}).catch(e=>{n||j(e.message)}).finally(()=>{n||ee(!1)}),()=>{n=!0}},[e,r,t,_,i,g]);let se=(0,X.useCallback)(()=>{_||fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}/versions?provider=${encodeURIComponent(i)}`).then(e=>e.ok?e.json():{versions:[]}).then(e=>N(e.versions)).catch(()=>N([]))},[e,_,i]);(0,X.useEffect)(()=>{P&&se()},[P,se]);let ce=/^custom-[a-z0-9][a-z0-9-]*$/.test(y),q=x.trim().length>0,le=/^---\s*\n[\s\S]*?\n---/.test(x),ue=q&&le&&(!_||ce)&&I,J=(0,X.useCallback)(async()=>{k(!0),j(null);try{let t,n=_&&i===`kimi`?Be(x,y):x;if(t=_?await fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(i)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:y,body:n,provider:i})}):await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:x})}),!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??g(`studio.errors.saveFailed`,{status:t.status}))}R(!1),n!==x&&C(n),d.success(g(_?`studio.toasts.agentCreated`:`studio.toasts.agentSaved`),{description:_?y:e}),u&&u(_?y:e)}catch(e){let t=e.message;j(t),d.error(g(_?`studio.toasts.createFailed`:`studio.toasts.saveFailed`),{description:t})}finally{k(!1)}},[e,x,y,_,u,i,g]),Y=(0,X.useCallback)(async()=>{if(!_){oe(!1),k(!0),j(null);try{let t=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??g(`studio.errors.deleteFailed`,{status:t.status}))}d.success(g(`studio.toasts.agentDeleted`),{description:e}),u&&u(e),c()}catch(e){let t=e.message;j(t),d.error(g(`studio.toasts.deleteFailed`),{description:t})}finally{k(!1)}}},[e,_,c,u,i,g]),de=(0,X.useCallback)(e=>{C(e.body),R(!0),F(!1)},[]),pe=(0,X.useCallback)(async()=>{if(h){te(!0),ie(null),G(null);try{let t=await fetch(`${l()}/profiles/catalog/test?provider=${encodeURIComponent(i)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:_?y||`draft`:e,draftBody:x,sampleTask:V})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??g(`studio.errors.testFailed`,{status:t.status}))}let n=await t.json();G(n)}catch(e){ie(e.message)}finally{te(!1)}}},[e,h,x,y,_,i,V,g]);return w?(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:g(`studio.loadingAgent`)})}):(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!_&&(0,Z.jsx)(je,{open:K,title:g(`studio.deleteConfirm.title`,{agentId:e}),description:g(`studio.deleteConfirm.description`),confirmLabel:g(`common:actions.delete`),destructive:!0,onConfirm:Y,onCancel:()=>oe(!1)}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 border-b border-border`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:c,className:`p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground`,title:g(`common:actions.back`),children:(0,Z.jsx)(f,{className:`w-4 h-4`})}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground uppercase tracking-wide`,children:g(_?`studio.modeCreate`:`studio.modeEdit`)}),_?(0,Z.jsx)(ne,{value:y,onChange:e=>{let t=e.target.value;b(t),i===`kimi`&&C(e=>Be(e,t||`custom-<name>`)),R(!0)},placeholder:`custom-my-agent`,className:`text-sm font-mono mt-1 max-w-sm`}):(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-mono`,children:e}),h&&r&&(0,Z.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!m||!e))try{let t=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`);if(!t.ok)return;m(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:g(`studio.resumeAiEditTitle`),children:[(0,Z.jsx)(fe,{className:`w-3 h-3`}),` `,g(`studio.resumeAiEdit`)]}),T&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,Z.jsx)(S,{className:`w-3 h-3 animate-spin`}),` `,g(`studio.loadingAiDraft`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>{B(e=>!e),z||F(!1)},title:g(`studio.testButtonTitle`),children:[(0,Z.jsx)(ye,{className:`w-3.5 h-3.5 mr-1`}),g(`studio.testButton`)]}),!_&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>{F(e=>!e),P||B(!1)},title:g(`studio.historyButtonTitle`),children:[(0,Z.jsx)(he,{className:`w-3.5 h-3.5 mr-1`}),g(`studio.historyButton`)]}),!_&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>oe(!0),disabled:O,className:`text-red-400 hover:text-red-300 aurora-light:text-destructive aurora-light:hover:text-destructive`,children:[(0,Z.jsx)(E,{className:`w-3.5 h-3.5 mr-1`}),g(`common:actions.delete`)]}),(0,Z.jsxs)(L,{size:`sm`,onClick:J,disabled:!ue||O,children:[(0,Z.jsx)(p,{className:`w-3.5 h-3.5 mr-1`}),g(O?`common:states.saving`:_?`studio.create`:`common:actions.save`)]})]})]}),A&&(0,Z.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,Z.jsx)(ae,{className:`w-3.5 h-3.5 flex-shrink-0`}),A]}),_&&y.length>0&&!ce&&(0,Z.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,Z.jsx)(o,{t:g,i18nKey:`studio.validation.namePattern`,components:{code:(0,Z.jsx)(`code`,{})}})}),!le&&(0,Z.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,Z.jsx)(o,{t:g,i18nKey:`studio.validation.missingFrontmatter`,components:{code:(0,Z.jsx)(`code`,{})}})}),(0,Z.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:[(0,Z.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,Z.jsx)(`span`,{children:Ve(i,_?y||`custom-…`:e)}),I&&(0,Z.jsx)(`span`,{className:`text-yellow-500 aurora-light:text-accent-warning`,children:g(`studio.unsaved`)})]}),(0,Z.jsx)(`textarea`,{value:x,onChange:e=>{C(e.target.value),R(!0)},spellCheck:!1,className:`flex-1 w-full p-4 text-xs font-mono bg-background text-foreground outline-none resize-none leading-relaxed`})]}),h&&z&&(0,Z.jsxs)(`aside`,{className:`w-96 flex-shrink-0 border-l border-border flex flex-col min-h-0`,children:[(0,Z.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,Z.jsx)(ye,{className:`w-3.5 h-3.5`}),` `,g(`studio.testPane.header`)]}),(0,Z.jsxs)(`div`,{className:`p-3 border-b border-border`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,Z.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,children:g(`studio.testPane.sampleTaskLabel`)}),(0,Z.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&&H(Re[t].prompt)},disabled:U,children:Re.map((e,t)=>(0,Z.jsx)(`option`,{value:t,children:g(e.labelKey)},t))})]}),(0,Z.jsx)(`textarea`,{value:V,onChange:e=>H(e.target.value),placeholder:g(`studio.testPane.placeholder`),className:`w-full text-xs p-2 rounded border border-border bg-background min-h-[80px] resize-y font-mono`,disabled:U}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,Z.jsx)(L,{size:`sm`,onClick:pe,disabled:U||!V.trim()||!x.trim(),children:U?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,g(`studio.testPane.running`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ye,{className:`w-3.5 h-3.5 mr-1.5`}),` `,g(`studio.testPane.run`)]})}),(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:g(`studio.testPane.sandboxNote`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 min-h-0`,children:[re&&(0,Z.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:re}),W&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground mb-2`,children:[(0,Z.jsx)(`span`,{children:W.tokens===null?(0,Z.jsx)(`span`,{className:`text-foreground font-mono`,title:g(`studio.testPane.tokensUnavailable`),"aria-label":g(`studio.testPane.tokensUnavailable`),children:`—`}):(0,Z.jsx)(o,{t:g,i18nKey:`studio.testPane.tokens`,count:W.tokens,components:{mono:(0,Z.jsx)(`span`,{className:`text-foreground font-mono`})}})}),(0,Z.jsx)(`span`,{children:(0,Z.jsxs)(`span`,{className:`text-foreground font-mono`,children:[(W.durationMs/1e3).toFixed(1),`s`]})})]}),(0,Z.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed rounded border border-border bg-background p-3`,children:W.output})]}),!U&&!W&&!re&&(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic`,children:g(`studio.testPane.emptyHint`)})]})]}),P&&!_&&(0,Z.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-l border-border flex flex-col`,children:[(0,Z.jsx)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:g(`studio.versions.header`)}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:M.length===0?(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic px-2 py-2`,children:g(`studio.versions.empty`)}):M.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>de(e),className:`w-full text-left px-2 py-1.5 rounded hover:bg-accent/50 transition-colors`,children:[(0,Z.jsxs)(`div`,{className:`text-xs font-mono text-foreground`,children:[`v`,e.version]}),(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.version))}),(0,Z.jsx)(`div`,{className:`px-3 py-2 border-t border-border text-[11px] text-muted-foreground`,children:g(`studio.versions.restoreHint`)})]})]})]})}var Ue={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 We(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function Ge(e,t){switch(t.type){case`OPEN`:return{...Ue,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:We(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 Ue;default:return e}}function Ke(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 qe(e){let[t,n]=(0,X.useReducer)(Ge,Ue),{t:r}=s(`aiedit`),{registerHandler:i,unregisterHandler:o}=a(),c=(0,X.useRef)(null);c.current=t.refineId;let u=(0,X.useRef)(null);u.current=t.agentId;let d=(0,X.useRef)(e);d.current=e;let f=(0,X.useRef)(e);(0,X.useEffect)(()=>{e!==f.current&&(f.current=e,n({type:`CLOSE`}))},[e]),(0,X.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!==d.current||t.refineId!==c.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}}),()=>o(e)},[i,o]);let p=(0,X.useCallback)((e,t)=>{n({type:`OPEN`,agentId:e,baseBody:t})},[]),m=(0,X.useCallback)(()=>{n({type:`CLOSE`})},[]);return{state:t,open:p,start:(0,X.useCallback)(async e=>{let i=u.current;if(i)try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e,autoTest:t.autoTest})});if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:null,message:e.error??r(`refine.serverError`,{status:a.status})});return}let o=await a.json();c.current=o.refineId,n({type:`START_TURN`,refineId:o.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,X.useCallback)(async e=>{let t=c.current,i=u.current;if(!(!t||!i)){n({type:`START_TURN`,refineId:t,userTurn:{role:`user`,content:e,timestamp:Date.now()}});try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/turn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e})});if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:t,message:e.error??r(`refine.serverError`,{status:a.status})})}}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}}},[r]),cancel:(0,X.useCallback)(async()=>{let e=c.current,t=u.current;if(!(!e||!t))try{await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`,{method:`DELETE`})}catch{}},[]),apply:(0,X.useCallback)(async e=>{let t=c.current,i=u.current;if(!(!t||!i))try{let a=await fetch(`${l()}/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){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:t,message:e.error??r(`refine.applyFailed`,{status:a.status})});return}let o=await a.json();n({type:`APPLIED`,refineId:t,version:o.version})}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}},[r]),toggleAutoTest:(0,X.useCallback)(async e=>{let t=c.current,r=u.current;if(n({type:`TOGGLE_AUTO_TEST`,enabled:e}),!(!t||!r))try{await fetch(`${l()}/profiles/catalog/${encodeURIComponent(r)}/refine/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({autoTest:e})})}catch{}},[]),rehydrate:(0,X.useCallback)(async(e,t)=>{try{let i=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}`);if(!i.ok)throw Error(r(`refine.loadAgentFailed`,{status:i.status}));let a=await i.json(),o=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`);if(!o.ok)throw Error(r(`refine.loadSessionFailed`,{status:o.status}));let s=await o.json();c.current=e,u.current=t,n({type:`REHYDRATE`,payload:{refineId:e,agentId:t,baseBody:a.body,draftBody:s.draftBody,history:s.history,autoTest:s.autoTest,phase:s.phase,uiState:Ke(s),streamingText:``}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.rehydrateFailed`,{message:e.message})})}},[r]),close:m}}var Je=e(r(),1);function Ye(){return typeof window>`u`||!(`__TAURI_INTERNALS__`in window)?!1:/mac/i.test(navigator.platform)}function Xe(e){let[t,n]=(0,X.useState)(!1),r=(0,X.useRef)(null),{panelRef:i,panelStyle:a,headerHandleProps:o,resizeHandles:s,isFloating:c}=k();(0,X.useEffect)(()=>(r.current=document.activeElement,()=>{let e=r.current;e&&e instanceof HTMLElement&&e.focus()}),[]);let l=(0,X.useCallback)(()=>{e.uiPhase===`streaming`||e.uiPhase===`reviewing`?n(!0):e.onClose()},[e]),u=(0,X.useCallback)(()=>{n(!1),e.onDiscard()},[e]);(0,X.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,Je.createPortal)((0,Z.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,Z.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,Z.jsx)(Ze,{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,Z.jsx)(Qe,{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,Z.jsx)(rt,{state:e,appliedNotice:e.appliedNotice}),t&&(0,Z.jsx)(lt,{onCancel:()=>n(!1),onConfirm:u})]}),(0,Z.jsx)(M,{handles:s})]}),document.body)}function Ze({eyebrow:e,targetLabel:t,targetLabelMono:n,showApply:r,showDiscard:i,onApply:a,onDiscard:o,onMinimize:c,headerHandleProps:l,isFloating:u}){let{t:d}=s(`aiedit`),p=Ye()?`pl-[88px]`:`pl-4`;return(0,Z.jsxs)(`div`,{...l,className:`flex-shrink-0 flex items-center justify-between ${p} pr-4 h-14 border-b border-border bg-card/60 backdrop-blur-sm${u?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:o,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,Z.jsx)(f,{className:`w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors flex-shrink-0`}),(0,Z.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/70 leading-none`,children:e}),n?(0,Z.jsx)(`code`,{className:`text-sm font-mono font-medium text-foreground truncate block`,children:t}):(0,Z.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate block`,children:t})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c&&(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:c,"aria-label":d(`common:actions.minimize`),"data-testid":`ai-edit-minimize`,children:(0,Z.jsx)(ce,{className:`w-4 h-4`})}),i&&(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:o,children:d(`common:actions.discard`)}),r&&(0,Z.jsxs)(L,{size:`sm`,onClick:a,className:`gap-1.5`,children:[(0,Z.jsx)(h,{className:`w-3.5 h-3.5`}),` `,d(`shell.apply`),(0,Z.jsx)(`span`,{className:`text-[10px] opacity-70 ml-1`,children:pe(`⌘⏎`)})]})]})]})}function Qe({uiPhase:e,headline:t,description:n,chips:r,onChipSubmit:i,streamingText:a,composer:o,composerAccessory:c,history:l,baseBody:u,baseBodyDisclosureLabel:d,errorMessage:f}){let{t:p}=s(`aiedit`),m=e===`composing`&&(r?.length??0)>0&&l.length===0,h=e===`error`,g=l.filter(e=>e.role===`user`||e.role===`system`&&e.kind===`test_result`);return(0,Z.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,Z.jsxs)(`div`,{className:`mx-auto max-w-2xl px-6 py-12 pb-32 flex flex-col gap-6`,children:[(0,Z.jsxs)(`header`,{className:`text-center space-y-2`,children:[(0,Z.jsx)(`div`,{className:`inline-flex items-center justify-center w-10 h-10 rounded-full ring-1 mx-auto `+(h?`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:h?(0,Z.jsx)(D,{className:`w-5 h-5 text-red-400 aurora-light:text-destructive`}):(0,Z.jsx)(T,{className:`w-5 h-5 text-accent-primary`})}),(0,Z.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:h?p(`shell.somethingWentWrong`):t}),h&&f&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto font-mono break-words`,children:f}),!h&&n&&(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto leading-relaxed`,children:n})]}),e===`streaming`&&(0,Z.jsx)(et,{streamingText:a}),m&&r&&i&&(0,Z.jsx)($e,{chips:r,onPick:i}),(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[o,c&&(0,Z.jsx)(`div`,{children:c})]}),g.length>0&&(0,Z.jsx)(tt,{history:g}),u&&(0,Z.jsx)(nt,{body:u,label:d??p(`shell.viewCurrentContent`)})]})})}function $e({chips:e,onPick:t}){let{t:n}=s(`aiedit`);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:n(`shell.quickPrompts`)}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,Z.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 et({streamingText:e}){let{t}=s(`aiedit`);return(0,Z.jsx)(`div`,{className:`rounded-xl border border-accent-primary/30 bg-accent-primary/5 p-4`,children:e?(0,Z.jsxs)(`div`,{className:`text-xs font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-64 overflow-y-auto leading-relaxed`,children:[dt(e),(0,Z.jsx)(`span`,{className:`inline-block w-1.5 h-3 bg-accent-primary animate-pulse align-middle ml-0.5`})]}):(0,Z.jsxs)(`div`,{className:`text-xs text-muted-foreground italic flex items-center gap-1.5`,children:[(0,Z.jsx)(S,{className:`w-3 h-3 animate-spin`}),t(`shell.workingOnRefinement`)]})})}function tt({history:e}){let{t}=s(`aiedit`);return e.length===0?null:(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:t(`shell.history`)}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Z.jsx)(ot,{turn:e},t))})]})}function nt({body:e,label:t}){let[n,r]=(0,X.useState)(!1);return(0,Z.jsxs)(`div`,{className:`border-t border-border/60 pt-4`,children:[(0,Z.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,Z.jsx)(y,{className:`w-3.5 h-3.5`}):(0,Z.jsx)(b,{className:`w-3.5 h-3.5`}),t]}),n&&(0,Z.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 rt({state:e,appliedNotice:t}){return(0,Z.jsxs)(`div`,{className:`flex-1 min-h-0 grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[(0,Z.jsx)(it,{history:e.history??[],composer:e.composer,composerAccessory:e.composerAccessory,secondaryAction:e.secondaryAction,appliedNotice:t,uiPhase:e.uiPhase}),(0,Z.jsx)(st,{diff:e.diff,label:e.diffHeaderLabel,applyConflict:e.applyConflict??null,onForceApply:e.onForceApply})]})}function it({history:e,composer:t,composerAccessory:n,secondaryAction:r,appliedNotice:i,uiPhase:a}){let{t:o}=s(`aiedit`);return(0,Z.jsxs)(`section`,{"aria-label":o(`shell.conversation`),className:`flex flex-col min-h-0 border-r border-border bg-card/20`,children:[(0,Z.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 pb-32 space-y-3`,"aria-live":`polite`,children:[e.map((e,t)=>(0,Z.jsx)(ot,{turn:e},t)),a===`applied`&&(i??(0,Z.jsx)(at,{}))]}),(0,Z.jsxs)(`div`,{className:`flex-shrink-0 border-t border-border p-3 space-y-2`,children:[t,n,r&&(0,Z.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,Z.jsx)(m,{className:`w-3 h-3`}),r.label]})]})]})}function at(){let{t:e}=s(`aiedit`);return(0,Z.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,Z.jsx)(h,{className:`w-3.5 h-3.5`}),e(`shell.applied`)]})}function ot({turn:e}){let{t}=s(`aiedit`);return e.role===`user`?(0,Z.jsxs)(`div`,{className:`flex flex-col items-end`,children:[(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1`,children:t(`shell.you`)}),(0,Z.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,Z.jsxs)(`div`,{className:`rounded-md border border-accent-info/30 bg-accent-info/5 p-3 text-xs`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium mb-1 text-accent-info`,children:[(0,Z.jsx)(T,{className:`w-3 h-3`}),` `,t(`shell.autoTestResult`)]}),(0,Z.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,Z.jsxs)(`div`,{className:`flex flex-col items-start`,children:[(0,Z.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 inline-flex items-center gap-1`,children:[(0,Z.jsx)(T,{className:`w-3 h-3 text-accent-primary`}),` `,t(`shell.ai`)]}),(0,Z.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 st({diff:e,label:t,applyConflict:n,onForceApply:r}){let{t:i}=s(`aiedit`);return(0,Z.jsxs)(`section`,{"aria-label":i(`shell.diffPreview`),className:`flex flex-col min-h-0`,children:[(0,Z.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between px-4 h-9 border-b border-border bg-card/40`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:t??i(`shell.proposedChanges`)}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`shell.wordLevelDiff`)})]}),n===`disk_changed`&&(0,Z.jsx)(ct,{kind:`disk_changed`,action:r&&(0,Z.jsxs)(L,{variant:`ghost`,size:`sm`,onClick:r,children:[(0,Z.jsx)(Y,{className:`w-3 h-3 mr-1`}),` `,i(`shell.forceApply`)]})}),n===`name_changed`&&(0,Z.jsx)(ct,{kind:`name_changed`}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-auto p-4 pb-32`,children:e})]})}function ct({kind:e,action:t}){let{t:n}=s(`aiedit`),r=n(e===`disk_changed`?`shell.conflict.diskChanged`:`shell.conflict.nameChanged`);return(0,Z.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,Z.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,Z.jsx)(D,{className:`w-3.5 h-3.5 mt-0.5 flex-shrink-0`}),(0,Z.jsx)(`span`,{children:r})]}),t]})}function lt({onCancel:e,onConfirm:t}){let{t:n}=s(`aiedit`);return(0,Z.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,Z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-5 max-w-sm shadow-xl`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Z.jsx)(D,{className:`w-4 h-4 text-yellow-400 aurora-light:text-accent-warning`}),(0,Z.jsx)(`h2`,{className:`text-sm font-medium`,children:n(`shell.discardDialog.title`)})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mb-4`,children:n(`shell.discardDialog.body`)}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:e,children:n(`shell.discardDialog.keepEditing`)}),(0,Z.jsx)(L,{size:`sm`,onClick:t,children:n(`common:actions.discard`)})]})]})})}function ut({hunks:e}){return(0,Z.jsx)(`pre`,{className:`font-mono text-xs leading-5 whitespace-pre-wrap break-words`,children:e.map((e,t)=>e.type===`eq`?(0,Z.jsx)(`span`,{className:`text-foreground/70`,children:e.text},t):e.type===`add`?(0,Z.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,Z.jsx)(`span`,{"aria-hidden":`true`,children:`+ `}),e.text]},t):(0,Z.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,Z.jsx)(`span`,{"aria-hidden":`true`,children:`− `}),e.text]},t))})}function dt(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function ft(e,t){let n=/(\s+)/,r=e.split(n),i=t.split(n);if(r.length>2e4||i.length>2e4)return pt(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 pt(e,t){let n=e.split(`
81
81
  `),r=t.split(`
82
82
  `),i=[],a=0,o=0;for(;a<n.length&&o<r.length;)if(n[a]===r[o])i.push({type:`eq`,text:n[a]+`
83
83
  `}),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]+`
84
84
  `}),o++):(i.push({type:`del`,text:n[a]+`
85
85
  `}),a++)}for(;a<n.length;)i.push({type:`del`,text:n[a++]+`
86
86
  `});for(;o<r.length;)i.push({type:`add`,text:r[o++]+`
87
- `});return i}function mt({value:e,onChange:t,onSubmit:n,disabled:r,placeholder:i,autoFocus:a,inputRef:o}){let{t:c}=s(`aiedit`);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.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,Z.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,Z.jsx)(`button`,{type:`button`,onClick:n,disabled:!e.trim()||r,"aria-label":c(`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,Z.jsx)(S,{className:`w-3.5 h-3.5 animate-spin`}):(0,Z.jsx)(ht,{})})]}),(0,Z.jsx)(`div`,{className:`flex items-center justify-end text-[11px] text-muted-foreground/70`,children:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:pe(`⌘⏎`)}),` `,c(`shell.composer.kbdSubmit`),(0,Z.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,Z.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`Esc`}),` `,c(`shell.composer.kbdCancel`)]})})]})}function ht(){return(0,Z.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,Z.jsx)(`path`,{d:`M22 2 11 13`}),(0,Z.jsx)(`path`,{d:`M22 2 15 22l-4-9-9-4Z`})]})}var gt=[`refine.chips.tightenTools`,`refine.chips.stricterPersonality`,`refine.chips.workflowSection`,`refine.chips.sharpenDescription`,`refine.chips.matchDeveloperStyle`];function _t({agentId:e,baseBody:t,resumeRefineId:n,onClose:r,onMinimize:i,onStateChange:a,onOpenInStudio:o,onApplied:c}){let{t:l}=s(`agentstudio`),{activeProjectId:d}=u(),f=qe(d),[p,h]=(0,X.useState)(``),g=(0,X.useRef)(null),_=(0,X.useRef)(!1);(0,X.useEffect)(()=>{_.current||(_.current=!0,n?f.rehydrate(n,e):f.open(e,t))},[e,t,n,f]),(0,X.useEffect)(()=>{let e=setTimeout(()=>g.current?.focus(),50);return()=>clearTimeout(e)},[]);let v=(0,X.useRef)(a);v.current=a,(0,X.useEffect)(()=>{v.current?.({refineId:f.state.refineId??null})},[f.state.refineId]);let y=(0,X.useRef)(null);(0,X.useEffect)(()=>{f.state.uiState===`applied`&&f.state.appliedVersion!==null&&f.state.appliedVersion!==y.current&&(y.current=f.state.appliedVersion,c&&f.state.agentId&&c(f.state.agentId,f.state.appliedVersion))},[f.state.uiState,f.state.appliedVersion,f.state.agentId,c]);let b=(0,X.useCallback)(async e=>{let t=e.trim();t&&(h(``),f.state.refineId?await f.sendTurn(t):await f.start(t))},[f]),x=(0,X.useCallback)(()=>{b(p)},[p,b]),S=(0,X.useCallback)(async()=>{f.state.refineId&&(f.state.uiState===`streaming`||f.state.uiState===`reviewing`)&&await f.cancel(),r()},[f,r]),C=vt(f.state),w=(0,X.useMemo)(()=>!f.state.draftBody||!f.state.baseBody?null:(0,Z.jsx)(ut,{hunks:ft(f.state.baseBody,f.state.draftBody)}),[f.state.baseBody,f.state.draftBody]);return(0,Z.jsx)(Xe,{uiPhase:C,errorMessage:f.state.errorMessage,applyConflict:f.state.applyConflict,eyebrow:l(`refine.eyebrow`),targetLabel:e,targetLabelMono:!0,headline:l(`refine.headline`),streamingHeadline:l(`refine.streamingHeadline`),description:yt(t),chips:gt.map(e=>l(e)),onChipSubmit:e=>void b(e),composer:(0,Z.jsx)(mt,{value:p,onChange:h,onSubmit:x,disabled:C===`streaming`||C===`applied`,placeholder:f.state.refineId?l(`refine.placeholderFollowUp`):l(`refine.placeholderInitial`),inputRef:g}),streamingText:f.state.streamingText,history:f.state.history,diff:w,diffHeaderLabel:`.claude/agents/${e}.md`,baseBody:t,baseBodyDisclosureLabel:l(`refine.viewCurrentBody`),appliedNotice:f.state.appliedVersion===null?void 0:(0,Z.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:l(`refine.appliedAsVersion`,{version:f.state.appliedVersion})}),canApply:f.state.uiState===`reviewing`&&!!f.state.draftBody&&!f.state.applyConflict,onApply:()=>void f.apply(),onForceApply:()=>void f.apply(!0),onDiscard:()=>void S(),onClose:()=>void S(),onMinimize:i?()=>i(f.state.refineId??null):void 0,secondaryAction:o&&f.state.draftBody&&f.state.refineId?{label:l(`refine.openInStudio`),icon:(0,Z.jsx)(m,{className:`w-3 h-3`}),onClick:()=>{f.state.refineId&&f.state.draftBody&&o&&o(f.state.refineId,f.state.draftBody)}}:void 0})}function vt(e){switch(e.uiState){case`streaming`:return`streaming`;case`reviewing`:return`reviewing`;case`applied`:return`applied`;case`error`:return`error`;default:return`composing`}}function yt(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 bt(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(null),[a,c]=(0,X.useState)(null),[d,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[y,b]=(0,X.useState)({kind:`closed`}),[E,D]=(0,X.useState)({kind:`closed`}),[k,j]=(0,X.useState)(!1),[M,z]=(0,X.useState)(``),[B,V]=(0,X.useState)(`all`),[H,U]=(0,X.useState)(null),[te,W]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(``),[G,ae]=(0,X.useState)(``),[K,oe]=(0,X.useState)(!1),[se,ce]=(0,X.useState)(null),{activeProjectId:q,projects:ue}=u(),J=ue.find(e=>e.id===q)?.provider??`claude`,Y=R(J),{minimize:pe}=_(),me=(0,X.useRef)({refineId:null}),ge=(0,X.useRef)(E);ge.current=E;let ve=(0,X.useCallback)(()=>{let t=ge.current;t.kind!==`open`||!t.projectId||pe({kind:`ai-edit`,projectId:t.projectId,label:e(`catalog.aiEditChipLabel`,{agentId:t.agentId}),restoreRoute:`/agents`,params:{agentId:t.agentId,baseBody:t.baseBody,resumeRefineId:me.current.refineId??t.resumeRefineId}})},[pe,e]);v(`ai-edit`,q,e=>{e.kind!==`ai-edit`||!Y||(ve(),me.current={refineId:e.params.resumeRefineId??null},D({kind:`open`,projectId:e.projectId,agentId:e.params.agentId,baseBody:e.params.baseBody,resumeRefineId:e.params.resumeRefineId}))});let ye=(0,X.useCallback)(()=>{let t=!1;return f(!0),fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(J)}`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||(n(e.agents),e.agents.length>0&&!r&&i(e.agents[0].id))}).catch(e=>{t||g(e.message)}).finally(()=>{t||f(!1)}),()=>{t=!0}},[J,r,e]);(0,X.useEffect)(()=>ye(),[ye]);let be=(0,X.useCallback)(t=>{let n=!1;return m(!0),c(null),fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}?provider=${encodeURIComponent(J)}`).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||g(e.message)}).finally(()=>{n||m(!1)}),()=>{n=!0}},[J,e]);if((0,X.useEffect)(()=>{if(r)return be(r)},[r,be]),d)return(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`catalog.loading`)})});if(y.kind!==`closed`)return(0,Z.jsx)(He,{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,provider:J,defaultModel:_e(J),automationEnabled:Y,onClose:()=>b({kind:`closed`}),onSaved:e=>{i(e),b({kind:`closed`}),ye()},onResumeRefine:(e,t,n)=>{b({kind:`closed`}),q&&(ve(),me.current={refineId:e},D({kind:`open`,projectId:q,agentId:t,baseBody:n,resumeRefineId:e}))}});if(E.kind===`open`&&Y)return(0,Z.jsx)(le,{onClose:()=>D({kind:`closed`}),children:(0,Z.jsx)(_t,{agentId:E.agentId,baseBody:E.baseBody,resumeRefineId:E.resumeRefineId,onStateChange:e=>{me.current=e},onClose:()=>D({kind:`closed`}),onMinimize:t=>{let n=E.kind===`open`?E.projectId:q;if(!n){D({kind:`closed`});return}let r=E.kind===`open`?E.agentId:``,i=E.kind===`open`?E.baseBody:``;pe({kind:`ai-edit`,projectId:n,label:e(`catalog.aiEditChipLabel`,{agentId:r}),restoreRoute:`/agents`,params:{agentId:r,baseBody:i,resumeRefineId:t??void 0}}),D({kind:`closed`})},onApplied:e=>{D({kind:`closed`}),i(e),ye()},onOpenInStudio:(e,t)=>{D({kind:`closed`}),b({kind:`edit`,agentId:E.agentId,draftFromRefine:e})}},`${E.agentId}:${E.resumeRefineId??`fresh`}`)});let xe=(()=>{let e=M.trim().toLowerCase();return Ie.filter(t=>!(B!==`all`&&t.category!==B||H&&!t.tags.includes(H)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),Se=(()=>{let e=new Map;for(let t of Ie)e.set(t.category,(e.get(t.category)??0)+1);return e})(),Ce=()=>{j(!1),z(``),V(`all`),U(null)},we=()=>(0,Z.jsx)(I,{open:k,onOpenChange:e=>{e||Ce()},children:(0,Z.jsxs)(F,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,Z.jsxs)(P,{children:[(0,Z.jsxs)(N,{className:`flex items-center gap-2 text-base`,children:[(0,Z.jsx)(x,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.templates.title`),(0,Z.jsx)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:e(`catalog.templates.countOf`,{shown:xe.length,total:Ie.length})})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e(`catalog.templates.description`)})]}),(0,Z.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,Z.jsx)(ee,{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,Z.jsx)(`input`,{value:M,onChange:e=>z(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}),M&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>z(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,Z.jsx)(O,{className:`w-3.5 h-3.5`})})]}),(0,Z.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,Z.jsx)(xt,{label:e(`catalog.templates.allCategories`),count:Ie.length,active:B===`all`,onClick:()=>V(`all`)}),Le.map(e=>(0,Z.jsx)(xt,{label:e,count:Se.get(e)??0,active:B===e,onClick:()=>V(e)},e))]}),H&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tagFilter`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>U(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,Z.jsx)(de,{className:`w-3 h-3`}),` `,H,(0,Z.jsx)(O,{className:`w-3 h-3`})]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:xe.length===0?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,Z.jsxs)(`div`,{className:`max-w-sm`,children:[(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e(`catalog.templates.noMatch`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{z(``),V(`all`),U(null)},className:`text-xs text-accent-primary hover:underline mt-2`,children:e(`catalog.templates.clearFilters`)})]})}):(0,Z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:xe.map(t=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{Ce(),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,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,Z.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:t.emoji}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-accent-primary truncate`,children:t.label}),(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:t.category})]})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:t.blurb}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:t.tags.slice(0,5).map(e=>(0,Z.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),U(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),U(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 `+(H===e?`bg-accent-primary/20 text-accent-primary`:``),children:e},e))}),(0,Z.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,Z.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:t.nameHint}),(0,Z.jsx)(`span`,{className:`text-[10px] text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity`,children:e(`catalog.templates.openInStudio`)})]})]},t.id))})}),(0,Z.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tip`)}),(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:Ce,children:e(`common:actions.cancel`)})]})]})}),Te=()=>Y?(0,Z.jsx)(I,{open:te,onOpenChange:e=>{!e&&!K&&(W(!1),ce(null))},children:(0,Z.jsxs)(F,{className:`max-w-lg`,children:[(0,Z.jsx)(P,{children:(0,Z.jsxs)(N,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(T,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.generate.title`)]})}),(0,Z.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.agentIdLabel`)}),(0,Z.jsx)(ne,{value:re,onChange:e=>ie(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:K}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Z.jsx)(o,{t:e,i18nKey:`catalog.generate.agentIdHint`,components:{code:(0,Z.jsx)(`code`,{})}})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.descriptionLabel`)}),(0,Z.jsx)(`textarea`,{value:G,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:K})]}),se&&(0,Z.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,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:(0,Z.jsx)(o,{t:e,i18nKey:`catalog.generate.note`,components:{code:(0,Z.jsx)(`code`,{})}})})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>W(!1),disabled:K,children:e(`common:actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:Ee,disabled:K||!re.trim()||!G.trim(),children:K?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,e(`catalog.generate.generating`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(T,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.generate.generateButton`)]})})]})]})}):null,Ee=async()=>{if(Y){oe(!0),ce(null);try{let t=await fetch(`${l()}/profiles/catalog/generate?provider=${encodeURIComponent(J)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:re.trim(),description:G.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();W(!1),b({kind:`create`,initialBody:n.draft,initialName:re.trim()})}catch(e){ce(e.message)}finally{oe(!1)}}},De=async t=>{try{let n=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}?provider=${encodeURIComponent(J)}`);if(!n.ok)throw Error(e(`catalog.errors.agentLoadFailed`,{status:n.status}));let r=await n.json();b({kind:`duplicate`,from:t,initialBody:r.body})}catch(e){g(e.message)}};if(t.length===0)return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`catalog.empty.title`)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:(0,Z.jsx)(o,{t:e,i18nKey:`catalog.empty.body`,values:{command:`npx specrails-core@latest update`},components:{code:(0,Z.jsx)(`code`,{className:`text-foreground`})}})}),(0,Z.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[Y&&(0,Z.jsxs)(L,{size:`sm`,onClick:()=>W(!0),children:[(0,Z.jsx)(T,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.generateWithAi`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>j(!0),children:[(0,Z.jsx)(x,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.template`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>b({kind:`create`}),children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.blank`)]})]})]})}),we(),Te()]});let Oe=t.filter(e=>e.kind===`upstream`),ke=t.filter(e=>e.kind===`custom`),Q=t.find(e=>e.id===r);return(0,Z.jsxs)(Z.Fragment,{children:[we(),Te(),(0,Z.jsxs)(`div`,{className:`flex h-full`,children:[(0,Z.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:e(`catalog.sidebar.title`)}),(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:e(`catalog.sidebar.createLabel`)}),(0,Z.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>j(!0),title:e(`catalog.actions.templateTitle`),children:[(0,Z.jsx)(x,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.template`)]}),Y&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>W(!0),title:e(`catalog.actions.generateWithAi`),children:[(0,Z.jsx)(T,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.generate`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>b({kind:`create`}),title:e(`catalog.actions.blankTitle`),children:[(0,Z.jsx)(w,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.blank`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,Z.jsx)(St,{title:e(`catalog.sections.upstream`,{count:Oe.length}),description:e(`catalog.sections.upstreamDescription`),children:Oe.map(e=>(0,Z.jsx)(Ct,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))}),(0,Z.jsx)(St,{title:e(`catalog.sections.custom`,{count:ke.length}),description:e(`catalog.sections.customDescription`),children:ke.length===0?(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:e(`catalog.sections.noCustomAgents`)}):ke.map(e=>(0,Z.jsx)(Ct,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))})]})]}),(0,Z.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[h&&(0,Z.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:h}),Q&&(0,Z.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Z.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:Q.id}),(0,Z.jsx)(wt,{kind:Q.kind}),Q.model&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:e(`catalog.detail.defaultModel`,{model:Q.model})})]}),Q.description&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:Q.description})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>void De(Q.id),children:[(0,Z.jsx)(fe,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.duplicate`)]}),Q.kind===`custom`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>b({kind:`edit`,agentId:Q.id}),children:[(0,Z.jsx)(C,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.edit`)]}),Y&&(0,Z.jsxs)(L,{size:`sm`,onClick:async()=>{if(q)try{let e=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(Q.id)}?provider=${encodeURIComponent(J)}`);if(!e.ok)throw Error(`Load failed: ${e.status}`);let t=await e.json();ve(),me.current={refineId:null},D({kind:`open`,projectId:q,agentId:Q.id,baseBody:t.body})}catch(e){g(e.message)}},title:e(`catalog.detail.aiEditTitle`),children:[(0,Z.jsx)(he,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`catalog.detail.aiEdit`)]})]})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:Ve(J,Q.id)}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:Q.kind===`upstream`?e(`catalog.detail.readOnly`):e(`catalog.detail.editableHint`)})]}),(0,Z.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:p?e(`common:states.loading`):a??``})]})]})]})]})]})}function xt({label:e,count:t,active:n,onClick:r}){return(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function Ct({agent:e,selected:t,onSelect:n}){return(0,Z.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,Z.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,Z.jsx)(wt,{kind:e.kind})]})}function wt({kind:e}){let{t}=s(`agents`);return(0,Z.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 Tt=[{days:7},{days:30},{days:90}];function Et(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(30),[a,o]=(0,X.useState)(!0);if((0,X.useEffect)(()=>{let e=!1;return o(!0),fetch(`${l()}/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,Z.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitleEmpty`)})]}),(0,Z.jsx)(`div`,{className:`flex gap-0.5`,children:Tt.map(t=>(0,Z.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,Z.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:e(`usage.empty`)})]});let c=Math.max(...t.rows.map(e=>e.jobs),1);return(0,Z.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitle`,{count:t.windowDays})})]}),(0,Z.jsx)(`div`,{className:`flex gap-0.5`,children:Tt.map(t=>(0,Z.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,Z.jsx)(`div`,{className:`p-4 space-y-2`,children:t.rows.map(t=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:t.profileName}),(0,Z.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full bg-accent-primary/70`,style:{width:`${Math.max(6,Math.round(t.jobs/c*100))}%`}})}),(0,Z.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,Z.jsxs)(`span`,{title:e(`usage.jobsTooltip`),children:[(0,Z.jsx)(`span`,{className:`text-foreground font-mono`,children:t.jobs}),` `,e(`usage.jobsLabel`,{count:t.jobs})]}),(0,Z.jsxs)(`span`,{title:e(`usage.successRateTooltip`),children:[(0,Z.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(t.successRate*100),`%`]}),` `,e(`usage.okSuffix`)]}),t.avgDurationMs!=null&&(0,Z.jsx)(`span`,{title:e(`usage.avgDurationTooltip`),children:(0,Z.jsx)(`span`,{className:`text-foreground font-mono`,children:Dt(t.avgDurationMs)})}),t.avgTokens!=null&&(0,Z.jsxs)(`span`,{title:e(`usage.avgTokensTooltip`),children:[(0,Z.jsx)(`span`,{className:`text-foreground font-mono`,children:Ot(t.avgTokens)}),` `,e(`usage.tokensSuffix`)]})]})]},t.profileName))})]})}function Dt(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 Ot(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var kt=`specrails-desktop:agents-tab`;function At(){try{let e=localStorage.getItem(kt);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function jt(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)(()=>At()),r=e=>{n(e);try{localStorage.setItem(kt,e)}catch{}},[i,a]=(0,X.useState)(null),{activeProjectId:c}=u(),{pendingRestores:d}=_(),f=(0,X.useRef)(!1);return(0,X.useEffect)(()=>{if(!c)return;let e=d.some(e=>e.kind===`ai-edit`&&e.projectId===c);e&&!f.current&&t!==`catalog`&&r(`catalog`),f.current=e},[d,c,t]),(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&a(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[i!==null&&!i.profileAware&&(0,Z.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,Z.jsx)(D,{className:`w-4 h-4 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,Z.jsxs)(`div`,{className:`text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-yellow-500 aurora-light:text-accent-warning`,children:e(`page.banner.title`,{required:i.required})}),(0,Z.jsx)(`div`,{className:`text-yellow-500/80 aurora-light:text-accent-warning mt-0.5`,children:(0,Z.jsx)(o,{t:e,i18nKey:`page.banner.body`,values:{version:i.version??e(`page.banner.unknownVersion`),command:`npx specrails-core@latest update`},components:{code:(0,Z.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20 aurora-light:bg-accent-warning/20`})}})})]})]}),(0,Z.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,Z.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,Z.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`page.title`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`page.subtitle`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,Z.jsx)(Nt,{active:t===`profiles`,onClick:()=>r(`profiles`),children:e(`page.tabs.profiles`)}),(0,Z.jsx)(Nt,{active:t===`usage`,onClick:()=>r(`usage`),children:e(`page.tabs.usage`)}),(0,Z.jsx)(Nt,{active:t===`catalog`,onClick:()=>r(`catalog`),children:e(`page.tabs.catalog`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[t===`profiles`&&(0,Z.jsx)(Fe,{}),t===`usage`&&(0,Z.jsx)(Mt,{}),t===`catalog`&&(0,Z.jsx)(bt,{})]})]})}function Mt(){return(0,Z.jsx)(`div`,{className:`min-h-full`,children:(0,Z.jsx)(Et,{})})}function Nt({active:e,children:t,onClick:n}){return(0,Z.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{jt as default};
87
+ `});return i}function mt({value:e,onChange:t,onSubmit:n,disabled:r,placeholder:i,autoFocus:a,inputRef:o}){let{t:c}=s(`aiedit`);return(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.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,Z.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,Z.jsx)(`button`,{type:`button`,onClick:n,disabled:!e.trim()||r,"aria-label":c(`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,Z.jsx)(S,{className:`w-3.5 h-3.5 animate-spin`}):(0,Z.jsx)(ht,{})})]}),(0,Z.jsx)(`div`,{className:`flex items-center justify-end text-[11px] text-muted-foreground/70`,children:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:pe(`⌘⏎`)}),` `,c(`shell.composer.kbdSubmit`),(0,Z.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,Z.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`Esc`}),` `,c(`shell.composer.kbdCancel`)]})})]})}function ht(){return(0,Z.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,Z.jsx)(`path`,{d:`M22 2 11 13`}),(0,Z.jsx)(`path`,{d:`M22 2 15 22l-4-9-9-4Z`})]})}var gt=[`refine.chips.tightenTools`,`refine.chips.stricterPersonality`,`refine.chips.workflowSection`,`refine.chips.sharpenDescription`,`refine.chips.matchDeveloperStyle`];function _t({agentId:e,baseBody:t,resumeRefineId:n,onClose:r,onMinimize:i,onStateChange:a,onOpenInStudio:o,onApplied:c}){let{t:l}=s(`agentstudio`),{activeProjectId:d}=u(),f=qe(d),[p,h]=(0,X.useState)(``),g=(0,X.useRef)(null),_=(0,X.useRef)(!1);(0,X.useEffect)(()=>{_.current||(_.current=!0,n?f.rehydrate(n,e):f.open(e,t))},[e,t,n,f]),(0,X.useEffect)(()=>{let e=setTimeout(()=>g.current?.focus(),50);return()=>clearTimeout(e)},[]);let v=(0,X.useRef)(a);v.current=a,(0,X.useEffect)(()=>{v.current?.({refineId:f.state.refineId??null})},[f.state.refineId]);let y=(0,X.useRef)(null);(0,X.useEffect)(()=>{f.state.uiState===`applied`&&f.state.appliedVersion!==null&&f.state.appliedVersion!==y.current&&(y.current=f.state.appliedVersion,c&&f.state.agentId&&c(f.state.agentId,f.state.appliedVersion))},[f.state.uiState,f.state.appliedVersion,f.state.agentId,c]);let b=(0,X.useCallback)(async e=>{let t=e.trim();t&&(h(``),f.state.refineId?await f.sendTurn(t):await f.start(t))},[f]),x=(0,X.useCallback)(()=>{b(p)},[p,b]),S=(0,X.useCallback)(async()=>{f.state.refineId&&(f.state.uiState===`streaming`||f.state.uiState===`reviewing`)&&await f.cancel(),r()},[f,r]),C=vt(f.state),w=(0,X.useMemo)(()=>!f.state.draftBody||!f.state.baseBody?null:(0,Z.jsx)(ut,{hunks:ft(f.state.baseBody,f.state.draftBody)}),[f.state.baseBody,f.state.draftBody]);return(0,Z.jsx)(Xe,{uiPhase:C,errorMessage:f.state.errorMessage,applyConflict:f.state.applyConflict,eyebrow:l(`refine.eyebrow`),targetLabel:e,targetLabelMono:!0,headline:l(`refine.headline`),streamingHeadline:l(`refine.streamingHeadline`),description:yt(t),chips:gt.map(e=>l(e)),onChipSubmit:e=>void b(e),composer:(0,Z.jsx)(mt,{value:p,onChange:h,onSubmit:x,disabled:C===`streaming`||C===`applied`,placeholder:f.state.refineId?l(`refine.placeholderFollowUp`):l(`refine.placeholderInitial`),inputRef:g}),streamingText:f.state.streamingText,history:f.state.history,diff:w,diffHeaderLabel:`.claude/agents/${e}.md`,baseBody:t,baseBodyDisclosureLabel:l(`refine.viewCurrentBody`),appliedNotice:f.state.appliedVersion===null?void 0:(0,Z.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:l(`refine.appliedAsVersion`,{version:f.state.appliedVersion})}),canApply:f.state.uiState===`reviewing`&&!!f.state.draftBody&&!f.state.applyConflict,onApply:()=>void f.apply(),onForceApply:()=>void f.apply(!0),onDiscard:()=>void S(),onClose:()=>void S(),onMinimize:i?()=>i(f.state.refineId??null):void 0,secondaryAction:o&&f.state.draftBody&&f.state.refineId?{label:l(`refine.openInStudio`),icon:(0,Z.jsx)(m,{className:`w-3 h-3`}),onClick:()=>{f.state.refineId&&f.state.draftBody&&o&&o(f.state.refineId,f.state.draftBody)}}:void 0})}function vt(e){switch(e.uiState){case`streaming`:return`streaming`;case`reviewing`:return`reviewing`;case`applied`:return`applied`;case`error`:return`error`;default:return`composing`}}function yt(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 bt(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)([]),[r,i]=(0,X.useState)(null),[a,c]=(0,X.useState)(null),[d,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[y,b]=(0,X.useState)({kind:`closed`}),[E,D]=(0,X.useState)({kind:`closed`}),[k,j]=(0,X.useState)(!1),[M,z]=(0,X.useState)(``),[B,V]=(0,X.useState)(`all`),[H,U]=(0,X.useState)(null),[te,W]=(0,X.useState)(!1),[G,re]=(0,X.useState)(``),[ie,ae]=(0,X.useState)(``),[K,oe]=(0,X.useState)(!1),[se,ce]=(0,X.useState)(null),{activeProjectId:q,projects:le}=u(),J=le.find(e=>e.id===q)?.provider??`claude`,Y=R(J),{minimize:pe}=_(),me=(0,X.useRef)({refineId:null}),he=(0,X.useRef)(E);he.current=E;let ve=(0,X.useCallback)(()=>{let t=he.current;t.kind!==`open`||!t.projectId||pe({kind:`ai-edit`,projectId:t.projectId,label:e(`catalog.aiEditChipLabel`,{agentId:t.agentId}),restoreRoute:`/agents`,params:{agentId:t.agentId,baseBody:t.baseBody,resumeRefineId:me.current.refineId??t.resumeRefineId}})},[pe,e]);v(`ai-edit`,q,e=>{e.kind!==`ai-edit`||!Y||(ve(),me.current={refineId:e.params.resumeRefineId??null},D({kind:`open`,projectId:e.projectId,agentId:e.params.agentId,baseBody:e.params.baseBody,resumeRefineId:e.params.resumeRefineId}))});let ye=(0,X.useCallback)(()=>{let t=!1;return f(!0),fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(J)}`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||(n(e.agents),e.agents.length>0&&!r&&i(e.agents[0].id))}).catch(e=>{t||g(e.message)}).finally(()=>{t||f(!1)}),()=>{t=!0}},[J,r,e]);(0,X.useEffect)(()=>ye(),[ye]);let be=(0,X.useCallback)(t=>{let n=!1;return m(!0),c(null),fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}?provider=${encodeURIComponent(J)}`).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||g(e.message)}).finally(()=>{n||m(!1)}),()=>{n=!0}},[J,e]);if((0,X.useEffect)(()=>{if(r)return be(r)},[r,be]),d)return(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`catalog.loading`)})});if(y.kind!==`closed`)return(0,Z.jsx)(He,{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,provider:J,defaultModel:ge(J),automationEnabled:Y,onClose:()=>b({kind:`closed`}),onSaved:e=>{i(e),b({kind:`closed`}),ye()},onResumeRefine:(e,t,n)=>{b({kind:`closed`}),q&&(ve(),me.current={refineId:e},D({kind:`open`,projectId:q,agentId:t,baseBody:n,resumeRefineId:e}))}});if(E.kind===`open`&&Y)return(0,Z.jsx)(_e,{onClose:()=>D({kind:`closed`}),children:(0,Z.jsx)(_t,{agentId:E.agentId,baseBody:E.baseBody,resumeRefineId:E.resumeRefineId,onStateChange:e=>{me.current=e},onClose:()=>D({kind:`closed`}),onMinimize:t=>{let n=E.kind===`open`?E.projectId:q;if(!n){D({kind:`closed`});return}let r=E.kind===`open`?E.agentId:``,i=E.kind===`open`?E.baseBody:``;pe({kind:`ai-edit`,projectId:n,label:e(`catalog.aiEditChipLabel`,{agentId:r}),restoreRoute:`/agents`,params:{agentId:r,baseBody:i,resumeRefineId:t??void 0}}),D({kind:`closed`})},onApplied:e=>{D({kind:`closed`}),i(e),ye()},onOpenInStudio:(e,t)=>{D({kind:`closed`}),b({kind:`edit`,agentId:E.agentId,draftFromRefine:e})}},`${E.agentId}:${E.resumeRefineId??`fresh`}`)});let xe=(()=>{let e=M.trim().toLowerCase();return Ie.filter(t=>!(B!==`all`&&t.category!==B||H&&!t.tags.includes(H)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),Se=(()=>{let e=new Map;for(let t of Ie)e.set(t.category,(e.get(t.category)??0)+1);return e})(),Ce=()=>{j(!1),z(``),V(`all`),U(null)},we=()=>(0,Z.jsx)(I,{open:k,onOpenChange:e=>{e||Ce()},children:(0,Z.jsxs)(F,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,Z.jsxs)(P,{children:[(0,Z.jsxs)(N,{className:`flex items-center gap-2 text-base`,children:[(0,Z.jsx)(x,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.templates.title`),(0,Z.jsx)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:e(`catalog.templates.countOf`,{shown:xe.length,total:Ie.length})})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e(`catalog.templates.description`)})]}),(0,Z.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,Z.jsx)(ee,{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,Z.jsx)(`input`,{value:M,onChange:e=>z(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}),M&&(0,Z.jsx)(`button`,{type:`button`,onClick:()=>z(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,Z.jsx)(O,{className:`w-3.5 h-3.5`})})]}),(0,Z.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,Z.jsx)(xt,{label:e(`catalog.templates.allCategories`),count:Ie.length,active:B===`all`,onClick:()=>V(`all`)}),Le.map(e=>(0,Z.jsx)(xt,{label:e,count:Se.get(e)??0,active:B===e,onClick:()=>V(e)},e))]}),H&&(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tagFilter`)}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>U(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,Z.jsx)(de,{className:`w-3 h-3`}),` `,H,(0,Z.jsx)(O,{className:`w-3 h-3`})]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:xe.length===0?(0,Z.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,Z.jsxs)(`div`,{className:`max-w-sm`,children:[(0,Z.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e(`catalog.templates.noMatch`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>{z(``),V(`all`),U(null)},className:`text-xs text-accent-primary hover:underline mt-2`,children:e(`catalog.templates.clearFilters`)})]})}):(0,Z.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:xe.map(t=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{Ce(),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,Z.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,Z.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:t.emoji}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-accent-primary truncate`,children:t.label}),(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:t.category})]})]}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:t.blurb}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:t.tags.slice(0,5).map(e=>(0,Z.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),U(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),U(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 `+(H===e?`bg-accent-primary/20 text-accent-primary`:``),children:e},e))}),(0,Z.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,Z.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:t.nameHint}),(0,Z.jsx)(`span`,{className:`text-[10px] text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity`,children:e(`catalog.templates.openInStudio`)})]})]},t.id))})}),(0,Z.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tip`)}),(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:Ce,children:e(`common:actions.cancel`)})]})]})}),Te=()=>Y?(0,Z.jsx)(I,{open:te,onOpenChange:e=>{!e&&!K&&(W(!1),ce(null))},children:(0,Z.jsxs)(F,{className:`max-w-lg`,children:[(0,Z.jsx)(P,{children:(0,Z.jsxs)(N,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(T,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.generate.title`)]})}),(0,Z.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.agentIdLabel`)}),(0,Z.jsx)(ne,{value:G,onChange:e=>re(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:K}),(0,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,Z.jsx)(o,{t:e,i18nKey:`catalog.generate.agentIdHint`,components:{code:(0,Z.jsx)(`code`,{})}})})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.descriptionLabel`)}),(0,Z.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:K})]}),se&&(0,Z.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,Z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:(0,Z.jsx)(o,{t:e,i18nKey:`catalog.generate.note`,components:{code:(0,Z.jsx)(`code`,{})}})})]}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(L,{variant:`ghost`,size:`sm`,onClick:()=>W(!1),disabled:K,children:e(`common:actions.cancel`)}),(0,Z.jsx)(L,{size:`sm`,onClick:Ee,disabled:K||!G.trim()||!ie.trim(),children:K?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,e(`catalog.generate.generating`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(T,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.generate.generateButton`)]})})]})]})}):null,Ee=async()=>{if(Y){oe(!0),ce(null);try{let t=await fetch(`${l()}/profiles/catalog/generate?provider=${encodeURIComponent(J)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:G.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();W(!1),b({kind:`create`,initialBody:n.draft,initialName:G.trim()})}catch(e){ce(e.message)}finally{oe(!1)}}},De=async t=>{try{let n=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}?provider=${encodeURIComponent(J)}`);if(!n.ok)throw Error(e(`catalog.errors.agentLoadFailed`,{status:n.status}));let r=await n.json();b({kind:`duplicate`,from:t,initialBody:r.body})}catch(e){g(e.message)}};if(t.length===0)return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Z.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`catalog.empty.title`)}),(0,Z.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:(0,Z.jsx)(o,{t:e,i18nKey:`catalog.empty.body`,values:{command:`npx specrails-core@latest update`},components:{code:(0,Z.jsx)(`code`,{className:`text-foreground`})}})}),(0,Z.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[Y&&(0,Z.jsxs)(L,{size:`sm`,onClick:()=>W(!0),children:[(0,Z.jsx)(T,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.generateWithAi`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>j(!0),children:[(0,Z.jsx)(x,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.template`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>b({kind:`create`}),children:[(0,Z.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.blank`)]})]})]})}),we(),Te()]});let Oe=t.filter(e=>e.kind===`upstream`),ke=t.filter(e=>e.kind===`custom`),Q=t.find(e=>e.id===r);return(0,Z.jsxs)(Z.Fragment,{children:[we(),Te(),(0,Z.jsxs)(`div`,{className:`flex h-full`,children:[(0,Z.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,Z.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:e(`catalog.sidebar.title`)}),(0,Z.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:e(`catalog.sidebar.createLabel`)}),(0,Z.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>j(!0),title:e(`catalog.actions.templateTitle`),children:[(0,Z.jsx)(x,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.template`)]}),Y&&(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>W(!0),title:e(`catalog.actions.generateWithAi`),children:[(0,Z.jsx)(T,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.generate`)]}),(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>b({kind:`create`}),title:e(`catalog.actions.blankTitle`),children:[(0,Z.jsx)(w,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.blank`)]})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,Z.jsx)(St,{title:e(`catalog.sections.upstream`,{count:Oe.length}),description:e(`catalog.sections.upstreamDescription`),children:Oe.map(e=>(0,Z.jsx)(Ct,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))}),(0,Z.jsx)(St,{title:e(`catalog.sections.custom`,{count:ke.length}),description:e(`catalog.sections.customDescription`),children:ke.length===0?(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:e(`catalog.sections.noCustomAgents`)}):ke.map(e=>(0,Z.jsx)(Ct,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))})]})]}),(0,Z.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[h&&(0,Z.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:h}),Q&&(0,Z.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Z.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:Q.id}),(0,Z.jsx)(wt,{kind:Q.kind}),Q.model&&(0,Z.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:e(`catalog.detail.defaultModel`,{model:Q.model})})]}),Q.description&&(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:Q.description})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>void De(Q.id),children:[(0,Z.jsx)(ue,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.duplicate`)]}),Q.kind===`custom`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(L,{size:`sm`,variant:`ghost`,onClick:()=>b({kind:`edit`,agentId:Q.id}),children:[(0,Z.jsx)(C,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.edit`)]}),Y&&(0,Z.jsxs)(L,{size:`sm`,onClick:async()=>{if(q)try{let e=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(Q.id)}?provider=${encodeURIComponent(J)}`);if(!e.ok)throw Error(`Load failed: ${e.status}`);let t=await e.json();ve(),me.current={refineId:null},D({kind:`open`,projectId:q,agentId:Q.id,baseBody:t.body})}catch(e){g(e.message)}},title:e(`catalog.detail.aiEditTitle`),children:[(0,Z.jsx)(fe,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`catalog.detail.aiEdit`)]})]})]})]}),(0,Z.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,Z.jsx)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:Ve(J,Q.id)}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:Q.kind===`upstream`?e(`catalog.detail.readOnly`):e(`catalog.detail.editableHint`)})]}),(0,Z.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:p?e(`common:states.loading`):a??``})]})]})]})]})]})}function xt({label:e,count:t,active:n,onClick:r}){return(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,Z.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function Ct({agent:e,selected:t,onSelect:n}){return(0,Z.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,Z.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,Z.jsx)(wt,{kind:e.kind})]})}function wt({kind:e}){let{t}=s(`agents`);return(0,Z.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 Tt=[{days:7},{days:30},{days:90}];function Et(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)(null),[r,i]=(0,X.useState)(30),[a,o]=(0,X.useState)(!0);if((0,X.useEffect)(()=>{let e=!1;return o(!0),fetch(`${l()}/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,Z.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitleEmpty`)})]}),(0,Z.jsx)(`div`,{className:`flex gap-0.5`,children:Tt.map(t=>(0,Z.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,Z.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:e(`usage.empty`)})]});let c=Math.max(...t.rows.map(e=>e.jobs),1);return(0,Z.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,Z.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitle`,{count:t.windowDays})})]}),(0,Z.jsx)(`div`,{className:`flex gap-0.5`,children:Tt.map(t=>(0,Z.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,Z.jsx)(`div`,{className:`p-4 space-y-2`,children:t.rows.map(t=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Z.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:t.profileName}),(0,Z.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full bg-accent-primary/70`,style:{width:`${Math.max(6,Math.round(t.jobs/c*100))}%`}})}),(0,Z.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,Z.jsxs)(`span`,{title:e(`usage.jobsTooltip`),children:[(0,Z.jsx)(`span`,{className:`text-foreground font-mono`,children:t.jobs}),` `,e(`usage.jobsLabel`,{count:t.jobs})]}),(0,Z.jsxs)(`span`,{title:e(`usage.successRateTooltip`),children:[(0,Z.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(t.successRate*100),`%`]}),` `,e(`usage.okSuffix`)]}),t.avgDurationMs!=null&&(0,Z.jsx)(`span`,{title:e(`usage.avgDurationTooltip`),children:(0,Z.jsx)(`span`,{className:`text-foreground font-mono`,children:Dt(t.avgDurationMs)})}),t.avgTokens!=null&&(0,Z.jsxs)(`span`,{title:e(`usage.avgTokensTooltip`),children:[(0,Z.jsx)(`span`,{className:`text-foreground font-mono`,children:Ot(t.avgTokens)}),` `,e(`usage.tokensSuffix`)]})]})]},t.profileName))})]})}function Dt(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 Ot(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var kt=`specrails-desktop:agents-tab`;function At(){try{let e=localStorage.getItem(kt);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function jt(){let{t:e}=s(`agents`),[t,n]=(0,X.useState)(()=>At()),r=e=>{n(e);try{localStorage.setItem(kt,e)}catch{}},[i,a]=(0,X.useState)(null),{activeProjectId:c}=u(),{pendingRestores:d}=_(),f=(0,X.useRef)(!1);return(0,X.useEffect)(()=>{if(!c)return;let e=d.some(e=>e.kind===`ai-edit`&&e.projectId===c);e&&!f.current&&t!==`catalog`&&r(`catalog`),f.current=e},[d,c,t]),(0,X.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&a(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,Z.jsxs)(`div`,{className:`flex flex-col h-full`,children:[i!==null&&!i.profileAware&&(0,Z.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,Z.jsx)(D,{className:`w-4 h-4 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,Z.jsxs)(`div`,{className:`text-xs`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-yellow-500 aurora-light:text-accent-warning`,children:e(`page.banner.title`,{required:i.required})}),(0,Z.jsx)(`div`,{className:`text-yellow-500/80 aurora-light:text-accent-warning mt-0.5`,children:(0,Z.jsx)(o,{t:e,i18nKey:`page.banner.body`,values:{version:i.version??e(`page.banner.unknownVersion`),command:`npx specrails-core@latest update`},components:{code:(0,Z.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20 aurora-light:bg-accent-warning/20`})}})})]})]}),(0,Z.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,Z.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,Z.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`page.title`)}),(0,Z.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`page.subtitle`)})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,Z.jsx)(Nt,{active:t===`profiles`,onClick:()=>r(`profiles`),children:e(`page.tabs.profiles`)}),(0,Z.jsx)(Nt,{active:t===`usage`,onClick:()=>r(`usage`),children:e(`page.tabs.usage`)}),(0,Z.jsx)(Nt,{active:t===`catalog`,onClick:()=>r(`catalog`),children:e(`page.tabs.catalog`)})]})]}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[t===`profiles`&&(0,Z.jsx)(Fe,{}),t===`usage`&&(0,Z.jsx)(Mt,{}),t===`catalog`&&(0,Z.jsx)(bt,{})]})]})}function Mt(){return(0,Z.jsx)(`div`,{className:`min-h-full`,children:(0,Z.jsx)(Et,{})})}function Nt({active:e,children:t,onClick:n}){return(0,Z.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{jt as default};