@capagents/forgeqe 2.10.4 → 3.0.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 (162) hide show
  1. package/HOW_TO_USE.md +119 -16
  2. package/README.md +1 -1
  3. package/THIRD_PARTY_NOTICES.md +1 -0
  4. package/dist/docs-site/docs/architecture/index.html +1 -0
  5. package/dist/docs-site/docs/cost-architecture/index.html +1 -1
  6. package/dist/docs-site/docs/index.html +158 -19
  7. package/dist/docs-site/docs/mobile/index.html +38 -2
  8. package/dist/docs-site/docs/search.js +1 -1
  9. package/dist/forgeqe.js +2121 -1947
  10. package/dist/web/assets/Agent-DISh0THc.js +8 -0
  11. package/dist/web/assets/ApiTests-CK0HqEH4.js +10 -0
  12. package/dist/web/assets/Browse-WylAQZvD.js +2 -0
  13. package/dist/web/assets/Chat-B7IOg3I3.js +5 -0
  14. package/dist/web/assets/CommandPalette-CkreEJ8R.js +1 -0
  15. package/dist/web/assets/Compare-CgOfZofk.js +1 -0
  16. package/dist/web/assets/Cost-Dl5-viu4.js +1 -0
  17. package/dist/web/assets/Data-Bv2S5wkW.js +6 -0
  18. package/dist/web/assets/Desktop-CifPwy5u.js +1 -0
  19. package/dist/web/assets/DesktopReview-fpGdtU4r.js +1 -0
  20. package/dist/web/assets/Evidence-hOZDzfKt.js +1 -0
  21. package/dist/web/assets/Explore-c85VGE9Q.js +2 -0
  22. package/dist/web/assets/Features-DXL_vSjn.js +1 -0
  23. package/dist/web/assets/Flags-B7x2pDud.js +2 -0
  24. package/dist/web/assets/Flaky-BM3syqCt.js +1 -0
  25. package/dist/web/assets/Impact-BUCh8OAI.js +3 -0
  26. package/dist/web/assets/Jobs-B8sBDYRI.js +5 -0
  27. package/dist/web/assets/KindPage-yVmpQm7L.js +6 -0
  28. package/dist/web/assets/Migration-BOLN1duU.js +2 -0
  29. package/dist/web/assets/Product-C0FeEaJg.js +7 -0
  30. package/dist/web/assets/Production-BSMQyWKd.js +1 -0
  31. package/dist/web/assets/Quality-DsM9gWZb.js +1 -0
  32. package/dist/web/assets/Readiness-BhqkAJYN.js +1 -0
  33. package/dist/web/assets/Record-CPx-lK53.js +2 -0
  34. package/dist/web/assets/Regression-BXbX46nO.js +5 -0
  35. package/dist/web/assets/{RelationGraph-D_ZVeOBh.js → RelationGraph-eoGXXz5t.js} +1 -1
  36. package/dist/web/assets/Reports-36YQzVhA.js +2 -0
  37. package/dist/web/assets/Response-DplUOsue.js +4 -0
  38. package/dist/web/assets/RunDiff-D0fDhRmK.js +1 -0
  39. package/dist/web/assets/Runs-Bv1Ef8zq.js +2 -0
  40. package/dist/web/assets/Steps-Cm-atRtk.js +2 -0
  41. package/dist/web/assets/TestCases-B9x9W3zJ.js +1 -0
  42. package/dist/web/assets/TestData-DsJ6Z2YI.js +2 -0
  43. package/dist/web/assets/TestDebt-B_FUbMOb.js +1 -0
  44. package/dist/web/assets/Tosca-nxVCubA5.js +3 -0
  45. package/dist/web/assets/WhatsNew-CdnbMvrr.js +1 -0
  46. package/dist/web/assets/agentLink-BGKAF6xd.js +1 -0
  47. package/dist/web/assets/capture.worklet-C2TjBQ56.js +11 -0
  48. package/dist/web/assets/capture.worklet-UcNywATd.js +1 -0
  49. package/dist/web/assets/dataParts-Bn-tzbKg.js +3 -0
  50. package/dist/web/assets/{families-zlLgApNV.js → families-DPlFfKf2.js} +1 -1
  51. package/dist/web/assets/filters-Bj5K1WaL.js +1 -0
  52. package/dist/web/assets/fold-BhRpA0sy.js +1 -0
  53. package/dist/web/assets/frame-D_TPoUTD.js +16 -0
  54. package/dist/web/assets/index-BRB-oAMd.js +67 -0
  55. package/dist/web/assets/index-CIw5WfL8.css +2 -0
  56. package/dist/web/assets/{line-icons-CQ-3V8ax.js → line-icons-DBwNPSmu.js} +1 -1
  57. package/dist/web/assets/{logos-DfCytw3-.js → logos-839CfoKx.js} +1 -1
  58. package/dist/web/assets/{markdown-nTIj9lyp.js → markdown-6z0km3hN.js} +7 -7
  59. package/dist/web/assets/paletteCommands-CZFdKGhh.js +1 -0
  60. package/dist/web/assets/parts-VPcxh6Jc.js +1 -0
  61. package/dist/web/assets/{productParts-DK3ULNpv.js → productParts-BjfWgMtq.js} +1 -1
  62. package/dist/web/assets/qualityParts-PGN65yfI.js +1 -0
  63. package/dist/web/assets/{recordTest-CqxnF953.js → recordTest-EkxSMWbe.js} +1 -1
  64. package/dist/web/assets/rows-uLoguIo5.js +1 -0
  65. package/dist/web/assets/segmented-DphDskQz.js +1 -0
  66. package/dist/web/assets/{usePageChat-Dl2aUtHP.js → usePageChat-DqEwGcyO.js} +1 -1
  67. package/dist/web/index.html +6 -6
  68. package/docs/ARCHITECTURE.md +1 -0
  69. package/docs/COST_ARCHITECTURE.md +1 -1
  70. package/docs/MOBILE.md +40 -0
  71. package/docs/user-guide.html +158 -19
  72. package/evals/prompts/brain/browser-narrow-with-filters.yaml +20 -0
  73. package/forgeqe.example.yaml +11 -1
  74. package/package.json +4 -1
  75. package/prompts/brain.md +4 -0
  76. package/prompts/browser-goal-verification.md +2 -0
  77. package/prompts/refine.md +2 -0
  78. package/prompts/requests-rule.md +1 -1
  79. package/prompts/talk-summary.md +43 -0
  80. package/prompts/talk.md +49 -0
  81. package/prompts/test-agent.md +1 -0
  82. package/prompts/test-reviewer.md +2 -1
  83. package/prompts/test-rules.md +3 -0
  84. package/py/forgeqe_data/__init__.py +1 -0
  85. package/py/forgeqe_data/__main__.py +12 -0
  86. package/py/forgeqe_data/connect.py +290 -0
  87. package/py/forgeqe_data/connstr.py +169 -0
  88. package/py/forgeqe_data/flows.py +603 -0
  89. package/py/forgeqe_data/guard.py +214 -0
  90. package/py/forgeqe_data/mongo.py +219 -0
  91. package/py/forgeqe_data/schema.py +431 -0
  92. package/py/forgeqe_data/service.py +651 -0
  93. package/py/forgeqe_data/streams.py +400 -0
  94. package/py/forgeqe_data/subset.py +299 -0
  95. package/py/forgeqe_data/testdata.py +861 -0
  96. package/py/forgeqe_data/vector.py +113 -0
  97. package/py/forgeqe_desktop/workflow.py +6 -4
  98. package/py/forgeqe_engine/capture.py +5 -4
  99. package/py/forgeqe_engine/diagnostics.py +2 -2
  100. package/py/forgeqe_engine/lenient_json.py +96 -0
  101. package/py/forgeqe_engine/llm.py +4 -0
  102. package/py/forgeqe_engine/network.py +93 -15
  103. package/py/forgeqe_engine/neutral_log.py +16 -1
  104. package/py/forgeqe_engine/recordsession.py +54 -1
  105. package/py/forgeqe_engine/service.py +22 -3
  106. package/py/forgeqe_mobile/appium_driver.py +9 -0
  107. package/py/forgeqe_mobile/apps.py +4 -0
  108. package/py/forgeqe_mobile/maestro.py +3 -0
  109. package/py/forgeqe_mobile/record.py +610 -0
  110. package/py/forgeqe_mobile/service.py +37 -7
  111. package/py/forgeqe_talk/__init__.py +1 -0
  112. package/py/forgeqe_talk/__main__.py +65 -0
  113. package/py/forgeqe_voice/worker.py +141 -0
  114. package/skills/dotnet-nunit-playwright/SKILL.md +1 -0
  115. package/skills/playwright-typescript/SKILL.md +1 -1
  116. package/dist/web/assets/Agent-DaA5WhAY.js +0 -8
  117. package/dist/web/assets/ApiTests-B7xsTGyo.js +0 -10
  118. package/dist/web/assets/Browse-ByYCyAwd.js +0 -2
  119. package/dist/web/assets/Chat-D1-cYNBr.js +0 -3
  120. package/dist/web/assets/CommandPalette-DbxKJJJB.js +0 -1
  121. package/dist/web/assets/Compare-CYLFEtJl.js +0 -1
  122. package/dist/web/assets/Cost-Csz0jMHo.js +0 -1
  123. package/dist/web/assets/Data-BWTme_Yw.js +0 -6
  124. package/dist/web/assets/Desktop-rZ0vB6Ie.js +0 -1
  125. package/dist/web/assets/DesktopReview-_Xha22_d.js +0 -1
  126. package/dist/web/assets/Evidence-DmUyZy9F.js +0 -1
  127. package/dist/web/assets/Explore-2wzgwz3J.js +0 -2
  128. package/dist/web/assets/Features-DazEWqYu.js +0 -1
  129. package/dist/web/assets/Flags-BTt0-pqd.js +0 -2
  130. package/dist/web/assets/Flaky-CjkQp73T.js +0 -1
  131. package/dist/web/assets/Impact-De87sv5J.js +0 -3
  132. package/dist/web/assets/Jobs-aiNGBVHL.js +0 -5
  133. package/dist/web/assets/KindPage-CrGoFeSa.js +0 -6
  134. package/dist/web/assets/Migration-BAhQ1DZO.js +0 -2
  135. package/dist/web/assets/Product-DpK-PIxV.js +0 -7
  136. package/dist/web/assets/Production-D6A89rZZ.js +0 -1
  137. package/dist/web/assets/Quality-Bc5wCsog.js +0 -1
  138. package/dist/web/assets/Readiness-CoVgZw2X.js +0 -1
  139. package/dist/web/assets/Record-DcgBatJJ.js +0 -2
  140. package/dist/web/assets/Regression-BJLYrqST.js +0 -5
  141. package/dist/web/assets/Reports-DYfyfEDy.js +0 -2
  142. package/dist/web/assets/Response-CNLi9Dqu.js +0 -4
  143. package/dist/web/assets/RunDiff-BMTdRhii.js +0 -1
  144. package/dist/web/assets/Runs-lb78rvPV.js +0 -2
  145. package/dist/web/assets/Steps-BDSeIznj.js +0 -2
  146. package/dist/web/assets/TestCases-CfUwd67O.js +0 -1
  147. package/dist/web/assets/TestData-DP7cvW48.js +0 -2
  148. package/dist/web/assets/TestDebt-CqARxL7k.js +0 -1
  149. package/dist/web/assets/Tosca-CLAz9tWT.js +0 -3
  150. package/dist/web/assets/WhatsNew-1lhTRE5Z.js +0 -1
  151. package/dist/web/assets/dataParts-DI_OJhy5.js +0 -3
  152. package/dist/web/assets/filters-CflRmNDz.js +0 -1
  153. package/dist/web/assets/fold-pOBiaSlF.js +0 -1
  154. package/dist/web/assets/frame-CYYiRu5P.js +0 -4
  155. package/dist/web/assets/index-CNDoTeRV.css +0 -2
  156. package/dist/web/assets/index-D4a0w3Vl.js +0 -67
  157. package/dist/web/assets/palette-Cj4CUs0K.js +0 -1
  158. package/dist/web/assets/parts-C53RxMcR.js +0 -1
  159. package/dist/web/assets/qualityParts-C9FItsTg.js +0 -1
  160. package/dist/web/assets/rows-D6rPRkHl.js +0 -1
  161. package/dist/web/assets/segmented-CAf_qz5Z.js +0 -1
  162. package/dist/web/assets/thread-DQdyL3Sv.js +0 -5
@@ -1,8 +0,0 @@
1
- import{$t as e,A as t,An as n,Ar as r,C as i,Cn as a,D as o,Dn as s,Fn as c,Gn as l,I as u,Ir as d,J as f,Jn as p,M as m,Mn as h,Nr as g,O as _,On as v,Pn as y,Q as b,Qt as x,Rn as S,T as C,Tn as w,Ut as T,Vn as E,Zn as D,a as O,cn as ee,gr as te,gt as ne,ht as re,ir as ie,it as ae,j as k,nr as oe,o as se,or as ce,p as le,pr as ue,qn as de,tt as fe,vr as pe,wr as me,xr as he,z as ge}from"./line-icons-CQ-3V8ax.js";import{$ as _e,B as A,G as ve,J as ye,K as be,Q as xe,R as j,Rt as Se,U as Ce,V as M,Zt as we,_ as Te,a as N,at as P,c as F,d as Ee,dt as De,f as I,h as L,i as Oe,it as ke,jt as R,l as z,m as Ae,nt as je,o as B,q as Me,r as Ne,s as V,st as Pe,t as Fe,ut as H,z as U}from"./filters-CflRmNDz.js";import{$t as W,At as Ie,Ft as Le,Gt as Re,It as ze,J as G,Jt as Be,Kt as Ve,Mt as K,Nt as He,Pt as Ue,Qt as We,Rt as Ge,Ut as Ke,Wt as qe,Yt as Je,Zt as Ye,an as Xe,at as q,bt as Ze,en as Qe,in as $e,it as et,jt as tt,n as nt,nn as rt,nt as it,ot as at,q as ot,qt as st,r as ct,rn as lt,rt as J,st as ut,t as dt,tn as ft,vt as pt,xt as mt,zt as ht}from"./frame-CYYiRu5P.js";import{r as gt}from"./markdown-nTIj9lyp.js";import{C as _t,F as vt,L as yt,M as bt,N as xt,P as St,S as Ct,V as wt,c as Tt,j as Et,l as Dt,r as Ot,s as kt,u as At,v as jt,w as Mt,y as Nt}from"./index-D4a0w3Vl.js";import{i as Pt}from"./Response-CNLi9Dqu.js";import{n as Ft,t as It}from"./segmented-CAf_qz5Z.js";import{t as Lt}from"./Data-BWTme_Yw.js";import{a as Rt,c as Y,f as zt,n as Bt}from"./dataParts-DI_OJhy5.js";import{t as Vt}from"./TestData-DP7cvW48.js";import{a as Ht,i as Ut,n as X,r as Wt,t as Gt}from"./RelationGraph-D_ZVeOBh.js";import{_ as Kt}from"./qualityParts-C9FItsTg.js";import{StatusIcon as qt}from"./Runs-lb78rvPV.js";var Z=d(g(),1),Q=we(),Jt=`forgeqe-agent-favourites`,Yt=`forgeqe-agent-favourites`;function Xt(){let e=()=>{try{return Ye(localStorage.getItem(Jt))}catch{return[]}},[t,n]=(0,Z.useState)(e);return(0,Z.useEffect)(()=>{let t=()=>n(e());return window.addEventListener(Yt,t),window.addEventListener(`storage`,t),()=>{window.removeEventListener(Yt,t),window.removeEventListener(`storage`,t)}},[]),{favs:t,toggle:e=>{let r=t.includes(e)?t.filter(t=>t!==e):[...t,e];n(r);try{localStorage.setItem(Jt,JSON.stringify(r)),window.dispatchEvent(new Event(Yt))}catch{}pt(`favourites`)}}}var Zt={attention:{label:`Needs attention`,tone:`fail`},partial:{label:`Partly set up`,tone:`warn`},ready:{label:`Ready`,tone:`pass`},unavailable:{label:`Unavailable`,tone:`neutral`}},Qt={pass:`bg-pass`,warn:`bg-warn`,fail:`bg-fail`,neutral:`bg-line-strong`,running:`bg-accent`},$t=(e,t)=>{let n=Re(e),r=t?.[n.agent];return{fav:n.id,href:I(`agents`,n.id),name:st(n.agent).name,about:n.about,short:n.short,icon:(0,Q.jsx)(He,{agent:n.agent,px:24,decorative:!0}),tags:r?.tags??[],...r?{status:r.status}:{},note:r?.note??``}},en={active:{label:`Active`,tone:`pass`},changed:{label:`Change waiting`,tone:`warn`},draft:{label:`Draft`,tone:`neutral`},invalid:{label:`Needs fixing`,tone:`fail`},broken:{label:`Cannot run`,tone:`fail`},disabled:{label:`Disabled`,tone:`neutral`}},tn={active:`ready`,changed:`partial`,draft:`partial`,invalid:`attention`,broken:`attention`,disabled:`unavailable`},nn=e=>({fav:Ve(e.id),href:I(`agents`,`custom`,e.id),name:e.name,about:e.description||`No description yet.`,short:e.description||en[e.state].label,icon:(0,Q.jsx)(He,{agent:e.id,icon:e.icon,px:24,decorative:!0}),status:tn[e.state],note:en[e.state].label,tags:[...e.state===`active`?[]:[en[e.state].label],...e.approvedVersion?[`v${e.approvedVersion}`]:[],...e.problems?[`${e.problems} problem${e.problems===1?``:`s`}`]:[]]});function rn({cards:e}){let t=Object.values(e||{});if(!t.length||t.some(e=>e.status!==`unavailable`))return null;let n=[...new Set(t.map(e=>(e.note||``).replace(/:\s*Set up\.?$/,``).trim()).filter(Boolean))],r=n.length>0&&n.every(e=>/^No model/i.test(e));return(0,Q.jsxs)(`div`,{role:`status`,className:`flex w-full flex-wrap items-center gap-x-4 gap-y-3 border-y border-line py-4`,children:[(0,Q.jsx)(L,{icon:y,size:20,className:`flex-none text-accent-fg`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-[1_1_280px] flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`No agent can run yet`}),(0,Q.jsx)(`span`,{className:`text-sm text-muted [overflow-wrap:anywhere]`,children:n.length?n.join(` · `):`ForgeQE is not set up on this computer.`})]}),(0,Q.jsxs)(`a`,{className:U({variant:`primary`}),href:r?I(`settings`,`models`):I(`settings`,`setup`),"data-tip":r?`Add a model key`:`Install what's missing`,children:[(0,Q.jsx)(l,{"aria-hidden":`true`}),`Set up`]})]})}function an({item:e,favs:t}){let n=t.favs.includes(e.fav),r=e.status?Zt[e.status]:void 0,i=[e.about,r&&`${r.label}${e.note?`: ${e.note}`:``}`,e.tags.length?e.tags.join(`, `):``].filter(Boolean).join(`
2
- `);return(0,Q.jsxs)(`li`,{className:`relative`,children:[(0,Q.jsxs)(`a`,{href:e.href,"data-tip":i,className:`flex min-h-[68px] items-center gap-2.5 rounded-[12px] py-2 pr-8 pl-1.5 @min-[260px]/col:gap-3 @min-[260px]/col:pl-2 @min-[260px]/col:pr-10 text-ink no-underline hover:bg-surface-strong hover:text-ink`,children:[(0,Q.jsx)(`span`,{className:`flex size-10 flex-none items-center justify-center rounded-[10px] @min-[260px]/col:size-11 bg-surface-strong`,children:e.icon}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-2 text-[14px] leading-tight font-semibold @min-[260px]/col:text-[14.5px]`,children:e.name}),r&&(0,Q.jsx)(`span`,{className:A(`size-[7px] flex-none rounded-full`,Qt[r.tone]),"aria-hidden":`true`})]}),(0,Q.jsx)(`span`,{className:`truncate text-[13px] text-muted`,children:e.short}),(0,Q.jsxs)(`span`,{className:`sr-only`,children:[r?`${r.label}${e.note?`: ${e.note}`:``}. `:``,e.about,e.tags.length?` ${e.tags.join(`, `)}.`:``]})]})]}),(0,Q.jsx)(j,{variant:`icon`,size:`icon`,"aria-pressed":n,"aria-label":n?`Remove ${W(e.name)} from favourites`:`Add ${W(e.name)} to favourites`,"data-tip":n?`Remove from favourites`:`Add to favourites`,onClick:()=>t.toggle(e.fav),className:A(`absolute top-1/2 right-0 size-8 -translate-y-1/2`,n?`text-ink`:`text-muted`),children:(0,Q.jsx)(ie,{size:14,strokeWidth:1.8,fill:n?`currentColor`:`none`,"aria-hidden":`true`})})]})}function on({level:e}){return(0,Q.jsx)(`span`,{role:`img`,"aria-label":`Autonomy ${e} of 3`,"data-tip":[``,`Helps you decide`,`Makes the work itself`,`Acts on its own`][e],className:`ml-auto flex items-end gap-[2px]`,children:[1,2,3].map(t=>(0,Q.jsx)(`span`,{className:A(`w-[4px] rounded-[1px]`,t<=e?`bg-accent`:`bg-line`),style:{height:4+t*4}},t))})}var sn={assisted:1,native:2,agentic:3};function cn({id:e,title:t,short:n,about:r,items:i,empty:a,favs:o,footer:s}){return(0,Q.jsxs)(`section`,{"aria-labelledby":`agents-${e}`,className:`@container/col flex min-w-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 border-b border-line px-2 pt-1 pb-3 mb-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`h2`,{id:`agents-${e}`,"data-tip":r,className:`m-0 text-[16px] font-semibold`,children:[t,(0,Q.jsx)(`span`,{className:`ml-2 text-[13px] font-normal text-muted tabular-nums`,children:i.length})]}),sn[e]&&(0,Q.jsx)(on,{level:sn[e]})]}),(0,Q.jsx)(`p`,{className:`m-0 text-[13px] text-muted`,children:n}),r&&(0,Q.jsx)(`p`,{className:`sr-only`,children:r})]}),i.length?(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:i.map(e=>(0,Q.jsx)(an,{item:e,favs:o},e.fav))}):(0,Q.jsx)(z,{center:!0,className:`py-10`,action:s,children:a}),s&&i.length>0&&(0,Q.jsx)(`div`,{className:`pt-2`,children:s})]})}function ln({items:e,value:t,onChange:n}){return(0,Q.jsx)(`div`,{role:`group`,"aria-label":`Show`,className:`flex flex-wrap gap-2`,children:e.map(e=>{let r=t===e.id;return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>n(e.id),className:A(`inline-flex h-9 cursor-pointer items-center gap-2 rounded-[8px] border px-3 text-[13px] font-medium`,r?`border-accent bg-accent-soft text-ink`:`border-transparent bg-surface-strong text-ink hover:bg-line`),children:[e.tone&&(0,Q.jsx)(`span`,{className:A(`size-2 rounded-[2px]`,Qt[e.tone]),"aria-hidden":`true`}),e.label,e.n!==void 0&&(0,Q.jsx)(`span`,{className:A(`tabular-nums`,r?`opacity-70`:`text-muted`),children:e.n})]},e.id)})})}var un=`favourites`;function dn(){return(0,Q.jsxs)(`a`,{href:I(`agents`,`custom`,`new`),className:A(U({variant:`primary`}),`no-underline`),"data-tip":`New agent`,children:[(0,Q.jsx)(n,{"aria-hidden":`true`}),`New`]})}function fn({onDone:e}){let[t,n]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(``),v=(0,Z.useRef)(null),y=()=>{a(null),s(``),l(``),d(null),p(!1),_(``)},b=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let e=String(r.result||``),n=e.indexOf(`,`);t(n>=0?e.slice(n+1):e)},r.onerror=()=>n(r.error||Error(`Could not read the package.`)),r.readAsDataURL(e)}),x=async e=>{if(_(``),d(null),e.size>4194304)_(`The package is larger than 4 MB.`);else try{let t=await b(e);a(t),s(e.name);let n=await H.importPreview(t);d(n),l(n.id||``)}catch(e){a(null),_(e.message||`That file is not a valid package.`)}},S=async e=>{if(i){h(!0),_(``);try{let t=await H.importPreview(i,e.trim()||void 0);d(t)}catch(e){_(e.message)}finally{h(!1)}}},C=async()=>{if(i&&u){h(!0),_(``);try{let t=await H.importPack(i,{id:c.trim()||void 0,overwriteKnowledge:f});n(!1),y(),e(t.id)}catch(e){_(e.message)}finally{h(!1)}}},w=u?[...u.missing.environments.map(e=>`environment ${e}`),...u.missing.systems.map(e=>`system ${e}`),...u.missing.capabilities.map(e=>`capability ${e}`),...u.missing.skills.map(e=>`skill ${e}`),...u.missing.knowledge.map(e=>`knowledge ${e}`)]:[],T=!(!u||u.problems.length||u.idTaken);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{size:`sm`,variant:`ghost`,onClick:()=>(n(!0),y()),"data-tip":`Import agent`,children:[(0,Q.jsx)(pe,{"aria-hidden":`true`}),`Import`]}),(0,Q.jsx)(K,{open:t,onClose:()=>(n(!1),y()),title:`Import a custom agent`,description:`A .forgeqe-agent.zip from Export to share (agent.json plus knowledge and skill files). It becomes a draft here: you edit, try and approve it. Environments and systems of this project must already exist.`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{variant:`ghost`,onClick:()=>(n(!1),y()),children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:m||!T||u?.warnings.some(e=>e.includes(`already exists here`)&&e.startsWith(`knowledge`))&&!f,onClick:()=>void C(),"data-tip":`Import as draft`,children:[(0,Q.jsx)(pe,{"aria-hidden":`true`}),`Import`]})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 text-sm`,children:[(0,Q.jsx)(`input`,{ref:v,type:`file`,accept:`.zip,application/zip`,className:`sr-only`,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&x(t)}}),(0,Q.jsxs)(j,{size:`sm`,className:`self-start`,onClick:()=>v.current?.click(),"data-tip":o?`Choose another file`:`Choose .zip package`,children:[(0,Q.jsx)(ne,{"aria-hidden":`true`}),`Choose`]}),o&&(0,Q.jsx)(`span`,{className:`text-muted`,children:o}),u&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Id`}),(0,Q.jsx)(N,{value:c,maxLength:40,spellCheck:!1,onChange:e=>l(e.target.value.toLowerCase()),onBlur:()=>void S(c)}),u.idTaken&&(0,Q.jsx)(`span`,{className:`text-[13px] text-warn`,children:`That id is taken here. Choose another before importing.`})]}),u.knowledge.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Knowledge it brings`}),(0,Q.jsx)(`ul`,{className:`m-0 list-disc pl-5 text-ink-2`,children:u.knowledge.map(e=>(0,Q.jsx)(`li`,{children:e.path},e.path))})]}),u.skills.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Skills it brings`}),(0,Q.jsx)(`ul`,{className:`m-0 list-disc pl-5 text-ink-2`,children:u.skills.map(e=>(0,Q.jsx)(`li`,{children:e.name},e.name))})]}),w.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-[12px] bg-warn-soft px-3 py-2 text-warn`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`This project still needs`}),(0,Q.jsx)(`ul`,{className:`m-0 list-disc pl-5`,children:w.map(e=>(0,Q.jsx)(`li`,{children:e},e))})]}),u.warnings.some(e=>e.startsWith(`knowledge file `)&&e.endsWith(` already exists here`))&&(0,Q.jsxs)(`label`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(kt,{checked:f,onCheckedChange:p}),`Replace existing knowledge files of the same path`]}),u.problems.length>0&&(0,Q.jsx)(`ul`,{className:`m-0 list-disc pl-5 text-fail`,children:u.problems.map((e,t)=>(0,Q.jsx)(`li`,{children:e},t))})]}),g&&(0,Q.jsx)(`p`,{className:`m-0 text-fail`,children:g})]})})]})}function pn(){let[e,t]=(0,Z.useState)(null),[n,r]=(0,Z.useState)(``),[i,a]=(0,Z.useState)(``);return(0,Z.useEffect)(()=>{let e=!1;return H.list().then(n=>{e||(We(n.agents,`replace`),t(n.agents),a(n.off||``))},n=>{e||(t([]),r(n.message))}),()=>{e=!0}},[]),{rows:e,error:n,off:i,setRows:t}}function mn(){return(0,Q.jsxs)(`p`,{role:`status`,className:`m-0 flex flex-wrap items-center gap-x-2 rounded-[12px] bg-surface-muted px-4 py-3 text-sm text-ink-2`,children:[`Custom agents are turned off for this project: none runs, from here, the terminal, the Orchestrator or a schedule.`,(0,Q.jsx)(`a`,{href:I(`settings`),children:`Turn them on in Settings, Custom agents`})]})}function hn({rows:t,onDone:n}){let[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)([]),[c,l]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(``),_=t.filter(e=>e.approvedVersion);if(!_.length)return null;let v=_.filter(e=>o.includes(e.id)),y=async()=>{if(c){m(!0);try{let e=await H.bulk(c,o,d);n(e.agents),g(`${c===`disable`?`Disabled`:`Enabled`} ${e.done.length}${e.skipped.length?`; skipped ${e.skipped.map(e=>e.id).join(`, `)} (already ${c}d)`:``}.`),l(null),s([]),a(!1)}catch(e){g(e.message)}finally{m(!1),f(``)}}};return(0,Q.jsxs)(`section`,{"aria-labelledby":`custom-bulk`,className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h2`,{id:`custom-bulk`,className:`m-0 flex-1 text-[13px] font-semibold text-muted`,children:`Disable or enable several`}),(0,Q.jsxs)(j,{size:`sm`,variant:`ghost`,onClick:()=>(a(!i),s([]),g(``)),"data-tip":i?void 0:`Select agents`,children:[i?(0,Q.jsx)(r,{"aria-hidden":`true`}):(0,Q.jsx)(e,{"aria-hidden":`true`}),i?`Cancel`:`Select`]})]}),i&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-[12px] card border p-3`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2.5 text-sm font-medium`,children:[(0,Q.jsx)(kt,{checked:o.length===_.length,onCheckedChange:e=>s(e?_.map(e=>e.id):[])}),`All `,_.length,` approved agents`]}),(0,Q.jsx)(`ul`,{className:`m-0 grid list-none grid-cols-1 gap-1.5 p-0 sm:grid-cols-2`,children:_.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`label`,{className:`flex items-center gap-2.5 text-sm`,children:[(0,Q.jsx)(kt,{checked:o.includes(e.id),onCheckedChange:t=>s(t?[...o,e.id]:o.filter(t=>t!==e.id))}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:e.name}),(0,Q.jsx)(F,{tone:en[e.state].tone,icon:!1,children:en[e.state].label})]})},e.id))}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(j,{size:`sm`,disabled:!o.length,onClick:()=>l(`disable`),children:[(0,Q.jsx)(u,{"aria-hidden":`true`}),o.length?`Disable (${o.length})`:`Disable`]}),(0,Q.jsxs)(j,{size:`sm`,variant:`ghost`,disabled:!o.length,onClick:()=>l(`enable`),children:[(0,Q.jsx)(k,{"aria-hidden":`true`}),o.length?`Enable (${o.length})`:`Enable`]})]})]}),h&&(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-[13px] text-muted`,children:h}),c&&(0,Q.jsx)(K,{open:!0,onClose:()=>(l(null),f(``)),title:`${c===`disable`?`Disable`:`Enable`} ${v.length} agent${v.length===1?``:`s`}`,description:c===`disable`?`None of them runs (not you, your team, the Orchestrator or their schedules) until a person enables it again. Their versions and history are kept.`:`Their approved versions run again, and their schedules come back.`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{variant:`ghost`,onClick:()=>(l(null),f(``)),children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:p||d!==String(v.length),onClick:()=>void y(),children:[c===`disable`?(0,Q.jsx)(u,{"aria-hidden":`true`}):(0,Q.jsx)(k,{"aria-hidden":`true`}),c===`disable`?`Disable`:`Enable`]})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-ink-2`,children:v.map(e=>e.name).join(`, `)}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsxs)(`span`,{children:[`Type `,v.length,` to confirm`]}),(0,Q.jsx)(N,{value:d,onChange:e=>f(e.target.value),autoComplete:`off`,inputMode:`numeric`})]})]})})]})}function gn({only:e}){let t=Xt(),r=pn(),[i,a]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{_e.directory().then(e=>a(e.agents),()=>a({}))},[]);let[o,s]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{je.list().then(e=>s(e.approvals.filter(e=>e.state===`waiting`)),()=>{})},[]);let[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(`all`),f=e?ht.find(t=>t.id===e):void 0,p=(0,Z.useMemo)(()=>Be(c,f?.id),[c,f]),m=(0,Z.useMemo)(()=>!f||f.id===`custom`?Je(r.rows||[],c):[],[r.rows,c,f]),h=e=>e===`custom`?m.map(nn):p.filter(t=>t.category===e).map(e=>$t(e.id,i)),g=e=>[...e.filter(e=>t.favs.includes(e.fav)),...e.filter(e=>!t.favs.includes(e.fav))],_=(f?[f]:ht).map(e=>({c:e,all:g(h(e.id))})),v=_.flatMap(e=>e.all),y=e=>u===`all`||(u===un?t.favs.includes(e.fav):e.status===u),b=e=>v.filter(t=>t.status===e).length,x=[{id:`all`,label:`All`,n:v.length},...[`attention`,`partial`,`ready`,`unavailable`].filter(e=>b(e)>0||e!==`unavailable`).map(e=>({id:e,label:Zt[e].label,n:b(e),tone:Zt[e].tone})),{id:un,label:`Favourites`,n:v.filter(e=>t.favs.includes(e.fav)).length}],S=u!==`all`||!!c.trim(),C=(e,t)=>S?`None here.`:e===`custom`?r.rows===null?`Reading your custom agents…`:r.error?`Your custom agents cannot be read: ${r.error}`:(0,Q.jsxs)(`span`,{className:`flex flex-col items-center gap-2`,children:[(0,Q.jsx)(Te,{name:Ze.agents,px:22}),(0,Q.jsx)(`span`,{className:`text-[15px] font-medium text-ink`,children:`No custom agents yet`}),(0,Q.jsx)(`span`,{children:`Make one for a job your team repeats.`})]}):`No ${t.toLowerCase()} yet.`;return(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsx)(ct,{}),(0,Q.jsxs)(`main`,{className:A(dt,`max-w-[1400px] flex-auto gap-4`),children:[f&&(0,Q.jsxs)(`a`,{href:I(`agents`),className:`inline-flex items-center gap-1.5 self-start text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),`All agents`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-6 gap-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-[1_1_480px] flex-col gap-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(Ie,{pixel:Ze.agents,size:`lg`}),(0,Q.jsx)(`h1`,{className:`m-0 text-[26px] font-semibold tracking-[-0.01em]`,children:f?f.label:`Agents`})]}),(0,Q.jsx)(`p`,{className:`m-0 max-w-[76ch] text-[14px] leading-relaxed text-ink-2`,children:f?f.about:`Open an agent to chat with it and see what it can do.`})]}),(!f||f.id===`custom`)&&!r.off&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 self-center`,children:[(0,Q.jsx)(fn,{onDone:e=>{H.list().then(e=>{We(e.agents,`replace`),r.setRows(e.agents)}),location.hash=I(`agents`,`custom`,e)}}),(0,Q.jsx)(dn,{})]})]}),(0,Q.jsx)(rn,{cards:i}),o.length>0&&(0,Q.jsx)(`a`,{href:I(`agents`,`custom`,o[0].agent),role:`status`,className:`flex items-center gap-2 self-start rounded-[12px] bg-warn-soft px-3 py-2 text-sm font-medium text-warn no-underline hover:text-warn`,children:o.length===1?`${o[0].agent} is waiting for your approval`:`${o.length} requests from your agents are waiting for your approval`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(Oe,{id:`agents-search`,label:f?`Find an agent in ${f.label}`:`Find an agent`,value:c,onChange:l}),(0,Q.jsx)(`span`,{className:`mx-2 hidden h-6 w-px bg-line sm:block`,"aria-hidden":`true`}),(0,Q.jsx)(ln,{items:x,value:u,onChange:d})]}),r.off&&(!f||f.id===`custom`)&&(0,Q.jsx)(mn,{}),f?.id===`custom`&&r.rows&&(0,Q.jsx)(hn,{rows:r.rows,onDone:r.setRows}),(0,Q.jsx)(`div`,{className:`@container`,children:(0,Q.jsx)(`div`,{className:A(`grid items-start gap-x-6 gap-y-8`,f?`max-w-[720px] grid-cols-1`:`grid-cols-1 @2xl:grid-cols-2 @5xl:grid-cols-4`),children:_.map(({c:e,all:i})=>(0,Q.jsx)(cn,{id:e.id,title:e.label,short:e.short,about:e.id===`custom`?`Agents your team makes for its own work, held to the environments and actions you choose.`:e.about,items:i.filter(y),empty:C(e.id,e.label),favs:t,footer:e.id===`custom`&&!r.off&&!S?(0,Q.jsxs)(`a`,{href:I(`agents`,`custom`,`new`),className:A(U({variant:`outline`,size:`sm`}),`justify-center gap-2 no-underline`,(r.rows?.length??0)>0&&`w-full`),"data-tip":`Make a custom agent`,children:[(0,Q.jsx)(n,{"aria-hidden":`true`}),`New`]}):void 0},e.id))})})]})]})}function _n({value:e,onChange:t,id:n}){let r=$e(e)?e:ft,[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)(10),[c,l]=(0,Z.useState)(()=>!!(Ue(`ph:robot`)||Ue(`lucide:bot`)));(0,Z.useEffect)(()=>{Le().then(()=>l(!0))},[]),(0,Z.useEffect)(()=>{s(10)},[i]);let u=!!i.trim(),{hits:d,total:f}=(0,Z.useMemo)(()=>u?ze(i,o,0):ze(``,o,Qe.length),[i,o,u]),p=Ge.length,m=u?f>o:o<p,h=u?Math.max(0,f-o):Math.max(0,p-o);return(0,Q.jsxs)(`div`,{id:n,className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`label`,{className:`relative block`,children:[(0,Q.jsx)(E,{"aria-hidden":`true`,className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted`}),(0,Q.jsx)(N,{value:i,onChange:e=>a(e.target.value),placeholder:`Search Phosphor and Lucide icons…`,"aria-label":`Search icons`,className:`pl-9`,spellCheck:!1})]}),!u&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-2 text-[13px] text-muted`,children:`ForgeQE faces`}),(0,Q.jsx)(`div`,{role:`listbox`,"aria-label":`ForgeQE faces`,className:`flex flex-wrap gap-2`,children:Qe.map(e=>(0,Q.jsx)(vn,{icon:e,label:rt(e),selected:e===r,ready:!0,onPick:t},e))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-2 text-[13px] text-muted`,children:u?`Top matches (${f})`:`Library icons (Phosphor and Lucide)`}),(0,Q.jsxs)(`div`,{role:`listbox`,"aria-label":u?`Icon search results`:`Library icons`,className:`flex flex-wrap gap-2`,children:[d.map(e=>(0,Q.jsx)(vn,{icon:e.id,label:e.label,selected:e.id===r,ready:c||e.kind===`face`,onPick:t},e.id)),d.length===0&&(0,Q.jsx)(`p`,{className:`text-[13px] text-muted`,children:`No icons match that search.`})]}),m&&(0,Q.jsxs)(`button`,{type:`button`,className:`mt-3 inline-flex items-center gap-1 text-[13px] font-medium text-accent underline-offset-4 hover:underline`,"data-tip":`Show ${Math.min(10,h)} of ${h} more`,onClick:()=>s(e=>e+10),children:[(0,Q.jsx)(C,{size:14,"aria-hidden":`true`}),`More (`,h,`)`]})]}),Xe(r)&&(0,Q.jsxs)(`p`,{className:`text-[13px] text-muted`,children:[`Selected `,(0,Q.jsx)(`span`,{className:`font-mono text-fg`,children:r})]})]})}function vn({icon:e,label:t,selected:n,ready:r,onPick:i}){return(0,Q.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":n,"aria-label":t,"data-tip":t,disabled:!r&&!!Xe(e),className:A(`inline-flex size-11 cursor-pointer items-center justify-center rounded-[10px] border bg-bg text-fg transition-colors disabled:cursor-wait disabled:opacity-50`,n?`border-accent ring-2 ring-accent/30`:`border-line-soft hover:border-line`),onClick:()=>i(e),children:lt(e)?(0,Q.jsx)(Te,{name:e,px:28}):(0,Q.jsx)(He,{agent:`custom`,icon:e,px:28,decorative:!0})})}var yn=[{label:`Defect retest`,about:`Each morning, retests the defects resolved since yesterday and says which are really fixed.`,text:`Every morning, find the defects resolved in our tracker since yesterday, retest each one on QA by rerunning its test or following its steps in a real browser, and tell me which are really fixed and which still fail, with screenshots. Add the result as a comment on each defect.`},{label:`Nightly smoke`,about:`Each night, runs the critical flows on QA and tells the team what broke and why.`,text:`Every night, run our critical flows (sign-in, search, checkout) on QA in a real browser, and tell the team in our channel what broke, with screenshots and the likely cause.`},{label:`Pull request test check`,about:`Reviews a pull request's tests, runs the ones it touches, and says what is missing or risky.`,text:`When I give it a pull request, review its tests and changes, run the automated tests it touches, and tell me what is missing or risky before I merge.`},{label:`Release readiness`,about:`Runs a release's regression pack and says whether it is ready to ship and what blocks it.`,text:`For a release I name, run its regression pack on QA, look at its test cases' results and its open defects, and tell me if it is ready to ship and what blocks it.`},{label:`API contracts`,about:`Checks an API against its contracts after each deploy and explains any break.`,text:`Check our order API against its contracts after each deploy and explain any break`},{label:`Test case quality`,about:`Reviews a story's test cases and says what is missing or vague.`,text:`Review a story's test cases and tell me what is missing or vague`}];function bn(){let[e,t]=(0,Z.useState)(``),[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)([]),[c,u]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{ke.list().then(e=>s(e.sessions.filter(e=>!e.saved)),()=>{}),H.templates().then(e=>u(e.templates),()=>{})},[]);let d=async()=>{if(e.trim()){r(!0),a(``);try{let t=await ke.start(e.trim());location.hash=I(`agents`,`custom`,`build`,t.sid)}catch(e){a(e.message),r(!1)}}};return(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-1 px-5 py-3.5`,children:[(0,Q.jsx)(nt,{}),(0,Q.jsxs)(`a`,{href:I(`agents`,`category`,`custom`),className:`inline-flex min-h-9 items-center gap-1.5 text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),`Custom agents`]})]}),(0,Q.jsx)(`main`,{className:`flex flex-auto flex-col items-center justify-center px-5 pt-6 pb-[120px]`,children:(0,Q.jsxs)(`div`,{className:`flex w-full max-w-[780px] flex-col items-center gap-9`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3.5 text-center`,children:[(0,Q.jsx)(Ae,{state:n?`working`:`idle`,px:112,label:n?`ForgeQE is working it out`:`ForgeQE is ready to build an agent`,className:`mb-1`}),(0,Q.jsx)(`h1`,{className:`m-0 text-[34px] leading-tight font-semibold tracking-[-0.015em] text-ink`,children:`What should your agent do?`}),(0,Q.jsx)(`p`,{className:`m-0 max-w-[54ch] text-[15px] leading-relaxed text-ink-2`,children:`Say it in your own words. ForgeQE works out what it needs from what your project has, asks only what it cannot decide, and builds it with you step by step.`})]}),(0,Q.jsx)(vt,{id:`build-goal`,label:`What your agent should do`,value:e,onChange:e=>{t(e),a(``)},onSend:()=>void d(),busy:n,disabled:n,placeholder:`An agent that checks the checkout on QA and tells me what broke…`}),i&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 -mt-6 text-sm text-fail`,children:i}),(0,Q.jsxs)(`section`,{"aria-labelledby":`build-starters`,className:`flex w-full flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`build-starters`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Or start from one of these, and change it to fit`}),(0,Q.jsx)(`ul`,{className:`m-0 grid list-none grid-cols-1 gap-2 p-0 sm:grid-cols-2`,children:yn.map(n=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":e===n.text,onClick:()=>{t(n.text),a(``),document.getElementById(`build-goal`)?.focus()},className:A(`flex h-full w-full cursor-pointer flex-col items-start gap-0.5 rounded-[12px] border px-3.5 py-2.5 text-left hover:bg-surface-muted`,e===n.text?`border-accent bg-accent-soft`:`border-line-soft bg-transparent`),children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium text-ink`,children:n.label}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:n.about})]})},n.label))})]}),o.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`build-resume`,className:`flex w-full flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`build-resume`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Pick up where you left off`}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:o.slice(0,5).map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`a`,{href:I(`agents`,`custom`,`build`,e.sid),className:`flex min-h-11 items-center gap-3 rounded-[8px] px-3 py-1.5 text-ink no-underline hover:bg-surface-muted hover:text-ink`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[14px]`,children:e.goal}),(0,Q.jsxs)(`span`,{className:`flex-none text-[12.5px] text-muted`,children:[xn[e.step].label,` · `,Ot(e.updatedAt)]})]})},e.sid))})]}),c.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`build-templates`,className:`flex w-full flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`build-templates`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Or start from a template, and review it before you save`}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:c.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`a`,{href:I(`agents`,`custom`,`new`,`template`,e.id),className:`flex min-h-11 items-center gap-3 rounded-[8px] px-3 py-1.5 text-ink no-underline hover:bg-surface-muted hover:text-ink`,children:[(0,Q.jsx)(`span`,{className:`flex-none text-[14px]`,children:e.title}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 text-[12.5px] text-muted`,children:e.why||e.about})]})},e.id))})]}),(0,Q.jsxs)(`a`,{href:I(`agents`,`custom`,`new`,`form`),className:`inline-flex items-center gap-1.5 text-[13px]`,children:[(0,Q.jsx)(l,{size:14,"aria-hidden":`true`}),`Or set every option yourself`]})]})})]})}var xn={understand:{label:`Understand`,title:`Let's understand your requirements`,next:`Make the plan`,working:`Working out the plan…`,thinking:`Reading what you want, and what your project has…`},plan:{label:`Plan`,title:`Here's how your agent will work`,next:`Set its boundaries`,working:`Working out what it may do…`,thinking:`Planning how your agent will do it, step by step…`},boundaries:{label:`Boundaries`,title:`Where it works and what it may do`,next:`Choose what it knows`,working:`Looking for what it should know…`,thinking:``},knowledge:{label:`Knowledge`,title:`What it should know`,next:`Review it`,working:`Putting it together…`,thinking:``},review:{label:`Review`,title:`Your agent`,next:`Save it as a draft`,working:`Saving it…`,thinking:`Naming it, and writing its instructions…`},try:{label:`Try`,title:`Try it, then approve it`,next:``,working:``,thinking:``}};function Sn({sid:e}){let[t,n]=(0,Z.useState)(null),[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1);if((0,Z.useEffect)(()=>{ke.view(e).then(e=>{n(e),o(Math.min(e.reached,e.steps.length-1))},e=>i(e.message))},[e]),(0,Z.useEffect)(()=>{if(!t?.working)return;let r=setTimeout(()=>{ke.view(e).then(n,()=>{})},1500);return()=>clearTimeout(r)},[t,e]),r&&!t)return(0,Q.jsx)(Cn,{children:(0,Q.jsxs)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail`,children:[r,` `,(0,Q.jsx)(`a`,{href:I(`agents`,`custom`,`new`),children:`Start again`})]})});if(!t||a===null)return(0,Q.jsx)(Cn,{children:(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`})});let l=t.steps[a].id,u=xn[l],d=s||t.working===l,f=async t=>{if(l!==`try`){c(!0),i(``);try{let r=await ke.answer(e,l,t);n(r),o(Math.min(a+1,r.steps.length-1)),window.scrollTo({top:0})}catch(e){i(e.message)}finally{c(!1)}}};return(0,Q.jsxs)(Cn,{children:[(0,Q.jsxs)(`a`,{href:I(`agents`,`category`,`custom`),className:`inline-flex items-center gap-1.5 self-start text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),`Custom agents`]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] text-muted`,children:`New agent`}),(0,Q.jsxs)(`p`,{className:`m-0 text-[15px] text-ink-2 [overflow-wrap:anywhere]`,children:[`“`,t.goal,`”`]})]}),(0,Q.jsx)(wn,{v:t,at:a,onGo:e=>!s&&o(e)}),(0,Q.jsxs)(`section`,{"aria-labelledby":`build-step`,className:`flex flex-col gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(Ae,{state:d?`working`:`idle`,px:36,label:d?u.working:`ForgeQE`,className:`flex-none`}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Q.jsx)(`h1`,{id:`build-step`,className:`m-0 text-[22px] font-semibold tracking-[-0.01em]`,children:u.title}),(0,Q.jsx)(`p`,{className:`m-0 max-w-[72ch] text-[15px] leading-relaxed text-ink-2`,children:d?t.working===l?xn[l].thinking:u.working:t.says[l]}),!d&&t.source?.[l]&&(0,Q.jsx)(`span`,{className:`text-[12px] text-muted`,children:t.source[l]===`model`?`Worked out by ForgeQE's model from what you said and what your project has.`:t.note||`Worked out by ForgeQE's rules: no model is set up.`})]})]}),r&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:r}),t.working===l?null:l===`understand`&&(0,Q.jsx)(Dn,{v:t,busy:s,onNext:f,next:u.next},`u-${t.updatedAt}`),t.working!==l&&l===`plan`&&(0,Q.jsx)(kn,{v:t,busy:s,onNext:f,onBack:()=>o(a-1),next:u.next},`p-${t.updatedAt}`),l===`boundaries`&&(0,Q.jsx)(An,{v:t,busy:s,onNext:f,onBack:()=>o(a-1),next:u.next},`b-${t.updatedAt}`),l===`knowledge`&&(0,Q.jsx)(jn,{v:t,busy:s,onNext:f,onBack:()=>o(a-1),next:u.next},`k-${t.updatedAt}`),t.working!==l&&l===`review`&&(0,Q.jsx)(Mn,{v:t,busy:s,onNext:f,onBack:()=>o(a-1),next:u.next},`r-${t.updatedAt}`),l===`try`&&(0,Q.jsx)(Nn,{v:t})]})]})}function Cn({children:e}){return(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsx)(ct,{}),(0,Q.jsx)(`main`,{className:A(dt,`max-w-[920px] flex-auto gap-6`),children:e})]})}function wn({v:e,at:t,onGo:n}){return(0,Q.jsx)(`nav`,{"aria-label":`Steps`,children:(0,Q.jsx)(`ol`,{className:`m-0 flex list-none flex-wrap gap-x-1 gap-y-2 p-0`,children:e.steps.map((r,a)=>{let o=a<=e.reached,s=a===t;return(0,Q.jsxs)(`li`,{className:`flex items-center gap-1`,children:[(0,Q.jsxs)(`button`,{type:`button`,disabled:!o,"aria-current":s?`step`:void 0,onClick:()=>n(a),className:A(`inline-flex min-h-9 items-center gap-2 rounded-[8px] border-0 px-2.5 text-[13px] font-medium`,s?`bg-accent-soft text-ink`:o?`cursor-pointer bg-transparent text-ink-2 hover:bg-surface-strong`:`bg-transparent text-muted`),children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:A(`inline-flex size-5 items-center justify-center rounded-full text-[11px] tabular-nums`,r.done&&!s?`bg-pass-soft text-pass`:s?`bg-accent text-accent-ink`:`bg-surface-strong text-muted`),children:r.done&&!s?(0,Q.jsx)(i,{size:12,strokeWidth:3}):a+1}),xn[r.id].label]}),a<e.steps.length-1&&(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`h-px w-4 bg-line`})]},r.id)})})})}function Tn({busy:e,onBack:t,next:n,onNext:r,disabled:a,aside:o}){let s=n.startsWith(`Save`);return(0,Q.jsxs)(`div`,{className:`sticky bottom-0 flex flex-wrap items-center gap-3 border-t border-line-soft bg-bg py-3`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 text-[13px]`,children:o}),t&&(0,Q.jsxs)(j,{variant:`ghost`,disabled:e,onClick:t,children:[(0,Q.jsx)(O,{"aria-hidden":`true`}),`Back`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:e||a,onClick:r,"data-tip":n,children:[s?(0,Q.jsx)(i,{"aria-hidden":`true`}):(0,Q.jsx)(se,{"aria-hidden":`true`}),s?`Save`:`Next`]})]})}function En({on:e,label:t,why:n,recommended:r,onToggle:a}){return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":e,onClick:a,className:A(`flex min-h-11 w-full cursor-pointer items-start gap-3 rounded-[12px] border px-3.5 py-2.5 text-left`,e?`border-accent bg-accent-soft`:`border-line-soft bg-bg hover:bg-surface-muted`),children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:A(`mt-0.5 inline-flex size-4 flex-none items-center justify-center rounded-[4px] border`,e?`border-accent bg-accent text-accent-ink`:`border-muted`),children:e&&(0,Q.jsx)(i,{size:12,strokeWidth:3})}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-[14px] font-medium text-ink`,children:[t,r&&(0,Q.jsx)(F,{tone:`running`,icon:!1,children:`Recommended`})]}),n&&(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:n})]})]})}function Dn({v:e,busy:t,onNext:n,next:r}){let[i,a]=(0,Z.useState)(()=>Object.fromEntries(e.questions.map(e=>[e.id,e.answer]))),[o,s]=(0,Z.useState)([]),c=(e,t,n)=>a(r=>{let i=r[e]||[];return{...r,[e]:t===`one`?[n]:i.includes(n)?i.filter(e=>e!==n):[...i,n]}});return(0,Q.jsxs)(Q.Fragment,{children:[e.questions.map(e=>{let t=e.assumed&&!o.includes(e.id);return(0,Q.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-2 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`legend`,{className:`sr-only`,children:e.text}),(0,Q.jsx)(`span`,{className:`text-[15px] font-semibold`,children:e.text}),t?(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm text-ink-2`,children:[(0,Q.jsx)(L,{icon:k,size:16,className:`text-pass`}),e.assumed,!(i[e.id]||[]).every(t=>e.assumed?.includes(t))&&(0,Q.jsxs)(`span`,{className:`text-muted`,children:[`(`,i[e.id]?.join(`, `),`)`]}),(0,Q.jsx)(j,{size:`sm`,variant:`ghost`,onClick:()=>s([...o,e.id]),"aria-label":`Change the answer`,"data-tip":`Change the answer`,children:(0,Q.jsx)(w,{"aria-hidden":`true`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-[13px] text-muted`,children:e.why}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:e.options.map(t=>(0,Q.jsx)(En,{on:(i[e.id]||[]).includes(t.id),label:t.label,why:t.why,recommended:t.recommended,onToggle:()=>c(e.id,e.kind,t.id)},t.id))})]})]},e.id)}),(0,Q.jsx)(Tn,{busy:t,next:r,onNext:()=>n({answers:i}),disabled:e.questions.some(e=>e.id===`environment`&&!(i[e.id]||[]).length),aside:e.environments.length===0?(0,Q.jsx)(`span`,{className:`text-fail`,children:`Add a test environment in Settings first: an agent needs one to work in.`}):void 0})]})}var On={ready:{icon:k,label:`Ready`,tone:`text-pass`},partial:{icon:m,label:`Partly set up`,tone:`text-warn`},needs_setup:{icon:u,label:`Not set up here yet`,tone:`text-muted`}};function kn({v:e,busy:t,onNext:r,onBack:i,next:a}){let[o,s]=(0,Z.useState)(()=>e.plan.filter(e=>e.on).map(e=>e.capability)),[c,l]=(0,Z.useState)(!1),u=o.map(t=>e.plan.find(e=>e.capability===t)).filter(Boolean),d=e.plan.filter(e=>!o.includes(e.capability));return(0,Q.jsxs)(Q.Fragment,{children:[e.planSteps&&e.planSteps.length>0&&(0,Q.jsx)(`ol`,{"aria-label":`How it will work`,className:`m-0 flex list-none flex-col gap-0 rounded-[14px] card border p-0`,children:e.planSteps.map((t,n)=>(0,Q.jsxs)(`li`,{className:A(`flex items-start gap-3 px-4 py-3`,n>0&&`border-t border-line-soft`),children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`inline-flex size-7 flex-none items-center justify-center rounded-full bg-accent-soft text-[13px] font-semibold text-accent-fg tabular-nums`,children:n+1}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`text-[15px] font-semibold`,children:t.title}),(0,Q.jsx)(`span`,{className:`text-[13.5px] text-ink-2`,children:t.why}),t.without&&(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[`Without it: `,t.without]}),(0,Q.jsx)(`span`,{className:`flex flex-wrap gap-1.5 pt-1`,children:t.uses.map(t=>{let n=e.plan.find(e=>e.capability===t);return(0,Q.jsx)(`span`,{className:`rounded-[6px] bg-surface-strong px-2 py-0.5 text-[12px] text-ink-2`,children:n?.title||t},t)})})]})]},n))}),e.planSteps&&e.planSteps.length>0&&(0,Q.jsx)(`h2`,{className:`m-0 mt-2 text-[13px] font-semibold text-muted`,children:`What it uses`}),(0,Q.jsx)(`ol`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:u.map((e,t)=>{let n=On[e.state];return(0,Q.jsxs)(`li`,{className:`flex items-start gap-3 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`inline-flex size-7 flex-none items-center justify-center rounded-full bg-accent-soft text-[13px] font-semibold text-accent-fg tabular-nums`,children:t+1}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-[15px] font-semibold`,children:e.title}),e.why&&(0,Q.jsx)(`span`,{className:`text-[13.5px] text-ink-2`,children:e.why}),(0,Q.jsx)(`span`,{className:`line-clamp-2 text-[13px] text-muted`,children:e.summary}),(0,Q.jsxs)(`span`,{className:A(`flex items-center gap-1.5 text-[12.5px]`,n.tone),children:[(0,Q.jsx)(L,{icon:n.icon,size:14}),n.label,e.state!==`ready`&&e.gaps.length?`: ${e.gaps.join(`; `)}`:``]})]}),(0,Q.jsx)(j,{variant:`icon`,size:`icon`,"aria-label":`Leave out ${e.title}`,"data-tip":`Leave out ${e.title}`,onClick:()=>s(o.filter(t=>t!==e.capability)),children:(0,Q.jsx)(ue,{"aria-hidden":`true`})})]},e.capability)})}),c?(0,Q.jsxs)(`section`,{"aria-labelledby":`build-add`,className:`flex flex-col gap-2 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`h2`,{id:`build-add`,className:`m-0 text-[14px] font-semibold`,children:`What else should it do?`}),(0,Q.jsx)(`ul`,{className:`m-0 grid list-none grid-cols-1 gap-2 p-0 sm:grid-cols-2`,children:d.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s([...o,e.capability]),className:`flex h-full w-full cursor-pointer items-start gap-2 rounded-[10px] border border-line-soft bg-bg px-3 py-2 text-left hover:bg-surface-muted`,children:[(0,Q.jsx)(n,{size:16,"aria-hidden":`true`,className:`mt-0.5 flex-none text-muted`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[13.5px] font-medium`,children:e.title}),(0,Q.jsx)(`span`,{className:`line-clamp-2 text-[12px] text-muted`,children:e.summary})]})]})},e.capability))})]}):(0,Q.jsxs)(j,{size:`sm`,className:`self-start`,onClick:()=>l(!0),"data-tip":`Add something it should also do`,children:[(0,Q.jsx)(n,{"aria-hidden":`true`}),`Add`]}),(0,Q.jsx)(Tn,{busy:t,onBack:i,next:a,onNext:()=>r({capabilities:o}),disabled:!o.length})]})}function $({text:e,help:t,on:n,onChange:r,locked:i}){return(0,Q.jsxs)(`div`,{className:`flex items-start gap-4 border-t border-line-soft py-3 first:border-t-0`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] text-ink`,children:e}),(t||i)&&(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:i||t})]}),i?(0,Q.jsx)(de,{size:18,"aria-label":`Always`,className:`mt-0.5 flex-none text-muted`}):(0,Q.jsx)(mt,{checked:n,onChange:e=>r?.(e),label:e})]})}function An({v:e,busy:t,onNext:n,onBack:r,next:i}){let a=e.boundaries,[o,s]=(0,Z.useState)(a.environments),[c,l]=(0,Z.useState)(a.actions),[u,d]=(0,Z.useState)(a.approve),[f,p]=(0,Z.useState)(a.shell),[m,h]=(0,Z.useState)(a.repository),[g,_]=(0,Z.useState)(a.unattended),[v,y]=(0,Z.useState)(a.trust||[]),[b,x]=(0,Z.useState)((a.production||[]).includes(`run`)),S=o.some(t=>e.production.includes(t)),C=(e,t)=>y(t?[...new Set([...v,e])]:v.filter(t=>t!==e)),w=e.plan.filter(e=>e.on&&e.capability.startsWith(`system:`)),T=(e,t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],E=e=>c.includes(e),D=(e,t)=>l(t?[...new Set([...c,e])]:c.filter(t=>t!==e)),O=(e,t)=>d(t?[...new Set([...u,e])]:u.filter(t=>t!==e)),ee=o.join(` and `)||`its environments`;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-2 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`legend`,{className:`sr-only`,children:`Where it works`}),(0,Q.jsx)(`span`,{className:`text-[15px] font-semibold`,children:`Where it works`}),(0,Q.jsx)(`span`,{className:`text-[13px] text-muted`,children:`Every run, test and call goes only here. In production it reads without asking, and a person approves every change.`}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:(0,Q.jsx)(Ne,{items:e.environments.map(t=>({id:t,label:t,...e.production.includes(t)&&!/prod/i.test(t)?{note:`production`,noteClass:`text-warn`}:{}})),value:o,onChange:s})}),S&&(0,Q.jsx)(`span`,{className:`text-[12.5px] text-warn`,children:`In production, it reads without asking; a person approves every change there, on a schedule too (it waits, and the team is told). Before a step that could reach real customers, it asks you itself.`})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`build-may`,className:`flex flex-col rounded-[14px] card border px-4 py-1`,children:[(0,Q.jsx)(`h2`,{id:`build-may`,className:`sr-only`,children:`What it may do`}),(0,Q.jsx)($,{text:`Read test cases, runs, reports and your systems' data`,on:!0,locked:`Always: it cannot work without it, and it changes nothing.`}),e.needs?.run&&(0,Q.jsx)($,{text:`Run tests and apps in ${ee}`,help:`Browser runs, tests, API calls and database queries.`,on:E(`run`),onChange:e=>D(`run`,e)}),e.needs?.run&&E(`run`)&&(0,Q.jsx)($,{text:`Ask me before each run`,help:`Recommended while it is new; turn it off once you trust it.`,on:u.includes(`run`),onChange:e=>O(`run`,e)}),e.needs?.run&&E(`run`)&&S&&(0,Q.jsx)($,{text:`Ask me before each run in production`,help:`Off: browser runs, tests and API calls there go ahead without asking. Each question also offers to allow the rest of the run.`,on:!b,onChange:e=>x(!e)}),(0,Q.jsx)($,{text:`Change test assets on this computer`,help:`Regression packs, API contracts, page memory, recordings. Off unless its job is to make them.`,on:E(`change`),onChange:e=>D(`change`,e)}),E(`change`)&&(0,Q.jsx)($,{text:`Ask me before each change`,on:u.includes(`change`),onChange:e=>O(`change`,e)}),e.needs?.external&&(0,Q.jsx)($,{text:`Change other systems as you asked`,help:`Work items or the team's channel, as you chose.`,on:E(`external`),onChange:e=>D(`external`,e)}),E(`external`)&&(0,Q.jsx)($,{text:`Ask me before each change to another system`,help:`Recommended. Off: it comments, updates and attaches as its job says, without asking.`,on:!v.includes(`external`),onChange:e=>C(`external`,!e)}),e.needs?.repository&&(0,Q.jsx)($,{text:`Change your repository to write or heal tests`,help:`A coding agent does it on this computer.`,on:m===`write`,onChange:e=>(h(e?`write`:`read`),e&&D(`change`,!0))}),e.needs?.repository&&m===`write`&&(0,Q.jsx)($,{text:`Ask me before the coding agent works`,help:`Off: it writes and heals tests without asking. The tests it runs can reach any address, so ForgeQE first looks in your test project's config and env files, and asks you when they name an address outside its environments.`,on:!v.includes(`coding`),onChange:e=>C(`coding`,!e)}),(0,Q.jsx)($,{text:`Use the shell`,help:`Commands on this computer, and fetching web pages. A person approves each one; ForgeQE's secrets stay out of reach.`,on:f,onChange:p})]}),e.schedule&&(0,Q.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-2 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`legend`,{className:`sr-only`,children:`What it may do alone`}),(0,Q.jsxs)(`span`,{className:`text-[15px] font-semibold`,children:[`When it runs `,e.schedule.toLowerCase(),`, with nobody watching`]}),(0,Q.jsx)(`span`,{className:`text-[13px] text-muted`,children:`What it may do without asking. Anything else waits for a person: the team is told, and no answer in four hours is a no. It may always ask a person itself.`}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[E(`run`)&&(0,Q.jsx)(En,{on:g.includes(`run`),label:`Run tests and apps`,why:`Recommended: what it is there to do.`,recommended:!0,onToggle:()=>_(T(g,`run`))}),E(`change`)&&(0,Q.jsx)(En,{on:g.includes(`change`),label:`Change test assets`,onToggle:()=>_(T(g,`change`))}),m===`write`&&v.includes(`coding`)&&(0,Q.jsx)(En,{on:g.includes(`coding`),label:`Write or heal tests`,why:`The coding agent, when its test project names no address outside its environments.`,onToggle:()=>_(T(g,`coding`))}),w.map(e=>(0,Q.jsx)(En,{on:g.includes(`${e.capability.slice(7)}_*`),label:`Change ${e.title.replace(/^Work with /,``)}`,why:`Comment, update states, attach evidence, without a person approving each.`,onToggle:()=>_(T(g,`${e.capability.slice(7)}_*`))},e.capability))]})]}),(0,Q.jsx)(Tn,{busy:t,onBack:r,next:i,onNext:()=>n({environments:o,actions:c,approve:u,repository:m,shell:f,unattended:g,trust:v,production:b?[`run`]:[]}),disabled:!o.length})]})}function jn({v:e,busy:t,onNext:n,onBack:r,next:i}){let a=e.knowledge,[o,s]=(0,Z.useState)(a.files.filter(e=>e.on).map(e=>e.file)),[c,l]=(0,Z.useState)(a.skills.filter(e=>e.on).map(e=>e.name)),[u,d]=(0,Z.useState)(a.notes),f=(e,t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],p=e=>[...e].sort((e,t)=>Number(!!t.why)-Number(!!e.why));return(0,Q.jsxs)(Q.Fragment,{children:[(a.files.length>0||a.skills.length>0)&&(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[p(a.files).map(e=>(0,Q.jsx)(En,{on:o.includes(e.file),label:e.title,why:e.why||e.file,recommended:e.on,onToggle:()=>s(f(o,e.file))},e.file)),p(a.skills).map(e=>(0,Q.jsx)(En,{on:c.includes(e.name),label:`Skill: ${e.name}`,why:e.why||e.about,recommended:e.on,onToggle:()=>l(f(c,e.name))},e.name))]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[15px] font-semibold`,children:`Anything else it should know?`}),(0,Q.jsx)(`span`,{className:`text-[13px] text-muted`,children:`Business rules, what “done” looks like, which test accounts to use (never passwords). It is kept as this agent's own knowledge.`}),(0,Q.jsx)(V,{rows:5,value:u,maxLength:2e4,onChange:e=>d(e.target.value),placeholder:`A declined card shows “Payment failed” and keeps the basket.`})]}),(0,Q.jsx)(Tn,{busy:t,onBack:r,next:i,onNext:()=>n({files:o,skills:c,notes:u})})]})}function Mn({v:e,busy:t,onNext:n,onBack:r,next:i}){let a=e.review,[o,s]=(0,Z.useState)(a.name),[c,u]=(0,Z.useState)(a.id),[d,f]=(0,Z.useState)(a.description),[p,m]=(0,Z.useState)(a.icon||`context-engine`),[h,g]=(0,Z.useState)(a.starters[0]?.text||e.goal),_=e.plan.filter(e=>e.on),v=e.boundaries,y=e.knowledge,b=[[`It works in`,v.environments.join(`, `)],[`It does`,_.map(e=>e.title).join(`; `)],[`It may`,[v.actions.includes(`run`)?`run tests and apps${v.approve.includes(`run`)?` (asking you first)`:``}`:``,v.actions.includes(`change`)?`change test assets`:``,v.actions.includes(`external`)?`change other systems${(v.trust||[]).includes(`external`)?` (without asking)`:` (asking you first)`}`:``,v.repository===`write`?`write or heal tests${(v.trust||[]).includes(`coding`)?` (without asking, unless its test project names an address outside its environments)`:` (asking you first)`}`:``].filter(Boolean).join(`; `)||`only read`],[`Runs by itself`,e.schedule?`${e.schedule.toLowerCase()}, with nobody watching${v.unattended.length?`; alone it may ${v.unattended.map(e=>e===`run`?`run tests and apps`:e===`change`?`change test assets`:e===`coding`?`write or heal tests`:`change ${e.replace(/_\*$/,``).replace(/_/g,` `)}`).join(`, `)}`:``}`:`no: you, your team or the Orchestrator start it`],...v.shell?[[`Shell`,`yes, a person approves each command`]]:[],[`It knows`,[...y.files.filter(e=>e.on).map(e=>e.title),...y.skills.filter(e=>e.on).map(e=>e.name),...y.notes.trim()?[`your notes`]:[]].join(`, `)||`nothing extra`]];return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Name`}),(0,Q.jsx)(N,{value:o,maxLength:60,onChange:e=>s(e.target.value)})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Id`}),(0,Q.jsx)(N,{value:c,maxLength:40,spellCheck:!1,disabled:!!e.saved,onChange:e=>u(e.target.value.toLowerCase())})]})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`What it is for`}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`One line. The Orchestrator reads it to know when to hand it work.`}),(0,Q.jsx)(N,{value:d,maxLength:300,onChange:e=>f(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Icon`}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`What it wears on the Agents page. Pick one of ForgeQE's agent icons.`}),(0,Q.jsx)(_n,{value:p,onChange:m})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Its first request`}),(0,Q.jsx)(N,{value:h,maxLength:500,onChange:e=>g(e.target.value)})]}),(0,Q.jsx)(`dl`,{className:`m-0 grid grid-cols-1 gap-x-6 gap-y-2 rounded-[14px] bg-surface-muted px-4 py-3 text-sm sm:grid-cols-[140px_1fr]`,children:b.map(([e,t])=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(`dt`,{className:`text-muted`,children:e}),(0,Q.jsx)(`dd`,{className:`m-0 text-ink [overflow-wrap:anywhere]`,children:t})]},e))}),e.advice.filter(e=>e.blocking).length>0&&(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:e.advice.filter(e=>e.blocking).map((e,t)=>(0,Q.jsxs)(`li`,{className:`flex flex-col gap-0.5 rounded-[12px] bg-warn-soft px-4 py-3 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-warn`,children:e.about}),(0,Q.jsx)(`span`,{className:`text-[13px] text-ink-2`,children:e.fix})]},t))}),(0,Q.jsx)(Tn,{busy:t,onBack:r,next:e.saved?`Save the changes`:i,onNext:()=>n({name:o,id:c,description:d,icon:p,starters:[{label:`Run it now`,text:h}]}),disabled:!o.trim()||!c.trim(),aside:(0,Q.jsxs)(`a`,{href:e.saved?I(`agents`,`custom`,e.saved,`edit`):I(`agents`,`custom`,`new`,`form`),className:`inline-flex items-center gap-1.5`,children:[(0,Q.jsx)(l,{size:14,"aria-hidden":`true`}),`Advanced settings`]})})]})}function Nn({v:e}){let t=e.saved,[n,r]=(0,Z.useState)(e.review?.starters[0]?.text||e.goal),[i,a]=(0,Z.useState)(``),[o,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(!1),p=async()=>{c(!0);try{let{id:e}=await Pe.start(n.trim(),{agent:t,try:!0});location.hash=I(`chats`,e)}catch(e){u(e.message),c(!1)}},m=async()=>{c(!0),u(``);try{await H.act(t,`approve`,{confirm:i,note:`Made with the agent builder`}),f(!0)}catch(e){u(e.message)}finally{c(!1)}};return d?(0,Q.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-[14px] bg-pass-soft px-4 py-4`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2 text-[15px] font-semibold text-pass`,children:[(0,Q.jsx)(k,{size:18,"aria-hidden":`true`}),W(e.review?.name||`agent`,!0),` is ready.`]}),(0,Q.jsx)(`span`,{className:`text-sm text-ink-2`,children:`You, your team and the Orchestrator can hand it work now.`}),(0,Q.jsxs)(`a`,{href:I(`agents`,`custom`,t),className:A(U({variant:`primary`,size:`sm`}),`no-underline`),"data-tip":`Open the agent`,children:[(0,Q.jsx)(se,{"aria-hidden":`true`}),`Open`]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`section`,{"aria-labelledby":`build-try`,className:`flex flex-col gap-2 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`h2`,{id:`build-try`,className:`m-0 text-[15px] font-semibold`,children:`1. Try it on a real request`}),(0,Q.jsx)(V,{rows:2,"aria-label":`What to try`,value:n,onChange:e=>r(e.target.value)}),(0,Q.jsxs)(j,{variant:`primary`,size:`sm`,className:`self-start`,disabled:o||!n.trim(),onClick:()=>void p(),"data-tip":`Try it in a chat`,children:[(0,Q.jsx)(s,{"aria-hidden":`true`}),`Try`]}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`It opens as a chat. Come back here to approve it: Agents, Custom agents, then this agent.`})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`build-approve`,className:`flex flex-col gap-2 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`h2`,{id:`build-approve`,className:`m-0 text-[15px] font-semibold`,children:`2. Approve it`}),(0,Q.jsxs)(`span`,{className:`text-[13px] text-muted`,children:[`Only an approved version runs. Type its id to confirm: `,t]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(N,{"aria-label":`Type ${t} to confirm`,className:`w-[260px]`,value:i,spellCheck:!1,autoComplete:`off`,onChange:e=>a(e.target.value),placeholder:t}),(0,Q.jsxs)(j,{size:`sm`,disabled:o||i!==t,onClick:()=>void m(),children:[(0,Q.jsx)(k,{"aria-hidden":`true`}),`Approve`]})]})]}),l&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 text-sm text-fail [overflow-wrap:anywhere]`,children:l}),(0,Q.jsx)(`a`,{href:I(`agents`,`custom`,t),className:`self-start text-[13px]`,children:`Open its page`})]})}function Pn({id:e}){let[t,n]=(0,Z.useState)(null),[r,i]=(0,Z.useState)(``),[a,o]=(0,Z.useState)(!1),s=(0,Z.useCallback)(()=>{H.view(e).then(e=>{We([{id:e.id,icon:e.icon}]),n(e),i(``)},e=>i(e.message))},[e]);(0,Z.useEffect)(()=>s(),[s]);let[c,l]=(0,Z.useState)(null);return Ke.test(e)?(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[t?(0,Q.jsx)(Ln,{view:t,detailsOpen:a,onDetails:o}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-1 px-5 py-3.5 short:py-2`,children:[(0,Q.jsx)(nt,{}),(0,Q.jsxs)(`a`,{href:I(`agents`,`category`,`custom`),className:`inline-flex min-h-9 items-center gap-1.5 text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),`Custom agents`]})]}),(0,Q.jsx)(`main`,{className:`flex flex-auto flex-col items-center justify-center px-5 py-10`,children:r?(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:r}):(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`})})]}),t&&c&&(0,Q.jsx)(Zn,{view:t,action:c.action,to:c.to,onClose:()=>l(null),onDone:e=>{`deleted`in e?(l(null),location.hash=I(`agents`,`category`,`custom`)):(n(e),l(null))}}),t&&(0,Q.jsx)(Un,{view:t,open:a,onClose:()=>o(!1),onAct:l})]}):(0,Q.jsx)(Fn,{})}function Fn(){return(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsx)(`header`,{className:`flex items-center gap-1 px-5 py-3.5`,children:(0,Q.jsx)(nt,{})}),(0,Q.jsxs)(`p`,{className:`m-0 px-6 py-10 text-sm text-muted`,children:[`There is no such agent. `,(0,Q.jsx)(`a`,{href:I(`agents`),children:`See every agent`}),`.`]})]})}var In=e=>e.length?e.join(`, `):`none`;function Ln({view:e,detailsOpen:t,onDetails:n}){let r=wt(),i=[...e.problems.working,...e.problems.active,...e.problems.other],o=e.state===`active`||e.state===`changed`,c=!!e.working,l=en[e.state],[u,d]=(0,Z.useState)(e.starters[0]?.text||``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1),v=Mt(),{setup:y}=v,b=`custom-agent-${e.id}`,x=yt(u,e=>{d(e),p(``)},b,{code:v.tools.code}),S=St(`custom-${e.id}`,e=>{d(e),xt(b)}),C=async()=>{h(``);try{let t=await H.pack(e.id),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${e.id}.forgeqe-agent.zip`,r.click(),setTimeout(()=>URL.revokeObjectURL(n),1e3),h(`Zip downloaded. A teammate imports it as a draft, then edits and approves it.`)}catch(e){h(e.message)}},T=async(t,n=u)=>{if(!(g||!n.trim()&&!x.hasFiles)&&(t||o)&&(!t||c)){_(!0),p(``);try{let r=await x.wrap(n.trim());if(!r.trim()){_(!1);return}let{id:i}=await Pe.start(r,{...v.choice,agent:e.id,...t||!o?{try:!0}:{}});x.reset({keep:!0}),location.hash=I(`chats`,i)}catch(e){p(e.message),_(!1)}}},E=!o&&!c;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-1 px-5 py-3.5 short:py-2`,children:[(0,Q.jsx)(nt,{}),(0,Q.jsxs)(`a`,{href:I(`agents`,`category`,`custom`),className:`inline-flex min-h-9 items-center gap-1.5 text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),`Custom agents`]}),(0,Q.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[(0,Q.jsx)(F,{tone:l.tone,children:l.label}),(0,Q.jsx)(j,{variant:`icon`,size:`icon`,onClick:()=>void C(),"aria-label":`Export to share`,"data-tip":`Export to share`,children:(0,Q.jsx)(fe,{size:18,"aria-hidden":`true`})}),(0,Q.jsx)(j,{variant:`icon`,size:`icon`,onClick:()=>n(!t),"aria-label":`Details`,"aria-pressed":t,"data-tip":`Details`,children:(0,Q.jsx)(a,{size:18,"aria-hidden":`true`})}),(0,Q.jsx)(`a`,{href:I(`agents`,`custom`,e.id,`edit`),className:A(U({variant:`icon`,size:`icon`}),`no-underline`),"aria-label":`Edit`,"data-tip":`Edit`,children:(0,Q.jsx)(w,{size:18,"aria-hidden":`true`})})]})]}),(0,Q.jsx)(`main`,{className:`flex flex-auto flex-col items-center justify-center px-5 pt-6 pb-[120px] short:pt-0 short:pb-8`,children:(0,Q.jsxs)(`div`,{className:`flex w-full max-w-[780px] flex-col items-center gap-9 short:gap-6`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3.5 text-center short:gap-2.5`,children:[(0,Q.jsx)(He,{agent:e.id,icon:e.icon,px:r?64:96,decorative:!0,working:g,className:`mb-1`}),(0,Q.jsx)(`h1`,{className:`m-0 text-[34px] leading-tight font-semibold tracking-[-0.015em] text-ink short:text-[28px] [overflow-wrap:anywhere]`,children:e.name}),(0,Q.jsx)(`p`,{className:`m-0 max-w-[52ch] text-[15px] leading-relaxed text-ink-2 short:max-w-[72ch]`,children:e.description||(o?`Ask ${W(e.name)}. It runs version ${e.approvedVersion}, within its limits.`:c?`Try ${W(e.name)}. It has no approved version yet: a try runs its manifest as it is.`:`Fix ${W(e.name)}'s manifest before it can be tried or approved.`)})]}),m&&(0,Q.jsx)(`p`,{role:`status`,className:A(`m-0 -mt-4 text-center text-[13px]`,/downloaded|Zip/.test(m)?`text-muted`:`text-fail`),children:m}),i.length>0&&(0,Q.jsxs)(`div`,{role:`alert`,className:`flex w-full flex-col gap-1 rounded-[12px] bg-fail-soft px-4 py-3 text-left text-sm text-fail`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.state===`invalid`?`Its manifest needs fixing before it can be tried or approved:`:`It cannot run as it is:`}),(0,Q.jsx)(`ul`,{className:`m-0 list-disc pl-5 [overflow-wrap:anywhere]`,children:i.map((e,t)=>(0,Q.jsx)(`li`,{children:e},t))})]}),(0,Q.jsx)(zn,{agent:e.id}),e.state===`changed`&&e.changes.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`ca-changes`,className:`flex w-full flex-col gap-2 text-left`,children:[(0,Q.jsxs)(`h2`,{id:`ca-changes`,className:`m-0 text-[13px] font-semibold text-muted`,children:[`Changed since `,e.approvedVersion,` was approved`]}),(0,Q.jsx)(`p`,{className:`m-0 text-[13px] text-muted`,children:`The approved version keeps running until this change is approved.`}),(0,Q.jsx)(Pt,{diff:e.changes})]}),E?(0,Q.jsx)(`p`,{className:`m-0 max-w-[54ch] text-center text-sm text-muted`,children:`Open Details for what is wrong, or Edit the agent.`}):(0,Q.jsxs)(Q.Fragment,{children:[y&&!y.ready&&(0,Q.jsx)(_t,{project:y.project}),y?.ready&&(0,Q.jsx)(Ct,{c:v}),(0,Q.jsx)(vt,{id:b,label:`Message ${W(e.name)}`,value:u,onChange:e=>{d(e),p(``)},onSend:()=>void T(!o),disabled:g||!!y&&!y.ready||S.running,canSend:!!u.trim()||x.hasFiles,onEdit:x.onEdit,onKey:x.onKeyDown,onFiles:x.onFiles,dropping:x.dropping,drop:x.drop,mentions:x.mentions,combo:x.combo,placeholder:`Ask ${W(e.name)} to…`,top:(0,Q.jsxs)(Q.Fragment,{children:[x.chips,S.state&&(0,Q.jsx)(bt,{state:S.state,onStop:()=>void S.stop(),onUndo:S.undo,onClose:S.close})]}),left:(0,Q.jsxs)(Q.Fragment,{children:[x.paperclip,(0,Q.jsx)(jt,{c:v}),(0,Q.jsx)(Et,{running:S.running,disabled:!u.trim()||g||!!y&&!y.ready,onClick:()=>void S.start(u)})]}),right:(0,Q.jsx)(Nt,{c:v})}),(0,Q.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:A(`-mt-5 m-0 text-center text-sm text-ink-2 short:-mt-3`,!(f||x.error)&&`sr-only`),children:(0,Q.jsx)(`span`,{className:x.error&&!f?`text-fail`:``,children:f||x.error||``})}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-3`,children:[e.starters.map(e=>(0,Q.jsx)(j,{onClick:()=>{d(e.text),p(``),document.getElementById(b)?.focus()},children:e.label},e.label)),o&&c&&(0,Q.jsxs)(j,{disabled:g||!u.trim(),onClick:()=>void T(!0),"data-tip":`Try the manifest`,children:[(0,Q.jsx)(s,{"aria-hidden":`true`}),`Try`]})]})]}),(0,Q.jsx)(Rn,{view:e})]})})]})}function Rn({view:e}){let t=e.capabilities;if(!t.length)return null;let n=t.some(e=>e.state===`needs_setup`)?`needs_setup`:t.some(e=>e.state===`partial`)?`partial`:`ready`,r=n===`ready`?`pass`:n===`partial`?`warn`:`neutral`,i=n===`ready`?`Ready`:n===`partial`?`Partly set up`:`Needs setup`,a=t.filter(e=>e.state!==`ready`);return(0,Q.jsxs)(`div`,{className:`flex w-full flex-col gap-6 pt-2 text-left`,children:[a.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`ca-needs`,className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h2`,{id:`ca-needs`,className:`m-0 text-[13px] font-semibold text-muted`,children:`What it needs`}),(0,Q.jsx)(F,{tone:r,children:i})]}),(0,Q.jsx)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:n===`needs_setup`?`${W(e.name,!0)} cannot work until these are set up.`:`${W(e.name,!0)} works, without the parts below.`}),(0,Q.jsx)(`ul`,{"aria-label":`What ${W(e.name)} needs`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-0`,children:a.map((e,t)=>(0,Q.jsxs)(`li`,{className:A(`flex items-center gap-3 px-3 py-2.5`,t>0&&`border-t border-line-soft`),children:[(0,Q.jsx)(L,{icon:Hn[e.state].icon,size:16,className:A(`flex-none`,Hn[e.state].cls)}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium`,children:e.title}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:e.gaps.join(`; `)||Hn[e.state].label})]})]},e.id))})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`ca-caps`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`ca-caps`,className:`m-0 text-[13px] font-semibold text-muted`,children:`What it can use`}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-0`,children:t.map((e,t)=>{let n=Hn[e.state];return(0,Q.jsxs)(`li`,{className:A(`flex items-start gap-3 px-3 py-2.5`,t>0&&`border-t border-line-soft`),children:[(0,Q.jsx)(L,{icon:n.icon,size:16,className:A(`mt-0.5 flex-none`,n.cls)}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium`,children:e.title}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[n.label,e.gaps.length?`: ${e.gaps.join(`; `)}`:``]})]})]},e.id)})})]})]})}function zn({agent:e}){let[t,n]=(0,Z.useState)([]),[r,a]=(0,Z.useState)(``),[o,s]=(0,Z.useState)(``),c=(0,Z.useCallback)(()=>{je.list().then(t=>n(t.approvals.filter(t=>t.agent===e&&t.state===`waiting`)),()=>{})},[e]);if((0,Z.useEffect)(()=>{c();let e=setInterval(c,15e3);return()=>clearInterval(e)},[c]),!t.length)return null;let l=async(t,n)=>{a(t.id),s(``);try{await je.answer(e,t.id,n),c()}catch(e){s(e.message)}finally{a(``)}};return(0,Q.jsxs)(`section`,{"aria-labelledby":`ca-waiting`,className:`flex w-full flex-col gap-2 rounded-[14px] border border-warn bg-warn-soft p-4 text-left`,children:[(0,Q.jsx)(`h2`,{id:`ca-waiting`,className:`m-0 text-base font-semibold text-warn`,children:`Waiting for you`}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-3 p-0`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-wrap items-start gap-3 rounded-[12px] bg-bg px-4 py-3`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-[1_1_320px] flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium [overflow-wrap:anywhere]`,children:e.title}),e.detail&&(0,Q.jsx)(`span`,{className:`text-[13px] text-ink-2 [overflow-wrap:anywhere]`,children:e.detail}),(e.lines||[]).map((e,t)=>(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:e},t)),(0,Q.jsxs)(`span`,{className:`text-[12px] text-muted`,children:[`Asked `,Ot(e.createdAt),`; no answer by `,e.until.slice(0,16).replace(`T`,` `),` UTC is a no.`]})]}),(0,Q.jsxs)(`span`,{className:`flex gap-2`,children:[(0,Q.jsxs)(j,{size:`sm`,variant:`primary`,disabled:!!r,onClick:()=>void l(e,`allow`),children:[(0,Q.jsx)(i,{"aria-hidden":`true`}),`Allow`]}),e.forRun&&(0,Q.jsxs)(j,{size:`sm`,variant:`outline`,disabled:!!r,onClick:()=>void l(e,`allow_run`),"data-tip":`Allow for the rest of this run`,children:[(0,Q.jsx)(i,{"aria-hidden":`true`}),`Allow run`]}),(0,Q.jsxs)(j,{size:`sm`,variant:`ghost`,disabled:!!r,onClick:()=>void l(e,`deny`),children:[(0,Q.jsx)(u,{"aria-hidden":`true`}),`Deny`]})]})]},e.id))}),o&&(0,Q.jsx)(`p`,{className:`m-0 text-[13px] text-fail`,children:o})]})}var Bn={approved:`Approved`,disabled:`Disabled`,enabled:`Enabled`,"rolled-back":`Rolled back to`};function Vn(e){let t=/\s*\(web\)$/i.test(e),n=e.replace(/\s*\(web\)$/i,``).trim(),r=/^(?:\d+\+)?([^@\s]+)@users\.noreply\.github\.com$/i.exec(n);return r?n=r[1]:n.includes(`@`)&&n.length>24&&(n=n.slice(0,n.indexOf(`@`))),t?`${n} · web`:n}var Hn={ready:{icon:k,label:`Ready`,cls:`text-pass`},partial:{icon:m,label:`Partly set up`,cls:`text-warn`},needs_setup:{icon:u,label:`Needs setup`,cls:`text-muted`}};function Un({view:e,open:t,onClose:n,onAct:i}){let a=e.active||e.working,o=!!e.working&&(e.state===`draft`||e.state===`changed`||e.state===`broken`&&e.working!==void 0);return(0,Q.jsx)(K,{open:t,onClose:n,wide:!0,title:`Details`,description:`${e.name} · ${e.id}`,footer:(0,Q.jsxs)(j,{variant:`ghost`,onClick:n,children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Close`]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[a&&(0,Q.jsx)(Gn,{spec:a,view:e}),(0,Q.jsx)(Kn,{view:e,approvable:o,onAct:i}),(0,Q.jsx)(Yn,{view:e})]})})}function Wn({id:e,title:t,children:n,aside:r}){return(0,Q.jsxs)(`section`,{"aria-labelledby":e,className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`h2`,{id:e,className:`m-0 flex-1 text-[13px] font-semibold text-muted`,children:t}),r]}),n]})}function Gn({spec:e,view:t}){let n=(t.active?t.describe?.active:t.describe?.working)||[],r=[...n.length?n.map(n=>[n.label,n.label===`Agents it may start`?In(e.agents.map(e=>t.agentNames[e]||e)):n.text]):[[`Environments`,In(e.environments)],[`Agents it may start`,In(e.agents.map(e=>t.agentNames[e]||e))],[`It may`,In(e.actions.map(e=>qn[e]||e))],[`A person approves first`,In(e.approve.map(e=>qn[e]||e))],[`Repository`,e.repository===`write`?`may change files`:`read only`]],...n.some(e=>e.label===`Runs by itself`)?[]:[[`Runs by itself`,e.schedule?`${e.schedule.every?`every ${e.schedule.every}`:`at ${e.schedule.cron}`}: “${e.schedule.request}”`:`no: you, your team or the Orchestrator start it`]],[`Skills`,In(e.skills)],[`Knowledge`,In(e.knowledge)]];return(0,Q.jsxs)(Wn,{id:`ca-reach`,title:t.active?`What version ${t.approvedVersion} may reach`:`What its manifest may reach`,children:[(0,Q.jsx)(`dl`,{className:`m-0 grid grid-cols-1 gap-x-6 gap-y-2 rounded-[12px] card border px-4 py-3 text-sm sm:grid-cols-[160px_1fr]`,children:r.map(([e,t])=>(0,Q.jsxs)(`div`,{className:`contents`,children:[(0,Q.jsx)(`dt`,{className:`text-muted`,children:e}),(0,Q.jsx)(`dd`,{className:`m-0 text-ink [overflow-wrap:anywhere]`,children:t})]},e))}),e.policies.length>0&&(0,Q.jsxs)(`p`,{className:`m-0 text-[13px] text-muted`,children:[`Guidance it is given (not a limit): `,e.policies.join(`; `)]})]})}function Kn({view:e,approvable:t,onAct:n}){return(0,Q.jsxs)(Wn,{id:`ca-versions`,title:`Versions`,aside:(0,Q.jsxs)(`span`,{className:`flex flex-wrap gap-2`,children:[t&&(0,Q.jsxs)(j,{size:`sm`,onClick:()=>n({action:`approve`}),"data-tip":`Approve ${e.manifestVersion}`,children:[(0,Q.jsx)(k,{"aria-hidden":`true`}),`Approve`]}),e.approvedVersion&&(0,Q.jsxs)(j,{size:`sm`,variant:`ghost`,onClick:()=>n({action:e.disabled?`enable`:`disable`}),children:[e.disabled?(0,Q.jsx)(k,{"aria-hidden":`true`}):(0,Q.jsx)(u,{"aria-hidden":`true`}),e.disabled?`Enable`:`Disable`]}),(0,Q.jsxs)(j,{size:`sm`,variant:`danger`,onClick:()=>n({action:`delete`}),children:[(0,Q.jsx)(ue,{"aria-hidden":`true`}),`Delete`]})]}),children:[e.tried&&e.manifestVersion&&(0,Q.jsxs)(`p`,{className:`m-0 text-[13px] text-muted`,children:[`Last try of manifest `,e.manifestVersion,`: `,e.tried.outcome,`.`]}),e.events.length===0?(0,Q.jsx)(z,{className:`py-4`,children:`No version has been approved yet. Try it, then approve it: only an approved version runs, for you, your team and the Orchestrator.`}):(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:[...e.events].reverse().map((t,r)=>{let i=t.event===`approved`||t.event===`rolled-back`?t.version===e.approvedVersion:!1,a=t.event===`approved`&&t.version!==e.approvedVersion&&!e.events.slice(e.events.indexOf(t)+1).some(e=>e.event===`approved`&&e.version===t.version);return(0,Q.jsxs)(`li`,{className:`flex min-h-11 flex-wrap items-center gap-3 rounded-[8px] px-3 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-[14px] font-medium`,children:[(0,Q.jsxs)(`span`,{children:[Bn[t.event],` `,t.version]}),i&&r===0?(0,Q.jsx)(F,{tone:`pass`,children:`Running`}):null]}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:[Vn(t.by),` · `,Ot(t.at),t.note?` · ${t.note}`:``,t.tried?` · tried: ${t.tried.outcome}`:``]})]}),a&&(0,Q.jsx)(j,{size:`sm`,variant:`ghost`,onClick:()=>n({action:`rollback`,to:t.version}),"aria-label":`Roll back to ${t.version}`,"data-tip":`Roll back to ${t.version}`,children:(0,Q.jsx)(c,{"aria-hidden":`true`})})]},`${t.at}-${r}`)})})]})}var qn={read:`read`,run:`run tests and apps`,change:`change files`,external:`change other systems`,schedule:`schedule work`},Jn={run:`Asked`,try:`Tried`,orchestrator:`From the Orchestrator`};function Yn({view:e}){let[t,n]=(0,Z.useState)(``),r=async()=>{n(``);try{let t=await H.audit(e.id),n=URL.createObjectURL(new Blob([t],{type:`application/x-ndjson;charset=utf-8`})),r=document.createElement(`a`);r.href=n,r.download=`${e.id}-audit.jsonl`,r.click(),setTimeout(()=>URL.revokeObjectURL(n),1e3)}catch(e){n(e.message)}};return(0,Q.jsxs)(Wn,{id:`ca-runs`,title:`Recent runs`,aside:(0,Q.jsxs)(j,{size:`sm`,variant:`ghost`,onClick:()=>void r(),"data-tip":`Download its whole record, for audit`,children:[(0,Q.jsx)(fe,{"aria-hidden":`true`}),`Download`]}),children:[t&&(0,Q.jsx)(`p`,{className:`m-0 text-[13px] text-fail`,children:t}),e.runs.length===0?(0,Q.jsxs)(z,{className:`py-4`,children:[W(e.name,!0),` has not run yet.`]}):(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-0`,children:e.runs.map((e,t)=>(0,Q.jsx)(`li`,{className:A(t>0&&`border-t border-line-soft`),children:(0,Q.jsxs)(`details`,{className:`group px-3 py-2.5`,children:[(0,Q.jsxs)(`summary`,{className:`flex cursor-pointer list-none flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,Q.jsx)(F,{tone:e.outcome===`done`?`pass`:e.outcome===`running`?`running`:e.outcome===`stopped`||e.outcome===`needs_input`?`neutral`:`fail`,children:e.outcome.replace(`_`,` `)}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[14px] font-medium`,"data-tip":e.request,children:e.request}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted tabular-nums`,children:[Jn[e.trigger],` · `,e.version,` · `,e.calls,` `,e.calls===1?`call`:`calls`,e.refused?`, ${e.refused} refused`:``,` · `,Ot(e.startedAt)]})]}),(0,Q.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2 pl-1 text-[13px]`,children:[(0,Q.jsxs)(`span`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,Q.jsxs)(`span`,{className:`text-muted`,children:[`By `,e.by]}),e.session&&(0,Q.jsxs)(`a`,{href:I(`runs`,encodeURIComponent(e.session)),className:`inline-flex items-center gap-1`,children:[`Open the run`,(0,Q.jsx)(se,{size:14,"aria-hidden":`true`})]})]}),e.error&&(0,Q.jsx)(`span`,{className:`text-fail [overflow-wrap:anywhere]`,children:e.error}),e.decisions.length>0&&(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:e.decisions.map((e,t)=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-2`,children:[e.allowed?(0,Q.jsx)(k,{size:14,"aria-label":`Allowed`,className:`mt-0.5 flex-none text-pass`}):(0,Q.jsx)(te,{size:14,"aria-label":`Refused`,className:`mt-0.5 flex-none text-fail`}),(0,Q.jsxs)(`span`,{className:`min-w-0 [overflow-wrap:anywhere]`,children:[(0,Q.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.tool}),e.allowed?(0,Q.jsxs)(`span`,{className:`text-muted`,children:[` · `,qn[e.action||``]||e.action,e.approved?`, approved by a person`:``]}):(0,Q.jsxs)(`span`,{className:`text-fail`,children:[` · `,e.reason]})]})]},t))})]})]})},e.run))})]})}var Xn={approve:{title:`Approve this version`,button:`Approve`,icon:k},disable:{title:`Disable this agent`,button:`Disable`,icon:u},enable:{title:`Enable this agent`,button:`Enable`,icon:k},rollback:{title:`Run an earlier version`,button:`Roll back`,icon:c},delete:{title:`Delete this agent`,button:`Delete`,icon:ue}};function Zn({view:e,action:t,to:n,onClose:i,onDone:a}){let[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(``),m=Xn[t],h=t===`approve`?`Version ${e.manifestVersion} becomes what runs, for you, your team and the Orchestrator${e.approvedVersion?`, in place of ${e.approvedVersion}`:``}.${e.tried?` Its last try: ${e.tried.outcome}.`:` It was never tried.`} Commit .forgeqe/agents/.releases/${e.id} so your team has it.`:t===`disable`?`Nothing of it runs (not you, your team, the Orchestrator or its schedule) until a person enables it again, here or with forgeqe agent enable.`:t===`enable`?`Version ${e.approvedVersion} runs again.`:t===`delete`?`${e.name} will be removed for good: its manifest, approved versions, runs and waiting approvals. Knowledge files and skills it named stay in the project.`:`Version ${n} runs from now on, in place of ${e.approvedVersion}.`,g=async()=>{d(!0),p(``);try{a(await H.act(e.id,t,{confirm:o,...c.trim()?{note:c.trim()}:{},...n?{to:n}:{}}))}catch(e){p(e.message),d(!1)}};return(0,Q.jsx)(K,{open:!0,onClose:i,title:m.title,description:h,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{variant:`ghost`,onClick:i,children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:t===`delete`?`destructive`:`primary`,disabled:u||o!==e.id,onClick:()=>void g(),children:[(0,Q.jsx)(m.icon,{"aria-hidden":`true`}),m.button]})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsxs)(`span`,{children:[`Type `,(0,Q.jsx)(`span`,{className:`font-mono`,children:e.id}),` to confirm`]}),(0,Q.jsx)(N,{value:o,onChange:e=>s(e.target.value),autoComplete:`off`,spellCheck:!1})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{children:`Note (optional)`}),(0,Q.jsx)(N,{value:c,maxLength:200,onChange:e=>l(e.target.value),placeholder:t===`rollback`?`Why it goes back`:`What changed, or why`})]}),f&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 text-sm text-fail [overflow-wrap:anywhere]`,children:f})]})})}var Qn={id:``,name:``,version:`1.0.0`,icon:ft,description:``,instructions:``,scope:{agents:[],capabilities:[],skills:[],knowledge:[],environments:[]},permissions:{repository:`read`,actions:[`read`],approve:[]},runtime:{maxDelegationDepth:1},policies:[],starters:[]};function $n(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^[^a-z]+/,``).replace(/-+$/,``).slice(0,40).replace(/-+$/,``)}var er={read:{label:`Read`,help:`Test cases, runs, reports, the repository, systems' data. Changes nothing.`},run:{label:`Run`,help:`Browser runs, tests, API calls and database queries, in its environments only.`},change:{label:`Change files`,help:`Test assets on this computer: packs, contracts, page memory, recordings.`},external:{label:`Change other systems`,help:`Work items, pull requests, pipelines, channels.`}},tr={ready:{icon:k,label:`Ready`,cls:`text-pass`},partial:{icon:m,label:`Partly set up`,cls:`text-warn`},needs_setup:{icon:u,label:`Needs setup`,cls:`text-muted`}},nr=(e,t,n)=>n?[...new Set([...e,t])]:e.filter(e=>e!==t);function rr({checked:e,onChange:t,disabled:n,children:r,help:i}){return(0,Q.jsxs)(`label`,{className:A(`flex items-start gap-2.5 text-sm`,n?`cursor-not-allowed opacity-60`:`cursor-pointer`),children:[(0,Q.jsx)(kt,{checked:e,disabled:n,onCheckedChange:t,className:`mt-0.5`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-ink`,children:r}),i&&(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:i})]})]})}function ir({id:e,template:t}){let r=!e,[a,s]=(0,Z.useState)(r&&!t?Qn:null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)([]),[g,_]=(0,Z.useState)([]),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{H.choices().then(d,e=>p(e.message)),t&&H.template(t).then(e=>{l(e),s({...Qn,...e.fields,scope:{...Qn.scope,...e.fields.scope},permissions:{...Qn.permissions,...e.fields.permissions}}),C(!0)},e=>p(e.message)),e&&H.view(e).then(t=>t.form?s({...Qn,...t.form,runtime:{maxDelegationDepth:t.form.runtime.maxDelegationDepth,...t.form.runtime.maxTokens?{maxTokens:t.form.runtime.maxTokens}:{}}}):p(`${e}'s manifest is not one the editor can read. Fix it in .forgeqe/agents/${e}.yaml.`),e=>p(e.message))},[e,t]);let w=(0,Z.useRef)(0);(0,Z.useEffect)(()=>{if(!a)return;let e=++w.current;y(!0);let t=setTimeout(()=>{H.validate(a).then(t=>e===w.current&&(h(t.problems||[]),_(t.advice||[]),y(!1)),t=>e===w.current&&(h([t.message]),y(!1)))},350);return()=>clearTimeout(t)},[a]);let T=e=>s(t=>t&&{...t,...e}),E=e=>s(t=>t&&{...t,scope:{...t.scope,...e}}),D=e=>s(t=>t&&{...t,permissions:{...t.permissions,...e}}),ee=(0,Z.useMemo)(()=>{let e=new Map;for(let t of u?.capabilities||[])e.set(t.area,[...e.get(t.area)||[],t]);return[...e]},[u]),te=async()=>{if(a){x(!0),p(``);try{let t=await H.save(a,r?{create:!0}:{id:e});location.hash=I(`agents`,`custom`,t.id)}catch(e){p(e.message),x(!1)}}},ne=e?I(`agents`,`custom`,e):I(`agents`,`custom`,`new`);return(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsx)(ct,{}),(0,Q.jsxs)(`main`,{className:A(dt,`settings-fields flex-auto gap-2`),children:[(0,Q.jsxs)(`a`,{href:ne,className:`mb-2 inline-flex items-center gap-1.5 self-start text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),e?`Back to the agent`:`Back to the builder`]}),(0,Q.jsx)(`h1`,{className:`m-0 text-[26px] font-semibold tracking-[-0.01em]`,children:r?`New custom agent`:`Edit ${a?.name||e}`}),(0,Q.jsx)(`p`,{className:`m-0 mb-2 max-w-[70ch] text-sm leading-relaxed text-ink-2`,children:r?c?`ForgeQE's ${c.title} template, filled from this project. Read every setting and change what does not fit: it is saved as a draft, and runs once a person has tried and approved it.`:`An agent for one job your team repeats. It uses ForgeQE's own agents, tools, skills and knowledge, and is held to the environments and actions you pick here, on every call. It runs once a person has tried and approved it.`:`Saving changes its manifest only. The approved version keeps running until this change is approved on its page.`}),f&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:f}),c&&u&&(0,Q.jsxs)(`section`,{"aria-labelledby":`ca-template`,className:`mb-2 flex flex-col gap-2`,children:[(0,Q.jsxs)(`h2`,{id:`ca-template`,className:`m-0 text-base font-semibold`,children:[`From the `,c.title,` template`]}),(0,Q.jsxs)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:[c.systems.length>0&&(0,Q.jsxs)(`li`,{className:`flex flex-col gap-0.5 rounded-[12px] bg-surface-muted px-4 py-3 text-sm`,children:[(0,Q.jsxs)(`span`,{className:`font-medium text-ink`,children:[`It uses the tools of `,c.systems.map(e=>u?.systems.find(t=>t.name===e)?.label||e).join(`, `)]}),(0,Q.jsx)(`span`,{className:`text-[13px] text-ink-2`,children:`Through ForgeQE, which checks every call against what this agent may do. The editor has no field for them yet: they are kept as the template set them.`})]}),c.notes.map(e=>(0,Q.jsx)(`li`,{className:`flex flex-col gap-0.5 rounded-[12px] bg-surface-muted px-4 py-3 text-sm`,children:(0,Q.jsx)(`span`,{className:`font-medium text-ink`,children:e})},e))]})]}),r&&!t&&(0,Q.jsx)(`p`,{className:`m-0 mb-2 text-sm`,children:(0,Q.jsx)(`a`,{href:I(`agents`,`custom`,`new`),children:`Or say what it should do, and let ForgeQE build it with you`})}),!a||!u?!f&&(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ot,{first:!0,children:`What it is`}),(0,Q.jsx)(G,{label:`Name`,help:`What it does, then “agent”: Checkout guard agent.`,htmlFor:`ca-name`,children:(0,Q.jsx)(N,{id:`ca-name`,value:a.name,maxLength:60,onChange:e=>T({name:e.target.value,...r&&!S?{id:$n(e.target.value)}:{}})})}),(0,Q.jsx)(G,{label:`Id`,help:r?`Its file name and address: lower-case words and hyphens. It cannot change later.`:`It cannot change. Make a new agent for another id.`,htmlFor:`ca-id`,children:(0,Q.jsx)(N,{id:`ca-id`,value:a.id,maxLength:40,disabled:!r,spellCheck:!1,onChange:e=>(C(!0),T({id:e.target.value.toLowerCase()}))})}),(0,Q.jsx)(G,{label:`Version`,help:`Raise it for each change you approve: 1.0.0, then 1.1.0.`,htmlFor:`ca-version`,children:(0,Q.jsx)(N,{id:`ca-version`,value:a.version,maxLength:14,onChange:e=>T({version:e.target.value})})}),(0,Q.jsx)(G,{label:`Description`,help:`One line: what it is for. The Orchestrator reads it to know when to hand it work.`,htmlFor:`ca-desc`,stacked:!0,children:(0,Q.jsx)(N,{id:`ca-desc`,value:a.description,maxLength:300,onChange:e=>T({description:e.target.value})})}),(0,Q.jsx)(G,{label:`Icon`,help:`What it wears on the Agents page and its own page: one of ForgeQE's agent icons.`,htmlFor:`ca-icon`,stacked:!0,children:(0,Q.jsx)(_n,{id:`ca-icon`,value:a.icon,onChange:e=>T({icon:e})})}),(0,Q.jsx)(G,{label:`Instructions`,help:`Its focus and how to work, in plain words. Guidance for the model: the limits below are what holds it.`,htmlFor:`ca-instr`,stacked:!0,children:(0,Q.jsx)(V,{id:`ca-instr`,rows:5,value:a.instructions,maxLength:8e3,onChange:e=>T({instructions:e.target.value})})}),(0,Q.jsx)(ot,{help:`Where its runs, tests and calls may go. In an environment named like production, reads go ahead, runs are asked unless you say otherwise, and every change is approved by a person.`,children:`Where it works`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 py-3`,children:[u.environments.length===0&&(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`No environments in env.yaml yet. Add them in Settings, Environments.`}),u.environments.map(e=>(0,Q.jsx)(rr,{checked:a.scope.environments.includes(e.name),onChange:t=>E({environments:nr(a.scope.environments,e.name,t)}),help:e.production?`Production: reads go ahead; a person approves every change there.`:void 0,children:e.name},e.name))]}),(0,Q.jsx)(ot,{help:`ForgeQE's capabilities it may use: their tools, and only theirs. Each says whether it is set up here.`,children:`What it can do`}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-4 py-3`,children:ee.map(([e,t])=>{let n=t.filter(e=>a.scope.capabilities.includes(e.id)).length;return(0,Q.jsxs)(`details`,{open:n>0||void 0,className:`group rounded-[12px] card border px-3 py-2`,children:[(0,Q.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-1 text-[14px] font-medium`,children:[(0,Q.jsx)(o,{size:14,"aria-hidden":`true`,className:`flex-none text-muted transition-transform duration-200 group-open:rotate-90`}),(0,Q.jsx)(`span`,{className:`flex-1`,children:e}),(0,Q.jsx)(`span`,{className:`text-[12.5px] font-normal text-muted tabular-nums`,children:n?`${n} of ${t.length} picked`:`${t.length}`})]}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 pt-2 pb-1 pl-6`,children:t.map(e=>{let t=tr[e.state];return(0,Q.jsx)(rr,{checked:a.scope.capabilities.includes(e.id),onChange:t=>E({capabilities:nr(a.scope.capabilities,e.id,t)}),help:(0,Q.jsxs)(`span`,{className:`flex items-start gap-1.5`,children:[(0,Q.jsx)(L,{icon:t.icon,size:13,className:A(`mt-0.5 flex-none`,t.cls)}),(0,Q.jsxs)(`span`,{children:[t.label,e.gaps.length?`: ${e.gaps.join(`; `)}`:``]})]}),children:(0,Q.jsx)(`span`,{"data-tip":e.summary,children:e.title})},e.id)})})]},e)})}),(0,Q.jsx)(ot,{help:`ForgeQE's agents it may start: a capability that needs one (a browser run needs the Browser agent) is refused without it.`,children:`Agents it may use`}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 py-3`,children:u.agents.map(e=>(0,Q.jsx)(rr,{checked:a.scope.agents.includes(e.name),onChange:t=>E({agents:nr(a.scope.agents,e.name,t)}),help:(0,Q.jsx)(`span`,{className:`font-mono text-[11.5px]`,children:e.name}),children:e.title},e.name))}),(0,Q.jsx)(ot,{help:`Only these are loaded for it.`,children:`Skills and knowledge`}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 py-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-2 border-0 p-0`,children:[(0,Q.jsx)(`legend`,{className:`mb-1 p-0 text-[13px] font-semibold text-muted`,children:`Skills`}),u.skills.length===0&&(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`None in this project yet.`}),u.skills.map(e=>(0,Q.jsx)(rr,{checked:a.scope.skills.includes(e.name),onChange:t=>E({skills:nr(a.scope.skills,e.name,t)}),help:e.about,children:e.name},e.name))]}),(0,Q.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-2 border-0 p-0`,children:[(0,Q.jsx)(`legend`,{className:`mb-1 p-0 text-[13px] font-semibold text-muted`,children:`Knowledge files`}),u.knowledge.length===0&&(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`None in .forgeqe/knowledge yet.`}),u.knowledge.map(e=>(0,Q.jsx)(rr,{checked:a.scope.knowledge.includes(e.file),onChange:t=>E({knowledge:nr(a.scope.knowledge,e.file,t)}),help:e.title===e.file?void 0:e.title,children:e.file},e.file))]})]}),(0,Q.jsx)(ot,{help:`Enforced on every call. Ask first: a person approves each such call in the chat. In production, every call is asked.`,children:`What it may do`}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 py-3`,children:u.actions.map(e=>(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-6 gap-y-1`,children:[(0,Q.jsx)(`div`,{className:`min-w-0 flex-[1_1_320px]`,children:(0,Q.jsx)(rr,{checked:a.permissions.actions.includes(e),onChange:t=>D({actions:nr(a.permissions.actions,e,t)}),help:er[e]?.help,children:er[e]?.label||e})}),(0,Q.jsx)(rr,{checked:e===`external`?!(a.permissions.trust||[]).includes(`external`):a.permissions.approve.includes(e),disabled:!a.permissions.actions.includes(e),onChange:t=>D(e===`external`?{trust:nr(a.permissions.trust||[],`external`,!t)}:{approve:nr(a.permissions.approve,e,t)}),children:`Ask first`})]},e))}),(0,Q.jsx)(G,{label:`Repository`,help:`Whether it may change files in the repository (with Change files).`,children:(0,Q.jsx)(`div`,{role:`radiogroup`,"aria-label":`Repository`,className:`flex gap-1 rounded-[10px] bg-surface-strong p-1`,children:[[`read`,`Read only`],[`write`,`May change files`]].map(([e,t])=>(0,Q.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":a.permissions.repository===e,onClick:()=>D({repository:e}),className:A(`min-h-8 cursor-pointer rounded-[7px] border-0 px-3.5 text-sm font-medium`,a.permissions.repository===e?`bg-bg text-ink shadow-sm`:`bg-transparent text-muted hover:text-ink`),children:t},e))})}),a.scope.environments.some(e=>u.environments.some(t=>t.name===e&&t.production))&&a.permissions.actions.includes(`run`)&&(0,Q.jsx)(G,{label:`Production`,help:`Reads there go ahead without asking; every change there is approved by a person.`,children:(0,Q.jsx)(rr,{checked:!(a.permissions.production||[]).includes(`run`),onChange:e=>D({production:e?[]:[`run`]}),children:`Ask before each run`})}),a.permissions.repository===`write`&&(()=>{let e=(u.coding||[]).filter(e=>u.capabilities.some(t=>a.scope.capabilities.includes(t.id)&&t.tools.includes(e)));if(!e.length)return null;let t=e.every(e=>(a.permissions.trust||[]).includes(e));return(0,Q.jsx)(G,{label:`Coding agent`,help:`The tests it runs can reach any address. Without asking, ForgeQE first looks in the test project's config and env files, and asks when they name an address outside its environments.`,children:(0,Q.jsx)(rr,{checked:!t,onChange:t=>D({trust:t?(a.permissions.trust||[]).filter(t=>!e.includes(t)):[...new Set([...a.permissions.trust||[],...e])]}),children:`Ask first`})})})(),(0,Q.jsx)(G,{label:`Hands work on`,help:`How many levels deep it may give part of a task to a helper.`,htmlFor:`ca-depth`,children:(0,Q.jsxs)(B,{id:`ca-depth`,value:String(a.runtime.maxDelegationDepth),onChange:e=>T({runtime:{...a.runtime,maxDelegationDepth:Number(e.target.value)}}),className:`w-[200px]`,children:[(0,Q.jsx)(`option`,{value:`0`,children:`Never`}),(0,Q.jsx)(`option`,{value:`1`,children:`1 level`}),(0,Q.jsx)(`option`,{value:`2`,children:`2 levels`}),(0,Q.jsx)(`option`,{value:`3`,children:`3 levels`})]})}),(0,Q.jsx)(G,{label:`Budget per run`,help:`The most model tokens one run may use; it stops there. Empty: no limit.`,htmlFor:`ca-budget`,children:(0,Q.jsx)(N,{id:`ca-budget`,type:`number`,min:1e3,step:1e3,className:`w-[200px]`,value:a.runtime.maxTokens??``,placeholder:`No limit`,onChange:e=>T({runtime:{maxDelegationDepth:a.runtime.maxDelegationDepth,...e.target.value?{maxTokens:Math.max(0,Math.round(Number(e.target.value)))}:{}}})})}),(0,Q.jsx)(ot,{help:`One per line: what it should keep in mind. Guidance for the model, never a limit.`,children:`Guidance`}),(0,Q.jsx)(V,{"aria-label":`Guidance, one per line`,rows:3,value:a.policies.join(`
3
- `),onChange:e=>T({policies:e.target.value.split(`
4
- `).map(e=>e.slice(0,300))})}),(0,Q.jsx)(ot,{help:`Requests its page offers to start from (at most 6).`,children:`Starters`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 py-2`,children:[a.starters.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(N,{"aria-label":`Starter ${t+1} label`,className:`w-[200px]`,maxLength:40,value:e.label,placeholder:`Label`,onChange:e=>T({starters:a.starters.map((n,r)=>r===t?{...n,label:e.target.value}:n)})}),(0,Q.jsx)(N,{"aria-label":`Starter ${t+1} request`,className:`min-w-0 flex-[1_1_280px]`,maxLength:500,value:e.text,placeholder:`The request`,onChange:e=>T({starters:a.starters.map((n,r)=>r===t?{...n,text:e.target.value}:n)})}),(0,Q.jsx)(j,{variant:`icon`,size:`icon`,"aria-label":`Remove starter ${t+1}`,"data-tip":`Remove starter ${t+1}`,onClick:()=>T({starters:a.starters.filter((e,n)=>n!==t)}),children:(0,Q.jsx)(ue,{"aria-hidden":`true`})})]},t)),a.starters.length<6&&(0,Q.jsxs)(j,{size:`sm`,className:`self-start`,onClick:()=>T({starters:[...a.starters,{label:``,text:``}]}),"data-tip":`Add a starter`,children:[(0,Q.jsx)(n,{"aria-hidden":`true`}),`Add`]})]}),g.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`ca-advice`,className:`mt-6 flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`ca-advice`,className:`m-0 text-base font-semibold`,children:`What it still needs`}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-2 p-0`,children:g.map((e,t)=>(0,Q.jsxs)(`li`,{className:A(`flex flex-col gap-0.5 rounded-[12px] px-4 py-3 text-sm`,e.blocking?`bg-warn-soft`:`bg-surface-muted`),children:[(0,Q.jsx)(`span`,{className:A(`font-medium`,e.blocking?`text-warn`:`text-ink`),children:e.about}),(0,Q.jsx)(`span`,{className:`text-[13px] text-ink-2`,children:e.why}),(0,Q.jsx)(`span`,{className:`text-[13px] text-muted`,children:e.fix})]},t))})]}),(0,Q.jsxs)(`div`,{className:`sticky bottom-0 mt-4 flex flex-wrap items-center gap-3 border-t border-line-soft bg-bg py-3`,children:[(0,Q.jsx)(`div`,{role:`status`,className:`min-w-0 flex-[1_1_320px] text-[13px]`,children:v?(0,Q.jsx)(`span`,{className:`text-muted`,children:`Checking…`}):m.length?(0,Q.jsxs)(`ul`,{className:`m-0 list-disc pl-5 text-fail [overflow-wrap:anywhere]`,children:[m.slice(0,4).map((e,t)=>(0,Q.jsx)(`li`,{children:e},t)),m.length>4&&(0,Q.jsxs)(`li`,{children:[`and `,m.length-4,` more`]})]}):(0,Q.jsx)(`span`,{className:`text-pass`,children:`Ready to save. It can be tried once saved.`})}),(0,Q.jsx)(`a`,{href:ne,className:`text-sm`,children:`Cancel`}),(0,Q.jsxs)(j,{variant:`primary`,disabled:b||!a.id||!a.name,onClick:()=>void te(),"data-tip":r?`Save the agent`:`Save changes`,children:[(0,Q.jsx)(i,{"aria-hidden":`true`}),`Save`]})]})]})]})]})}var ar=232,or=34,sr=22,cr=96,lr=22,ur=20,dr=10;function fr(e){let t=new Set(e.fks.flatMap(e=>e.columns)),n=n=>e.pk.includes(n.name)?0:t.has(n.name)?1:2;return{cols:[...e.columns].sort((e,t)=>n(e)-n(t)).slice(0,dr),hidden:Math.max(0,e.columns.length-dr)+(e.more_columns||0)}}function pr(e){let t=new Set(e.map(e=>e.name)),n=new Map(e.map(e=>[e.name,0]));for(let r=0;r<e.length;r++){let r=!1;for(let i of e)for(let a of i.fks){if(!t.has(a.table)||a.table===i.name)continue;let o=(n.get(a.table)??0)+1;o>(n.get(i.name)??0)&&o<e.length&&(n.set(i.name,o),r=!0)}if(!r)break}return n}function mr(e){let t=pr(e),n=new Map;for(let r of e)n.set(t.get(r.name),[...n.get(t.get(r.name))||[],r]);let r=new Map,i=0;for(let[e,t]of[...n.entries()].sort((e,t)=>e[0]-t[0])){let n=ur;for(let i of t.sort((e,t)=>e.name.localeCompare(t.name))){let{cols:t,hidden:a}=fr(i),o=or+t.length*sr+(a?sr:0)+6;r.set(i.name,{t:i,x:ur+e*328,y:n,h:o,cols:t,hidden:a}),n+=o+lr}i=Math.max(i,n)}return{boxes:r,width:40+(Math.max(0,...n.keys())+1)*328-cr,height:i+ur-lr}}function hr(e,t){let n=t?e.cols.findIndex(e=>e.name===t):-1;return e.y+(n<0?or/2:or+n*sr+sr/2)}function gr({tables:e,selected:t,onSelect:n}){let{boxes:r,width:i,height:a}=(0,Z.useMemo)(()=>mr(e),[e]),o=(0,Z.useMemo)(()=>{if(!t)return null;let n=new Set([t]);for(let r of e)for(let e of r.fks)(r.name===t||e.table===t)&&(n.add(r.name),n.add(e.table));return n},[e,t]),s=e.flatMap(e=>e.fks.filter(e=>r.has(e.table)).map((n,i)=>{let a=r.get(e.name),o=r.get(n.table),s=hr(a,n.columns[0]),c=hr(o,n.references[0]),l=a===o,u=l||a.x>o.x?a.x:a.x+ar,d=l?o.x:a.x>o.x?o.x+ar:o.x,f=l?-40:Math.max(40,Math.abs(u-d)/2),p=l?`M ${u} ${s} C ${u+f} ${s}, ${d+f} ${c-12}, ${d} ${c-12}`:`M ${u} ${s} C ${u-Math.sign(u-d)*f} ${s}, ${d+Math.sign(u-d)*f} ${c}, ${d} ${c}`,m=!!t&&(e.name===t||n.table===t);return{key:`${e.name}.${i}`,d:p,on:m,label:`${e.name}.${n.columns.join(`, `)} references ${n.table}.${n.references.join(`, `)}`}}));return(0,Q.jsx)(`div`,{className:`overflow-auto rounded-[10px] border border-line-soft bg-surface-muted/40`,role:`group`,"aria-label":`Schema diagram: ${e.length} tables, ${s.length} relationships`,children:(0,Q.jsxs)(`div`,{className:`relative`,style:{width:i,height:a},children:[(0,Q.jsxs)(`svg`,{width:i,height:a,className:`absolute inset-0`,"aria-hidden":`true`,children:[(0,Q.jsx)(`defs`,{children:(0,Q.jsx)(`marker`,{id:`fk-end`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,Q.jsx)(`path`,{d:`M0 0 L8 4 L0 8 z`,fill:`currentColor`})})}),s.map(e=>(0,Q.jsx)(`path`,{d:e.d,fill:`none`,markerEnd:`url(#fk-end)`,strokeWidth:e.on?2:1.25,className:A(e.on?`text-accent`:t?`text-line`:`text-muted`),stroke:`currentColor`,"data-tip":e.label},e.key))]}),[...r.values()].map(e=>{let r=new Set(e.t.fks.flatMap(e=>e.columns)),i=t===e.t.name,a=!!o&&!o.has(e.t.name);return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":i,onClick:()=>n(e.t.name),"data-tip":e.t.comment||e.t.name,className:A(`absolute flex cursor-pointer flex-col overflow-hidden rounded-[10px] border bg-bg p-0 text-left shadow-sm transition-opacity`,i?`border-accent ring-2 ring-accent/30`:`border-line hover:border-accent`,a&&`opacity-35`),style:{left:e.x,top:e.y,width:ar,height:e.h},children:[(0,Q.jsxs)(`span`,{className:A(`flex h-[34px] w-full flex-none items-center gap-2 border-b border-line-soft px-3`,i?`bg-accent-soft`:`bg-surface-muted`),children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[12.5px] font-semibold text-ink`,children:e.t.name}),e.t.kind===`view`&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted`,children:`view`}),e.t.rows!==void 0&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted tabular-nums`,children:e.t.rows.toLocaleString()})]}),e.cols.map(t=>(0,Q.jsxs)(`span`,{className:`flex h-[22px] w-full flex-none items-center gap-1.5 px-3 text-[12px]`,children:[(0,Q.jsx)(`span`,{className:`flex w-3.5 flex-none justify-center text-muted`,children:e.t.pk.includes(t.name)?(0,Q.jsx)(T,{size:11,"aria-label":`key`,className:`text-warn`}):r.has(t.name)?(0,Q.jsx)(x,{size:11,"aria-label":`foreign key`,className:`text-accent-fg`}):null}),(0,Q.jsx)(`span`,{className:A(`min-w-0 flex-1 truncate font-mono`,e.t.pk.includes(t.name)?`font-semibold text-ink`:`text-ink-2`),children:t.name}),(0,Q.jsx)(`span`,{className:`max-w-[90px] flex-none truncate font-mono text-[11px] text-muted lowercase`,children:t.type})]},t.name)),e.hidden>0&&(0,Q.jsxs)(`span`,{className:`flex h-[22px] flex-none items-center px-3 pl-8 text-[11.5px] text-muted`,children:[`+`,e.hidden,` more`]})]},e.t.name)})]})})}var _r=[`databases`,`schema`,`ask`,`requests`,`about`],vr={test:`databases`,map:`schema`,ask:`ask`,checks:`ask`,request:`ask`,fetch:`requests`},yr=40;function br({view:e,job:t,busy:n,act:r,maps:i}){let a=t&&!t.running&&t.kind===`test`?t:null,o=a?a.lines.filter(e=>/^[✓✗]/.test(e.trim())).join(` `)||a.lines.filter(e=>!/^args |^token /.test(e)).slice(-1)[0]:``;return e.databases.length?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[a&&o&&(0,Q.jsx)(`p`,{className:A(`m-0 rounded-[12px] px-3 py-2 text-sm [overflow-wrap:anywhere]`,a.exitCode===0?`bg-pass-soft text-pass`:`bg-fail-soft text-fail`),children:o.replace(/^[✓✗]\s*/,``)}),(0,Q.jsx)(it,{label:`Connected databases`,minWidth:720,head:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`th`,{className:q,children:`Database`}),(0,Q.jsx)(`th`,{className:q,children:`Engine`}),(0,Q.jsx)(`th`,{className:q,children:`Where`}),(0,Q.jsx)(`th`,{className:q,children:`Access`}),(0,Q.jsx)(`th`,{className:at,children:`Tables`}),(0,Q.jsx)(`th`,{className:q,children:(0,Q.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]}),children:e.databases.map(e=>{let t=i[e.name]?.map;return(0,Q.jsxs)(`tr`,{className:ut,children:[(0,Q.jsx)(`td`,{className:J,children:(0,Q.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.name}),e.description&&(0,Q.jsx)(`span`,{className:`text-[12px] text-muted`,children:e.description})]})}),(0,Q.jsx)(`td`,{className:A(J,`whitespace-nowrap`),children:e.engine||`from its connection string`}),(0,Q.jsx)(`td`,{className:A(J,`max-w-[240px] truncate font-mono text-[12px]`),"data-tip":e.where,children:e.where}),(0,Q.jsx)(`td`,{className:A(J,`whitespace-nowrap`),children:(0,Q.jsx)(F,{tone:e.writable?`warn`:`neutral`,icon:e.writable,children:e.writable?`Writable, after asking`:`Read only`})}),(0,Q.jsx)(`td`,{className:et,children:t?t.total:(0,Q.jsx)(`span`,{className:`text-muted`,children:`—`})}),(0,Q.jsx)(`td`,{className:A(J,`whitespace-nowrap text-right`),children:(0,Q.jsxs)(`span`,{className:`inline-flex gap-1.5`,children:[(0,Q.jsx)(j,{size:`icon`,variant:`icon`,disabled:n,onClick:()=>r(`test`,{db:e.name}),"aria-label":`Test the connection to ${e.name}`,"data-tip":`Test the connection to ${e.name}`,className:`size-8`,children:(0,Q.jsx)(v,{"aria-hidden":`true`})}),(0,Q.jsx)(`a`,{href:I(`agents`,`db`,`schema`,encodeURIComponent(e.name)),"aria-label":`Schema of ${e.name}`,"data-tip":`Schema of ${e.name}`,className:A(U({variant:`icon`,size:`icon`}),`size-8 no-underline`),children:(0,Q.jsx)(ae,{"aria-hidden":`true`})}),(0,Q.jsx)(`a`,{href:I(`data`,`databases/${encodeURIComponent(e.name)}`),"aria-label":`Query ${e.name}`,"data-tip":`Query ${e.name}`,className:A(U({variant:`icon`,size:`icon`}),`size-8 no-underline`),children:(0,Q.jsx)(b,{"aria-hidden":`true`})})]})})]},e.name)})}),(0,Q.jsx)(`a`,{href:I(`settings`,`databases`),className:`self-start text-[13px]`,children:`Add or change databases in Settings`})]}):(0,Q.jsxs)(z,{className:`py-3`,children:[`The DB agent is not connected to a database yet. `,(0,Q.jsx)(`a`,{href:I(`settings`,`databases`),children:`Add one in Settings`}),`: a connection string, or its host, user and password, kept in your credential store.`]})}function xr({t:e,all:t,onSelect:n}){let r=new Map(e.fks.flatMap(e=>e.columns.map((t,n)=>[t,`${e.table}.${e.references[n]??e.references[0]??``}`]))),i=t.filter(t=>t.fks.some(t=>t.table===e.name));return(0,Q.jsxs)(`section`,{"aria-labelledby":`table-h`,className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,Q.jsxs)(`h3`,{id:`table-h`,className:`m-0 flex items-center gap-2 font-mono text-base font-semibold`,children:[(0,Q.jsx)(L,{icon:ce,size:18,className:`text-accent-fg`}),e.name]}),(0,Q.jsxs)(`span`,{className:`text-[13px] text-muted`,children:[e.kind===`view`?`view · `:``,M(e.columns.length+(e.more_columns||0),`column`),e.rows===void 0?``:` · about ${e.rows.toLocaleString()} rows`]})]}),e.comment&&(0,Q.jsx)(`p`,{className:`m-0 text-sm text-ink-2`,children:e.comment}),(0,Q.jsx)(it,{label:`Columns of ${e.name}`,resetKey:e.name,search:e.columns.length>12,head:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`th`,{className:q,children:`Column`}),(0,Q.jsx)(`th`,{className:q,children:`Type`}),(0,Q.jsx)(`th`,{className:q,children:`Null`}),(0,Q.jsx)(`th`,{className:q,children:`Key`})]}),children:e.columns.map(t=>(0,Q.jsxs)(`tr`,{className:ut,children:[(0,Q.jsx)(`td`,{className:A(J,`font-mono text-[12.5px]`,e.pk.includes(t.name)&&`font-semibold`),children:t.name}),(0,Q.jsx)(`td`,{className:A(J,`font-mono text-[12px] text-muted`),children:t.type}),(0,Q.jsx)(`td`,{className:A(J,`text-muted`),children:t.nullable?`Allowed`:`Not null`}),(0,Q.jsxs)(`td`,{className:J,children:[e.pk.includes(t.name)&&(0,Q.jsx)(`span`,{className:`mr-2`,children:`Primary key`}),r.has(t.name)&&(0,Q.jsxs)(`button`,{type:`button`,className:`cursor-pointer border-0 bg-transparent p-0 font-mono text-[12px] text-accent-fg underline-offset-2 hover:underline`,onClick:()=>n(r.get(t.name).split(`.`)[0]),children:[`→ `,r.get(t.name)]})]})]},t.name))}),i.length>0&&(0,Q.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-2 text-[13px] text-muted`,children:[`Pointed at by`,i.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>n(e.name),className:A(U({size:`sm`}),`font-mono text-[12px]`),children:e.name},e.name))]})]})}function Sr({view:e,job:t,busy:n,act:r,maps:i,dbName:a,setDb:o}){let[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(!1),p=i[a],m=p?.map?.tables??[],g=!!t?.running&&t.kind===`map`&&t.target===a,v=(0,Z.useRef)(new Set);(0,Z.useEffect)(()=>{!a||i[a]||n||v.current.has(a)||(v.current.add(a),r(`map`,{db:a}))},[a,n]),(0,Z.useEffect)(()=>c(``),[a]);let y=m.length>yr,b=s||y&&[...m].sort((e,t)=>Cr(m,t.name)-Cr(m,e.name))[0]?.name||``,x=(0,Z.useMemo)(()=>{if(!y||d)return m;let e=new Set([b]);for(let t of m)for(let n of t.fks)(t.name===b||n.table===b)&&(e.add(t.name),e.add(n.table));return m.filter(t=>e.has(t.name))},[m,y,d,b]),S=l.toLowerCase().split(/\s+/).filter(Boolean),w=S.length?m.filter(e=>S.every(t=>`${e.name} ${e.comment||``} ${e.columns.map(e=>e.name).join(` `)}`.toLowerCase().includes(t))):m,T=m.find(e=>e.name===s),E=m.reduce((e,t)=>e+t.fks.length,0);return e.databases.length?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(B,{"aria-label":`Database`,value:a,onChange:e=>o(e.target.value),className:`w-[220px]`,children:e.databases.map(e=>(0,Q.jsx)(`option`,{children:e.name},e.name))}),(0,Q.jsxs)(j,{disabled:n,onClick:()=>r(`map`,{db:a,refresh:!0}),"data-tip":`Read the schema again`,children:[(0,Q.jsx)(h,{"aria-hidden":`true`}),`Refresh`]}),p?.map&&(0,Q.jsxs)(`span`,{className:`text-sm text-muted tabular-nums`,children:[M(p.map.total,`table`),` · `,M(E,`relationship`),p.map.total>m.length?` · the first ${m.length} drawn`:``]})]}),g&&(0,Q.jsxs)(`p`,{className:`m-0 text-sm text-muted`,children:[`Reading the schema of `,a,`…`]}),p&&!p.ok&&(0,Q.jsx)(Y,{text:p.error||`Could not read the schema of ${a}.`}),p?.ok&&m.length===0&&(0,Q.jsxs)(z,{className:`py-3`,children:[a,` has no tables the DB agent can see.`]}),m.length>0&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start gap-x-6 gap-y-4`,children:[(0,Q.jsxs)(`nav`,{"aria-label":`Tables`,className:`flex min-w-0 flex-[1_1_220px] flex-col gap-2 @3xl:max-w-[240px]`,children:[(0,Q.jsx)(Oe,{id:`schema-find`,label:`Find a table`,value:l,onChange:u,className:`max-w-none flex-none`}),(0,Q.jsxs)(`ul`,{className:`m-0 flex max-h-[520px] list-none flex-col overflow-auto p-0`,children:[w.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":s===e.name,onClick:()=>c(s===e.name?``:e.name),className:A(`flex min-h-9 w-full cursor-pointer items-center gap-2 rounded-[8px] border-0 px-2.5 text-left text-[13px]`,s===e.name?`bg-surface-strong font-medium text-ink`:`bg-transparent text-ink-2 hover:bg-surface-muted`),children:[(0,Q.jsx)(L,{icon:ce,size:14,className:`flex-none text-muted`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono`,"data-tip":e.name,children:e.name}),(0,Q.jsx)(`span`,{className:`flex-none text-[11.5px] text-muted tabular-nums`,children:e.columns.length+(e.more_columns||0)})]})},e.name)),!w.length&&(0,Q.jsx)(`li`,{className:`px-2.5 py-2 text-[13px] text-muted`,children:`No table matches.`})]})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-[999_1_560px] flex-col gap-4`,children:[y&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-[13px] text-muted`,children:[(0,Q.jsxs)(`span`,{className:`flex-1`,children:[d?`All ${m.length} tables`:`${b} and the tables it joins (${x.length} of ${m.length})`,`. Pick a table to draw it with its neighbours.`]}),(0,Q.jsxs)(j,{size:`sm`,onClick:()=>f(!d),"data-tip":d?`Draw around one table`:`Draw every table`,children:[d?(0,Q.jsx)(_,{"aria-hidden":`true`}):(0,Q.jsx)(C,{"aria-hidden":`true`}),d?`Less`:`All (${m.length})`]})]}),(0,Q.jsx)(gr,{tables:x,selected:s||void 0,onSelect:e=>c(s===e?``:e)}),(0,Q.jsx)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:`Parents on the left; each line runs from a foreign key to the table it references. Pick a table to see its columns and what points at it.`}),T&&(0,Q.jsx)(xr,{t:T,all:m,onSelect:c})]})]})]}):(0,Q.jsx)(br,{view:e,job:t,busy:n,act:r,maps:i})}var Cr=(e,t)=>e.reduce((e,n)=>e+n.fks.filter(e=>e.table===t).length+(n.name===t?n.fks.length:0),0);function wr({page:e,tab:t,sub:n}){let{view:r,error:i,busy:a,act:o,stop:s,job:c}=zt(),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)({}),p=_r.includes(t)?t:`databases`,m=st(e.agent),h=n?Ee(n):``,[g,_]=(0,Z.useState)(h);(0,Z.useEffect)(()=>{h&&_(h)},[h]),(0,Z.useEffect)(()=>{!g&&r?.databases[0]&&_(r.databases[0].name)},[r,g]);let v=c&&!c.running?c.endedAt:``;(0,Z.useEffect)(()=>{c&&!c.running&&c.kind===`map`&&c.target&&f(e=>({...e,[c.target]:c.result??{ok:!1,error:c.lines.slice(-1)[0]}})),De.log().then(u,()=>u([]))},[v]);let y=(l||[]).filter(e=>!e.ok).length,x={databases:`Databases${r?` (${r.databases.length})`:``}`,schema:`Schema`,ask:`Ask`,requests:`Requests${l?` (${l.length})`:``}`,about:`Tools and runs`};return(0,Q.jsxs)(`section`,{"aria-label":`${W(m.name,!0)}'s screens`,className:`@container flex w-full flex-col gap-4 text-left`,children:[r&&(0,Q.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-x-1 text-sm text-ink-2 tabular-nums`,children:[(0,Q.jsx)(L,{icon:b,size:14,className:`text-muted`}),M(r.databases.length,`database`),` connected · `,l?M(l.length,`request`):`…`,y?(0,Q.jsxs)(Q.Fragment,{children:[` · `,(0,Q.jsxs)(`span`,{className:`text-fail`,children:[y,` failed`]})]}):null,` · ${r.requests.length} kept`]}),i&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:i}),!r&&!i&&(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`}),r&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ft,{label:m.name,current:p,onPick:e=>location.hash=I(`agents`,`db`,e),tabs:_r.map(e=>({id:e,label:x[e]}))}),c&&(c.running?vr[c.kind]!==void 0:vr[c.kind]===p)&&(0,Q.jsx)(Rt,{job:c,onStop:s}),(0,Q.jsxs)(`div`,{role:`tabpanel`,id:`panel-${p}`,"aria-labelledby":`tab-${p}`,children:[p===`databases`&&(0,Q.jsx)(br,{view:r,job:c,busy:a,act:o,maps:d}),p===`schema`&&(0,Q.jsx)(Sr,{view:r,job:c,busy:a,act:o,maps:d,dbName:g,setDb:e=>location.hash=I(`agents`,`db`,`schema`,encodeURIComponent(e))}),p===`ask`&&(0,Q.jsx)(Lt,{view:r,job:c,busy:a,act:o,preset:h||void 0}),p===`requests`&&(0,Q.jsx)(Vt,{view:r,log:l,busy:a,act:o}),p===`about`&&(0,Q.jsx)(Ii,{page:e})]})]})]})}var Tr={legitimate:`Legitimate`,opportunistic:`Opportunistic`,adversarial:`Adversarial`},Er={sme:`Subject matter expert`,end_user:`End user`,specialist:`Specialist`,business_user:`Business user`},Dr=[`personas`,`about`],Or={personas:`Personas`,about:`Tools and runs`};function kr({current:e,count:t}){let[n,r]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{t===void 0&&R.list().then(e=>r(e.personas.length),()=>r(null))},[t===void 0]);let i=t??n;return(0,Q.jsx)(It,{label:`Persona agent's pages`,current:e,links:[{id:`agent`,label:`Agent`,href:I(`agents`,`persona`)},{id:`personas`,label:i===null?`Personas`:`Personas (${i})`,href:I(`agents`,`persona`,`personas`)},{id:`about`,label:`Tools and runs`,href:I(`agents`,`persona`,`about`)}]})}var Ar=/^[a-z0-9][a-z0-9-]{0,39}$/,jr=/^[a-z][a-z0-9-]{1,39}$/,Mr=e=>I(`agents`,`persona`,`personas`,encodeURIComponent(e));function Nr({page:e,tab:t,sub:n}){let[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)([]),[s,c]=(0,Z.useState)(``),l=t===`new`,u=Dr.includes(t)?t:`personas`,d=st(e.agent),f=()=>R.list().then(e=>{i(e.personas),o(e.notLoaded),c(``)},e=>c(`The personas did not load: ${e.message}`));(0,Z.useEffect)(()=>{f()},[]);let p=u===`personas`&&n?Ee(n):``;return(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsx)(Dt,{agent:e,tabs:(0,Q.jsx)(kr,{current:u,...r?{count:r.length}:{}})}),(0,Q.jsxs)(`main`,{className:A(dt,`@container flex-auto gap-5 pt-4`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(He,{agent:e.agent,px:40,decorative:!0}),(0,Q.jsx)(`h1`,{className:`m-0 text-[26px] font-semibold tracking-[-0.01em]`,"aria-label":`${d.name}: ${Or[u]}`,children:Or[u]})]}),s&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:s}),!r&&!s&&(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`}),r&&(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{children:[u===`personas`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Pr,{personas:r,notLoaded:a,onChanged:e=>(i(e.personas),o(e.notLoaded))}),(0,Q.jsx)(Rr,{personas:r,opened:p,onChanged:e=>(i(e.personas),o(e.notLoaded))}),(0,Q.jsx)(Jr,{open:l,onClose:()=>location.hash=Fr,personas:r,onSaved:e=>{f().then(()=>(Vr=e,location.hash=Mr(e)))}})]}),u===`about`&&(0,Q.jsx)(Ii,{page:e})]})})]})]})}function Pr({personas:e,notLoaded:t,onChanged:r}){let[i,a]=(0,Z.useState)(`all`),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(!1),m=(0,Z.useRef)(null),h=e.filter(e=>!e.builtIn).length,g=async()=>{l(``),d(``);try{let e=await R.exportFile(),t=URL.createObjectURL(new Blob([`${JSON.stringify(e,null,2)}\n`],{type:`application/json;charset=utf-8`})),n=document.createElement(`a`);n.href=t,n.download=`forgeqe-personas.json`,n.click(),setTimeout(()=>URL.revokeObjectURL(t),1e3),l(`Exported ${M(h,`persona`)} of your own. Another project imports the file here.`)}catch(e){d(e.message)}},_=async e=>{let t=e?.[0];if(t){if(l(``),d(``),t.size>262144)return d(`${t.name} is over 256 KB.`);p(!0);try{let e=await R.importFile(await t.text());r(e),l(e.added.length?`Imported ${e.added.length===1?`the persona`:`${e.added.length} personas:`} ${e.added.join(`, `)}.`:`No new persona in the file.`),e.skipped.length&&d(`Not imported: ${e.skipped.map(e=>`${e.id} (${e.why})`).join(`; `)}`)}catch(e){d(e.message)}finally{p(!1)}}},v=o.toLowerCase().split(/\s+/).filter(Boolean),y=e.filter(e=>(i===`all`||e.kind===i)&&v.every(t=>`${e.name} ${e.role} ${e.domain} ${e.id} /${e.handle}`.toLowerCase().includes(t)));return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`p`,{className:`m-0 mr-auto flex flex-wrap items-center gap-x-1 text-sm text-ink-2 tabular-nums`,children:[(0,Q.jsx)(L,{icon:he,size:14,className:`text-muted`}),M(e.length,`persona`),` · `,h,` of your own`,t.length?(0,Q.jsxs)(Q.Fragment,{children:[` · `,(0,Q.jsxs)(`span`,{className:`text-fail`,children:[t.length,` not loaded`]})]}):null]}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[h>0&&(0,Q.jsxs)(j,{size:`sm`,onClick:()=>void g(),"data-tip":`A file of your own personas, for another project to import`,children:[(0,Q.jsx)(fe,{"aria-hidden":`true`}),`Export`]}),(0,Q.jsxs)(j,{size:`sm`,disabled:f,onClick:()=>m.current?.click(),"data-tip":`Personas another project exported`,children:[(0,Q.jsx)(pe,{"aria-hidden":`true`}),f?`Importing…`:`Import`]}),(0,Q.jsxs)(j,{size:`sm`,variant:`primary`,onClick:()=>location.hash=I(`agents`,`persona`,`new`),"data-tip":`Describe a person and the Persona agent drafts the persona, or write it yourself`,children:[(0,Q.jsx)(n,{"aria-hidden":`true`}),`New persona`]})]}),(0,Q.jsx)(`input`,{ref:m,type:`file`,accept:`.json,application/json`,hidden:!0,onChange:e=>(_(e.target.files),e.target.value=``)})]}),c&&(0,Q.jsx)(`p`,{role:`status`,className:`m-0 rounded-[12px] bg-surface-muted px-3 py-2 text-sm text-ink-2 [overflow-wrap:anywhere]`,children:c}),u&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:u}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(Oe,{id:`persona-find`,label:`Find a persona`,value:o,onChange:s}),(0,Q.jsx)(Fe,{items:[{id:`all`,label:`All`,n:e.length},...Me.map(t=>({id:t,label:Er[t],n:e.filter(e=>e.kind===t).length}))],value:i,onChange:a})]}),y.length===0?(0,Q.jsx)(z,{className:`py-4`,children:e.length?`No persona matches.`:`There are no personas yet.`}):(0,Q.jsx)(`ul`,{"aria-label":`Personas`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:y.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`a`,{href:Mr(e.id),className:`flex min-h-11 items-center gap-3 rounded-[8px] px-3 py-1.5 text-ink no-underline hover:bg-surface-muted hover:text-ink`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsxs)(`span`,{className:`truncate text-[14px] font-medium`,"data-tip":e.name,children:[e.name,!e.builtIn&&(0,Q.jsx)(`span`,{className:`font-normal text-muted`,children:` · yours`})]}),(0,Q.jsxs)(`span`,{className:`truncate text-[12.5px] text-muted`,children:[(0,Q.jsxs)(`span`,{className:`font-mono`,children:[`/`,e.handle]}),` · `,Er[e.kind],e.intent===`legitimate`?``:` · ${Tr[e.intent].toLowerCase()}`,` · `,e.role,e.domain?` · ${e.domain}`:``]})]}),(0,Q.jsx)(`span`,{className:`flex-none text-[12.5px] text-muted tabular-nums`,children:M(e.validates.length,`check`)})]})},e.id))}),t.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`persona-not-loaded`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`persona-not-loaded`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Not loaded`}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:t.map(e=>(0,Q.jsx)(`li`,{className:`text-[12.5px] text-fail [overflow-wrap:anywhere]`,children:e},e))})]}),(0,Q.jsx)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:`Your own personas are in .forgeqe/business-personas (each with its profile as a .md file), shared with everyone who uses the repository. Type a persona's command in any agent's chat, such as /priya and the task.`})]})}var Fr=I(`agents`,`persona`,`personas`),Ir=e=>{let{builtIn:t,...n}=e;return n},Lr=(e,t)=>{for(let n=1;n<100;n++){let r=n===1?`-copy`:`-copy-${n}`,i=`${e.slice(0,40-r.length)}${r}`;if(!t.has(i))return i}return``};function Rr({personas:e,opened:t,onChanged:n}){let[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(``),d=a?void 0:e.find(e=>e.id===t),p=!!t&&!a&&!d,m=()=>location.hash=Fr,h=(t,n)=>{let r=new Set(e.flatMap(e=>[e.id,e.handle])),i=n===`copy`?{...Ir(t),id:Lr(t.id,r),handle:``}:Ir(t);u(``),o({mode:n,from:t,fields:i,listText:Object.fromEntries(Kr.map(({key:e})=>[e,t[e].join(`
5
- `)]))})},g=(0,Z.useMemo)(()=>new Set(e.filter(e=>a?.mode!==`edit`||e.id!==a.from.id).flatMap(e=>[e.id,e.handle])),[e,a]),_=a?Yr(a.fields,a.listText,g,a.mode===`edit`):null,v=zr(!!t||!!a),y=async(e,t,r)=>{e[t].includes(r)||n(await R.update(e.id,{...Ir(e),[t]:[...e[t],r]}))},b=async()=>{if(a&&_?.canSave){c(!0),u(``);try{let e={...a.fields,...Object.fromEntries(Kr.map(({key:e})=>[e,qr(a.listText[e]||``)]))},t=a.mode===`edit`?await R.update(a.from.id,e):await R.save(e);n(t),o(null),a.mode===`copy`&&(Vr=t.saved),location.hash=Mr(t.saved)}catch(e){u(e.message)}finally{c(!1)}}};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(K,{wide:!0,open:!!d||p,onClose:m,title:d?.name||`No such persona`,description:d?d.builtIn?`ForgeQE's persona: read only. Copy it to edit your own version for this project.`:`This project's own persona: you can edit it.`:void 0,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{onClick:m,children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Close`]}),d&&!d.builtIn&&(0,Q.jsxs)(j,{variant:`primary`,onClick:()=>h(d,`edit`),children:[(0,Q.jsx)(w,{"aria-hidden":`true`}),`Edit`]}),d?.builtIn&&(0,Q.jsxs)(j,{variant:`primary`,"data-tip":`Make your own persona from this one, under another id and command`,onClick:()=>h(d,`copy`),children:[(0,Q.jsx)(f,{"aria-hidden":`true`}),`Copy to edit`]})]}),children:d?(0,Q.jsx)(Wr,{persona:d,resources:v,onAdd:d.builtIn?void 0:(e,t)=>y(d,e,t)}):(0,Q.jsxs)(z,{className:`py-6`,children:[`There is no persona "`,t,`" in this project.`]})}),(0,Q.jsx)(K,{wide:!0,open:!!a,onClose:()=>o(null),title:a?.mode===`edit`?`Edit ${a.from.name}`:`Copy ${a?.from.name||``}`,description:(0,Q.jsxs)(Q.Fragment,{children:[a?.mode===`copy`&&(0,Q.jsx)(Q.Fragment,{children:`A persona of your own, made from the built-in one, which stays as it is. `}),`Saved in `,(0,Q.jsxs)(`span`,{className:`font-mono text-[12px]`,children:[`.forgeqe/business-personas/`,a?.fields.id||`<id>`,`.yaml`]}),`, shared with everyone who uses the repository.`]}),footer:(0,Q.jsxs)(Q.Fragment,{children:[l?(0,Q.jsx)(`span`,{role:`alert`,className:`mr-auto self-center text-sm text-fail [overflow-wrap:anywhere]`,children:l}):a&&!_?.canSave&&(0,Q.jsxs)(`span`,{className:`mr-auto self-center text-[12.5px] text-muted`,children:[`It needs a name, `,a.mode===`copy`?`an id, `:``,`a role, and what they check or want.`]}),(0,Q.jsxs)(j,{onClick:()=>o(null),children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:s||!_?.canSave,onClick:()=>void b(),children:[(0,Q.jsx)(i,{"aria-hidden":`true`}),s?`Saving…`:a?.mode===`copy`?`Save copy`:`Save`]})]}),children:a&&_&&(0,Q.jsx)(`div`,{className:`pt-4`,children:(0,Q.jsx)(Xr,{fields:a.fields,listText:a.listText,onFields:e=>o({...a,fields:e}),onListText:e=>o({...a,listText:e}),check:_,idLocked:a.mode===`edit`,resources:v})})})]})}function zr(e){let[t,n]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{e&&!t&&R.resources().then(n,e=>n({skills:[],documents:[],error:`The skills and documents did not load: ${e.message}`}))},[e,t]),t}function Br({persona:e,resources:t,onAdd:r}){let[i,a]=(0,Z.useState)(null),o=t?.error?null:t,[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),d=`${e.skills.join(`,`)}|${e.knowledge.join(`,`)}`;(0,Z.useEffect)(()=>{a(null),R.suggest(e.id).then(a,e=>a({skills:[],documents:[],error:`The suggestions did not load: ${e.message}`}))},[e.id,d]);let f=e=>o?.skills.find(t=>t.name===e),p=e=>o?.documents.find(t=>t.ref===e),m=(0,Q.jsx)(`span`,{className:`text-warn`,children:` · not in this project`}),h=async(e,t)=>{if(r){c(`${e}:${t}`),u(``);try{await r(e,t)}catch(e){u(e.message)}finally{c(``)}}},g=i?[...i.skills.map(e=>({key:`skills`,...e})),...i.documents.map(e=>({key:`knowledge`,...e}))]:[];return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`section`,{"aria-labelledby":`persona-uses`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`persona-uses`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Shared skills and documents`}),e.skills.length+e.knowledge.length===0?(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:r?`No skills or documents yet. Add a suggestion below, or pick them in Edit.`:`No skills or documents. Copy it to edit, then pick them.`}):(0,Q.jsxs)(`ul`,{"aria-label":`Skills and documents`,className:`m-0 flex list-none flex-col p-0`,children:[e.skills.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-3 border-t border-line-soft py-2`,children:[(0,Q.jsx)(L,{icon:D,size:16,className:`mt-0.5 text-muted`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`font-mono text-[13px] [overflow-wrap:anywhere]`,children:e}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:[`Skill`,o&&!f(e)?m:f(e)?` · ${f(e).description}`:``]})]})]},`s:${e}`)),e.knowledge.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-3 border-t border-line-soft py-2`,children:[(0,Q.jsx)(L,{icon:le,size:16,className:`mt-0.5 text-muted`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] font-medium [overflow-wrap:anywhere]`,children:p(e)?.title||e}),(0,Q.jsxs)(`span`,{className:`font-mono text-[12px] text-muted [overflow-wrap:anywhere]`,children:[e,o&&!p(e)?m:null]})]})]},`k:${e}`))]}),t?.error&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:t.error})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`persona-suggested`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`persona-suggested`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Suggested for them`}),i?i.error?(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:i.error}):g.length===0?(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`Nothing else matches their domain and checks. Add documents in Settings › Evidence, or knowledge notes, to see more.`}):(0,Q.jsx)(`ul`,{"aria-label":`Suggested skills and documents`,className:`m-0 flex list-none flex-col p-0`,children:g.map(t=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 border-t border-line-soft py-2`,children:[(0,Q.jsx)(L,{icon:t.key===`skills`?D:le,size:16,className:`text-muted`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:A(`text-[13px] [overflow-wrap:anywhere]`,t.key===`skills`?`font-mono`:`font-medium`),children:t.key===`knowledge`&&p(t.name)?.title||t.name}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:[t.key===`skills`?`Skill`:t.name,` · matched `,t.why]})]}),r&&(0,Q.jsxs)(j,{size:`sm`,disabled:!!s,onClick:()=>void h(t.key,t.name),"data-tip":`Add to what ${e.name} uses`,children:[(0,Q.jsx)(n,{"aria-hidden":`true`}),s===`${t.key}:${t.name}`?`Adding…`:`Add`]})]},`${t.key}:${t.name}`))}):(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Looking for skills and documents that match…`}),l&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:l})]})]})}var Vr=``,Hr=e=>e.name.split(`,`)[0].trim()||e.name;function Ur({persona:e}){let[t,n]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(``),p=Hr(e),m=()=>R.own(e.id).then(n,e=>n({skills:[],knowledge:[],problems:[],error:`${p}'s own skills and notes did not load: ${e.message}`})),h=async()=>{c(`draft`),u(``);try{let[t,n]=await Promise.all([R.draftOwn(e.id),R.own(e.id)]),r=(e,t)=>n[e].some(e=>e.name===t);f(``),o({drafted:!0,items:[t.skill,t.knowledge].map(e=>({...e,replace:r(e.kind,e.name)}))})}catch(e){u(e.message)}finally{c(``)}};(0,Z.useEffect)(()=>{n(null),m(),Vr===e.id&&(Vr=``,h())},[e.id]);let g=async()=>{if(a){c(`save`),f(``);try{let t=a.items.filter(e=>e.was&&e.was!==e.name),r=await R.saveOwn(e.id,a.items.map(({was:e,...n})=>({...n,replace:n.replace&&!t.some(e=>e.kind===n.kind&&e.name===n.name)})));o({...a,items:a.items.map(e=>({...e,replace:!0}))});for(let n of t)await R.removeOwn(e.id,n.kind,n.was);n(t.length?await R.own(e.id):r),o(null)}catch(e){f(e.message),m()}finally{c(``)}}},_=async t=>{c(`remove:${t.kind}/${t.name}`),f(``);try{n(await R.removeOwn(e.id,t.kind,t.name)),o(null)}catch(e){f(e.message)}finally{c(``)}},v=t?[...t.skills,...t.knowledge]:[],y=(e,t)=>a&&o({...a,items:a.items.map((n,r)=>r===e?{...n,...t}:n)}),b=!!a&&a.items.every(e=>/^[a-z0-9]+(-[a-z0-9]+)*$/.test(e.name)&&e.body.trim()&&(e.kind===`knowledge`||e.description.trim()));return(0,Q.jsxs)(`section`,{"aria-labelledby":`persona-own`,className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsxs)(`h3`,{id:`persona-own`,className:`m-0 text-[13px] font-semibold text-muted`,children:[p,`'s own skills and knowledge`]}),(0,Q.jsxs)(j,{size:`sm`,disabled:!!s||!t,onClick:()=>void h(),"data-tip":`The Persona agent drafts a skill and a knowledge note for ${p}; you review them before anything is saved`,children:[(0,Q.jsx)(me,{"aria-hidden":`true`}),s===`draft`?`Generating…`:v.length?`Generate again`:`Generate skill and knowledge`]})]}),(0,Q.jsxs)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:[`Used only when someone works as `,p,`, never by other agents.`]}),s===`draft`&&(0,Q.jsxs)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:[`The Persona agent is writing `,p,`'s skill and knowledge note…`]}),t?v.length===0?!t.error&&s!==`draft`&&(0,Q.jsxs)(`p`,{className:`m-0 text-sm text-muted`,children:[`None yet. Generate a skill and a knowledge note from `,p,`'s checks, then change them as you need.`]}):(0,Q.jsx)(`ul`,{"aria-label":`${p}'s own skills and knowledge`,className:`m-0 flex list-none flex-col p-0`,children:v.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 border-t border-line-soft py-2`,children:[(0,Q.jsx)(L,{icon:e.kind===`skills`?D:le,size:16,className:`text-muted`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`font-mono text-[13px] [overflow-wrap:anywhere]`,children:e.name}),(0,Q.jsx)(`span`,{className:`line-clamp-2 text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:e.kind===`skills`?`Skill · ${e.description}`:`Knowledge note`})]}),(0,Q.jsxs)(j,{size:`sm`,disabled:!!s,onClick:()=>(f(``),o({drafted:!1,items:[{...e,replace:!0,was:e.name}]})),children:[(0,Q.jsx)(w,{"aria-hidden":`true`}),`Edit`]})]},`${e.kind}:${e.name}`))}):(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`}),t?.problems.length?(0,Q.jsxs)(`p`,{className:`m-0 text-[12.5px] text-warn [overflow-wrap:anywhere]`,children:[`Not read: `,t.problems.join(`; `)]}):null,(l||t?.error)&&(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:l||t?.error}),(0,Q.jsx)(K,{wide:!0,open:!!a,onClose:()=>o(null),title:a?.drafted?`Review ${p}'s skill and knowledge`:`Edit ${a?.items[0]?.was||``}`,description:(0,Q.jsxs)(Q.Fragment,{children:[a?.drafted&&(0,Q.jsx)(Q.Fragment,{children:`The Persona agent's draft: change anything, then save. `}),`Kept in `,(0,Q.jsxs)(`span`,{className:`font-mono text-[12px]`,children:[`.forgeqe/business-personas/`,e.id,`/`]}),` and used only when someone works as `,p,`.`]}),footer:(0,Q.jsxs)(Q.Fragment,{children:[d?(0,Q.jsx)(`span`,{role:`alert`,className:`mr-auto self-center text-sm text-fail [overflow-wrap:anywhere]`,children:d}):a&&!b&&(0,Q.jsx)(`span`,{className:`mr-auto self-center text-[12.5px] text-muted`,children:`Each needs a name of lower-case words joined by dashes and its text; a skill also its "use when" line.`}),a&&!a.drafted&&a.items[0]?.was&&(0,Q.jsxs)(j,{disabled:!!s,onClick:()=>void _({...a.items[0],name:a.items[0].was}),className:A(!d&&b&&`mr-auto`,`text-fail`),children:[(0,Q.jsx)(ue,{"aria-hidden":`true`}),s.startsWith(`remove:`)?`Deleting…`:`Delete`]}),(0,Q.jsxs)(j,{onClick:()=>o(null),children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:s===`save`||!b,onClick:()=>void g(),children:[(0,Q.jsx)(i,{"aria-hidden":`true`}),s===`save`?`Saving…`:a?.drafted?`Save both`:`Save`]})]}),children:a&&(0,Q.jsx)(`div`,{className:`flex flex-col gap-6 pt-4`,children:a.items.map((e,t)=>(0,Q.jsxs)(`section`,{"aria-labelledby":`own-item-${t}`,className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`h3`,{id:`own-item-${t}`,className:`m-0 flex items-center gap-1.5 text-[13px] font-semibold text-muted`,children:[(0,Q.jsx)(L,{icon:e.kind===`skills`?D:le,size:14}),e.kind===`skills`?`Skill`:`Knowledge note`,e.replace&&!e.was&&(0,Q.jsx)(`span`,{className:`font-normal text-warn`,children:` · replaces the one of this name`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Name`}),(0,Q.jsx)(N,{value:e.name,maxLength:64,spellCheck:!1,autoComplete:`off`,className:`font-mono`,onChange:e=>y(t,{name:e.target.value.toLowerCase().replace(/[^a-z0-9-]+/g,`-`)})})]}),e.kind===`skills`&&(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Use when`}),(0,Q.jsx)(N,{value:e.description,maxLength:400,onChange:e=>y(t,{description:e.target.value})})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`label`,{htmlFor:`own-body-${t}`,className:`font-medium`,children:e.kind===`skills`?`Instructions`:`What it says`}),(0,Q.jsx)(Tt,{id:`own-body-${t}`,value:e.body,lang:`markdown`,onChange:e=>y(t,{body:e})})]})]},t))})})]})}function Wr({persona:e,resources:t,onAdd:n}){let r=[[`persona-validates`,`What they check before accepting the software`,e.validates],[`persona-goals`,`What they want to do`,e.goals],[`persona-knows`,`What they know`,e.knows],[`persona-frustrations`,`What puts them off`,e.frustrations],[`persona-scenarios`,`What they would try`,e.scenarios],[`persona-motivations`,`What drives them`,e.motivations],[`persona-permissions`,`What their role lets them do`,e.permissions],[`persona-constraints`,`What limits them`,e.constraints],[`persona-mistakes`,`Mistakes they make`,e.mistakes],[`persona-relationships`,`Who they deal with`,e.relationships]];return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6 pt-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsxs)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:[(0,Q.jsxs)(`span`,{className:`font-mono`,children:[`/`,e.handle]}),` · `,Er[e.kind],` · `,e.role,e.domain?` · ${e.domain}`:``,` · `,e.expertise.charAt(0).toUpperCase()+e.expertise.slice(1),e.intent===`legitimate`?``:` · ${Tr[e.intent].toLowerCase()}, risk appetite ${e.risk_appetite}`,e.builtIn?``:` · version ${e.version}`]}),e.description&&(0,Q.jsx)(`p`,{className:`m-0 max-w-[72ch] text-sm leading-relaxed text-ink-2`,children:e.description})]}),(0,Q.jsx)(Ur,{persona:e}),(0,Q.jsx)(Br,{persona:e,resources:t,...n?{onAdd:n}:{}}),r.filter(([,,e])=>e.length).map(([e,t,n])=>(0,Q.jsxs)(`section`,{"aria-labelledby":e,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:e,className:`m-0 text-[13px] font-semibold text-muted`,children:t}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5 text-sm text-ink-2`,children:n.map(e=>(0,Q.jsx)(`li`,{className:`[overflow-wrap:anywhere]`,children:e},e))})]},e))]})}var Gr={id:``,handle:``,name:``,kind:`business_user`,role:``,domain:``,expertise:`intermediate`,description:``,goals:[],knows:[],validates:[],frustrations:[],scenarios:[],intent:`legitimate`,risk_appetite:`low`,motivations:[],permissions:[],constraints:[],mistakes:[],relationships:[],version:1,skills:[],knowledge:[]},Kr=[{key:`validates`,label:`What they check`,hint:`One rule a test can check per line, such as: a refund never exceeds the captured amount.`},{key:`goals`,label:`What they want to do`,hint:`One per line.`},{key:`knows`,label:`What they know`,hint:`Terms and rules of the domain, one per line.`},{key:`frustrations`,label:`What puts them off`,hint:`One per line.`},{key:`scenarios`,label:`What they would try`,hint:`Tasks in their words, one per line.`},{key:`motivations`,label:`What drives them`,hint:`One per line, such as: save money, hit the monthly target.`},{key:`permissions`,label:`What their role lets them do`,hint:`In the app, one per line, such as: issue refunds up to 500.`},{key:`constraints`,label:`What limits them`,hint:`Money, time or rules they work within, one per line.`},{key:`mistakes`,label:`Mistakes they make`,hint:`One per line, such as: double-clicks Pay when the page is slow.`},{key:`relationships`,label:`Who they deal with`,hint:`Other personas by id and how, one per line, such as: approves for insider-agent.`}],qr=e=>e.split(`
6
- `).map(e=>e.trim()).filter(Boolean);function Jr({open:e,onClose:t,personas:n,onSaved:a}){let[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)({}),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(``),[b,x]=(0,Z.useState)(``),S=(0,Z.useMemo)(()=>new Set(n.flatMap(e=>[e.id,e.handle])),[n]),C=zr(!!f),w=(0,Z.useRef)(0);(0,Z.useEffect)(()=>{w.current+=1,e&&(s(``),l(``),d(``),p(null),h({}),_(!1),y(``),x(``))},[e]);let T=e=>{p(e),h(Object.fromEntries(Kr.map(({key:t})=>[t,e[t].join(`
7
- `)])))},E=async()=>{let e=w.current;y(`draft`),x(``);try{let{persona:t}=await R.draft({request:o.trim(),...c?{kind:c}:{},...u.trim()?{domain:u.trim()}:{}});if(e!==w.current)return;let{builtIn:n,...r}=t;T(r),_(!0)}catch(t){e===w.current&&x(t.message)}finally{e===w.current&&y(``)}},D=async()=>{if(f){y(`save`),x(``);try{let e={...f,...Object.fromEntries(Kr.map(({key:e})=>[e,qr(m[e]||``)]))};a((await R.save(e)).saved)}catch(e){x(e.message),y(``)}}},O=f?Yr(f,m,S,!1):null,ee=!!O?.canSave;return(0,Q.jsx)(K,{wide:!0,open:e,onClose:t,title:`New persona`,description:(0,Q.jsxs)(Q.Fragment,{children:[`Saved in `,(0,Q.jsxs)(`span`,{className:`font-mono text-[12px]`,children:[`.forgeqe/business-personas/`,f?.id||`<id>`,`.yaml`]}),`, shared with the project.`]}),footer:(0,Q.jsxs)(Q.Fragment,{children:[b?(0,Q.jsx)(`span`,{role:`alert`,className:`mr-auto self-center text-sm text-fail [overflow-wrap:anywhere]`,children:b}):f&&!ee&&(0,Q.jsx)(`span`,{className:`mr-auto self-center text-[12.5px] text-muted`,children:`It needs a name, an id, a role, and what they check or want.`}),(0,Q.jsxs)(j,{onClick:t,children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:!!v||!ee,onClick:()=>void D(),children:[(0,Q.jsx)(i,{"aria-hidden":`true`}),v===`save`?`Saving…`:`Save`]})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6 pt-4`,children:[(0,Q.jsxs)(`section`,{"aria-labelledby":`persona-ask`,className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`h3`,{id:`persona-ask`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Who is the persona?`}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Describe them`}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`Their job, what they know and what they check. The Persona agent drafts the rest.`}),(0,Q.jsx)(V,{rows:3,value:o,maxLength:2e3,onChange:e=>s(e.target.value),placeholder:`An SME in card payments who reconciles settlements every morning and signs off refunds`})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Kind`}),(0,Q.jsxs)(B,{value:c,onChange:e=>l(e.target.value),children:[(0,Q.jsx)(`option`,{value:``,children:`Let the agent choose`}),Me.map(e=>(0,Q.jsx)(`option`,{value:e,children:Er[e]},e))]})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Domain`}),(0,Q.jsx)(N,{value:u,maxLength:80,onChange:e=>d(e.target.value),placeholder:`payments`})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(j,{disabled:!!v||!o.trim(),onClick:()=>void E(),"data-tip":g?`Ask the Persona agent for another draft`:`Ask the Persona agent for a draft`,children:[(0,Q.jsx)(me,{"aria-hidden":`true`}),g?`Draft again`:`Draft`]}),!f&&(0,Q.jsxs)(j,{disabled:!!v,onClick:()=>T(Gr),"data-tip":`Write every field yourself`,children:[(0,Q.jsx)(oe,{"aria-hidden":`true`}),`Write`]}),v===`draft`&&(0,Q.jsx)(`span`,{role:`status`,className:`text-sm text-muted`,children:`The Persona agent is drafting…`})]})]}),f&&O&&(0,Q.jsxs)(`section`,{"aria-labelledby":`persona-fields`,className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`h3`,{id:`persona-fields`,className:`m-0 text-[13px] font-semibold text-muted`,children:`The persona`}),(0,Q.jsx)(Xr,{fields:f,listText:m,onFields:p,onListText:h,check:O,idLocked:!1,resources:C})]})]})})}function Yr(e,t,n,r){let i=r||e.id===``?``:Ar.test(e.id)?n.has(e.id)?`A persona has this id: pick another.`:``:`Lower-case letters, digits and dashes, at most 40.`,a=e.handle||e.id,o=a===``?``:jr.test(a)?e.handle&&e.handle!==e.id&&n.has(e.handle)?`A persona has this command: pick another.`:``:`A word of lower-case letters, digits and dashes that starts with a letter.`;return{idProblem:i,handleProblem:o,canSave:!!e.id&&!i&&!o&&!!e.name.trim()&&!!e.role.trim()&&(qr(t.validates||``).length>0||qr(t.goals||``).length>0)}}function Xr({fields:e,listText:t,onFields:n,onListText:r,check:i,idLocked:a,resources:o}){let s=(t,r)=>n({...e,[t]:r}),{idProblem:c,handleProblem:l}=i;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Name`}),(0,Q.jsx)(N,{value:e.name,maxLength:80,onChange:e=>s(`name`,e.target.value),placeholder:`Priya, payments SME`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Id`}),(0,Q.jsx)(N,{value:e.id,disabled:a,maxLength:40,spellCheck:!1,autoComplete:`off`,"aria-invalid":!!c,"aria-describedby":c?`persona-id-error`:void 0,onChange:e=>s(`id`,e.target.value.toLowerCase()),className:`font-mono`}),c&&(0,Q.jsx)(`p`,{id:`persona-id-error`,role:`alert`,className:`m-0 text-[12.5px] text-fail`,children:c})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Command`}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[`Type it in any agent's chat: /`,e.handle||e.id||`priya`,` Validate the payment change.`]}),(0,Q.jsx)(N,{value:e.handle,maxLength:40,spellCheck:!1,autoComplete:`off`,"aria-invalid":!!l,"aria-describedby":l?`persona-handle-error`:void 0,onChange:e=>s(`handle`,e.target.value.toLowerCase().replace(/^\//,``)),className:`font-mono`,placeholder:e.id||`priya`}),l&&(0,Q.jsx)(`p`,{id:`persona-handle-error`,role:`alert`,className:`m-0 text-[12.5px] text-fail`,children:l})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Kind`}),(0,Q.jsx)(B,{value:e.kind,onChange:e=>s(`kind`,e.target.value),children:Me.map(e=>(0,Q.jsx)(`option`,{value:e,children:Er[e]},e))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Expertise in the domain`}),(0,Q.jsx)(B,{value:e.expertise,onChange:e=>s(`expertise`,e.target.value),children:ve.map(e=>(0,Q.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Intent`}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`Opportunistic takes any advantage the app gives; adversarial sets out to misuse it. The Business assurance agent tests as them.`}),(0,Q.jsx)(B,{value:e.intent,onChange:e=>s(`intent`,e.target.value),children:be.map(e=>(0,Q.jsx)(`option`,{value:e,children:Tr[e]},e))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Risk appetite`}),(0,Q.jsx)(B,{value:e.risk_appetite,onChange:e=>s(`risk_appetite`,e.target.value),children:ye.map(e=>(0,Q.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Role`}),(0,Q.jsx)(N,{value:e.role,maxLength:120,onChange:e=>s(`role`,e.target.value),placeholder:`Payments operations lead`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Domain`}),(0,Q.jsx)(N,{value:e.domain,maxLength:80,onChange:e=>s(`domain`,e.target.value)})]})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Who they are`}),(0,Q.jsx)(V,{rows:3,value:e.description,maxLength:1200,onChange:e=>s(`description`,e.target.value)})]}),Kr.map(({key:e,label:n,hint:i})=>(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:n}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:i}),(0,Q.jsx)(V,{rows:e===`validates`?5:3,value:t[e]||``,onChange:n=>r({...t,[e]:n.target.value})})]},e)),(0,Q.jsx)(Qr,{id:`persona-skills`,label:`Skills an agent loads as them`,hint:`The agent loads these with its skill tool whenever someone works as this persona.`,items:o?.skills.map(e=>({id:e.name,title:e.name,note:e.description,mono:!0}))??null,...o?.error?{error:o.error}:{},value:e.skills,onChange:e=>s(`skills`,e)}),(0,Q.jsx)(Qr,{id:`persona-knowledge`,label:`Documents they rely on`,hint:`Knowledge notes and the project's documents. The agent searches them for what the request needs.`,items:o?.documents.map(e=>({id:e.ref,title:e.title,note:e.ref}))??null,...o?.error?{error:o.error}:{},value:e.knowledge,onChange:e=>s(`knowledge`,e)})]})}var Zr=12;function Qr({id:e,label:t,hint:n,items:r,error:i,value:a,onChange:o}){let[s,c]=(0,Z.useState)(``),l=s.toLowerCase().split(/\s+/).filter(Boolean),u=r?[...a.filter(e=>!r.some(t=>t.id===e)).map(e=>({id:e,title:e,note:`Not in this project`,mono:!0})),...r]:[],d=u.filter(e=>l.every(t=>`${e.title} ${e.note} ${e.id}`.toLowerCase().includes(t))).sort((e,t)=>Number(a.includes(t.id))-Number(a.includes(e.id))),f=a.length>=Zr;return(0,Q.jsxs)(`fieldset`,{className:`m-0 flex flex-col gap-1.5 border-0 p-0 text-sm`,children:[(0,Q.jsxs)(`legend`,{className:`mb-1.5 p-0 font-medium`,children:[t,` `,(0,Q.jsxs)(`span`,{className:`font-normal text-muted tabular-nums`,children:[`· `,a.length,` picked`]})]}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:n}),i?(0,Q.jsx)(`p`,{role:`alert`,className:`m-0 rounded-[12px] bg-fail-soft px-3 py-2 text-sm text-fail [overflow-wrap:anywhere]`,children:i}):r?u.length===0?(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`There are none in this project yet.`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,Q.jsx)(Oe,{id:`${e}-find`,label:`Find in ${t.toLowerCase()}`,value:s,onChange:c})}),(0,Q.jsxs)(`ul`,{"aria-label":t,className:`m-0 max-h-72 list-none overflow-y-auto rounded-[12px] card border px-3 py-0`,children:[d.length===0&&(0,Q.jsx)(`li`,{className:`py-3 text-sm text-muted`,children:`Nothing matches.`}),d.map(e=>{let t=a.includes(e.id);return(0,Q.jsx)(`li`,{className:`border-t border-line-soft first:border-t-0`,children:(0,Q.jsxs)(`label`,{className:A(`flex min-h-12 items-center gap-3 py-2`,!t&&f?`cursor-not-allowed opacity-60`:`cursor-pointer`),children:[(0,Q.jsx)(kt,{checked:t,disabled:!t&&f,onCheckedChange:t=>o(t?[...a,e.id]:a.filter(t=>t!==e.id))}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:A(`text-[13px] [overflow-wrap:anywhere]`,e.mono?`font-mono`:`font-medium`),children:e.title}),(0,Q.jsx)(`span`,{className:`line-clamp-2 text-[12.5px] text-muted [overflow-wrap:anywhere]`,"data-tip":e.note.length>120?e.note:void 0,children:e.note})]})]})},e.id)})]}),f&&(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[`At most `,Zr,`: take one off to pick another.`]})]}):(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`})]})}var $r=600,ei={approves:`Approval`,colludes:`May collude`,serves:`Serves`,deals:`Deals with`},ti=e=>`${String(e[0]).padStart(2,`0`)}:00–${String(e[1]).padStart(2,`0`)}:00`;function ni(){let[e,t]=(0,Z.useState)(null),[n,r]=(0,Z.useState)(``),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(`200`),[c,l]=(0,Z.useState)(`7`),[u,d]=(0,Z.useState)(`15`),[f,m]=(0,Z.useState)(`5`),h=e=>{if(t(e),e.population){let t=e.population.spec;s(String(t.size)),l(String(t.seed)),d(String(Math.round(t.mix.opportunistic*100))),m(String(Math.round(t.mix.adversarial*100)))}},g=e=>P.population(e).then(e=>(h(e),r(``)),e=>r(`The population did not load: ${e.message}`));(0,Z.useEffect)(()=>{g()},[]);let _=async()=>{let e=Number(u)/100,t=Number(f)/100;if(![Number(o),Number(c),e,t].every(Number.isFinite)||e<0||t<0||e+t>1)return r(`Give a number of people, a seed, and shares that add up to 100% at most.`);a(!0),r(``);try{h(await P.populate({size:Math.round(Number(o)),seed:Math.round(Number(c)),mix:{legitimate:Math.max(0,1-e-t),opportunistic:e,adversarial:t}}))}catch(e){r(e.message)}finally{a(!1)}},v=e?.population??null,y=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-x-4 gap-y-2`,children:[e&&e.populations.length>1&&(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Population`}),(0,Q.jsx)(B,{value:v?.id||``,onChange:e=>void g(e.target.value),children:e.populations.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`People`}),(0,Q.jsx)(N,{type:`number`,min:5,max:2e3,value:o,onChange:e=>s(e.target.value),className:`w-[110px] tabular-nums`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Opportunists %`}),(0,Q.jsx)(N,{type:`number`,min:0,max:100,value:u,onChange:e=>d(e.target.value),className:`w-[110px] tabular-nums`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Adversarial %`}),(0,Q.jsx)(N,{type:`number`,min:0,max:100,value:f,onChange:e=>m(e.target.value),className:`w-[110px] tabular-nums`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Seed`}),(0,Q.jsx)(N,{type:`number`,min:0,value:c,onChange:e=>l(e.target.value),className:`w-[110px] tabular-nums`})]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:i,onClick:()=>void _(),"data-tip":`Draw a population from the personas: the same seed gives the same people`,children:[(0,Q.jsx)(p,{"aria-hidden":`true`}),i?`Making…`:`Make population`]})]});return e?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[y,n&&(0,Q.jsx)(Y,{text:n}),v?(0,Q.jsx)(ii,{p:v,personas:e.personas,onRefresh:()=>void g(v.id),refreshing:i},v.id+v.createdAt):(0,Q.jsxs)(z,{icon:he,title:`No population yet`,action:(0,Q.jsxs)(`a`,{className:U({size:`sm`}),href:I(`agents`,`persona`,`personas`),"data-tip":`Open the Persona agent's personas`,children:[(0,Q.jsx)(se,{"aria-hidden":`true`}),`Personas`]}),children:[`Make one above: people drawn from your `,M(e.personas.length,`persona`),`, mostly legitimate customers, some opportunists, a few insiders, and the staff they deal with.`]})]}):n?(0,Q.jsx)(Y,{text:n}):(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`})}function ri(e,t,n){return e===`approves`?`APPROVAL_FROM`:e===`colludes`?`MAY_COLLUDE_WITH`:e===`serves`?t?.side===`customer`&&n?.side===`business`?`BUYS_FROM`:`SERVES`:t?.persona===n?.persona?`SHARES_DEALS_WITH`:`DEALS_WITH`}function ii({p:e,personas:t,onRefresh:n,refreshing:r}){let[i,a]=(0,Z.useState)(null),o=(0,Z.useMemo)(()=>new Map(e.members.map(e=>[e.id,e])),[e]),s=(0,Z.useMemo)(()=>{let t=new Set(e.links.flatMap(e=>[e.from,e.to]));return[...e.members].sort((e,n)=>Number(t.has(n.id))-Number(t.has(e.id))).slice(0,$r)},[e]),c=t=>e.archetypes.find(e=>e.persona===t)?.name||t,l=(0,Z.useMemo)(()=>e.archetypes.map(e=>e.name),[e]),u=e=>Ht[Math.max(0,l.indexOf(e))%Ht.length],d=(0,Z.useMemo)(()=>s.map(e=>({id:e.id,name:e.name,type:c(e.persona),r:e.side===`business`?7:e.activity===`high`?6:5})),[s]),f=(0,Z.useMemo)(()=>e.links.map((e,t)=>({id:`e${t}`,from:e.from,to:e.to,label:ri(e.kind,o.get(e.from),o.get(e.to))})),[e,o]),p=null;if(i?.kind===`node`){let e=o.get(i.id),n=e&&t.find(t=>t.id===e.persona);e&&(p={title:`Node Details`,pill:{text:c(e.persona).split(`,`)[0],colour:u(c(e.persona))},body:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(X,{label:`Name`,children:e.name}),(0,Q.jsx)(X,{label:`ID`,children:(0,Q.jsx)(`span`,{className:`font-mono text-[12px]`,children:e.id})}),(0,Q.jsx)(X,{label:`Persona`,children:(0,Q.jsx)(`a`,{href:I(`agents`,`persona`,`personas`,encodeURIComponent(e.persona)),children:n?.name||e.persona})}),(0,Q.jsxs)(Wt,{title:`Properties`,children:[(0,Q.jsx)(X,{label:`side`,children:e.side===`customer`?`customer`:`staff or partner`}),(0,Q.jsx)(X,{label:`intent`,children:e.intent}),(0,Q.jsx)(X,{label:`risk_appetite`,children:e.risk_appetite}),(0,Q.jsx)(X,{label:`activity`,children:e.activity}),(0,Q.jsx)(X,{label:`hours`,children:ti(e.hours)}),(0,Q.jsxs)(X,{label:`budget`,children:[e.budget.toLocaleString(),` a month`]}),(0,Q.jsx)(X,{label:`joined`,children:e.tenure===0?`today`:`${M(e.tenure,`day`)} ago`})]}),n&&(n.motivations.length>0||n.role)&&(0,Q.jsx)(Wt,{title:`Summary`,children:(0,Q.jsxs)(`p`,{className:`m-0 leading-relaxed text-ink-2`,children:[n.role,n.motivations.length?`. Driven by ${n.motivations.join(`, `)}.`:`.`]})}),(0,Q.jsx)(Wt,{title:`Labels`,children:(0,Q.jsxs)(`span`,{className:`flex flex-wrap gap-1.5`,children:[(0,Q.jsx)(Gt,{children:`Person`}),(0,Q.jsx)(Gt,{children:e.side===`customer`?`Customer`:`Staff`}),(0,Q.jsx)(Gt,{children:e.intent})]})})]})})}else if(i?.kind===`edge`){let t=f.find(e=>e.id===i.id),n=t?e.links[Number(t.id.slice(1))]:void 0,r=n&&o.get(n.from),s=n&&o.get(n.to);t&&n&&r&&s&&(p={title:`Relationship`,body:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`m-0 rounded-[8px] bg-surface-strong px-3 py-2 text-ink [overflow-wrap:anywhere]`,children:[r.name,` → `,t.label,` → `,s.name]}),(0,Q.jsx)(X,{label:`Label`,children:t.label}),(0,Q.jsx)(X,{label:`Type`,children:ei[n.kind]}),(0,Q.jsx)(X,{label:`Fact`,children:n.why}),(0,Q.jsx)(X,{label:`From`,children:(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer border-0 bg-transparent p-0 text-left text-accent-fg hover:underline`,onClick:()=>a({kind:`node`,id:r.id}),children:r.name})}),(0,Q.jsx)(X,{label:`To`,children:(0,Q.jsx)(`button`,{type:`button`,className:`cursor-pointer border-0 bg-transparent p-0 text-left text-accent-fg hover:underline`,onClick:()=>a({kind:`node`,id:s.id}),children:s.name})})]})})}return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`p`,{className:`m-0 text-[12.5px] text-muted tabular-nums`,children:[(0,Q.jsx)(`span`,{className:`font-mono`,children:e.id}),` · `,M(e.members.length,`person`,`people`),` · `,M(e.links.length,`relationship`),` · seed `,e.spec.seed,e.members.length>s.length?` · ${e.members.length-s.length} people without relationships left out of the drawing`:``,e.notes.length?` · ${e.notes.join(` `)}`:``]}),(0,Q.jsx)(Ut,{title:`Graph Relationship Visualization`,nodes:d,edges:f,colourOfType:u,types:l,typesTitle:`Persona types`,picked:i,onPick:a,detail:p,onRefresh:n,refreshing:r})]})}var ai={confirmed_failure:`fail`,policy_ambiguity:`warn`,potential_risk:`warn`,missing_evidence:`neutral`,expected_behaviour:`pass`},oi={financial:`Financial`,operational:`Operational`,customer:`Customer`,regulatory:`Regulatory`,reputational:`Reputational`,fairness:`Fairness`},si={executive:`Leaders`,product:`Product`,risk:`Risk and compliance`,engineering:`Engineering`};function ci(e){let{version:t,createdAt:n,by:r,...i}=e;return i}function li(e){let t={};for(let n of e.split(`,`)){let e=n.indexOf(`=`);if(e<1)continue;let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();/^[a-z][a-z0-9_]{0,39}$/.test(r)&&(t[r]=/^-?\d+(\.\d+)?$/.test(i)?Number(i):i===`true`||i!==`false`&&i)}return t}var ui=e=>I(`agents`,`business`,`simulation`,encodeURIComponent(e)),di=10;function fi({opened:e,environments:t}){return e?(0,Q.jsx)(mi,{id:e,environments:t},e):(0,Q.jsx)(pi,{})}function pi(){let[e,t]=(0,Z.useState)(null),[n,r]=(0,Z.useState)(``),[i,a]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{P.simulations().then(t,e=>r(`The simulations did not load: ${e.message}`))},[]);let o=async()=>{a(!0),r(``);try{let{id:e}=await P.planSimulation({});location.hash=ui(e)}catch(e){r(e.message),a(!1)}};return e?e.populations.length?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,Q.jsxs)(j,{variant:`primary`,disabled:i,onClick:()=>void o(),"data-tip":`Plan everyday trading for ${e.populations[0]}, the newest population`,children:[(0,Q.jsx)(ge,{"aria-hidden":`true`}),i?`Planning…`:`Plan a simulation`]}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`For the newest population, from your saved API calls: customers order, pay, refund and redeem; opportunists refund twice and redeem in bursts.`})]}),n&&(0,Q.jsx)(Y,{text:n}),e.simulations.length===0?(0,Q.jsx)(z,{className:`py-4`,children:`No simulation yet. Plan one above.`}):(0,Q.jsx)(`ul`,{"aria-label":`Simulations`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:e.simulations.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`a`,{href:ui(e.id),className:`flex min-h-11 items-center gap-3 rounded-[8px] px-3 py-1.5 text-ink no-underline hover:bg-surface-muted hover:text-ink`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`truncate text-[14px] font-medium`,"data-tip":e.title,children:e.title}),(0,Q.jsxs)(`span`,{className:`truncate text-[12.5px] text-muted`,children:[(0,Q.jsx)(`span`,{className:`font-mono`,children:e.id}),` · `,M(e.actions,`action`),` · `,M(e.checks,`check`),e.calls===void 0?``:` · last run ${M(e.calls,`call`)}`,e.problem?` · ${e.problem}`:``]})]}),e.outcome&&e.label?(0,Q.jsx)(F,{tone:ai[e.outcome],children:e.label}):(0,Q.jsx)(`span`,{className:`flex-none text-[12.5px] text-muted`,children:`Not run`})]})},e.id))})]}):(0,Q.jsx)(z,{icon:he,title:`No population yet`,action:(0,Q.jsxs)(`a`,{className:U({size:`sm`}),href:I(`agents`,`business`,`personas`),"data-tip":`Open the Personas tab`,children:[(0,Q.jsx)(se,{"aria-hidden":`true`}),`Personas`]}),children:`A simulation plays a population: make one on the Personas tab first.`}):n?(0,Q.jsx)(Y,{text:n}):(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`})}function mi({id:e,environments:t}){let[n,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)({}),b=()=>P.simulation(e).then(e=>{i(e),p(n=>n||e.simulation.environment||t[0]||``),l(``)},e=>l(`The simulation did not load: ${e.message}`));(0,Z.useEffect)(()=>{b()},[e]);let x=(0,Q.jsxs)(`a`,{href:I(`agents`,`business`,`simulation`),className:`inline-flex items-center gap-1.5 self-start text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),`Every simulation`]});if(c&&!n)return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[x,(0,Q.jsx)(Y,{text:c})]});if(!n)return(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`});let S=n.simulation,C=n.run,w=async e=>{_(!0),d(``);try{await P.runSimulation(S.id,e,f||void 0),h(!1),await b()}catch(e){d(e.message)}finally{_(!1)}},T=(C?.events||[]).map(e=>`Day ${e.day} ${String(e.hour).padStart(2,`0`)}:00 ${e.name.padEnd(18)} ${e.action}${e.attempt>1?` #${e.attempt}`:``} ${e.error?`not done: ${e.error}`:`→ ${e.status}`}${Object.keys(e.values).length?` ${Object.entries(e.values).map(([e,t])=>`${e}=${String(t)}`).join(` `)}`:``}`).join(`
8
- `);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[x,(0,Q.jsx)(`h2`,{className:`m-0 text-[18px] font-semibold`,children:S.title}),(0,Q.jsxs)(`p`,{className:`m-0 text-[13px] text-muted`,children:[(0,Q.jsx)(`span`,{className:`font-mono`,children:S.id}),` · population `,S.population,` · `,M(S.days,`day`),` · at most `,M(S.max_calls,`call`),` · seed `,S.seed]})]}),c&&(0,Q.jsx)(Y,{text:c}),(0,Q.jsxs)(`section`,{"aria-labelledby":`sim-run`,className:`flex flex-col gap-3 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`h3`,{id:`sim-run`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Run it`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Test environment`}),(0,Q.jsxs)(B,{value:f,onChange:e=>p(e.target.value),disabled:!t.length,children:[!t.length&&(0,Q.jsx)(`option`,{value:``,children:`No test environment in env.yaml`}),t.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:g||!t.length,onClick:()=>n.writes.length?h(!0):void w([]),"data-tip":n.writes.length?`Shows the calls that change data before any is sent`:`Plays the population through the plan's API calls`,children:[(0,Q.jsx)(s,{"aria-hidden":`true`}),g?`Running…`:`Run`]})]}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`Each simulated hour, the people active in it act through your API, only on this environment's own address and never on one named like production, until the days or the call budget run out. The same seed acts the same way.`}),u&&(0,Q.jsx)(Y,{text:u}),C&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(F,{tone:ai[C.outcome],children:C.label}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[`Confidence `,C.confidence,` · `,Kt(C.at),C.environment?` on ${C.environment}`:``,` · `,M(C.calls,`call`),C.budget_reached?` (the call budget was reached)`:``]})]}),(0,Q.jsx)(`p`,{className:`m-0 max-w-[80ch] text-sm text-ink-2 [overflow-wrap:anywhere]`,children:C.why})]})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`sim-checks`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`sim-checks`,className:`m-0 text-[13px] font-semibold text-muted`,children:`What the business intended`}),S.checks.length===0?(0,Q.jsx)(z,{className:`py-3`,children:`The plan has no check, so no outcome can be judged. Add checks in the plan below.`}):(0,Q.jsx)(`ul`,{"aria-label":`Checks`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:S.checks.map(e=>{let t=C?.results.find(t=>t.id===e.oracle.id),n=t?.breakers||[],r=v[e.oracle.id];return(0,Q.jsxs)(`li`,{className:`flex flex-col gap-1.5 rounded-[8px] px-3 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`flex min-h-8 items-center gap-3`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium [overflow-wrap:anywhere]`,children:e.oracle.says}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:[e.scope===`member`?`For each person`:`For the whole population`,t?` · ${t.detail}`:``]})]}),t&&(0,Q.jsx)(F,{tone:t.status===`held`?`pass`:t.status===`violated`?`fail`:`neutral`,children:t.status===`held`?`Held`:t.status===`violated`?`Broken`:`Not known`})]}),n.length>0&&(0,Q.jsxs)(`ul`,{"aria-label":`Who broke: ${e.oracle.says}`,className:`m-0 flex list-none flex-col gap-0.5 p-0 pl-3 text-[12.5px] text-ink-2`,children:[(r?n:n.slice(0,di)).map(t=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-2 [overflow-wrap:anywhere]`,children:[(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-ink`,children:t.name}),` `,(0,Q.jsxs)(`span`,{className:`text-muted`,children:[`(`,t.persona,`)`]}),`: `,t.detail]}),(0,Q.jsxs)(j,{size:`sm`,variant:`ghost`,onClick:()=>o({member:t.member,name:t.name,persona:t.persona,says:e.oracle.says}),"data-tip":`Ask ${t.name} why, as the model tells it`,children:[(0,Q.jsx)(ee,{"aria-hidden":`true`}),`Ask why`]})]},t.member)),n.length>di&&(0,Q.jsx)(`li`,{children:(0,Q.jsx)(j,{size:`sm`,variant:`ghost`,onClick:()=>y({...v,[e.oracle.id]:!r}),children:r?`Show fewer`:`Show all ${n.length}`})})]})]},e.oracle.id)})})]}),C&&C.personas.some(e=>e.actions>0)&&(0,Q.jsxs)(`section`,{"aria-labelledby":`sim-personas`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`sim-personas`,className:`m-0 text-[13px] font-semibold text-muted`,children:`By persona`}),(0,Q.jsx)(it,{label:`Calls by persona`,search:!1,head:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`th`,{className:`px-3 py-1.5 text-left text-[11.5px] font-medium whitespace-nowrap text-muted`,children:`Persona`}),(0,Q.jsx)(`th`,{className:`px-3 py-1.5 text-right text-[11.5px] font-medium whitespace-nowrap text-muted`,children:`Calls`}),(0,Q.jsx)(`th`,{className:`px-3 py-1.5 text-right text-[11.5px] font-medium whitespace-nowrap text-muted`,children:`Accepted`}),(0,Q.jsx)(`th`,{className:`px-3 py-1.5 text-right text-[11.5px] font-medium whitespace-nowrap text-muted`,children:`Refused`}),(0,Q.jsx)(`th`,{className:`px-3 py-1.5 text-right text-[11.5px] font-medium whitespace-nowrap text-muted`,children:`Not sent`})]}),children:C.personas.filter(e=>e.actions>0).map(e=>(0,Q.jsxs)(`tr`,{className:`border-t border-line-soft align-top`,children:[(0,Q.jsx)(`td`,{className:`px-3 py-2`,children:e.persona}),(0,Q.jsx)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap tabular-nums`,children:e.actions}),(0,Q.jsx)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap tabular-nums`,children:e.accepted}),(0,Q.jsx)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap tabular-nums`,children:e.refused}),(0,Q.jsx)(`td`,{className:`px-3 py-2 text-right whitespace-nowrap tabular-nums`,children:e.failed})]},e.persona))})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`sim-actions`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`sim-actions`,className:`m-0 text-[13px] font-semibold text-muted`,children:`What people may do`}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5 text-sm text-ink-2`,children:S.actions.map(e=>(0,Q.jsxs)(`li`,{className:`[overflow-wrap:anywhere]`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-ink`,children:e.does}),(0,Q.jsxs)(`span`,{className:`text-muted`,children:[` · `,(0,Q.jsx)(`span`,{className:`font-mono`,children:e.contract}),e.burst>1?` · ×${e.burst} at once`:``,e.who.intents?` · ${e.who.intents.join(`, `)} only`:``,e.who.sides?` · ${e.who.sides.join(`, `)}`:``]})]},e.id))}),S.needs.length>0&&(0,Q.jsx)(`ul`,{"aria-label":`What the plan still needs`,className:`m-0 flex list-disc flex-col gap-1 pl-5 text-[12.5px] text-warn`,children:S.needs.map(e=>(0,Q.jsx)(`li`,{className:`[overflow-wrap:anywhere]`,children:e},e))})]}),C&&C.events.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`sim-log`,className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`h3`,{id:`sim-log`,className:`m-0 text-[13px] font-semibold text-muted`,children:[`Run log`,C.calls>C.events.length?` (the last ${C.events.length} of ${C.calls} calls)`:``]}),(0,Q.jsx)(Bt,{label:`Run log`,children:T})]}),n.interviews.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`sim-interviews`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`sim-interviews`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Interviews`}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`What people of the population say about what they did, as the model tells it: their account, not evidence. The checks above are the evidence.`}),(0,Q.jsx)(`ul`,{"aria-label":`Interviews`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:[...n.interviews].reverse().map(e=>(0,Q.jsxs)(`li`,{className:`flex flex-col gap-1 rounded-[8px] px-3 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-ink`,children:e.name}),` (`,e.persona,`) · `,Kt(e.at),` · asked: `,e.question]}),(0,Q.jsx)(gi,{i:e})]},`${e.member}-${e.at}`))})]}),(0,Q.jsx)(hi,{simulation:S,onSaved:()=>void b()}),a&&(0,Q.jsx)(_i,{simulation:S.id,person:a,onClose:()=>o(null),onAsked:()=>void b()}),(0,Q.jsx)(K,{open:m,onClose:()=>h(!1),title:`Run the calls that change data?`,description:`People of ${S.population}, on ${f||`the test environment`}, through the API's own address only, up to ${M(S.max_calls,`call`)}.`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{variant:`ghost`,onClick:()=>h(!1),children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:g,onClick:()=>void w(n.writes),children:[(0,Q.jsx)(s,{"aria-hidden":`true`}),g?`Running…`:`Run them`]})]}),children:(0,Q.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5 text-sm text-ink-2`,children:n.writes.map(e=>(0,Q.jsx)(`li`,{className:`[overflow-wrap:anywhere]`,children:e},e))})})]})}function hi({simulation:e,onSaved:t}){let[n,r]=(0,Z.useState)(()=>{let{version:t,createdAt:n,...r}=e;return JSON.stringify(r,null,2)}),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),u=async()=>{a(!0),s(``),l(``);let r;try{r=JSON.parse(n)}catch{s(`The plan is not valid JSON.`),a(!1);return}if(r.id!==e.id)s(`Keep the id ${e.id}: a changed id would be another simulation.`),a(!1);else try{await P.planSimulation({simulation:r}),l(`Saved.`),t()}catch(e){s(e.message)}finally{a(!1)}};return(0,Q.jsxs)(`section`,{"aria-labelledby":`sim-plan`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`sim-plan`,className:`m-0 text-[13px] font-semibold text-muted`,children:`The plan`}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`Change the days, the call budget, who may do what and how often (weight, max_per_member, burst), how values are worked out (derive, over $budget and what the person captured), and the checks.`}),(0,Q.jsx)(V,{rows:14,value:n,spellCheck:!1,onChange:e=>r(e.target.value),"aria-labelledby":`sim-plan`,className:`font-mono text-[12.5px]`}),(0,Q.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:(0,Q.jsxs)(j,{disabled:i,onClick:()=>void u(),"data-tip":`Keeps it as .forgeqe/business/simulations/${e.id}.json`,children:[(0,Q.jsx)(oe,{"aria-hidden":`true`}),i?`Saving…`:`Save the plan`]})}),c&&(0,Q.jsx)(`p`,{role:`status`,className:`m-0 rounded-[12px] bg-surface-muted px-3 py-2 text-sm text-ink-2 [overflow-wrap:anywhere]`,children:c}),o&&(0,Q.jsx)(Y,{text:o})]})}function gi({i:e}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`m-0 max-w-[80ch] text-sm leading-relaxed text-ink-2 [overflow-wrap:anywhere]`,children:[`“`,e.answer,`”`]}),(0,Q.jsx)(`span`,{className:e.untied?`text-[12px] text-warn`:`text-[12px] text-muted`,children:e.untied?`It cites none of their calls in the run: not tied to the run.`:`Rests on their calls ${e.cites.map(e=>`#${e}`).join(`, `)}.`})]})}function _i({simulation:e,person:t,onClose:n,onAsked:i}){let[a,o]=(0,Z.useState)(`You broke "${t.says}". Why did you do it?`),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(null),p=async()=>{c(!0),u(``);try{let{interview:n}=await P.interview(e,t.member,a.trim());f(n),i()}catch(e){u(e.message)}finally{c(!1)}};return(0,Q.jsx)(K,{open:!0,onClose:n,title:`Ask ${t.name} why`,description:`One of ${t.persona}. The answer is the model's account as this person, from their persona and their own calls in the latest run: not evidence.`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{variant:`ghost`,onClick:n,children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),d?`Close`:`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:s||!a.trim(),onClick:()=>void p(),children:[(0,Q.jsx)(ee,{"aria-hidden":`true`}),s?`Asking…`:d?`Ask again`:`Ask`]})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Your question`}),(0,Q.jsx)(V,{rows:3,value:a,maxLength:300,onChange:e=>o(e.target.value)})]}),s&&(0,Q.jsxs)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:[t.name,` is answering…`]}),d&&(0,Q.jsxs)(`section`,{"aria-label":`The answer`,className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-[12.5px] font-medium text-muted`,children:`As the model tells it, not evidence`}),(0,Q.jsx)(gi,{i:d})]}),l&&(0,Q.jsx)(Y,{text:l})]})})}var vi=[`agent`,`investigations`,`hypotheses`,`personas`,`simulation`,`model`,`findings`],yi={investigations:`Investigations`,hypotheses:`Hypotheses`,personas:`Personas`,simulation:`Simulation`,model:`Model of the business`,findings:`Findings`},bi={investigations:`Business scenarios played out as personas: what the business intended, what the software did, and the evidence. Run one on a test environment; calls that change data are listed first and sent only once you agree.`,hypotheses:`What real people could make the business lose, give away or treat unfairly, with the personas who would try it. The score weighs impact, how easy it is, and how likely someone tries it. Plan one to make it an investigation.`,personas:`The people a business simulation plays: a population drawn from your personas, mostly legitimate customers, some opportunists, a few insiders, and the staff they deal with, linked by who deals with whom.`,simulation:`A population playing everyday trading on a test environment over simulated days, each person in their own hours, and checks of the whole population and of each person, naming who broke them.`,model:`How the business works, as read from the product's code: what was read as written is observed; what it means is inferred, and still to be confirmed by a run or a person.`,findings:`Every investigation's latest outcome, ranked by what the business could lose, written for the people who act on it.`},xi=e=>e===`agent`?I(`agents`,`business`):I(`agents`,`business`,e),Si=e=>I(`agents`,`business`,`investigations`,encodeURIComponent(e)),Ci=({outcome:e,label:t})=>(0,Q.jsx)(F,{tone:ai[e],children:t});function wi({page:e,tab:t,sub:n}){let r=vi.includes(t)?t:`agent`,i=r===`investigations`&&n?Ee(n):``,[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(()=>new Set([r]));(0,Z.useEffect)(()=>{u(e=>e.has(r)?e:new Set([...e,r]))},[r]);let d=()=>P.view().then(e=>{o(e),c(``)},e=>c(`The business model did not load: ${e.message}`));(0,Z.useEffect)(()=>{d()},[]);let f=(a?.investigations||[]).filter(e=>e.outcome===`confirmed_failure`).length,p={agent:`Agent`,investigations:`Investigations`,hypotheses:`Hypotheses`,personas:`Personas`,simulation:`Simulation`,model:`Model`,findings:f?`Findings · ${f}`:`Findings`},m=a?{investigations:a.investigations.length,hypotheses:a.hypotheses.length}:{},h=(0,Q.jsx)(Ft,{label:`Business assurance agent`,current:r,onPick:e=>location.hash=xi(e),tabs:vi.map(e=>({id:e,label:p[e],...m[e]===void 0?{}:{n:m[e]}})),className:`mb-0`}),g=(e,t)=>l.has(e)?(0,Q.jsxs)(`div`,{role:`tabpanel`,id:`panel-${e}`,"aria-labelledby":`tab-${e}`,hidden:r!==e,className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(Ie,{pixel:Ze.business,size:`lg`}),(0,Q.jsx)(`h1`,{className:`m-0 text-[26px] font-semibold tracking-[-0.01em]`,children:yi[e]})]}),!(e===`investigations`&&i)&&!(e===`simulation`&&r===`simulation`&&n)&&(0,Q.jsx)(`p`,{className:`m-0 max-w-[80ch] text-[13px] leading-relaxed text-ink-2`,children:bi[e]}),s&&e!==`findings`&&e!==`personas`&&e!==`simulation`&&(0,Q.jsx)(Y,{text:s}),!a&&!s&&e!==`findings`&&e!==`personas`&&e!==`simulation`?(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`}):t]},e):null;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{role:`tabpanel`,id:`panel-agent`,"aria-labelledby":`tab-agent`,hidden:r!==`agent`,children:(0,Q.jsx)(At,{agent:e,below:(0,Q.jsx)(Ii,{page:e}),tabs:h})}),r!==`agent`&&(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-1 px-5 py-3.5 short:py-2`,children:[(0,Q.jsx)(nt,{}),(0,Q.jsxs)(`a`,{href:I(`agents`),className:`inline-flex min-h-9 items-center gap-1.5 text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),`All agents`]}),(0,Q.jsx)(`div`,{className:`ml-auto`,children:h})]}),(0,Q.jsxs)(`main`,{className:A(`mx-auto box-border flex w-full max-w-[1180px] flex-col px-6 pt-8 pb-10 md:px-12 short:pt-5 short:pb-6`,`@container flex-auto gap-4 pt-2`),children:[g(`investigations`,a&&(i?(0,Q.jsx)(Di,{id:i,environments:a.environments,onChanged:()=>void d()},i):(0,Q.jsx)(Ti,{view:a}))),g(`hypotheses`,a&&(0,Q.jsx)(Ei,{view:a,onPlanned:e=>void d().then(()=>location.hash=Si(e))})),g(`personas`,(0,Q.jsx)(ni,{})),g(`simulation`,(0,Q.jsx)(fi,{opened:r===`simulation`&&n?Ee(n):``,environments:a?.environments||[]})),g(`model`,a&&(0,Q.jsx)(Mi,{view:a,onRebuilt:o})),g(`findings`,(0,Q.jsx)(Ni,{}))]})]})]})}function Ti({view:e}){return e.investigations.length?(0,Q.jsx)(`ul`,{"aria-label":`Investigations`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:e.investigations.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`a`,{href:Si(e.id),className:`flex min-h-11 items-center gap-3 rounded-[8px] px-3 py-1.5 text-ink no-underline hover:bg-surface-muted hover:text-ink`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`truncate text-[14px] font-medium`,"data-tip":e.title,children:e.title}),(0,Q.jsxs)(`span`,{className:`truncate text-[12.5px] text-muted`,children:[(0,Q.jsx)(`span`,{className:`font-mono`,children:e.id}),` · `,e.personas.join(`, `)||`no persona`,` · `,M(e.steps,`step`),e.needs?` · needs ${e.needs}`:``,e.pending?` · ${e.pending} pending`:``,e.problem?` · ${e.problem}`:``]})]}),e.outcome&&e.label?(0,Q.jsx)(Ci,{outcome:e.outcome,label:e.label}):(0,Q.jsx)(`span`,{className:`flex-none text-[12.5px] text-muted`,children:`Not run`})]})},e.id))}):(0,Q.jsx)(z,{icon:ge,title:`No investigation yet`,action:(0,Q.jsxs)(`a`,{className:U({size:`sm`}),href:I(`agents`,`business`,`hypotheses`),"data-tip":`Open the hypotheses`,children:[(0,Q.jsx)(se,{"aria-hidden":`true`}),`Hypotheses`]}),children:`Plan one from a hypothesis, or ask the agent on its Agent tab to investigate what worries you.`})}function Ei({view:e,onPlanned:n}){let[r,i]=(0,Z.useState)(`all`),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``);if(e.contextProblem&&!e.hypotheses.length)return(0,Q.jsx)(z,{icon:t,title:`No model of the business yet`,action:(0,Q.jsxs)(`a`,{className:U({size:`sm`}),href:I(`agents`,`business`,`model`),"data-tip":`Open the model of the business`,children:[(0,Q.jsx)(se,{"aria-hidden":`true`}),`Model`]}),children:e.contextProblem});let d=[...new Set(e.hypotheses.map(e=>e.area))],f=a.toLowerCase().split(/\s+/).filter(Boolean),p=e.hypotheses.filter(e=>(r===`all`||e.area===r)&&f.every(t=>`${e.question} ${e.capability} ${e.personas.join(` `)} ${e.id}`.toLowerCase().includes(t))),m=async e=>{c(e),u(``);try{let t=await P.plan({hypothesis:e});if(!t.saved){u(`Not planned: ${t.needs.join(` `)}`),c(``);return}n(t.id)}catch(e){u(e.message),c(``)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(Oe,{id:`hypothesis-find`,label:`Find a hypothesis`,value:a,onChange:o}),(0,Q.jsx)(Fe,{items:[{id:`all`,label:`All`,n:e.hypotheses.length},...d.map(t=>({id:t,label:oi[t]||t,n:e.hypotheses.filter(e=>e.area===t).length}))],value:r,onChange:i})]}),l&&(0,Q.jsx)(Y,{text:l}),p.length===0?(0,Q.jsx)(z,{className:`py-4`,children:e.hypotheses.length?`No hypothesis matches.`:`No hypothesis yet: the model of the business has nothing to question.`}):(0,Q.jsx)(`ul`,{"aria-label":`Hypotheses`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:p.map(e=>(0,Q.jsxs)(`li`,{className:`flex min-h-11 items-center gap-3 rounded-[8px] px-3 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium [overflow-wrap:anywhere]`,children:e.question}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:[oi[e.area]||e.area,` · `,e.capability,` · as `,e.personas.join(`, `)||`nobody yet`,e.by===`model`?` · from the Scenario Strategist`:``]}),e.needsPersona&&(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-warn`,children:[`Needs a persona: `,e.needsPersona,`. `,(0,Q.jsx)(`a`,{href:I(`agents`,`persona`,`new`),children:`Make one`})]})]}),(0,Q.jsx)(`span`,{className:`flex-none text-[12.5px] text-muted tabular-nums`,"data-tip":`Impact × how easy × how likely, each out of 5`,children:e.score}),e.planned?(0,Q.jsxs)(`a`,{href:Si(e.id),className:U({size:`sm`}),"data-tip":`It is planned: open the investigation`,children:[(0,Q.jsx)(ae,{"aria-hidden":`true`}),`Open`]}):(0,Q.jsxs)(j,{size:`sm`,disabled:!!s||!e.personas.length,onClick:()=>void m(e.id),"data-tip":e.personas.length?`Make it an investigation you can run`:`It needs a persona first`,children:[(0,Q.jsx)(ge,{"aria-hidden":`true`}),s===e.id?`Planning…`:`Plan`]})]},e.id))})]})}function Di({id:e,environments:t,onChanged:n}){let[i,a]=(0,Z.useState)(null),[o,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(``),y=()=>P.investigation(e).then(e=>{a(e),f(n=>n||e.investigation.environment||t[0]||``),c(``)},e=>c(`The investigation did not load: ${e.message}`));(0,Z.useEffect)(()=>{y()},[e]);let b=(0,Q.jsxs)(`a`,{href:I(`agents`,`business`,`investigations`),className:`inline-flex items-center gap-1.5 self-start text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),`Every investigation`]});if(o&&!i)return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[b,(0,Q.jsx)(Y,{text:o})]});if(!i)return(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`});let x=i.investigation,C=i.run,w=async e=>{m(!0),u(``);try{await P.run(x.id,e,d||void 0),g(!1),await y(),n()}catch(e){u(e.message)}finally{m(!1)}},T=e=>C?.results.find(t=>t.id===e);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[b,(0,Q.jsx)(`h2`,{className:`m-0 text-[18px] font-semibold`,children:x.title}),(0,Q.jsxs)(`p`,{className:`m-0 text-[13px] text-muted`,children:[(0,Q.jsx)(`span`,{className:`font-mono`,children:x.id}),` · as `,x.personas.join(`, `),` · `,M(x.steps.length,`step`),x.hypothesis?` · from hypothesis ${x.hypothesis}`:``]}),x.question!==x.title&&(0,Q.jsx)(`p`,{className:`m-0 max-w-[72ch] text-sm leading-relaxed text-ink-2`,children:x.question})]}),o&&(0,Q.jsx)(Y,{text:o}),(0,Q.jsxs)(`section`,{"aria-labelledby":`business-run`,className:`flex flex-col gap-3 rounded-[14px] card border p-4`,children:[(0,Q.jsx)(`h3`,{id:`business-run`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Run it`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Test environment`}),(0,Q.jsxs)(B,{value:d,onChange:e=>f(e.target.value),disabled:!t.length,children:[!t.length&&(0,Q.jsx)(`option`,{value:``,children:`No test environment in env.yaml`}),t.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))]})]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:p||!t.length,onClick:()=>i.writes.length?g(!0):void w([]),"data-tip":i.writes.length?`Shows the calls that change data before any is sent`:`Sends the plan's API calls as its personas`,children:[(0,Q.jsx)(s,{"aria-hidden":`true`}),p?`Running…`:`Run`]})]}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted`,children:`API steps are sent by ForgeQE, only to the API's own address on this environment; never on one named like production. Browser and person steps stay pending: ask the agent (its Agent tab) to do them as the personas, or say below what each showed.`}),l&&(0,Q.jsx)(Y,{text:l}),C&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(Ci,{outcome:C.outcome,label:C.label}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[`Confidence `,C.confidence,` · `,Kt(C.at),C.environment?` on ${C.environment}`:``]})]}),(0,Q.jsx)(`p`,{className:`m-0 max-w-[80ch] text-sm text-ink-2 [overflow-wrap:anywhere]`,children:C.why})]})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`business-expect`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`business-expect`,className:`m-0 text-[13px] font-semibold text-muted`,children:`What the business intended`}),x.oracles.length===0?(0,Q.jsx)(z,{className:`py-3`,children:`The plan says nothing the business intended, so no outcome can be judged. Add expectations in the plan below.`}):(0,Q.jsx)(`ul`,{"aria-label":`Expectations`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:x.oracles.map(e=>{let t=T(e.id),n=i.decisions.filter(t=>t.says===e.says).pop();return(0,Q.jsxs)(`li`,{className:`flex min-h-11 items-center gap-3 rounded-[8px] px-3 py-1.5`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium [overflow-wrap:anywhere]`,children:e.says}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:[e.basis===`policy`?`Policy`:e.basis===`code_rule`?`A rule the code enforces elsewhere`:e.basis===`persona`?`A persona's check`:`An assumption to confirm`,n?` · decided: ${n.decision?.replace(`_`,` `)} (${n.reason})`:``,t?` · ${t.detail}`:``]})]}),t&&(0,Q.jsx)(F,{tone:t.status===`held`?`pass`:t.status===`violated`?`fail`:`neutral`,children:t.status===`held`?`Held`:t.status===`violated`?`Broken`:`Not known`}),(0,Q.jsxs)(j,{size:`sm`,onClick:()=>v(e.id),"data-tip":`Record whether this is the business's policy`,children:[(0,Q.jsx)(S,{"aria-hidden":`true`}),`Decide`]})]},e.id)})})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`business-steps`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`business-steps`,className:`m-0 text-[13px] font-semibold text-muted`,children:`The scenario`}),(0,Q.jsx)(`ol`,{className:`m-0 flex list-decimal flex-col gap-1 pl-5 text-sm text-ink-2`,children:x.steps.map(e=>(0,Q.jsxs)(`li`,{className:`[overflow-wrap:anywhere]`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-ink`,children:e.actor}),`: `,e.does,(0,Q.jsxs)(`span`,{className:`text-muted`,children:[` · `,e.channel===`api`?(0,Q.jsx)(`span`,{className:`font-mono`,children:e.api?.contract}):e.channel,e.repeat>1?` · ×${e.repeat}${e.concurrent?` at the same moment`:``}`:``]})]},e.n))}),x.needs.length>0&&(0,Q.jsx)(`ul`,{"aria-label":`What the plan still needs`,className:`m-0 flex list-disc flex-col gap-1 pl-5 text-[12.5px] text-warn`,children:x.needs.map(e=>(0,Q.jsx)(`li`,{className:`[overflow-wrap:anywhere]`,children:e},e))})]}),C&&C.pending.length>0&&(0,Q.jsx)(Oi,{id:x.id,run:C,steps:x.steps,onSaved:()=>void y().then(n)}),C&&C.observations.length>0&&(0,Q.jsx)(ki,{run:C}),(0,Q.jsx)(Ai,{investigation:x,onSaved:()=>void y().then(n)}),(0,Q.jsx)(K,{open:h,onClose:()=>g(!1),title:`Run the calls that change data?`,description:`As the investigation's personas, on ${d||`the test environment`}, through the API's own address only.`,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{variant:`ghost`,onClick:()=>g(!1),children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:p,onClick:()=>void w(i.writes),children:[(0,Q.jsx)(s,{"aria-hidden":`true`}),p?`Running…`:`Run them`]})]}),children:(0,Q.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5 text-sm text-ink-2`,children:i.writes.map(e=>(0,Q.jsx)(`li`,{className:`[overflow-wrap:anywhere]`,children:e},e))})}),_&&(0,Q.jsx)(ji,{id:x.id,expectation:x.oracles.find(e=>e.id===_),onClose:()=>v(``),onDecided:()=>(v(``),void y().then(n))})]})}function Oi({id:e,run:t,steps:n,onSaved:r}){let[a,o]=(0,Z.useState)({}),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(``),d=e=>a[e]||{result:``,values:``,note:``},f=(e,t)=>o({...a,[e]:{...d(e),...t}}),p=t.pending.filter(e=>d(e).result||d(e).values.trim()||d(e).note.trim()),m=async()=>{c(!0),u(``);try{await P.observe(e,p.map(e=>{let t=d(e);return{step:e,channel:`person`,...t.result===`accepted`?{accepted:!0,refused:!1}:t.result===`refused`?{refused:!0,accepted:!1}:{},values:li(t.values),...t.note.trim()?{note:t.note.trim()}:{}}})),o({}),r()}catch(e){u(e.message)}finally{c(!1)}};return(0,Q.jsxs)(`section`,{"aria-labelledby":`business-pending`,className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`h3`,{id:`business-pending`,className:`m-0 text-[13px] font-semibold text-muted`,children:`What the pending steps showed`}),t.pending.map(e=>{let t=n.find(t=>t.n===e);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-[12px] card border p-3`,children:[(0,Q.jsxs)(`p`,{className:`m-0 text-sm text-ink-2 [overflow-wrap:anywhere]`,children:[(0,Q.jsxs)(`span`,{className:`font-medium text-ink`,children:[`Step `,e]}),` · `,t?.actor,`: `,t?.does]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`What happened`}),(0,Q.jsxs)(B,{value:d(e).result,onChange:t=>f(e,{result:t.target.value}),children:[(0,Q.jsx)(`option`,{value:``,children:`Not known`}),(0,Q.jsx)(`option`,{value:`accepted`,children:`The app let them do it`}),(0,Q.jsx)(`option`,{value:`refused`,children:`The app refused it`})]})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Values seen`}),(0,Q.jsx)(N,{value:d(e).values,maxLength:400,spellCheck:!1,onChange:t=>f(e,{values:t.target.value}),placeholder:`refunded=60, status=shipped`,className:`font-mono`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Note`}),(0,Q.jsx)(N,{value:d(e).note,maxLength:300,onChange:t=>f(e,{note:t.target.value}),placeholder:`The order page showed Shipped`})]})]})]},e)}),(0,Q.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:(0,Q.jsxs)(j,{disabled:s||!p.length,onClick:()=>void m(),"data-tip":`Adds what you saw to the latest run and judges it again`,children:[(0,Q.jsx)(i,{"aria-hidden":`true`}),s?`Saving…`:`Save what they showed`]})}),l&&(0,Q.jsx)(Y,{text:l})]})}function ki({run:e}){return(0,Q.jsxs)(`section`,{"aria-labelledby":`business-observed`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`business-observed`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Evidence`}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5 text-[12.5px] text-ink-2`,children:e.observations.map(e=>(0,Q.jsxs)(`li`,{className:`[overflow-wrap:anywhere]`,children:[`Step `,e.step,e.attempt>1?` #${e.attempt}`:``,` (`,e.channel,`, `,e.actor,`): `,e.error?`not done: ${e.error}`:e.accepted?`accepted`:e.refused?`refused`:`outcome not known`,e.status?`, HTTP ${e.status}`:``,Object.keys(e.values).length?(0,Q.jsx)(`span`,{className:`font-mono`,children:` · ${Object.entries(e.values).map(([e,t])=>`${e}=${String(t)}`).join(`, `)}`}):null,e.note?` · ${e.note}`:``,e.anomaly?(0,Q.jsx)(`span`,{className:`text-warn`,children:` · ${e.anomaly}`}):null]},`${e.step}-${e.attempt}-${e.channel}`))})]})}function Ai({investigation:e,onSaved:t}){let[n,r]=(0,Z.useState)(()=>JSON.stringify(ci(e),null,2)),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),u=async()=>{a(!0),s(``),l(``);let r;try{r=JSON.parse(n)}catch{s(`The plan is not valid JSON.`),a(!1);return}if(r.id!==e.id)s(`Keep the id ${e.id}: a changed id would be another investigation.`),a(!1);else try{let e=await P.plan({investigation:r});l(e.needs.length?`Saved. It still needs: ${e.needs.join(` `)}`:`Saved.`),t()}catch(e){s(e.message)}finally{a(!1)}};return(0,Q.jsxs)(`section`,{"aria-labelledby":`business-plan`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h3`,{id:`business-plan`,className:`m-0 text-[13px] font-semibold text-muted`,children:`The plan`}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[`Fill in what it needs: inputs (test data, never a credential), each API step's body, and where its answer holds a value (capture). `,`{{name}}`,` takes an input or a captured value.`]}),(0,Q.jsx)(V,{rows:14,value:n,spellCheck:!1,onChange:e=>r(e.target.value),"aria-labelledby":`business-plan`,className:`font-mono text-[12.5px]`}),(0,Q.jsx)(`div`,{className:`flex flex-wrap items-center gap-3`,children:(0,Q.jsxs)(j,{disabled:i,onClick:()=>void u(),"data-tip":`Keeps it as .forgeqe/business/investigations/${e.id}.json`,children:[(0,Q.jsx)(oe,{"aria-hidden":`true`}),i?`Saving…`:`Save the plan`]})}),c&&(0,Q.jsx)(`p`,{role:`status`,className:`m-0 rounded-[12px] bg-surface-muted px-3 py-2 text-sm text-ink-2 [overflow-wrap:anywhere]`,children:c}),o&&(0,Q.jsx)(Y,{text:o})]})}function ji({id:e,expectation:t,onClose:n,onDecided:i}){let[a,o]=(0,Z.useState)(`policy`),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(``),h=async()=>{f(!0),m(``);try{await P.decide({id:e,typed:l,expectation:t.id,decision:a,reason:s.trim()}),i()}catch(e){m(e.message),f(!1)}};return(0,Q.jsx)(K,{open:!0,onClose:n,title:`Is this the business's policy?`,description:t.says,footer:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(j,{variant:`ghost`,onClick:n,children:[(0,Q.jsx)(r,{"aria-hidden":`true`}),`Cancel`]}),(0,Q.jsxs)(j,{variant:`primary`,disabled:d||l!==e||!s.trim(),onClick:()=>void h(),children:[(0,Q.jsx)(S,{"aria-hidden":`true`}),d?`Recording…`:`Record it`]})]}),children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Decision`}),(0,Q.jsxs)(B,{value:a,onChange:e=>o(e.target.value),children:[(0,Q.jsx)(`option`,{value:`policy`,children:`It is policy: breaking it is a failure`}),(0,Q.jsx)(`option`,{value:`permitted`,children:`The behaviour is permitted`}),(0,Q.jsx)(`option`,{value:`not_policy`,children:`It is not the business's policy`})]})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`Reason`}),(0,Q.jsx)(N,{value:s,maxLength:300,onChange:e=>c(e.target.value),placeholder:`Operations confirmed: cancelled orders never ship`})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Q.jsxs)(`span`,{children:[`Type `,(0,Q.jsx)(`span`,{className:`font-mono`,children:e}),` to confirm`]}),(0,Q.jsx)(N,{value:l,onChange:e=>u(e.target.value),autoComplete:`off`,spellCheck:!1})]}),p&&(0,Q.jsx)(Y,{text:p})]})})}function Mi({view:e,onRebuilt:n}){let[r,i]=(0,Z.useState)(!1),[a,o]=(0,Z.useState)(``),s=e.context,c=async()=>{i(!0),o(``);try{n(await P.rebuild())}catch(e){o(e.message)}finally{i(!1)}},l=s?[[`business-capabilities`,`Capabilities`,s.capabilities.map(e=>`${e.label}: ${M(e.transactions,`transaction`)}`)],[`business-processes`,`Processes`,s.processes.map(e=>`${e.name}${e.basis===`inferred`?` (inferred)`:``}`)],[`business-rules`,`Rules the code enforces`,s.rules.map(e=>`${e.text}${e.where?` — ${e.where}`:``}`)],[`business-states`,`Record states`,s.states.map(e=>`${e.record}: ${e.states.join(`, `)}`)],[`business-data`,`Personal data`,s.data.map(e=>`${e.table}: ${e.columns.join(`, `)}`)],[`business-risks`,`Exposures to investigate (inferred)`,s.risks.map(e=>`${oi[e.area]||e.area}: ${e.title}`)],[`business-assumptions`,`Assumptions to confirm`,s.assumptions.map(e=>e.text)]]:[];return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`m-0 text-[13px] text-muted`,children:s?`${s.product}, read ${Kt(s.builtAt)} from the product knowledge graph: ${M(s.transactions,`transaction`)}.`:`Not read yet.`}),(0,Q.jsxs)(j,{size:`sm`,disabled:r,onClick:()=>void c(),"data-tip":`Read the product graph again`,children:[(0,Q.jsx)(h,{"aria-hidden":`true`}),r?`Reading…`:`Read again`]})]}),a&&(0,Q.jsx)(Y,{text:a}),e.contextProblem&&!s&&(0,Q.jsx)(z,{icon:t,title:`Not read yet`,children:e.contextProblem}),l.filter(([,,e])=>e.length).map(([e,t,n])=>(0,Q.jsxs)(`section`,{"aria-labelledby":e,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:e,className:`m-0 text-[13px] font-semibold text-muted`,children:t}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-disc flex-col gap-1 pl-5 text-sm text-ink-2`,children:n.map((e,t)=>(0,Q.jsx)(`li`,{className:`[overflow-wrap:anywhere]`,children:e},`${t}-${e}`))})]},e))]})}function Ni(){let[e,t]=(0,Z.useState)(`executive`),[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(``);return(0,Z.useEffect)(()=>{r(null),P.report(e).then(e=>(r(e.markdown),a(``)),e=>a(`The report did not load: ${e.message}`))},[e]),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,Q.jsx)(Fe,{items:Ce.map(e=>({id:e,label:si[e]})),value:e,onChange:t})}),i&&(0,Q.jsx)(Y,{text:i}),n===null&&!i?(0,Q.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted`,children:`Loading…`}):n===null?null:(0,Q.jsx)(`div`,{className:`max-w-[88ch] rounded-[12px] card border p-4`,children:(0,Q.jsx)(gt,{text:n})})]})}var Pi=5;function Fi({id:e}){if(!e)return(0,Q.jsx)(gn,{});let[t,n,r,...i]=e.split(`/`);if(t===`custom`&&n===`new`&&r===`template`&&i.length===1&&/^[a-z][a-z0-9-]{0,39}$/.test(i[0]))return(0,Q.jsx)(ir,{template:i[0]},i[0]);if(t===`custom`&&!i.length){if(n===`new`&&r===void 0)return(0,Q.jsx)(bn,{});if(n===`new`&&r===`form`)return(0,Q.jsx)(ir,{});if(n===`build`&&r&&/^[a-f0-9]{16}$/.test(r))return(0,Q.jsx)(Sn,{sid:r},r);if(n&&Ke.test(n)&&r===void 0)return(0,Q.jsx)(Pn,{id:n},n);if(n&&Ke.test(n)&&r===`edit`)return(0,Q.jsx)(ir,{id:n},n)}let[a,o,...s]=(e||``).split(`/`),c=Re(a);if(c?.id===`db`&&o!==`tools`)return(0,Q.jsx)(At,{agent:c,wide:(0,Q.jsx)(wr,{page:c,tab:o,sub:s.join(`/`)})},c.id);if(c?.id===`persona`&&o===void 0)return(0,Q.jsx)(At,{agent:c,tabs:(0,Q.jsx)(kr,{current:`agent`})},c.id);if(c?.id===`persona`&&o!==`tools`)return(0,Q.jsx)(Nr,{page:c,tab:o,sub:s.join(`/`)},`${c.id}/${o}`);if(c?.id===`business`&&o!==`tools`)return(0,Q.jsx)(wi,{page:c,tab:o,sub:s.join(`/`)},c.id);let l=a===`category`&&!s.length?qe(o):void 0;return l?(0,Q.jsx)(gn,{only:l.id},l.id):c&&o===`tools`&&!s.length?(0,Q.jsx)(Vi,{page:c},c.id):!c||o!==void 0?(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsx)(ct,{}),(0,Q.jsxs)(`p`,{className:`m-0 px-6 py-10 text-sm text-muted`,children:[`There is no such agent. `,(0,Q.jsx)(`a`,{href:I(`agents`),children:`See every agent`}),`, or `,(0,Q.jsx)(`a`,{href:I(),children:`start a chat`}),` instead.`]})]}):(0,Q.jsx)(At,{agent:c,below:(0,Q.jsx)(Ii,{page:c})},c.id)}function Ii({page:e}){let[t,n]=(0,Z.useState)(null),[r,i]=(0,Z.useState)([]),[a,o]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{let t=!1;return _e.directory().then(n=>!t&&u(n.agents[e.agent]??null),()=>{}),_e.tools(e.agent).then(e=>!t&&o(e),e=>!t&&c(e.message)),Se.list().then(r=>!t&&n(r.runs.filter(t=>t.agents.some(t=>e.runs.includes(t.name))).slice(0,Pi)),()=>!t&&n([])),xe.prompts().then(n=>!t&&i(n.agents.filter(t=>e.runs.includes(t.name))),()=>{}),()=>{t=!0}},[e]);let d=st(e.agent).name,f=[...new Set(r.map(e=>e.prompt))];return(0,Q.jsxs)(`div`,{className:`flex w-full flex-col gap-6 pt-2`,children:[l&&l.status!==`ready`&&(0,Q.jsx)(Ri,{card:l,name:d}),(0,Q.jsxs)(`section`,{"aria-labelledby":`agent-tools`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`agent-tools`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Tools it can use`}),s?(0,Q.jsx)(`p`,{className:`m-0 text-sm text-fail`,children:s}):a?(0,Q.jsx)(Hi,{view:a,limit:Pi,more:I(`agents`,e.id,`tools`)}):(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`Reading its tools…`})]}),a&&a.connections.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`agent-connected`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`agent-connected`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Connected to`}),(0,Q.jsx)(Bi,{list:a.connections,limit:4,more:I(`agents`,e.id,`tools`)})]}),e.prompt!==!1&&(0,Q.jsxs)(`section`,{"aria-labelledby":`agent-prompt`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`agent-prompt`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Its instructions`}),(0,Q.jsxs)(`a`,{href:I(`prompts`),className:`flex items-center gap-3 rounded-[12px] card border px-4 py-3 text-ink no-underline hover:bg-surface-muted hover:text-ink`,children:[(0,Q.jsx)(L,{icon:re,size:18,className:`flex-none text-muted`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium`,children:f.length?f.map(e=>`${e}.md`).join(`, `):`The prompt it starts from`}),(0,Q.jsxs)(`span`,{className:`text-[12.5px] text-muted`,children:[`What `,W(d),` starts with, and your team's additions: change them in Prompts.`]})]}),(0,Q.jsx)(se,{size:16,"aria-hidden":`true`,className:`flex-none text-muted`})]})]}),(0,Q.jsxs)(`section`,{"aria-labelledby":`agent-runs`,className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsx)(`h2`,{id:`agent-runs`,className:`m-0 flex-1 text-[13px] font-semibold text-muted`,children:`Recent runs`}),(0,Q.jsx)(`a`,{href:I(`runs`),className:`text-[13px]`,children:`All runs`})]}),t===null?(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`Reading the runs…`}):t.length===0?(0,Q.jsxs)(z,{className:`py-4`,children:[W(d,!0),` has not worked in this project yet.`]}):(0,Q.jsx)(`ul`,{"aria-label":`${W(d,!0)}'s recent runs`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-1.5`,children:t.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`a`,{href:I(`runs`,encodeURIComponent(e.name)),className:`flex min-h-11 items-center gap-3 rounded-[8px] px-3 py-1.5 text-ink no-underline hover:bg-surface-muted hover:text-ink`,children:[(0,Q.jsx)(qt,{status:e.status}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`truncate text-[14px] font-medium`,"data-tip":e.title,children:e.title}),e.error&&(0,Q.jsx)(`span`,{className:`truncate text-[12px] text-fail`,children:e.error})]}),(0,Q.jsx)(`span`,{className:`flex-none text-[12.5px] text-muted tabular-nums`,children:Ot(e.startedAt)})]})},e.name))})]})]})}var Li={setup:{to:I(`settings`,`setup`),label:`Settings, Set up`},models:{to:I(`settings`,`models`),label:`Settings, Models`},tests:{to:I(`settings`,`tests`),label:`Settings, Code`},databases:{to:I(`settings`,`databases`),label:`Settings, Databases`},integrations:{to:I(`settings`,`integrations`),label:`Settings, Integrations`},features:{to:I(`settings`,`features`),label:`What's ready`}};function Ri({card:e,name:n}){let r=Zt[e.status],i=e.needs??[];return(0,Q.jsxs)(`section`,{"aria-labelledby":`agent-needs`,className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h2`,{id:`agent-needs`,className:`m-0 text-[13px] font-semibold text-muted`,children:`What it needs`}),(0,Q.jsx)(F,{tone:r.tone,children:r.label})]}),i.length===0?(0,Q.jsx)(`p`,{className:`m-0 rounded-[12px] bg-surface-muted px-4 py-3 text-sm text-ink-2`,children:e.note}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:i.some(e=>e.blocks)?`${W(n,!0)} cannot work until the first ${i.filter(e=>e.blocks).length===1?`one is`:`ones are`} set up.`:`${W(n,!0)} works, without the parts below.`}),(0,Q.jsx)(`ul`,{"aria-label":`What ${W(n)} needs`,className:`m-0 flex list-none flex-col rounded-[12px] card border p-0`,children:i.map((e,n)=>(0,Q.jsxs)(`li`,{className:A(`flex items-center gap-3 px-3 py-2.5`,n>0&&`border-t border-line-soft`),children:[(0,Q.jsx)(t,{size:16,"aria-label":e.blocks?`Needed`:`Optional`,className:A(`flex-none`,e.blocks?`text-fail`:`text-warn`)}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`text-[14px] font-medium`,children:e.what}),(0,Q.jsx)(`span`,{className:`text-[12.5px] text-muted [overflow-wrap:anywhere]`,children:e.why})]}),e.fix&&(0,Q.jsxs)(`a`,{href:Li[e.fix].to,className:`flex flex-none items-center gap-1 text-[13px]`,children:[Li[e.fix].label,(0,Q.jsx)(se,{size:14,"aria-hidden":`true`})]})]},`${e.what}:${n}`))})]})]})}var zi={repository:`branch`,database:`container`,environment:`web`,system:`plug`};function Bi({list:e,limit:t,more:n}){let r=t?e.slice(0,t):e;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`ul`,{className:`m-0 grid list-none grid-cols-1 gap-2 p-0 sm:grid-cols-2`,children:r.map((e,t)=>(0,Q.jsxs)(`li`,{className:A(`flex items-center gap-3 rounded-[12px] card border px-3 py-2.5`,!e.on&&`bg-surface-muted`),children:[(0,Q.jsx)(Te,{name:zi[e.kind],px:22,className:A(!e.on&&`opacity-50 grayscale`)}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsx)(`span`,{className:`truncate text-[14px] font-medium`,"data-tip":e.name,children:e.name}),(0,Q.jsx)(`span`,{className:`truncate text-[12.5px] text-muted`,children:e.on?e.detail:`Not connected: ${e.why||`not set up`}`})]})]},`${e.kind}:${e.name}:${t}`))}),n&&r.length<e.length&&(0,Q.jsxs)(`a`,{href:n,className:`self-start text-[13px]`,children:[`Show all `,e.length,` connections`]})]})}function Vi({page:e}){let[t,n]=(0,Z.useState)(null),[r,i]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{let t=!1;return _e.tools(e.agent).then(e=>!t&&n(e),e=>!t&&i(e.message)),()=>{t=!0}},[e]);let a=st(e.agent).name;return(0,Q.jsxs)(`div`,{className:`flex min-h-(--screen) flex-col`,children:[(0,Q.jsx)(ct,{}),(0,Q.jsxs)(`main`,{className:dt,children:[(0,Q.jsxs)(`a`,{href:I(`agents`,e.id),className:`mb-4 inline-flex items-center gap-1.5 text-sm`,children:[(0,Q.jsx)(O,{size:16,"aria-hidden":`true`}),a]}),(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-3`,children:[(0,Q.jsx)(`span`,{"aria-hidden":`true`,className:`theme-side inline-flex size-10 border border-line-soft flex-none items-center justify-center rounded-[10px]`,children:(0,Q.jsx)(He,{agent:e.agent,px:24,decorative:!0})}),(0,Q.jsxs)(`h1`,{className:`m-0 text-[26px] font-semibold tracking-[-0.01em]`,children:[`What `,W(a),` can use`]})]}),(0,Q.jsxs)(`p`,{className:`mt-1 mb-6 max-w-[64ch] text-sm leading-relaxed text-ink-2`,children:[t?`${t.title.replace(/\.$/,``)}.`:e.about,` Every tool it has, in the groups its session is given, and what it reaches from this project.`]}),r?(0,Q.jsx)(`p`,{className:`m-0 text-sm text-fail`,children:r}):t?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(`section`,{"aria-labelledby":`all-tools`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`all-tools`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Tools it can use`}),(0,Q.jsx)(Hi,{view:t,openAll:!0})]}),t.connections.length>0&&(0,Q.jsxs)(`section`,{"aria-labelledby":`all-connected`,className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`h2`,{id:`all-connected`,className:`m-0 text-[13px] font-semibold text-muted`,children:`Connected to`}),(0,Q.jsx)(Bi,{list:t.connections})]})]}):(0,Q.jsx)(`p`,{className:`m-0 text-sm text-muted`,children:`Reading its tools…`})]})]})}function Hi({view:e,limit:t,more:n,openAll:r}){let[i,a]=(0,Z.useState)(()=>r?e.groups.map(e=>e.id):[]),s=t?e.groups.slice(0,t):e.groups,c=e.groups.reduce((e,t)=>e+t.tools.length,0),l=e.groups.filter(e=>e.on).length;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`p`,{className:`m-0 text-[12.5px] text-muted`,children:[l,` of `,e.groups.length,` `,e.groups.length===1?`group`:`groups`,` usable here.`]}),(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-col rounded-[12px] card border p-0`,children:s.map((e,n)=>{let r=i.includes(e.id);return(0,Q.jsxs)(`li`,{className:A(n>0&&`border-t border-line-soft`),children:[(0,Q.jsxs)(`button`,{type:`button`,"aria-expanded":r,"aria-controls":`tools-${n}`,disabled:!e.tools.length,onClick:()=>a(r?i.filter(t=>t!==e.id):[...i,e.id]),className:`flex w-full cursor-pointer items-center gap-3 border-0 bg-transparent px-3 py-2.5 text-left text-ink disabled:cursor-default`,children:[e.on?(0,Q.jsx)(k,{size:16,"aria-label":`Usable`,className:`flex-none text-pass`}):(0,Q.jsx)(u,{size:16,"aria-label":`Not usable here`,className:`flex-none text-muted`}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsxs)(`span`,{className:`text-[14px] font-medium`,children:[e.label,e.tools.length>0&&(0,Q.jsxs)(`span`,{className:`font-normal text-muted`,children:[` · `,e.tools.length]})]}),(0,Q.jsx)(`span`,{className:A(`text-[12.5px] text-muted`,t&&`truncate`),children:e.on?[e.about,e.limited].filter(Boolean).join(` · `):`Not here: ${e.why||`not set up`}`})]}),e.tools.length>0&&(0,Q.jsx)(o,{size:16,"aria-hidden":`true`,className:A(`flex-none text-muted transition-transform duration-200`,r&&`rotate-90`)})]}),(0,Q.jsx)(tt,{open:r,id:`tools-${n}`,children:(0,Q.jsx)(`ul`,{className:`m-0 flex list-none flex-wrap gap-1.5 px-3 pb-3 pl-10`,children:e.tools.map(e=>(0,Q.jsxs)(`li`,{"data-tip":e.what||void 0,className:`rounded-[6px] bg-surface-strong px-2 py-1 font-mono text-[12px] text-ink-2`,children:[e.name,e.what&&(0,Q.jsx)(`span`,{className:`ml-1.5 font-sans text-muted`,children:e.what})]},e.name))})})]},e.id)})}),n&&(s.length<e.groups.length||c>0)&&(0,Q.jsx)(`a`,{href:n,className:`self-start text-[13px]`,children:s.length<e.groups.length?`Show all ${e.groups.length} groups and ${c} tools`:`Show every tool (${c})`})]})}export{Fi as Agent,Ii as AgentDetails};