@oscharko-dev/keiko 0.2.0-beta.2 → 0.2.0-beta.3

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 (125) hide show
  1. package/dist/ui/csp-hashes.json +28 -27
  2. package/dist/ui/static/404.html +1 -1
  3. package/dist/ui/static/_next/static/chunks/258-e3b5ee46b0669967.js +1 -0
  4. package/dist/ui/static/_next/static/chunks/422-4c94c107b90d3ccc.js +1 -0
  5. package/dist/ui/static/_next/static/chunks/app/_not-found/page-c4d800f366186be0.js +1 -0
  6. package/dist/ui/static/_next/static/chunks/app/launch/page-17ca39367f25f372.js +1 -0
  7. package/dist/ui/static/_next/static/chunks/app/layout-0f75a39edc90325d.js +1 -0
  8. package/dist/ui/static/_next/static/chunks/app/local-knowledge/capsule/page-87a2ea239308ed34.js +1 -0
  9. package/dist/ui/static/_next/static/chunks/app/local-knowledge/page-98bb7704fc7fd0ad.js +1 -0
  10. package/dist/ui/static/_next/static/chunks/app/memoriaviva/consolidation/page-f912263f1ee5d2dd.js +1 -0
  11. package/dist/ui/static/_next/static/chunks/app/memoriaviva/detail/page-fa590f135356e0af.js +1 -0
  12. package/dist/ui/static/_next/static/chunks/app/memoriaviva/page-b8555600c1113f14.js +1 -0
  13. package/dist/ui/static/_next/static/chunks/app/memoriaviva/review-queue/page-85cfbeb3598c0a36.js +1 -0
  14. package/dist/ui/static/_next/static/chunks/app/page-2881856ad25d9935.js +1 -0
  15. package/dist/ui/static/_next/static/chunks/{main-app-b52a8fa1d8127a5f.js → main-app-5b043f6c611974ae.js} +1 -1
  16. package/dist/ui/static/_next/static/css/eac94895f3edc5a5.css +1 -0
  17. package/dist/ui/static/index.html +1 -1
  18. package/dist/ui/static/index.txt +4 -4
  19. package/dist/ui/static/launch.html +1 -1
  20. package/dist/ui/static/launch.txt +4 -4
  21. package/dist/ui/static/local-knowledge/capsule.html +1 -1
  22. package/dist/ui/static/local-knowledge/capsule.txt +4 -4
  23. package/dist/ui/static/local-knowledge.html +1 -1
  24. package/dist/ui/static/local-knowledge.txt +4 -4
  25. package/dist/ui/static/manifest.webmanifest +2 -2
  26. package/dist/ui/static/memoriaviva/consolidation.html +1 -1
  27. package/dist/ui/static/memoriaviva/consolidation.txt +4 -4
  28. package/dist/ui/static/memoriaviva/detail.html +1 -1
  29. package/dist/ui/static/memoriaviva/detail.txt +4 -4
  30. package/dist/ui/static/memoriaviva/review-queue.html +1 -1
  31. package/dist/ui/static/memoriaviva/review-queue.txt +4 -4
  32. package/dist/ui/static/memoriaviva.html +1 -1
  33. package/dist/ui/static/memoriaviva.txt +4 -4
  34. package/node_modules/@oscharko-dev/keiko-cli/dist/.tsbuildinfo +1 -1
  35. package/node_modules/@oscharko-dev/keiko-cli/dist/lifecycle.d.ts +2 -0
  36. package/node_modules/@oscharko-dev/keiko-cli/dist/lifecycle.d.ts.map +1 -1
  37. package/node_modules/@oscharko-dev/keiko-cli/dist/lifecycle.js +51 -10
  38. package/node_modules/@oscharko-dev/keiko-cli/dist/ui.d.ts +3 -1
  39. package/node_modules/@oscharko-dev/keiko-cli/dist/ui.d.ts.map +1 -1
  40. package/node_modules/@oscharko-dev/keiko-cli/dist/ui.js +93 -28
  41. package/node_modules/@oscharko-dev/keiko-cli/package.json +1 -1
  42. package/node_modules/@oscharko-dev/keiko-contracts/dist/.tsbuildinfo +1 -1
  43. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts +2 -2
  44. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts.map +1 -1
  45. package/node_modules/@oscharko-dev/keiko-contracts/dist/index.js +1 -1
  46. package/node_modules/@oscharko-dev/keiko-contracts/dist/qualityIntelligence/bffWire.d.ts +15 -0
  47. package/node_modules/@oscharko-dev/keiko-contracts/dist/qualityIntelligence/bffWire.d.ts.map +1 -1
  48. package/node_modules/@oscharko-dev/keiko-contracts/dist/qualityIntelligence/bffWire.js +1 -1
  49. package/node_modules/@oscharko-dev/keiko-contracts/dist/qualityIntelligence/index.d.ts +1 -1
  50. package/node_modules/@oscharko-dev/keiko-contracts/dist/qualityIntelligence/index.d.ts.map +1 -1
  51. package/node_modules/@oscharko-dev/keiko-contracts/package.json +1 -1
  52. package/node_modules/@oscharko-dev/keiko-evaluations/dist/.tsbuildinfo +1 -1
  53. package/node_modules/@oscharko-dev/keiko-evaluations/package.json +1 -1
  54. package/node_modules/@oscharko-dev/keiko-evidence/dist/.tsbuildinfo +1 -1
  55. package/node_modules/@oscharko-dev/keiko-evidence/package.json +1 -1
  56. package/node_modules/@oscharko-dev/keiko-harness/dist/.tsbuildinfo +1 -1
  57. package/node_modules/@oscharko-dev/keiko-harness/package.json +1 -1
  58. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/.tsbuildinfo +1 -1
  59. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/orchestrator.d.ts.map +1 -1
  60. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/orchestrator.js +5 -1
  61. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/parsers/pdf-parser.d.ts.map +1 -1
  62. package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/parsers/pdf-parser.js +3 -1
  63. package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +1 -1
  64. package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +1 -1
  65. package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +1 -1
  66. package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +1 -1
  67. package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +1 -1
  68. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/.tsbuildinfo +1 -1
  69. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/paths.d.ts.map +1 -1
  70. package/node_modules/@oscharko-dev/keiko-memory-vault/dist/paths.js +11 -5
  71. package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +1 -1
  72. package/node_modules/@oscharko-dev/keiko-model-gateway/dist/.tsbuildinfo +1 -1
  73. package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +1 -1
  74. package/node_modules/@oscharko-dev/keiko-quality-intelligence/dist/.tsbuildinfo +1 -1
  75. package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +1 -1
  76. package/node_modules/@oscharko-dev/keiko-sdk/dist/.tsbuildinfo +1 -1
  77. package/node_modules/@oscharko-dev/keiko-sdk/package.json +1 -1
  78. package/node_modules/@oscharko-dev/keiko-security/dist/.tsbuildinfo +1 -1
  79. package/node_modules/@oscharko-dev/keiko-security/package.json +1 -1
  80. package/node_modules/@oscharko-dev/keiko-server/dist/.tsbuildinfo +1 -1
  81. package/node_modules/@oscharko-dev/keiko-server/dist/deps.d.ts.map +1 -1
  82. package/node_modules/@oscharko-dev/keiko-server/dist/deps.js +3 -3
  83. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-handlers.d.ts.map +1 -1
  84. package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-handlers.js +9 -0
  85. package/node_modules/@oscharko-dev/keiko-server/dist/memory-handlers.d.ts +1 -1
  86. package/node_modules/@oscharko-dev/keiko-server/dist/memory-handlers.d.ts.map +1 -1
  87. package/node_modules/@oscharko-dev/keiko-server/dist/memory-handlers.js +6 -5
  88. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/reCheckRoutes.d.ts.map +1 -1
  89. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/reCheckRoutes.js +25 -4
  90. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/runExecution.d.ts.map +1 -1
  91. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/runExecution.js +11 -0
  92. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/runIngestion.d.ts.map +1 -1
  93. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/runIngestion.js +39 -4
  94. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/uiRoutes.d.ts.map +1 -1
  95. package/node_modules/@oscharko-dev/keiko-server/dist/qualityIntelligence/uiRoutes.js +13 -0
  96. package/node_modules/@oscharko-dev/keiko-server/dist/store/paths.d.ts.map +1 -1
  97. package/node_modules/@oscharko-dev/keiko-server/dist/store/paths.js +9 -2
  98. package/node_modules/@oscharko-dev/keiko-server/package.json +1 -1
  99. package/node_modules/@oscharko-dev/keiko-tools/dist/.tsbuildinfo +1 -1
  100. package/node_modules/@oscharko-dev/keiko-tools/package.json +1 -1
  101. package/node_modules/@oscharko-dev/keiko-verification/dist/.tsbuildinfo +1 -1
  102. package/node_modules/@oscharko-dev/keiko-verification/package.json +1 -1
  103. package/node_modules/@oscharko-dev/keiko-workflows/dist/.tsbuildinfo +1 -1
  104. package/node_modules/@oscharko-dev/keiko-workflows/dist/qualityIntelligence/modelRoutedTestDesign.d.ts.map +1 -1
  105. package/node_modules/@oscharko-dev/keiko-workflows/dist/qualityIntelligence/modelRoutedTestDesign.js +41 -19
  106. package/node_modules/@oscharko-dev/keiko-workflows/package.json +1 -1
  107. package/node_modules/@oscharko-dev/keiko-workspace/dist/.tsbuildinfo +1 -1
  108. package/node_modules/@oscharko-dev/keiko-workspace/dist/ignore.d.ts.map +1 -1
  109. package/node_modules/@oscharko-dev/keiko-workspace/dist/ignore.js +3 -0
  110. package/node_modules/@oscharko-dev/keiko-workspace/package.json +1 -1
  111. package/package.json +1 -1
  112. package/dist/ui/static/_next/static/chunks/923-4141696576191bc0.js +0 -1
  113. package/dist/ui/static/_next/static/chunks/app/_not-found/page-03d642dcd0f15b52.js +0 -1
  114. package/dist/ui/static/_next/static/chunks/app/launch/page-c725ff0c02b50663.js +0 -1
  115. package/dist/ui/static/_next/static/chunks/app/layout-aadefe615729db05.js +0 -1
  116. package/dist/ui/static/_next/static/chunks/app/local-knowledge/capsule/page-4a7f242906e19a07.js +0 -1
  117. package/dist/ui/static/_next/static/chunks/app/local-knowledge/page-3361769b8964e659.js +0 -1
  118. package/dist/ui/static/_next/static/chunks/app/memoriaviva/consolidation/page-44b3f4fa3e10085f.js +0 -1
  119. package/dist/ui/static/_next/static/chunks/app/memoriaviva/detail/page-0cdfb3eeb659daeb.js +0 -1
  120. package/dist/ui/static/_next/static/chunks/app/memoriaviva/page-e78e0cd2876fec41.js +0 -1
  121. package/dist/ui/static/_next/static/chunks/app/memoriaviva/review-queue/page-e32fe86466827484.js +0 -1
  122. package/dist/ui/static/_next/static/chunks/app/page-9ad91065d05ddfa0.js +0 -1
  123. package/dist/ui/static/_next/static/css/51fdcfdc624e723d.css +0 -1
  124. /package/dist/ui/static/_next/static/{BNiyfCos3TiM2QdurajIZ → RAzN8WLtYaktD-ZePowXl}/_buildManifest.js +0 -0
  125. /package/dist/ui/static/_next/static/{BNiyfCos3TiM2QdurajIZ → RAzN8WLtYaktD-ZePowXl}/_ssgManifest.js +0 -0
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[422],{1352:(e,t,n)=>{"use strict";n.d(t,{Af:()=>i,CZ:()=>m,Ir:()=>o,RT:()=>b,Rx:()=>p,W_:()=>u,ax:()=>f,fC:()=>d,h0:()=>v,hz:()=>g,mc:()=>y,oW:()=>x,tR:()=>c,w0:()=>h,xr:()=>r});var a=n(2982);async function l(e){try{let t=await e.json();return{code:t.error.code,message:t.error.message}}catch(t){return{code:"INTERNAL",message:"HTTP ".concat(e.status.toString())}}}async function s(e,t){var n;let s=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),i=null==t?void 0:t.body,r=await fetch(e,{...t,headers:function(e,t){let n={Accept:"application/json"};return null!=t&&(n["Content-Type"]="application/json"),"GET"!==e&&"HEAD"!==e&&(n["X-Keiko-CSRF"]="1"),n}(s,i)});if(!r.ok){let{code:e,message:t}=await l(r);throw new a.hD(e,t,r.status)}return r.json()}async function i(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s,n=new URLSearchParams;void 0!==e.scope&&e.scope.length>0&&n.set("scope",e.scope.join(",")),void 0!==e.type&&e.type.length>0&&n.set("type",e.type.join(",")),void 0!==e.status&&e.status.length>0&&n.set("status",e.status.join(",")),void 0!==e.sensitivity&&e.sensitivity.length>0&&n.set("sensitivity",e.sensitivity.join(",")),void 0!==e.limit&&n.set("limit",e.limit.toString()),void 0!==e.offset&&n.set("offset",e.offset.toString());let a=n.toString();return t("/api/memory".concat(a.length>0?"?".concat(a):""))}async function r(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:s;return e("/api/memory/review-queue")}async function o(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs",{method:"POST",body:JSON.stringify({settings:e})})}async function c(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs/".concat(encodeURIComponent(e)))}async function d(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/consolidation/jobs/".concat(encodeURIComponent(e),"/cancel"),{method:"POST",body:"{}"})}async function u(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e)))}async function h(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e)),{method:"PATCH",body:JSON.stringify(t)})}async function p(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e),"/pin"),{method:"POST",body:"{}"})}async function m(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e),"/unpin"),{method:"POST",body:"{}"})}async function f(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/archive"),{method:"POST",body:JSON.stringify({...void 0!==t?{reason:t}:{}})})}async function g(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/forget"),{method:"POST",body:JSON.stringify({acknowledged:!0,...void 0!==t?{reason:t}:{}})})}async function v(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/".concat(encodeURIComponent(e)),{method:"DELETE",body:"{}"})}async function x(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/".concat(encodeURIComponent(e),"/correct"),{method:"POST",body:JSON.stringify({body:t})})}async function y(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;return t("/api/memory/proposals/".concat(encodeURIComponent(e),"/accept"),{method:"POST",body:"{}"})}async function b(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:s;return n("/api/memory/proposals/".concat(encodeURIComponent(e),"/reject"),{method:"POST",body:JSON.stringify({...void 0!==t?{reason:t}:{}})})}},7002:(e,t,n)=>{"use strict";n.d(t,{KeikoDesktop:()=>rg});var a=n(4568),l=n(7620);let s=(0,l.createContext)(null);function i(e){let{value:t,children:n}=e;return(0,a.jsx)(s.Provider,{value:t,children:n})}function r(){let e=(0,l.useContext)(s);if(null===e)throw Error("useChatSessionContext must be used inside ChatSessionProvider");return e}function o(){return(0,l.useContext)(s)}let c=[{id:"read",action:"Read files",scope:"workspace",decision:"allow"},{id:"write",action:"Write files",scope:"src/** \xb7 docs/**",decision:"allow"},{id:"write-prod",action:"Write files",scope:"prod/** \xb7 infra/**",decision:"deny"},{id:"command",action:"Run commands",scope:"test \xb7 build \xb7 lint",decision:"allow"},{id:"command-danger",action:"Run commands",scope:"deploy \xb7 rm \xb7 db",decision:"ask"},{id:"network",action:"Network / fetch",scope:"allowlist",decision:"ask"},{id:"pr",action:"Open pull request",scope:"feature branches",decision:"allow"},{id:"mail",action:"Mail / calendar",scope:"any",decision:"ask"}],d=["Prefers TypeScript + functional React","Writes Conventional Commits","Always reviews diffs before merge","Never touches infra without explicit ok","Deep-work mornings (CET), async afternoons"],u={calendar:!0,mail:!1,jira:!0,docs:!0},h="keiko.twin.mode",p="keiko.twin.persona",m="keiko.twin.policy",f="keiko.twin.memory",g="keiko.twin.bridges",v=(0,l.createContext)(null);function x(e,t){try{let n=window.localStorage.getItem(e);if(null===n)return t;let a=JSON.parse(n);return null==a?t:a}catch(e){return t}}function y(e,t){try{window.localStorage.setItem(e,t)}catch(e){}}function b(e,t){try{window.localStorage.setItem(e,JSON.stringify(t))}catch(e){}}function j(e){let{children:t}=e,[n,s]=(0,l.useState)("manual"),[i,r]=(0,l.useState)("Developer"),[o,j]=(0,l.useState)(c),[w,k]=(0,l.useState)(d),[N,S]=(0,l.useState)(u),[C,R]=(0,l.useState)(!1);(0,l.useEffect)(()=>{s(function(){try{let e=window.localStorage.getItem(h);return"manual"===e||"autonomous"===e?e:"manual"}catch(e){return"manual"}}()),r(function(){try{let e=window.localStorage.getItem(p);if("Developer"===e||"Product Owner"===e||"Designer"===e)return e;return"Developer"}catch(e){return"Developer"}}()),j(x(m,c)),k(x(f,d)),S(x(g,u)),R(!0)},[]),(0,l.useEffect)(()=>{C&&y(h,n)},[n,C]),(0,l.useEffect)(()=>{C&&y(p,i)},[i,C]),(0,l.useEffect)(()=>{C&&b(m,o)},[o,C]),(0,l.useEffect)(()=>{C&&b(f,w)},[w,C]),(0,l.useEffect)(()=>{C&&b(g,N)},[N,C]);let E=(0,l.useCallback)((e,t)=>(function(e,t,n){var a,l,s,i,r,o,c;let d=t=>{var n,a;return null!=(a=null==(n=e.find(e=>e.id===t))?void 0:n.decision)?a:null};return"write"===t?"high"===n?null!=(a=d("write-prod"))?a:"deny":null!=(l=d("write"))?l:"allow":"command"===t?"high"===n?null!=(s=d("command-danger"))?s:"ask":null!=(i=d("command"))?i:"allow":"git"===t?null!=(r=d("pr"))?r:"allow":"mail"===t?null!=(o=d("mail"))?o:"ask":"network"===t&&null!=(c=d("network"))?c:"ask"})(o,e,t),[o]),I=(0,l.useMemo)(()=>({mode:n,setMode:s,persona:i,setPersona:r,policy:o,setPolicy:j,memory:w,setMemory:k,bridges:N,setBridges:S,decide:E}),[n,i,o,w,N,E]);return(0,a.jsx)(v.Provider,{value:I,children:t})}function w(){let e=(0,l.useContext)(v);if(null===e)throw Error("useTwin must be used inside <TwinProvider>");return e}let k=(0,l.createContext)({wins:[],active:null,winCount:0});var N=n(1230);function S(e){let{winCount:t,mode:n,selectedModel:l,projectName:s,branchLabel:i,shellStatusLabel:r,evidenceStatusLabel:o,statusRef:c}=e,d=null!=l?l:"No model selected";return(0,a.jsxs)("footer",{ref:c,className:"footer mono",tabIndex:-1,"aria-label":"Workspace status","aria-live":"polite",children:[(0,a.jsxs)("span",{className:"ft-seg ft-gov","data-mode":n,"aria-atomic":"true",title:"autonomous"===n?"Governance mode: Keiko governs agents per your policy":"Governance mode: you approve every privileged action",children:["autonomous"===n?(0,a.jsx)("img",{className:"ft-orca",src:"/assets/keiko-logo.svg",alt:""}):(0,a.jsx)("span",{className:"ft-you","aria-hidden":"true",children:(0,a.jsx)(N.F.user,{size:10})}),"autonomous"===n?"Keiko governing":"You \xb7 manual"]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2","aria-atomic":"true",title:"Active project: ".concat(s),children:[(0,a.jsx)(N.F.folder,{size:13}),(0,a.jsx)("span",{className:"ft-val",children:s})]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt1","aria-atomic":"true",title:"Git branch: ".concat(i),children:[(0,a.jsx)(N.F.branch,{size:13}),(0,a.jsx)("span",{className:"ft-val",children:i})]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2","aria-atomic":"true",title:"Shell status: ".concat(r),children:[(0,a.jsx)(N.F.cube,{size:13})," ",r]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"ft-seg ft-accent","aria-atomic":"true",title:"Open windows in the workspace",children:[(0,a.jsx)(N.F.tile,{size:13})," ",t," ",1===t?"window":"windows"]}),(0,a.jsxs)("span",{className:"ft-seg ft-opt2","aria-atomic":"true",title:"Selected model: ".concat(d),children:[(0,a.jsx)(N.F.bolt,{size:13,style:{color:"var(--accent-text)"}}),(0,a.jsx)("span",{className:"ft-val",children:d})]}),(0,a.jsxs)("span",{className:"ft-seg ft-accent","aria-atomic":"true",title:"Review evidence status: ".concat(o),children:[(0,a.jsx)(N.F.review,{size:13})," ",o]})]})}let C=[{id:"finder",name:"Finder",tile:"finder"},{id:"terminal",name:"Terminal",tile:"terminal"},{id:"vscode",name:"VS Code",img:"/assets/editors/vscode.svg"},{id:"intellij",name:"IntelliJ IDEA",img:"/assets/editors/intellij.svg"},{id:"goland",name:"GoLand",img:"/assets/editors/goland.svg"},{id:"rustrover",name:"RustRover",img:"/assets/editors/rustrover.svg"},{id:"pycharm",name:"PyCharm",img:"/assets/editors/pycharm.svg"},{id:"webstorm",name:"WebStorm",img:"/assets/editors/webstorm.svg"}],R="keiko.editor",E="intellij";function I(){try{var e;return null!=(e=window.localStorage.getItem(R))?e:E}catch(e){return E}}function T(e){let{ed:t,size:n=20}=e;if(void 0!==t.img)return(0,a.jsx)("img",{className:"ed-img",src:t.img,width:n,height:n,alt:""});let l=Math.round(.27*n);return"terminal"===t.tile?(0,a.jsx)("span",{className:"ed-tile",style:{width:n,height:n,borderRadius:l,background:"#2a2c33"},children:(0,a.jsx)("span",{className:"ed-mark mono",style:{color:"#4ee08d",fontSize:.42*n},children:">_"})}):(0,a.jsx)("span",{className:"ed-tile",style:{width:n,height:n,borderRadius:l,background:"linear-gradient(180deg,#36c4ff,#1e7cf0)"},children:(0,a.jsx)(N.F.folder,{size:.56*n,style:{color:"#fff"}})})}function F(e){var t;let{project:n}=e,[s,i]=(0,l.useState)(!1),[r,o]=(0,l.useState)(I),c=(0,l.useRef)(null),d=(0,l.useRef)(null),u=null!=(t=C.find(e=>e.id===r))?t:C[3],h="Editor: ".concat(u.name),p="Preferred editor for ".concat(n,": ").concat(u.name);(0,l.useEffect)(()=>{try{window.localStorage.setItem(R,r)}catch(e){}},[r]),(0,l.useEffect)(()=>{var e;if(!s)return;let t=d.current;if(null===t)return;let n=null!=(e=t.querySelector('.edm-item[data-sel="true"]'))?e:t.querySelector(".edm-item");null==n||n.focus()},[s]);let m=()=>{var e;i(!1),null==(e=c.current)||e.focus()};return(0,a.jsxs)("div",{className:"edm",children:[(0,a.jsxs)("button",{type:"button",ref:c,className:"edm-trigger",onClick:()=>i(e=>!e),title:p,"aria-label":p,"aria-haspopup":"menu","aria-expanded":s,children:[(0,a.jsx)(T,{ed:u,size:20}),(0,a.jsx)("span",{className:"edm-trigger-label",children:h}),(0,a.jsx)(N.F.chevron,{size:13,style:{color:"var(--fg-faint)"}})]}),s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"edm-backdrop",onClick:()=>i(!1),"aria-hidden":"true",role:"presentation"}),(0,a.jsxs)("div",{className:"edm-menu",role:"menu",tabIndex:-1,ref:d,onKeyDown:e=>{var t,n,a;if("Escape"===e.key){e.preventDefault(),e.stopPropagation(),m();return}if(!["ArrowDown","ArrowUp","Home","End"].includes(e.key))return;let l=d.current;if(null===l)return;let s=Array.from(l.querySelectorAll(".edm-item"));if(0===s.length)return;e.preventDefault();let i=s.findIndex(e=>e===document.activeElement);null==(t=s[n=e.key,a=s.length,"ArrowDown"===n?i<0?0:(i+1)%a:"ArrowUp"===n?i<0?a-1:(i-1+a)%a:"Home"===n?0:a-1])||t.focus()},children:[(0,a.jsxs)("div",{className:"edm-head mono",children:["Preferred editor for “",n,"”"]}),C.map(e=>(0,a.jsxs)("button",{type:"button",className:"edm-item","data-sel":e.id===r,onClick:()=>{o(e.id),m()},role:"menuitemradio","aria-checked":e.id===r,children:[(0,a.jsx)(T,{ed:e,size:24}),(0,a.jsx)("span",{className:"edm-name",children:e.name}),e.id===r?(0,a.jsx)(N.F.check,{size:14,style:{color:"var(--accent)"}}):null]},e.id))]})]}):null]})}function q(e){let{mode:t,onChange:n}=e;return(0,a.jsxs)("div",{className:"modesw","data-mode":t,role:"group","aria-label":"Agent mode",children:[(0,a.jsxs)("button",{type:"button",className:"modesw-opt","data-on":"manual"===t,"aria-pressed":"manual"===t,onClick:()=>n("manual"),title:"You approve every privileged action",children:[(0,a.jsx)("span",{className:"modesw-av","aria-hidden":"true",children:"M"})," ","You"]}),(0,a.jsxs)("button",{type:"button",className:"modesw-opt","data-on":"autonomous"===t,"aria-pressed":"autonomous"===t,onClick:()=>n("autonomous"),title:"Keiko governs agents per your policy",children:[(0,a.jsx)("img",{className:"modesw-orca",src:"/assets/keiko-logo.svg",alt:""})," Keiko"]})]})}function A(e){let{mode:t,projectName:n,statusLabel:l,statusTone:s,onModeChange:i,openPalette:r,openCommandPalette:o,onTileAll:c,onSplitFront:d,onCascade:u,onExpandFront:h,onRestoreFront:p}=e;return(0,a.jsxs)("header",{className:"header",children:[(0,a.jsxs)("div",{className:"hd-brand",children:[(0,a.jsx)("img",{className:"hd-logo",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsx)("span",{className:"hd-wordmark",children:"Keiko"})]}),(0,a.jsx)("div",{className:"tb-tabs",children:(0,a.jsx)("div",{className:"tb-tab","data-active":"true",title:n,children:(0,a.jsx)("span",{children:n})})}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"hd-tools",children:[(0,a.jsxs)("button",{type:"button",className:"hd-tool hd-tool-cta",onClick:r,title:"New window — press Ctrl/⌘K for all commands",children:[(0,a.jsx)(N.F.add,{size:16}),(0,a.jsx)("span",{children:"New"})]}),(0,a.jsx)("button",{type:"button",className:"hd-tool hd-tool-kbd",onClick:o,title:"Open the command palette (Ctrl/⌘K)","aria-label":"Open the command palette (Ctrl/⌘K)",children:(0,a.jsx)("span",{className:"kbd","aria-hidden":"true",children:"⌘K"})}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)(F,{project:n}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:c,title:"Tile all windows","aria-label":"Tile all windows",children:(0,a.jsx)(N.F.tile,{size:16})}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:d,title:"Split front windows","aria-label":"Split front windows",children:(0,a.jsx)(N.F.split,{size:16})}),(0,a.jsx)("button",{type:"button",className:"hd-tool",onClick:u,title:"Cascade windows","aria-label":"Cascade windows",children:(0,a.jsx)(N.F.cascade,{size:16})})]}),(0,a.jsx)("span",{className:"hd-div"}),(0,a.jsx)(q,{mode:t,onChange:i}),(0,a.jsxs)("div",{className:"tb-status mono",role:"status",children:[(0,a.jsx)("span",{className:"dot","data-tone":s})," ",l]}),(0,a.jsx)("button",{type:"button",className:"tb-btn",onClick:h,title:"Expand the front window","aria-label":"Expand window",children:(0,a.jsx)(N.F.expand,{size:16})}),(0,a.jsx)("button",{type:"button",className:"tb-btn",onClick:p,title:"Restore the front window","aria-label":"Restore window",children:(0,a.jsx)(N.F.minimize,{size:16})})]})}var M=n(9664),P=n.n(M);let D=[{id:"keiko",icon:"spark",label:"Keiko",img:"/assets/keiko-logo.svg"},{id:"project",icon:"folder",label:"Project"},{id:"search",icon:"search",label:"Search"},{id:"plugins",icon:"plugins",label:"Plugins"}],L=[{id:"automations",icon:"automations",label:"Automations"},{id:"mobile",icon:"mobile",label:"Keiko Mobile"}];function z(e){let{tool:t,active:n,onClick:l}=e,s=N.F[t.icon];return(0,a.jsx)("button",{type:"button",className:"rail-btn","data-active":n?"true":"false","data-side":"left","aria-label":t.label,"aria-pressed":n,"data-tip":t.label,onClick:l,children:void 0!==t.img?(0,a.jsx)("img",{className:"rail-img",src:t.img,alt:""}):(0,a.jsx)(s,{size:19})})}function O(e){let{openTools:t,onTool:n,onNewChat:l,theme:s,onToggleTheme:i}=e;return(0,a.jsxs)("nav",{className:"rail rail-left","aria-label":"Primary workspace navigation",children:[(0,a.jsx)("button",{type:"button",className:"rail-new",onClick:l,"data-side":"left","aria-label":"New chat","data-tip":"New chat",children:(0,a.jsx)(N.F.newChat,{size:18})}),(0,a.jsx)("div",{className:"rail-div"}),(0,a.jsx)("div",{className:"rail-group",children:D.map(e=>(0,a.jsx)(z,{tool:e,active:t.has(e.id),onClick:()=>n(e.id)},e.id))}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"rail-group",children:[L.map(e=>(0,a.jsx)(z,{tool:e,active:t.has(e.id),onClick:()=>n(e.id)},e.id)),(0,a.jsx)(P(),{href:"/memoriaviva",className:"rail-btn","data-active":"false","data-side":"left","aria-label":"MemoriaViva","data-tip":"MemoriaViva",children:(0,a.jsx)(N.F.brain,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("quality")?"true":"false","aria-label":"Quality Intelligence","aria-pressed":t.has("quality"),"data-tip":"Quality Intelligence",onClick:()=>n("quality"),children:(0,a.jsx)(N.F.check,{size:19})}),(0,a.jsx)(P(),{href:"/local-knowledge",className:"rail-btn","data-active":"false","data-side":"left","aria-label":"Local Knowledge","data-tip":"Local Knowledge",children:(0,a.jsx)(N.F.localKnowledge,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("relationships")?"true":"false","aria-label":"Relationships","aria-pressed":t.has("relationships"),"data-tip":"Relationships",onClick:()=>n("relationships"),children:(0,a.jsx)(N.F.branch,{size:19})})]}),(0,a.jsx)("div",{className:"rail-div"}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","aria-label":"light"===s?"Dark mode":"Light mode","data-tip":"light"===s?"Dark mode":"Light mode",onClick:i,children:"light"===s?(0,a.jsx)(N.F.moon,{size:19}):(0,a.jsx)(N.F.sun,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("settings")?"true":"false","aria-label":"Settings","aria-pressed":t.has("settings"),"data-tip":"Settings",onClick:()=>n("settings"),children:(0,a.jsx)(N.F.settings,{size:19})}),(0,a.jsx)("button",{type:"button",className:"rail-avatar","data-side":"left","aria-label":"Account","data-tip":"Account",onClick:()=>n("settings"),children:(0,a.jsx)(N.F.user,{size:15})})]})}let K=[{id:"inspector",label:"Inspector",icon:"layers"},{id:"activity",label:"Activity",icon:"activity"},{id:"notifications",label:"Notifications",icon:"bell"},{id:"resources",label:"Resources",icon:"cube"}];function B(e){let{openTools:t,onTool:n}=e;return(0,a.jsx)("aside",{className:"rail rail-right","aria-label":"Workspace utilities",children:(0,a.jsx)("div",{className:"rail-group",children:K.map(e=>{let l=N.F[e.icon];return(0,a.jsx)("button",{type:"button",className:"rail-btn","data-active":t.has(e.id),"data-side":"right","data-tip":e.label,"aria-label":e.label,"aria-pressed":t.has(e.id),onClick:()=>n(e.id),children:(0,a.jsx)(l,{size:19})},e.id)})})})}function W(e,t,n){let a=e.createShader(t);return null===a?null:(e.shaderSource(a,n),e.compileShader(a),e.getShaderParameter(a,e.COMPILE_STATUS))?a:(console.warn("[keiko-shader]",e.getShaderInfoLog(a)),e.deleteShader(a),null)}function U(){let e=window.localStorage.getItem("keiko.wallpaper.opacity");if(null===e)return 1;let t=Number.parseInt(e,10);return Number.isFinite(t)?Math.max(0,Math.min(100,t))/100:1}function _(){let e=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let t,n=e.current;if(null===n)return;let a=n.parentElement;if(null===a)return;let l=window.matchMedia("(prefers-reduced-motion: reduce)"),s=()=>{l.matches?(null==t||t(),t=void 0):void 0===t&&(t=function(e,t){var n;t.style.opacity=String(U());let a=e=>{let n=e.detail,a="number"==typeof n?n:100*U();t.style.opacity=String(Math.max(0,Math.min(100,a))/100)};window.addEventListener("keiko:wallpaper-opacity",a);let l=null;try{l=t.getContext("webgl",{antialias:!1,alpha:!1,premultipliedAlpha:!1,depth:!1})}catch(e){l=null}if(null===l)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};let s=W(l,l.VERTEX_SHADER,"\nattribute vec2 aPos;\nvoid main(){ gl_Position = vec4(aPos, 0.0, 1.0); }\n"),i=W(l,l.FRAGMENT_SHADER,"\nprecision highp float;\nuniform vec2 uRes;\nuniform float uTime;\nuniform vec2 uMouse; // 0..1, y up\nuniform float uDark; // 1 = dark theme, 0 = light\nuniform vec2 uRip[4]; // ripple origins (0..1, y up)\nuniform float uRipT[4]; // seconds since each ripple fired (large = inactive)\n\nfloat hash(vec2 p){\n p = fract(p * vec2(123.34, 456.21));\n p += dot(p, p + 45.32);\n return fract(p.x * p.y);\n}\nfloat vnoise(vec2 p){\n vec2 i = floor(p), f = fract(p);\n vec2 u = f * f * (3.0 - 2.0 * f);\n float a = hash(i), b = hash(i + vec2(1.,0.));\n float c = hash(i + vec2(0.,1.)), d = hash(i + vec2(1.,1.));\n return mix(mix(a,b,u.x), mix(c,d,u.x), u.y);\n}\nfloat fbm(vec2 p){\n float v = 0.0, a = 0.5;\n mat2 m = mat2(1.6, 1.2, -1.2, 1.6);\n for(int i = 0; i < 5; i++){ v += a * vnoise(p); p = m * p; a *= 0.5; }\n return v;\n}\n\nvoid main(){\n vec2 uv = gl_FragCoord.xy / uRes.xy;\n float aspect = uRes.x / uRes.y;\n vec2 p = vec2(uv.x * aspect, uv.y);\n vec2 m = vec2(uMouse.x * aspect, uMouse.y);\n\n float t = uTime * 0.06;\n\n // --- click ripples ---------------------------------------------------\n float rip = 0.0;\n for(int i = 0; i < 4; i++){\n float age = uRipT[i];\n if(age < 2.4){\n vec2 rc = vec2(uRip[i].x * aspect, uRip[i].y);\n float d = distance(p, rc);\n float ring = sin(d * 15.0 - age * 9.0);\n float env = exp(-d * 3.6) * exp(-age * 2.1);\n rip += ring * env;\n }\n }\n\n // --- liquid domain warp ---------------------------------------------\n vec2 warp = vec2(\n fbm(p * 2.1 + vec2(0.0, t)),\n fbm(p * 2.1 + vec2(t, 4.7))\n );\n // mouse bends the flow toward the cursor\n vec2 toM = m - p;\n float md = exp(-length(toM) * 2.2);\n warp += toM * md * 0.28;\n warp += rip * 0.07;\n\n float f = fbm(p * 2.4 + warp * 1.7 + vec2(t * 0.6, 0.0));\n\n // --- chrome banding (sharp metallic streaks) ------------------------\n float bands = abs(sin((f * 4.0 + warp.x * 2.0) * 3.14159 + t * 1.4));\n float chrome = pow(bands, 2.6);\n\n // --- palette (brand) -------------------------------------------------\n vec3 baseD = vec3(0.072, 0.085, 0.079); // warm near-black ~ --bg\n vec3 metalD = vec3(0.205, 0.230, 0.216); // chrome mid grey\n vec3 baseL = vec3(0.930, 0.942, 0.935); // near-white\n vec3 metalL = vec3(0.795, 0.835, 0.812); // soft grey\n vec3 green = vec3(0.306, 0.729, 0.529); // #4EBA87\n\n vec3 base = mix(baseL, baseD, uDark);\n vec3 metal = mix(metalL, metalD, uDark);\n\n vec3 col = mix(base, metal, chrome * 0.85);\n\n // orca-green sheen on the brightest specular ridges\n float spec = smoothstep(0.80, 1.0, bands);\n col += green * spec * mix(0.085, 0.16, uDark);\n\n // soft green glow trailing the cursor — fun to fidget with\n col += green * md * 0.085;\n\n // ripple highlight\n vec3 ripCol = mix(green, vec3(1.0), uDark);\n col += ripCol * max(rip, 0.0) * 0.032;\n\n // keep it dezent — pull back toward base\n col = mix(base, col, 0.84);\n\n gl_FragColor = vec4(col, 1.0);\n}\n");if(null===s||null===i)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};let r=l.createProgram();if(null===r)return()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};if(l.attachShader(r,s),l.attachShader(r,i),l.linkProgram(r),!l.getProgramParameter(r,l.LINK_STATUS))return console.warn("[keiko-shader]",l.getProgramInfoLog(r)),()=>{window.removeEventListener("keiko:wallpaper-opacity",a)};l.useProgram(r);let o=l.createBuffer();l.bindBuffer(l.ARRAY_BUFFER,o),l.bufferData(l.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),l.STATIC_DRAW);let c=l.getAttribLocation(r,"aPos");l.enableVertexAttribArray(c),l.vertexAttribPointer(c,2,l.FLOAT,!1,0,0);let d=l.getUniformLocation(r,"uRes"),u=l.getUniformLocation(r,"uTime"),h=l.getUniformLocation(r,"uMouse"),p=l.getUniformLocation(r,"uDark"),m=l.getUniformLocation(r,"uRip"),f=l.getUniformLocation(r,"uRipT"),g=1,v=1,x=Math.min(null!=(n=window.devicePixelRatio)?n:1,1.5),y={tx:.5,ty:.5,x:.5,y:.5},b=new Float32Array(8),j=[,,,,].fill(-1/0),w=0;function k(){let n=e.getBoundingClientRect();g=Math.max(1,Math.round(n.width)),v=Math.max(1,Math.round(n.height)),t.width=Math.round(g*x),t.height=Math.round(v*x),t.style.width="".concat(String(g),"px"),t.style.height="".concat(String(v),"px"),null!==l&&l.viewport(0,0,t.width,t.height)}k();let N="undefined"!=typeof ResizeObserver?new ResizeObserver(k):null;null!==N?N.observe(e):window.addEventListener("resize",k);let S=t=>{let n=e.getBoundingClientRect();y.tx=(t.clientX-n.left)/Math.max(1,n.width),y.ty=1-(t.clientY-n.top)/Math.max(1,n.height)},C=t=>{let n=e.getBoundingClientRect(),a=(t.clientX-n.left)/Math.max(1,n.width),l=1-(t.clientY-n.top)/Math.max(1,n.height);a<0||a>1||l<0||l>1||(b[2*w]=a,b[2*w+1]=l,j[w]=performance.now(),w=(w+1)%4)};e.addEventListener("pointermove",S),e.addEventListener("pointerdown",C);let R=performance.now(),E=0,I=!0,T=new Float32Array(4);function F(){if(!I)return;let e=performance.now();y.x+=(y.tx-y.x)*.06,y.y+=(y.ty-y.y)*.06;for(let t=0;t<4;t++){var n;T[t]=(e-(null!=(n=j[t])?n:-1/0))/1e3}let a=+("light"!==document.documentElement.dataset.theme);null!==l&&(l.uniform2f(d,t.width,t.height),l.uniform1f(u,(e-R)/1e3),l.uniform2f(h,y.x,y.y),l.uniform1f(p,a),l.uniform2fv(m,b),l.uniform1fv(f,T),l.drawArrays(l.TRIANGLES,0,3)),E=requestAnimationFrame(F)}E=requestAnimationFrame(F);let q=()=>{document.hidden?(I=!1,cancelAnimationFrame(E)):I||(I=!0,E=requestAnimationFrame(F))};return document.addEventListener("visibilitychange",q),()=>{if(I=!1,cancelAnimationFrame(E),document.removeEventListener("visibilitychange",q),window.removeEventListener("keiko:wallpaper-opacity",a),e.removeEventListener("pointermove",S),e.removeEventListener("pointerdown",C),null!==N?N.disconnect():window.removeEventListener("resize",k),null!==l){let e=l.getExtension("WEBGL_lose_context");null!==e&&e.loseContext()}}}(a,n))};return s(),l.addEventListener("change",s),()=>{l.removeEventListener("change",s),null==t||t()}},[]),(0,a.jsx)("canvas",{ref:e,className:"ws-shader","aria-hidden":"true"})}let H={agents:["files","terminal","plugins","review","browser","agents","keiko"],chat:["files","browser","plugins","keiko","connector"],files:["agents","chat","quality"],terminal:["agents"],plugins:["agents","chat"],review:["agents"],browser:["agents","chat"],keiko:["agents","chat"],connector:["chat","quality"],quality:["files","connector","figma"],figma:["quality"]};function G(e,t){var n,a;return void 0!==e&&void 0!==t&&e!==t&&((null!=(n=H[e])?n:[]).includes(t)||(null!=(a=H[t])?a:[]).includes(e))}function J(e,t){let n="files"===e.type?e:"files"===t.type?t:null,a=null===n?null:n===e?t:e;if(null!==n&&null!==a&&("chat"===a.type||"agents"===a.type||"quality"===a.type)){var l;let e=function(e){if(void 0===e)return null;let t=e.resolvedRoot;if("string"==typeof t&&t.length>0)return t;let n=e.root;return"string"==typeof n&&n.length>0?n:null}(n.cfg);if(null===e)return"no folder selected";let t=null!=(l=e.split(/[/\\]/u).filter(Boolean).pop())?l:e;return"uses ".concat(t,"/")}let s=[e.type,t.type];return s.includes("connector")?"uses knowledge":s.includes("figma")?"uses snapshot":s.includes("keiko")?"governed by":"agents"===s[0]&&"agents"===s[1]?"delegates":s.includes("terminal")?"runs in":s.includes("plugins")?"uses tools":s.includes("review")?"reviews":s.includes("browser")?"browses":"connected"}function V(e){return{left:{x:e.x,y:e.y,w:e.w/2,h:e.h},right:{x:e.x+e.w/2,y:e.y,w:e.w/2,h:e.h},maxi:{x:e.x,y:e.y,w:e.w,h:e.h},tl:{x:e.x,y:e.y,w:e.w/2,h:e.h/2},tr:{x:e.x+e.w/2,y:e.y,w:e.w/2,h:e.h/2},bl:{x:e.x,y:e.y+e.h/2,w:e.w/2,h:e.h/2},br:{x:e.x+e.w/2,y:e.y+e.h/2,w:e.w/2,h:e.h/2}}}let X=new Set(["files","connector","browser","plugins","agents","quality"]);function Y(e,t){return e>=4||t>=8192}function Z(e){let{pathId:t,intensity:n}=e,l="heavy"===n?3:1,s="heavy"===n?1.1:2.2;return(0,a.jsx)(a.Fragment,{children:Array.from({length:l},(e,i)=>(0,a.jsx)("circle",{className:"conn-particle",r:"heavy"===n?3:2.4,"aria-hidden":"true",children:(0,a.jsx)("animateMotion",{dur:"".concat(String(s),"s"),repeatCount:"indefinite",begin:"".concat(String(s/l*i),"s"),rotate:"auto",keyPoints:"0;1",keyTimes:"0;1",calcMode:"linear",children:(0,a.jsx)("mpath",{href:"#".concat(t)})})},i))})}function Q(e){let{wins:t,conns:n,connecting:s,api:i}=e,r=o(),c=function(){let[e,t]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),n=e=>t(e);n(e.matches);let a=e=>n(e.matches);return e.addEventListener("change",a),()=>e.removeEventListener("change",a)},[]),e}(),{armedId:d,arm:u,disarm:h}=function(){let[e,t]=(0,l.useState)(null);return(0,l.useEffect)(()=>{if(null===e)return;let n=setTimeout(()=>t(null),3e3);return()=>clearTimeout(n)},[e]),{armedId:e,arm:e=>t(e),disarm:()=>t(null)}}(),{flowing:p,intensity:m}=function(e,t){let[n,a]=(0,l.useState)("light"),[s,i]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{if(void 0===t)return;a(function(e){switch(e.groundingKind){case"connected-context":return Y(e.contextPack.usage.filesRead,e.contextPack.usage.excerptBytes)?"heavy":"light";case"hybrid":return Y(e.contextPack.folder.usage.filesRead,e.contextPack.folder.usage.excerptBytes)||e.contextPack.knowledge.referencesUsed>=4?"heavy":"light";case"local-knowledge":return e.contextPack.referencesUsed>=4?"heavy":"light";default:return"light"}}(t)),i(!0);let e=setTimeout(()=>i(!1),2500);return()=>clearTimeout(e)},[t]),{flowing:e||s,intensity:n}}((null==r?void 0:r.sending)===!0,null==r?void 0:r.latestGrounded),f=function(e,t){let n=new Map(e.map(e=>[e.id,e])),a=[];for(let e of t){let t=n.get(e.a),l=n.get(e.b);if(void 0===t||void 0===l)continue;let s=function(e,t){let n,a,l,s,i={x:e.x+e.w/2,y:e.y+e.h/2},r={x:t.x+t.w/2,y:t.y+t.h/2},o=r.x-i.x,c=r.y-i.y;if(Math.abs(o)>=Math.abs(c)){n=o>=0?{x:e.x+e.w,y:i.y}:{x:e.x,y:i.y};let c=Math.max(40,Math.abs((a=o>=0?{x:t.x,y:r.y}:{x:t.x+t.w,y:r.y}).x-n.x)/2),d=o>=0?1:-1;l={x:n.x+d*c,y:n.y},s={x:a.x-d*c,y:a.y}}else{n=c>=0?{x:i.x,y:e.y+e.h}:{x:i.x,y:e.y};let o=Math.max(40,Math.abs((a=c>=0?{x:r.x,y:t.y}:{x:r.x,y:t.y+t.h}).y-n.y)/2),d=c>=0?1:-1;l={x:n.x,y:n.y+d*o},s={x:a.x,y:a.y-d*o}}let d={x:(n.x+3*l.x+3*s.x+a.x)/8,y:(n.y+3*l.y+3*s.y+a.y)/8};return{d:"M".concat(String(n.x),",").concat(String(n.y)," C").concat(String(l.x),",").concat(String(l.y)," ").concat(String(s.x),",").concat(String(s.y)," ").concat(String(a.x),",").concat(String(a.y)),mid:d}}(t,l);a.push({c:e,d:s.d,mid:s.mid,label:J(t,l),dataChannel:function(e,t){let n=[e.type,t.type].includes("chat"),a="chat"===e.type?X.has(t.type):X.has(e.type);return n&&a}(t,l)})}return a}(t,n),g=null!==s?function(e,t){let n=t.find(t=>t.id===e.from);if(void 0===n)return null;let a={x:n.x+n.w/2,y:n.y+n.h/2},l=e.x-a.x,s=e.y-a.y,i=Math.abs(l)>=Math.abs(s),r=i?{x:l>=0?n.x+n.w:n.x,y:a.y}:{x:a.x,y:s>=0?n.y+n.h:n.y},o=Math.max(40,Math.abs(i?l:s)/2),c=i?{x:r.x+(l>=0?o:-o),y:r.y}:{x:r.x,y:r.y+(s>=0?o:-o)},d=e.x,u=e.y;return{d:"M".concat(String(r.x),",").concat(String(r.y)," C").concat(String(c.x),",").concat(String(c.y)," ").concat(String(d),",").concat(String(u)," ").concat(String(d),",").concat(String(u)),ex:d,ey:u}}(s,t):null;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"conn-layer",children:(0,a.jsxs)("svg",{className:"conn-svg",viewBox:"-10000 -10000 20000 20000",preserveAspectRatio:"xMidYMid meet",children:[f.map(e=>{let t=p&&e.dataChannel,n="conn-path-".concat(e.c.id);return(0,a.jsxs)("g",{children:[(0,a.jsx)("path",{id:n,className:"conn-path",d:e.d,"data-active":t?"true":void 0,"data-intensity":t?m:void 0,"data-reduced-motion":t&&c?"true":void 0}),t&&!c?(0,a.jsx)(Z,{pathId:n,intensity:m}):null]},e.c.id)}),null!==g?(0,a.jsx)("path",{className:"conn-path conn-temp",d:g.d}):null,null!==g?(0,a.jsx)("circle",{className:"conn-dot",cx:g.ex,cy:g.ey,r:"5"}):null]})}),(0,a.jsx)("div",{className:"conn-badge-layer",children:f.map(e=>{let t=p&&e.dataChannel,n=d===e.c.id;return(0,a.jsxs)("button",{type:"button",className:"conn-badge","data-active":t?"true":void 0,"data-intensity":t?m:void 0,"data-armed":n?"true":void 0,style:{left:e.mid.x,top:e.mid.y},onClick:()=>{n?(h(),i.removeConn(e.c.id)):u(e.c.id)},onBlur:()=>{n&&h()},title:n?"Click again to remove: ".concat(e.label):"Remove connection: ".concat(e.label),"aria-label":n?"Confirm removal of connection: ".concat(e.label,". Activate again to remove."):t?"".concat(e.label," — ").concat(m," data exchange in progress. Activate to remove connection."):"Remove connection: ".concat(e.label),children:[(0,a.jsx)(N.F.git,{size:11})," ",(0,a.jsx)("span",{children:n?"Remove?":e.label}),t&&!n?(0,a.jsx)("span",{className:"conn-flow-tag","aria-hidden":"true",children:"heavy"===m?"⇶":"→"}):null]},e.c.id)})})]})}var $=n(2982);function ee(e,t){return e instanceof $.hD?e.message.trim().length>0?"".concat(e.message," (").concat(e.code,")"):"".concat(t," (").concat(e.code,")"):e instanceof Error&&e.message.trim().length>0?e.message:t}let et={w:150,h:110},en={w:290,h:190},ea={chat:{title:"Chat",icon:"newChat",accent:!0,desc:"Talk to Keiko",w:480,h:480,min:{w:300,h:260},config:[{key:"title",label:"Title",type:"text",def:"New chat",optional:!0,placeholder:"Name this conversation"}]},files:{title:"Files",icon:"files",accent:!0,desc:"Browse a folder",w:290,h:340,tiny:{w:200,h:150},config:[{key:"root",label:"Folder",type:"directory",def:""}]},editor:{title:"Editor",icon:"editor",desc:"Code preview (demo)",w:480,h:360,config:[{key:"file",label:"Tab label",type:"text",def:"",optional:!0,placeholder:"file.jsx"}]},browser:{title:"Browser",icon:"browser",desc:"Open a URL",w:460,h:340,config:[{key:"url",label:"URL",type:"text",def:"",optional:!0,placeholder:"https://…"}]},terminal:{title:"Terminal",icon:"terminal",accent:!0,desc:"Run commands",w:460,h:250,tiny:{w:250,h:140},config:[{key:"projectPath",label:"Project path",type:"text",def:""},{key:"cwd",label:"Working directory",type:"directory",def:""}]},review:{title:"Review",icon:"review",desc:"Review a proposed diff",w:520,h:420,config:[{key:"runId",label:"Run ID",type:"text",def:"",optional:!0,placeholder:"e.g. r-2026-06-01-…"}]},agents:{title:"Agents",icon:"agents",desc:"Run a BFF workflow",w:520,h:560,tiny:{w:250,h:140},cta:"Start agent",config:[]},integ:{title:"Integrations",icon:"plugins",desc:"Connect apps",w:320,h:300,config:[{key:"provider",label:"Provider",type:"select",options:["GitHub","Linear","Slack","Sentry"],def:"GitHub"}]},keiko:{title:"Keiko",icon:"spark",desc:"Keiko twin",w:344,h:520,tool:!0,singleton:!0},settings:{title:"Settings",icon:"settings",desc:"Preferences",w:470,h:560,tool:!0,singleton:!0},project:{title:"Project",icon:"folder",desc:"Project tree",w:304,h:440,tool:!0,singleton:!0},search:{title:"Search",icon:"search",desc:"Search the workspace",w:320,h:500,tool:!0,singleton:!0},plugins:{title:"Plugins",icon:"plugins",desc:"Plugins & tools",w:320,h:470,tool:!0,singleton:!0},automations:{title:"Automations",icon:"automations",desc:"Workflow automations",w:320,h:300,tool:!0,singleton:!0},mobile:{title:"Keiko Mobile",icon:"mobile",desc:"Mobile companion",w:300,h:380,tool:!0,singleton:!0},inspector:{title:"Inspector",icon:"layers",desc:"Inspect the workspace",w:290,h:440,tool:!0,singleton:!0},activity:{title:"Activity",icon:"activity",desc:"Activity timeline",w:322,h:460,tool:!0,singleton:!0},notifications:{title:"Notifications",icon:"bell",desc:"Review alerts & updates",w:300,h:360,tool:!0,singleton:!0},resources:{title:"Resources",icon:"cube",desc:"System resources",w:300,h:320,tool:!0,singleton:!0},connector:{title:"Connector",icon:"plugins",accent:!0,desc:"Pick a Local Knowledge connector",w:320,h:380,min:{w:280,h:300},config:[],cta:"Select connector"},quality:{title:"Quality Intelligence",icon:"check",accent:!0,desc:"Design & review test cases",w:384,h:580,min:{w:300,h:320},tiny:{w:260,h:200},tool:!0,singleton:!0},qiRun:{title:"QI Run",icon:"check",desc:"Generated test cases",w:760,h:660,min:{w:320,h:280},tiny:{w:280,h:200},config:[{key:"runId",label:"Run ID",type:"text",def:""}]},relationships:{title:"Relationships",icon:"branch",accent:!0,desc:"Inspect the relationship graph",w:760,h:600,min:{w:360,h:320},tiny:{w:300,h:220},tool:!0,singleton:!0},figma:{title:"Figma Snapshot",icon:"layers",accent:!0,desc:"Capture a Figma board snapshot",w:420,h:540,min:{w:320,h:360},tiny:{w:280,h:240}}},el=new Map;function es(e,t){el.set(e,t)}let ei=function(){let e={};return Object.keys(ea).forEach(t=>{e[t]=function(e,t){var n,a;let l={title:t.title,icon:t.icon,desc:t.desc,w:t.w,h:t.h,min:null!=(n=t.min)?n:et,tiny:null!=(a=t.tiny)?a:en,render:(t,n)=>{let a=el.get(e);return void 0!==a?a(t,n):null}},s={};return!0===t.accent&&(s.accent=!0),!0===t.tool&&(s.tool=!0),!0===t.singleton&&(s.singleton=!0),void 0!==t.config&&(s.config=t.config),void 0!==t.cta&&(s.cta=t.cta),{...l,...s}}(t,ea[t])}),e}();function er(e,t,n,a,l){return{x:e.x+Math.max(16,Math.min(l+26*a,e.w-t-16)),y:e.y+Math.max(16,Math.min(l+26*a,e.h-n-16))}}function eo(e){let{prev:t,...n}=e;return n}function ec(e,t,n){return e.some(e=>e.a===t&&e.b===n||e.a===n&&e.b===t)}function ed(e){return e.length>0&&(e.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(e))}function eu(e){if("files"!==e.type)return null;let t=e.cfg.resolvedRoot,n=e.cfg.root,a="string"==typeof t&&t.length>0?t:"string"==typeof n&&n.length>0?n:null;return null!==a&&ed(a)?a:null}function eh(e,t){let n="files"===e.type?e:"files"===t.type?t:null,a="chat"===e.type?e:"chat"===t.type?t:null;return null===n||null===a?null:eu(n)}function ep(e){var t;return null!=(t=e.connectedScopes)?t:void 0!==e.connectedScope?[e.connectedScope]:[]}function em(e){var t;return null!=(t=e.localKnowledgeScopes)?t:void 0!==e.localKnowledgeScope?[e.localKnowledgeScope]:[]}function ef(e){return"capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId)}function eg(e,t){let n="connector"===e.type?e:"connector"===t.type?t:null,a="chat"===e.type?e:"chat"===t.type?t:null;if(null===n||null===a)return null;let l=n.cfg.selectedKind,s=n.cfg.selectedId;return"string"!=typeof l||"string"!=typeof s||0===s.length?null:"capsule"===l?{kind:"capsule",capsuleId:s,connectedAtMs:Date.now()}:"capsule-set"===l?{kind:"capsule-set",capsuleSetId:s,connectedAtMs:Date.now()}:null}let ev={low:"Low",moderate:"Moderate",high:"High",exceeded:"Exceeded"},ex={low:"cmp-budget-badge cmp-budget-badge-low",moderate:"cmp-budget-badge cmp-budget-badge-moderate",high:"cmp-budget-badge cmp-budget-badge-high",exceeded:"cmp-budget-badge cmp-budget-badge-exceeded"};function ey(e,t){if(Number.isFinite(t)&&!(t<=0))return e/t}function eb(e){let t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return -1===n?t:t.slice(n+1)}function ej(e){null!=e&&window.setTimeout(()=>{var t;let n=null!=(t=e.querySelector(".scope-pill-disconnect"))?t:e.querySelector("button, select, input, [href], [tabindex]");null==n||n.focus()},0)}function ew(e){var t;let{chat:n,scope:s,index:i,allScopes:r,onDisconnect:o,updateScopes:c}=e,[d,u]=(0,l.useState)(!1),[h,p]=(0,l.useState)(null),m=(0,l.useRef)(null),f=function(e){var t,n;if("string"==typeof e.root&&e.root.length>0){let t=eb(e.root);return 0===t.length?"Connected folder":"Folder: ".concat(t)}if("workspace-root"===e.kind)return"Repository scope";if("directory"===e.kind){let n=eb(null!=(t=e.relativePaths[0])?t:"");return 0===n.length?"Connected folder":"Folder: ".concat(n)}if(1===e.relativePaths.length){let t=eb(null!=(n=e.relativePaths[0])?n:"");return 0===t.length?"Connected file":"File: ".concat(t)}return"".concat(String(e.relativePaths.length)," files connected")}(s),g=null!=(t=s.root)?t:s.relativePaths[0];async function v(){var e;if(d)return;p(null),u(!0);let t=null==(e=m.current)?void 0:e.closest(".chat-scope-header");try{let e=r.filter((e,t)=>t!==i),a=await c(n.id,e.length>0?e:null);null==o||o(a.chat),ej(t)}catch(e){p(ee(e,"Unable to disconnect scope."))}finally{u(!1)}}return(0,a.jsxs)("span",{className:"scope-pill-wrap",children:[(0,a.jsxs)("span",{className:"scope-pill",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"●"}),(0,a.jsx)("span",{role:"status","aria-live":"polite",title:g,children:f}),(0,a.jsx)("button",{type:"button",ref:m,className:"scope-pill-disconnect","aria-disabled":d,"aria-label":"Disconnect ".concat(f," from chat"),title:void 0===g?"Disconnect ".concat(f," from chat"):"Disconnect ".concat(f," from chat (").concat(g,")"),onClick:()=>{v()},children:(0,a.jsx)("span",{"aria-hidden":"true",children:"\xd7"})})]}),(0,a.jsx)("span",{className:"scope-pill-detail",children:function(e){let t="workspace-root"===e.kind?"the connected repository":"directory"===e.kind?"the connected folder":"the connected file scope";return"Keiko may inspect only ".concat(t,"; safe-read exclusions and context budget limits apply before each answer.")}(s)}),null!==h?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:h}):null]})}function ek(e){let{chat:t,onDisconnect:n,lastGroundedBudgetStatus:l,updateScopes:s=$.Mr}=e,i=ep(t);return 0===i.length?null:(0,a.jsxs)("span",{className:"scope-pill-group",children:[i.map((e,l)=>{var r;return(0,a.jsx)(ew,{chat:t,scope:e,index:l,allScopes:i,onDisconnect:n,updateScopes:s},"".concat(null!=(r=e.root)?r:e.kind,"-").concat(String(e.connectedAtMs),"-").concat(String(l)))}),void 0!==l?(0,a.jsx)("span",{className:"scope-pill-wrap",children:(0,a.jsxs)("span",{className:"scope-pill-detail",style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[(0,a.jsx)("span",{className:ex[l.pressure],children:l.label}),(0,a.jsx)("span",{children:l.summary})]})}):null]})}function eN(e){return"capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId)}function eS(e){let{chat:t,scope:n,allScopes:s,onDisconnect:i,updateScopes:r,labels:o}=e,[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),p=(0,l.useRef)(null),m=function(e,t){let n=eN(e),a=t.get(n);return void 0!==a&&a.length>0?a:"capsule"===e.kind?"Capsule: ".concat(e.capsuleId):"Capsule set: ".concat(e.capsuleSetId)}(n,o),f=eN(n);async function g(){var e;if(c)return;h(null),d(!0);let n=null==(e=p.current)?void 0:e.closest(".chat-scope-header");try{let e=s.filter(e=>eN(e)!==f),a=await r(t.id,e.length>0?e:null);null==i||i(a.chat),ej(n)}catch(e){h(ee(e,"Unable to disconnect capsule."))}finally{d(!1)}}return(0,a.jsxs)("span",{className:"scope-pill-wrap",children:[(0,a.jsxs)("span",{className:"scope-pill scope-pill--connector",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"◆"}),(0,a.jsx)("span",{role:"status","aria-live":"polite",children:m}),(0,a.jsx)("button",{type:"button",ref:p,className:"scope-pill-disconnect","aria-disabled":c,"aria-label":"Disconnect ".concat(m," from chat"),title:"Disconnect ".concat(m," from chat"),onClick:()=>{g()},children:(0,a.jsx)("span",{"aria-hidden":"true",children:"\xd7"})})]}),null!==u?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:u}):null]})}function eC(e){let{chat:t,onDisconnect:n,updateScopes:l=$.Cp,labels:s=new Map}=e,i=em(t);return 0===i.length?null:(0,a.jsx)("span",{className:"scope-pill-group scope-pill-group--connector",children:i.map(e=>(0,a.jsx)(eS,{chat:t,scope:e,allScopes:i,onDisconnect:n,updateScopes:l,labels:s},eN(e)))})}let eR="cmp-budget-exceeded-alert",eE={low:"Low",moderate:"Moderate",high:"High",exceeded:"Exceeded"},eI={low:"cmp-budget-badge cmp-budget-badge-low",moderate:"cmp-budget-badge cmp-budget-badge-moderate",high:"cmp-budget-badge cmp-budget-badge-high",exceeded:"cmp-budget-badge cmp-budget-badge-exceeded"},eT="Token counts are approximate. Actual model usage may vary.";function eF(e){return e>=1e3?"".concat((e/1e3).toFixed(1),"k"):e.toString()}function eq(e){let{budget:t,onClearHistory:n,disabled:s}=e,[i,r]=(0,l.useState)(!1),[o,c]=(0,l.useState)(!1),d=(0,l.useRef)(null),u=(0,l.useRef)(null);if((0,l.useEffect)(()=>{if(i){var e;null==(e=d.current)||e.focus()}},[i]),void 0===t)return null;let h=t.contextWindowTokens>0,p=eF(t.approximateTokens),m=eF(t.contextWindowTokens),f=t.pressure,g=h&&"exceeded"===f;return(0,a.jsxs)("div",{className:"cmp-budget","data-pressure":h?f:"unknown",children:[(0,a.jsxs)("div",{className:"cmp-budget-row",children:[(0,a.jsx)("span",{className:"cmp-budget-count",children:h?"Approximate context: ".concat(p," / ").concat(m," tokens"):"Approximate context: ".concat(p," tokens")}),h?(0,a.jsx)("span",{className:eI[f],"aria-label":"Context pressure: ".concat(eE[f]),children:eE[f]}):null,(0,a.jsx)("span",{className:"cmp-budget-info",role:"img",tabIndex:0,"aria-label":eT,"data-tip":eT,children:"i"}),i?(0,a.jsxs)("span",{className:"cmp-budget-confirm",children:[(0,a.jsx)("span",{className:"cmp-budget-confirm-label",id:"cmp-budget-confirm-label",children:"Clear history?"}),(0,a.jsx)("button",{type:"button",ref:d,className:"cmp-budget-clear","aria-describedby":"cmp-budget-confirm-label",onClick:function(){n(),r(!1),c(!0),requestAnimationFrame(()=>{var e;return null==(e=u.current)?void 0:e.focus()})},children:"Clear"}),(0,a.jsx)("button",{type:"button",className:"cmp-budget-clear",onClick:function(){r(!1),requestAnimationFrame(()=>{var e;return null==(e=u.current)?void 0:e.focus()})},children:"Cancel"})]}):(0,a.jsx)("button",{type:"button",ref:u,className:"cmp-budget-clear","aria-label":"Clear conversation history for next prompt",onClick:()=>{c(!1),r(!0)},disabled:!0===s,children:"Clear history"}),o?(0,a.jsx)("span",{role:"status",className:"cmp-budget-cleared",children:"History cleared for the next prompt — messages remain saved."}):null]}),g?(0,a.jsx)("div",{id:eR,role:"alert",className:"cmp-budget-alert gw-error",children:"Context exceeds the selected model's window. Clear history or pick a model with a larger context."}):null]})}function eA(e){return e<1024?"".concat(e.toString()," B"):e<1048576?"".concat((e/1024).toFixed(1)," KB"):"".concat((e/1048576).toFixed(1)," MB")}function eM(e){if(e<1e3)return"".concat(e.toString()," ms");if(e<6e4)return"".concat((e/1e3).toFixed(1)," s");let t=Math.floor(e/6e4),n=Math.floor(e%6e4/1e3);return"".concat(t.toString(),"m ").concat(n.toString(),"s")}function eP(e){var t;return null!=(t=({running:"Running",completed:"Completed","dry-run":"Dry run",rejected:"Rejected",cancelled:"Cancelled",failed:"Failed","fix-applied":"Fix applied","fix-proposed":"Fix proposed","investigation-only":"Investigation only"})[e])?t:e}function eD(e){return e<1e3?e.toString():"".concat((e/1e3).toFixed(1),"k")}function eL(e){return Number.isFinite(e)?String(e):"—"}function ez(e,t){return Number.isFinite(e)?t(e):"—"}function eO(e){return e.toLocaleString("en-US")}function eK(e){return e.replaceAll("-"," ")}function eB(e){let{label:t,value:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("dt",{className:"grounded-context-pack-dt",children:t}),(0,a.jsx)("dd",{className:"grounded-context-pack-dd",children:n})]})}function eW(e){let{contextPack:t}=e,{usage:n,budget:l}=t,s=function(e){if("workspace-root"===e.scopeKind)return"workspace root";let t=e.scopeId.slice(-8);return"".concat(eK(e.scopeKind)," (").concat(t,")")}(t),i="files"===t.scopeKind?"Scope: ".concat(String(t.fileCount)," file").concat(1===t.fileCount?"":"s"," in ").concat(s):"Scope: ".concat(s);return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Context inspection summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:i}),(0,a.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,a.jsx)(eB,{label:"Searched",value:"".concat(String(n.searchCalls)," / ").concat(eL(l.searchCallsMax)," searches")}),(0,a.jsx)(eB,{label:"Read",value:"".concat(String(n.filesRead)," / ").concat(eL(l.filesReadMax)," files")}),(0,a.jsx)(eB,{label:"Bytes",value:"".concat(eA(n.excerptBytes)," / ").concat(ez(l.excerptBytesMax,eA))}),(0,a.jsx)(eB,{label:"Input",value:"".concat(eO(n.modelInputTokens)," / ").concat(ez(l.modelInputTokensMax,eO)," tokens")}),(0,a.jsx)(eB,{label:"Output",value:"".concat(eO(n.modelOutputTokens)," / ").concat(ez(l.modelOutputTokensMax,eO)," tokens")}),(0,a.jsx)(eB,{label:"Rerank",value:"".concat(String(n.rerankCalls)," / ").concat(eL(l.rerankCallsMax)," calls")}),(0,a.jsx)(eB,{label:"Time",value:"".concat(eM(t.elapsedMs)," / ").concat(ez(l.elapsedMsMax,eM))}),(0,a.jsx)(eB,{label:"Query",value:eK(t.queryKind)})]})]})}function eU(e){let{score:t}=e;return(0,a.jsxs)("span",{className:"grounded-citation-score",children:[(0,a.jsx)("span",{className:"sr-only",children:"relevance "}),t.toFixed(2)]})}function e_(e){let{citation:t}=e;return(0,a.jsxs)("span",{className:"grounded-citation",title:function(e){let t="relevance ".concat(e.score.toFixed(2));return void 0===e.lineRange?"Evidence citation in ".concat(e.scopePath," — ").concat(t):"Evidence citation in ".concat(e.scopePath," at lines ").concat(String(e.lineRange.startLine),"-").concat(String(e.lineRange.endLine)," — ").concat(t)}(t),children:[(0,a.jsx)("span",{children:void 0===t.lineRange?t.scopePath:"".concat(t.scopePath,":").concat(String(t.lineRange.startLine),"-").concat(String(t.lineRange.endLine))}),(0,a.jsx)(eU,{score:t.score})]})}function eH(e){let{total:t,expanded:n,onToggle:l}=e;return t<=8?null:(0,a.jsx)("button",{type:"button",className:"grounded-citations-more","aria-expanded":n,onClick:l,children:n?"Show fewer sources":"Show all ".concat(String(t)," sources")})}function eG(e){let{citations:t}=e,[n,s]=(0,l.useState)(!1);if(0===t.length)return null;let i=[...t].sort((e,t)=>t.score-e.score),r=n?i:i.slice(0,8);return(0,a.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,a.jsx)("span",{className:"grounded-citations-label",children:"Evidence"}),(0,a.jsx)("ul",{className:"grounded-citations","aria-label":"Evidence citations",children:r.map(e=>(0,a.jsx)("li",{className:"grounded-citations-item",children:(0,a.jsx)(e_,{citation:e})},e.stableId))}),(0,a.jsx)(eH,{total:i.length,expanded:n,onToggle:()=>{s(e=>!e)}})]})}function eJ(e){let{citations:t}=e,[n,s]=(0,l.useState)(!1);if(0===t.length)return null;let i=[...t].sort((e,t)=>t.score-e.score),r=n?i:i.slice(0,8);return(0,a.jsxs)("div",{className:"grounded-citations-wrap",children:[(0,a.jsx)("span",{className:"grounded-citations-label",children:"Knowledge citations"}),(0,a.jsx)("ul",{className:"grounded-citations","aria-label":"Knowledge citations",children:r.map(e=>(0,a.jsx)("li",{className:"grounded-citations-item",children:(0,a.jsxs)("span",{className:"grounded-citation",title:void 0===e.source?"".concat(e.label," — relevance ").concat(e.score.toFixed(2)):"".concat(e.source," \xb7 ").concat(e.label," — relevance ").concat(e.score.toFixed(2)),children:[(0,a.jsx)("span",{children:void 0===e.source?"".concat(e.marker," ").concat(e.label):"".concat(e.marker," ").concat(e.source," \xb7 ").concat(e.label)}),(0,a.jsx)(eU,{score:e.score})]})},e.stableId))}),(0,a.jsx)(eH,{total:i.length,expanded:n,onToggle:()=>{s(e=>!e)}})]})}function eV(e){let{markers:t}=e;if(0===t.length)return null;let n=Array.from(new Set(t.map(e=>eK(e.kind)))).join(", ");return(0,a.jsxs)("div",{className:"grounded-uncertainty",role:"note",children:[(0,a.jsx)("div",{children:"Uncertainty (".concat(String(t.length)," markers — ").concat(n,")")}),(0,a.jsx)("ul",{className:"grounded-uncertainty-list",children:t.map((e,t)=>(0,a.jsx)("li",{children:"".concat(eK(e.kind),": ").concat(e.claim)},"".concat(e.kind,"-").concat(String(t))))})]})}function eX(e){let{omittedCount:t,omittedCounts:n}=e;if(t<=0)return null;let l=Object.entries(n).filter(e=>{let[,t]=e;return t>0}).sort((e,t)=>{let[n]=e,[a]=t;return n<a?-1:+(n>a)}).map(e=>{let[t,n]=e;return"".concat(eK(t),": ").concat(String(n))}).join(", "),s=l.length>0?" (".concat(l,")"):"";return(0,a.jsx)("div",{className:"grounded-meta",children:"Not used: ".concat(String(t)," excerpt").concat(1===t?"":"s").concat(s)})}let eY=[{reason:"size-exceeded",label:"larger than 2 MB"},{reason:"binary",label:"binary or an unsupported format"},{reason:"generated",label:"generated artifacts"},{reason:"budget-exhausted",label:"skipped after the exploration budget was reached"},{reason:"tool-unavailable",label:"unreadable"}];function eZ(e){let{omittedCounts:t}=e,n=eY.map(e=>{let{reason:n,label:a}=e;return{label:a,count:t[n]}}).filter(e=>e.count>0),l=n.reduce((e,t)=>e+t.count,0);if(l<=0)return null;let s=n.map(e=>"".concat(String(e.count)," ").concat(e.label)).join(", ");return(0,a.jsxs)("div",{className:"grounded-coverage-notice",role:"note",children:[(0,a.jsx)("span",{className:"grounded-coverage-notice-title",children:"Partial coverage"}),(0,a.jsx)("span",{children:"This answer reflects only the searchable files in the connected scope — ".concat(String(l)," ").concat(1===l?"file":"files"," ").concat(1===l?"was":"were"," not searched (").concat(s,"). It does not cover the entire folder.")})]})}function eQ(e){let{runId:t}=e;return void 0===t?null:(0,a.jsx)("div",{className:"grounded-meta",children:(0,a.jsx)("a",{className:"sm-link",href:"/api/evidence/".concat(encodeURIComponent(t)),target:"_blank",rel:"noopener noreferrer",children:"View connected-context audit evidence"})})}function e$(e){let{contextPack:t}=e;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Knowledge scope summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:"Knowledge scope: ".concat(t.scopeLabel)}),(0,a.jsxs)("dl",{className:"grounded-context-pack-dl",children:[(0,a.jsx)(eB,{label:"Mode",value:eK(t.scopeKind)}),(0,a.jsx)(eB,{label:"Capsules",value:String(t.capsuleCount)}),(0,a.jsx)(eB,{label:"Sources",value:String(t.sourceCount)}),(0,a.jsx)(eB,{label:"Citations",value:String(t.citationCount)}),(0,a.jsx)(eB,{label:"Context budget",value:"".concat(String(t.referencesUsed)," / ").concat(String(t.referenceBudget)," references")})]})]})}function e0(e){let{contextPack:t}=e;return(0,a.jsxs)("section",{className:"grounded-context-pack","aria-label":"Hybrid source summary",children:[(0,a.jsx)("div",{className:"grounded-context-pack-headline",children:"Hybrid: ".concat(String(t.folderSourceCount)," folder source").concat(1===t.folderSourceCount?"":"s"," + ").concat(String(t.connectorSourceCount)," connector source").concat(1===t.connectorSourceCount?"":"s")}),(0,a.jsx)(eW,{contextPack:t.folder}),(0,a.jsx)(e$,{contextPack:t.knowledge})]})}function e1(e){let{answer:t,busy:n}=e;return void 0===t?n?(0,a.jsx)("div",{className:"grounded-meta",children:"Searching connected sources and asking Keiko…"}):null:"local-knowledge"===t.groundingKind?(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)(eJ,{citations:t.citations}),(0,a.jsx)(eV,{markers:t.uncertainty}),(0,a.jsx)(e$,{contextPack:t.contextPack})]}):"hybrid"===t.groundingKind?(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)(eZ,{omittedCounts:t.contextPack.folder.omittedCounts}),(0,a.jsx)(eG,{citations:t.citations}),(0,a.jsx)(eJ,{citations:t.knowledgeCitations}),(0,a.jsx)(eV,{markers:t.uncertainty}),(0,a.jsx)(eX,{omittedCount:t.omittedCount,omittedCounts:t.contextPack.folder.omittedCounts}),(0,a.jsx)(eQ,{runId:t.evidenceRunId}),(0,a.jsx)(e0,{contextPack:t.contextPack})]}):(0,a.jsxs)("div",{className:"grounded-answer",children:[(0,a.jsx)(eZ,{omittedCounts:t.contextPack.omittedCounts}),(0,a.jsx)(eG,{citations:t.citations}),(0,a.jsx)(eV,{markers:t.uncertainty}),(0,a.jsx)(eX,{omittedCount:t.omittedCount,omittedCounts:t.contextPack.omittedCounts}),(0,a.jsx)(eQ,{runId:t.evidenceRunId}),(0,a.jsx)(eW,{contextPack:t.contextPack})]})}let e2=["<script","</script","<iframe","</iframe","<object","</object","<embed","</embed","<style","</style","<svg","</svg","<form","</form","<meta","<link","<base"],e3=[" ","\n"," ","'",'"'];function e4(e){var t;let n=function(e){let t=e.toLowerCase().replaceAll("\0",""),n="";for(let e=0;e<t.length;e++){var a;let l=null!=(a=t[e])?a:"";if("<"===l){for(n+="<";e+1<t.length&&(" "===t[e+1]||" "===t[e+1]||"\n"===t[e+1]||"\r"===t[e+1]);)e++;continue}n+=l}return n}(e);for(let e of e2)if(n.includes(e))return!0;let a=0;for(;a<n.length-4;){let e=n[a];if(e3.includes(e)&&"o"===n[a+1]&&"n"===n[a+2]){let e=a+3;for(;e<n.length&&/[a-z]/.test(null!=(t=n[e])?t:"");)e++;if(e<n.length&&"="===n[e])return!0}a++}return!1}function e6(e,t,n,a){a>n&&e.push({kind:"text",text:t.slice(n,a)})}function e5(e){return void 0!==e&&/[A-Za-z0-9]/.test(e)}let e8=new Set([" "," ","\n","<",">",'"']),e9=new Set([".",",",")","]","!","?"]);function e7(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(t>=16)return e.length>0?[{kind:"text",text:e}]:[];let n=[],a=0,l=0;for(;a<e.length;){let s=function(e,t,n,a){if("`"!==t[n])return -1;let l=t.indexOf("`",n+1);return -1===l?-1:(e6(e,t,a,n),e.push({kind:"inline-code",text:t.slice(n+1,l)}),l+1)}(n,e,a,l);if(-1!==s||-1!==(s=function(e,t,n,a,l){let s=t[n],i=t[n+1];if(n+1>=t.length||("*"!==s||"*"!==i)&&("_"!==s||"_"!==i))return -1;let r=t.indexOf(s+i,n+2);if(-1===r)return -1;e6(e,t,a,n);let o=t.slice(n+2,r);return e.push({kind:"strong",children:e7(o,l+1)}),r+2}(n,e,a,l,t))||-1!==(s=function(e,t,n,a,l){let s=t[n];if("*"!==s&&"_"!==s||"_"===s&&e5(t[n-1])&&e5(t[n+1])||t[n+1]===s||n>0&&t[n-1]===s)return -1;let i=function(e,t,n){for(let a=n;a<e.length;a++)if(e[a]===t&&e[a-1]!==t&&(a+1>=e.length||e[a+1]!==t))return a;return -1}(t,s,n+1);return -1===i||"_"===s&&e5(t[i-1])&&e5(t[i+1])?-1:(e6(e,t,a,n),e.push({kind:"em",children:e7(t.slice(n+1,i),l+1)}),i+1)}(n,e,a,l,t))||-1!==(s=function(e,t,n,a){if("["!==t[n])return -1;let l=t.indexOf("]",n+1);if(-1===l||"("!==t[l+1])return -1;let s=t.indexOf(")",l+2);if(-1===s)return -1;let i=t.slice(n+1,l),r=t.slice(l+2,s);return e6(e,t,a,n),!function(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")}(r)||e4(i)||e4(r)?e.push({kind:"text",text:"[".concat(i,"](").concat(r,")")}):e.push({kind:"link",text:i,href:r}),s+1}(n,e,a,l))||-1!==(s=function(e,t,n,a){if("h"!==t[n])return -1;let l="https://"===t.slice(n,n+8),s="http://"===t.slice(n,n+7);if(!l&&!s)return -1;let i=function(e,t){var n,a;let l=t;for(;l<e.length&&!e8.has(null!=(n=e[l])?n:"");)l++;for(;l>t&&e9.has(null!=(a=e[l-1])?a:"");)l--;return l}(t,n);if(i-n<=(l?8:7))return -1;let r=t.slice(n,i);return e6(e,t,a,n),e.push({kind:"link",text:r,href:r}),i}(n,e,a,l))){l=s,a=s;continue}a++}return e6(n,e,l,e.length),n}function te(e){let t=e.trim(),n=t.startsWith(":"),a=t.endsWith(":");return n&&a?"center":a?"right":n?"left":void 0}function tt(e){let t=e.trim();return t.startsWith("|")&&(t=t.slice(1)),t.endsWith("|")&&(t=t.slice(0,-1)),t.split("|")}function tn(e){var t,n,a;let l=/^( *)([*+\-]) (.*)$/.exec(e);return l?{match:!0,indent:null!=(n=null==(t=l[1])?void 0:t.length)?n:0,text:null!=(a=l[3])?a:""}:{match:!1}}function ta(e){var t,n,a;let l=/^( *)\d+\. (.*)$/.exec(e);return l?{match:!0,indent:null!=(n=null==(t=l[1])?void 0:t.length)?n:0,text:null!=(a=l[2])?a:""}:{match:!1}}function tl(e){return e.includes("|")}function ts(e){let t=e.trim();return/^(-{3,}|\*{3,}|_{3,})$/.test(t)}function ti(e,t){let n=[],a=t?ta:tn;for(;e.i<e.lines.length;){var l;let t=null!=(l=e.lines[e.i])?l:"",s=a(t);if(s.match)n.push({text:s.text,indent:s.indent}),e.i++;else if(""===t.trim())break;else break}return function e(t,n,a){let l=n?"ol":"ul",s=[],i=0;for(;i<t.length;){let l=t[i];if(void 0===l){i++;continue}let r=l.indent,o=[];for(i++;i<t.length;){let e=t[i];if(void 0===e||e.indent<=r)break;o.push(e),i++}let c=[...e7(l.text)];o.length>0&&a<16?c.push(e(o,n,a+1)):o.length>0&&c.push({kind:"text",text:o.map(e=>e.text).join("\n")}),s.push({kind:"li",children:c})}return{kind:l,children:s}}(n,t,e.depth)}function tr(e){let{text:t}=e,[n,s]=(0,l.useState)(!1),[i,r]=(0,l.useState)(""),o=(0,l.useCallback)(()=>{var e;if("undefined"==typeof navigator||(null==(e=navigator.clipboard)?void 0:e.writeText)===void 0)return void r("Copy unavailable: the clipboard requires a secure (HTTPS) connection.");navigator.clipboard.writeText(t).then(()=>{s(!0),r("Code copied"),setTimeout(()=>{s(!1),r("")},1500)},()=>{})},[t]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"sm-code-copy","aria-label":n?"Copied":"Copy code block",title:n?"Copied!":"Copy code block","data-copied":n?"true":"false",onClick:o,children:n?"Copied":"Copy"}),(0,a.jsx)("span",{role:"status",className:"sr-only",children:i})]})}let to={1:"h3",2:"h4",3:"h5",4:"h6",5:"h6",6:"h6"},tc={1:"sm-h sm-h1",2:"sm-h sm-h2",3:"sm-h sm-h3",4:"sm-h sm-h4",5:"sm-h sm-h5",6:"sm-h sm-h6"};function td(e,t){return void 0===e.children?null:e.children.map((e,n)=>tu(e,t+"-"+String(n)))}function tu(e,t){let n=function(e,t){var n,l;switch(e.kind){case"paragraph":return(0,a.jsx)("p",{className:"sm-p",children:td(e,t)},t);case"heading":{let l=null!=(n=e.level)?n:1,s=to[l],i=tc[l];return(0,a.jsx)(s,{className:i,children:td(e,t)},t)}case"blockquote":return(0,a.jsx)("blockquote",{className:"sm-blockquote",children:td(e,t)},t);case"hr":return(0,a.jsx)("hr",{className:"sm-hr"},t);case"code-block":{let n=e.language,s=null!=(l=e.text)?l:"",i=void 0!==n?"lang-".concat(n):void 0;return(0,a.jsxs)("div",{className:"sm-code-block-frame",children:[(0,a.jsxs)("div",{className:"sm-code-block-header",children:[(0,a.jsx)("span",{className:"sm-code-lang",children:null!=n?n:"text"}),(0,a.jsx)(tr,{text:s})]}),(0,a.jsx)("pre",{className:"sm-pre",children:(0,a.jsx)("code",{className:i,children:s})})]},t)}default:return null}}(e,t);if(null!==n)return n;let l=function(e,t){switch(e.kind){case"ul":return(0,a.jsx)("ul",{className:"sm-ul",children:td(e,t)},t);case"ol":return(0,a.jsx)("ol",{className:"sm-ol",children:td(e,t)},t);case"li":return(0,a.jsx)("li",{className:"sm-li",children:td(e,t)},t);default:return null}}(e,t);if(null!==l)return l;let s=function(e,t){let n=void 0!==e.align?{textAlign:e.align}:void 0;switch(e.kind){case"table":return(0,a.jsx)("div",{className:"sm-table-wrapper",children:(0,a.jsx)("table",{className:"sm-table",children:td(e,t)})},t);case"thead":return(0,a.jsx)("thead",{children:td(e,t)},t);case"tbody":return(0,a.jsx)("tbody",{children:td(e,t)},t);case"tr":return(0,a.jsx)("tr",{children:td(e,t)},t);case"th":return(0,a.jsx)("th",{style:n,children:td(e,t)},t);case"td":return(0,a.jsx)("td",{style:n,children:td(e,t)},t);default:return null}}(e,t);if(null!==s)return s;let i=function(e,t){switch(e.kind){case"text":return(0,a.jsx)("span",{children:e.text},t);case"inline-code":return(0,a.jsx)("code",{className:"sm-inline-code",children:e.text},t);case"link":return(0,a.jsxs)("a",{href:e.href,className:"sm-link",rel:"noopener noreferrer",target:"_blank",children:[e.text,(0,a.jsx)("span",{className:"sr-only",children:" (opens in new tab)"})]},t);case"strong":return(0,a.jsx)("strong",{children:td(e,t)},t);case"em":return(0,a.jsx)("em",{children:td(e,t)},t);default:return null}}(e,t);return null!==i?i:null}function th(e){let{source:t}=e,n=function e(t,n){let a=[],l={lines:t.split("\n"),i:0,depth:n};for(;l.i<l.lines.length;)!function(t,n){var a,l;let s=null!=(a=t.lines[t.i])?a:"";if(""===s.trim())return t.i++;if(function(e,t,n){var a;let l=/^(`{3,}|~{3,})(\S*)/.exec(t.trim());if(null===l)return!1;let s=null!=(a=l[1])?a:"```",i=l[2],r=void 0!==i&&i.length>0?i:void 0;return n.push(function(e,t,n){let a=[];for(e.i++;e.i<e.lines.length;){var l,s,i;let n=null!=(l=e.lines[e.i])?l:"",r=/^(`{3,}|~{3,})\s*$/.exec(n.trim());if(null!==r){let n=null!=(s=r[1])?s:"";if(n.startsWith(null!=(i=t[0])?i:"")&&n.length>=t.length){e.i++;break}}a.push(n),e.i++}let r={kind:"code-block",text:a.join("\n")};return void 0!==n?{...r,language:n}:r}(e,s,r)),!0}(t,s,n)||function(e,t,n){var a,l;let s=/^(#{1,6}) (.+)$/.exec(t.trim());if(null===s)return!1;let i=Math.min((null!=(a=s[1])?a:"").length,6),r=null!=(l=s[2])?l:"";return n.push({kind:"heading",level:i,children:e7(r)}),e.i++,!0}(t,s,n))return;if(ts(s)){n.push({kind:"hr"}),t.i++;return}if(s.trimStart().startsWith("> ")||">"===s.trim())return n.push(function(t){let n=[];for(;t.i<t.lines.length;){var a;let e=null!=(a=t.lines[t.i])?a:"";if(e.trimStart().startsWith("> ")||">"===e.trim())n.push(e.replace(/^( *)> ?/,"")),t.i++;else break}let l=n.join("\n");return t.depth>=16?{kind:"blockquote",children:[{kind:"paragraph",children:[{kind:"text",text:l}]}]}:{kind:"blockquote",children:[...e(l,t.depth+1)]}}(t));if(tl(s.trim())&&function(e){if(0===e.length)return!1;for(let t of e){let e=t.trim().replace(/^:/,"").replace(/:$/,"");if(!/^-+$/.test(e))return!1}return!0}(tt(null!=(l=t.lines[t.i+1])?l:""))&&(n.push(function(e,t){var n,a;e.i++;let l=null!=(n=e.lines[e.i])?n:"",s=[];for(e.i++;e.i<e.lines.length;){let t=null!=(a=e.lines[e.i])?a:"";if(""===t.trim()||!tl(t.trim()))break;s.push(t),e.i++}let i=tt(t),r=tt(l).map(te);return{kind:"table",children:[{kind:"thead",children:[{kind:"tr",children:i.map((e,t)=>(function(e,t){let n={kind:"th",children:e7(e.trim())};return void 0!==t?{...n,align:t}:n})(e,r[t]))}]},{kind:"tbody",children:s.map(e=>({kind:"tr",children:tt(e).map((e,t)=>(function(e,t){let n={kind:"td",children:e7(e.trim())};return void 0!==t?{...n,align:t}:n})(e,r[t]))}))}]}}(t,s)),1)||(tn(s).match?(n.push(ti(t,!1)),!0):!!ta(s).match&&(n.push(ti(t,!0)),!0)))return;let i=function(e){let t=[];for(;e.i<e.lines.length;){var n;let a=null!=(n=e.lines[e.i])?n:"";if(function(e){let t=e.trim();return!!(""===t||/^#{1,6} /.test(t)||e.trimStart().startsWith("> ")||/^(`{3,}|~{3,})/.test(t))||!!tn(e).match||!!ta(e).match||ts(e)}(a))break;t.push(a),e.i++}return 0===t.length?null:{kind:"paragraph",children:e7(t.join(" "))}}(t);null!==i&&n.push(i)}(l,a);return a}(t,0);return(0,a.jsx)("div",{className:"sm-root",children:n.map((e,t)=>tu(e,String(t)))})}class tp extends l.Component{static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?(0,a.jsx)("div",{className:"sm-root sm-fallback","data-markdown-fallback":"true",children:this.props.source}):(0,a.jsx)(th,{source:this.props.source})}constructor(...e){super(...e),this.state={failed:!1}}}function tm(e){var t;let{attachment:n,onRemove:l}=e,s="Remove attachment ".concat(n.name),i=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:32;if(e.length<=t)return e;let n=e.lastIndexOf(".");if(n>0&&e.length-n<=8){let a=e.slice(n);return"".concat(e.slice(0,t-a.length-1),"…").concat(a)}return"".concat(e.slice(0,t-1),"…")}(n.name);return(0,a.jsxs)("div",{className:"attach-chip",role:"listitem",children:["image"===n.kind&&void 0!==n.previewDataUrl?(0,a.jsx)("img",{src:n.previewDataUrl,alt:"",className:"attach-chip-thumb",width:40,height:40}):(0,a.jsx)("span",{className:"attach-chip-icon","aria-hidden":"true",children:(0,a.jsx)(N.F.file,{size:16})}),(0,a.jsx)("span",{className:"attach-chip-name",title:n.name,children:i}),(0,a.jsx)("span",{className:"attach-chip-size",children:(t=n.sizeBytes)<1024?"".concat(String(t)," B"):t<1048576?"".concat((t/1024).toFixed(1)," KB"):"".concat((t/1048576).toFixed(1)," MiB")}),(0,a.jsx)("button",{type:"button",className:"attach-chip-remove","aria-label":s,onClick:()=>l(n.id),children:(0,a.jsx)(N.F.close,{size:12})})]})}function tf(e){let{attachments:t,onRemove:n}=e;return 0===t.length?null:(0,a.jsx)("div",{className:"attach-strip",role:"list","aria-label":"Pending attachments",children:t.map(e=>(0,a.jsx)(tm,{attachment:e,onRemove:n},e.id))})}function tg(e){let{enabled:t,onFiles:n}=e,[s,i]=(0,l.useState)(!1),[r,o]=(0,l.useState)(!1);(0,l.useEffect)(()=>{if(!t)return;let e=0,n=t=>{var n,a;Array.from(null!=(a=null==(n=t.dataTransfer)?void 0:n.types)?a:[]).includes("Files")&&(e+=1,o(!0))},a=()=>{0===(e=Math.max(0,e-1))&&o(!1)},l=()=>{e=0,o(!1)};return window.addEventListener("dragenter",n),window.addEventListener("dragleave",a),window.addEventListener("drop",l),window.addEventListener("dragend",l),()=>{window.removeEventListener("dragenter",n),window.removeEventListener("dragleave",a),window.removeEventListener("drop",l),window.removeEventListener("dragend",l)}},[t]);let c=(0,l.useCallback)(e=>{t&&(e.preventDefault(),i(!0))},[t]),d=(0,l.useCallback)(()=>{i(!1)},[]),u=(0,l.useCallback)(e=>{if(e.preventDefault(),i(!1),!t)return;let a=Array.from(e.dataTransfer.files);a.length>0&&n(a)},[t,n]);return t?(0,a.jsx)("div",{className:"attach-drop-zone","data-dragover":s?"true":void 0,"data-active":r?"true":"false","aria-hidden":"true",onDragOver:c,onDragLeave:d,onDrop:u,children:(0,a.jsx)("span",{className:"attach-drop-hint",children:"Drop files here to attach"})}):null}let tv="cmp-attach-disabled-hint";function tx(e){let{model:t,onFiles:n,anyModelSupportsAttachments:s=!0}=e,i=(0,l.useRef)(null),r=void 0!==t&&(t.supportsImageInput||t.supportsDocumentInput),o=function(e){if(void 0===e)return"";let t=[];return e.supportsImageInput&&t.push("image/*"),e.supportsDocumentInput&&t.push(".pdf,.txt,.md,.csv,.json,.yaml,.yml"),t.join(",")}(t),c=(0,l.useCallback)(()=>{var e;r&&(null==(e=i.current)||e.click())},[r]),d=(0,l.useCallback)(()=>{var e,t;let a=Array.from(null!=(t=null==(e=i.current)?void 0:e.files)?t:[]);a.length>0&&(n(a),null!==i.current&&(i.current.value=""))},[n]);return(0,a.jsxs)(a.Fragment,{children:[r?null:(0,a.jsx)("span",{id:tv,className:"sr-only",children:s?"The selected model does not support image or document input. Choose a different model to attach files.":"The selected model does not support image or document input. No configured model currently supports attachments."}),(0,a.jsx)("input",{ref:i,type:"file",multiple:!0,accept:o,className:"sr-only",tabIndex:-1,"aria-hidden":"true",onChange:d}),(0,a.jsx)("button",{type:"button",className:"cmp-icon","aria-label":"Attach file","aria-disabled":r?void 0:"true","aria-describedby":r?void 0:tv,title:r?"Attach file":"Attachments not supported by this model",onClick:c,children:(0,a.jsx)(N.F.files,{size:16})})]})}function ty(e){let{reason:t,mimeType:n}=e;return void 0===t?null:(0,a.jsx)("div",{role:"alert",className:"attach-rejection-alert",children:function(e,t){switch(e){case"text-only-model":return"The selected model can't accept this attachment type. Choose a model that supports images or documents.";case"unsupported-type":return"Unsupported file type".concat(void 0!==t&&t.length>0?": ".concat(t):"",". Supported types: images (image/*), PDF, plain text, markdown, JSON, YAML.");case"oversized":return"File is larger than the 8 MiB limit. Choose a smaller file or summarize the content as text.";case"empty":return"Empty file. Add a file with content to attach."}}(t,n)})}function tb(e){let{documents:t}=e;if(0===t.length)return null;let n=t.some(e=>e.truncated);return(0,a.jsxs)("div",{role:"note",className:"sent-docs-note","aria-label":"Documents included as context",children:[(0,a.jsx)("span",{className:"sent-docs-note-label",children:1===t.length?"Document included as context:":"Documents included as context:"}),(0,a.jsx)("ul",{className:"sent-docs-note-list",children:t.map(e=>(0,a.jsxs)("li",{className:"sent-docs-note-item",children:[e.displayName,e.truncated?(0,a.jsx)("span",{className:"sent-docs-note-trunc",children:" (truncated)"}):null]},e.id))}),n?(0,a.jsx)("span",{className:"sent-docs-note-hint",children:"Some document text was truncated to fit the context limit."}):null]})}var tj=n(7509);let tw=[{workflowId:"unit-test-generation",label:"Generate unit tests",description:"Drafts a reviewable unit-test patch for a target file. Dry-run only from chat — apply from the workflow view.",prompt:"Target file (workspace-relative)",placeholder:"src/example.ts",buildInput:(e,t)=>({workspaceRoot:e,target:{kind:"file",filePath:t.trim()}})},{workflowId:"bug-investigation",label:"Investigate bug",description:"Investigates a reported issue and proposes a root-cause hypothesis. Dry-run only from chat.",prompt:"Describe the bug",placeholder:"The login button does nothing when the form is empty…",buildInput:(e,t)=>({workspaceRoot:e,report:{description:t.trim()}})}];function tk(e){return tw.find(t=>t.workflowId===e)}function tN(e){return"chat"===e.kind&&e.toolCalling&&e.structuredOutput}function tS(e){let{selectedModel:t,launch:n}=e,[s,i]=(0,l.useState)(!1),r=(0,l.useRef)(null);return void 0!==t&&tN(t)?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{ref:r,type:"button",className:"cmp-mode",title:"Launch a governed workflow with the current model","aria-haspopup":"dialog","aria-expanded":s,onClick:()=>i(!0),children:[(0,a.jsx)(N.F.spark,{size:14,style:{color:"var(--accent)"}})," Launch workflow",(0,a.jsx)(N.F.chevron,{size:12})]}),s?(0,a.jsx)(tR,{modelId:t.id,launch:n,onClose:()=>{var e;i(!1),null==(e=r.current)||e.focus()}}):null]}):null}function tC(e){return Array.from(e.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))}function tR(e){let{modelId:t,launch:n,onClose:s}=e,i=(0,l.useId)(),r=(0,l.useId)(),[o,c]=(0,l.useState)(),[d,u]=(0,l.useState)(""),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(),g=(0,l.useRef)(null),v=void 0===o?void 0:tk(o);async function x(){if(void 0===v||0===d.trim().length)return;p(!0),f(void 0);let e=await n({workflowId:v.workflowId,modelId:t,text:d});if(p(!1),e.ok)return void s();f(function(e){if(void 0!==e.message&&e.message.length>0)return e.message;switch(e.reason){case"not-workflow-eligible":return"The selected model does not support workflow runs. Pick a model with tool calling and structured output.";case"unknown-workflow":return"That workflow is no longer available.";case"missing-chat":return"Open or create a chat first, then launch the workflow.";case"missing-input":return"Provide an input before launching the workflow.";case"request-failed":return"Could not launch the workflow. Try again, or check the gateway logs.";default:return"Could not launch the workflow."}}(e))}(0,l.useEffect)(()=>{var e;null==(e=g.current)||e.focus()},[]),(0,l.useEffect)(()=>{function e(e){if("Escape"===e.key)return void s();if("Tab"!==e.key)return;let t=g.current;if(null===t)return;let n=tC(t);if(0===n.length){e.preventDefault(),t.focus();return}let a=n[0],l=n[n.length-1],i=document.activeElement;e.shiftKey&&(i===a||i===t)?(e.preventDefault(),null==l||l.focus()):e.shiftKey||i!==l||(e.preventDefault(),null==a||a.focus())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[s]);let y=(0,a.jsx)("div",{ref:g,role:"dialog","aria-modal":"true","aria-labelledby":i,tabIndex:-1,className:"wf-dialog-overlay",children:(0,a.jsxs)("div",{className:"wf-dialog",children:[(0,a.jsx)("h2",{id:i,className:"wf-dialog-title",children:"Launch workflow"}),void 0===v?(0,a.jsx)("ul",{className:"wf-dialog-list","aria-label":"Available workflows",children:tw.map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"wf-dialog-choice",onClick:()=>c(e.workflowId),children:[(0,a.jsx)("span",{className:"wf-dialog-choice-label",children:e.label}),(0,a.jsx)("span",{className:"wf-dialog-choice-desc",children:e.description})]})},e.workflowId))}):(0,a.jsxs)("div",{className:"wf-dialog-form",children:[(0,a.jsx)("p",{className:"wf-dialog-form-desc",children:v.description}),(0,a.jsx)("label",{className:"wf-dialog-field",htmlFor:r,children:v.prompt}),(0,a.jsx)("textarea",{id:r,className:"wf-dialog-input mono",rows:3,placeholder:v.placeholder,value:d,onChange:e=>u(e.target.value)}),void 0!==m?(0,a.jsx)("div",{role:"alert",className:"wf-dialog-error",children:m}):null,(0,a.jsxs)("div",{className:"wf-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"wf-dialog-cancel",onClick:()=>c(void 0),children:"Back"}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-launch",disabled:h||0===d.trim().length,onClick:()=>{x()},children:h?"Launching…":"Launch"})]})]}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-close","aria-label":"Close launch workflow",onClick:s,children:(0,a.jsx)(N.F.close,{size:14})})]})});return"undefined"==typeof document?y:(0,tj.createPortal)(y,document.body)}let tE=[{workflowKind:"unit-test-generation",label:"Generate unit tests",description:"Use the grounded evidence as read-only context and propose in-scope test changes."},{workflowKind:"bug-investigation",label:"Investigate bug",description:"Investigate a bug against the grounded evidence and keep writes inside approved paths."},{workflowKind:"verification",label:"Run verification",description:"Run verification against the grounded workspace context without granting write access."}],tI=["verify","lint","typecheck","tests","manual"];function tT(e){return e.split(/\r?\n|,/).map(e=>e.trim()).filter(e=>e.length>0)}function tF(e){let{answer:t,modelId:n,busy:s,launch:i}=e,[r,o]=(0,l.useState)(!1),c=(0,l.useRef)(null);return void 0===t||"connected-context"!==t.groundingKind||void 0===n?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{ref:c,type:"button",className:"cmp-mode",title:"Launch a governed workflow from this grounded answer","aria-haspopup":"dialog","aria-expanded":r,disabled:!0===s,onClick:()=>o(!0),children:[(0,a.jsx)(N.F.spark,{size:14,style:{color:"var(--accent)"}})," Launch grounded workflow",(0,a.jsx)(N.F.chevron,{size:12})]}),r?(0,a.jsx)(tq,{answer:t,modelId:n,launch:i,onClose:()=>{var e;o(!1),null==(e=c.current)||e.focus()}}):null]})}function tq(e){let{answer:t,modelId:n,launch:s,onClose:i}=e,r=(0,l.useId)(),o=(0,l.useRef)(null),[c,d]=(0,l.useState)(),[u,h]=(0,l.useState)("file"),[p,m]=(0,l.useState)(""),[f,g]=(0,l.useState)(""),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(""),[j,w]=(0,l.useState)(""),[k,S]=(0,l.useState)(""),[C,R]=(0,l.useState)([]),[E,I]=(0,l.useState)(!1),[T,F]=(0,l.useState)();async function q(){if(void 0===c)return;let e=function(e,t,n,a,l,s){if("unit-test-generation"===e){if("changedFiles"===t){let e=tT(n);return 0===e.length?{ok:!1,message:"Provide at least one changed file."}:{ok:!0,input:{target:{kind:"changedFiles",filePaths:e}}}}let e=n.trim();return 0===e.length?{ok:!1,message:"module"===t?"Provide a module directory.":"Provide a target file."}:"module"===t?{ok:!0,input:{target:{kind:"module",moduleDir:e}}}:{ok:!0,input:{target:{kind:"file",filePath:e}}}}if("bug-investigation"===e){let e=tT(l),t=a.trim();return 0===t.length&&0===e.length?{ok:!1,message:"Provide at least a bug description or one suspected target file."}:{ok:!0,input:{report:{...0===t.length?{}:{description:t},...0===e.length?{}:{targetFiles:e}}}}}let i=tT(s);return{ok:!0,input:0===i.length?{}:{targetFiles:i}}}(c,u,p,f,v,y);if(!e.ok)return void F(e.message);if(0===C.length)return void F("Select at least one expected check.");I(!0),F(void 0);let a=await s({assistantMessageId:t.assistantMessageId,modelId:n,workflowKind:c,input:e.input,editablePaths:tT(j),expectedChecks:C,unknowns:tT(k)});if(I(!1),a.ok)return void i();F(function(e){if(e.ok)return"";if(void 0!==e.message&&e.message.length>0)return e.message;switch(e.reason){case"missing-chat":return"Open a chat with the grounded answer you want to hand off.";case"missing-model":return"Pick a model before launching the grounded workflow.";default:return"Could not launch the grounded workflow."}}(a))}(0,l.useEffect)(()=>{var e;null==(e=o.current)||e.focus()},[]),(0,l.useEffect)(()=>{void 0!==c&&R("unit-test-generation"===c?["tests"]:["verify"])},[c]),(0,l.useEffect)(()=>{function e(e){if("Escape"===e.key)return void i();if("Tab"!==e.key)return;let t=o.current;if(null===t)return;let n=tC(t);if(0===n.length){e.preventDefault(),t.focus();return}let a=n[0],l=n[n.length-1],s=document.activeElement;e.shiftKey&&(s===a||s===t)?(e.preventDefault(),null==l||l.focus()):e.shiftKey||s!==l||(e.preventDefault(),null==a||a.focus())}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i]);let A=tE.find(e=>e.workflowKind===c),M=(0,a.jsx)("div",{ref:o,role:"dialog","aria-modal":"true","aria-labelledby":r,tabIndex:-1,className:"wf-dialog-overlay",children:(0,a.jsxs)("div",{className:"wf-dialog",children:[(0,a.jsx)("h2",{id:r,className:"wf-dialog-title",children:"Grounded workflow handoff"}),void 0===A?(0,a.jsx)("ul",{className:"wf-dialog-list","aria-label":"Available grounded workflows",children:tE.map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"wf-dialog-choice",onClick:()=>d(e.workflowKind),children:[(0,a.jsx)("span",{className:"wf-dialog-choice-label",children:e.label}),(0,a.jsx)("span",{className:"wf-dialog-choice-desc",children:e.description})]})},e.workflowKind))}):(0,a.jsxs)("div",{className:"wf-dialog-form",children:[(0,a.jsx)("p",{className:"wf-dialog-form-desc",children:A.description}),"unit-test-generation"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Target mode",(0,a.jsxs)("select",{className:"wf-dialog-input mono",value:u,onChange:e=>h(e.target.value),children:[(0,a.jsx)("option",{value:"file",children:"File"}),(0,a.jsx)("option",{value:"module",children:"Module"}),(0,a.jsx)("option",{value:"changedFiles",children:"Changed files"})]})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["module"===u?"Module directory":"changedFiles"===u?"Changed files (one per line)":"Target file",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:"changedFiles"===u?3:2,value:p,onChange:e=>m(e.target.value),placeholder:"module"===u?"src/components":"changedFiles"===u?"src/a.ts\nsrc/b.ts":"src/example.ts"})]})]}):null,"bug-investigation"===c?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Bug description",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:3,value:f,onChange:e=>g(e.target.value),placeholder:"Describe the failing behavior or regression."})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Suspected target files (one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:v,onChange:e=>x(e.target.value),placeholder:"src/app.ts\\nsrc/lib/foo.ts"})]})]}):null,"verification"===c?(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Target files (optional, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:y,onChange:e=>b(e.target.value),placeholder:"src/app.ts\\nsrc/lib/foo.ts"})]}):null,(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Editable paths (explicit, workspace-relative, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:3,value:j,onChange:e=>w(e.target.value),placeholder:"src/example.test.ts"})]}),(0,a.jsxs)("fieldset",{className:"wf-dialog-field",style:{border:0,padding:0,margin:0},children:[(0,a.jsx)("legend",{children:"Expected checks"}),(0,a.jsx)("div",{className:"wf-dialog-form",style:{gap:8},children:tI.map(e=>(0,a.jsxs)("label",{className:"wf-dialog-choice-desc",style:{display:"flex",gap:8},children:[(0,a.jsx)("input",{type:"checkbox",checked:C.includes(e),onChange:()=>{R(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])}}),(0,a.jsx)("span",{children:e})]},e))})]}),(0,a.jsxs)("label",{className:"wf-dialog-field",children:["Unknowns (optional, one per line)",(0,a.jsx)("textarea",{className:"wf-dialog-input mono",rows:2,value:k,onChange:e=>S(e.target.value),placeholder:"Need confirmation on public API behavior"})]}),void 0!==T?(0,a.jsx)("div",{role:"alert",className:"wf-dialog-error",children:T}):null,(0,a.jsxs)("div",{className:"wf-dialog-actions",children:[(0,a.jsx)("button",{type:"button",className:"wf-dialog-cancel",onClick:()=>d(void 0),children:"Back"}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-launch",disabled:E,onClick:()=>{q()},children:E?"Launching…":"Launch"})]})]}),(0,a.jsx)("button",{type:"button",className:"wf-dialog-close","aria-label":"Close grounded workflow handoff",onClick:i,children:(0,a.jsx)(N.F.close,{size:14})})]})});return"undefined"==typeof document?M:(0,tj.createPortal)(M,document.body)}function tA(e){return"system"===e.role&&"string"==typeof e.runId}function tM(e){var t,n,l;let{message:s}=e,i=null!=(t=s.workflowStatus)?t:"queued",r=null!=(l=null!=(n=s.workflowId)?n:s.taskType)?l:"workflow",o=void 0===s.runId?"":s.runId.slice(0,8);return(0,a.jsxs)("article",{className:"run-summary-card","data-testid":"run-summary-card","data-status":i,role:"group","aria-label":"Workflow run ".concat(r," — ").concat(i),children:[(0,a.jsxs)("header",{className:"run-summary-card-head",children:[(0,a.jsx)(N.F.spark,{size:14,style:{color:"var(--accent)"}}),(0,a.jsx)("span",{className:"run-summary-card-workflow mono",children:r}),(0,a.jsx)("span",{className:"run-summary-card-status","data-status":i,children:i})]}),(0,a.jsxs)("div",{className:"run-summary-card-body",children:[(0,a.jsx)("p",{className:"run-summary-card-line",children:s.content}),void 0!==s.shortResult&&s.shortResult.length>0?(0,a.jsx)("p",{className:"run-summary-card-result",children:s.shortResult}):null,void 0!==s.runId?(0,a.jsxs)("p",{className:"run-summary-card-meta mono",children:["run"," ",(0,a.jsx)("span",{className:"run-summary-card-runshort","data-runid":s.runId,title:s.runId,children:o})]}):null]})]})}function tP(e){let{on:t,onChange:n,label:l}=e;return(0,a.jsx)("button",{type:"button",role:"switch","aria-checked":t,"aria-label":l,className:"auto-toggle".concat(t?" on":""),onClick:()=>{n(!t)},children:(0,a.jsx)("span",{})})}var tD=n(1352),tL=n(2516);let tz="\n…[truncated]",tO=["text/"],tK=new Set(["application/json","application/x-yaml","application/yaml"]),tB=new TextEncoder;function tW(e){return tB.encode(e).length}function tU(e){let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}let t_="".concat(String(256)," KB");function tH(e){return'"'.concat(e,"\" won't be sent — the ").concat(t_," attachment limit was already used by earlier files.")}async function tG(e,t){let n;if(e.remainingAggregate<=0)return tH(tU(t.name));try{n=await t.file.text()}catch(e){var a;return a=tU(t.name),"Couldn't read \"".concat(a,'" — it will be skipped. Your message will be sent without it.')}let l=Math.min(65536,Math.max(e.remainingAggregate-tW(tz),0));if(l<=0)return tH(tU(t.name));let{entry:s,consumed:i}=function(e,t,n){let a=tW(t)>n,l=a?function(e,t){if(t<=0)return"";if(tW(e)<=t)return e;let n=0,a="";for(let l of e){let e=n+tW(l);if(e>t)break;n=e,a+=l}return a}(t,n):t,s=tW(l),i=a?tW(tz):0;return{entry:{id:e.id,displayName:tU(e.name),mimeType:e.mimeType,sizeBytes:e.sizeBytes,extractedBytes:s,truncated:a,truncationMarker:a?tz:void 0,text:l},consumed:s+i}}(t,n,l);if(0===s.text.length)return 0===n.length?void 0:tH(tU(t.name));e.entries.push(s),e.remainingAggregate-=i}async function tJ(e){let t=e.filter(e=>{var t;return t=e.mimeType,!!tO.some(e=>t.startsWith(e))||tK.has(t)}),n=t.slice(0,16),a={entries:[],remainingAggregate:262144},l=[];for(let e of n){let t=await tG(a,e);void 0!==t&&l.push(t)}for(let e of t.slice(16)){var s;l.push((s=tU(e.name),'"'.concat(s,"\" won't be sent — only the first ").concat(String(16)," documents are included.")))}return{entries:a.entries,failures:l}}let tV=["text/"],tX=new Set(["application/pdf","application/json","application/x-yaml","application/yaml"]),tY="New chat",tZ=["completed","failed","cancelled"];function tQ(e){return"idle"!==e&&!tZ.includes(e)}let t$="The conversation context exceeded the model's window. Clear history or pick a larger-context model.",t0=new Set(["CONVERSATION_OVERSIZED_CONTEXT","GATEWAY_CONTEXT_OVERFLOW"]),t1=["context length","context_length_exceeded","max_tokens","too many tokens"];function t2(e){return void 0!==e&&e.contextWindowTokens>0&&"exceeded"===e.pressure}function t3(e){return!function(e){if(e instanceof $.hD&&t0.has(e.code))return!0;let t=e instanceof Error?e.message.toLowerCase():"";return 0!==t.length&&t1.some(e=>t.includes(e))}(e)?ee(e,"Something went wrong. Try again."):t$}function t4(e){return[...e].sort((e,t)=>t.updatedAt-e.updatedAt)}function t6(e){var t;return null==(t=e.find(tL.S_))?void 0:t.id}function t5(e,t){return void 0!==e&&t.some(t=>t.id===e&&(0,tL.S_)(t))?e:t6(t)}let t8={projects:[],chats:[],messages:[],models:[],activeProject:void 0,activeChat:void 0,selectedModel:void 0};async function t9(){var e;let t=(await (0,$.ZC)().catch(()=>({models:[]}))).models.filter(tL.S_),n=t6(t),a=await (0,$.vj)().catch(()=>({projects:[]})),l=null!=(e=a.projects.find(e=>e.available))?e:a.projects[0];if(void 0!==l){let e=t4((await (0,$.Oz)(l.path).catch(()=>({chats:[]}))).chats),n=e[0];if(void 0!==n){let s=await (0,$.T$)(n.id,l.path),i=t5(n.selectedModel,t);return{models:t,selectedModel:i,projects:Array.from(a.projects),activeProject:l,chats:e,activeChat:n,messages:Array.from(s.messages)}}}if(void 0===n)return{models:t,selectedModel:void 0,projects:Array.from(a.projects),activeProject:l,chats:[],activeChat:void 0,messages:[]};let s={modelId:n,title:tY};(null==l?void 0:l.available)===!0&&(s.projectPath=l.path);let i=await (0,$.tA)(s);return{models:t,selectedModel:i.chat.selectedModel,projects:Array.from(i.projects),activeProject:i.project,chats:t4(i.chats),activeChat:i.chat,messages:Array.from(i.messages)}}var t7=n(9389);let ne="cmp-no-model-alert",nt="cmp-send-hint",nn="cmp-loading-status",na="Ask Keiko about your code…",nl="Send message — Enter to send, Shift+Enter for a new line";function ns(e){return t=>{!t.nativeEvent.isComposing&&("Enter"!==t.key||t.shiftKey||(t.preventDefault(),e()))}}let ni=/\s*[[【[]\d+[\]】]]/g;function nr(e){let{content:t}=e,[n,s]=(0,l.useState)(!1),[i,r]=(0,l.useState)(""),o=(0,l.useCallback)(()=>{var e;if("undefined"==typeof navigator||(null==(e=navigator.clipboard)?void 0:e.writeText)===void 0)return void r("Copy unavailable: the clipboard requires a secure (HTTPS) connection.");navigator.clipboard.writeText(t.replace(ni,"")).then(()=>{s(!0),r("Message copied"),setTimeout(()=>{s(!1),r("")},1500)},()=>{})},[t]);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"chat-msg-copy","aria-label":n?"Copied":"Copy message",title:n?"Copied!":"Copy message","data-copied":n?"true":"false",onClick:o,children:n?"Copied":"Copy"}),(0,a.jsx)("span",{role:"status",className:"sr-only",children:i})]})}function no(e){let{message:t}=e;if(tA(t))return(0,a.jsx)(tM,{message:t});let n="user"===t.role;return(0,a.jsx)("article",{className:"chat-msg","data-role":t.role,children:(0,a.jsxs)("div",{className:"chat-msg-bubble",children:[(0,a.jsx)("div",{className:"chat-msg-role",children:n?"You":"Keiko"}),n?t.content:(0,a.jsx)(tp,{source:t.content}),(0,a.jsxs)("div",{className:"chat-msg-foot",children:[(0,a.jsx)("div",{className:"chat-msg-time",title:new Date(t.timestamp).toLocaleString(),children:function(e){let t=new Date(e),n=t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});return t.toDateString()===new Date().toDateString()?n:"".concat(t.toLocaleDateString([],{month:"short",day:"numeric"}),", ").concat(n)}(t.timestamp)}),n?null:(0,a.jsx)(nr,{content:t.content})]})]})})}function nc(){return(0,a.jsx)("article",{className:"chat-msg","data-role":"assistant",children:(0,a.jsxs)("div",{className:"chat-msg-bubble",children:[(0,a.jsx)("div",{className:"chat-msg-role",children:"Keiko"}),(0,a.jsxs)("span",{className:"chat-typing",role:"img","aria-label":"Keiko is responding",children:[(0,a.jsx)("i",{}),(0,a.jsx)("i",{}),(0,a.jsx)("i",{})]})]})})}function nd(e){let{session:t,ready:n,selectedModelCapability:l,onAttachFiles:s,budgetExceeded:i}=e,{models:r,selectedModel:o,setSelectedModel:c,draft:d,noEligibleModels:u,loading:h,sending:p,cancelSend:m,launchWorkflowFromConversation:f}=t,g=u||i||!n,v=0===d.trim().length,x=u?ne:void 0,y=u?ne:i?eR:h?nn:v?nt:void 0,b=u?"No conversation-eligible model is configured — connect a gateway in Settings":"Model",j=h||u?"":null!=o?o:"";return(0,a.jsxs)("div",{className:"cmp-bar",children:[(0,a.jsx)(tx,{model:l,onFiles:s,anyModelSupportsAttachments:r.some(e=>e.supportsImageInput||e.supportsDocumentInput)}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("label",{className:"cmp-model mono",title:b,children:[(0,a.jsx)(N.F.cube,{size:13,style:{color:"var(--accent)"}}),(0,a.jsx)("select",{className:"cmp-model-select",value:j,"aria-label":"Model","aria-disabled":u||h?"true":void 0,"aria-describedby":x,title:b,disabled:h,onChange:e=>{u||h||c(e.target.value)},children:h?(0,a.jsx)("option",{value:"",disabled:!0,children:"Loading models…"}):u?(0,a.jsx)("option",{value:"",children:"No conversation-eligible model"}):r.filter(e=>"chat"===e.kind).map(e=>(0,a.jsx)("option",{value:e.id,children:e.id},e.id))}),(0,a.jsx)(N.F.chevron,{size:12})]}),(0,a.jsx)(tS,{selectedModel:l,launch:f}),null,y===nt?(0,a.jsx)("span",{id:nt,className:"sr-only",children:"Type a message to send"}):null,p?(0,a.jsx)("button",{type:"button",className:"cmp-send cmp-send-cancel","data-on":!0,"aria-label":"Cancel response",title:"Cancel response",onClick:m,children:(0,a.jsx)(N.F.close,{size:16})}):(0,a.jsx)("button",{type:g?"button":"submit",className:"cmp-send","data-on":!g,"aria-disabled":g,"aria-describedby":y,title:u?"No conversation-eligible model is configured — connect a gateway in Settings":i?"Context exceeds the model's window — clear history or pick a larger-context model":h?"Connecting to your gateway":v?"Type a message to send":nl,"aria-label":"Send message",children:(0,a.jsx)(N.F.arrowUp,{size:16})})]})}function nu(){return(0,a.jsx)("div",{id:ne,role:"alert",className:"gw-error cmp-no-model",children:"No conversation-eligible model is configured. Connect a gateway in Settings to enable chat."})}function nh(){return(0,a.jsxs)("div",{id:nn,role:"status",className:"cmp-loading-status",children:[(0,a.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),"Connecting to your gateway…"]})}function np(e){let{status:t}=e,n=function(e){switch(e){case"idle":case"completed":case"failed":return"";case"queued":return"Submitting your message…";case"contacting":return"Contacting model…";case"streaming":return"Receiving response…";case"cancelled":return"Response cancelled."}}(t);return(0,a.jsx)("div",{role:"status","aria-live":"polite","data-send-status":t,className:"cmp-send-status",children:0===n.length?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("span",{className:"cmp-loading-dot","aria-hidden":"true"}),n]})})}function nm(e){let{session:t,ready:n,placeholder:s}=e,{draft:i,loading:r,sending:o,sendStatus:c,setDraft:d,sendMessage:u,models:h,selectedModel:p,pendingAttachments:m,addPendingAttachment:f,removePendingAttachment:g,budget:v,clearHistory:x}=t,y=t2(v),b=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=b.current;null!==e&&(e.style.height="auto",e.style.height="".concat(String(Math.min(e.scrollHeight,220)),"px"))},[i]);let[j,w]=(0,l.useState)(),[k,N]=(0,l.useState)(),S=h.find(e=>e.id===p),C=void 0!==S&&(S.supportsImageInput||S.supportsDocumentInput),R=(0,l.useCallback)(async e=>{let t,n;for(let a of e){let e=await f(a);e.ok||void 0!==t||(t=e.reason,n=a.type)}w(t),N(n)},[f]);return(0,a.jsxs)("div",{className:"cmp-box",children:[(0,a.jsx)(tg,{enabled:C,onFiles:R}),(0,a.jsx)(tf,{attachments:m,onRemove:g}),(0,a.jsx)("textarea",{className:"cmp-input",ref:b,rows:2,value:i,"aria-label":"Chat message",placeholder:s,onChange:e=>d(e.target.value),onKeyDown:ns(u)}),(0,a.jsx)(ty,{reason:j,mimeType:k}),(0,a.jsx)(np,{status:c}),(0,a.jsx)(eq,{budget:v,onClearHistory:x,disabled:o||r}),(0,a.jsx)(nd,{session:t,ready:n,selectedModelCapability:S,onAttachFiles:R,budgetExceeded:y})]})}function nf(e){let{session:t,noEligibleModels:n}=e,{activeProject:l,setDraft:s}=t,i=void 0!==l?["Explain the architecture of ".concat(l.name),"Find a bug in ".concat(l.name),"Write tests for ".concat(l.name)]:["Explain the architecture of this codebase","Find and fix a bug in the workspace store","Write tests for the window manager"];return(0,a.jsxs)("div",{className:"chatw-empty",children:[(0,a.jsx)("h2",{className:"chatw-empty-headline",children:"Start a Keiko conversation"}),(0,a.jsx)("p",{className:"chatw-empty-sub",children:void 0!==l?"Working in ".concat(l.name,". What would you like to explore?"):"Pick a project from the sidebar to scope your workspace, or ask anything below."}),n?null:(0,a.jsx)("div",{className:"chatw-empty-prompts",role:"group","aria-label":"Starter prompts",children:i.map(e=>(0,a.jsxs)("button",{type:"button",className:"suggest",onClick:()=>s(e),children:[(0,a.jsx)(N.F.spark,{size:12,style:{color:"var(--accent)"}}),e]},e))})]})}function ng(){return(0,a.jsxs)("div",{className:"chatw-empty-no-chat",children:[(0,a.jsx)("div",{className:"chatw-empty-no-chat-icon","aria-hidden":"true",children:(0,a.jsx)(N.F.spark,{size:20})}),(0,a.jsx)("p",{className:"chatw-empty-no-chat-label",children:"Pick or start a chat"}),(0,a.jsx)("p",{className:"chatw-empty-no-chat-hint",children:"Select a conversation from the project sidebar, or create a new one to get started."})]})}function nv(e){let{session:t,ready:n}=e,{draft:l,loading:s,sending:i,sendStatus:r,cancelSend:o,setDraft:c,sendMessage:d}=t;return(0,a.jsxs)("form",{className:"composer composer-fill",onSubmit:e=>{e.preventDefault(),d()},children:[(0,a.jsxs)("div",{className:"cmp-box cmp-box-fill",children:[(0,a.jsx)("textarea",{className:"cmp-input cmp-input-mini",value:l,"aria-label":"Chat message",placeholder:s?"Loading…":"Ask Keiko…",onChange:e=>c(e.target.value),onKeyDown:ns(d)}),i?(0,a.jsx)("button",{type:"button",className:"cmp-send cmp-send-float cmp-send-cancel","data-on":!0,"aria-label":"Cancel response",title:"Cancel response",onClick:o,children:(0,a.jsx)(N.F.close,{size:16})}):(0,a.jsx)("button",{type:n?"submit":"button",className:"cmp-send cmp-send-float","data-on":n,"aria-disabled":!n,"aria-label":"Send message",title:nl,children:(0,a.jsx)(N.F.arrowUp,{size:16})})]}),(0,a.jsx)(np,{status:r})]})}function nx(e){let{root:t}=e;return(0,a.jsxs)("div",{className:"chat-ctx",children:[(0,a.jsx)(N.F.files,{size:12})," Context ",(0,a.jsxs)("span",{className:"mono",children:[t,"/"]})]})}function ny(e){var t,n;return(null==(t=e.localKnowledgeScope)?void 0:t.kind)==="capsule"?"capsule:".concat(e.localKnowledgeScope.capsuleId):(null==(n=e.localKnowledgeScope)?void 0:n.kind)==="capsule-set"?"capsule-set:".concat(e.localKnowledgeScope.capsuleSetId):void 0!==e.connectedScope?"files":"none"}function nb(e){return ee(e,"Unable to update knowledge scope.")}function nj(e){let{chat:t,onChatChanged:n,catalog:s}=e,{capsules:i,capsuleSets:r,loadError:o}=s,[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null);async function p(e){d(!0),h(null);try{if("none"===e){let e=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:null});n(e.chat);return}if("files"===e){let e=await (0,$.wi)(t.id,{localKnowledgeScope:null});n(e.chat);return}if(e.startsWith("capsule-set:")){let a=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:{kind:"capsule-set",capsuleSetId:e.slice(12),connectedAtMs:Date.now()}});n(a.chat);return}if(e.startsWith("capsule:")){let a=await (0,$.wi)(t.id,{connectedScope:null,localKnowledgeScope:{kind:"capsule",capsuleId:e.slice(8),connectedAtMs:Date.now()}});n(a.chat)}}catch(e){h(nb(e))}finally{d(!1)}}let m=ny(t),f=function(e,t){let n=t.map(e=>({value:"capsule:".concat(e.id),label:"Knowledge capsule: ".concat(e.displayName)})),a=ny(e);if(!a.startsWith("capsule:")||n.some(e=>e.value===a))return n;let l=a.slice(8);return[...n,{value:a,label:"Knowledge capsule: ".concat(l," (unavailable)")}]}(t,i),g=function(e,t){let n=t.map(e=>({value:"capsule-set:".concat(e.id),label:"Capsule set: ".concat(e.displayName)})),a=ny(e);if(!a.startsWith("capsule-set:")||n.some(e=>e.value===a))return n;let l=a.slice(12);return[...n,{value:a,label:"Capsule set: ".concat(l," (unavailable)")}]}(t,r),v=null!=u?u:o;return(0,a.jsxs)("label",{className:"scope-grounding",children:[(0,a.jsx)("span",{className:"mono",children:"Grounding"}),(0,a.jsxs)("select",{className:"scope-grounding-select",value:m,disabled:c,"aria-label":"Grounding mode",onChange:e=>{p(e.target.value)},children:[(0,a.jsx)("option",{value:"none",children:"Model only"}),(0,a.jsx)("option",{value:"files",disabled:void 0===t.connectedScope,children:"Live Files context"}),f.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value)),g.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))]}),null!==v?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:v}):null]})}function nw(e){let{chat:t,onChatChanged:n,lastGroundedBudgetStatus:s}=e,i=function(){let[e,t]=(0,l.useState)([]),[n,a]=(0,l.useState)([]),[s,i]=(0,l.useState)(null);return(0,l.useEffect)(()=>{let e=!1;return async function(){try{let[n,l]=await Promise.allSettled([(0,t7.xr)(),(0,t7.R3)()]);if("fulfilled"!==n.status)throw n.reason;if(e)return;t(n.value.capsules.filter(e=>"ready"===e.lifecycleState)),"fulfilled"===l.status?a(l.value.capsuleSets):(a([]),i(nb(l.reason)))}catch(t){e||i(nb(t))}}(),()=>{e=!0}},[]),{capsules:e,capsuleSets:n,loadError:s}}();return(0,a.jsxs)("div",{className:"chat-scope-header",children:[(0,a.jsx)(ek,{chat:t,onDisconnect:n,lastGroundedBudgetStatus:s}),(0,a.jsx)(eC,{chat:t,onDisconnect:n,labels:function(e){let t=new Map;for(let n of e.capsules)t.set("capsule:".concat(n.id),"Capsule: ".concat(n.displayName));for(let n of e.capsuleSets)t.set("set:".concat(n.id),"Capsule set: ".concat(n.displayName));return t}(i)}),(0,a.jsx)(nj,{chat:t,onChatChanged:n,catalog:i})]})}function nk(e){let{chat:t,answer:n,busy:l,selectedModelId:s,launchGroundedWorkflowHandoff:i}=e;if(void 0===t)return null;let r=void 0!==t.connectedScope||void 0!==t.connectedScopes&&t.connectedScopes.length>0,o=void 0!==t.localKnowledgeScope||void 0!==t.localKnowledgeScopes&&t.localKnowledgeScopes.length>0;return(r||o)&&(void 0!==n||l)?(0,a.jsxs)("div",{className:"chatw-grounded",children:[(0,a.jsx)(e1,{answer:n,busy:l}),(0,a.jsx)(tF,{answer:n,modelId:s,busy:l,launch:i})]}):null}function nN(e){let{action:t,acceptCandidate:n,rejectCandidate:s,forgetMemoryAction:i}=e,[r,o]=(0,l.useState)(!1),[c,d]=(0,l.useState)(),[u,h]=(0,l.useState)(!1);if("candidate"===t.kind)return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:t.scopeLabel}),(0,a.jsx)("span",{children:t.requiresApproval?"Approval required":"Proposed memory"})]}),(0,a.jsx)("p",{children:t.body}),(0,a.jsxs)("div",{className:"chat-memory-action-buttons",children:[(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{o(!0),d(void 0),n(t.proposalId).catch(e=>{d(e instanceof Error?e.message:"Unable to accept memory.")}).finally(()=>o(!1))},children:"Accept"}),(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{o(!0),d(void 0),s(t.proposalId).catch(e=>{d(e instanceof Error?e.message:"Unable to reject memory.")}).finally(()=>o(!1))},children:"Reject"})]}),void 0!==c?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:c}):null]});if("update"===t.kind)return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:"MemoriaViva update detected"}),(0,a.jsx)("span",{children:t.memoryId})]}),(0,a.jsx)("p",{children:void 0!==t.bodyPatch?"Suggested update: ".concat(t.bodyPatch):"Suggested update."})]});if("forget"===t.kind){let e=()=>{o(!0),d(void 0),i(t.memoryId).then(()=>h(!1)).catch(e=>{d(e instanceof Error?e.message:"Unable to forget memory.")}).finally(()=>o(!1))};return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsxs)("div",{className:"chat-memory-action-head",children:[(0,a.jsx)("strong",{children:"MemoriaViva forget detected"}),(0,a.jsx)("span",{children:t.requiresConfirmation?"Confirmation required":t.memoryId})]}),(0,a.jsx)("p",{children:"Matched memory ".concat(t.memoryId," for a forget operation.")}),(0,a.jsx)("div",{className:"chat-memory-action-buttons",children:t.requiresConfirmation?u?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",disabled:r,onClick:e,children:"Forget permanently"}),(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{d(void 0),h(!1)},children:"Cancel"})]}):(0,a.jsx)("button",{type:"button",disabled:r,onClick:()=>{d(void 0),h(!0)},children:"Review forget"}):(0,a.jsx)("button",{type:"button",disabled:r,onClick:e,children:"Forget"})}),void 0!==c?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:c}):null]})}return(0,a.jsxs)("article",{className:"chat-memory-action",children:[(0,a.jsx)("div",{className:"chat-memory-action-head",children:(0,a.jsx)("strong",{children:"MemoriaViva action not created"})}),(0,a.jsx)("p",{children:t.reason})]})}function nS(e){var t;let{memoryEnabled:n,setMemoryEnabled:s,memoryBudgetTokens:i,setMemoryBudgetTokens:r,latestMemory:o,acceptCandidate:c,rejectCandidate:d,forgetMemoryAction:u}=e,[h,p]=(0,l.useState)(!1),m="chat-memory-disclosure",f=null!=(t=null==o?void 0:o.context.memories.length)?t:0;return(0,a.jsxs)("section",{className:"chat-memory-panel","aria-label":"Conversation memory",children:[(0,a.jsxs)("div",{className:"chat-memory-panel-head",children:[(0,a.jsxs)("div",{className:"chat-memory-toggle",children:[(0,a.jsx)(tP,{on:n,onChange:s,label:"Enable MemoriaViva for the next request"}),(0,a.jsxs)("span",{children:["MemoriaViva ",n?"on":"off"]})]}),(0,a.jsxs)("label",{className:"chat-memory-budget",children:[(0,a.jsx)("span",{children:"Budget (tokens)"}),(0,a.jsx)("input",{type:"number",min:0,step:100,value:i,onChange:e=>r(Math.max(0,Number(e.target.value)||0))})]}),(0,a.jsx)("button",{type:"button",className:"chip","aria-expanded":h,"aria-controls":m,onClick:()=>p(e=>!e),children:f>0?"".concat(String(f)," memories included"):"No memories included"})]}),h?(0,a.jsxs)("div",{id:m,className:"chat-memory-disclosure",children:[(0,a.jsx)("p",{className:"chat-memory-summary",children:void 0===o?"MemoriaViva disclosure appears after the next response.":o.context.enabled?"Used ".concat(String(o.context.budget.used)," of ").concat(String(o.context.budget.tokens)," MemoriaViva tokens."):"MemoriaViva was disabled for the last request."}),null==o?void 0:o.context.memories.map(e=>(0,a.jsxs)("article",{className:"chat-memory-item",children:[(0,a.jsxs)("div",{className:"chat-memory-item-head",children:[(0,a.jsx)("strong",{children:e.memoryId}),(0,a.jsx)("span",{children:e.inclusionReason})]}),(0,a.jsx)("p",{children:e.bodyExcerpt})]},e.memoryId)),null==o?void 0:o.actions.map(e=>(0,a.jsx)(nN,{action:e,acceptCandidate:c,rejectCandidate:d,forgetMemoryAction:u},"candidate"===e.kind?e.proposalId:"rejected"===e.kind?e.reason:e.memoryId))]}):null]})}function nC(e){let{mini:t=!1,linkedRoot:n=null}=e,s=r(),{messages:i,draft:o,loading:c,sending:d,sendStatus:u,error:h,noEligibleModels:p,selectedModel:m,sendMessage:f,cancelGrounded:g,activeChat:v,replaceChat:x,latestGrounded:y,latestMemory:b,lastSentDocuments:j,memoryEnabled:w,setMemoryEnabled:k,memoryBudgetTokens:N,setMemoryBudgetTokens:S,acceptMemoryCandidate:C,rejectMemoryCandidate:R,launchGroundedWorkflowHandoff:E,forgetMemoryAction:I}=s,T=o.trim().length>0&&!d&&!c&&!p,F=i.filter(e=>"user"===e.role||"assistant"===e.role&&e.content.length>0||tA(e)),q=(0,l.useRef)(null),A=function(e){if(void 0===e)return;let{usage:t,budget:n}=e,a=[ey(t.searchCalls,n.searchCallsMax),ey(t.filesRead,n.filesReadMax),ey(t.excerptBytes,n.excerptBytesMax),ey(t.modelInputTokens,n.modelInputTokensMax),ey(t.modelOutputTokens,n.modelOutputTokensMax),ey(e.elapsedMs,n.elapsedMsMax),ey(t.rerankCalls,n.rerankCallsMax)].filter(e=>void 0!==e),l=0===a.length?0:Math.max(...a),s=l>1?"exceeded":l>=.85?"high":l>=.6?"moderate":"low",i=t.modelInputTokens+t.modelOutputTokens;return{pressure:s,label:ev[s],summary:"Last grounded run: ".concat(i>=1e3?"".concat((i/1e3).toFixed(1),"k"):i.toString()," tokens, ").concat(String(t.filesRead)," files")}}(void 0===y?void 0:"connected-context"===y.groundingKind?y.contextPack:"hybrid"===y.groundingKind?y.contextPack.folder:void 0),M=(0,l.useRef)(!0),P=(0,l.useRef)(!1),D=F.length>0?F[F.length-1]:void 0,L=void 0===D?"":D.content;return((0,l.useEffect)(()=>{d&&!P.current&&(M.current=!0),P.current=d;let e=q.current;null!==e&&M.current&&(e.scrollTop=e.scrollHeight)},[F.length,d,L]),t)?(0,a.jsxs)("div",{className:"chatw chatw-mini",children:[null!==n?(0,a.jsx)(nx,{root:n}):null,void 0!==v?(0,a.jsx)(nw,{chat:v,onChatChanged:x,lastGroundedBudgetStatus:A}):null,p?(0,a.jsx)(nu,{}):null,(0,a.jsx)(nv,{session:s,ready:T}),void 0!==h?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h}):null]}):(0,a.jsxs)("div",{className:"chatw",children:[null!==n?(0,a.jsx)(nx,{root:n}):null,void 0!==v?(0,a.jsx)(nw,{chat:v,onChatChanged:x,lastGroundedBudgetStatus:A}):null,void 0!==v?(0,a.jsx)(nS,{memoryEnabled:w,setMemoryEnabled:k,memoryBudgetTokens:N,setMemoryBudgetTokens:S,latestMemory:b,acceptCandidate:C,rejectCandidate:R,forgetMemoryAction:I}):null,p?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(nu,{})}):null,c?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)(nh,{})}):null,(0,a.jsx)("div",{className:"chatw-scroll",ref:q,role:"log","aria-label":"Conversation",tabIndex:0,onScroll:e=>{let t=e.currentTarget;M.current=t.scrollHeight-t.scrollTop-t.clientHeight<64},children:0===F.length?void 0!==v?(0,a.jsx)(nf,{session:s,noEligibleModels:p}):(0,a.jsx)(ng,{}):(0,a.jsxs)("div",{className:"chatw-log",children:[F.map(e=>(0,a.jsx)(no,{message:e},e.id)),d&&"streaming"!==u?(0,a.jsxs)("div",{className:"chatw-typing-row",children:[(0,a.jsx)(nc,{}),(null==v?void 0:v.connectedScope)!==void 0||(null==v?void 0:v.localKnowledgeScope)!==void 0?(0,a.jsx)("button",{type:"button",className:"grounded-cancel-btn","aria-label":"Cancel grounded request",onClick:g,children:"Cancel"}):null]}):null,(0,a.jsx)(nk,{chat:v,answer:y,busy:d,selectedModelId:m,launchGroundedWorkflowHandoff:E}),(0,a.jsx)(tb,{documents:j})]})}),F.length>0?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsxs)("form",{className:"composer",onSubmit:e=>{e.preventDefault(),f()},children:[(0,a.jsx)(nm,{session:s,ready:T,placeholder:na}),void 0!==h?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h}):null]})}):null,0===F.length&&void 0!==v?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsxs)("form",{className:"composer",onSubmit:e=>{e.preventDefault(),f()},children:[(0,a.jsx)(nm,{session:s,ready:T,placeholder:c?"Connecting to your gateway…":na}),void 0!==h?(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h}):null]})}):null,0===F.length&&void 0!==h&&void 0===v?(0,a.jsx)("div",{className:"chatw-foot",children:(0,a.jsx)("div",{role:"alert",className:"cmp-err",children:h})}):null]})}let nR=["n","s","e","w","ne","nw","se","sw"],nE=["t","r","b","l"];function nI(e){let{icon:t,label:n}=e,l=N.F[t];return(0,a.jsxs)("div",{className:"too-small",children:[(0,a.jsx)("div",{className:"ts-ico",children:(0,a.jsx)(l,{size:28})}),(0,a.jsxs)("div",{className:"ts-title",children:["Too small to show ",n]}),(0,a.jsx)("div",{className:"ts-sub",children:"Enlarge the window or zoom its content out"}),(0,a.jsx)("div",{className:"ts-arrow","aria-hidden":"true",children:(0,a.jsx)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,a.jsx)("path",{d:"M8 8l8 8M16 11v5h-5"})})})]})}function nT(e){var t,n;let{win:s,top:i,connState:r,view:o,api:c,wsRef:d}=e,u=ei[s.type],h=N.F[u.icon],p=null!=(n=s.zoom)?n:1,m="chat"===s.type||"agents"===s.type||"quality"===s.type?c.linkedFilesRoot(s.id):null,f="agents"===s.type||"quality"===s.type?null==(t=c.linkedFilesContext(s.id))?void 0:t.activeFilePath:void 0,g="quality"===s.type?c.linkedAllFilesRoots(s.id):null!==m?[m]:[],v="quality"===s.type?c.linkedConnectorCapsuleIds(s.id):[],x="quality"===s.type?c.linkedConnectorCapsuleSetIds(s.id):[],y="quality"===s.type?c.linkedFigmaSnapshotRunIds(s.id):[],b=s.w/p,j=s.h/p,w=(0,l.useCallback)(e=>{c.update(s.id,{cfg:{...s.cfg,...e}})},[c,s.cfg,s.id]),k=(0,l.useCallback)((e,t)=>c.add(e,t),[c]),{mode:S,node:C}=function(e,t,n,l,s,i,r,o,c,d,u,h){if("chat"===e){let e=t<430||n<430;return{mode:e?"mini":"full",node:(0,a.jsx)(nC,{mini:e,linkedRoot:s})}}let p=ei[e];return t<p.tiny.w||n<p.tiny.h?{mode:"tiny",node:(0,a.jsx)(nI,{icon:p.icon,label:p.title})}:{mode:"full",node:p.render(l,{linkedRoot:s,linkedFilePath:i,linkedRoots:r,linkedCapsuleIds:o,linkedCapsuleSetIds:c,linkedFigmaSnapshotRunIds:d,updateCfg:u,openWindow:h})}}(s.type,b,j,s.cfg,m,f,g,v,x,y,w,k),R=(0,l.useCallback)(e=>c.update(s.id,{zoom:Math.max(.5,Math.min(2,Math.round(10*e)/10))}),[c,s.id]),E=(0,l.useCallback)(e=>{var t,n,a,l;if(0!==e.button||"valid"===r)return;e.preventDefault(),c.focus(s.id);let i=d.current;if(null===i)return;let u=function(e,t){let n=t.zoom;return{z:n,vpx0:-t.x/n,vpy0:-t.y/n,vpw:e.width/n,vph:e.height/n,toWX:a=>(a-e.left-t.x)/n,toWY:a=>(a-e.top-t.y)/n}}(i.getBoundingClientRect(),o),h=s.max,p=h?null!=(a=null==(t=s.prev)?void 0:t.w)?a:480:s.w,m=h?null!=(l=null==(n=s.prev)?void 0:n.h)?l:360:s.h,f=h?p/2:u.toWX(e.clientX)-s.x,g=h?18:u.toWY(e.clientY)-s.y;h&&c.update(s.id,{max:!1,w:p,h:m}),function(e,t,n){let a=30/t.z,l=l=>{let s=t.toWX(l.clientX),i=t.toWY(l.clientY),r=s-n.offX,o=i-n.offY;r=Math.max(t.vpx0-(n.W-120),Math.min(t.vpx0+t.vpw-120,r)),o=Math.max(t.vpy0,Math.min(t.vpy0+t.vph-38,o)),e.setSnap(function(e,t,n,a){let l=e-n.vpx0<a,s=n.vpx0+n.vpw-e<a,i=t-n.vpy0<a,r=n.vpy0+n.vph-t<a;return i&&l?"tl":i&&s?"tr":r&&l?"bl":r&&s?"br":l?"left":s?"right":i?"maxi":null}(s,i,t,a)),e.update(n.winId,{x:r,y:o})},s=()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),e.commitSnap(n.winId),document.body.style.cursor=""};document.body.style.cursor="grabbing",window.addEventListener("pointermove",l),window.addEventListener("pointerup",s)}(c,u,{winId:s.id,offX:f,offY:g,W:p})},[c,s.id,s.x,s.y,s.w,s.h,s.max,s.prev,o,d,r]),I=(0,l.useCallback)(e=>t=>{t.preventDefault(),t.stopPropagation(),c.focus(s.id);let n={x:s.x,y:s.y,w:s.w,h:s.h},a=t.clientX,l=t.clientY,i=o.zoom,r=t=>{let r=function(e,t,n,a,l){let{x:s,y:i,w:r,h:o}=e;t.includes("e")&&(r=e.w+n),t.includes("s")&&(o=e.h+a),t.includes("w")&&(r=e.w-n,s=e.x+n),t.includes("n")&&(o=e.h-a,i=e.y+a);let c=ei[l].min,d=c.w>0?c.w:240,u=c.h>0?c.h:150;return r<d&&(t.includes("w")&&(s-=d-r),r=d),o<u&&(t.includes("n")&&(i-=u-o),o=u),{x:s,y:i,w:r,h:o}}(n,e,(t.clientX-a)/i,(t.clientY-l)/i,s.type);c.update(s.id,{...r,max:!1})},d=()=>{window.removeEventListener("pointermove",r),window.removeEventListener("pointerup",d),document.body.style.cursor=""};document.body.style.cursor="n"===e||"s"===e?"ns-resize":"e"===e||"w"===e?"ew-resize":"ne"===e||"sw"===e?"nesw-resize":"nwse-resize",window.addEventListener("pointermove",r),window.addEventListener("pointerup",d)},[c,s.id,s.x,s.y,s.w,s.h,s.type,o.zoom]),T=(0,l.useCallback)((e,t)=>{let n=e.getBoundingClientRect();c.startConnect(s.id,{clientX:"clientX"in t?t.clientX:n.left+n.width/2,clientY:"clientY"in t?t.clientY:n.top+n.height/2,preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()})},[c,s.id]),F=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),T(e.currentTarget,e)},[T]),q=(0,l.useCallback)(e=>{if("Enter"===e.key||" "===e.key||"Spacebar"===e.key){if("valid"===r)return void c.confirmConnect(s.id,{preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()});e.preventDefault(),e.stopPropagation(),T(e.currentTarget,e)}},[T,r,c,s.id]),A=(0,l.useCallback)(()=>{c.close(s.id),requestAnimationFrame(()=>{var e;let t=null!=(e=document.querySelector('.window[data-top="true"]'))?e:document.querySelector(".ws-fab");null==t||t.focus({preventScroll:!0})})},[c,s.id]),M="full"===S?function(e,t){if(void 0===t)return null;let n=e=>{let n=t[e];return"string"==typeof n&&n.length>0?n:null};switch(e){case"files":return n("root");case"browser":return n("url");case"editor":return n("file");case"terminal":return n("cwd");case"review":{let e=n("base"),t=n("head");return null!==e&&null!==t?"".concat(e," → ").concat(t):null}case"agents":return n("role");case"chat":{let e=n("title");return null!==e&&"New chat"!==e?e:null}default:return null}}(s.type,s.cfg):null,P={left:s.x,top:s.y,width:s.w,height:s.h,zIndex:s.z};return(0,a.jsxs)("section",{className:"window","aria-label":null!==M?"".concat(u.title," — ").concat(M):u.title,"aria-roledescription":"window","data-top":i?"true":"false","data-max":s.max?"true":"false","data-conn":null!=r?r:void 0,"data-window-id":s.id,style:P,tabIndex:-1,onPointerDown:e=>{"valid"===r&&c.confirmConnect(s.id,e),c.focus(s.id)},onFocusCapture:()=>{i||c.focus(s.id)},children:[(0,a.jsxs)("header",{className:"win-head",onPointerDown:E,onDoubleClick:()=>c.maximize(s.id),children:[(0,a.jsx)("span",{className:"win-ico",style:{color:!0===u.accent?"var(--accent)":"var(--fg-muted)"},children:(0,a.jsx)(h,{size:14})}),(0,a.jsx)("span",{className:"win-title",children:u.title}),null!==M?(0,a.jsx)("span",{className:"win-sub mono",title:M,children:M}):null,(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("div",{className:"win-zoom",children:[(0,a.jsx)("button",{type:"button",className:"win-zbtn",title:"Zoom content out","aria-label":"Zoom ".concat(u.title," content out"),disabled:p<=.5,onPointerDown:e=>e.stopPropagation(),onClick:()=>R(p-.1),children:(0,a.jsx)(N.F.zoomOut,{size:13})}),(0,a.jsxs)("button",{type:"button",className:"win-zpct",title:"Reset content zoom to 100%","aria-label":"".concat(String(Math.round(100*p)),"% — reset ").concat(u.title," content zoom"),onPointerDown:e=>e.stopPropagation(),onClick:()=>c.update(s.id,{zoom:1}),children:[Math.round(100*p),"%"]}),(0,a.jsx)("button",{type:"button",className:"win-zbtn",title:"Zoom content in","aria-label":"Zoom ".concat(u.title," content in"),disabled:p>=2,onPointerDown:e=>e.stopPropagation(),onClick:()=>R(p+.1),children:(0,a.jsx)(N.F.zoomIn,{size:13})})]}),(0,a.jsx)("button",{type:"button",className:"win-btn",title:s.max?"Restore":"Maximize","aria-label":s.max?"Restore ".concat(u.title," window"):"Maximize ".concat(u.title," window"),onPointerDown:e=>e.stopPropagation(),onClick:()=>c.maximize(s.id),children:s.max?(0,a.jsx)(N.F.restore,{size:13}):(0,a.jsx)(N.F.maximize,{size:13})}),(0,a.jsx)("button",{type:"button",className:"win-btn win-close",title:"Close","aria-label":"Close ".concat(u.title," window"),onPointerDown:e=>e.stopPropagation(),onClick:A,children:(0,a.jsx)(N.F.close,{size:14})})]}),(0,a.jsx)("div",{className:"win-body","data-mode":S,style:"tiny"===S?{}:{zoom:p},children:C}),s.max?null:nR.map(e=>(0,a.jsx)("div",{className:"wz wz-".concat(e),onPointerDown:I(e)},e)),s.max?null:nE.map(e=>(0,a.jsx)("div",{className:"win-port wp-".concat(e),title:"Click to connect to another window","aria-label":"Connect ".concat(u.title," from ").concat("t"===e?"top":"r"===e?"right":"b"===e?"bottom":"left"," edge"),role:"button",tabIndex:0,onPointerDown:F,onKeyDown:q},"p".concat(e)))]})}let nF=[/\bsk-[A-Za-z0-9_-]{20,}\b/,/\bAKIA[0-9A-Z]{16}\b/,/\bgh[pousr]_[A-Za-z0-9]{36,}\b/,/\bxox[abporsu]-[A-Za-z0-9-]{10,}\b/,/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/,/-----BEGIN [A-Z ]*PRIVATE KEY-----/],nq=/\b(?:\d[ -]?){13,19}\b/g;n(7011);let nA={chat:{lifecycle:["draft","streaming","final","archived"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"durable.ui"},files:{lifecycle:["connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},connector:{lifecycle:["connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},editor:{lifecycle:["viewing","editing","unsaved","saved","error"],trustBoundary:["ui","fs"],authority:"user",persistence:"fs-reference"},browser:{lifecycle:["idle","live","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"transient"},terminal:{lifecycle:["idle","running","blocked","cancelled","error"],trustBoundary:["ui","tool"],authority:"user-confirm",persistence:"transient"},review:{lifecycle:["proposed","needs-review","applied","reverted","archived"],trustBoundary:["ui","evidence"],authority:"user-confirm",persistence:"evidence-reference"},agents:{lifecycle:["proposed","running","blocked","needs-review","verified","cancelled"],trustBoundary:["ui","model","tool","evidence"],authority:"user-confirm",persistence:"durable.ui"},integ:{lifecycle:["idle","connecting","connected","degraded","disconnected","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"durable.config"},keiko:{lifecycle:["live"],trustBoundary:["ui","memory"],authority:"user",persistence:"memory-reference"},settings:{lifecycle:["viewing","editing","saved"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},project:{lifecycle:["none","connecting","connected","disconnected"],trustBoundary:["ui","fs"],authority:"user",persistence:"durable.config"},search:{lifecycle:["idle","searching","results","error"],trustBoundary:["ui","fs"],authority:"read-only",persistence:"transient"},plugins:{lifecycle:["idle","installed","disabled","enabled"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},automations:{lifecycle:["idle","enabled","disabled"],trustBoundary:["ui"],authority:"user",persistence:"durable.config"},mobile:{lifecycle:["paired","unpaired","error"],trustBoundary:["ui","network"],authority:"user-confirm",persistence:"durable.config"},inspector:{lifecycle:["empty","focused"],trustBoundary:["ui"],authority:"ui-only",persistence:"transient"},activity:{lifecycle:["live","archived"],trustBoundary:["ui"],authority:"read-only",persistence:"transient"},notifications:{lifecycle:["unread","read","dismissed"],trustBoundary:["ui"],authority:"ui-only",persistence:"transient"},resources:{lifecycle:["live"],trustBoundary:["ui"],authority:"read-only",persistence:"transient"},quality:{lifecycle:["idle","running","results","error"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"evidence-reference"},qiRun:{lifecycle:["running","final","needs-review","verified","failed","cancelled"],trustBoundary:["ui","model","evidence"],authority:"user-confirm",persistence:"evidence-reference"},relationships:{lifecycle:["idle","live","degraded","blocked","error"],trustBoundary:["ui","evidence"],authority:"user-confirm",persistence:"durable.ui"},figma:{lifecycle:["idle","running","results","error"],trustBoundary:["ui","evidence","network"],authority:"user-confirm",persistence:"evidence-reference"}},nM=["apikey","accesskey","clientsecret","credential","password","privatekey","secret","token"],nP=["api_key=","apikey=","client_secret=","clientsecret=","credential=","authorization:","password=","secret=","token="],nD=[".env",".env.local",".env.development",".env.test",".env.production"];function nL(e){return"number"==typeof e&&Number.isFinite(e)}function nz(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function nO(e){let t=e.trim();if(0===t.length)return!1;let n=t.toLowerCase();return function(e){for(let t of nF)if(t.test(e))return!0;for(let t of e.matchAll(nq)){let e=t[0].replaceAll(/[ -]/g,"");if(e.length>=13&&e.length<=19&&function(e){let t=0,n=!1;for(let a=e.length-1;a>=0;a-=1){let l=Number(e[a]);n&&(l*=2)>9&&(l-=9),t+=l,n=!n}return t%10==0}(e))return!0}return!1}(t)||function(e){let t="bearer ",n=e.toLowerCase().indexOf(t);if(-1===n)return!1;let a=0;for(let s=n+t.length;s<e.length;s+=1){var l;if(0===(null!=(l=e[s])?l:"").trim().length)break;a+=1}return a>=8}(t)||function(e){if(!e.includes("://"))return!1;try{let t=new URL(e);return t.username.length>0||t.password.length>0}catch(e){return!1}}(t)||nP.some(e=>n.includes(e))||function(e){let t=e.toLowerCase().replaceAll("\\","/").split("/");for(let e=0;e<t.length;e+=1){var n,a;let l=null!=(n=t[e])?n:"",s=null!=(a=t[e+1])?a:"";if(nD.includes(l)||".npmrc"===l||"credentials.json"===l||".aws"===l&&"credentials"===s||".ssh"===l&&s.startsWith("id_"))return!0}return!1}(t)}function nK(e){let t=[];for(let n of e){let e=function(e){var t;if(!nz(e)||!("string"==typeof(t=e.type)&&t in ei))return null;let n=e.type;if("transient"===nA[n].persistence||"string"!=typeof e.id||!nL(e.x)||!nL(e.y)||!nL(e.w)||!nL(e.h)||!nL(e.z)||"boolean"!=typeof e.max)return null;let a={id:e.id,type:n,x:e.x,y:e.y,w:e.w,h:e.h,z:e.z,cfg:function(e,t){var n;if(!nz(t)||"durable.config"===nA[e].persistence)return{};let a=new Set((null!=(n=ei[e].config)?n:[]).map(e=>e.key)),l={};for(let[n,s]of Object.entries(t)){if(!a.has(n))continue;let t=function(e,t,n){if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n||function(e){let t=function(e){let t="";for(let n of e.toLowerCase())(n>="a"&&n<="z"||n>="0"&&n<="9")&&(t+=n);return t}(e);return nM.some(e=>t.includes(e))}(t))return;if("string"!=typeof n)return n;let a=nA[e].persistence;return"evidence-reference"===a?!function(e){if(0===e.length||e.length>256||e.startsWith(".")||e.trim()!==e||nO(e))return!1;for(let t of e)if(!function(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||46===t||95===t||45===t}(t))return!1;return!0}(n)?void 0:n:nO(n)?"durable.ui"===a?"[REDACTED]":void 0:n}(e,n,s);void 0!==t&&(l[n]=t)}return l}(n,e.cfg),max:e.max},l=function(e){if(nz(e)&&nL(e.x)&&nL(e.y)&&nL(e.w)&&nL(e.h))return{x:e.x,y:e.y,w:e.w,h:e.h}}(e.prev);return{...a,...void 0!==l?{prev:l}:{},...nL(e.zoom)?{zoom:e.zoom}:{}}}(n);null!==e&&t.push(e)}return t}function nB(e,t){let n=new Set(t.map(e=>e.id)),a=[];for(let t of e)"string"==typeof t.id&&"string"==typeof t.a&&"string"==typeof t.b&&n.has(t.a)&&n.has(t.b)&&a.push({id:t.id,a:t.a,b:t.b});return a}let nW="keiko.workspace.v4",nU="keiko.conns.v1",n_="keiko.view";function nH(){try{let e=window.localStorage.getItem(n_);if(null===e)return{zoom:1,x:0,y:0};let t=JSON.parse(e);if("object"==typeof t&&null!==t&&"zoom"in t&&"number"==typeof t.zoom)return{zoom:t.zoom,x:"number"==typeof t.x?t.x:0,y:"number"==typeof t.y?t.y:0}}catch(e){}return{zoom:1,x:0,y:0}}function nG(e){return Math.max(.3,Math.min(2.5,e))}function nJ(e){return Math.max(.5,Math.min(2,Math.round(10*e)/10))}function nV(e){let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}function nX(e,t){try{window.localStorage.setItem(e,JSON.stringify(t))}catch(e){}}let nY={Equal:"=",NumpadAdd:"+",Minus:"-",NumpadSubtract:"-",Digit0:"0",Numpad0:"0"};function nZ(e,t){let n=e+t;return e<1&&n>1||e>1&&n<1?1:n}function nQ(e){let{wins:t,connecting:n,conns:s}=e,[i,r]=(0,l.useState)(""),o=(0,l.useRef)(null),c=(0,l.useRef)(s.length);return(0,l.useEffect)(()=>{let e=o.current;o.current=n;let a=c.current;if(c.current=s.length,null===e&&null!==n){let e=null==t?void 0:t.find(e=>e.id===n.from),a=void 0!==e?ei[e.type].title:"window";r("Connecting from ".concat(a," — select a highlighted window, press Escape to cancel"));return}if(null!==e&&null===n)if(s.length>a){let e=s[s.length-1],n=void 0!==e?null==t?void 0:t.find(t=>t.id===e.a):void 0,a=void 0!==e?null==t?void 0:t.find(t=>t.id===e.b):void 0;r(void 0!==n&&void 0!==a?"Connected: ".concat(J(n,a)):"Connected")}else r("Connection cancelled")},[n,s,t]),(0,a.jsx)("div",{className:"sr-only","aria-live":"polite",children:i})}function n$(e){var t;let{ws:n,wsRef:s,openPalette:i,palette:r}=e,{wins:o,view:c,snapPrev:d,conns:u,connecting:h,api:p}=n,m=function(e){if(null===e||0===e.length)return null;let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}(o),f=null!==h&&null!==o&&null!=(t=o.find(e=>e.id===h.from))?t:null,g=(0,l.useMemo)(()=>({backgroundSize:"".concat(String(22*c.zoom),"px ").concat(String(22*c.zoom),"px"),backgroundPosition:"".concat(String(c.x),"px ").concat(String(c.y),"px")}),[c]),v=(0,l.useMemo)(()=>({transform:"translate(".concat(String(c.x),"px, ").concat(String(c.y),"px)"),transformOrigin:"0 0",zoom:c.zoom}),[c]),x=null!==o&&0===o.length;return(0,a.jsxs)("main",{className:"workspace",ref:s,"aria-label":"Workspace surface","data-connecting":null!==h?"true":void 0,onPointerDownCapture:e=>{if(0!==e.button||null===h||null===f||null===o)return;let t=function(e){if(!(e instanceof Element))return;let t=e.closest(".window[data-window-id]");return null==t?void 0:t.dataset.windowId}(e.target);if(void 0===t||t===f.id)return;let n=o.find(e=>e.id===t);void 0!==n&&G(f.type,n.type)&&p.confirmConnect(n.id,e)},onPointerDown:e=>{var t;if(0===e.button&&!((t=e.target)instanceof Element&&(null!==t.closest(".window")||null!==t.closest(".ws-zoom")||null!==t.closest(".ws-fab")||null!==t.closest(".ws-empty-btn")||null!==t.closest(".conn-badge")))){if(null!==h)return void p.cancelConnect();!function(e,t){let n=t.clientX,a=t.clientY;document.body.style.cursor="grabbing";let l=t=>{e(t.clientX-n,t.clientY-a),n=t.clientX,a=t.clientY},s=()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",s),document.body.style.cursor=""};window.addEventListener("pointermove",l),window.addEventListener("pointerup",s)}(p.panBy,e)}},children:[(0,a.jsx)(_,{}),(0,a.jsx)("div",{className:"ws-grid",style:g,"aria-hidden":"true"}),(0,a.jsx)(nQ,{wins:o,connecting:h,conns:u}),null!==h?(0,a.jsx)("div",{className:"ws-connect-hint","aria-hidden":"true",children:"Click a highlighted window to connect — Esc to cancel"}):null,x?(0,a.jsxs)("div",{className:"ws-empty",children:[(0,a.jsx)("img",{className:"ws-empty-logo",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsx)("div",{className:"ws-empty-title",children:"Empty workspace"}),(0,a.jsx)("div",{className:"ws-empty-sub",children:"Open a window to start working"}),(0,a.jsxs)("button",{type:"button",className:"ws-empty-btn",onClick:i,children:[(0,a.jsx)(N.F.add,{size:15})," New window"]})]}):null,(0,a.jsxs)("div",{className:"ws-scene",style:v,children:[null!==d?(0,a.jsx)("div",{className:"snap-ghost",style:{left:d.x,top:d.y,width:d.w,height:d.h}}):null,null!==o?(0,a.jsx)(Q,{wins:o,conns:u,connecting:h,api:p}):null,null!==o?o.map(e=>(0,a.jsx)(nT,{win:e,top:null!==m&&e.id===m.id,connState:null===f?null:e.id===f.id?"source":G(f.type,e.type)?"valid":"invalid",view:c,api:p,wsRef:s},e.id)):null]}),(0,a.jsxs)("div",{className:"ws-zoom",children:[(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn",onClick:()=>p.zoomTo(nZ(c.zoom,-.2)),disabled:c.zoom<=.3,"aria-label":"Zoom out",title:"Zoom out",children:(0,a.jsx)(N.F.zoomOut,{size:15})}),(0,a.jsxs)("button",{type:"button",className:"ws-zoom-pct mono",onClick:p.resetView,"aria-label":"".concat(String(Math.round(100*c.zoom)),"% — reset view"),title:"Reset view to 100%",children:[Math.round(100*c.zoom),"%"]}),(0,a.jsx)("button",{type:"button",className:"ws-zoom-btn",onClick:()=>p.zoomTo(nZ(c.zoom,.2)),disabled:c.zoom>=2.5,"aria-label":"Zoom in",title:"Zoom in",children:(0,a.jsx)(N.F.zoomIn,{size:15})})]}),(0,a.jsx)("button",{type:"button",className:"ws-fab",onPointerDown:e=>e.stopPropagation(),onClick:i,"aria-label":"New window",title:"New window",children:(0,a.jsx)(N.F.add,{size:20})}),null!=r?r:null]})}function n0(e){let{commands:t,onClose:n}=e,[s,i]=(0,l.useState)(""),[r,o]=(0,l.useState)(0),c=(0,l.useRef)(null),d=(0,l.useRef)(null),u=(0,l.useRef)(null);(0,l.useEffect)(()=>(d.current=document.activeElement,()=>{var e,t;null==(t=d.current)||null==(e=t.focus)||e.call(t)}),[]),(0,l.useEffect)(()=>{var e;null==(e=c.current)||e.focus()},[]);let h=(0,l.useMemo)(()=>{let e=s.toLowerCase();return t.filter(t=>{var n;return"".concat(t.label," ").concat(null!=(n=t.group)?n:"").toLowerCase().includes(e)})},[t,s]);(0,l.useEffect)(()=>{o(0)},[s]),(0,l.useEffect)(()=>{var e,t;null==(t=document.getElementById("cmdk-row-".concat(String(r))))||null==(e=t.scrollIntoView)||e.call(t,{block:"nearest"})},[r,h]);let p=e=>{void 0!==e&&(e.run(),n())};return(0,a.jsx)("div",{className:"cmdk-overlay",onPointerDown:n,children:(0,a.jsxs)("div",{ref:u,className:"cmdk",role:"dialog","aria-modal":"true","aria-labelledby":"cmdk-title","aria-describedby":"cmdk-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Tab"===e.key){var t,a;let n=Array.from(null!=(a=null==(t=u.current)?void 0:t.querySelectorAll("button:not([disabled]),input:not([disabled]),[tabindex]:not([tabindex='-1'])"))?a:[]);if(n.length>0){let t=n[0],a=n[n.length-1];if(e.shiftKey&&document.activeElement===t){e.preventDefault(),a.focus();return}if(!e.shiftKey&&document.activeElement===a){e.preventDefault(),t.focus();return}}}if("ArrowDown"===e.key){e.preventDefault(),o(e=>Math.min(h.length-1,e+1));return}if("ArrowUp"===e.key){e.preventDefault(),o(e=>Math.max(0,e-1));return}if("Enter"===e.key){e.preventDefault(),p(h[r]);return}"Escape"===e.key&&n()},children:[(0,a.jsx)("h2",{id:"cmdk-title",className:"sr-only",children:"Command palette"}),(0,a.jsx)("p",{id:"cmdk-desc",className:"sr-only",children:"Search commands and press Enter to run the selected action."}),(0,a.jsxs)("div",{className:"cmdk-input",children:[(0,a.jsx)(N.F.search,{size:16}),(0,a.jsx)("input",{ref:c,role:"combobox","aria-expanded":"true","aria-controls":"cmdk-list","aria-activedescendant":h.length>0?"cmdk-row-".concat(String(r)):void 0,"aria-label":"Command query",placeholder:"Type a command…",value:s,onChange:e=>i(e.target.value)}),(0,a.jsx)("span",{className:"kbd",children:"esc"})]}),(0,a.jsx)("div",{className:"sr-only",role:"status",children:0===h.length?"No matching commands":"".concat(String(h.length)," command").concat(1===h.length?"":"s")}),(0,a.jsxs)("div",{id:"cmdk-list",role:"listbox",className:"cmdk-list",children:[0===h.length&&(0,a.jsx)("div",{className:"cmdk-empty",children:"No matching commands"}),h.map((e,t)=>(0,a.jsxs)("div",{role:"option",id:"cmdk-row-".concat(String(t)),"aria-selected":t===r,className:"cmdk-row","data-sel":t===r,tabIndex:-1,onMouseEnter:()=>o(t),onClick:()=>p(e),children:[(0,a.jsx)("span",{className:"cmdk-ico",children:function(e){var t;let n=null!=(t=N.F[e])?t:N.F.spark;return(0,a.jsx)(n,{size:16})}(e.icon)}),(0,a.jsx)("span",{className:"cmdk-label",children:e.label}),(0,a.jsx)("span",{className:"spacer"}),void 0!==e.shortcut&&(0,a.jsx)("span",{className:"kbd",children:e.shortcut}),void 0!==e.group&&(0,a.jsx)("span",{className:"cmdk-group mono",children:e.group})]},e.id))]})]})})}function n1(e){let{onCancel:t}=e,n=(0,l.useRef)(null),s=(0,l.useRef)(null),i=(0,l.useRef)(null),[r,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(""),[u,h]=(0,l.useState)(""),[p,m]=(0,l.useState)(""),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(),[y,b]=(0,l.useState)(),[j,w]=(0,l.useState)();async function k(e){var t;if(e.preventDefault(),!f){g(!0),x(void 0),b(void 0),w(void 0),null==(t=n.current)||t.focus();try{let e=Array.from(new Set(p.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0)));if(function(e){try{return new URL(e.trim()).hostname.endsWith(".services.ai.azure.com")}catch(e){return!1}}(r)&&0===e.length){x("Azure AI Foundry requires deployment names. Paste the names from the Deployments tab."),g(!1);return}let t=(await (0,$.qe)({baseUrl:r,apiKey:c,apiKeyHeaderName:""===u.trim()?void 0:u.trim(),deploymentNames:e})).testedModelIds.length;w("Verified ".concat(String(t)," workflow chat model").concat(1===t?"":"s",". Reloading Keiko…")),window.setTimeout(()=>window.location.reload(),800)}catch(t){let e=t instanceof $.hD?{message:t.message,code:t.code}:t instanceof Error?{message:t.message}:{message:"The gateway could not be configured."};x(e.message),b(e.code),g(!1)}}}(0,l.useEffect)(()=>{var e;return i.current=document.activeElement,null==(e=s.current)||e.focus(),()=>{var e,t;null==(t=i.current)||null==(e=t.focus)||e.call(t)}},[]),(0,l.useEffect)(()=>{let e=n.current;if(null===e)return;let a=n=>{if("Escape"===n.key){if(f||void 0!==j||void 0===t)return;n.preventDefault(),t();return}if("Tab"!==n.key)return;let a=Array.from(e.querySelectorAll("button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex='-1'])"));if(0===a.length)return;let l=a[0],s=a[a.length-1];n.shiftKey&&document.activeElement===l?(n.preventDefault(),s.focus()):n.shiftKey||document.activeElement!==s||(n.preventDefault(),l.focus())};return e.addEventListener("keydown",a),()=>e.removeEventListener("keydown",a)},[f,t,j]),(0,l.useEffect)(()=>{if(void 0!==v&&!f){var e;null==(e=s.current)||e.focus()}},[v,f]);let S=(0,a.jsx)("div",{className:"gw-setup-backdrop",role:"presentation",children:(0,a.jsx)("div",{ref:n,className:"gw-setup",role:"dialog","aria-modal":"true","aria-labelledby":"gw-setup-title","aria-describedby":"gw-setup-desc",tabIndex:-1,children:(0,a.jsxs)("form",{onSubmit:e=>void k(e),children:[(0,a.jsxs)("div",{className:"gw-setup-badge",children:[(0,a.jsx)(N.F.cube,{size:18}),"Model gateway setup"]}),(0,a.jsx)("h1",{id:"gw-setup-title",children:"Connect Keiko to your internal LLMs"}),(0,a.jsx)("p",{id:"gw-setup-desc",children:"Keiko needs the internal gateway URL and API token before chat and agent workflows can run. The token is tested once and stored only on this machine."}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"Base URL"}),(0,a.jsx)("input",{className:"gw-input mono",value:r,placeholder:"https://llm-gateway.example.com/v1",autoComplete:"off",disabled:f||void 0!==j,ref:s,onChange:e=>o(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"API token"}),(0,a.jsx)("input",{className:"gw-input mono",type:"password",value:c,placeholder:"Paste your API token",autoComplete:"off",disabled:f||void 0!==j,onChange:e=>d(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsxs)("span",{children:["API key header ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("input",{className:"gw-input mono",value:u,placeholder:"Authorization",autoComplete:"off",disabled:f||void 0!==j,onChange:e=>h(e.target.value)})]}),(0,a.jsxs)("label",{className:"gw-field",children:[(0,a.jsx)("span",{children:"Deployment names for Azure"}),(0,a.jsx)("textarea",{className:"gw-input gw-textarea mono",value:p,placeholder:"Paste deployment names, one per line",autoComplete:"off",disabled:f||void 0!==j,onChange:e=>m(e.target.value)})]}),(0,a.jsx)("div",{className:"gw-note",children:"Leave the header field empty unless your gateway admin gave you a custom API-key header, for example X-Litellm-Key. Supported headers are Authorization, X-Litellm-Key, X-Api-Key, and api-key. Leave deployment names empty only for OpenAI-compatible gateways with model discovery. For Azure AI Foundry, paste deployment names exactly as shown in the Deployments tab. Testing several deployments can take up to 30 seconds."}),void 0!==v?(0,a.jsxs)("div",{className:"gw-error",role:"alert",children:[v,void 0!==y?(0,a.jsx)("div",{className:"gw-error-code mono",children:y}):null]}):null,void 0!==j?(0,a.jsx)("div",{className:"gw-success",role:"status",children:j}):null,(0,a.jsxs)("div",{className:"gw-actions",children:[void 0!==t?(0,a.jsx)("button",{className:"gw-cancel",type:"button",disabled:f||void 0!==j,onClick:t,children:"Cancel"}):null,(0,a.jsx)("button",{className:"gw-submit",type:"submit",disabled:f||void 0!==j||""===r.trim()||""===c.trim(),children:f?"Testing connection…":"Test & save"})]})]})})});return"undefined"==typeof document?S:(0,tj.createPortal)(S,document.body)}let n2=[["ask","Ask every action"],["full","Full access"]];function n3(e){let{cfg:t,set:n}=e,l=!1!==t.keikoMode,s="full"===t.access?"full":"ask",i=l?"No rights by default. You approve while manual; Keiko governs per policy when autonomous.":"full"===s?"Legacy: agent acts without prompts.":"Legacy: you approve each privileged action.";return(0,a.jsxs)("div",{className:"permctl",children:[(0,a.jsxs)("button",{type:"button",className:"perm-toggle","data-on":l,"aria-pressed":l,onClick:()=>n("keikoMode",!l),children:[(0,a.jsx)("img",{className:"perm-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsxs)("span",{className:"perm-tt",children:[(0,a.jsx)("span",{className:"perm-name",children:"Keiko-Mode"}),(0,a.jsx)("span",{className:"perm-desc",children:"Zero standing rights \xb7 Keiko governs"})]}),(0,a.jsx)("span",{className:"perm-sw"+(l?" on":""),children:(0,a.jsx)("span",{})})]}),!l&&(0,a.jsx)("div",{className:"perm-legacy",children:n2.map(e=>{let[t,l]=e;return(0,a.jsx)("button",{type:"button",className:"perm-opt","data-on":s===t,"aria-pressed":s===t,onClick:()=>n("access",t),children:l},t)})}),(0,a.jsx)("div",{className:"perm-note",children:i})]})}function n4(e){if(e instanceof $.hD){if("BAD_ROOT"===e.code)return"Enter an absolute folder path.";if("DENIED"===e.code)return"That location is excluded."}return e instanceof Error?e.message:"Unable to read directories."}function n6(e){let{value:t,projectId:n,selectProjectRoot:s=!1,onSelect:i,onClose:r}=e,[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(t),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(null),g=null!=n?n:t.trim(),v=(0,l.useCallback)(async e=>{if(0===g.length){c(null),f("Enter an absolute folder path.");return}p(!0),f(null);try{let t=await (0,$.xe)(g,e);c(t),u(t.path)}catch(e){f(n4(e))}finally{p(!1)}},[g]);return(0,l.useEffect)(()=>{v(t.length>0?t:void 0)},[]),(0,a.jsxs)("div",{className:"dir-picker",role:"group","aria-label":"Directory picker",children:[(0,a.jsxs)("div",{className:"dir-top",children:[(0,a.jsx)("input",{className:"dlg-input mono dir-path",value:d,"aria-label":"Folder path",placeholder:"/absolute/folder/path",onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),v(d))}}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dir-go",onClick:()=>void v(d),children:"Go"})]}),null!==o?(0,a.jsx)("div",{className:"dir-roots",children:o.roots.map(e=>(0,a.jsx)("button",{type:"button",className:"dir-chip",onClick:()=>void v(e.path),children:e.label},"".concat(e.label,":").concat(e.path)))}):null,(0,a.jsxs)("div",{className:"dir-list",children:[(null==o?void 0:o.parent)!==null&&(null==o?void 0:o.parent)!==void 0?(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>{var e;v(null!=(e=o.parent)?e:void 0)},children:[(0,a.jsx)(N.F.back,{size:14}),(0,a.jsx)("span",{children:"Parent directory"})]}):null,null==o?void 0:o.entries.map(e=>(0,a.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>void v(e.path),children:[(0,a.jsx)(N.F.folder,{size:14}),(0,a.jsx)("span",{children:e.name})]},e.path)),h?(0,a.jsx)("div",{className:"dir-note",role:"status",children:"Loading directories…"}):null,h||null===o||0!==o.entries.length?null:(0,a.jsx)("div",{className:"dir-note",children:"No child directories."}),null!==m?(0,a.jsx)("div",{className:"dir-error",role:"alert",children:m}):null]}),(0,a.jsxs)("div",{className:"dir-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:r,children:"Close"}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{if(null!==o){var e,t;i(s&&null!=(t=null==(e=o.roots[0])?void 0:e.path)?t:o.path),r()}},disabled:null===o,children:"Use directory"})]})]})}let n5=[{id:"verify",label:"Verify"},{id:"explain-plan",label:"Explain plan"},{id:"unit-test-generation",label:"Generate unit tests"},{id:"bug-investigation",label:"Investigate bug"}];function n8(e){return e.filter(e=>e.available).map(e=>e.path)}function n9(e){return e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0)}function n7(e){return e.replaceAll("\\","/")}function ae(e,t){let n=n7(t.trim());if(0===n.length)return"";let a=n7(e.trim()).replace(/\/+$/u,"");if(0===a.length)return n;if(n===a)return".";let l="".concat(a,"/");return n.startsWith(l)?n.slice(l.length):n}function at(e,t){return n9(t).map(t=>ae(e,t)).join(", ")}function an(e){var t;let{filesContext:n,firstRef:s,directoryField:i,setDirectoryField:r,setDialogError:o,onConfirm:c}=e,[d,u]=(0,l.useState)("verify"),[h,p]=(0,l.useState)(null!=(t=null==n?void 0:n.root)?t:""),[m,f]=(0,l.useState)(""),[g,v]=(0,l.useState)([]),[x,y]=(0,l.useState)([]),[b,j]=(0,l.useState)(()=>{var e,t;return function(e,t){let n=null===t?"":ae(e,t);return{verifyTargetFiles:n,explainFilePath:n,explainQuestion:"",unitTargetKind:"file",unitFilePath:n,unitModuleDir:"",unitFilePaths:n,bugDescription:"",bugFailingOutput:"",bugStackTrace:"",bugTargetFiles:n}}(null!=(e=null==n?void 0:n.root)?e:"",null!=(t=null==n?void 0:n.activeFilePath)?t:null)}),[w,k]=(0,l.useState)(!0),[S,C]=(0,l.useState)(!1),[R,E]=(0,l.useState)(!1),I=h.trim(),T=null!==n&&n.root===I&&void 0!==n.activeFilePath?n.activeFilePath:null,F=I.length>0&&x.includes(I),q=function(e,t,n,a){if(0===t.length)return"Workspace is required.";if(0===n.length)return"No model is available.";if("explain-plan"===e&&0===a.explainFilePath.trim().length)return"Explain plan requires a file path.";if("unit-test-generation"===e){if("file"===a.unitTargetKind&&0===a.unitFilePath.trim().length)return"Unit test generation requires a file path.";if("module"===a.unitTargetKind&&0===a.unitModuleDir.trim().length)return"Unit test generation requires a module folder.";if("changedFiles"===a.unitTargetKind&&0===n9(a.unitFilePaths).length)return"Unit test generation requires at least one file path."}return"bug-investigation"!==e||a.bugDescription.trim().length>0||a.bugFailingOutput.trim().length>0||a.bugStackTrace.trim().length>0||n9(a.bugTargetFiles).length>0?null:"Bug investigation requires description, output, stack trace, or target files."}(d,I,m,b),A=null===q&&F&&!R&&!w;(0,l.useEffect)(()=>{let e=!1;return k(!0),o(null),Promise.all([(0,$.ZC)(),(0,$.vj)()]).then(t=>{let[n,a]=t;if(e)return;let l=n.models.filter(tN);v(l),f(e=>{var t,n;return e||(null!=(n=null==(t=l[0])?void 0:t.id)?n:"")}),y(n8(a.projects))}).catch(t=>{e||o(n4(t))}).finally(()=>{e||k(!1)}),()=>{e=!0}},[o]);let M=e=>{j(t=>({...t,...e}))};(0,l.useEffect)(()=>{if(null===T)return;let e=ae(I,T);j(t=>{let n={};return 0===t.verifyTargetFiles.trim().length&&(n.verifyTargetFiles=e),0===t.explainFilePath.trim().length&&(n.explainFilePath=e),0===t.unitFilePath.trim().length&&(n.unitFilePath=e),0===t.unitFilePaths.trim().length&&(n.unitFilePaths=e),0===t.bugTargetFiles.trim().length&&(n.bugTargetFiles=e),0===Object.keys(n).length?t:{...t,...n}})},[T,I]);let P=async()=>{y(n8((await (0,$.vj)()).projects))},D=async()=>{if(0!==I.length){C(!0),o(null);try{await (0,$.gA)({path:I}),await P()}catch(e){o(n4(e))}finally{C(!1)}}},L=async()=>{if(!A)return void o(null!=q?q:"Workspace is not registered.");E(!0),o(null);let e=function(e,t,n,a){if("verify"===e){let e=n9(a.verifyTargetFiles).map(e=>ae(t,e));return{taskType:"verify",modelId:n,input:{workspaceRoot:t,...e.length>0?{targetFiles:e}:{}}}}if("explain-plan"===e)return{taskType:"explain-plan",modelId:n,input:{workspaceRoot:t,filePath:ae(t,a.explainFilePath),...a.explainQuestion.trim().length>0?{question:a.explainQuestion.trim()}:{}}};if("unit-test-generation"===e){let e=n9(a.unitFilePaths).map(e=>ae(t,e)),l="module"===a.unitTargetKind?{kind:"module",moduleDir:ae(t,a.unitModuleDir)}:"changedFiles"===a.unitTargetKind?{kind:"changedFiles",filePaths:e}:{kind:"file",filePath:ae(t,a.unitFilePath)};return{workflowId:"unit-test-generation",modelId:n,input:{workspaceRoot:t,target:l}}}return{workflowId:"bug-investigation",modelId:n,input:{workspaceRoot:t,report:{...a.bugDescription.trim().length>0?{description:a.bugDescription.trim()}:{},...a.bugFailingOutput.trim().length>0?{failingOutput:a.bugFailingOutput.trim()}:{},...a.bugStackTrace.trim().length>0?{stackTrace:a.bugStackTrace.trim()}:{},...n9(a.bugTargetFiles).length>0?{targetFiles:n9(a.bugTargetFiles).map(e=>ae(t,e))}:{}}}}}(d,I,m,b);try{let t=await (0,$.AD)(e);c({workflow:d,model:m,runId:t.runId,fingerprint:t.fingerprint,workspaceRoot:I,inputJson:JSON.stringify(e.input),...null!==n&&n.root===I?{__connectFilesId:n.id}:{}})}catch(e){e instanceof $.hD&&"WORKSPACE_NOT_REGISTERED"===e.code?(await P().catch(()=>void 0),o("Workspace is not registered.")):o(n4(e))}finally{E(!1)}};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Workflow"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{ref:s,className:"dlg-input mono",value:d,onChange:e=>u(e.target.value),children:n5.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(N.F.chevron,{size:15})})]})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Workspace"}),(0,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{className:"dlg-input mono",value:h,placeholder:"/absolute/project/path",onClick:()=>r("agentWorkspace"),onChange:e=>p(e.target.value)}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",onClick:()=>r("agentWorkspace"),children:"Browse"})]}),"agentWorkspace"===i?(0,a.jsx)(n6,{value:h,projectId:F?I:void 0,onSelect:p,onClose:()=>r(null)}):null]}),I.length>0&&!F?(0,a.jsxs)("div",{className:"dlg-agent-warning",children:[(0,a.jsx)("span",{children:"Workspace is not registered."}),(0,a.jsx)("button",{type:"button",className:"dlg-btn",disabled:S,onClick:()=>void D(),children:S?"Registering…":"Register workspace"})]}):null,(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Model"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{className:"dlg-input mono",value:m,onChange:e=>f(e.target.value),disabled:0===g.length,children:g.map(e=>(0,a.jsx)("option",{value:e.id,children:e.id},e.id))}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(N.F.chevron,{size:15})})]})]}),null!==T?(0,a.jsxs)("button",{type:"button",className:"dlg-current-file",onClick:()=>{if(null===T)return;let e=ae(I,T);"verify"===d?M({verifyTargetFiles:e}):"explain-plan"===d?M({explainFilePath:e}):"unit-test-generation"===d?"changedFiles"===b.unitTargetKind?M({unitFilePaths:e}):M({unitTargetKind:"file",unitFilePath:e}):M({bugTargetFiles:e})},title:T,children:[(0,a.jsx)(N.F.files,{size:13})," Use current file ",(0,a.jsx)("span",{className:"mono",children:T})]}):null,"verify"===d?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Target files ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.verifyTargetFiles,onChange:e=>M({verifyTargetFiles:e.target.value}),onBlur:e=>M({verifyTargetFiles:at(I,e.target.value)})})]}):"explain-plan"===d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"File path"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:b.explainFilePath,onChange:e=>M({explainFilePath:e.target.value}),onBlur:e=>M({explainFilePath:ae(I,e.target.value)})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Question ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"What should the plan focus on?",value:b.explainQuestion,onChange:e=>M({explainQuestion:e.target.value})})]})]}):"unit-test-generation"===d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Target"}),(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsxs)("select",{className:"dlg-input mono",value:b.unitTargetKind,onChange:e=>M({unitTargetKind:e.target.value}),children:[(0,a.jsx)("option",{value:"file",children:"Single file"}),(0,a.jsx)("option",{value:"module",children:"Module"}),(0,a.jsx)("option",{value:"changedFiles",children:"Changed files"})]}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(N.F.chevron,{size:15})})]})]}),"module"===b.unitTargetKind?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"Module folder"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/module",value:b.unitModuleDir,onChange:e=>M({unitModuleDir:e.target.value}),onBlur:e=>M({unitModuleDir:ae(I,e.target.value)})})]}):"changedFiles"===b.unitTargetKind?(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"File paths"}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.unitFilePaths,onChange:e=>M({unitFilePaths:e.target.value}),onBlur:e=>M({unitFilePaths:at(I,e.target.value)})})]}):(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsx)("span",{className:"dlg-label",children:"File path"}),(0,a.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:b.unitFilePath,onChange:e=>M({unitFilePath:e.target.value}),onBlur:e=>M({unitFilePath:ae(I,e.target.value)})})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Description ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"Describe the observed bug.",value:b.bugDescription,onChange:e=>M({bugDescription:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Failing output ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:b.bugFailingOutput,onChange:e=>M({bugFailingOutput:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Stack trace ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:b.bugStackTrace,onChange:e=>M({bugStackTrace:e.target.value})})]}),(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:["Target files ",(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,a.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:b.bugTargetFiles,onChange:e=>M({bugTargetFiles:e.target.value}),onBlur:e=>M({bugTargetFiles:at(I,e.target.value)})})]})]}),(0,a.jsxs)("div",{className:"dlg-agent-actions",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",disabled:!A,onClick:()=>void L(),children:R?"Starting…":"Start agent"}),w?(0,a.jsx)("span",{className:"dlg-note",role:"status",children:"Loading models and projects…"}):null,w||null===q?null:(0,a.jsx)("span",{className:"dlg-note",role:"status",children:q})]})]})}function aa(e){var t,n;let{type:s,types:i,filesContext:r=null,onConfirm:o,onClose:c}=e,d=i[s],u=null!=(t=d.config)?t:[],[h,p]=(0,l.useState)(()=>(function(e){let t={};for(let a of e){var n;t[a.key]=null!=(n=a.def)?n:""}return t})(u)),[m,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(null),b=(0,l.useRef)(null),j=(0,l.useRef)(null),w=(0,l.useRef)(null);(0,l.useEffect)(()=>(w.current=document.activeElement,()=>{let e=w.current;if(null!==e&&e.isConnected)return void e.focus();requestAnimationFrame(()=>{var e;let t=null!=(e=document.querySelector('.window[data-top="true"]'))?e:document.querySelector(".ws-fab");null==t||t.focus({preventScroll:!0})})}),[]),(0,l.useEffect)(()=>{let e=requestAnimationFrame(()=>{var e,t;f(!0),null==(e=null!=(t=b.current)?t:j.current)||e.focus()});return()=>cancelAnimationFrame(e)},[]),(0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&c()};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[c]),(0,l.useEffect)(()=>{if("files"!==s)return;let e=!1,t=h.root;if("string"!=typeof t||!(t.length>0))return v(null),(0,$.vj)().then(t=>{let n=n8(t.projects)[0];e||void 0===n||p(e=>({...e,root:n}))}).catch(t=>{e||v(n4(t))}),()=>{e=!0}},[h.root,s]);let k=(e,t)=>p(n=>({...n,[e]:t})),S=()=>{"agents"!==s&&o(h)},C=N.F[d.icon],R=null!=(n=d.cta)?n:"Open ".concat(d.title);return(0,a.jsx)("div",{className:"dlg-overlay"+(m?" in":""),onPointerDown:c,children:(0,a.jsxs)("div",{ref:j,className:"dlg",role:"dialog","aria-modal":"true","aria-labelledby":"new-window-title","aria-describedby":"new-window-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Escape"===e.key)return void c();if("Enter"===e.key&&(e.metaKey||e.ctrlKey))return void S();if("Enter"===e.key){let t=e.target instanceof HTMLElement?e.target.tagName:"";("INPUT"===t||"SELECT"===t)&&(e.preventDefault(),S());return}if("Tab"!==e.key)return;let t=function(e){let t=e.querySelectorAll("button,input,select,textarea"),n=[];return t.forEach(e=>{e.hasAttribute("disabled")||(null!==e.offsetParent||"BUTTON"===e.tagName)&&n.push(e)}),n}(e.currentTarget);if(0===t.length)return;let n=t[0],a=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),a.focus()):e.shiftKey||document.activeElement!==a||(e.preventDefault(),n.focus())},children:[(0,a.jsxs)("div",{className:"dlg-head",children:[(0,a.jsx)("span",{className:"dlg-ico",children:(0,a.jsx)(C,{size:20})}),(0,a.jsxs)("div",{className:"dlg-htext",children:[(0,a.jsxs)("span",{id:"new-window-title",className:"dlg-title",children:["New ",d.title," window"]}),(0,a.jsx)("span",{id:"new-window-desc",className:"dlg-sub",children:d.desc})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:c,"aria-label":"Cancel",title:"Cancel",children:(0,a.jsx)(N.F.close,{size:16})})]}),(0,a.jsxs)("div",{className:"dlg-body",children:["agents"===s?(0,a.jsx)(an,{filesContext:r,firstRef:e=>{b.current=e},directoryField:x,setDirectoryField:y,setDialogError:v,onConfirm:o}):0===u.length&&(0,a.jsxs)("div",{className:"dlg-empty",children:["Add a new ",d.title," window to your workspace."]}),"agents"!==s&&u.map((e,t)=>(0,a.jsxs)("label",{className:"dlg-field",children:[(0,a.jsxs)("span",{className:"dlg-label",children:[e.label,!0===e.optional&&(0,a.jsx)("span",{className:"dlg-opt",children:"optional"})]}),function(e,t,n,l,s){var i,r,o,c;if("perm"===e.type)return(0,a.jsx)(n3,{cfg:t,set:n});let d=t[e.key],u="string"==typeof d?d:void 0===d?"":String(d);if("select"===e.type){let t=null!=(i=e.options)?i:[];return(0,a.jsxs)("span",{className:"dlg-selwrap",children:[(0,a.jsx)("select",{ref:null!=l?l:void 0,className:"dlg-input mono",value:u,onChange:t=>n(e.key,t.target.value),disabled:0===t.length,children:t.map(t=>{var n;return(0,a.jsx)("option",{value:t,children:(null!=(n=e.prefix)?n:"")+t},t)})}),(0,a.jsx)("span",{className:"dlg-selchev",children:(0,a.jsx)(N.F.chevron,{size:15})})]})}return"textarea"===e.type?(0,a.jsx)("textarea",{ref:null!=l?l:void 0,className:"dlg-input dlg-textarea",rows:3,placeholder:null!=(r=e.placeholder)?r:"",value:u,onChange:t=>n(e.key,t.target.value)}):"directory"===e.type?(0,a.jsxs)("span",{className:"dlg-dirwrap",children:[(0,a.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(o=e.placeholder)?o:e.label,value:u,onClick:()=>s(e.key),onChange:t=>n(e.key,t.target.value)}),(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",onClick:()=>s(e.key),children:"Browse"})]}):(0,a.jsx)("input",{ref:null!=l?l:void 0,className:"dlg-input mono",placeholder:null!=(c=e.placeholder)?c:e.label,value:u,onChange:t=>n(e.key,t.target.value)})}(e,h,k,0===t?e=>{b.current=e}:null,y),"directory"===e.type&&x===e.key?(0,a.jsx)(n6,{value:"string"==typeof h[e.key]?h[e.key]:"",selectProjectRoot:"root"===e.key,onSelect:t=>k(e.key,t),onClose:()=>y(null)}):null]},e.key)),null!==g?(0,a.jsx)("div",{className:"dlg-error",role:"alert",children:g}):null]}),(0,a.jsxs)("div",{className:"dlg-foot",children:[(0,a.jsx)("button",{type:"button",className:"dlg-btn",onClick:c,children:"Cancel"}),"agents"!==s?(0,a.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:S,children:R}):null]})]})})}let al=new Map([["ArrowRight",1],["ArrowLeft",-1],["ArrowDown",2],["ArrowUp",-2]]);function as(e){let{types:t,order:n,onAdd:s,onClose:i}=e,r=(0,l.useRef)(null),o=(0,l.useRef)(null),[c,d]=(0,l.useState)(0);return(0,l.useEffect)(()=>{var e;o.current=document.activeElement;let t=null==(e=r.current)?void 0:e.querySelector(".pal-card");return null==t||t.focus(),()=>{var e,t;let n=document.activeElement;(null===n||n===document.body)&&(null==(t=o.current)||null==(e=t.focus)||e.call(t))}},[]),(0,l.useEffect)(()=>{let e=e=>{null!==r.current&&e.target instanceof Node&&!r.current.contains(e.target)&&i()};return document.addEventListener("pointerdown",e),()=>{document.removeEventListener("pointerdown",e)}},[i]),(0,a.jsxs)("div",{ref:r,className:"palette",role:"dialog","aria-labelledby":"palette-title","aria-describedby":"palette-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{var t,n,a;if("Escape"===e.key){e.preventDefault(),i();return}if(!(e.target instanceof HTMLElement)||!e.target.classList.contains("pal-card"))return;let l=Array.from(null!=(a=null==(t=r.current)?void 0:t.querySelectorAll(".pal-card"))?a:[]),s=function(e,t,n){if(0===n)return null;if("Home"===e)return 0;if("End"===e)return n-1;let a=al.get(e);return void 0===a?null:Math.max(0,Math.min(n-1,t+a))}(e.key,l.indexOf(e.target),l.length);null!==s&&(e.preventDefault(),d(s),null==(n=l[s])||n.focus())},onBlur:e=>{var t;e.relatedTarget instanceof Node&&(null==(t=r.current)?void 0:t.contains(e.relatedTarget))!==!0&&i()},children:[(0,a.jsxs)("div",{className:"palette-head",children:[(0,a.jsx)("span",{className:"palette-badge",children:(0,a.jsx)(N.F.add,{size:17})}),(0,a.jsxs)("div",{className:"palette-htext",children:[(0,a.jsx)("span",{id:"palette-title",className:"palette-title",children:"New window"}),(0,a.jsx)("span",{id:"palette-desc",className:"palette-sub",children:"Pick a card to add to your workspace"})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:i,"aria-label":"Close",title:"Close",children:(0,a.jsx)(N.F.close,{size:16})})]}),(0,a.jsx)("div",{className:"palette-grid",children:n.map((e,n)=>{let l=t[e],i=N.F[l.icon];return(0,a.jsxs)("button",{type:"button",className:"pal-card pal-main",tabIndex:n===c?0:-1,onFocus:()=>d(n),onClick:()=>s(e),children:[(0,a.jsx)("span",{className:"pal-ico",children:(0,a.jsx)(i,{size:18})}),(0,a.jsx)("span",{className:"pal-name",children:l.title}),(0,a.jsx)("span",{className:"pal-desc",children:l.desc}),(0,a.jsx)("span",{className:"pal-add",children:(0,a.jsx)(N.F.plus,{size:15})})]},e)})})]})}let ai="keiko.theme",ar="dark",ao=["agent","capsule","capsule-set","chat","connector","data-source","evidence-run","mcp-tool","memory","patch-proposal","skill","tool","workflow-run","workspace-path"],ac=["capsule","capsule-set","chat","evidence-run","memory","patch-proposal","tool","workflow-run","workspace-path"],ad=["reads-context","proposes-patch","uses-tool","starts-workflow","produces-evidence","references-document","depends-on"],au=["draft","active","archived","superseded","revoked","blocked","stale"],ah={"reads-context":{id:"reads-context",displayName:"reads context",semantics:"A consumer endpoint reads the contextual content of the target at a specific point in time.",validSourceKinds:["workflow-run","chat"],validTargetKinds:["memory","capsule","capsule-set","evidence-run","workspace-path","connector","data-source"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"proposes-patch":{id:"proposes-patch",displayName:"proposes patch",semantics:"A workflow run proposes a patch against one or more workspace paths. The relationship records the proposal; diff content stays in the harness PatchProposedEvent.",validSourceKinds:["workflow-run"],validTargetKinds:["workspace-path","patch-proposal"],cardinality:"1:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"fs"},"uses-tool":{id:"uses-tool",displayName:"uses tool",semantics:"A workflow run uses a registered tool. Per-call arguments and results remain in the harness ToolCallRequest / ToolCallResult envelopes.",validSourceKinds:["workflow-run"],validTargetKinds:["tool","mcp-tool"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"tool"},"starts-workflow":{id:"starts-workflow",displayName:"starts workflow",semantics:"A chat or a parent workflow run initiates a workflow run. The relationship records the origin; run identity belongs to the workflow ledger.",validSourceKinds:["chat","workflow-run"],validTargetKinds:["workflow-run"],cardinality:"1:N",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"produces-evidence":{id:"produces-evidence",displayName:"produces evidence",semantics:"A workflow run produces exactly one durable evidence-run record. If a run produces no evidence, no relationship is recorded.",validSourceKinds:["workflow-run"],validTargetKinds:["evidence-run"],cardinality:"1:1",direction:"directed",lifecycle:{creatable:!0,immutable:!0,reconnectable:!1,deletable:!1,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"produces",ownerPackage:"@oscharko-dev/keiko-evidence",trustBoundary:"evidence"},"references-document":{id:"references-document",displayName:"references document",semantics:"A chat or workflow run holds a structural pointer to a document (workspace file or local-knowledge capsule). Distinct from reads-context: a reference is structural, a read is an event.",validSourceKinds:["chat","workflow-run"],validTargetKinds:["workspace-path","capsule","capsule-set"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!1,reconnectable:!0,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-workflows",trustBoundary:"per-endpoint"},"depends-on":{id:"depends-on",displayName:"depends on",semantics:"A capsule, capsule-set, workflow run, or memory depends on another. Used by impact analysis (#542). Self-loops and direct two-edge cycles are forbidden at validation time; transitive cycle detection is deferred to impact traversal.",validSourceKinds:["capsule","capsule-set","workflow-run","memory"],validTargetKinds:["capsule","capsule-set","workflow-run","memory","evidence-run","workspace-path"],cardinality:"N:N",direction:"directed",lifecycle:{creatable:!0,immutable:!1,reconnectable:!0,deletable:!0,archivable:!0},auditEventOnMutation:!0,evidenceRelevance:"reference",ownerPackage:"@oscharko-dev/keiko-contracts",trustBoundary:"per-endpoint"}},ap=["prompt","documentcontent","filecontent","toolstdout","toolstderr","secret","credential","apikey","password","token"],am="Unable to reach the local backend. Check that the Keiko server is running (keiko ui).";class af extends Error{constructor(e,t,n,a=[]){super(t),this.name="RelationshipApiError",this.code=e,this.status=n,this.reasons=a}}async function ag(e){let t;try{t=await e.json()}catch(t){throw new af("relationship/parse-error","Response is not valid JSON.",e.status)}if(!e.ok){var n;let a=t,l=null!=(n=a.error)?n:a,s="string"==typeof l.code?l.code:"relationship/unknown-error",i="string"==typeof l.message?l.message:"An unknown error occurred.",r=Array.isArray(a.reasons)?a.reasons:[];throw new af(s,i,e.status,r)}return t}function av(e){let t={"Content-Type":"application/json","X-Keiko-CSRF":"1"};return void 0!==e.idempotencyKey&&(t["Idempotency-Key"]=e.idempotencyKey),void 0!==e.ifMatch&&(t["If-Match"]=e.ifMatch),t}async function ax(e){let t={schemaVersion:"1",proposal:{type:e.type,source:{kind:e.source.kind,id:e.source.id},target:{kind:e.target.kind,id:e.target.id},...void 0!==e.summary?{summary:e.summary}:{}}},n=await fetch("/api/relationships/validate",{method:"POST",headers:av({}),body:JSON.stringify(t)});return{decision:(await ag(n)).decision}}async function ay(e,t){let n={schemaVersion:"1",proposal:{type:e.type,source:{kind:e.source.kind,id:e.source.id},target:{kind:e.target.kind,id:e.target.id},...void 0!==e.summary?{summary:e.summary}:{}}},a=await fetch("/api/relationships",{method:"POST",headers:av({idempotencyKey:t}),body:JSON.stringify(n)}),l=await ag(a);return{relationship:l.relationship,etag:l.etag}}async function ab(e){let t=new URLSearchParams;void 0!==e.lifecycle&&t.set("lifecycle",e.lifecycle),void 0!==e.type&&t.set("type",e.type),void 0!==e.sourceKind&&t.set("sourceKind",e.sourceKind),void 0!==e.targetKind&&t.set("targetKind",e.targetKind),void 0!==e.sourceId&&t.set("sourceId",e.sourceId),void 0!==e.targetId&&t.set("targetId",e.targetId),void 0!==e.limit&&t.set("limit",String(e.limit)),void 0!==e.cursor&&t.set("cursor",e.cursor);let n=await fetch("/api/relationships?".concat(t.toString())),a=await ag(n);return{entries:a.entries,truncated:a.truncated,nextCursor:a.nextCursor}}async function aj(e){let t=await fetch("/api/relationships/".concat(encodeURIComponent(e)));return(await ag(t)).relationship}async function aw(e,t,n,a){let l=await fetch("/api/relationships/".concat(encodeURIComponent(e)),{method:"PATCH",headers:av({idempotencyKey:a,ifMatch:n}),body:JSON.stringify({schemaVersion:"1",...t})}),s=await ag(l);return{relationship:s.relationship,etag:s.etag}}async function ak(e,t,n){let a=await fetch("/api/relationships/".concat(encodeURIComponent(e)),{method:"DELETE",headers:av({idempotencyKey:n,ifMatch:t})});return(await ag(a)).relationship}async function aN(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new URLSearchParams;void 0!==t.direction&&n.set("direction",t.direction),void 0!==t.maxDepth&&n.set("maxDepth",String(t.maxDepth)),void 0!==t.maxNodes&&n.set("maxNodes",String(t.maxNodes)),void 0!==t.maxRelationships&&n.set("maxRelationships",String(t.maxRelationships));let a=await fetch("/api/relationships/".concat(encodeURIComponent(e),"/dependencies?").concat(n.toString()));return(await ag(a)).report}async function aS(e){return ag(await fetch("/api/relationships/".concat(encodeURIComponent(e),"/explain")))}async function aC(){return ag(await fetch("/api/relationships/health"))}let aR=[{key:"t",mod:["cmd"]},{key:"t",mod:["ctrl"]},{key:"r",mod:["cmd"]},{key:"r",mod:["ctrl"]},{key:"n",mod:["cmd","shift"]},{key:"n",mod:["ctrl","shift"]},{key:"w",mod:["cmd"]},{key:"w",mod:["ctrl"]}];function aE(e){switch(e.kind){case"ui.window.move":return"Move window";case"ui.window.resize":return"Resize window";case"ui.window.zorder":return"Reorder window";case"ui.window.close":return"Close window";case"ui.window.open":return"Open window";case"ui.workspace.pan":return"Pan workspace";case"ui.workspace.zoom":return"Zoom workspace";case"ui.workspace.fit":return"Fit workspace to view";case"ui.panel.toggle":return"Toggle ".concat(e.panel," panel");case"ui.selection.change":return"Change selection";case"ui.tab.switch":return"Switch tab"}}function aI(e){let t=[...e.mod].sort();return"".concat(t.join("+"),"|").concat(e.key.toLowerCase())}let aT={undoStack:[],redoStack:[]};class aF extends Error{constructor(e){super("Workspace keyboard shortcut conflicts detected: ".concat(e.map(e=>"".concat(aI(e.chord)," (").concat(e.commandIds.join(", "),")")).join("; "))),this.name="WorkspaceShortcutConflictError",this.conflicts=e}}class aq extends Error{constructor(e){super("Workspace keyboard shortcut bindings refused: ".concat(e.map(e=>"".concat(e.commandId," → ").concat(aI(e.chord))).join("; ")," are browser-reserved")),this.name="WorkspaceShortcutReservedError",this.reserved=e}}let aA=[{commandId:"undo",chord:{key:"z",mod:["cmd"]}},{commandId:"redo",chord:{key:"z",mod:["cmd","shift"]}},{commandId:"focus-status",chord:{key:"s",mod:["alt"]}}];function aM(e){let{project:t,activeProjectPath:n,chats:s,activeChatId:i,onProject:r,onChat:o}=e,c=n===t.path,[d,u]=(0,l.useState)(c),h=t.available?"Available":"Unavailable";return(0,l.useEffect)(()=>{c&&u(!0)},[c]),(0,a.jsxs)("div",{className:"proj",children:[(0,a.jsxs)("button",{className:"proj-head",type:"button","data-active":c?"true":"false","aria-expanded":d,"aria-current":c?"true":void 0,"aria-label":"".concat(t.name," (").concat(h,")"),onClick:()=>{u(e=>!e),r(t)},children:[(0,a.jsx)("span",{className:"proj-caret","data-open":d,children:(0,a.jsx)(N.F.chevronR,{size:13})}),(0,a.jsx)(N.F.folder,{size:15}),(0,a.jsx)("span",{className:"proj-name",children:t.name}),(0,a.jsx)("span",{className:"chat-time",children:h})]}),d&&(0,a.jsx)("div",{className:"proj-chats",children:c?0===s.length?(0,a.jsx)("div",{className:"proj-empty",children:"No chats"}):s.map(e=>(0,a.jsxs)("button",{type:"button",className:"chat-row","data-active":i===e.id,"aria-pressed":i===e.id,onClick:()=>{o(e)},children:[(0,a.jsx)("span",{className:"chat-title",children:e.title}),void 0!==e.branchLabel?(0,a.jsx)("span",{className:"chat-meta mono",children:e.branchLabel}):null]},e.id)):(0,a.jsx)("div",{className:"proj-empty",children:"Select project to load chats"})})]})}function aP(){let e=r();return(0,a.jsxs)("div",{className:"tw-scroll",children:[(0,a.jsx)("div",{className:"sb-section",children:(0,a.jsx)("span",{className:"sb-section-label",children:"Projects"})}),0===e.projects.length?(0,a.jsx)("div",{className:"proj-empty",children:"No registered projects"}):e.projects.map(t=>{var n,l,s;return(0,a.jsx)(aM,{project:t,activeProjectPath:null==(n=e.activeProject)?void 0:n.path,chats:(null==(l=e.activeProject)?void 0:l.path)===t.path?e.chats:[],activeChatId:null==(s=e.activeChat)?void 0:s.id,onProject:t=>{e.openProject(t)},onChat:t=>{e.openChat(t)}},t.path)})]})}function aD(){var e,t;let n=o(),l=null!=(t=null==n||null==(e=n.activeProject)?void 0:e.name)?t:"No project selected";return(0,a.jsxs)("div",{className:"srch",children:[(0,a.jsxs)("div",{className:"srch-box",children:[(0,a.jsx)(N.F.search,{size:15,"aria-hidden":"true"}),(0,a.jsx)("input",{type:"search","aria-label":"Search files and symbols",placeholder:"Search files & symbols…",disabled:!0})]}),(0,a.jsxs)("div",{className:"tw-label srch-label",children:[l," ",(0,a.jsx)("span",{className:"srch-meta mono",children:"workspace search"})]}),(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsxs)("div",{className:"rb-placeholder",style:{height:150},children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)("span",{className:"rb-ph-label mono",children:"search"})]}),(0,a.jsx)("div",{className:"rb-foot mono",style:{marginTop:14},children:"Search across workspace files & symbols — coming soon."})]})]})}let aL=[{name:"Context7",img:"upstash",desc:"Up-to-date library docs",on:!0},{name:"Sequential Thinking",icon:"layers",desc:"Step-by-step reasoning",on:!0},{name:"Filesystem",icon:"files",desc:"Local file access",on:!0},{name:"GitHub",img:"github",desc:"Repos \xb7 PRs \xb7 issues",on:!0},{name:"Playwright",img:"playwright",desc:"Browser automation",on:!1},{name:"Brave Search",img:"brave",desc:"Web search",on:!1},{name:"MemoriaViva",icon:"cube",desc:"Knowledge graph",on:!0}],az=[{name:"GitHub",img:"github",on:!0},{name:"Linear",img:"linear",on:!0},{name:"PostgreSQL",img:"postgresql",on:!0},{name:"Sentry",img:"sentry",on:!1},{name:"Slack",img:"slack",on:!1},{name:"Notion",img:"notion",on:!1}];function aO(e){let{img:t,icon:n,glyph:l}=e;if(void 0!==t)return(0,a.jsx)("img",{className:"pl-img",src:"/assets/icons/".concat(t,".svg"),width:"20",height:"20",alt:""});if(void 0!==n){let e=N.F[n];return(0,a.jsx)("span",{className:"pl-line",children:(0,a.jsx)(e,{size:18})})}return(0,a.jsx)("span",{className:"mono pl-glyph",children:l})}function aK(){let[e,t]=(0,l.useState)(aL.map(e=>e.on)),n=e.filter(Boolean).length;return(0,a.jsxs)("div",{className:"plg",children:[(0,a.jsxs)("div",{className:"plg-sec",children:[(0,a.jsx)("span",{className:"plg-sec-t",children:"MCP Servers"}),(0,a.jsxs)("span",{className:"plg-sec-c mono",children:[n,"/",aL.length," active"]})]}),aL.map((n,l)=>{var s;let i=null!=(s=e[l])&&s;return(0,a.jsxs)("div",{className:"plg-row",children:[(0,a.jsx)("span",{className:"plg-ico",children:(0,a.jsx)(aO,{img:n.img,icon:n.icon})}),(0,a.jsxs)("span",{className:"plg-text",children:[(0,a.jsx)("span",{className:"plg-name",children:n.name}),(0,a.jsx)("span",{className:"plg-desc",children:n.desc})]}),(0,a.jsx)("button",{className:"plg-dot".concat(i?" on":""),title:i?"Running":"Stopped","aria-label":"".concat(n.name,": ").concat(i?"running":"stopped"),onClick:()=>{t(e=>{var t;let n=[...e];return n[l]=!(null!=(t=n[l])&&t),n})}})]},n.name)}),(0,a.jsx)("div",{className:"plg-sec plg-sec2",children:(0,a.jsx)("span",{className:"plg-sec-t",children:"Connectors"})}),az.map(e=>(0,a.jsxs)("button",{className:"plg-row plg-conn","data-on":e.on,children:[(0,a.jsx)("span",{className:"plg-ico",children:(0,a.jsx)(aO,{img:e.img})}),(0,a.jsxs)("span",{className:"plg-text",children:[(0,a.jsx)("span",{className:"plg-name",children:e.name}),(0,a.jsx)("span",{className:"plg-desc",children:e.on?"Connected":"Not connected"})]}),e.on?(0,a.jsx)("span",{className:"integ-on",children:(0,a.jsx)(N.F.check,{size:13})}):(0,a.jsx)("span",{className:"integ-add",children:(0,a.jsx)(N.F.plus,{size:14})})]},e.name))]})}let aB=[{id:"nightly-review",name:"Nightly review",when:"02:00 daily",defaultOn:!0},{id:"on-push-lint",name:"On push → lint",when:"git push",defaultOn:!0},{id:"weekly-digest",name:"Weekly digest",when:"Mon 09:00",defaultOn:!1}],aW="keiko.automations.v1",aU=Object.fromEntries(aB.map(e=>[e.id,e.defaultOn]));function a_(){try{let e=localStorage.getItem(aW);if(null===e)return{...aU};let t=JSON.parse(e);if("object"!=typeof t||null===t||Array.isArray(t))return{...aU};let n={...aU};for(let[e,a]of Object.entries(t))e in aU&&"boolean"==typeof a&&(n[e]=a);return n}catch(e){return{...aU}}}function aH(){let[e,t]=(0,l.useState)(a_);return(0,a.jsx)("div",{className:"tw-list",children:aB.map(n=>{var l;let s=null!=(l=e[n.id])?l:n.defaultOn;return(0,a.jsxs)("div",{className:"auto-row",children:[(0,a.jsx)("span",{className:"dot",style:{background:s?"var(--accent)":"var(--fg-faint)"}}),(0,a.jsxs)("span",{className:"auto-text",children:[(0,a.jsx)("span",{className:"auto-name",children:n.name}),(0,a.jsx)("span",{className:"auto-when mono",children:n.when})]}),(0,a.jsx)(tP,{on:s,onChange:()=>{var e;e=n.id,t(t=>{var n;let a={...t,[e]:!(null!=(n=t[e])&&n)};return localStorage.setItem(aW,JSON.stringify(a)),a})},label:n.name})]},n.id)})})}function aG(){return(0,a.jsxs)("div",{className:"tw-pad mob",children:[(0,a.jsxs)("div",{className:"mob-qr",children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)(N.F.mobile,{size:28,style:{position:"relative",color:"var(--fg-dim)"}})]}),(0,a.jsx)("div",{className:"mob-title",children:"Keiko Mobile"}),(0,a.jsx)("div",{className:"mob-sub",children:"Scan to continue this workspace on your phone."})]})}function aJ(){let{wins:e,active:t,winCount:n}=(0,l.useContext)(k),s=null!==t?ei[t.type]:null,i=null!==t?Object.entries(t.cfg).filter(e=>{let[,t]=e;return""!==t&&null!=t}):[];return(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsx)("div",{className:"rb-section-label",style:{marginTop:0},children:"Active window"}),null!==t&&null!==s?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"insp-top",children:[(0,a.jsx)("span",{className:"insp-ico",style:{color:!0===s.accent?"var(--accent)":"var(--fg-muted)"},children:function(e,t){let n=N.F[e];return(0,a.jsx)(n,{size:16})}(s.icon,16)}),(0,a.jsx)("span",{className:"insp-title",children:s.title})]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Size"}),(0,a.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(t.w)," \xd7 ",Math.round(t.h)]})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Position"}),(0,a.jsxs)("span",{className:"rb-row-v mono",children:[Math.round(t.x),", ",Math.round(t.y)]})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"State"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:t.max?"maximized":"floating"})]})]}),i.length>0&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"rb-section-label",children:"Configuration"}),(0,a.jsx)("div",{className:"rb-rows",children:i.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:t}),(0,a.jsx)("span",{className:"rb-row-v mono",children:String(n).slice(0,20)||"—"})]},t)})})]}),(0,a.jsx)("div",{className:"rb-section-label insp-governance",children:"Governance"}),(0,a.jsxs)("div",{className:"rb-rows insp-governance","data-testid":"insp-governance",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Authority"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nA[t.type].authority})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Persistence"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nA[t.type].persistence})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Trust"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nA[t.type].trustBoundary.join(", ")})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Lifecycle"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:nA[t.type].lifecycle.join(" → ")})]})]})]}):(0,a.jsx)("div",{className:"insp-empty",children:"No window focused"}),(0,a.jsx)("div",{className:"rb-section-label",children:"Workspace"}),(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Open windows"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n})]})})]})}let aV=[{t:"Agent finished build-board",time:"2m",c:"var(--accent)"},{t:"diff-review ready to merge",time:"9m",c:"var(--info)"},{t:"lint-pass queued",time:"14m",c:"var(--fg-faint)"}];function aX(){return(0,a.jsx)("div",{className:"tw-list",children:aV.map((e,t)=>(0,a.jsxs)("div",{className:"nt-row",children:[(0,a.jsx)("span",{className:"dot",style:{background:e.c,marginTop:6}}),(0,a.jsxs)("span",{className:"nt-text",children:[(0,a.jsx)("span",{className:"nt-title",children:e.t}),(0,a.jsxs)("span",{className:"nt-time mono",children:[e.time," ago"]})]})]},t))})}function aY(){return(0,a.jsxs)("div",{className:"tw-pad",children:[(0,a.jsxs)("div",{className:"rb-placeholder",style:{height:150},children:[(0,a.jsx)("div",{className:"ph-stripes"}),(0,a.jsx)("span",{className:"rb-ph-label mono",children:"resources"})]}),(0,a.jsx)("div",{className:"rb-foot mono",style:{marginTop:14},children:"Shared assets & references — coming soon."})]})}let aZ="keiko-activity",aQ={step:"var(--fg-dim)",approval:"var(--warn)",approved:"var(--accent)",rejected:"var(--danger)",stopped:"var(--danger)",open:"var(--info)","twin-approved":"var(--accent)","twin-denied":"var(--danger)"};function a$(){let e=function(){var e;let[,t]=(0,l.useState)(0);return(0,l.useEffect)(()=>{let e=()=>{t(e=>e+1)};return window.addEventListener(aZ,e),()=>{window.removeEventListener(aZ,e)}},[]),null!=(e=window.__keikoActivity)?e:[]}();return(0,a.jsxs)("div",{className:"tl",role:"log","aria-label":"Activity timeline",children:[0===e.length&&(0,a.jsxs)("div",{className:"tl-empty",children:["No activity yet.",(0,a.jsx)("br",{}),"Start an agent to see its actions stream here."]}),e.map((e,t)=>{var n,l;return(0,a.jsxs)("div",{className:"tl-row",children:[(0,a.jsx)("span",{className:"tl-dot","aria-hidden":"true",style:{background:null!=(n=aQ[e.type])?n:"var(--fg-faint)"}}),(0,a.jsxs)("div",{className:"tl-body",children:[(0,a.jsx)("span",{className:"visually-hidden",children:e.type}),(0,a.jsx)("span",{className:"tl-text",children:e.text}),(0,a.jsxs)("span",{className:"tl-meta mono",children:[null!=(l=e.agent)?l:"workspace"," \xb7 ",new Date(e.time).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})]})]})]},t)})]})}function a0(e){let{chatId:t,scopeKind:n,currentScopeKind:s,candidateRelativePaths:i,onConnected:r,chat:o,updateScope:c=$.Mr,now:d=Date.now,targetName:u}=e,h=(0,l.useId)(),[p,m]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),v="workspace-root"!==n&&0===i.length,x=v||p,y=void 0!==s?"Update connected scope":"workspace-root"===n?"Connect repository":"directory"===n?"Connect folder":"Connect to chat",b=void 0!==u?"".concat(y,": ").concat(u):y,j=v?"Select a folder or file first":b;async function w(){if(!x){g(null),m(!0);try{let e={kind:n,relativePaths:[...i],connectedAtMs:d()},a=[...ep(null!=o?o:{}).filter(t=>t.kind!==e.kind||JSON.stringify(t.relativePaths)!==JSON.stringify(e.relativePaths)),e],l=await c(t,a);null==r||r(l.chat)}catch(e){g(ee(e,"Unable to connect scope."))}finally{m(!1)}}}return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"scope-connect-btn",disabled:p,"aria-disabled":v,"aria-label":v?"Connect to chat (no selection)":b,"aria-describedby":v?h:void 0,title:j,onClick:()=>{v||w()},children:p?"Connecting…":y}),v?(0,a.jsx)("span",{id:h,className:"scope-connect-hint",children:"Select a folder or file first."}):null,null!==f?(0,a.jsx)("span",{role:"alert",className:"scope-connect-error",children:f}):null]})}function a1(e){let{name:t,icon:n}=e,l=null!=n?n:function(e){let t=e.toLowerCase();return"dockerfile"===t||t.includes("docker-compose")||t.endsWith(".dockerignore")?"docker":t.endsWith(".json")?"json":t.endsWith(".yml")||t.endsWith(".yaml")?"yaml":t.endsWith(".md")?"markdown":t.endsWith(".properties")||t.endsWith(".env")||t.startsWith(".env.")?"properties":t.endsWith(".java")?"java":t.endsWith(".tsx")?"react":t.endsWith(".ts")?"typescript":t.endsWith(".jsx")||t.endsWith(".js")||t.endsWith(".mjs")||t.endsWith(".cjs")?"javascript":t.endsWith(".py")?"python":t.endsWith(".go")?"go":t.endsWith(".rs")?"rust":t.endsWith(".gradle")?"gradle":t.endsWith(".sql")?"postgresql":t.endsWith(".html")?"html5":t.endsWith(".css")?"css3":t.endsWith(".graphql")||t.endsWith(".gql")?"graphql":t.endsWith(".png")||t.endsWith(".jpg")||t.endsWith(".jpeg")||t.endsWith(".gif")||t.endsWith(".webp")||t.endsWith(".svg")?"image":null}(t);return null!==l?(0,a.jsx)("img",{className:"fi-img",src:"/assets/icons/".concat(l,".svg"),width:"15",height:"15",alt:""}):(0,a.jsx)("span",{className:"fi-fallback",children:(0,a.jsx)(N.F.file,{size:14})})}let a2={jsx:"js",js:"js",mjs:"js",ts:"ts",tsx:"ts",java:"java",kt:"kotlin",kts:"kotlin",py:"py",rb:"py",go:"go",rs:"rust",json:"json",yml:"yaml",yaml:"yaml",md:"md",markdown:"md",html:"html",xml:"html",css:"css",sql:"sql",sh:"sh",bash:"sh",cob:"cobol",cbl:"cobol",gradle:"js",graphql:"graphql",gql:"graphql",properties:"props",toml:"props",env:"props",dockerfile:"docker"};function a3(e){var t;let n=e.toLowerCase();if(".env"===n||n.startsWith(".env."))return"props";if("dockerfile"===n||n.startsWith("dockerfile"))return"docker";if(n.includes("docker-compose"))return"yaml";let a=n.split("."),l=a.length>1?a[a.length-1]:void 0;return void 0===l?"code":null!=(t=a2[l])?t:"code"}let a4=new Set("const let var function return if else for while do switch case break continue import from export default class extends implements interface enum new async await yield of in typeof instanceof this super public private protected static final readonly void int long double float boolean char byte short val fun object data override companion package def pass lambda try catch except finally throw throws raise with as not and or is null nil None True False true false undefined struct impl trait pub use mod match where select insert update delete create table from join on group by order limit FROM RUN CMD ENV COPY WORKDIR EXPOSE ENTRYPOINT AS".split(" "));function a6(e){let t=[];return e.split(/(`[^`]+`|\*\*[^*]+\*\*)/).forEach(e=>{""!==e&&(e.startsWith("`")?t.push(["str",e]):e.startsWith("**")?t.push(["type",e]):t.push(["id",e]))}),t.length>0?t:[["id",e]]}function a5(e,t){if("md"===t)return e.split("\n").map(e=>{if(/^#{1,6}\s/.test(e))return[["head",e]];if(/^\s*```/.test(e))return[["com",e]];let t=/^(\s*)([-*+]|\d+\.)(\s)/.exec(e);if(null!==t){var n,a,l;let s=null!=(n=t[1])?n:"";return[["ws",s],["key",null!=(a=t[2])?a:""],["ws",null!=(l=t[3])?l:""],...a6(e.slice(t[0].length))]}return a6(e)});if("json"===t)return e.split("\n").map(e=>{let t=[],n=0;for(;n<e.length;){let a=e.slice(n),l=/^"(?:[^"\\]|\\.)*"/.exec(a);if(null!==l){let a=e.slice(n+l[0].length),s=/^\s*:/.test(a);t.push([s?"key2":"str",l[0]]),n+=l[0].length;continue}let s=/^-?\d[\d.eE+\-]*/.exec(a);if(null!==s){t.push(["num",s[0]]),n+=s[0].length;continue}let i=/^(true|false|null)\b/.exec(a);if(null!==i){t.push(["lit",i[0]]),n+=i[0].length;continue}let r=/^\s+/.exec(a);if(null!==r){t.push(["ws",r[0]]),n+=r[0].length;continue}t.push(["punct",a.charAt(0)]),n+=1}return t});let n="py"===t||"sh"===t||"yaml"===t||"props"===t||"docker"===t?{line:"#",block:null}:"sql"===t?{line:"--",block:["/*","*/"]}:"cobol"===t?{line:"*>",block:null}:"html"===t?{line:null,block:["\x3c!--","--\x3e"]}:{line:"//",block:["/*","*/"]},a={inBlock:!1},l=[];for(let t of e.split("\n"))l.push(function(e,t,n){let a=[],l=0;if(t.inBlock&&null!==n.block){let s=e.indexOf(n.block[1]);if(-1===s)return a.push(["com",e]),a;a.push(["com",e.slice(0,s+n.block[1].length)]),l=s+n.block[1].length,t.inBlock=!1}for(;l<e.length;){let i=e.slice(l);if(null!==n.line&&i.startsWith(n.line)){a.push(["com",i]);break}if(null!==n.block&&i.startsWith(n.block[0])){let s=e.indexOf(n.block[1],l+n.block[0].length);if(-1===s){a.push(["com",i]),t.inBlock=!0;break}a.push(["com",e.slice(l,s+n.block[1].length)]),l=s+n.block[1].length;continue}let r=/^(?:"(?:[^"\\]|\\.)*"?|'(?:[^'\\]|\\.)*'?)/.exec(i);if(null!==r&&r[0].length>1){a.push(["str",r[0]]),l+=r[0].length;continue}if(/^\d/.test(i)){var s;let e=/^\d[\w.]*/.exec(i),t=null!=(s=null==e?void 0:e[0])?s:i.charAt(0);a.push(["num",t]),l+=t.length;continue}let o=/^[@A-Za-z_$][\w$]*/.exec(i);if(null!==o){let t=o[0],n="id";a4.has(t)?n="key":t.startsWith("@")||/^[A-Z]/.test(t)?n="type":"("===e.charAt(l+t.length)&&(n="fn"),a.push([n,t]),l+=t.length;continue}let c=/^\s+/.exec(i);if(null!==c){a.push(["ws",c[0]]),l+=c[0].length;continue}let d=/^[^\w\s$@]+/.exec(i);if(null!==d){a.push(["punct",d[0]]),l+=d[0].length;continue}a.push(["id",i.charAt(0)]),l+=1}return a}(t,a,n));return l}function a8(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,a=0;for(;n>=1024&&a<t.length-1;)n/=1024,a+=1;let l=0===a?n.toFixed(0):n.toFixed(n>=10?1:2);return"".concat(l," ").concat(t[a])}function a9(e){return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(e))}function a7(e){let{label:t,value:n}=e;return(0,a.jsxs)("div",{className:"fpv-meta-row",children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)("strong",{children:n})]})}function le(e){var t,n,s,i,r,c;let{root:d,path:u,onClose:h}=e,p=o(),m=null==p?void 0:p.activeChat,f=u.length>0?[u]:[],[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(!0),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(0),S=(0,l.useRef)(null);(0,l.useEffect)(()=>{var e;null==(e=S.current)||e.focus({preventScroll:!0})},[]),(0,l.useEffect)(()=>{let e=!1;return y(!0),j(null),v(null),(0,$.q7)(d,u).then(t=>{e||v(t)}).catch(t=>{e||j(t instanceof $.hD&&"DENIED"===t.code?{message:"This file is excluded from the read surface for safety (matches a deny pattern such as .env, *.pem, node_modules, .git, …).",denied:!0}:t instanceof Error?{message:/^HTTP \d+$/.test(t.message)?"The file could not be loaded. Try again.":t.message,denied:!1}:{message:"Unable to read this file.",denied:!1})}).finally(()=>{e||y(!1)}),()=>{e=!0}},[u,d,w]);let C=(null==b?void 0:b.denied)===!0,R=null!==g?"text"===g.kind?null!=(r=g.extension)?r:"text":"image"===g.kind?g.mime:null!=(c=g.extension)?c:"binary":C?"denied":null!==b?"error":"loading",E=C?"Hidden file":null!=(n=null==g?void 0:g.name)?n:null!==b?"Preview unavailable":"Loading preview",I=(null==g?void 0:g.kind)==="text"&&g.content.length<=2e5,T=(null==g?void 0:g.kind)==="text"?I?a5(g.content,a3(g.name)):g.content.split("\n").map(e=>[["id",e]]):[];return(0,a.jsxs)("div",{className:"fpv",onKeyDown:e=>{"Escape"===e.key&&(e.stopPropagation(),h())},children:[(0,a.jsxs)("div",{className:"fpv-bar",children:[(0,a.jsx)("button",{className:"fpv-back",type:"button",ref:S,onClick:h,title:"Back to files","aria-label":"Back to files",children:(0,a.jsx)(N.F.back,{size:15})}),(0,a.jsx)(a1,{name:C||null===g?"":g.name}),(0,a.jsx)("span",{className:"fpv-name",title:E,children:E}),(0,a.jsx)("span",{className:"fpv-lang mono",children:R}),(0,a.jsx)("span",{className:"spacer"}),void 0!==m&&null!==p?(0,a.jsx)(a0,{chatId:m.id,scopeKind:"files",currentScopeKind:null==(t=m.connectedScope)?void 0:t.kind,candidateRelativePaths:f,chat:m,onConnected:p.replaceChat}):null,(0,a.jsx)("button",{className:"fpv-back",type:"button",onClick:h,title:"Close preview","aria-label":"Close preview",children:(0,a.jsx)(N.F.close,{size:15})})]}),x?(0,a.jsx)("div",{className:"fpv-state",role:"status",children:"Loading preview…"}):null,null!==b?(0,a.jsxs)("div",{className:"fpv-state fpv-error",role:"alert",children:[(0,a.jsx)("span",{children:b.message}),b.denied?null:(0,a.jsx)("button",{type:"button",className:"fpv-retry",onClick:()=>k(e=>e+1),children:"Retry"})]}):null,(null==g?void 0:g.kind)==="text"?(0,a.jsxs)(a.Fragment,{children:[g.truncated?(0,a.jsxs)("div",{className:"fpv-banner",children:["Preview truncated at ",a8(g.maxBytes),". Larger files can't be shown in full here."]}):null,I?null:(0,a.jsx)("div",{className:"fpv-banner",children:"Syntax highlighting disabled for large previews."}),(0,a.jsx)("div",{className:"fpv-code mono",tabIndex:0,role:"region","aria-label":"File preview: ".concat(g.name),style:{"--fpv-gutter-w":"max(44px, calc(".concat(String(String(T.length).length),"ch + 16px))")},children:T.map((e,t)=>(0,a.jsxs)("div",{className:"fpv-line",children:[(0,a.jsx)("span",{className:"fpv-num",children:t+1}),(0,a.jsx)("span",{className:"fpv-src",children:e.map((e,t)=>(0,a.jsx)("span",{className:"hl-".concat(e[0]),children:e[1]},t))})]},t))})]}):null,(null==g?void 0:g.kind)==="image"?(0,a.jsxs)("div",{className:"fpv-image-pane",children:[(0,a.jsx)("div",{className:"fpv-image-card",children:(0,a.jsx)("img",{className:"fpv-image",src:g.dataUrl,alt:g.name})}),(0,a.jsxs)("div",{className:"fpv-meta",children:[(0,a.jsx)(a7,{label:"Type",value:g.mime}),(0,a.jsx)(a7,{label:"Size",value:a8(g.sizeBytes)}),(0,a.jsx)(a7,{label:"Modified",value:a9(g.modifiedAt)})]})]}):null,(null==g?void 0:g.kind)==="binary"?(0,a.jsx)("div",{className:"fpv-meta-pane",children:(0,a.jsxs)("div",{className:"fpv-meta-card",children:[(0,a.jsx)(a1,{name:g.name}),(0,a.jsx)("h3",{children:g.name}),(0,a.jsx)("p",{children:"too_large"===g.reason?"Preview disabled because this file exceeds ".concat(a8(null!=(s=g.maxBytes)?s:0),"."):"No safe text or image preview is available for this file type."}),(0,a.jsxs)("div",{className:"fpv-meta",children:[(0,a.jsx)(a7,{label:"Type",value:g.mime}),(0,a.jsx)(a7,{label:"Extension",value:null!=(i=g.extension)?i:"none"}),(0,a.jsx)(a7,{label:"Size",value:a8(g.sizeBytes)}),(0,a.jsx)(a7,{label:"Modified",value:a9(g.modifiedAt)})]})]})}):null]})}function lt(e){let t=e.replace(/[/\\]+$/,""),n=Math.max(t.lastIndexOf("/"),t.lastIndexOf("\\"));return n<0?null:0===n?"/":/^[A-Za-z]:$/.test(t.slice(0,n))?"".concat(t.slice(0,n),"\\"):t.slice(0,n)}function ln(e){return 8+18*e}let la=new Set(["ArrowDown","ArrowUp","ArrowRight","ArrowLeft","Home","End"]);function ll(e){var t;let{root:n,onActiveFileChange:s,onRootChange:i}=e,r=o(),c=null==r?void 0:r.activeChat,d=null==n?void 0:n.trim(),u=void 0!==d&&d.length>0?d:null,[h,p]=(0,l.useState)(null),m=null!=(t=null!=u?u:h)?t:"",[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)({}),[k,S]=(0,l.useState)(()=>new Set([""])),[C,R]=(0,l.useState)(0),E=(0,l.useRef)(s);E.current=s;let I=(0,l.useRef)(null),T=(0,l.useRef)(null),F=(0,l.useId)();(0,l.useEffect)(()=>{var e,t;if(null!==y)return;let n=T.current;if(null===n)return;T.current=null;let a=null==(e=I.current)?void 0:e.querySelector('.tr-file[data-path="'.concat("undefined"!=typeof CSS&&"function"==typeof CSS.escape?CSS.escape(n):n.replace(/\\/g,"\\\\").replace(/"/g,'\\"'),'"]'));null==(t=null!=a?a:I.current)||t.focus({preventScroll:!0})},[y]),(0,l.useEffect)(()=>{if(null!==u)return;let e=!1;return(0,$.vj)().then(t=>{var n;if(e)return;let a=null==(n=t.projects.find(e=>e.available))?void 0:n.path;p(null!=a?a:null)}).catch(()=>{e||p(null)}),()=>{e=!0}},[u]);let q=(0,l.useCallback)(async e=>{if(0===m.length)return void w(t=>({...t,[e]:{entries:[],truncated:!1,loading:!1,error:null,notice:"no-root"}}));w(t=>{var n,a,l,s;return{...t,[e]:{entries:null!=(l=null==(n=t[e])?void 0:n.entries)?l:[],truncated:null!=(s=null==(a=t[e])?void 0:a.truncated)&&s,loading:!0,error:null,notice:null}}});try{let n=await (0,$.KD)(m,e);if(""===e){var t;g(n.root),null==(t=E.current)||t.call(E,null,n.root)}w(t=>({...t,[e]:{entries:n.entries,truncated:n.truncated,loading:!1,error:null,notice:null}}))}catch(t){w(n=>{var a,l,s,i;return{...n,[e]:{entries:null!=(s=null==(a=n[e])?void 0:a.entries)?s:[],truncated:null!=(i=null==(l=n[e])?void 0:l.truncated)&&i,loading:!1,error:t instanceof Error?t.message:"Unable to read this folder.",notice:null}}})}},[m]);(0,l.useEffect)(()=>{var e;b(null),null==(e=E.current)||e.call(E,null,null),g(null),S(new Set([""])),w({}),q("")},[m,q,C]),(0,l.useEffect)(()=>{x(null!=f?f:m.length>0?m:"")},[f,m]);let A=(0,l.useCallback)(e=>{let t=e.trim();void 0!==i&&0!==t.length&&t!==(null!=f?f:m)&&i(t)},[i,f,m]),M=(0,l.useCallback)(()=>{let e=lt(null!=f?f:m);null!==e&&A(e)},[f,m,A]),P=(e,t,n)=>{var l;return null===r||void 0===c||0===m.length||"workspace-root"!==e&&0===t.length?null:(0,a.jsx)(a0,{chatId:c.id,scopeKind:e,currentScopeKind:null==(l=c.connectedScope)?void 0:l.kind,candidateRelativePaths:"workspace-root"===e?[]:[t],chat:c,onConnected:r.replaceChat,targetName:n})},D=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:j[e];return(0,a.jsxs)("div",{className:"tr-dir",role:0===t?void 0:"group",children:[(null==n?void 0:n.loading)===!0?(0,a.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:ln(t)+18},children:"Loading…"}):null,(null==n?void 0:n.notice)==="no-root"?(0,a.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:ln(t)+18},children:void 0!==i?"No folder is open yet. Enter a folder path above and press Open.":"No registered project is available."}):null,(null==n?void 0:n.error)!==null&&(null==n?void 0:n.error)!==void 0?(0,a.jsxs)("div",{className:"files-error",role:"alert",style:{marginLeft:ln(t)},children:[(0,a.jsx)("span",{children:n.error}),(0,a.jsx)("button",{type:"button",className:"files-retry",onClick:()=>{q(e)},children:"Retry"})]}):null,(null==n?void 0:n.truncated)===!0?(0,a.jsxs)("div",{className:"files-note files-warning",role:"status",style:{paddingLeft:ln(t)+18},children:["Showing only the first ",n.entries.length," entries — this folder contains more."]}):null,null==n?void 0:n.entries.map(e=>((e,t)=>{let n=ln(t),l=k.has(e.path),s="This link can't be opened from this folder.";if("directory"===e.kind){let i=j[e.path];return(0,a.jsxs)("div",{className:"tr-row-wrap",children:[(0,a.jsxs)("button",{className:"tr-row",role:"treeitem","aria-level":t+1,"aria-selected":!1,"data-readable":e.readable,style:{paddingLeft:n},type:"button","aria-disabled":!e.readable||void 0,"aria-describedby":e.readable?void 0:F,"aria-expanded":l,onClick:()=>(e=>{if(!e.readable)return;let t=k.has(e.path);S(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),t||void 0!==j[e.path]||q(e.path)})(e),title:e.readable?e.path:s,children:[(0,a.jsx)("span",{className:"tr-caret","data-open":l,children:(0,a.jsx)(N.F.chevronR,{size:11})}),(0,a.jsx)("span",{className:"fi-fallback",style:{color:"var(--accent)"},children:(0,a.jsx)(N.F.folder,{size:14})}),(0,a.jsx)("span",{className:"tr-name tr-folder",children:e.name}),e.symlink?(0,a.jsx)("span",{className:"tr-badge",children:"link"}):null]}),e.readable?(0,a.jsx)("div",{className:"tr-connect",style:{paddingLeft:n+20},children:P("directory",e.path,e.name)}):null,l?D(e.path,t+1,i):null]},e.path)}return(0,a.jsxs)("button",{className:"tr-row tr-file",role:"treeitem","aria-level":t+1,"aria-selected":y===e.path,"data-active":y===e.path,"data-readable":e.readable,"data-path":e.path,style:{paddingLeft:n},type:"button","aria-disabled":!e.readable||void 0,"aria-describedby":e.readable?void 0:F,onClick:()=>{var t;e.readable&&(b(e.path),null==(t=E.current)||t.call(E,e.path,null!=f?f:m))},title:e.readable?e.path:s,children:[(0,a.jsx)("span",{className:"tr-caret tr-caret-ghost","aria-hidden":"true",children:(0,a.jsx)(N.F.chevronR,{size:11})}),(0,a.jsx)(a1,{name:e.name}),(0,a.jsx)("span",{className:"tr-name",children:e.name}),e.symlink?(0,a.jsx)("span",{className:"tr-badge",children:"link"}):null,(0,a.jsx)("span",{className:"tr-meta mono",children:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,a=0;for(;n>=1024&&a<t.length-1;)n/=1024,a+=1;let l=0===a?n.toFixed(0):n.toFixed(n>=10?1:2);return"".concat(l," ").concat(t[a])}(e.sizeBytes)})]},e.path)})(e,t)),void 0===n||n.loading||null!==n.error||null!==n.notice||0!==n.entries.length?null:(0,a.jsx)("div",{className:"files-note",role:"status",style:{paddingLeft:ln(t)+18},children:"Empty folder."})]})};return null!==y?(0,a.jsx)(le,{root:null!=f?f:m,path:y,onClose:()=>{var e;T.current=y,b(null),null==(e=E.current)||e.call(E,null,null!=f?f:m)}}):(0,a.jsxs)("div",{className:"files",ref:I,tabIndex:-1,children:[void 0!==i?(0,a.jsxs)("form",{className:"files-root-bar",role:"group","aria-label":"Folder root",onSubmit:e=>{e.preventDefault(),A(v)},children:[(0,a.jsx)("button",{type:"button",className:"files-root-up",onClick:M,disabled:null===lt(null!=f?f:m),title:"Open parent folder","aria-label":"Open parent folder",children:(0,a.jsx)(N.F.arrowUp,{size:13})}),(0,a.jsx)("input",{type:"text",className:"files-root-input mono","aria-label":"Folder path — open any folder on this machine",placeholder:"/path/to/any/folder",spellCheck:!1,value:v,onChange:e=>x(e.target.value)}),(0,a.jsx)("button",{type:"submit",className:"files-root-open",title:"Open this folder",children:"Open"})]}):null,(0,a.jsx)("button",{className:"files-refresh",type:"button",onClick:()=>R(e=>e+1),title:"Refresh folder","aria-label":"Refresh folder",children:(0,a.jsx)(N.F.reset,{size:13})}),(()=>{let e=P("workspace-root","");return null===e?null:(0,a.jsxs)("div",{className:"files-scope-bar",role:"group","aria-label":"Repository scope connector",children:[(0,a.jsx)("span",{className:"files-scope-label",children:"Repository scope"}),e]})})(),(0,a.jsx)("span",{id:F,className:"visually-hidden",children:"This link can't be opened from this folder."}),(0,a.jsx)("div",{className:"tr files-tree",role:"tree","aria-label":"Files",tabIndex:-1,onKeyDown:e=>{if(!la.has(e.key))return;let t=e.target,n=t instanceof HTMLElement?t.closest("button.tr-row"):null;if(null===n)return;let a=Array.from(e.currentTarget.querySelectorAll("button.tr-row")),l=a.indexOf(n);l<0||(e.preventDefault(),function(e,t,n){var a,l,s,i,r;let o=e[t];if(void 0!==o)if("ArrowDown"===n)null==(a=e[t+1])||a.focus();else if("ArrowUp"===n)null==(l=e[t-1])||l.focus();else if("Home"===n)null==(s=e[0])||s.focus();else if("End"===n)null==(i=e[e.length-1])||i.focus();else if("ArrowRight"===n){let n=o.getAttribute("aria-expanded");"false"===n?o.click():"true"===n&&(null==(r=e[t+1])||r.focus())}else"ArrowLeft"===n&&("true"===o.getAttribute("aria-expanded")?o.click():function(e,t){var n,a,l,s,i;let r=Number(null!=(a=null==(n=e[t])?void 0:n.getAttribute("aria-level"))?a:"1");for(let n=t-1;n>=0;n-=1)if(Number(null!=(s=null==(l=e[n])?void 0:l.getAttribute("aria-level"))?s:"1")<r){null==(i=e[n])||i.focus();return}}(e,t))}(a,l,e.key))},children:D("",0)})]})}let ls=[{n:1,t:[["k","const"],[""," "],["v","{ useState }"],[""," = "],["v","React"]]},{n:2,t:[]},{n:3,t:[["k","function"],[""," "],["f","WindowFrame"],["p","({ win, on })"],[""," {"]]},{n:4,t:[[""," "],["k","const"],[""," [drag, setDrag] = "],["f","useState"],["p","(null)"]]},{n:5,t:[[""," "],["k","return"],[""," "],["p","<section"],["a"," className"],["","="],["s",'"window"'],["p",">"]]},{n:6,t:[[""," "],["c","// drag \xb7 resize \xb7 snap"]]},{n:7,t:[[""," "],["p","</section>"]]},{n:8,t:[["","}"]]}];function li(e){let{file:t="windows.jsx"}=e;return(0,a.jsxs)("div",{className:"editor",children:[(0,a.jsx)("div",{className:"ed-tabs mono",children:(0,a.jsxs)("span",{className:"ed-tab active",children:[(0,a.jsx)(N.F.editor,{size:12})," ",t]})}),(0,a.jsx)("div",{className:"ed-mock-note",role:"note",children:"Static demo — file editing isn't available yet. Use the Files window to browse real files."}),(0,a.jsx)("div",{className:"ed-code mono",tabIndex:0,role:"region","aria-label":"Code preview: ".concat(t),children:ls.map(e=>(0,a.jsxs)("div",{className:"ed-line",children:[(0,a.jsx)("span",{className:"ed-num",children:e.n}),(0,a.jsx)("span",{className:"ed-src",children:e.t.map((e,t)=>(0,a.jsx)("span",{className:""===e[0]?void 0:"tk-".concat(e[0]),children:e[1]},t))})]},e.n))})]})}async function lr(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s="GET"!==l&&"HEAD"!==l,i=await fetch(e,{...t,headers:{Accept:"application/json",...s?{"Content-Type":"application/json"}:{},...s?{"X-Keiko-CSRF":"1"}:{},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!i.ok){let e="INTERNAL",t="HTTP ".concat(i.status.toString());try{let n=await i.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,i.status)}if(204!==i.status)return i.json()}async function lo(e){return lr("/api/browser/status?port=".concat(encodeURIComponent(String(e))))}async function lc(e){return lr("/api/browser/sessions",{method:"POST",body:JSON.stringify({port:e})})}async function ld(e){await lr("/api/browser/sessions/".concat(encodeURIComponent(e)),{method:"DELETE"})}async function lu(e,t){return lr("/api/browser/sessions/".concat(encodeURIComponent(e),"/navigate"),{method:"POST",body:JSON.stringify({url:t})})}async function lh(e){return lr("/api/browser/sessions/".concat(encodeURIComponent(e),"/screenshot"),{method:"POST",body:JSON.stringify({})})}async function lp(e,t){return lr("/api/browser/sessions/".concat(encodeURIComponent(e),"/apply"),{method:"POST",body:JSON.stringify({captureSeq:t})})}async function lm(e){return lr("/api/browser/sessions/".concat(encodeURIComponent(e),"/content"),{method:"POST",body:JSON.stringify({})})}function lf(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function lg(e){var t,n;let s=null!=(t=e.cdpPort)?t:9222,i=null!=(n=e.url)?n:"http://localhost:5173",[r,o]=(0,l.useState)(String(s)),[c,d]=(0,l.useState)(i),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(null),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)([]),[k,N]=(0,l.useState)(null),[S,C]=(0,l.useState)(null),[R,E]=(0,l.useState)(null),I=(0,l.useRef)(null),T=(0,l.useCallback)(()=>{b(null)},[]),F=(0,l.useCallback)(e=>{w(t=>{let n=[...t,e];return n.length>50?n.slice(n.length-50):n}),"navigated"===e.kind&&"string"==typeof e.payload.originOnly&&E(e.payload.originOnly),"error"===e.kind&&b({code:"string"==typeof e.payload.code?e.payload.code:"INTERNAL",message:"string"==typeof e.payload.message?e.payload.message:"Error."})},[]);(0,l.useEffect)(()=>{var e,t;if(null===u){null==(e=I.current)||e.close(),I.current=null;return}let n=new EventSource((t=u.sessionId,"/api/browser/sessions/".concat(encodeURIComponent(t),"/events")));for(let e of["session-opened","navigated","screenshot-captured","page-content-captured","session-closed","trust-warning","error"])n.addEventListener("browser:".concat(e),e=>{try{let t=JSON.parse(e.data);F(t)}catch(e){}});return I.current=n,()=>{n.close(),I.current=null}},[u,F]);let q=(0,l.useCallback)(async()=>{T(),g(!0);try{let e=Number.parseInt(r,10),t=await lo(e);m(t)}catch(e){b(lf(e))}finally{g(!1)}},[r,T]),A=(0,l.useCallback)(async()=>{T(),g(!0);try{let e=Number.parseInt(r,10),t=await lc(e);h(t),w([]),C(null),E(null)}catch(e){b(lf(e))}finally{g(!1)}},[r,T]),M=(0,l.useCallback)(async()=>{if(null!==u){T(),g(!0);try{await ld(u.sessionId),h(null),N(null),C(null),E(null)}catch(e){b(lf(e))}finally{g(!1)}}},[u,T]),P=(0,l.useCallback)(async()=>{if(null!==u){T(),g(!0);try{let e=await lu(u.sessionId,c);E(e.originOnly)}catch(e){b(lf(e))}finally{g(!1)}}},[u,c,T]),D=(0,l.useCallback)(async()=>{if(null!==u){T(),g(!0);try{let e=await lh(u.sessionId);e.persisted||N({seq:e.seq,dataBase64:e.dataBase64})}catch(e){b(lf(e))}finally{g(!1)}}},[u,T]),L=(0,l.useCallback)(async()=>{if(null!==u&&null!==k){T(),g(!0);try{let e=await lp(u.sessionId,k.seq);e.persisted&&C(e.path),N(null)}catch(e){b(lf(e))}finally{g(!1)}}},[u,k,T]),z=(0,l.useCallback)(async()=>{if(null!==u){T(),g(!0);try{await lm(u.sessionId)}catch(e){b(lf(e))}finally{g(!1)}}},[u,T]),O=(0,l.useMemo)(()=>f||null!==u,[f,u]),K=(0,l.useMemo)(()=>f||null===u,[f,u]),B=f||null!==u,W=f||null===k,U=f&&null!==v?v:null!==k?"Screenshot ready (dry-run) — press Apply to persist.":null!==S?"Persisted as ".concat(S,"."):null!==R?"Current origin: ".concat(R):null!==p&&null===u?"Reachable: ".concat(p.reachable?"yes":"no"):"";return(0,a.jsxs)("div",{className:"browser",children:[(0,a.jsxs)("div",{className:"bw-bar",children:[(0,a.jsx)("span",{className:"bw-dot",style:{background:null===u?"var(--line-strong)":"var(--ok)"},"aria-hidden":"true"}),(0,a.jsxs)("label",{className:"bw-field",children:[(0,a.jsx)("span",{className:"bw-field-label",children:"Port"}),(0,a.jsx)("input",{type:"text",inputMode:"numeric",className:"bw-input",value:r,onChange:e=>o(e.target.value),disabled:null!==u||f})]}),(0,a.jsxs)("label",{className:"bw-field bw-field-url",children:[(0,a.jsx)("span",{className:"bw-field-label",children:"URL"}),(0,a.jsx)("input",{type:"url",className:"bw-input bw-input-url",value:c,onChange:e=>d(e.target.value),disabled:f})]})]}),(0,a.jsxs)("div",{className:"bw-actions",role:"group","aria-label":"Browser actions",children:[(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{B||(x("Checking Chrome…"),q())},"aria-disabled":B,children:"Check"}),(0,a.jsx)("button",{type:"button",className:"bw-btn bw-btn-primary",onClick:()=>{O||(x("Opening session…"),A())},"aria-disabled":O,children:"Open session"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{K||(x("Navigating…"),P())},"aria-disabled":K,children:"Navigate"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{K||(x("Capturing screenshot…"),D())},"aria-disabled":K,children:"Screenshot"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{W||(x("Applying screenshot…"),L())},"aria-disabled":W,children:"Apply"}),(0,a.jsx)("button",{type:"button",className:"bw-btn",onClick:()=>{K||(x("Capturing HTML…"),z())},"aria-disabled":K,children:"Capture HTML"}),(0,a.jsx)("button",{type:"button",className:"bw-btn bw-btn-danger",onClick:()=>{K||(x("Closing session…"),M())},"aria-disabled":K,children:"Close"})]}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:U}),f&&null!==v?(0,a.jsx)("p",{className:"bw-status",children:v}):null,null!==p&&null===u?(0,a.jsxs)("p",{className:"bw-status",children:["Reachable: ",p.reachable?"yes":"no",null===p.browserVersion?"":" — ".concat(p.browserVersion)]}):null,null!==R?(0,a.jsxs)("p",{className:"bw-status",children:["Current origin: ",(0,a.jsx)("span",{className:"mono",children:R})]}):null,null!==k?(0,a.jsx)("p",{className:"bw-status",children:"Screenshot ready (dry-run) — press Apply to persist."}):null,null!==S?(0,a.jsxs)("p",{className:"bw-status",children:["Persisted as ",(0,a.jsx)("span",{className:"mono",children:S}),"."]}):null,null!==y?(0,a.jsxs)("div",{className:"bw-error",role:"alert",children:[y.message," ",(0,a.jsxs)("span",{className:"err-code mono",children:["(",y.code,")"]})]}):null,(0,a.jsx)("div",{className:"bw-view",children:null!==k?(0,a.jsx)("img",{className:"bw-screenshot",src:"data:image/png;base64,".concat(k.dataBase64),alt:"Pending screenshot preview"}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"ph-stripes","aria-hidden":"true"}),(0,a.jsx)("div",{className:"bw-overlay mono",children:null===u?"No session — choose a port and press Open session":"Session open — use Screenshot to capture a preview"})]})}),(0,a.jsx)("div",{className:"bw-log",role:"log","aria-label":"Browser event log",children:(0,a.jsx)("ul",{className:"bw-log-list",children:j.slice(-10).reverse().map((e,t)=>(0,a.jsxs)("li",{className:"bw-log-item",children:[(0,a.jsx)("span",{className:"bw-log-kind",children:function(e){switch(e){case"session-opened":return"session opened";case"navigated":return"navigated";case"screenshot-captured":return"screenshot captured";case"page-content-captured":return"content captured";case"session-closed":return"session closed";case"trust-warning":return"trust warning";case"error":return"error"}}(e.kind)}),(0,a.jsx)("span",{className:"bw-log-detail mono",children:function(e){let t=e.payload;if("navigated"===e.kind){let e="string"==typeof t.originOnly?t.originOnly:"",n="number"==typeof t.httpStatus?" (".concat(String(t.httpStatus),")"):"";return"".concat(e).concat(n)}return"screenshot-captured"===e.kind?!0===t.persisted?"persisted":"dry-run":"page-content-captured"===e.kind?"number"==typeof t.byteLength?"".concat(String(t.byteLength)," bytes"):"":"error"===e.kind||"trust-warning"===e.kind?"string"==typeof t.message?t.message:"string"==typeof t.warning?t.warning:"":""}(e)})]},"".concat(String(e.kind),"-").concat(String(t))))})})]})}async function lv(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s="GET"!==l&&"HEAD"!==l,i=await fetch(e,{...t,headers:{Accept:"application/json",...s?{"Content-Type":"application/json"}:{},...s?{"X-Keiko-CSRF":"1"}:{},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!i.ok){let e="INTERNAL",t="HTTP ".concat(i.status.toString());try{let n=await i.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,i.status)}if(204!==i.status)return i.json()}async function lx(){return lv("/api/terminal/policy")}async function ly(e,t){let n=new URLSearchParams;return n.set("projectId",e),void 0!==t&&t.length>0&&n.set("path",t),lv("/api/terminal/directories?".concat(n.toString()))}async function lb(e){return lv("/api/terminal/executions",{method:"POST",body:JSON.stringify(e)})}async function lj(e){await lv("/api/terminal/executions/".concat(encodeURIComponent(e)),{method:"DELETE"})}function lw(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function lk(e){var t,n;let[s,i]=(0,l.useState)(null),[r,o]=(0,l.useState)(""),[c,d]=(0,l.useState)(""),[u,h]=(0,l.useState)(null!=(t=e.cwd)?t:""),[p,m]=(0,l.useState)(null!=(n=e.projectPath)?n:""),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)(null),[k,N]=(0,l.useState)([]),S=(0,l.useRef)(null),C=(0,l.useRef)(!1),R=(0,l.useRef)(null),[E,I]=(0,l.useState)([]);(0,l.useEffect)(()=>{let e=!1;return lx().then(t=>{e||(i(t),o(e=>{var n;return e.length>0?e:null!=(n=t.commands[0])?n:""}))}).catch(t=>{e||w(lw(t))}),()=>{e=!0}},[]),(0,l.useEffect)(()=>{if(0===p.length)return void I([]);let e=!1;return ly(p,u.length>0?u:void 0).then(t=>{e||I(t.entries)}).catch(()=>{e||I([])}),()=>{e=!0}},[p,u]),(0,l.useEffect)(()=>{let e=new EventSource("/api/terminal/events");S.current=e;let t=e=>{try{let t=JSON.parse(e.data);if("execution-started"===t.kind&&C.current){let e=t.payload;"string"==typeof e.requestId&&e.requestId===R.current&&x(e=>null!==e?e:t.executionId)}if("execution-completed"===t.kind||"execution-failed"===t.kind||"execution-cancelled"===t.kind){let e=t.payload;"string"==typeof e.requestId&&e.requestId===R.current&&x(e=>null===e||e!==t.executionId?e:null)}N(e=>{let n=[t,...e];return n.length>30?n.slice(0,30):n})}catch(e){}};for(let n of["execution-started","execution-completed","execution-failed","execution-cancelled"])e.addEventListener("terminal:".concat(n),t);return()=>{e.close(),S.current=null}},[]);let T=(0,l.useCallback)(async e=>{if(e.preventDefault(),f)return;w(null),b(null),x(null);let t="function"==typeof crypto.randomUUID?crypto.randomUUID():"terminal-".concat(Date.now().toString(36),"-").concat(Math.random().toString(36).slice(2));R.current=t;let n=function(e){let t=e.trim();return 0===t.length?[]:t.split(/\s+/)}(c);C.current=!0,g(!0);try{let e={projectId:p,command:r,args:n,...u.length>0?{cwd:u}:{},requestId:t},a=await lb(e);b(a)}catch(e){w(lw(e))}finally{C.current=!1,g(!1),R.current=null,x(null)}},[c,r,u,p,f]),F=(0,l.useCallback)(async()=>{if(null!==v)try{await lj(v)}catch(e){w(lw(e))}},[v]),q=(0,l.useMemo)(()=>{var e;return null!=(e=null==s?void 0:s.limits)?e:null},[s]),A=(0,l.useRef)(null),M=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{if(M.current&&!f&&document.activeElement===document.body){var e;null==(e=A.current)||e.focus()}M.current=f},[f]),(0,a.jsxs)("div",{className:"terminal",children:[(0,a.jsxs)("form",{className:"tm-form",onSubmit:e=>void T(e),children:[(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Project path"}),(0,a.jsx)("input",{type:"text",value:p,onChange:e=>m(e.target.value),placeholder:"/absolute/path/to/project",required:!0})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Command"}),(0,a.jsx)("select",{value:r,onChange:e=>o(e.target.value),disabled:null===s,required:!0,children:null==s?void 0:s.commands.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Args (space-separated)"}),(0,a.jsx)("input",{type:"text",value:c,onChange:e=>d(e.target.value),placeholder:"e.g. -la src"})]}),(0,a.jsxs)("label",{className:"tm-field",children:[(0,a.jsx)("span",{children:"Working directory (optional)"}),(0,a.jsx)("input",{type:"text",value:u,onChange:e=>h(e.target.value),placeholder:"(project root)",list:"tm-cwd-suggestions"}),(0,a.jsx)("datalist",{id:"tm-cwd-suggestions",children:E.map(e=>(0,a.jsx)("option",{value:e.path},e.path))})]}),(0,a.jsxs)("div",{className:"tm-actions",children:[(0,a.jsx)("button",{type:"submit",className:"tm-action","data-primary":"true",ref:A,disabled:null===s,"aria-disabled":f||null===s,children:f?"Running…":"Run"}),f?(0,a.jsx)("button",{type:"button",className:"tm-action","aria-disabled":null===v,onClick:()=>void F(),children:"Cancel"}):null]}),null!==q?(0,a.jsxs)("p",{className:"tm-limits",children:["Limits: ",eA(q.maxOutputBytes)," output \xb7"," ",eM(q.defaultTimeoutMs)," timeout"]}):null]}),null!==j?(0,a.jsxs)("div",{className:"tm-error",role:"alert",children:[(0,a.jsxs)("span",{className:"tm-error-text",children:[j.message," ",(0,a.jsxs)("span",{className:"err-code mono",children:["(",j.code,")"]})]}),(0,a.jsx)("button",{type:"button",className:"tm-error-dismiss","aria-label":"Dismiss error",onClick:()=>w(null),children:"✕"})]}):null,(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==y?"Command finished: exit ".concat(String(y.exitCode),", ").concat(String(y.durationMs)," ms").concat(y.truncated?", output truncated":"").concat(y.timedOut?", timed out":""):""}),null!==y?(0,a.jsxs)("div",{className:"tm-result",children:[(0,a.jsxs)("div",{className:"tm-badges",children:[(0,a.jsxs)("span",{className:0===y.exitCode?"tm-badge tm-badge-ok":"tm-badge tm-badge-fail",children:["exit ",String(y.exitCode)]}),(0,a.jsxs)("span",{className:"tm-badge",children:[y.durationMs," ms"]}),y.truncated?(0,a.jsx)("span",{className:"tm-badge tm-badge-warn",children:"truncated"}):null,y.timedOut?(0,a.jsx)("span",{className:"tm-badge tm-badge-warn",children:"timed out"}):null]}),y.stdout.length>0?(0,a.jsx)("pre",{className:"tm-stdout",children:y.stdout}):null,y.stderr.length>0?(0,a.jsx)("pre",{className:"tm-stderr",children:y.stderr}):null]}):null,(0,a.jsx)("ul",{className:"tm-events",role:"log","aria-live":"polite","aria-relevant":"additions text","aria-atomic":"false","aria-label":"Recent terminal events",children:k.map((e,t)=>(0,a.jsxs)("li",{className:"tm-event",children:[(0,a.jsx)("span",{className:"tm-event-kind",children:function(e){switch(e){case"execution-started":return"started";case"execution-completed":return"completed";case"execution-failed":return"failed";case"execution-cancelled":return"cancelled"}}(e.kind)}),(0,a.jsx)("span",{className:"tm-event-detail",children:function(e){let t=e.payload;return"execution-completed"===e.kind?["number"==typeof t.exitCode||null===t.exitCode?"exit ".concat(String(t.exitCode)):"","number"==typeof t.durationMs?"".concat(String(t.durationMs),"ms"):""].filter(Boolean).join(" \xb7 "):"execution-failed"===e.kind?"string"==typeof t.code?t.code:"":"execution-started"===e.kind&&"string"==typeof t.command?t.command:""}(e)})]},"".concat(e.executionId,"-").concat(String(t),"-").concat(e.kind)))})]})}function lN(e){return e.startsWith("a/")||e.startsWith("b/")?e.slice(2):e}function lS(e){return e instanceof $.hD?{code:e.code,message:e.message}:e instanceof Error?{code:"INTERNAL",message:e.message}:{code:"INTERNAL",message:"Unexpected error."}}function lC(e){return("dry-run"===e.status||"fix-proposed"===e.status)&&void 0!==e.proposedDiff&&void 0===e.appliedAt}function lR(e){return void 0!==e.proposedDiff&&""!==e.proposedDiff}function lE(e){let{href:t,hasManifest:n,error:l}=e;return n?(0,a.jsx)("a",{className:"rv-evidence-link",href:t,target:"_blank",rel:"noopener noreferrer",children:"Evidence"}):null!==l?(0,a.jsxs)("span",{className:"rv-evidence-link rv-evidence-error",role:"status",children:["Evidence error: ",l.message]}):(0,a.jsx)("span",{className:"rv-evidence-link rv-evidence-disabled",role:"link","aria-disabled":"true",children:"Evidence"})}function lI(e){let{tokens:t}=e;return(0,a.jsx)(a.Fragment,{children:t.map((e,t)=>(0,a.jsx)("span",{className:"hl-".concat(e[0]),children:e[1]},t))})}function lT(e){var t,n,l;let s,{line:i,lang:r}=e,o="add"===i.kind?"+":"del"===i.kind?"−":"ctx"===i.kind?"\xb7":"",c="ctx"===i.kind?"":" rv-".concat(i.kind);if("meta"!==i.kind&&"code"!==r){let e=null!=(t=a5(i.text,a3(r))[0])?t:[];s=(0,a.jsx)(lI,{tokens:e})}else s=i.text;return(0,a.jsxs)("div",{className:"rv-line".concat(c),children:[(0,a.jsx)("span",{className:"rv-sr-only",children:{add:"Added line",del:"Deleted line",ctx:"Context line",meta:"Diff metadata"}[i.kind]}),(0,a.jsx)("span",{className:"rv-num-old rv-num",children:null!=(n=i.oldLine)?n:""}),(0,a.jsx)("span",{className:"rv-num-new rv-num",children:null!=(l=i.newLine)?l:""}),(0,a.jsx)("span",{className:"rv-gutter","aria-hidden":"true",children:o}),(0,a.jsx)("code",{className:"rv-src",children:s})]})}function lF(e){let{hunk:t,lang:n}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rv-hunk mono","aria-label":"Hunk header ".concat(t.header),children:[(0,a.jsx)("span",{className:"rv-sr-only",children:"Hunk header"}),t.header]}),t.lines.map((e,t)=>(0,a.jsx)(lT,{line:e,lang:n},t))]})}function lq(e){var t;let{file:n,index:l,changedFiles:s,sectionRef:i}=e,r=s.find(e=>e.path===n.path),o=n.path.includes(".")&&null!=(t=n.path.split(".").pop())?t:"code";return(0,a.jsxs)("section",{id:"rv-file-".concat(l),"aria-labelledby":"rv-file-".concat(l,"-h"),ref:i,children:[(0,a.jsxs)("h3",{id:"rv-file-".concat(l,"-h"),className:"rv-file mono",children:[(0,a.jsx)("span",{className:"rv-path",children:n.path}),void 0!==n.oldPath&&(0,a.jsxs)("span",{className:"rv-oldpath",children:[" (was ",n.oldPath,")"]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"rv-stat add",children:["+",n.addedLines]}),(0,a.jsxs)("span",{className:"rv-stat del",children:["−",n.removedLines]}),(null==r?void 0:r.elevatedReview)===!0&&(0,a.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]}),(0,a.jsx)("div",{className:"rv-code mono",children:n.hunks.map((e,t)=>(0,a.jsx)(lF,{hunk:e,lang:o},t))})]})}function lA(e){var t,n;let{runId:s,onRunIdSubmit:i}=e,[r,o]=(0,l.useState)(null),[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)(null),[k,N]=(0,l.useState)(""),[S,C]=(0,l.useState)(!1),R=(0,l.useRef)(null);(0,l.useEffect)(()=>()=>{null!==R.current&&window.clearTimeout(R.current)},[]),(0,l.useEffect)(()=>{if(void 0===s||""===s)return;let e=!1;return m(!0),g(null),o(null),d(!1),h(null),w(null),Promise.allSettled([(0,$.Qe)(s),(0,$.tZ)(s)]).then(t=>{let[n,a]=t;if(!e){if("fulfilled"===a.status)d(!0),h(null);else{let e=lS(a.reason);d(!1),h("NOT_FOUND"===e.code?null:e)}if("fulfilled"===n.status){o(n.value.report),m(!1);return}g(lS(n.reason)),m(!1)}}),()=>{e=!0}},[s]);let E="/api/evidence/".concat(encodeURIComponent(null!=s?s:"")),I=(0,l.useMemo)(()=>(null==r?void 0:r.proposedDiff)!==void 0?function(e){let t=new TextEncoder,n=t.encode(e).byteLength;if(0===e.length)return{files:[],truncated:!1,totalBytes:0};let a=e,l=!1;if(n>524288){l=!0;let n=t.encode(e),s=new TextDecoder().decode(n.slice(0,524288)),i=s.lastIndexOf("\n");a=-1===i?s:s.slice(0,i+1)}let s=a.split("\n"),i=s.length>0&&""===s[s.length-1]?s.slice(0,-1):s,r=[],o=null,c=null,d=0,u=0,h=()=>{null!==o&&null!==c&&o.hunks.push(c),c=null},p=()=>{h(),null!==o&&(r.length<400?r.push(o):l=!0),o=null},m=0;for(;m<i.length;){var f,g,v;let e=null!=(f=i[m])?f:"";if(e.startsWith("diff --git ")){p();let t=/^diff --git a\/(.+?) b\/(.+)$/.exec(e);if(null!==t&&void 0!==t[1]&&void 0!==t[2]){let e=t[1],n=t[2],a=lN("b/".concat(n)),l=lN("a/".concat(e)),s={path:a,hunks:[],addedLines:0,removedLines:0};l!==a&&(s.oldPath=l),o=s}m++;continue}if(null!==c){if(e.startsWith("+")){let t={kind:"add",oldLine:null,newLine:u,text:e.slice(1)};c.lines.push(t),null!==o&&o.addedLines++,u++,m++;continue}if(e.startsWith("-")){let t={kind:"del",oldLine:d,newLine:null,text:e.slice(1)};c.lines.push(t),null!==o&&o.removedLines++,d++,m++;continue}if(e.startsWith("\\ ")){let t={kind:"meta",oldLine:null,newLine:null,text:e};c.lines.push(t),m++;continue}if(e.startsWith(" ")||""===e){let t={kind:"ctx",oldLine:d,newLine:u,text:e.startsWith(" ")?e.slice(1):e};c.lines.push(t),d++,u++,m++;continue}}if(e.startsWith("--- ")){let t=e.slice(4);if("/dev/null"!==t&&null===o)p(),o={path:lN(t),hunks:[],addedLines:0,removedLines:0};else if("/dev/null"!==t&&null!==o){let e=lN(t);e!==o.path&&(o.oldPath=e)}m++;continue}if(e.startsWith("+++ ")){let t=e.slice(4);"/dev/null"!==t&&null!==o?o.path=lN(t):"/dev/null"!==t&&(p(),o={path:lN(t),hunks:[],addedLines:0,removedLines:0}),m++;continue}if(e.startsWith("@@ ")){null===o&&(o={path:"(unknown)",hunks:[],addedLines:0,removedLines:0}),h();let t=function(e){let t=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(e);return null===t||void 0===t[1]||void 0===t[2]?null:{oldStart:parseInt(t[1],10),newStart:parseInt(t[2],10)}}(e);d=null!=(g=null==t?void 0:t.oldStart)?g:1,u=null!=(v=null==t?void 0:t.newStart)?v:1,c={header:e,lines:[]},m++;continue}m++}return p(),{files:r,truncated:l,totalBytes:n}}(r.proposedDiff):null,[null==r?void 0:r.proposedDiff]),T=null!=(t=null==r?void 0:r.changedFiles)?t:[],F=(0,l.useMemo)(()=>{var e,t;return{added:null!=(e=null==I?void 0:I.files.reduce((e,t)=>e+t.addedLines,0))?e:0,removed:null!=(t=null==I?void 0:I.files.reduce((e,t)=>e+t.removedLines,0))?t:0}},[I]),q=null!==I&&I.files.length>0?Math.min(null!=j?j:0,I.files.length-1):null,A=null!==q?null==I?void 0:I.files[q]:void 0,M=(null==r?void 0:r.status)==="running";return void 0===s||""===s?(0,a.jsxs)("section",{className:"review rv-empty","aria-label":"Diff review",children:[(0,a.jsx)("h2",{className:"rv-empty-h",children:"Review"}),void 0!==i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("p",{className:"rv-empty-p",children:"Paste a run ID below to load a proposed diff."}),(0,a.jsxs)("form",{className:"rv-empty-form",onSubmit:e=>{e.preventDefault();let t=k.trim();0!==t.length&&i(t)},children:[(0,a.jsx)("label",{className:"rv-empty-label",htmlFor:"rv-runid-input",children:"Run ID"}),(0,a.jsx)("input",{id:"rv-runid-input",className:"rv-runid-input mono",type:"text",value:k,onChange:e=>N(e.target.value),placeholder:"e.g. 7f3a9c12…"}),(0,a.jsx)("button",{type:"submit",className:"arun-btn",children:"Load run"})]})]}):(0,a.jsx)("p",{className:"rv-empty-p",children:"Enter a run ID in the window configuration to load a proposed diff."})]}):(0,a.jsxs)("section",{className:"review","aria-label":"Diff review",children:[p&&(0,a.jsxs)("div",{className:"rv-loading",role:"status","aria-busy":"true","aria-label":"Loading diff",children:[(0,a.jsx)("div",{className:"rv-skel"}),(0,a.jsx)("div",{className:"rv-skel rv-skel-sm"})]}),!p&&null!==f&&(0,a.jsxs)("div",{role:"alert",className:"rv-error",children:["NOT_FOUND"===f.code?"No run with that ID was found.":(0,a.jsxs)(a.Fragment,{children:[f.message," ",(0,a.jsxs)("span",{className:"err-code mono",children:["(",f.code,")"]})]}),(c||null!==u)&&(0,a.jsx)("span",{className:"rv-error-evidence",children:(0,a.jsx)(lE,{href:E,hasManifest:c,error:u})})]}),(0,a.jsx)("p",{role:"status","aria-live":"polite",className:!p&&null===f&&null!==r&&M?"rv-no-diff":"sr-only",children:!p&&null===f&&null!==r&&M?"Run is still running. The proposed diff will appear when the run completes.":""}),!p&&null===f&&null!==r&&!M&&!lR(r)&&(0,a.jsx)("p",{className:"rv-no-diff",children:"This run has no proposed diff to review."}),!p&&null===f&&null!==r&&lR(r)&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"rv-header",children:[(0,a.jsx)("span",{className:"rv-status mono",children:eP(r.status)}),void 0!==r.modelId&&(0,a.jsx)("span",{className:"rv-model mono",children:r.modelId}),(0,a.jsxs)("span",{className:"rv-counts mono",children:[null!==I&&"".concat(I.files.length," file").concat(1!==I.files.length?"s":"")," ",(0,a.jsxs)("span",{className:"rv-stat add",children:["+",F.added]})," ",(0,a.jsxs)("span",{className:"rv-stat del",children:["−",F.removed]})]}),(0,a.jsx)("span",{className:"spacer"}),(0,a.jsx)(lE,{href:E,hasManifest:c,error:u})]}),null!==I&&I.files.length>0&&null!==q&&void 0!==A&&(0,a.jsxs)("div",{className:"rv-layout",children:[(0,a.jsx)("nav",{className:"rv-filelist","aria-label":"Changed files",children:(0,a.jsx)("ul",{children:I.files.map((e,t)=>{let n=T.find(t=>t.path===e.path),l=q===t;return(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"rv-filerow",title:e.path,"aria-pressed":l,"aria-controls":l?"rv-file-".concat(t):void 0,onClick:()=>{w(t)},children:[(0,a.jsx)("span",{className:"rv-filerow-path mono",children:function(e){if(e.length<=40)return e;let t=e.split("/");return t.length<=2?e:"…/".concat(t.slice(-2).join("/"))}(e.path)}),(0,a.jsxs)("span",{className:"rv-stat add",children:["+",e.addedLines]}),(0,a.jsxs)("span",{className:"rv-stat del",children:["−",e.removedLines]}),(null==n?void 0:n.elevatedReview)===!0&&(0,a.jsx)("span",{className:"rv-elevated","aria-label":"Elevated review",children:"!"})]})},e.path)})})}),(0,a.jsxs)("div",{className:"rv-body",children:[(0,a.jsx)(lq,{file:A,index:q,changedFiles:T,sectionRef:()=>void 0},A.path),I.truncated&&(0,a.jsxs)("p",{role:"note",className:"rv-truncated",children:["Diff truncated at 512 KB. Open the"," ",c?(0,a.jsx)("a",{href:E,target:"_blank",rel:"noopener noreferrer",children:"evidence manifest"}):"evidence manifest"," ","for the full record."]})]})]}),(0,a.jsxs)("div",{className:"rv-controls",children:[(0,a.jsx)("span",{role:"status","aria-live":"polite",className:"rv-apply-status",children:v?"Applying…":void 0!==r.appliedAt?"Applied":""}),null!==y&&(0,a.jsx)("span",{role:"alert",className:"rv-apply-error",children:y.message}),void 0!==r.appliedAt?(0,a.jsx)("span",{className:"rv-final mono",children:"Applied"}):lC(r)?(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":v,onClick:()=>{if(!v){if(!S){C(!0),null!==R.current&&window.clearTimeout(R.current),R.current=window.setTimeout(()=>{C(!1),R.current=null},6e3);return}null!==R.current&&(window.clearTimeout(R.current),R.current=null),C(!1),void 0!==s&&null!==r&&lC(r)&&!v&&(x(!0),b(null),(0,$.qU)(s).then(e=>{o(e.report),x(!1)}).catch(e=>{b(lS(e)),x(!1)}))}},children:v?"Applying…":S?"Confirm apply (".concat((null!=(n=null==I?void 0:I.files.length)?n:0).toString()," file").concat((null==I?void 0:I.files.length)===1?"":"s",")"):"Apply"}):null]})]})]})}let lM=new Set(["completed","dry-run","rejected","cancelled","failed","fix-applied","fix-proposed","investigation-only"]),lP={verify:"Verify","explain-plan":"Explain plan","unit-test-generation":"Generate unit tests","bug-investigation":"Investigate bug"};function lD(e,t){return void 0===t||0===t.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:e}),(0,a.jsx)("pre",{children:t})]})}function lL(e){var t,n,s,i,r,o,c,d,u,h;let{cfg:p={},linkedRoot:m=null,linkedFilePath:f}=e,g=null!=(n=p.runId)?n:null,v="verify"===(u=p.workflow)||"explain-plan"===u||"unit-test-generation"===u||"bug-investigation"===u?u:null,x=null!=(s=p.model)?s:"",y=function(e){if(void 0===e||0===e.length)return null;try{let t=JSON.parse(e);return"object"!=typeof t||null===t||Array.isArray(t)?null:t}catch(e){return null}}(p.inputJson),b=function(e){let[t,n]=(0,l.useState)([]),[a,s]=(0,l.useState)("connecting"),[i,r]=(0,l.useState)(null),o=(0,l.useRef)(-1);return(0,l.useEffect)(()=>{if(null===e)return;n([]),s("connecting"),r(null),o.current=-1;let t=null,a=!1,l="/api/runs/".concat(encodeURIComponent(e),"/events");(t=new EventSource(o.current>=0?"".concat(l,"?lastEventId=").concat(o.current.toString()):l)).onopen=()=>{a||(s("live"),r(null))},t.onerror=()=>{a||(s("error"),r("Stream disconnected. Attempting to reconnect…"))};let i=e=>{let l;if(!a){try{l=JSON.parse(e.data)}catch(e){return}o.current=l.seq,n(e=>[...e,l]),tL.eQ.has(l.type)&&(s("terminal"),null==t||t.close())}};for(let e of tL.$Q)t.addEventListener(e,i);return()=>{a=!0,null==t||t.close()}},[e]),{events:t,status:a,error:i}}(g),[j,w]=(0,l.useState)(null),[k,S]=(0,l.useState)(null),[C,R]=(0,l.useState)(null),[E,I]=(0,l.useState)(!1),[T,F]=(0,l.useState)(null),[q,A]=(0,l.useState)(null),[M,P]=(0,l.useState)(!1),D=(0,l.useRef)(null),L=(0,l.useRef)(null),z=(0,l.useCallback)(async()=>{if(null!==g){R(null);try{let e=await (0,$.Qe)(g);w(e.report),S(null)}catch(e){if(e instanceof $.hD&&404===e.status){try{let e=await (0,$.tZ)(g);S(e.manifest),w(null)}catch(e){R(e instanceof Error?e.message:"Unable to load evidence.")}return}R(e instanceof Error?e.message:"Unable to load run report.")}}},[g]);(0,l.useEffect)(()=>{z()},[z]),(0,l.useEffect)(()=>{"terminal"===b.status&&z()},[z,b.status]),(0,l.useEffect)(()=>{let e=!1;if(0!==x.length)return(0,$.ZC)().then(t=>{var n,a;e||A(null!=(a=null==(n=t.models.find(e=>e.id===x))?void 0:n.costClass)?a:null)}).catch(()=>{e||A(null)}),()=>{e=!0}},[x]);let O=(0,l.useMemo)(()=>(function(e,t){var n,a,l,s,i,r;let o=null!=(s=null==t||null==(n=t.usage)?void 0:n.promptTokens)?s:0,c=null!=(i=null==t||null==(a=t.usage)?void 0:a.completionTokens)?i:0,d=null!=(r=null==t||null==(l=t.usage)?void 0:l.latencyMs)?r:0,u=+((null==t?void 0:t.usage)!==void 0);if(u>0)return{promptTokens:o,completionTokens:c,latencyMs:d,requestCount:u};for(let t of e){let e=function(e){if("model:call:completed"===e.type)return{promptTokens:e.usage.promptTokens,completionTokens:e.usage.completionTokens,latencyMs:e.usage.latencyMs,requestCount:1};let t=e.promptTokens,n=e.completionTokens,a=e.latencyMs;return"number"==typeof t&&"number"==typeof n&&"number"==typeof a?{promptTokens:t,completionTokens:n,latencyMs:a,requestCount:1}:null}(t);null!==e&&(o+=e.promptTokens,c+=e.completionTokens,d+=e.latencyMs,u+=e.requestCount)}return{promptTokens:o,completionTokens:c,latencyMs:d,requestCount:u}})(b.events,j),[b.events,j]),K=null!=(o=null!=(i=null==j?void 0:j.durationMs)?i:null==k?void 0:k.run.durationMs)?o:b.events.length>0?Math.max(0,Date.now()-Number(new Date(null!=(r=null==(t=b.events[0])?void 0:t.ts)?r:Date.now()))):0,B=null!==j?j.status:null!==k?k.run.outcome:"loading",W=function(e,t){if(null!==e)return eP(e.status);if(null!==t){var n=t.run.outcome;switch(n){case"fix-applied":return"Fix applied";case"fix-proposed":return"Fix proposed (dry-run)";case"investigation-only":return"Investigation only";case"limit-exceeded":return"Limit exceeded";case"dry-run":return"Dry-run";default:return n.charAt(0).toUpperCase()+n.slice(1)}}return"Loading…"}(j,k),U=null!==j&&lM.has(j.status),_=null!==j&&void 0!==j.proposedDiff&&void 0===j.appliedAt&&("unit-test-generation"===v&&"dry-run"===j.status||"bug-investigation"===v&&"fix-proposed"===j.status),H=!U&&(null==j?void 0:j.status)==="running",G=function(e){if(void 0===e||0===e.length)return 0;let t=e.match(/^diff --git /gm);if(null!==t)return t.length;let n=e.match(/^\+\+\+ /gm);return null===n?0:n.length}(null==j?void 0:j.proposedDiff),J=(0,l.useRef)(!1);(0,l.useEffect)(()=>{if(J.current&&!H&&document.activeElement===document.body){var e;null==(e=L.current)||e.focus()}J.current=H},[H]),(0,l.useEffect)(()=>()=>{null!==D.current&&window.clearTimeout(D.current)},[]);let V=async()=>{if(null!==g){R(null);try{await (0,$.Su)(g),await z()}catch(e){R(e instanceof Error?e.message:"Unable to cancel run.")}}},X=async()=>{if(null!==g&&_&&!E){I(!0),F(null);try{let e=await (0,$.qU)(g);w(e.report)}catch(e){F(e instanceof Error?e.message:"Unable to apply run.")}finally{I(!1)}}};return null===g||null===v?(0,a.jsxs)("div",{className:"arun arun-empty",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Agent run is not configured."}),(0,a.jsx)("p",{children:"Open a new Agent window from the launcher to start a workflow."})]}):(0,a.jsxs)("div",{className:"arun arun-real",children:[(0,a.jsxs)("div",{className:"arun-head",children:[(0,a.jsx)("span",{className:"arun-role",children:lP[v]}),x.length>0?(0,a.jsx)("span",{className:"ag-model mono",children:x}):null,null!==q?(0,a.jsx)("span",{className:"arun-gov",title:"Model cost class",children:function(e){switch(e){case"low":return"Low cost";case"medium":return"Medium cost";case"high":return"High cost";case"unknown":return"Unknown cost"}}(q)}):null,(0,a.jsx)("span",{className:"spacer"}),(0,a.jsxs)("span",{className:"arun-status",children:[(0,a.jsx)("span",{className:"dot","data-live":(null==j?void 0:j.status)==="running","data-status":B}),W]})]}),(0,a.jsxs)("div",{className:"arun-summary",role:"status","aria-live":"polite",children:[(0,a.jsx)("strong",{children:function(e,t,n){var a;if(null===t&&null===n)return"Loading run state…";let l=null===e?"Agent run":lP[e];return(null==t?void 0:t.status)==="running"?"".concat(l," is running."):(null==t?void 0:t.status)==="dry-run"?"".concat(l," produced a reviewable dry-run."):(null==t?void 0:t.status)==="fix-proposed"?"".concat(l," proposed a fix."):(null==t?void 0:t.status)==="fix-applied"?"".concat(l," applied changes."):(null==t?void 0:t.status)==="investigation-only"?"".concat(l," completed without a patch."):(null==t?void 0:t.status)==="failed"||(null==t?void 0:t.status)==="rejected"?"".concat(l," failed."):(null==t?void 0:t.status)==="cancelled"?"".concat(l," was cancelled."):null!==t?"".concat(l," completed."):"".concat(l," evidence loaded: ").concat(null!=(a=null==n?void 0:n.run.outcome)?a:"unknown",".")}(v,j,k)}),(0,a.jsxs)("span",{className:"mono",title:g,children:["run ",g.slice(0,8)]})]}),(0,a.jsxs)("div",{className:"arun-meters",children:[(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Elapsed"}),(0,a.jsx)("span",{className:"arun-mv mono",children:eM(K)})]}),(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Usage"}),(0,a.jsx)("span",{className:"arun-mv mono",children:0===O.requestCount?"No model usage":"".concat(eD(O.promptTokens+O.completionTokens)," tok")})]}),(0,a.jsxs)("div",{className:"arun-meter",children:[(0,a.jsx)("span",{className:"arun-mk",children:"Latency"}),(0,a.jsx)("span",{className:"arun-mv mono",children:0===O.requestCount?"—":eM(O.latencyMs)})]})]}),(0,a.jsxs)("div",{className:"arun-perms",children:[(0,a.jsxs)("span",{className:"arun-perm","data-on":null!==m,title:null!==m?m:null!=(c=p.workspaceRoot)?c:void 0,children:[(0,a.jsx)(N.F.files,{size:11}),(0,a.jsx)("span",{className:"arun-perm-path",children:null!==m?m:null!=(d=p.workspaceRoot)?d:"no workspace"})]}),void 0!==f?(0,a.jsxs)("span",{className:"arun-perm","data-on":!0,title:f,children:[(0,a.jsx)(N.F.files,{size:11}),(0,a.jsx)("span",{className:"arun-perm-path",children:f})]}):null]}),null!==y?(0,a.jsxs)("details",{className:"arun-input",children:[(0,a.jsx)("summary",{children:"Run input"}),(0,a.jsx)("pre",{children:JSON.stringify(y,null,2)})]}):null,(0,a.jsxs)("div",{className:"arun-log",role:"log","aria-live":"polite","aria-label":"Run events",children:["error"===b.status&&null!==b.error?(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(N.F.reset,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:b.error})]}):null,0===b.events.length?"error"===b.status?null:(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(N.F.reset,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:"connecting"===b.status?"Connecting to run events…":"Waiting for run events…"})]}):b.events.slice().reverse().slice(0,50).map(e=>(0,a.jsxs)("div",{className:"arun-log-row",children:[(0,a.jsx)("span",{className:"arun-log-ico",children:(0,a.jsx)(N.F.spark,{size:12})}),(0,a.jsx)("span",{className:"arun-log-text",children:function(e){switch(e.type){case"ready":return"SSE stream ready";case"run:started":return"Started ".concat(e.taskType);case"run:completed":return"Run completed";case"run:failed":return"Run failed: ".concat(e.failure.message);case"run:cancelled":return"Run cancelled";case"state:transition":return"".concat(e.from," -> ").concat(e.to).concat(void 0===e.reason?"":": ".concat(e.reason));case"model:call:started":return"Model call started (".concat(eA(e.contextBytes),")");case"model:call:completed":return"Model call completed (".concat(eD(e.usage.promptTokens+e.usage.completionTokens)," tokens)");case"model:call:failed":return"Model call failed: ".concat(e.message);case"patch:proposed":return"Patch proposed (".concat(eA(e.patchBytes),")");case"verification:result":return"Verification ".concat(e.passed?"passed":"failed",": ").concat(e.detail);case"workflow:started":return"Unit-test workflow started";case"workflow:model:call:completed":return"Unit-test model call completed (".concat(eD(e.promptTokens+e.completionTokens)," tokens)");case"workflow:verification:result":return"Unit-test verification ".concat(e.overallStatus);case"workflow:completed":return"Unit-test workflow ".concat(e.status);case"workflow:failed":return"Unit-test workflow failed: ".concat(e.message);case"bug:started":return"Bug investigation started";case"bug:model:call:completed":return"Bug model call completed (".concat(eD(e.promptTokens+e.completionTokens)," tokens)");case"bug:rootcause:proposed":return"Root cause proposed".concat(e.hasPatch?" with patch":"");case"bug:verification:result":return"Bug verification ".concat(e.overallStatus);case"bug:completed":return"Bug investigation ".concat(e.status);case"bug:failed":return"Bug investigation failed: ".concat(e.message);default:return e.type}}(e)}),(0,a.jsx)("span",{className:"arun-log-t mono",children:function(e){let t="number"==typeof e.ts?e.ts:Date.parse(e.ts);return Number.isFinite(t)?new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}):""}(e)})]},"".concat(e.runId,":").concat(e.seq,":").concat(e.type)))]}),null!==j?(0,a.jsxs)("div",{className:"arun-results",children:[void 0===j.report?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Report"}),(0,a.jsx)("pre",{children:j.report})]}),void 0===j.overallStatus||void 0===j.results?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Status"}),(0,a.jsx)("strong",{children:j.overallStatus})]}),j.results.slice(0,8).map(e=>(0,a.jsxs)("div",{className:"arun-check-row",children:[(0,a.jsx)("span",{children:e.kind}),(0,a.jsx)("span",{className:"mono",children:e.status})]},"".concat(e.kind,":").concat(e.command)))]}),lD("Failure",j.failureReason),lD("Covered behavior",j.coveredBehavior),lD("Known gaps",j.knownGaps),lD("Verification note",j.verificationSkipReason),function(e){let t=e.hypothesis;if(void 0===t)return null;let n=[["Root cause",t.rootCause],["Regression test",t.regressionTestStrategy],["Uncertainty",t.uncertainty],["Confidence",t.confidence]].filter(e=>"string"==typeof e[1]&&e[1].length>0);return 0===n.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Hypothesis"}),n.map(e=>{let[t,n]=e;return(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:t}),(0,a.jsx)("strong",{children:n})]},t)})]})}(j),void 0===(h=j.nextActions)||0===h.length?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Next actions"}),h.map(e=>(0,a.jsx)("div",{className:"arun-check-row",children:(0,a.jsx)("span",{children:e})},e))]}),void 0!==j.dryRunPreview?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Dry-run preview"}),(0,a.jsx)("pre",{children:j.dryRunPreview})]}):null,void 0!==j.proposedDiff?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Proposed diff"}),(0,a.jsx)("pre",{children:j.proposedDiff})]}):null,function(e){let t=e.verificationSummary;return void 0===t?null:(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Verification"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Status"}),(0,a.jsx)("strong",{children:t.overallStatus})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Duration"}),(0,a.jsx)("strong",{children:eM(t.durationMs)})]}),t.results.slice(0,5).map(e=>(0,a.jsxs)("div",{className:"arun-check-row",children:[(0,a.jsx)("span",{children:e.kind}),(0,a.jsx)("span",{className:"mono",children:e.status})]},"".concat(e.kind,":").concat(e.command)))]})}(j),void 0!==j.applyReport?(0,a.jsxs)("div",{className:"arun-result-card arun-applied",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Applied"}),(0,a.jsx)("pre",{children:JSON.stringify(j.applyReport,null,2)})]}):null]}):null!==k?(0,a.jsxs)("div",{className:"arun-result-card",children:[(0,a.jsx)("div",{className:"arun-result-title",children:"Evidence"}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Outcome"}),(0,a.jsx)("strong",{children:k.run.outcome})]}),(0,a.jsxs)("div",{className:"arun-kv",children:[(0,a.jsx)("span",{children:"Duration"}),(0,a.jsx)("strong",{children:eM(k.run.durationMs)})]})]}):null,null!==C?(0,a.jsx)("div",{className:"arun-error",role:"alert",children:C}):null,null!==T?(0,a.jsx)("div",{className:"arun-error",role:"alert",children:T}):null,(0,a.jsxs)("div",{className:"arun-controls",children:[(0,a.jsx)("a",{className:"arun-btn ghost",href:"/api/evidence/".concat(encodeURIComponent(g)),target:"_blank",rel:"noreferrer",ref:L,children:"Evidence"}),_?(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":E,onClick:()=>{if(!E){if(!M){P(!0),null!==D.current&&window.clearTimeout(D.current),D.current=window.setTimeout(()=>{P(!1),D.current=null},6e3);return}null!==D.current&&(window.clearTimeout(D.current),D.current=null),P(!1),X()}},children:E?"Applying…":M?"Confirm apply (".concat(G.toString()," file").concat(1===G?"":"s",")"):"Apply"}):(null==j?void 0:j.appliedAt)!==void 0?(0,a.jsx)("span",{className:"arun-final mono",children:"Applied"}):null,H?(0,a.jsx)("button",{type:"button",className:"arun-btn danger",onClick:()=>void V(),children:"Cancel"}):null]})]})}let lz=[{name:"Messaging",desc:"Catch up on threads",glyph:"#"},{name:"GitHub",desc:"PRs, code & CI",glyph:"{ }"},{name:"Linear",desc:"Track issues",glyph:"⊿"},{name:"Slack",desc:"Team channels",glyph:"≡"},{name:"Sentry",desc:"Error tracking",glyph:"◎"}];function lO(){return(0,a.jsx)("ul",{className:"integ","aria-label":"Integrations",children:lz.map(e=>(0,a.jsxs)("li",{className:"integ-row",children:[(0,a.jsx)("span",{className:"integ-glyph mono",children:e.glyph}),(0,a.jsxs)("span",{className:"integ-text",children:[(0,a.jsx)("span",{className:"integ-name",children:e.name}),(0,a.jsx)("span",{className:"integ-desc",children:e.desc})]}),(0,a.jsx)("span",{className:"integ-status",children:"Not connected — coming soon"})]},e.name))})}let lK={allow:["Allow","var(--accent)"],ask:["Ask","var(--warn)"],deny:["Deny","var(--danger)"]},lB={allow:"ask",ask:"deny",deny:"allow"},lW=[{id:1,label:"Write src/windows.jsx",kind:"write",risk:"low",expect:"allow"},{id:2,label:"Overwrite prod/secrets.env",kind:"write",risk:"high",expect:"deny"},{id:3,label:"Run `npm test`",kind:"command",risk:"low",expect:"allow"},{id:4,label:"Run `kubectl apply` → prod",kind:"command",risk:"high",expect:"ask"},{id:5,label:"Open pull request #142",kind:"git",risk:"low",expect:"allow"},{id:6,label:"Email the customer",kind:"mail",risk:"low",expect:"ask"}],lU=[["Developer","Codes, reviews diffs, runs tests, opens PRs"],["Product Owner","Searches docs, drafts Jira tickets, plans releases"],["Designer","Explores UI options, reviews flows, writes specs"]],l_=[["calendar","Calendar","automations"],["mail","Mail","bell"],["jira","Jira","review"],["docs","Docs","files"]];function lH(e){let{policy:t,setPolicy:n}=e;return(0,a.jsxs)("div",{className:"pol",children:[(0,a.jsx)("div",{className:"pol-hint",children:"Rights an agent inherits when Keiko governs. Tap a decision to cycle through Allow → Ask → Deny."}),t.map(e=>{let t=lK[e.decision];return(0,a.jsxs)("div",{className:"pol-row",children:[(0,a.jsxs)("div",{className:"pol-text",children:[(0,a.jsx)("span",{className:"pol-action",children:e.action}),(0,a.jsx)("span",{className:"pol-scope mono",children:e.scope})]}),(0,a.jsx)("button",{type:"button",className:"pol-dec",style:{color:t[1],borderColor:t[1]},onClick:()=>{let t;return t=e.id,n(e=>e.map(e=>e.id===t?{...e,decision:lB[e.decision]}:e))},children:t[0]})]},e.id)})]})}function lG(e){let{decide:t}=e,[n,s]=(0,l.useState)(!1),i=lW.map(e=>{let n=t(e.kind,e.risk);return{...e,actual:n,pass:n===e.expect}}),r=i.filter(e=>e.pass).length;return(0,a.jsxs)("div",{className:"evl",children:[(0,a.jsxs)("div",{className:"evl-head",children:[(0,a.jsxs)("button",{type:"button",className:"evl-run",onClick:()=>s(!0),children:[(0,a.jsx)(N.F.spark,{size:13})," Run evaluation"]}),n&&(0,a.jsxs)("span",{className:"evl-score"+(r===i.length?" ok":""),children:[r,"/",i.length," passed"]})]}),(0,a.jsx)("div",{className:"evl-hint",children:"Mock scenarios against your policy before going autonomous."}),i.map(e=>(0,a.jsxs)("div",{className:"evl-row","data-state":n?e.pass?"pass":"fail":"idle",children:[(0,a.jsx)("span",{className:"evl-ico",children:n?e.pass?(0,a.jsx)(N.F.check,{size:13}):(0,a.jsx)(N.F.close,{size:13}):(0,a.jsx)("span",{className:"evl-dot"})}),(0,a.jsx)("span",{className:"evl-label",children:e.label}),n&&(0,a.jsx)("span",{className:"evl-res mono",style:{color:lK[e.actual][1]},children:lK[e.actual][0]})]},e.id))]})}function lJ(e){let{memory:t,setMemory:n}=e,[s,i]=(0,l.useState)(""),r=()=>{let e=s.trim();""!==e&&(n(t=>[e,...t]),i(""))};return(0,a.jsxs)("div",{className:"mem",children:[(0,a.jsxs)("div",{className:"mem-add",children:[(0,a.jsx)("input",{value:s,onChange:e=>i(e.target.value),placeholder:"Teach Keiko something about you…",onKeyDown:e=>{"Enter"===e.key&&r()}}),(0,a.jsx)("button",{type:"button",onClick:r,"aria-label":"Add memory",children:(0,a.jsx)(N.F.plus,{size:15})})]}),t.map((e,t)=>(0,a.jsxs)("div",{className:"mem-row",children:[(0,a.jsx)(N.F.spark,{size:12}),(0,a.jsx)("span",{className:"mem-text",children:e}),(0,a.jsx)("button",{type:"button",className:"mem-x","aria-label":"Remove memory: ".concat(e),onClick:()=>n(e=>e.filter((e,n)=>n!==t)),children:(0,a.jsx)(N.F.close,{size:12})})]},"".concat(String(t),"-").concat(e)))]})}function lV(e){let{bridges:t,setBridges:n}=e;return(0,a.jsxs)("div",{className:"brg",children:[(0,a.jsx)("div",{className:"evl-hint",children:"What your twin can reach on your behalf."}),l_.map(e=>{let[l,s,i]=e,r=N.F[i],o=t[l];return(0,a.jsxs)("button",{type:"button",className:"brg-row","data-on":o,"aria-pressed":o,onClick:()=>n(e=>({...e,[l]:!e[l]})),children:[(0,a.jsx)("span",{className:"brg-ico",children:(0,a.jsx)(r,{size:16})}),(0,a.jsx)("span",{className:"brg-name",children:s}),(0,a.jsx)("span",{className:"brg-tg"+(o?" on":""),children:(0,a.jsx)("span",{})})]},l)})]})}function lX(e){let{persona:t,setPersona:n}=e;return(0,a.jsxs)("div",{className:"prs",children:[(0,a.jsx)("div",{className:"evl-hint",children:"Keiko adapts behaviour & tools to who is at the wheel."}),lU.map(e=>{let[l,s]=e;return(0,a.jsxs)("button",{type:"button",className:"prs-row","data-on":t===l,"aria-pressed":t===l,onClick:()=>n(l),children:[(0,a.jsx)("span",{className:"prs-dot"}),(0,a.jsxs)("span",{className:"prs-text",children:[(0,a.jsx)("span",{className:"prs-name",children:l}),(0,a.jsx)("span",{className:"prs-desc",children:s})]}),t===l&&(0,a.jsx)(N.F.check,{size:14,style:{color:"var(--accent)"}})]},l)})]})}let lY=[["policy","Policy"],["eval","EVAL"],["memory","MemoriaViva"],["bridges","Connections"],["persona","Persona"]];function lZ(){let e=w(),[t,n]=(0,l.useState)("policy");return(0,a.jsxs)("div",{className:"twin",children:[(0,a.jsxs)("div",{className:"twin-hero",children:[(0,a.jsx)("img",{className:"twin-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,a.jsxs)("div",{className:"twin-id",children:[(0,a.jsx)("span",{className:"twin-name",children:"Keiko — Digital Twin"}),(0,a.jsxs)("span",{className:"twin-sub mono",children:["mirroring \xb7 ",e.persona]})]}),(0,a.jsx)("span",{className:"twin-mode "+("autonomous"===e.mode?"on":""),children:"autonomous"===e.mode?"Autonomous":"Manual"})]}),(0,a.jsx)("div",{className:"twin-tabs",children:lY.map(e=>{let[l,s]=e;return(0,a.jsx)("button",{type:"button",className:"twin-tab","data-on":t===l,onClick:()=>n(l),children:s},l)})}),(0,a.jsxs)("div",{className:"twin-body",children:["policy"===t&&(0,a.jsx)(lH,{policy:e.policy,setPolicy:e.setPolicy}),"eval"===t&&(0,a.jsx)(lG,{decide:e.decide}),"memory"===t&&(0,a.jsx)(lJ,{memory:e.memory,setMemory:e.setMemory}),"bridges"===t&&(0,a.jsx)(lV,{bridges:e.bridges,setBridges:e.setBridges}),"persona"===t&&(0,a.jsx)(lX,{persona:e.persona,setPersona:e.setPersona})]})]})}function lQ(e){return"embedding-only"===e?"Embedding model — not selectable for text conversation":"ocr-vision-only"===e?"OCR/vision-only — not selectable for text conversation":"Not a chat model — not selectable for text conversation"}function l$(e){let{model:t}=e,n=(0,tL.nP)(t);return void 0===n?(0,a.jsx)("span",{className:"ml-elig ml-elig-ok","data-testid":"conv-elig-ok",role:"status","aria-label":"Model eligibility: eligible for conversation",children:"Conversation-eligible"}):(0,a.jsxs)("span",{className:"ml-elig ml-elig-no","data-testid":"conv-elig-no",role:"status","aria-label":"Model eligibility: "+lQ(n),title:lQ(n),children:["Not selectable — ","embedding-only"===n?"embedding model":"ocr-vision-only"===n?"OCR/vision-only":"not a chat model"]})}function l0(e){var t;let{model:n}=e,l=(0,tL.S_)(n);return(0,a.jsxs)("div",{className:"ml-row",children:[(0,a.jsx)("span",{className:"ml-ico",children:(0,a.jsx)(N.F.cube,{size:16})}),(0,a.jsxs)("div",{className:"ml-info",children:[(0,a.jsxs)("div",{className:"ml-top",children:[(0,a.jsx)("span",{className:"ml-name",children:n.id}),(0,a.jsx)("span",{className:"ml-type mono",children:"ocr-vision"===(t=n.kind)?"OCR":t}),(0,a.jsx)(l$,{model:n})]}),(0,a.jsxs)("div",{className:"ml-url mono",children:["tools ",n.toolCalling?"yes":"no"," \xb7 structured"," ",n.structuredOutput?"yes":"no"," \xb7 ",n.costClass,"/",n.latencyClass]})]}),(0,a.jsx)("span",{className:"ml-status "+(l?"connected":"ineligible"),title:l?"conversation-eligible":"not selectable for conversation","aria-hidden":"true"})]})}let l1="keiko.wallpaper.opacity";function l2(){let e=window.localStorage.getItem(l1);if(null===e)return 100;let t=Number.parseInt(e,10);return Number.isFinite(t)?Math.max(0,Math.min(100,t)):100}function l3(){let[e,t]=(0,l.useState)(l2);(0,l.useEffect)(()=>{try{window.localStorage.setItem(l1,String(e))}catch(e){}window.dispatchEvent(new CustomEvent("keiko:wallpaper-opacity",{detail:e}))},[e]);let n={"--p":"".concat(String(e),"%")};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("div",{className:"set-sec-h",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"set-sec-t",children:"Workspace wallpaper"}),(0,a.jsx)("div",{className:"set-sec-d",children:"Liquid Chrome — a subtle metallic flow behind the grid that reacts to your cursor and clicks. Set to 0% for the plain workspace background."})]})}),(0,a.jsxs)("div",{className:"gpref",children:[(0,a.jsxs)("div",{className:"gpref-row",children:[(0,a.jsx)("label",{className:"gpref-label",htmlFor:"wp-op",children:"Wallpaper opacity"}),(0,a.jsxs)("span",{className:"gpref-val mono",children:[e,"%"]})]}),(0,a.jsx)("input",{id:"wp-op",className:"gpref-slider",type:"range",min:0,max:100,step:1,value:e,onChange:e=>t(Number.parseInt(e.target.value,10)),style:n,"aria-label":"Wallpaper opacity"}),(0,a.jsxs)("div",{className:"gpref-scale",children:[(0,a.jsx)("span",{children:"Off"}),(0,a.jsx)("span",{children:"Full"})]})]})]})}function l4(){let[e,t]=(0,l.useState)("models"),[n,s]=(0,l.useState)([]),[i,r]=(0,l.useState)(!1),[o,c]=(0,l.useState)(!0),[d,u]=(0,l.useState)(),[h,p]=(0,l.useState)(!1),[m,f]=(0,l.useState)(0);(0,l.useEffect)(()=>{let e=!1;return async function(){c(!0),u(void 0);try{let[t,n]=await Promise.all([(0,$.Dz)(),(0,$.ZC)()]);if(e)return;r(t.configPresent),s(n.models)}catch(t){if(e)return;u(function(e){let t="Could not load gateway settings — the local Keiko backend did not respond.";if(!(e instanceof Error))return t;let n=e.message.trim();return 0===n.length||/^HTTP \d+$/u.test(n)||"Failed to fetch"===n||"Load failed"===n||"NetworkError when attempting to fetch a resource."===n?t:n}(t))}finally{e||c(!1)}}(),()=>{e=!0}},[m]);let g=n.filter(tL.S_).length,v=n.length>0,x=i?v?0===g?"Gateway connected, but none of the discovered models can be used for conversation. Add a chat-capable deployment.":"Keiko can use the configured gateway models for chat and agent workflows.":"The gateway is configured, but no conversation-capable models are currently available.":"Enter the gateway base URL and API token before using chat or agent workflows.";return(0,a.jsxs)("div",{className:"set",children:[(0,a.jsxs)("div",{className:"set-hero",children:[(0,a.jsx)(N.F.settings,{size:18}),(0,a.jsx)("span",{className:"set-title",children:"Settings"}),(0,a.jsxs)("span",{className:"set-onprem",title:"Runs inside your network",children:[(0,a.jsx)("span",{className:"dot",style:{background:"var(--accent)"}})," Self-hosted"]})]}),(0,a.jsx)("div",{className:"set-tabs",children:["models","general","security"].map(n=>(0,a.jsx)("button",{type:"button",className:"set-tab","data-on":e===n,"aria-pressed":e===n,onClick:()=>t(n),children:"models"===n?"Models":"general"===n?"General":"Security"},n))}),(0,a.jsxs)("div",{className:"set-body",children:["models"===e&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"set-sec-h",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("div",{className:"set-sec-t",children:"Model gateway"}),(0,a.jsx)("div",{className:"set-sec-d",children:"Credentials are stored locally by the Keiko loopback server; secrets are never returned to the browser."})]}),(0,a.jsxs)("button",{type:"button",className:"set-add",onClick:()=>p(!0),children:[(0,a.jsx)(N.F.plus,{size:14}),i?"Update credentials":"Connect gateway"]})]}),(0,a.jsxs)("div",{className:"ml-row",children:[(0,a.jsx)("span",{className:"ml-ico",children:(0,a.jsx)(N.F.cube,{size:16})}),(0,a.jsxs)("div",{className:"ml-info",children:[(0,a.jsxs)("div",{className:"ml-top",children:[(0,a.jsx)("span",{className:"ml-name",children:i?v?"Gateway connected":"Gateway configured":"Gateway setup required"}),(0,a.jsxs)("span",{className:"ml-type mono",children:[n.length.toString()," models"]}),(0,a.jsxs)("span",{className:"ml-type mono",children:[g.toString()," chat"]})]}),(0,a.jsx)("div",{className:"ml-url mono",children:x})]}),(0,a.jsx)("span",{className:"ml-status "+(i?"connected":"untested"),title:i?"gateway configured":"setup required","aria-hidden":"true"})]}),void 0!==d?(0,a.jsxs)("div",{className:"gw-error",role:"alert",children:[d,(0,a.jsx)("button",{type:"button",className:"gw-error-retry",onClick:()=>f(e=>e+1),children:"Retry"})]}):null,o?(0,a.jsx)("div",{className:"set-placeholder",role:"status",children:"Loading gateway models…"}):0===n.length?(0,a.jsx)("div",{className:"set-placeholder",role:"status",children:i?"No conversation-capable models are currently available. Review the gateway configuration or discovered model set.":"No models are configured yet. Connect the gateway to load configured model capabilities."}):(0,a.jsx)("div",{className:"set-list",children:n.map(e=>(0,a.jsx)(l0,{model:e},e.id))}),h?(0,a.jsx)(n1,{onCancel:()=>p(!1)}):null]}),"general"===e&&(0,a.jsx)(l3,{}),"security"===e&&(0,a.jsx)("div",{className:"set-placeholder",children:"SSO \xb7 audit log \xb7 data residency — coming soon."})]})]})}function l6(e){return e instanceof $.hD?"".concat(e.message," (").concat(e.code,")"):e instanceof Error?e.message:"Failed to load connectors."}function l5(){return(0,a.jsx)("div",{className:"connector-picker-status",role:"status","aria-live":"polite",children:"Loading connectors…"})}function l8(e){let{message:t,onRetry:n}=e;return(0,a.jsxs)("div",{className:"connector-picker-error",role:"alert",children:[(0,a.jsx)("p",{children:t}),(0,a.jsx)("button",{type:"button",className:"connector-picker-retry",onClick:n,children:"Try again"})]})}function l9(){return(0,a.jsxs)("div",{className:"connector-picker-empty",children:[(0,a.jsx)("p",{children:"No ready connectors found."}),(0,a.jsx)("a",{href:"/local-knowledge",className:"connector-picker-create-link",children:"Create a connector"})]})}function l7(e){let{capsules:t,capsuleSets:n,selectedKind:l,selectedId:s}=e,i=function(e,t,n,a){if(void 0===n||void 0===a||0===a.length)return null;if("capsule"===n){let t=e.find(e=>e.id===a);return void 0!==t?t.displayName:"Capsule ".concat(a)}if("capsule-set"===n){let e=t.find(e=>e.id===a);return void 0!==e?e.displayName:"Set ".concat(a)}return null}(t,n,l,s);return null===i?null:(0,a.jsxs)("div",{className:"connector-picker-selected",role:"status","aria-live":"polite",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"●"}),(0,a.jsx)("span",{children:i})]})}function se(e){let{selectedKind:t,selectedId:n,onSelect:s}=e,[i,r]=(0,l.useState)([]),[o,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!0),[h,p]=(0,l.useState)(null),[m,f]=(0,l.useState)(!1),[g,v]=(0,l.useState)(0);if((0,l.useEffect)(()=>{let e=!1;return async function(){u(!0),p(null),f(!1);try{let[t,n]=await Promise.allSettled([(0,t7.xr)(),(0,t7.R3)()]);if(e)return;"fulfilled"===t.status?r(t.value.capsules.filter(e=>"ready"===e.lifecycleState)):p(l6(t.reason)),"fulfilled"===n.status?c(n.value.capsuleSets):f(!0)}catch(t){e||p(l6(t))}finally{e||u(!1)}}(),()=>{e=!0}},[g]),d)return(0,a.jsx)(l5,{});if(null!==h)return(0,a.jsx)(l8,{message:h,onRetry:()=>{v(e=>e+1)}});let x=i.length>0,y=o.length>0;if(!x&&!y)return(0,a.jsx)(l9,{});let b=void 0!==t&&void 0!==n&&n.length>0?"".concat(t,":").concat(n):"";return(0,a.jsxs)("div",{className:"connector-picker",children:[(0,a.jsx)(l7,{capsules:i,capsuleSets:o,selectedKind:t,selectedId:n}),(0,a.jsx)("label",{className:"connector-picker-label",htmlFor:"connector-picker-select",children:"Select a connector"}),(0,a.jsxs)("select",{id:"connector-picker-select",className:"connector-picker-select",value:b,onChange:e=>{!function(e){if(""===e)return;let t=e.indexOf(":");if(-1===t)return;let n=e.slice(0,t),a=e.slice(t+1);0!==a.length&&s({selectedKind:n,selectedId:a})}(e.target.value)},children:[(0,a.jsx)("option",{value:"",disabled:!0,children:"— choose a connector —"}),x&&(0,a.jsx)("optgroup",{label:"Capsules",children:i.map(e=>(0,a.jsx)("option",{value:"capsule:".concat(e.id),children:"".concat(e.displayName," (").concat(function(e){switch(e){case"ready":return"Ready";case"indexing":return"Indexing…";case"error":return"Failed";default:return e}}(e.lifecycleState),")")},"capsule:".concat(e.id)))}),y&&(0,a.jsx)("optgroup",{label:"Capsule sets",children:o.map(e=>(0,a.jsx)("option",{value:"capsule-set:".concat(e.id),children:"".concat(e.displayName," (").concat(String(e.capsuleCount)," capsules)")},"capsule-set:".concat(e.id)))})]}),m?(0,a.jsx)("p",{className:"connector-picker-notice",role:"status",children:"Capsule sets could not be loaded."}):null,(0,a.jsx)("div",{className:"connector-picker-footer",children:(0,a.jsx)("a",{href:"/local-knowledge",className:"connector-picker-create-link",children:"Create or manage connectors"})})]})}async function st(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s=await fetch(e,{...t,headers:{Accept:"application/json",...(null==t?void 0:t.body)!==void 0?{"Content-Type":"application/json"}:{},..."GET"===l||"HEAD"===l?{}:{"X-Keiko-CSRF":"1"},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!s.ok){let e="INTERNAL",t="HTTP ".concat(s.status.toString());try{let n=await s.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,s.status)}return s.json()}async function sn(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return st("/api/figma/snapshots",{method:"POST",body:JSON.stringify({boardLink:e,...!0===t.acknowledgeReadOnly?{acknowledgeReadOnly:!0}:{},...!0===t.isResnapshot?{isResnapshot:!0}:{}})})}async function sa(e){return st("/api/figma/snapshots/".concat(encodeURIComponent(e)))}async function sl(e){return st("/api/figma/snapshots/".concat(encodeURIComponent(e),"/code"),{method:"POST",body:JSON.stringify({})})}function ss(e){try{let t=new URL(e.trim()),n=t.hostname.toLowerCase();if("figma.com"!==n&&!n.endsWith(".figma.com")||!/^\/(design|file)\//u.test(t.pathname))return!1;let a=t.searchParams.get("node-id");return null!==a&&a.length>0}catch(e){return!1}}let si=new Set(["FIGMA_PROXY_EGRESS_FAILED","FIGMA_PROXY_UNREACHABLE","FIGMA_TLS_CA_FAILURE","FIGMA_UPSTREAM_UNAVAILABLE"]);function sr(e){return e instanceof $.hD?si.has(e.code)?{title:"Figma snapshot blocked by outbound egress",detail:"".concat(e.code,": ").concat(e.message),status:"HTTP ".concat(e.status.toString()),remediation:"Check the configured proxy, NO_PROXY rules, and CA bundle, then retry. No snapshot was stored.",assertive:!0}:{title:"Figma snapshot failed",detail:e.message}:e instanceof Error?{title:"Figma snapshot failed",detail:e.message}:{title:"Figma snapshot failed",detail:"An unexpected error occurred."}}function so(e){let{index:t,screenId:n,name:l,irSummary:s,imageByteLength:i}=e;return(0,a.jsxs)("article",{className:"figma-snapshot-screen-card","aria-label":"Screen ".concat(String(t+1),": ").concat(l),children:[(0,a.jsxs)("div",{className:"figma-snapshot-screen-placeholder","aria-hidden":"true",children:[(0,a.jsx)("svg",{className:"figma-snapshot-screen-frame-icon",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,a.jsx)("path",{d:"M7 2v20M17 2v20M2 7h20M2 17h20"})}),(0,a.jsx)("span",{className:"figma-snapshot-screen-index",children:String(t+1)})]}),(0,a.jsxs)("div",{className:"figma-snapshot-screen-meta",children:[(0,a.jsx)("h3",{className:"figma-snapshot-screen-name",title:l,children:l}),(0,a.jsx)("p",{className:"figma-snapshot-screen-summary",children:s}),(0,a.jsx)("p",{className:"figma-snapshot-screen-size",children:eA(i)}),(0,a.jsx)("p",{className:"figma-snapshot-screen-id",children:n})]})]})}function sc(e){let{snapshotRunId:t,updateCfg:n,triggerImpl:s=sn,loadImpl:i=sa,codegenImpl:r=sl}=e,o=(0,l.useId)(),c=(0,l.useId)(),d=(0,l.useId)(),[u,h]=(0,l.useState)(""),[p,m]=(0,l.useState)("idle"),[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(!1),[j,w]=(0,l.useState)(!1),k=(0,l.useRef)(null),N=(0,l.useCallback)(()=>{w(!0)},[]),[S,C]=(0,l.useState)("idle"),[R,E]=(0,l.useState)(null),[I,T]=(0,l.useState)(null),F=ss(u),q=function(e){let t=e.trim();if(0===t.length||ss(t))return null;try{let e=new URL(t).hostname.toLowerCase();if("figma.com"===e||e.endsWith(".figma.com"))return"Add a node-id by selecting a frame or section in Figma and copying its link (Copy link to selection)."}catch(e){}return"This doesn't look like a Figma board link. Use a figma.com design/file link that includes a node-id parameter."}(u),A="building"===p,M="loading"===p,P=A||M;(0,l.useEffect)(()=>{var e;j&&"error"===p&&(null==(e=k.current)||e.focus())},[j,p]);let D=(0,l.useCallback)(async(e,t)=>{m("building"),x(null),C("idle"),E(null);try{let a=await s(e,{acknowledgeReadOnly:y,isResnapshot:t});g(a),n({snapshotRunId:a.runId}),m("done")}catch(e){if(e instanceof $.hD&&"FIGMA_CONSENT_REQUIRED"===e.code){let t=sr(e);x({...t,detail:"".concat(t.detail," Tick the acknowledgement checkbox below, then snapshot again.")}),N()}else x(sr(e));m("error")}},[s,n,y,N]),L=(0,l.useCallback)(e=>{if(e.preventDefault(),F&&!P){if(!y){x({title:"Figma snapshot failed",detail:"Tick the read-only acknowledgement checkbox below, then snapshot again."}),m("error"),N();return}D(u,!1)}},[u,P,y,F,D,N]),z=(0,l.useCallback)(()=>{P||null===f||D("https://www.figma.com/design/".concat(f.fileKey,"/board?node-id=").concat(f.nodeId),!0)},[P,D,f]),O=(0,l.useCallback)(()=>{var e;let n=null!=(e=null==f?void 0:f.runId)?e:t;void 0!==n&&0!==n.length&&"generating"!==S&&(C("generating"),T(null),r(n).then(e=>{E(e),C("done")}).catch(e=>{T(function(e){let t=sr(e);return void 0===t.status?t.detail:"".concat(t.detail," (").concat(t.status,")")}(e)),C("error")}))},[r,S,t,f]),K=(0,l.useCallback)(()=>{void 0===t||0===t.length||P||(m("loading"),x(null),i(t).then(e=>{g(e),m("done")}).catch(e=>{x(sr(e)),m("error")}))},[P,i,t]),B=void 0!==t&&t.length>0&&null===f&&("idle"===p||"loading"===p);return(0,a.jsxs)("section",{className:"figma-snapshot-window","aria-label":"Figma Snapshot",children:[(0,a.jsxs)("form",{className:"figma-snapshot-form",onSubmit:L,noValidate:!0,children:[(0,a.jsx)("label",{className:"figma-snapshot-label",htmlFor:o,children:"Board link"}),(0,a.jsxs)("div",{className:"figma-snapshot-input-row",children:[(0,a.jsx)("input",{id:o,type:"url",className:"figma-snapshot-input",placeholder:"https://www.figma.com/design/…?node-id=…",value:u,onChange:e=>{h(e.target.value),null!==v&&x(null),"error"===p&&m("idle"),j&&w(!1)},"aria-describedby":null!==q?"".concat(d," ").concat(c):c,"aria-invalid":null!==q?"true":void 0,readOnly:P,autoComplete:"off",spellCheck:!1}),(0,a.jsx)("button",{type:"submit",className:"figma-snapshot-trigger-btn",disabled:!F&&!P,"aria-disabled":!F||P?"true":void 0,"aria-busy":A,children:A?"Building…":"Snapshot"})]}),null!==q&&(0,a.jsx)("p",{id:d,className:"figma-snapshot-link-error",children:q}),(0,a.jsxs)("label",{className:"figma-snapshot-consent",children:[(0,a.jsx)("input",{type:"checkbox",className:"figma-snapshot-consent-checkbox",ref:k,checked:y,"aria-invalid":j?"true":void 0,onChange:e=>{b(e.target.checked),null!==v&&x(null),"error"===p&&m("idle"),w(!1)},disabled:A}),(0,a.jsxs)("span",{children:["I acknowledge the configured Figma PAT is read-only and least-privilege (",(0,a.jsx)("code",{children:"files:read"}),")."," ",(0,a.jsx)("span",{className:"figma-snapshot-consent-required",children:"Required before the first snapshot of a board."})]})]}),(0,a.jsx)("p",{className:"figma-snapshot-hint",children:"Paste a Figma board link with a node-id param (section or frame anchor). The access token is resolved server-side — it never reaches this page."})]}),(0,a.jsxs)("div",{id:c,role:"status","aria-live":"polite","aria-atomic":"true",className:"figma-snapshot-status",children:[A&&(0,a.jsx)("p",{className:"figma-snapshot-progress",children:"Building snapshot — fetching screens from Figma…"}),M&&(0,a.jsx)("p",{className:"figma-snapshot-progress",children:"Loading stored snapshot…"}),"done"===p&&null!==f&&(0,a.jsxs)("p",{className:"sr-only",children:["Snapshot complete — ",f.reductionHint,"."]}),"done"===S&&null!==R&&(0,a.jsxs)("p",{className:"sr-only",children:["Code generated — ",String(R.fileCount)," file",1!==R.fileCount?"s":""," ready for review."]}),"error"===p&&null!==v&&!0===v.assertive&&(0,a.jsxs)("div",{className:"figma-snapshot-error-card",role:"alert","aria-labelledby":"".concat(c,"-error-title"),children:[(0,a.jsx)("p",{id:"".concat(c,"-error-title"),className:"figma-snapshot-error-title",children:v.title}),(0,a.jsx)("p",{className:"figma-snapshot-error-detail",children:v.detail}),void 0!==v.status&&(0,a.jsx)("p",{className:"figma-snapshot-error-status",children:v.status}),void 0!==v.remediation&&(0,a.jsx)("p",{className:"figma-snapshot-error-remediation",children:v.remediation})]}),"error"===p&&null!==v&&!0!==v.assertive&&(0,a.jsx)("p",{className:"figma-snapshot-error",children:v.detail})]}),"idle"===p&&null===f&&!B&&(0,a.jsxs)("div",{className:"figma-snapshot-empty",children:[(0,a.jsx)("p",{className:"figma-snapshot-empty-title",children:"Capture screens from a Figma board"}),(0,a.jsxs)("ol",{className:"figma-snapshot-empty-steps",children:[(0,a.jsx)("li",{children:"In Figma, select the frame or section you want to capture."}),(0,a.jsx)("li",{children:"Copy its link (Copy link to selection) — it contains the node-id."}),(0,a.jsx)("li",{children:"Paste it above, acknowledge the read-only scope, then take the snapshot."})]}),(0,a.jsx)("p",{className:"figma-snapshot-empty-note",children:"The snapshot stores the captured screens and their structure as immutable evidence — connect this window to Quality Intelligence to ground generated tests in the design. Requires a Figma access token configured on the server."})]}),B&&(0,a.jsxs)("div",{className:"figma-snapshot-stored-notice",children:[(0,a.jsx)("p",{className:"figma-snapshot-stored-text",children:"A stored snapshot is available."}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-load-btn",onClick:K,"aria-disabled":M?"true":void 0,"aria-busy":M,children:M?"Loading…":"Load snapshot"})]}),null!==f&&"done"===p&&(0,a.jsxs)("div",{className:"figma-snapshot-result",children:[(0,a.jsxs)("div",{className:"figma-snapshot-reduction",children:[(0,a.jsx)("p",{className:"figma-snapshot-reduction-hint",children:f.reductionHint}),(0,a.jsxs)("p",{className:"figma-snapshot-captured-at",children:["Captured ",function(e){try{return new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch(t){return"string"==typeof e?e:e.toString()}}(f.fetchedAt)]}),f.skippedCount>0&&(0,a.jsxs)("p",{className:"figma-snapshot-skipped-notice",children:[String(f.skippedCount)," screen",1!==f.skippedCount?"s":""," could not be rendered and were skipped."]})]}),(0,a.jsx)("button",{type:"button",className:"figma-snapshot-resnapshot-btn",onClick:z,disabled:A,"aria-label":"Re-snapshot this board",children:"Re-snapshot"}),(0,a.jsxs)("div",{className:"figma-snapshot-codegen",children:[(0,a.jsx)("button",{type:"button",className:"figma-snapshot-codegen-btn",onClick:O,"aria-disabled":"generating"===S?"true":void 0,"aria-busy":"generating"===S,children:"generating"===S?"Generating code…":"Generate code"}),"error"===S&&null!==I&&(0,a.jsx)("p",{className:"figma-snapshot-error",role:"alert",children:I}),"done"===S&&null!==R&&(0,a.jsxs)("div",{className:"figma-snapshot-code-result",children:[(0,a.jsxs)("p",{className:"figma-snapshot-code-summary",children:[String(R.fileCount)," reviewable file",1!==R.fileCount?"s":""," (",String(R.screenCount)," screen",1!==R.screenCount?"s":"",","," ",R.adapterName,") — proposal only, never auto-applied."]}),R.files.map(e=>(0,a.jsxs)("details",{className:"figma-snapshot-code-file",children:[(0,a.jsx)("summary",{className:"figma-snapshot-code-file-path",children:e.path}),(0,a.jsx)("pre",{className:"figma-snapshot-code-file-contents",children:(0,a.jsx)("code",{children:e.contents})})]},e.path))]})]}),(0,a.jsxs)("details",{className:"figma-snapshot-scopes",children:[(0,a.jsx)("summary",{className:"figma-snapshot-scopes-summary",children:"Required Figma PAT scopes"}),(0,a.jsxs)("ul",{className:"figma-snapshot-scopes-list",children:[(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"file_read"})," — read design file structure and node metadata"]}),(0,a.jsxs)("li",{children:[(0,a.jsx)("code",{children:"files:read"})," — read file content (REST API scope)"]})]}),(0,a.jsxs)("p",{className:"figma-snapshot-scopes-note",children:["The token is read server-side from the ",(0,a.jsx)("code",{children:"FIGMA_ACCESS_TOKEN"})," environment variable or vault. This window never holds or transmits the token."]})]}),f.screens.length>0?(0,a.jsx)("section",{className:"figma-snapshot-gallery","aria-label":"".concat(String(f.screenCount)," captured screen").concat(1!==f.screenCount?"s":""),children:f.screens.map((e,t)=>(0,a.jsx)(so,{index:t,screenId:e.screenId,name:e.name,irSummary:e.irSummary,imageByteLength:e.imageByteLength},e.screenId))}):(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"No screens were captured from this board section."})})]})]})}async function sd(e,t){var n,a;let l=(null!=(n=null==t?void 0:t.method)?n:"GET").toUpperCase(),s=await fetch(e,{...t,headers:{Accept:"application/json",...(null==t?void 0:t.body)!==void 0?{"Content-Type":"application/json"}:{},..."GET"===l||"HEAD"===l?{}:{"X-Keiko-CSRF":"1"},...null!=(a=null==t?void 0:t.headers)?a:{}}});if(!s.ok){let e="INTERNAL",t="HTTP ".concat(s.status.toString());try{let n=await s.json();e=n.error.code,t=n.error.message}catch(e){}throw new $.hD(e,t,s.status)}return s.json()}async function su(){return sd("/api/quality-intelligence/runs")}async function sh(e){return sd("/api/quality-intelligence/runs/".concat(encodeURIComponent(e)))}async function sp(e){let t="QI_RUN_FAILED",n="HTTP ".concat(e.status.toString());try{var a,l,s,i;let r=await e.json();t=null!=(s=null==(a=r.error)?void 0:a.code)?s:t,n=null!=(i=null==(l=r.error)?void 0:l.message)?i:n}catch(e){}return new $.hD(t,n,e.status)}async function sm(e,t,n){var a,l;let s=await fetch("/api/quality-intelligence/runs",{method:"POST",headers:{Accept:"text/event-stream","Content-Type":"application/json","X-Keiko-CSRF":"1"},body:JSON.stringify(e),signal:t}),i=null!=(a=s.headers.get("content-type"))?a:"";if(!s.ok||!i.includes("text/event-stream"))throw await sp(s);let r=s.body;if(null===r)throw new $.hD("QI_NO_STREAM","The server did not return a progress stream.",s.status);let o=r.getReader(),c=new TextDecoder,d="";try{for(;!t.aborted;){let e=await o.read();if(e.done)break;let t=(d+=c.decode(e.value,{stream:!0})).split("\n");for(let e of(d=null!=(l=t.pop())?l:"",t)){let t=e.trim();if(t.startsWith("data:"))try{n(JSON.parse(t.slice(5).trim()))}catch(e){}}}}finally{o.releaseLock()}}async function sf(e,t,n,a){return sd("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/review"),{method:"POST",body:JSON.stringify({action:t,...void 0!==n?{candidateId:n}:{},...void 0!==a?{reviewerLabel:a}:{}})})}async function sg(e,t,n,a){return(await sd("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/edit"),{method:"POST",body:JSON.stringify({candidateId:t,edited:n,...void 0!==a?{editorLabel:a}:{}})})).candidate}async function sv(e,t){return sd("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/re-check"),{method:"POST",body:JSON.stringify({sources:t})})}async function sx(e,t){return sd("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/regenerate-stale"),{method:"POST",body:JSON.stringify({sources:t})})}async function sy(e,t,n){var a,l;return sd("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/export"),{method:"POST",body:JSON.stringify({adapter:t,dryRun:null!=(a=null==n?void 0:n.dryRun)&&a,approvedOnly:null!=(l=null==n?void 0:n.approvedOnly)&&l})})}async function sb(e,t){return sd("/api/quality-intelligence/runs/".concat(encodeURIComponent(e),"/traceability"),{method:"POST",body:JSON.stringify({format:t})})}let sj={open:"Open",approved:"Approved","changes-requested":"Changes requested",rejected:"Rejected",withdrawn:"Withdrawn"};function sw(e,t){return"".concat(t," (").concat(e,")")}function sk(e){return e instanceof $.hD?sw(e.code,e.message):e instanceof Error?e.message:"An unexpected error occurred."}function sN(e){try{return new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"})}catch(t){return e}}let sS={running:"Running",succeeded:"Succeeded",failed:"Failed",cancelled:"Cancelled"},sC={running:"qi-badge-running",succeeded:"qi-badge-succeeded",failed:"qi-badge-failed",cancelled:"qi-badge-cancelled"};function sR(e){return"running"===e||"succeeded"===e||"failed"===e||"cancelled"===e}function sE(e){let{status:t}=e,n=sR(t)?sS[t]:t,l=sR(t)?sC[t]:"qi-badge-default";return(0,a.jsx)("span",{className:"qi-badge ".concat(l),children:n})}let sI={critical:"qi-sev-critical",high:"qi-sev-high",medium:"qi-sev-medium",low:"qi-sev-low"};function sT(e){let{severity:t}=e,n="critical"===t||"high"===t||"medium"===t||"low"===t?sI[t]:"qi-sev-low";return(0,a.jsxs)("span",{className:"qi-sev ".concat(n),children:[(0,a.jsx)("span",{className:"sr-only",children:"Severity: "}),t]})}function sF(e){let{score:t}=e;if(null===t)return(0,a.jsxs)("span",{className:"qi-badge qi-badge-default","data-testid":"qi-quality-badge",children:[(0,a.jsx)("span",{"aria-hidden":"true",children:"—"}),(0,a.jsx)("span",{className:"sr-only",children:"Quality score not available"})]});let n=Math.round(t);return(0,a.jsxs)("span",{className:"qi-badge ".concat(n>=90?"qi-quality-high":n>=70?"qi-quality-mid":"qi-quality-low"),"data-testid":"qi-quality-badge",children:[n.toString(),(0,a.jsx)("span",{className:"sr-only",children:" out of 100"})]})}function sq(e){let{flag:t}=e;return(0,a.jsxs)("div",{role:"note","aria-label":"Weak test flagged by the quality judge: ".concat(t.rationale),className:"qi-weak-flag","data-testid":"qi-weak-flag",children:[(0,a.jsxs)("span",{className:"qi-weak-flag-badge",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-weak-flag-icon",children:"⚠"}),"Weak test"]}),(0,a.jsx)("p",{className:"qi-weak-flag-reason",children:t.rationale})]})}function sA(e){let{height:t=20,width:n="100%"}=e;return(0,a.jsx)("div",{"aria-hidden":"true",className:"qi-skeleton",style:{height:t,width:n}})}function sM(){return(0,a.jsx)("div",{"data-testid":"qi-loading-state","aria-busy":"true",style:{display:"flex",flexDirection:"column",gap:8,padding:"12px 0"},children:[1,2,3].map(e=>(0,a.jsxs)("div",{className:"qi-skeleton-row",children:[(0,a.jsx)(sA,{height:14,width:"60%"}),(0,a.jsx)(sA,{height:12,width:"40%"})]},e))})}function sP(e){let{message:t,onRetry:n}=e;return(0,a.jsxs)("div",{role:"alert","aria-live":"assertive",className:"lk-alert","data-testid":"qi-error-state",children:[t,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:n,children:"Retry"})]})}function sD(e){var t;let n=e.split(/[\\/]/u).filter(e=>e.length>0);return n.length>0&&null!=(t=n[n.length-1])?t:e}function sL(e){return e.replaceAll("\\","/")}function sz(e){return/^[A-Za-z]:[/\\]?$/u.test(e)?e.replaceAll("\\","/"):/^\/\/[^/]+\/[^/]+$/u.test(sL(e))?sL(e):sL(e).replace(/\/+$/u,"")}function sO(e){var t,n,a,l,s;let i=null!=(t=e.connectedRoot)?t:null,r=function(e,t){var n,a;let l=null!=(n=null==t?void 0:t.trim())?n:"";if(0===l.length)return null;if(l.startsWith("/")||/^[A-Za-z]:[/\\]/u.test(l)||l.startsWith("\\\\")||l.startsWith("//"))return l;let s=null!=(a=null==e?void 0:e.trim())?a:"";if(0===s.length)return null;let i=sz(s),r=sL(l).replace(/^\/+/u,"");return"".concat(i,"/").concat(r)}(i,null!=(n=e.connectedFilePath)?n:null),o=null!==i?sz(i):null,c=(void 0!==e.connectedRoots&&null!==e.connectedRoots&&e.connectedRoots.length>0?e.connectedRoots:null!==i?[i]:[]).map(sz),d=null!==r?c.filter(e=>e!==o):c,u=[];for(let e of(null!==r&&u.push({kind:"file",label:sD(r),path:r}),d))u.push({kind:"workspace",label:sD(e),path:e});for(let t of null!=(a=e.connectedCapsuleIds)?a:[])u.push({kind:"capsule",label:t,capsuleId:t});for(let t of null!=(l=e.connectedCapsuleSetIds)?l:[])u.push({kind:"capsule-set",label:t,capsuleSetId:t});for(let t of null!=(s=e.connectedFigmaSnapshotRunIds)?s:[])u.push({kind:"figma-snapshot",label:t,snapshotRunId:t});let h=new Set,p=[];for(let e of u){if(p.length>=16)break;let t=function(e){switch(e.kind){case"file":case"workspace":return"".concat(e.kind,":").concat(e.path);case"capsule":return"capsule:".concat(e.capsuleId);case"capsule-set":return"capsule-set:".concat(e.capsuleSetId);case"figma-snapshot":return"figma-snapshot:".concat(e.snapshotRunId)}}(e);h.has(t)||(h.add(t),p.push(e))}return p}let sK=[{id:"regression-default",label:"Regression (default)"},{id:"banking-default",label:"Banking"},{id:"insurance-default",label:"Insurance"}],sB={phase:"Starting…",stageName:null,candidates:0,findings:0,atomCount:null,droppedSourceCount:0,skippedSources:[]};function sW(e){switch(e.kind){case"file":return"File";case"workspace":return"Folder";case"capsule":return"Capsule";case"capsule-set":return"Capsule set";case"figma-snapshot":return"Figma snapshot"}}function sU(e){switch(e.kind){case"file":case"workspace":return e.path;case"capsule":return e.capsuleId;case"capsule-set":return e.capsuleSetId;case"figma-snapshot":return e.snapshotRunId}}function s_(e){let{onRunCompleted:t,startImpl:n=sm,fetchCapsulesImpl:s=t7.xr,fetchCapsuleSetsImpl:i=t7.R3,connectedRoot:r=null,connectedFilePath:o=null,connectedRoots:c,connectedCapsuleIds:d,connectedCapsuleSetIds:u,connectedFigmaSnapshotRunIds:h}=e,[p,m]=(0,l.useState)(""),[f,g]=(0,l.useState)("requirements"),[v,x]=(0,l.useState)(""),[y,b]=(0,l.useState)(""),[j,w]=(0,l.useState)(""),[k,N]=(0,l.useState)(""),[S,C]=(0,l.useState)([]),[R,E]=(0,l.useState)([]),[I,T]=(0,l.useState)(!1),[F,q]=(0,l.useState)(null),[A,M]=(0,l.useState)("regression-default"),[P,D]=(0,l.useState)(""),[L,z]=(0,l.useState)(!1),[O,K]=(0,l.useState)(sB),[B,W]=(0,l.useState)(null),U=(0,l.useRef)(null),_=(0,l.useRef)(null),H=sO({connectedRoot:r,connectedFilePath:o,connectedRoots:c,connectedCapsuleIds:d,connectedCapsuleSetIds:u,connectedFigmaSnapshotRunIds:h}),G=H.length>0,J=S.find(e=>e.id===j),V=R.find(e=>e.id===k),X=y.trim().length>0,Y="requirements"===f?v.trim().length>0:"workspace"===f||"file"===f?X:"capsule"===f?j.trim().length>0:k.trim().length>0,Z="requirements"===f?0===v.trim().length:("workspace"===f||"file"===f)&&!X,Q=Y||Z&&G,$=P.trim(),ee=0===$.length?void 0:/^\d+$/u.test($)?Number($):NaN,et=void 0===ee||Number.isSafeInteger(ee)&&Number.isFinite(ee),en=!Q||!et,ea=(0,l.useId)(),el=(0,l.useId)(),es=(0,l.useId)(),ei=Q?et?void 0:el:ea,er=(0,l.useCallback)(e=>{"accepted"===e.type&&(_.current=e.runId),"error"===e.type&&W(sw(e.code,e.message)),K(t=>(function(e,t){var n,a,l;if("accepted"===t.type)return{...e,phase:"Ingested sources",atomCount:t.atomCount,droppedSourceCount:null!=(n=t.droppedSourceCount)?n:0,skippedSources:null!=(a=t.skippedSources)?a:[]};if("event"===t.type){let n="candidate:proposed"===t.kind?e.candidates+1:e.candidates,a="finding:recorded"===t.kind?e.findings+1:e.findings,s="stage:started"===t.kind?null!=(l=t.stageName)?l:null:e.stageName;return{...e,phase:t.kind,stageName:s,candidates:n,findings:a}}return e})(t,e))},[]),eo="capsule"===f||"capsule-set"===f;(0,l.useEffect)(()=>{if(!eo)return;let e=!1;return async function(){T(!0),q(null);try{let[t,n]=await Promise.allSettled([s(),i()]);if(e)return;"fulfilled"===t.status?C(t.value.capsules.filter(e=>"ready"===e.lifecycleState)):(C([]),"capsule"===f&&q(sk(t.reason))),"fulfilled"===n.status?E(n.value.capsuleSets):(E([]),"capsule-set"===f&&q(sk(n.reason)))}finally{e||T(!1)}}(),()=>{e=!0}},[s,i,eo,f]),(0,l.useEffect)(()=>{var e,t,n,a;if("capsule"===f){let n=S.some(e=>e.id===j)?j:null!=(t=null==(e=S[0])?void 0:e.id)?t:"";n!==j&&w(n)}if("capsule-set"===f){let e=R.some(e=>e.id===k)?k:null!=(a=null==(n=R[0])?void 0:n.id)?a:"";e!==k&&N(e)}},[j,k,R,S,f]);let ec=(0,l.useCallback)(()=>{let e=p.trim();return"requirements"===f&&v.trim().length>0?[{kind:"requirements",label:e||"Requirements",text:v}]:"workspace"===f&&y.trim().length>0?[{kind:"workspace",label:e||"Folder",path:y.trim()}]:"file"===f&&y.trim().length>0?[{kind:"file",label:e||"File",path:y.trim()}]:"capsule"===f&&j.trim().length>0?[{kind:"capsule",label:e||(null==J?void 0:J.displayName)||"Knowledge capsule",capsuleId:j.trim()}]:"capsule-set"===f&&k.trim().length>0?[{kind:"capsule-set",label:e||(null==V?void 0:V.displayName)||"Capsule set",capsuleSetId:k.trim()}]:null},[j,k,p,y,J,V,f,v]),ed=(0,l.useCallback)(async()=>{var e;if(!Q||L||!et)return;z(!0),W(null),K(sB),_.current=null;let a=new AbortController;U.current=a;let l=null!=(e=ec())?e:H,s={sources:l,profileId:A,...void 0!==ee?{seed:ee}:{}};try{await n(s,a.signal,er);let e=_.current;null!==e&&(null==t||t(e,l.filter(e=>"requirements"!==e.kind)))}catch(e){a.signal.aborted||W(sk(e))}finally{z(!1),U.current=null}},[Q,A,L,H,ec,er,t,ee,et,n]),eu=(0,l.useCallback)(()=>{var e;null==(e=U.current)||e.abort()},[]),eh=O.droppedSourceCount>0?"".concat(O.droppedSourceCount.toString()," source").concat(1!==O.droppedSourceCount?"s":""," over the 16-source limit ").concat(1!==O.droppedSourceCount?"were":"was"," not included."):null,ep=O.skippedSources.length>0?"".concat(O.skippedSources.length.toString()," connected source").concat(1!==O.skippedSources.length?"s":""," could not be read and ").concat(1!==O.skippedSources.length?"were":"was"," skipped: ").concat(O.skippedSources.map(e=>e.label).join(", "),"."):null,em=[eh,ep].filter(e=>null!==e).join(" ");return(0,a.jsxs)("section",{className:"qi-launcher","aria-label":"Start a Quality Intelligence run",children:[(0,a.jsx)("header",{className:"qi-col-header",children:(0,a.jsx)("h2",{className:"qi-col-title",children:"New run"})}),(0,a.jsxs)("div",{className:"qi-launcher-body",children:[1===H.length&&void 0!==H[0]?(0,a.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,a.jsxs)("span",{className:"qi-connected-kind",children:["Connected ",sW(H[0]).toLowerCase()]}),(0,a.jsx)("span",{className:"qi-connected-path qi-monospace",title:sU(H[0]),children:sU(H[0])}),(0,a.jsx)("span",{className:"qi-connected-hint",children:Y?"Manual input below overrides the connected source for this run.":"Generate uses the connected ".concat(sW(H[0]).toLowerCase(),".")})]}):H.length>1?(0,a.jsxs)("div",{className:"qi-connected-source","data-testid":"qi-connected-source",children:[(0,a.jsxs)("span",{className:"qi-connected-kind",children:["Connected sources (",H.length.toString(),")"]}),(0,a.jsx)("ul",{className:"qi-connected-roots","aria-label":"Connected sources",children:H.map(e=>(0,a.jsxs)("li",{className:"qi-connected-root-item",children:[(0,a.jsx)("span",{className:"qi-connected-root-name",children:sW(e)}),(0,a.jsx)("span",{className:"qi-connected-path qi-monospace",title:sU(e),children:sU(e)})]},"".concat(e.kind,":").concat(sU(e))))}),(0,a.jsx)("span",{className:"qi-connected-hint",children:Y?"Manual input below overrides the connected sources for this run.":"Generate uses all connected sources."})]}):null,(0,a.jsxs)("div",{className:"qi-launcher-row",children:[(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Source label"}),(0,a.jsx)("input",{type:"text",className:"qi-input",value:p,placeholder:"e.g. Funds Transfer — acceptance criteria",disabled:L,"aria-describedby":G&&!Y?es:void 0,onChange:e=>{m(e.target.value)}}),G&&!Y?(0,a.jsx)("span",{className:"qi-field-hint",id:es,children:"Applies to manual input only — connected sources use their own labels."}):null]}),(0,a.jsxs)("label",{className:"qi-field qi-field-kind",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Source type"}),(0,a.jsxs)("select",{className:"qi-select",value:f,disabled:L,onChange:e=>{let t=e.target.value;g("workspace"===t||"file"===t||"capsule"===t||"capsule-set"===t?t:"requirements"),W(null),q(null)},children:[(0,a.jsx)("option",{value:"requirements",children:"Requirements text"}),(0,a.jsx)("option",{value:"workspace",children:"Local folder"}),(0,a.jsx)("option",{value:"file",children:"Single file"}),(0,a.jsx)("option",{value:"capsule",children:"Knowledge capsule"}),(0,a.jsx)("option",{value:"capsule-set",children:"Capsule set"})]})]})]}),function(){if("requirements"===f)return(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Requirements"}),(0,a.jsx)("textarea",{className:"qi-textarea",value:v,rows:6,placeholder:"Paste requirements or acceptance criteria, one statement per line.",disabled:L,onChange:e=>{x(e.target.value)}})]});if("workspace"===f||"file"===f){let e="file"===f;return(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:e?"File path":"Folder path"}),(0,a.jsx)("input",{type:"text",className:"qi-input",value:y,placeholder:e?"/absolute/path/to/requirements.md":"/absolute/path/to/folder",disabled:L,onChange:e=>{b(e.target.value)}})]})}let e="capsule"===f,t=e?S:R;return(0,a.jsxs)("label",{className:"qi-field",children:[(0,a.jsx)("span",{className:"qi-field-label",children:e?"Knowledge capsule":"Capsule set"}),(0,a.jsxs)("select",{className:"qi-select",value:e?j:k,disabled:L||I||null!==F||0===t.length,onChange:t=>{e?w(t.target.value):N(t.target.value)},children:[I?(0,a.jsx)("option",{value:"",children:"Loading connectors..."}):null,I||0!==t.length?null:(0,a.jsx)("option",{value:"",children:e?"No ready capsules":"No capsule sets"}),e?S.map(e=>(0,a.jsx)("option",{value:e.id,children:e.displayName},e.id)):R.map(e=>(0,a.jsx)("option",{value:e.id,children:"".concat(e.displayName," (").concat(String(e.capsuleCount)," capsules)")},e.id))]})]})}(),null!==F?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-connector-error",children:F}):null,(0,a.jsxs)("div",{className:"qi-launcher-controls",children:[(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Policy profile"}),(0,a.jsx)("select",{className:"qi-select",value:A,disabled:L,onChange:e=>{M(e.target.value)},children:sK.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Seed (optional)"}),(0,a.jsx)("input",{type:"number",min:0,step:1,className:"qi-input",value:P,placeholder:"e.g. 42",disabled:L,"aria-invalid":!et||void 0,"aria-describedby":et?void 0:el,onChange:e=>{D(e.target.value),W(null)}}),et?null:(0,a.jsx)("span",{className:"qi-field-error",id:el,children:"Seed must be a non-negative integer."})]}),(0,a.jsx)("button",{type:"button",className:L?"qi-btn qi-btn-secondary":"qi-btn qi-btn-primary","aria-disabled":!L&&en||void 0,"aria-describedby":L?void 0:ei,onClick:()=>{if(L)return void eu();en||ed()},children:L?"Cancel":"Generate test cases"}),L||Q?null:(0,a.jsx)("span",{className:"qi-generate-hint",id:ea,children:"Add requirements text, a folder path, a file path, select a capsule, select a capsule set, or connect a source to generate."})]}),L?(0,a.jsxs)("div",{className:"qi-progress",role:"status","aria-live":"polite","aria-label":"Run progress","data-testid":"qi-launch-progress",children:[(0,a.jsx)("span",{className:"qi-progress-spinner","aria-hidden":"true"}),(0,a.jsxs)("span",{className:"qi-progress-text",children:[null!==O.stageName?"Stage: ".concat(O.stageName," \xb7 "):"",O.candidates.toString()," test case",1!==O.candidates?"s":"",O.findings>0?" \xb7 ".concat(O.findings.toString()," finding").concat(1!==O.findings?"s":""):""]})]}):null,(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:em}),null!==eh||null!==ep?(0,a.jsxs)("div",{className:"qi-coverage-notice","data-testid":"qi-coverage-notice",children:[null!==eh?(0,a.jsx)("p",{className:"qi-coverage-line",children:eh}):null,null!==ep?(0,a.jsx)("p",{className:"qi-coverage-line",children:ep}):null]}):null,null!==B?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-launch-error",children:B}):null]})]})}function sH(e){var t;let{run:n,onOpen:l}=e,s=n.totals.candidates;return(0,a.jsx)("li",{children:(0,a.jsxs)("button",{type:"button",className:"qi-run-item",onClick:()=>{l(n.id)},"aria-label":"Open run ".concat(n.id," — ").concat(sR(t=n.status)?sS[t]:t,", ").concat(sN(n.requestedAt),", ").concat(s.toString()," test case").concat(1!==s?"s":""),title:"Open run ".concat(n.id),children:[(0,a.jsx)("span",{className:"qi-run-title",children:sN(n.requestedAt)}),(0,a.jsx)(sE,{status:n.status}),(0,a.jsxs)("span",{className:"qi-run-id",children:[n.id.slice(0,16),"…"]}),(0,a.jsxs)("span",{className:"qi-run-totals",children:[n.totals.candidates.toString()," test case",1!==n.totals.candidates?"s":""]})]})})}function sG(e){let{openRun:t,connectedRoot:n=null,connectedFilePath:s=null,connectedRoots:i,connectedCapsuleIds:r,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c,fetchRunsImpl:d=su}=e,[u,h]=(0,l.useState)([]),[p,m]=(0,l.useState)(0),[f,g]=(0,l.useState)(!1),[v,x]=(0,l.useState)(!0),[y,b]=(0,l.useState)(null),j=(0,l.useCallback)(async()=>{x(!0),b(null);try{let e=await d();h(e.runs),m(e.totalRunIds),g(e.truncated)}catch(e){b(sk(e))}finally{x(!1)}},[d]);(0,l.useEffect)(()=>{j()},[j]);let w=(0,l.useCallback)((e,n)=>{j(),t(e,n)},[j,t]);return(0,a.jsxs)("div",{className:"qi-hub",children:[(0,a.jsx)(s_,{onRunCompleted:w,connectedRoot:n,connectedFilePath:s,connectedRoots:i,connectedCapsuleIds:r,connectedCapsuleSetIds:o,connectedFigmaSnapshotRunIds:c}),(0,a.jsxs)("section",{className:"qi-hub-runs","aria-label":"Quality Intelligence runs",children:[(0,a.jsxs)("header",{className:"qi-col-header",children:[(0,a.jsx)("h2",{className:"qi-col-title",children:"Runs"}),v||null!==y?null:(0,a.jsx)("span",{className:"qi-col-count",children:p.toString()})]}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:v?"Loading runs…":null===y?"Run list loaded: ".concat(u.length.toString()," run").concat(1===u.length?"":"s").concat(f?" of ".concat(p.toString()):"","."):""}),(0,a.jsx)("div",{className:"qi-col-body","aria-busy":v,children:v?(0,a.jsx)(sM,{}):null!==y?(0,a.jsx)(sP,{message:y,onRetry:()=>{j()}}):0===u.length?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No runs yet"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"Start a run above — generated test cases open as cards on your workspace."})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("ul",{className:"qi-run-list","aria-label":"Run list",children:u.map(e=>(0,a.jsx)(sH,{run:e,onOpen:t},e.id))}),f?(0,a.jsx)("p",{className:"qi-runs-truncated","data-testid":"qi-runs-truncated",children:"Showing ".concat(u.length.toString()," of ").concat(p.toString()," runs.")}):null]})})]})]})}let sJ=["P0","P1","P2","P3"],sV=["safety","compliance","regression","functional","visual"],sX=e=>e.split("\n").map(e=>e.trim()).filter(e=>e.length>0),sY=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);function sZ(e,t){let n=sX(t.preconditions),a=sX(t.steps),l=sX(t.expectedResults),s=t.tags.split(",").map(e=>e.trim()).filter(e=>e.length>0);return{...t.title!==e.title?{title:t.title}:{},...!sY(n,e.preconditions)?{preconditions:n}:{},...!sY(a,e.steps)?{steps:a}:{},...!sY(l,e.expectedResults)?{expectedResults:l}:{},...t.priority!==e.priority?{priority:t.priority}:{},...t.riskClass!==e.riskClass?{riskClass:t.riskClass}:{},...!sY(s,e.tags)?{tags:s}:{}}}function sQ(e){let{id:t,label:n,value:l,disabled:s=!1,onChange:i}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("textarea",{id:t,className:"qi-edit-textarea",value:l,rows:3,disabled:s,onChange:e=>{i(e.target.value)}})]})}function s$(e){let{id:t,label:n,value:l,disabled:s=!1,onChange:i}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("input",{id:t,className:"qi-edit-input",value:l,disabled:s,onChange:e=>{i(e.target.value)}})]})}function s0(e){let{id:t,label:n,value:l,options:s,disabled:i=!1,onChange:r}=e;return(0,a.jsxs)("label",{className:"qi-edit-field",htmlFor:t,children:[(0,a.jsx)("span",{className:"qi-edit-label",children:n}),(0,a.jsx)("select",{id:t,className:"qi-edit-select",value:l,disabled:i,onChange:e=>{r(e.target.value)},children:s.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]})}function s1(e){let{onCancel:t,saving:n}=e;return(0,a.jsxs)("div",{className:"qi-edit-actions",children:[(0,a.jsx)("button",{type:"submit",className:"qi-btn qi-btn-approve qi-edit-save","aria-disabled":n||void 0,children:"Save"}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-edit-cancel","aria-disabled":n||void 0,onClick:()=>{n||t()},children:"Cancel"})]})}function s2(e){let{candidate:t,onSave:n,onCancel:s}=e,[i,r]=(0,l.useState)(()=>({title:t.title,preconditions:t.preconditions.join("\n"),steps:t.steps.join("\n"),expectedResults:t.expectedResults.join("\n"),priority:t.priority,riskClass:t.riskClass,tags:t.tags.join(", ")})),[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1),[h,p]=(0,l.useState)(!1),m=(0,l.useRef)(null),f=(e,t)=>{c(null),p(!1),r(n=>({...n,[e]:t}))},g=(0,l.useCallback)(()=>{if(!d){if(!(Object.keys(sZ(t,i)).length>0)||h)return void s();p(!0)}},[t,h,s,d,i]);(0,l.useEffect)(()=>{let e=e=>{if("Escape"!==e.key||d)return;let t=m.current;null!==t&&t.contains(document.activeElement)&&g()};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[g,d]),(0,l.useEffect)(()=>{var e,t;null==(t=m.current)||null==(e=t.querySelector("input.qi-edit-input"))||e.focus()},[]);let v="qi-edit-".concat(t.id),x=async()=>{if(!d){u(!0),c(null);try{await n(sZ(t,i))}catch(e){c(sk(e))}finally{u(!1)}}};return(0,a.jsxs)("form",{ref:m,className:"qi-edit-form","aria-label":"Edit ".concat(t.title),"aria-busy":d,onSubmit:e=>{e.preventDefault(),x()},children:[(0,a.jsx)(s$,{id:"".concat(v,"-title"),label:"Title",value:i.title,disabled:d,onChange:e=>{f("title",e)}}),null!==o?(0,a.jsx)("p",{className:"qi-edit-error",role:"alert","aria-live":"assertive",children:o}):null,h?(0,a.jsx)("p",{className:"qi-edit-discard-note",role:"status",children:"Unsaved changes — press Escape or activate Cancel again to discard them."}):null,(0,a.jsx)(s1,{onCancel:g,saving:d}),(0,a.jsx)(sQ,{id:"".concat(v,"-preconditions"),label:"Preconditions (one per line)",value:i.preconditions,disabled:d,onChange:e=>{f("preconditions",e)}}),(0,a.jsx)(sQ,{id:"".concat(v,"-steps"),label:"Steps (one per line)",value:i.steps,disabled:d,onChange:e=>{f("steps",e)}}),(0,a.jsx)(sQ,{id:"".concat(v,"-expected"),label:"Expected results (one per line)",value:i.expectedResults,disabled:d,onChange:e=>{f("expectedResults",e)}}),(0,a.jsx)(s0,{id:"".concat(v,"-priority"),label:"Priority",value:i.priority,options:sJ,disabled:d,onChange:e=>{f("priority",e)}}),(0,a.jsx)(s0,{id:"".concat(v,"-risk"),label:"Risk class",value:i.riskClass,options:sV,disabled:d,onChange:e=>{f("riskClass",e)}}),(0,a.jsx)(s$,{id:"".concat(v,"-tags"),label:"Tags (comma-separated)",value:i.tags,disabled:d,onChange:e=>{f("tags",e)}})]})}let s3={open:"qi-review-open",approved:"qi-review-approved","changes-requested":"qi-review-changes",rejected:"qi-review-rejected",withdrawn:"qi-review-withdrawn"};function s4(e){let{state:t}=e;return(0,a.jsxs)("span",{className:"qi-review-badge ".concat(s3[t]),children:[(0,a.jsx)("span",{className:"sr-only",children:"Review: "}),sj[t]]})}function s6(e){let{items:t,label:n}=e;return 0===t.length?null:(0,a.jsxs)("div",{className:"qi-cand-block",children:[(0,a.jsx)("p",{className:"qi-cand-block-label",children:n}),(0,a.jsx)("ol",{className:"qi-cand-list","aria-label":n,children:t.map((e,t)=>(0,a.jsx)("li",{children:e},"".concat(n,"-").concat(String(t))))})]})}function s5(e){let{className:t,label:n,pressed:l,disabled:s,describedBy:i,onActivate:r}=e;return(0,a.jsx)("button",{type:"button",className:t,...void 0!==l?{"aria-pressed":l}:{},"aria-disabled":s||void 0,"aria-describedby":s?i:void 0,onClick:()=>{s||r()},children:n})}function s8(e){let{candidateId:t,state:n,onReview:l,disabled:s=!1,describedBy:i,pendingReview:r}=e,o=null!=r,c=e=>o&&r.candidateId===t&&r.action===e;return(0,a.jsxs)("div",{className:"qi-cand-actions",role:"group","aria-label":"Review decision",children:[(0,a.jsx)(s5,{className:"qi-btn qi-btn-approve",label:c("approve")?"Saving…":"Approve",pressed:"approved"===n,disabled:s||o,describedBy:i,onActivate:()=>{l(t,"approve")}}),(0,a.jsx)(s5,{className:"qi-btn qi-btn-reject",label:c("reject")?"Saving…":"Reject",pressed:"rejected"===n,disabled:s||o,describedBy:i,onActivate:()=>{l(t,"reject")}}),(0,a.jsx)(s5,{className:"qi-btn qi-btn-secondary",label:c("request-changes")?"Saving…":"Request changes",pressed:"changes-requested"===n,disabled:s||o,describedBy:i,onActivate:()=>{l(t,"request-changes")}})]})}function s9(e){let{candidate:t,onReview:n,onStartEdit:l,actionsDisabled:s=!1,describedBy:i,editButtonRef:r,pendingReview:o}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"qi-cand-header",children:[(0,a.jsx)("h3",{className:"qi-cand-title",children:t.title}),(0,a.jsxs)("div",{className:"qi-cand-badges",children:[(0,a.jsx)("span",{className:"qi-cand-pri",children:t.priority}),(0,a.jsx)("span",{className:"qi-cand-risk",children:t.riskClass}),(0,a.jsx)(s4,{state:t.reviewState})]})]}),void 0!==t.weakTestFlag?(0,a.jsx)(sq,{flag:t.weakTestFlag}):null,(0,a.jsx)(s6,{items:t.preconditions,label:"Preconditions"}),(0,a.jsx)(s6,{items:t.steps,label:"Steps"}),(0,a.jsx)(s6,{items:t.expectedResults,label:"Expected results"}),t.tags.length>0?(0,a.jsx)("ul",{className:"qi-cand-tags","aria-label":"Tags",children:t.tags.map(e=>(0,a.jsx)("li",{className:"qi-cand-tag",children:e},e))}):null,(0,a.jsxs)("div",{className:"qi-cand-actions-row",children:[void 0!==l?(0,a.jsx)("button",{ref:r,type:"button",className:"qi-btn qi-btn-secondary qi-cand-edit","aria-disabled":s||void 0,"aria-describedby":s?i:void 0,onClick:()=>{s||l()},children:"Edit"}):null,void 0!==n?(0,a.jsx)(s8,{candidateId:t.id,state:t.reviewState,onReview:n,disabled:s,describedBy:i,pendingReview:o}):null]})]})}function s7(e){let{candidate:t,onReview:n,onEdit:s,actionsDisabled:i=!1,describedBy:r,pendingReview:o}=e,[c,d]=(0,l.useState)(!1),u=(0,l.useRef)(null),h=(0,l.useRef)(!1);(0,l.useEffect)(()=>{var e;h.current&&!c&&(null==(e=u.current)||e.focus()),h.current=c},[c]);let p=async e=>{void 0!==s&&await s(t.id,e),d(!1)};return(0,a.jsx)("li",{className:c?"qi-cand-card qi-cand-card-editing":"qi-cand-card",children:c&&void 0!==s?(0,a.jsx)(s2,{candidate:t,onSave:p,onCancel:()=>{d(!1)}}):(0,a.jsx)(s9,{candidate:t,onReview:n,actionsDisabled:i,describedBy:r,pendingReview:o,editButtonRef:u,onStartEdit:void 0!==s?()=>{d(!0)}:void 0})})}function ie(e){let{candidates:t,onReview:n,onEdit:s,actionsDisabled:i=!1,actionsDisabledReason:r,pendingReview:o}=e,[c,d]=(0,l.useState)(25),u=(0,l.useId)(),h=i&&void 0!==r;if(0===t.length)return(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"No test cases"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"This run produced no generated test cases."})]});let p=t.slice(0,c);return(0,a.jsxs)("div",{className:"qi-cand-pane",children:[h?(0,a.jsx)("p",{id:u,className:"qi-cand-governance-note",role:"note",children:r}):null,(0,a.jsx)("ul",{className:"qi-cand-cards","aria-label":"Generated test cases",children:p.map(e=>(0,a.jsx)(s7,{candidate:e,onReview:n,onEdit:s,actionsDisabled:i,describedBy:h?u:void 0,pendingReview:o},e.id))}),c<t.length?(0,a.jsxs)("button",{type:"button",className:"qi-btn qi-btn-secondary qi-cand-more",onClick:()=>{d(e=>e+25)},children:["Show more (",(t.length-c).toString()," remaining)"]}):null]})}function it(e){return 0===e?"No drift — every test is current.":"".concat(e.toString()," ").concat(1===e?"test is":"tests are"," stale — source changed since this run.")}function ia(e){let t=e.regeneratedCount,n=e.preservedCount;return"Regenerated ".concat(t.toString()," ").concat(1===t?"test":"tests"," as a new run (").concat(n.toString()," ").concat(1===n?"test":"tests"," preserved).")}function il(e){let{staleCount:t}=e;return 0===t?(0,a.jsxs)("p",{className:"qi-drift-fresh","data-testid":"qi-drift-fresh",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-ok",children:"✓"}),it(0)]}):(0,a.jsxs)("p",{className:"qi-drift-stale","data-testid":"qi-drift-stale",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"qi-drift-icon-warn",children:"⚠"}),it(t)]})}function is(e){let{runId:t,connectedSources:n,onRegenerated:s,reCheckImpl:i=sv,regenerateImpl:r=sx}=e,[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(null),h=null!==d,[p,m]=(0,l.useState)(null),[f,g]=(0,l.useState)(null),v=(0,l.useRef)(null),x=(0,l.useRef)(null),y=(0,l.useCallback)(()=>{h||(async()=>{u("check"),m(null),g(null);try{c(await i(t,n))}catch(e){m(sk(e))}finally{u(null)}})()},[h,i,t,n]),b=(0,l.useCallback)(()=>{h||(async()=>{u("regenerate"),m(null);try{let a=await r(t,n);if(document.activeElement===x.current){var e;null==(e=v.current)||e.focus()}g(a),c(null),null==s||s(a)}catch(e){m(sk(e))}finally{u(null)}})()},[h,r,t,n,s]);return(0,a.jsxs)("section",{className:"qi-drift-panel","aria-label":"Drift detection",children:[(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==f?ia(f):null!==o?it(o.staleCount):""}),(0,a.jsxs)("div",{className:"qi-drift-head",children:[(0,a.jsx)("h3",{className:"qi-col-subtitle",children:"Living tests"}),(0,a.jsx)("button",{type:"button",ref:v,className:"qi-btn qi-btn-secondary",onClick:y,"aria-disabled":h||void 0,"data-testid":"qi-drift-recheck",children:"check"===d?"Checking…":"Re-check drift"})]}),null!==p?(0,a.jsx)("p",{className:"lk-alert",role:"alert",children:p}):null,null!==o?(0,a.jsx)(il,{staleCount:o.staleCount}):null,null!==o&&o.staleCount>0&&null===f?(0,a.jsx)("button",{type:"button",ref:x,className:"qi-btn qi-btn-approve",onClick:b,"aria-disabled":h||void 0,"data-testid":"qi-drift-regenerate",children:"regenerate"===d?"Regenerating…":"Regenerate ".concat(o.staleCount.toString()," stale ").concat(1===o.staleCount?"test":"tests")}):null,null!==f?(0,a.jsx)("p",{className:"qi-drift-regenerated","data-testid":"qi-drift-regenerated",children:ia(f)}):null]})}let ii={"traceability-csv":"csv","traceability-markdown":"markdown"},ir=[{id:"csv",label:"CSV",tms:!1},{id:"json",label:"JSON",tms:!1},{id:"spreadsheet-safe-csv",label:"Spreadsheet-safe CSV",tms:!1},{id:"markdown",label:"Markdown",tms:!1},{id:"plain-text",label:"Plain text",tms:!1},{id:"pdf",label:"PDF",tms:!1},{id:"zip-bundle",label:"ZIP bundle (all formats)",tms:!1},{id:"traceability-csv",label:"Traceability matrix (CSV)",tms:!1},{id:"traceability-markdown",label:"Traceability matrix (Markdown)",tms:!1},{id:"jira-issues",label:"Jira (preview)",tms:!0},{id:"qtest",label:"qTest (preview)",tms:!0},{id:"xray",label:"Xray (preview)",tms:!0},{id:"polarion",label:"Polarion (preview)",tms:!0},{id:"quality-center",label:"Quality Center (preview)",tms:!0}];function io(e,t,n,a){let l=new Blob(["base64"===a?function(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}(n):n],{type:t}),s=URL.createObjectURL(l),i=document.createElement("a");i.href=s,i.download=e,document.body.appendChild(i),i.click(),i.remove(),window.setTimeout(()=>{URL.revokeObjectURL(s)},250)}function ic(e){var t;let{runId:n,exportImpl:s=sy,traceabilityImpl:i=sb}=e,[r,o]=(0,l.useState)("csv"),[c,d]=(0,l.useState)(!1),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(null),[f,g]=(0,l.useState)(null),v=ir.find(e=>e.id===r),x=null!=(t=null==v?void 0:v.tms)&&t,y=(0,l.useCallback)(async()=>{let e=ii[r];if(void 0!==e){let t=await i(n,e);io(t.filename,t.contentType,t.body),g(t.filename);return}let t=await s(n,r,{dryRun:x,approvedOnly:!1});t.dryRun?m("".concat(t.candidateCount.toString()," test case").concat(1===t.candidateCount?"":"s"," \xb7 ").concat(t.byteLen.toString()," bytes\n\n").concat(t.preview)):(io(t.filename,t.contentType,t.body,t.encoding),g(t.filename))},[n,r,x,s,i]),b=(0,l.useCallback)(async()=>{d(!0),h(null),m(null),g(null);try{await y()}catch(e){h(sk(e))}finally{d(!1)}},[y]);return(0,a.jsxs)("div",{className:"qi-export","data-testid":"qi-export-bar",children:[(0,a.jsxs)("label",{className:"qi-field qi-field-inline",children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Export"}),(0,a.jsx)("select",{className:"qi-select",value:r,disabled:c,onChange:e=>{o(e.target.value),m(null),h(null),g(null)},children:ir.map(e=>(0,a.jsx)("option",{value:e.id,children:e.label},e.id))})]}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary",disabled:c,onClick:()=>{b()},children:c?"Exporting…":x?"Preview":"Download"}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:null!==f?"Downloaded ".concat(f):null!==p?"Export preview ready below.":""}),x?(0,a.jsx)("p",{className:"qi-export-hint",role:"note","data-testid":"qi-export-connector-hint",children:(null==v?void 0:v.id)==="quality-center"?"Quality Center is preview-only. Configure a connector to enable live export.":"External target — preview only. Configure a connector to enable live export."}):null,null!==f?(0,a.jsx)("p",{className:"qi-export-success","data-testid":"qi-export-success",children:"Downloaded ".concat(f)}):null,null!==p?(0,a.jsx)("pre",{className:"qi-export-preview",role:"region","aria-label":"Export preview",tabIndex:0,"data-testid":"qi-export-preview",children:p}):null,null!==u?(0,a.jsx)("p",{className:"lk-alert",role:"alert","data-testid":"qi-export-error",children:u}):null]})}let id="keiko.qi.reviewerLabel",iu="Set a reviewer label to review or edit candidates.";function ih(e){let{detail:t}=e;return(0,a.jsxs)("dl",{className:"qi-run-summary","aria-label":"Run summary",children:[(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Status"}),(0,a.jsx)("dd",{children:(0,a.jsx)(sE,{status:t.status})})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Test cases"}),(0,a.jsx)("dd",{children:t.totals.candidates.toString()})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Findings"}),(0,a.jsx)("dd",{children:t.totals.findings.toString()})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Quality"}),(0,a.jsx)("dd",{children:(0,a.jsx)(sF,{score:t.qualityScore})})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Review"}),(0,a.jsx)("dd",{className:"qi-run-summary-review",children:sj[t.reviewState]})]}),(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Requested"}),(0,a.jsx)("dd",{children:sN(t.requestedAt)})]}),null!==t.completedAt?(0,a.jsxs)("div",{className:"qi-run-summary-item",children:[(0,a.jsx)("dt",{children:"Completed"}),(0,a.jsx)("dd",{children:sN(t.completedAt)})]}):null]})}let ip={"logic-defect":"Logic defect","faithfulness-defect":"Faithfulness defect","semantic-defect":"Semantic defect","mutation-defect":"Mutation defect","policy-violation":"Policy violation","manual-rejection":"Manual rejection","coverage-gap":"Coverage gap","test-quality":"Test quality"};function im(e){let{detail:t}=e;return 0===t.findingRefs.length?null:(0,a.jsxs)("section",{className:"qi-run-findings","aria-label":"Findings",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Findings",(0,a.jsx)("span",{className:"qi-col-count",children:t.findingRefs.length.toString()})]}),(0,a.jsx)("ul",{className:"qi-finding-list","aria-label":"Findings list",children:t.findingRefs.map(e=>{var t;return(0,a.jsxs)("li",{className:"qi-finding-item",children:[(0,a.jsxs)("div",{className:"qi-finding-header",children:[(0,a.jsx)("span",{className:"qi-finding-kind",children:null!=(t=ip[e.kind])?t:e.kind}),(0,a.jsx)(sT,{severity:e.severity})]}),(0,a.jsx)("p",{className:"qi-finding-summary",children:e.summaryRedacted})]},e.id)})})]})}let ig={covered:"Covered","weakly-covered":"Weakly covered",uncovered:"Uncovered"},iv={covered:"qi-cov-covered","weakly-covered":"qi-cov-weak",uncovered:"qi-cov-uncovered"};function ix(e){let{detail:t}=e;if(0===t.coverageByAtom.length)return null;let n=t.coverageByAtom.length,l=t.coverageByAtom.filter(e=>"covered"===e.status).length,s=t.coverageByAtom.filter(e=>"covered"!==e.status);return(0,a.jsxs)("section",{className:"qi-coverage-panel","aria-label":"Coverage",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Coverage",(0,a.jsxs)("span",{className:"qi-badge qi-badge-default","aria-label":"Coverage: ".concat(t.coveragePercentage.toFixed(0)," percent, ").concat(l.toString()," of ").concat(n.toString()," requirements covered"),"data-testid":"qi-coverage-pct",children:[t.coveragePercentage.toFixed(0),"%"]})]}),(0,a.jsx)("p",{className:"qi-coverage-summary","data-testid":"qi-coverage-summary",children:"".concat(l.toString()," of ").concat(n.toString()," requirements covered \xb7 ").concat(s.length.toString()," gap").concat(1===s.length?"":"s")}),s.length>0?(0,a.jsxs)("section",{className:"qi-coverage-gaps","aria-label":"Gap radar",children:[(0,a.jsx)("h4",{className:"qi-col-subtitle",children:"Gap radar (".concat(s.length.toString(),")")}),(0,a.jsx)("ul",{className:"qi-coverage-gap-list","aria-label":"Uncovered and weakly covered atoms",children:s.map(e=>{let t=ig[e.status],n=iv[e.status],l=e.requirementExcerptRedacted;return(0,a.jsxs)("li",{className:"qi-coverage-gap-item","aria-label":void 0===l?"Atom ".concat(e.atomId,": ").concat(t):'Requirement "'.concat(l,'" (atom ').concat(e.atomId,"): ").concat(t),children:[(0,a.jsxs)("span",{className:"qi-coverage-gap-req",children:[void 0===l?null:(0,a.jsx)("span",{className:"qi-coverage-gap-text","data-testid":"qi-coverage-gap-text",children:l}),(0,a.jsx)("span",{className:"qi-coverage-atom-id qi-monospace",children:e.atomId})]}),(0,a.jsx)("span",{className:"qi-badge ".concat(n),"aria-hidden":"true",children:t}),(0,a.jsx)("span",{className:"qi-sr-only",children:t})]},e.atomId)})})]}):null]})}function iy(e){let{detail:t}=e;return t.drift.reCheckSupported?(0,a.jsxs)("section",{className:"qi-drift-panel","aria-label":"Drift detection",children:[(0,a.jsxs)("div",{className:"qi-drift-head",children:[(0,a.jsx)("h3",{className:"qi-col-subtitle",children:"Living tests"}),(0,a.jsx)("button",{type:"button",className:"qi-btn qi-btn-secondary",disabled:!0,"data-testid":"qi-drift-recheck-unavailable",children:"Re-check drift"})]}),(0,a.jsx)("p",{className:"qi-drift-note","data-testid":"qi-drift-unavailable",children:"Drift fingerprints are recorded for this run, but this card has no current source handle. Reopen it from the connected source or start a new run from the current source."})]}):null}function ib(e){let{runId:t,connectedSources:n,onRegenerated:s,fetchDetailImpl:i=sh,reviewImpl:r=sf,editImpl:o=sg,reCheckImpl:c,regenerateImpl:d}=e,[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!0),[f,g]=(0,l.useState)(null),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(null),[j,w]=(0,l.useState)(""),[k,N]=(0,l.useState)(!1),S=(0,l.useId)(),C=(0,l.useId)(),R=(0,l.useRef)(0),E=(0,l.useCallback)(async()=>{let e=R.current+1;R.current=e,m(!0),g(null);try{let n=await i(t);R.current===e&&h(n)}catch(t){R.current===e&&g(sk(t))}finally{R.current===e&&m(!1)}},[i,t]);(0,l.useEffect)(()=>{E()},[E]),(0,l.useEffect)(()=>{w(function(){try{var e;return null!=(e=window.localStorage.getItem(id))?e:""}catch(e){return""}}()),N(!0)},[]),(0,l.useEffect)(()=>{if(k)try{window.localStorage.setItem(id,j)}catch(e){}},[j,k]);let I=j.trim(),T=I.length>0,F=(0,l.useCallback)((e,n)=>{T&&null===y&&(b({candidateId:e,action:n}),(async()=>{x(null);try{await r(t,n,e,I),await E()}catch(e){x(sk(e))}finally{b(null)}})())},[T,y,r,t,I,E]),q=(0,l.useCallback)(async(e,n)=>{if(!T)throw Error(iu);await o(t,e,n,I),await E()},[o,T,t,I,E]);return(0,a.jsxs)("div",{className:"qi-run-card","data-testid":"qi-run-card",children:[(0,a.jsx)("header",{className:"qi-run-card-head",children:(0,a.jsx)("span",{className:"qi-run-id qi-monospace",title:t,children:t})}),(0,a.jsx)("p",{className:"sr-only",role:"status","aria-live":"polite",children:p?"Loading run…":null===f&&null!==u?"Run loaded: ".concat(u.totals.candidates.toString()," test case").concat(1===u.totals.candidates?"":"s","."):""}),(0,a.jsx)("div",{className:"qi-run-card-body","aria-busy":p,children:p&&null===u?(0,a.jsx)(sM,{}):null!==f?(0,a.jsx)(sP,{message:f,onRetry:()=>void E()}):null===u?(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"Run not found."})}):(0,a.jsxs)(a.Fragment,{children:[null!==v?(0,a.jsxs)("div",{className:"lk-alert qi-action-error",role:"alert","data-testid":"qi-action-error",children:[v,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>{x(null)},children:"Dismiss"})]}):null,(0,a.jsxs)("section",{className:"qi-run-governance","aria-label":"Review governance",children:[(0,a.jsxs)("label",{className:"qi-field",htmlFor:"qi-reviewer-label-".concat(t),children:[(0,a.jsx)("span",{className:"qi-field-label",children:"Reviewer label"}),(0,a.jsx)("input",{id:"qi-reviewer-label-".concat(t),className:"qi-input qi-run-governance-input",value:j,placeholder:"Required for review and edit actions","aria-invalid":!T,"aria-describedby":T?S:"".concat(S," ").concat(C),onChange:e=>{w(e.target.value)}})]}),(0,a.jsx)("p",{id:S,className:"qi-run-governance-help",children:"Used for QI review and edit audit entries."}),T?null:(0,a.jsx)("p",{id:C,className:"qi-run-governance-warning",role:"note",children:iu})]}),(0,a.jsx)(ih,{detail:u}),(0,a.jsx)(im,{detail:u}),(0,a.jsx)(ix,{detail:u}),void 0!==n&&n.length>0?(0,a.jsx)(is,{runId:t,connectedSources:n,onRegenerated:s,reCheckImpl:c,regenerateImpl:d}):(0,a.jsx)(iy,{detail:u}),(0,a.jsxs)("section",{className:"qi-run-cases","aria-label":"Generated test cases",children:[(0,a.jsxs)("div",{className:"qi-run-cases-head",children:[(0,a.jsxs)("h3",{className:"qi-col-subtitle",children:["Test cases",(0,a.jsx)("span",{className:"qi-col-count",children:u.candidates.length.toString()})]}),u.candidates.length>0?(0,a.jsx)(ic,{runId:t}):null]}),(0,a.jsx)(ie,{candidates:u.candidates,onReview:F,pendingReview:y,onEdit:q,actionsDisabled:!T,actionsDisabledReason:iu})]})]})})]})}let ij={inactive:{label:"Inactive",ariaDescription:"No recent activity for this relationship.",iconShape:"hollow-circle",textColor:"var(--fg-muted)",bgColor:"var(--inset)",animated:!1},queued:{label:"Queued",ariaDescription:"A workflow run referencing this relationship is queued.",iconShape:"clock",textColor:"var(--fg-muted)",bgColor:"var(--inset)",animated:!1},active:{label:"Active",ariaDescription:"A model call referencing this relationship is in progress.",iconShape:"filled-circle",textColor:"var(--accent)",bgColor:"var(--accent-dim)",borderColor:"var(--accent-line)",animated:!1},processing:{label:"Processing",ariaDescription:"A tool or command referencing this relationship is executing.",iconShape:"spinning-circle",textColor:"var(--accent)",bgColor:"var(--accent-dim)",borderColor:"var(--accent-line)",animated:!0},completed:{label:"Completed",ariaDescription:"The most recent run referencing this relationship completed successfully.",iconShape:"check",textColor:"var(--accent)",bgColor:"var(--accent-dim)",animated:!1},failed:{label:"Failed",ariaDescription:"The most recent run referencing this relationship failed.",iconShape:"triangle-exclamation",textColor:"var(--danger)",bgColor:"color-mix(in oklch, var(--danger) 12%, var(--card))",animated:!1},blocked:{label:"Blocked",ariaDescription:"The validator denied a recent proposal referencing this relationship; see the inspector for the reason.",iconShape:"filled-square",textColor:"var(--warn)",bgColor:"color-mix(in oklch, var(--warn) 12%, var(--card))",animated:!1},degraded:{label:"Degraded",ariaDescription:"The health check flagged at least one endpoint of this relationship as not currently live.",iconShape:"broken-line",textColor:"var(--warn)",bgColor:"color-mix(in oklch, var(--warn) 8%, var(--card))",animated:!1},"high-throughput":{label:"High throughput",ariaDescription:"More than fifty events referenced this relationship in the last sixty seconds.",iconShape:"stacked-lines",textColor:"var(--accent)",bgColor:"var(--accent-dim)",animated:!1}};function iw(e){let{shape:t,color:n,animated:l,highContrast:s}=e,i=["rb-edge-badge-icon",l?"rb-edge-badge-icon--processing":"",s?"rb-edge-badge-icon--high-contrast":""].filter(e=>e.length>0).join(" "),r=s?2:1.5,o={width:12,height:12,viewBox:"0 0 12 12","aria-hidden":!0,fill:"currentColor",className:i,style:{color:n}};switch(t){case"hollow-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r})});case"clock":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r}),(0,a.jsx)("path",{d:"M6 3v3l2 1",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",fill:"none"})]});case"filled-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"5"})});case"spinning-circle":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("circle",{cx:"6",cy:"6",r:"4.5",fill:"none",stroke:"currentColor",strokeWidth:r,strokeDasharray:"8 4"})});case"check":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("path",{d:"M2 6l3 3 5-5",stroke:"currentColor",strokeWidth:s?2.2:1.8,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"triangle-exclamation":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("path",{d:"M6 1 L11 10 L1 10 Z",fill:"currentColor"}),(0,a.jsx)("path",{d:"M6 5v2.5",stroke:"var(--card)",strokeWidth:r,strokeLinecap:"round",fill:"none"}),(0,a.jsx)("circle",{cx:"6",cy:"9",r:"0.7",fill:"var(--card)"})]});case"filled-square":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("rect",{x:"1.5",y:"1.5",width:"9",height:"9",rx:"1.5"})});case"broken-line":return(0,a.jsx)("svg",{...o,children:(0,a.jsx)("path",{d:"M1 6h2.5l1.5-2 2 4 1.5-2H11",stroke:"currentColor",strokeWidth:r,strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"stacked-lines":return(0,a.jsxs)("svg",{...o,children:[(0,a.jsx)("rect",{x:"2",y:"2.5",width:"8",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"2",y:"5.25",width:"8",height:"1.5",rx:"0.75"}),(0,a.jsx)("rect",{x:"2",y:"8",width:"8",height:"1.5",rx:"0.75"})]})}}function ik(e){let{state:t}=e,n={width:10,height:10,viewBox:"0 0 10 10","aria-hidden":!0,fill:"currentColor"};switch(t){case"draft":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("circle",{cx:"5",cy:"5",r:"4",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})});case"active":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("circle",{cx:"5",cy:"5",r:"4.5"})});case"archived":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"})});case"superseded":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("path",{d:"M2 5h6M6 3l2 2-2 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})});case"revoked":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("path",{d:"M2 2l6 6M8 2L2 8",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",fill:"none"})});case"blocked":return(0,a.jsxs)("svg",{...n,children:[(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1"}),(0,a.jsx)("path",{d:"M5 3v3",stroke:"var(--card)",strokeWidth:"1.5",strokeLinecap:"round",fill:"none"}),(0,a.jsx)("circle",{cx:"5",cy:"7.5",r:"0.6",fill:"var(--card)"})]});case"stale":return(0,a.jsx)("svg",{...n,children:(0,a.jsx)("rect",{x:"1",y:"1",width:"8",height:"8",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})})}}function iN(e){var t;let{type:n,lifecycle:s,activity:i,throughputCount:r,animateOverride:o=!0,highContrast:c,onClick:d,className:u=""}=e,[h,p]=(0,l.useState)(!1);(0,l.useEffect)(()=>{if(void 0!==c)return;let e=window.matchMedia("(prefers-contrast: more)"),t=e=>{p(e)};t(e.matches);let n=e=>{t(e.matches)};return e.addEventListener("change",n),()=>{e.removeEventListener("change",n)}},[c]);let m=null!=(t=ij[i])?t:ij.inactive,f=ah[n],g=null!=c?c:h,v="high-throughput"===i&&void 0!==r?"".concat(m.label," (").concat(String(r),")"):m.label,x="".concat(f.displayName," — ").concat(m.ariaDescription),y=m.animated&&o,b=g?{color:m.textColor,background:"var(--card)",border:"1px solid ".concat(m.textColor)}:{color:m.textColor,background:m.bgColor,border:void 0!==m.borderColor?"1px solid ".concat(m.borderColor):void 0};return(0,a.jsx)("span",{role:"status","aria-live":"polite","aria-atomic":"true",className:"rb-edge-badge ".concat(u).trim(),"data-activity-state":i,"data-high-contrast":g?"true":void 0,children:void 0!==d?(0,a.jsxs)("button",{type:"button",className:"rb-edge-badge-btn",style:b,"aria-label":x,onClick:d,children:[(0,a.jsx)("span",{"aria-hidden":"true",children:(0,a.jsx)(iw,{shape:m.iconShape,color:m.textColor,animated:y,highContrast:g})}),(0,a.jsx)("span",{className:"visually-hidden",children:m.ariaDescription}),(0,a.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,a.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,a.jsx)(ik,{state:s})]}):(0,a.jsxs)("span",{className:"rb-edge-badge-static",style:b,"aria-label":x,children:[(0,a.jsx)("span",{"aria-hidden":"true",children:(0,a.jsx)(iw,{shape:m.iconShape,color:m.textColor,animated:y,highContrast:g})}),(0,a.jsx)("span",{className:"visually-hidden",children:m.ariaDescription}),(0,a.jsx)("span",{"aria-hidden":"true",className:"rb-edge-badge-label",children:v}),(0,a.jsx)("span",{className:"rb-edge-badge-type",children:f.displayName}),(0,a.jsx)(ik,{state:s})]})})}let iS="keiko.relationships.density",iC={minimal:5,standard:25,dense:512};function iR(){try{let e=window.localStorage.getItem(iS);if("minimal"===e||"standard"===e||"dense"===e)return e}catch(e){}return"minimal"}function iE(e,t){return void 0===e||0===e.length?[]:e.split(",").map(e=>e.trim()).filter(e=>t.includes(e))}function iI(e){return{types:iE(e.relType,ad),lifecycles:iE(e.relLifecycle,au),activities:iE(e.relActivity,["inactive","queued","active","processing","completed","failed","blocked","degraded","high-throughput"]),srcKinds:iE(e.relSrcKind,ao),tgtKinds:iE(e.relTgtKind,ao)}}let iT={"high-throughput":0,processing:1,active:2,blocked:3,failed:4,degraded:5,queued:6,completed:7,inactive:8};function iF(e,t,n){var a;return null!=(a=n.get(e))?a:function(e){switch(e){case"blocked":return"blocked";case"stale":return"degraded";default:return"inactive"}}(t)}function iq(e){var t,n,s,i,r,o,c;let{filters:d,selectedId:u,onSelect:h,onFilterChange:p,activityMap:m=new Map,throughputMap:f=new Map,animateBadges:g=!0,highContrast:v=!1}=e,[x,y]=(0,l.useState)(()=>{let e=d.relDensity;return"minimal"===e||"standard"===e||"dense"===e?e:iR()}),[b,j]=(0,l.useState)(!1),[w,k]=(0,l.useState)([]),[N,S]=(0,l.useState)(!1),[C,R]=(0,l.useState)(null),[E,I]=(0,l.useState)(!1),T=(0,l.useRef)(null),F=(0,l.useRef)(null),[q,A]=(0,l.useState)(null!=(t=d.relType)?t:""),M=(0,l.useRef)(null),P=(0,l.useCallback)(e=>{y(e),p({relDensity:e});try{window.localStorage.setItem(iS,e)}catch(e){}},[p]);(0,l.useEffect)(()=>{let e=d.relDensity;if("minimal"===e||"standard"===e||"dense"===e)return void y(e);y(iR())},[d.relDensity]),(0,l.useEffect)(()=>{var e;A(null!=(e=d.relType)?e:"")},[d.relType]);let D=(0,l.useCallback)(async()=>{R(null),S(!0);try{let e=iI(d),t=1===e.lifecycles.length?e.lifecycles[0]:"active",n=1===e.types.length?e.types[0]:void 0,a=1===e.srcKinds.length?e.srcKinds[0]:void 0,l=1===e.tgtKinds.length?e.tgtKinds[0]:void 0,s=await ab({lifecycle:t,type:n,sourceKind:a,targetKind:l,limit:iC[x]});k(s.entries),I(s.truncated)}catch(e){R(e instanceof af?e.message:am)}finally{S(!1)}},[d,x]);(0,l.useEffect)(()=>{D()},[D]),(0,l.useEffect)(()=>{let e=T.current;if(null!==e)return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t);function t(e){if("undefined"!=typeof document&&null!==document.querySelector('[role="dialog"][aria-modal="true"]'))return;let t=e.target;if(!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLElement&&t.isContentEditable)){if("f"===e.key||"F"===e.key)e.preventDefault(),j(e=>!e);else if("Escape"===e.key)j(!1);else if("/"===e.key){var n;e.preventDefault(),null==(n=F.current)||n.focus()}}}},[]);let L=(0,l.useCallback)(e=>{let t=e.target.value;A(t),null!==M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{p({relType:t.length>0?t:void 0})},250)},[p]),z=(0,l.useMemo)(()=>{var e;let t=iI(d),n=(null!=(e=d.relType)?e:"").split(",").map(e=>e.trim().toLowerCase()).filter(e=>e.length>0),a=0===n.length?w:w.filter(e=>n.some(t=>e.type.toLowerCase().includes(t)));return(0===t.activities.length?a:a.filter(e=>t.activities.includes(iF(e.id,e.lifecycle,m)))).slice(0,iC[x])},[m,x,d,w]),O=z.slice(0,25),K=z.slice(25),B=K.length,W=B>0?function(e,t){let n=new Map;for(let l of e){var a;let e=iF(l.id,l.lifecycle,t);n.set(e,(null!=(a=n.get(e))?a:0)+1)}return Array.from(n.entries()).sort((e,t)=>{var n,a;return t[1]!==e[1]?t[1]-e[1]:(null!=(n=iT[e[0]])?n:Number.MAX_SAFE_INTEGER)-(null!=(a=iT[t[0]])?a:Number.MAX_SAFE_INTEGER)}).map(e=>{let[t,n]=e,a=1===n?"relationship":"relationships";return"high-throughput"===t?"".concat(n," high-throughput ").concat(a):"".concat(n," ").concat(t," ").concat(a)}).join(", ")}(K,m):"",U=E?"Showing first ".concat(String(z.length)," relationships — more available."):"Showing ".concat(String(z.length)," relationship").concat(1!==z.length?"s":"","."),_=(null!=(n=d.relType)?n:"").trim().length>0||(null!=(s=d.relActivity)?s:"").trim().length>0||(null!=(i=d.relSrcKind)?i:"").trim().length>0||(null!=(r=d.relTgtKind)?r:"").trim().length>0||(null!=(o=d.relLifecycle)?o:"").trim().length>0&&"active"!==d.relLifecycle,H=iE(d.relLifecycle,au),G=1===H.length&&null!=(c=H[0])?c:"active";return(0,a.jsxs)("div",{ref:T,className:"tw-pad","data-testid":"relationship-list-panel","data-relationship-focus":b?"true":void 0,children:[(0,a.jsxs)("div",{role:"group","aria-label":"Relationship density",style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:8},children:[["minimal","standard","dense"].map(e=>(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":x===e,onClick:()=>P(e),style:{textTransform:"capitalize",minWidth:24,minHeight:24},children:e},e)),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-pressed":b,onClick:()=>j(e=>!e),title:"Toggle focus mode (F)","aria-label":"Focus mode: ".concat(b?"on":"off"),style:{minWidth:24,minHeight:24},children:"Focus"})]}),(0,a.jsxs)("div",{style:{marginBottom:8},children:[(0,a.jsx)("label",{htmlFor:"rel-type-filter",className:"rb-row-k",style:{display:"block",marginBottom:2,fontSize:11,fontWeight:600},children:"Filter by type (press / to focus)"}),(0,a.jsx)("input",{id:"rel-type-filter",ref:F,type:"text",list:"rel-type-filter-options",value:q,onChange:L,placeholder:"e.g. reads-context","aria-label":"Filter relationships by type",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:9,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:13}}),(0,a.jsx)("datalist",{id:"rel-type-filter-options",children:ad.map(e=>(0,a.jsx)("option",{value:e},e))})]}),(0,a.jsxs)("div",{style:{marginBottom:8},children:[(0,a.jsx)("label",{htmlFor:"rel-lifecycle-filter",className:"rb-row-k",style:{display:"block",marginBottom:2,fontSize:11,fontWeight:600},children:"Lifecycle"}),(0,a.jsx)("select",{id:"rel-lifecycle-filter",value:G,onChange:e=>p({relLifecycle:e.target.value}),"aria-label":"Filter relationships by lifecycle",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:9,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:13},children:au.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsx)("div",{"aria-live":"polite","aria-atomic":"true",className:"visually-hidden",children:U}),E&&(0,a.jsx)("div",{"data-testid":"list-truncation-note",style:{fontSize:11,color:"var(--fg-muted)",marginBottom:6},children:U}),null!==C&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:C}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void D(),children:"Retry"})]}),N&&0===w.length&&(0,a.jsx)("div",{role:"status",className:"insp-empty",children:"Loading…"}),(!N||w.length>0)&&null===C&&0===z.length&&(0,a.jsx)("div",{className:"insp-empty","data-testid":"list-empty",children:_?"No relationships match the current filter.":'No active relationships yet. Create one with "+ New relationship", or connect a source — connections appear here automatically.'}),z.length>0&&(0,a.jsxs)("div",{role:"list","aria-label":"Relationships","aria-busy":N||void 0,style:{display:"flex",flexDirection:"column",gap:2,opacity:N?.6:1,transition:"opacity 0.15s ease"},children:[O.map(e=>{var t;let n=e.id===u,l=iF(e.id,e.lifecycle,m),s=b&&n,i=b&&!n;return(0,a.jsx)("div",{role:"listitem",style:{opacity:i?.4:1},children:(0,a.jsxs)("button",{type:"button","aria-pressed":n,"aria-label":"".concat(e.type," relationship from ").concat(e.source.kind," ").concat(e.source.id," to ").concat(e.target.kind," ").concat(e.target.id,", lifecycle: ").concat(e.lifecycle),title:"".concat(e.source.id," → ").concat(e.target.id),onClick:()=>h(e.id),onKeyDown:t=>{var n;return n=e.id,void(("Enter"===t.key||" "===t.key)&&(t.preventDefault(),h(n)))},"data-incident":s?"true":void 0,className:"rel-row",children:[(0,a.jsx)(iN,{type:e.type,lifecycle:e.lifecycle,activity:l,throughputCount:f.get(e.id),animateOverride:g,highContrast:v}),(0,a.jsxs)("span",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column"},children:[(0,a.jsxs)("span",{style:{fontSize:12,color:"var(--fg)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[e.source.kind," → ",e.target.kind]}),(0,a.jsx)("span",{style:{fontSize:10.5,color:"var(--fg-muted)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:null!=(t=e.summary)?t:"".concat(e.source.id," → ").concat(e.target.id)})]}),(0,a.jsx)("span",{style:{fontSize:11,color:"var(--fg-muted)",whiteSpace:"nowrap"},children:e.lifecycle})]})},e.id)}),B>0&&(0,a.jsxs)("div",{role:"listitem","aria-live":"polite",style:{fontSize:12,color:"var(--fg-muted)",padding:"4px 6px"},"data-testid":"animation-cap-aggregate",children:["+",String(B)," more: ",W]})]})]})}function iA(){return(0,a.jsx)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)",borderLeft:"2px solid var(--warn)",paddingLeft:8},children:"The walk hit a bound before the graph was fully traversed; more objects may be affected than shown."})}function iM(e){let{title:t,help:n,report:l,onSelectRelationship:s}=e;if(null===l)return(0,a.jsxs)("section",{style:{marginBottom:12},children:[(0,a.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:t}),(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"Loading…"})]});let i=l.endpoints.slice(1),r=l.relationships,o=i.slice(0,50),c=r.slice(0,50);return(0,a.jsxs)("section",{style:{marginBottom:12},"aria-label":t,children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":4,children:[t,(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:i.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:n}),0===i.length?(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:0},children:"No further objects are affected in this direction."}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:o.map(e=>(0,a.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,a.jsx)("span",{className:"mono",children:"".concat(e.kind,": ").concat(e.id)})},"".concat(e.kind,":").concat(e.id)))}),i.length>o.length&&(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)"},children:["Showing the first ",String(50)," of ",String(i.length)," ","objects."]}),r.length>0&&(0,a.jsxs)("details",{style:{marginTop:6},children:[(0,a.jsxs)("summary",{style:{fontSize:11,color:"var(--fg-muted)",cursor:"pointer"},children:[String(r.length)," relationship",1===r.length?"":"s"," on the path"]}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:"4px 0 0",padding:0},children:c.map(e=>(0,a.jsx)("li",{style:{marginBottom:2},children:(0,a.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>s(e.id),"aria-label":"Inspect ".concat(e.type," relationship from ").concat(e.source.kind," ").concat(e.source.id," to ").concat(e.target.kind," ").concat(e.target.id),style:{display:"flex",width:"100%",gap:6,alignItems:"center",textAlign:"left",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",children:e.type}),(0,a.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[e.source.id," → ",e.target.id]})]})},e.id))})]})]}),l.truncated&&(0,a.jsx)(iA,{})]})}function iP(e){let{outgoing:t,incoming:n,onSelectRelationship:l}=e;return(0,a.jsxs)("div",{style:{marginTop:8,padding:"8px 10px",border:"1px solid var(--line)",borderRadius:8,background:"var(--inset)"},"aria-label":"Bounded impact analysis",children:[(0,a.jsx)(iM,{title:"Downstream impact",help:"Objects this relationship's target leads to. Deleting or revoking here may affect them.",report:t,onSelectRelationship:l}),(0,a.jsx)(iM,{title:"Upstream impact",help:"Objects that depend on this relationship's source.",report:n,onSelectRelationship:l})]})}let iD={draft:{bg:"var(--inset)",fg:"var(--fg-muted)"},active:{bg:"var(--accent-dim)",fg:"var(--accent)"},archived:{bg:"var(--inset)",fg:"var(--fg-dim)"},superseded:{bg:"var(--inset)",fg:"var(--fg-dim)"},revoked:{bg:"color-mix(in oklch, var(--danger) 14%, var(--card))",fg:"var(--danger)"},blocked:{bg:"color-mix(in oklch, var(--warn) 12%, var(--card))",fg:"var(--warn)"},stale:{bg:"var(--inset)",fg:"var(--fg-faint)"}},iL={draft:"Proposed but not yet validated or awaiting an upstream gate.",active:"Validated and committed. Both endpoints are currently live.",archived:"Preserved for audit but no longer participates in queries by default.",superseded:"Replaced by a newer relationship of the same type.",revoked:"Rejected after proposal or retracted after acceptance. Terminal state.",blocked:"Cannot transition to active because the validator returned a denial reason.",stale:"At least one endpoint is tombstoned, retired, or unavailable."};function iz(e){let{lines:t=3}=e;return(0,a.jsx)("div",{className:"rb-rows","aria-hidden":"true",children:Array.from({length:t},(e,t)=>(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",style:{background:"var(--inset)",borderRadius:3,width:"40%",display:"block",height:12}}),(0,a.jsx)("span",{className:"rb-row-v",style:{background:"var(--inset)",borderRadius:3,width:"55%",display:"block",height:12}})]},t))})}function iO(e){let{children:t,style:n}=e;return(0,a.jsx)("div",{className:"rb-section-label",role:"heading","aria-level":3,style:n,children:t})}function iK(e){let{rel:t}=e,n=ah[t.type],l="".concat(t.source.kind," ").concat(t.type," ").concat(t.target.kind);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"insp-top",children:[(0,a.jsx)("span",{className:"chip",style:{fontSize:11},children:t.type}),(0,a.jsx)("span",{className:"insp-title",children:l})]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Semantics"}),(0,a.jsx)("span",{className:"rb-row-v",children:n.semantics})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Cardinality"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n.cardinality})]})]})]})}function iB(e){let{label:t,kind:n,id:l}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(iO,{children:[t," endpoint"]}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Kind"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:n})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Reference"}),(0,a.jsx)("span",{className:"rb-row-v mono","aria-label":"Reference id: ".concat(l),children:l})]})]})]})}function iW(e){var t;let{lifecycle:n}=e,l="lifecycle-desc-".concat(n),s=null!=(t=iD[n])?t:iD.draft;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{children:"Lifecycle status"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"State"}),(0,a.jsx)("span",{className:"rb-row-v",children:(0,a.jsx)("span",{className:"chip",style:{background:s.bg,color:s.fg},"aria-describedby":l,children:n})})]}),(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("span",{id:l,className:"rb-row-v",style:{color:"var(--fg-muted)",fontSize:12},children:iL[n]})})]})]})}function iU(e){let{type:t,lifecycle:n,activity:l,throughputCount:s,animateBadges:i,highContrast:r,transitions:o,densityMode:c}=e,d=o.slice(0,"minimal"===c?3:5);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{children:"Activity"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Current state"}),(0,a.jsx)("span",{className:"rb-row-v",children:(0,a.jsx)(iN,{type:t,lifecycle:n,activity:l,throughputCount:s,animateOverride:i,highContrast:r})})]}),d.length>0&&(0,a.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",gap:4,alignItems:"flex-start"},children:[(0,a.jsx)("span",{className:"rb-row-k",style:{marginBottom:4},children:"Recent transitions"}),d.map((e,t)=>(0,a.jsxs)("div",{style:{fontSize:12,color:"var(--fg-muted)",display:"flex",gap:8},children:[(0,a.jsxs)("span",{className:"mono",children:[e.from," → ",e.to]}),(0,a.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)"},children:new Date(e.occurredAt).toLocaleString()})]},t))]})]})]})}function i_(){return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{children:"Authority status"}),(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsx)("div",{className:"rb-row","data-testid":"authority-disclaimer",children:(0,a.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)",fontStyle:"italic"},children:"Relationship: governance only. No model/tool/file/workflow authority granted."})})})]})}function iH(e){let{auditRows:t,loading:n,error:l,onRetry:s,onLoadMore:i,hasMore:r}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{children:"Audit history"}),n&&(0,a.jsx)(iz,{lines:3}),null!==l&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:l}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:s,children:"Retry"})]}),!n&&null===l&&0===t.length&&(0,a.jsx)("div",{className:"rb-rows",children:(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("span",{className:"rb-row-v",style:{color:"var(--fg-muted)"},children:"No audit events for this relationship yet."})})}),!n&&t.length>0&&(0,a.jsxs)("div",{className:"rb-rows",children:[t.map((e,t)=>(0,a.jsxs)("div",{className:"rb-row",style:{flexDirection:"column",alignItems:"flex-start",gap:2},children:[(0,a.jsxs)("span",{className:"rb-row-k mono",style:{fontSize:11},children:[e.from," → ",e.to]}),(0,a.jsx)("time",{dateTime:new Date(e.occurredAt).toISOString(),style:{color:"var(--fg-faint)",fontSize:11},children:new Date(e.occurredAt).toLocaleString()})]},t)),r&&(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("button",{type:"button",className:"rb-row-v",style:{color:"var(--accent)",fontSize:12,background:"none",border:"none",padding:0,cursor:"pointer",minHeight:24,minWidth:24},onClick:i,"aria-label":"Load more audit events",children:"Load more"})})]})]})}function iG(e){let{rel:t}=e,n=function(e){let t=[];return"evidence-run"===e.source.kind&&t.push(e.source.id),"evidence-run"===e.target.kind&&t.push(e.target.id),t}(t);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{children:"Evidence references"}),0===n.length?(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)",margin:"0 0 4px"},"data-testid":"evidence-empty",children:"No evidence references for this relationship."}):(0,a.jsx)("div",{className:"rb-rows",children:n.map(e=>(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Evidence run"}),(0,a.jsx)("span",{className:"rb-row-v mono","aria-label":"Evidence run reference ".concat(e),title:e,children:e})]},e))})]})}function iJ(e){let{relationshipId:t,forwardCount:n,reverseCount:l,outgoing:s,incoming:i,expanded:r,onToggle:o,onSelectRelationship:c}=e;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{children:"Impact summary"}),(0,a.jsxs)("div",{className:"rb-rows",children:[(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Forward dependencies"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:null===n?"—":String(n)})]}),(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:"Reverse dependencies"}),(0,a.jsx)("span",{className:"rb-row-v mono",children:null===l?"—":String(l)})]}),(0,a.jsx)("div",{className:"rb-row",children:(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:o,"aria-expanded":r,"aria-controls":"rb-impact-detail","aria-label":r?"Hide impact for relationship ".concat(t):"View impact for relationship ".concat(t),"data-testid":"view-impact-btn",children:r?"Hide impact":"View impact"})})]}),r&&(0,a.jsx)("div",{id:"rb-impact-detail",children:(0,a.jsx)(iP,{outgoing:s,incoming:i,onSelectRelationship:c})})]})}function iV(e){let{codes:t,messages:n,deniedAt:l}=e;return 0===t.length?null:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{children:"Denial reason"}),(0,a.jsxs)("div",{className:"lk-alert",role:"status","aria-live":"polite","data-testid":"denial-section",children:[t.map((e,l)=>{var s;return(0,a.jsxs)("div",{style:{marginBottom:8*(l<t.length-1)},children:[(0,a.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,a.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(s=n[l])?s:e})]},e)}),void 0!==l&&(0,a.jsxs)("div",{style:{fontSize:11,color:"var(--fg-faint)",marginTop:6},children:["Denied at ",(0,a.jsx)("time",{dateTime:l,children:l})]})]})]})}function iX(e){return null==e||0===e.length?null:{codes:e.map(e=>e.code),messages:e.map(e=>e.message)}}function iY(e){let{rel:t,onReconnect:n,onArchive:l,onRevoke:s,onViewImpact:i,onViewEvidence:r,mutating:o}=e,c=t.lifecycle,d="blocked"===c,u="active"===c,h="active"===c||"blocked"===c||"archived"===c,p="active"===c;return(0,a.jsxs)("div",{style:{display:"flex",gap:6,flexWrap:"wrap",marginTop:8},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn".concat(d?" primary":""),"aria-disabled":!d||o,"aria-label":"Reconnect — only available for blocked relationships",title:d?"Reconnect this relationship":"Only blocked relationships can be reconnected.",disabled:!d||o,onClick:d?n:void 0,children:"Reconnect"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!u||o,"aria-label":"Archive — only available for active relationships",title:u?"Archive this relationship":"Only active relationships can be archived.",disabled:!u||o,onClick:u?l:void 0,children:"Archive"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!h||o,"aria-label":"Revoke relationship",title:h?"Revoke this relationship":"Already revoked or superseded.",disabled:!h||o,onClick:h?s:void 0,style:{color:h?"var(--danger)":void 0},children:"Revoke"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-disabled":!p,"aria-label":"View impact analysis",title:p?"Toggle the impact analysis card":"Impact analysis is unavailable in this state.",disabled:!p,onClick:p?i:void 0,children:"View impact"}),(0,a.jsx)("button",{type:"button",className:"arun-btn","aria-label":"View evidence references",title:"Jump to the evidence references section",onClick:r,children:"View evidence"})]})}function iZ(e){var t,n,s;let{relationshipId:i,densityMode:r="minimal",onClearFocus:o,onViewImpact:c,activityMap:d=new Map,throughputMap:u=new Map,animateBadges:h=!0,highContrast:p=!1}=e,[m,f]=(0,l.useState)(null),[g,v]=(0,l.useState)(null),[x,y]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[w,k]=(0,l.useState)(!1),[N,S]=(0,l.useState)(null),[C,R]=(0,l.useState)(null),[E,I]=(0,l.useState)(null),[T,F]=(0,l.useState)(null),[q,A]=(0,l.useState)(!1),M=null===E?null:E.relationships.length,P=null===T?null:T.relationships.length,[D,L]=(0,l.useState)(!1),z=(0,l.useRef)(null),O=(0,l.useRef)(0),K=(0,l.useCallback)(async e=>{let t=++O.current;j(null),y(!0),R(null),I(null),F(null),A(!1);let n=setTimeout(()=>{O.current===t&&L(!0)},500);z.current=n;try{let[n,a]=await Promise.all([aj(e),aS(e)]);if(O.current!==t)return;f(n),v(a);try{let[n,a]=await Promise.all([aN(e,{direction:"outgoing",maxDepth:3,maxRelationships:512}),aN(e,{direction:"incoming",maxDepth:3,maxRelationships:512})]);if(O.current!==t)return;I(n),F(a)}catch(e){}}catch(e){if(O.current!==t)return;j(e instanceof af?e.message:am)}finally{z.current===n?(clearTimeout(n),z.current=null):clearTimeout(n),O.current===t&&(y(!1),L(!1))}},[]);(0,l.useEffect)(()=>{if(null===i){O.current+=1,null!==z.current&&(clearTimeout(z.current),z.current=null),f(null),v(null),j(null),R(null),L(!1),y(!1);return}return K(i),()=>{null!==z.current&&(clearTimeout(z.current),z.current=null)}},[i,K]);let B=(0,l.useCallback)(async e=>{if(null!==m){k(!0),S(null),R(null);try{let t=crypto.randomUUID(),{relationship:n}=await aw(m.id,{transition:{to:e}},String(m.etag),t);f(n),v(null),await K(m.id)}catch(e){S(e instanceof af?e.message:"Mutation failed. Please retry."),R(e instanceof af?iX(e.reasons):null)}finally{k(!1)}}},[m,K]),W=(0,l.useCallback)(()=>void B("draft"),[B]),U=(0,l.useCallback)(()=>void B("archived"),[B]),_=(0,l.useCallback)(async()=>{if(null!==m&&window.confirm('Revoke relationship "'.concat(m.type,'"? This cannot be undone.'))){k(!0),S(null),R(null);try{let e=crypto.randomUUID(),t=await ak(m.id,String(m.etag),e);f(t)}catch(e){S(e instanceof af?e.message:"Revoke failed. Please retry."),R(e instanceof af?iX(e.reasons):null)}finally{k(!1)}}},[m]),H=(0,l.useCallback)(()=>{A(e=>!e)},[]),G=(0,l.useCallback)(e=>{null==c||c(e)},[c]),J=(0,l.useRef)(null),V=(0,l.useCallback)(()=>{var e,t;null==(t=J.current)||null==(e=t.scrollIntoView)||e.call(t,{block:"start"})},[]);if(null===i)return(0,a.jsxs)("div",{className:"tw-pad","data-testid":"relationship-inspector-panel",children:[(0,a.jsx)(iO,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)("div",{className:"insp-empty","data-testid":"inspector-empty",children:"Select a relationship from the list to inspect it."}),(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)",marginTop:4},children:"If the list is empty, use “+ New relationship” in the toolbar to create one."})]});let X=iX(null==g?void 0:g.decision.reasons),Y=null!=X?X:C,Z=null!==Y&&((null==m?void 0:m.lifecycle)==="blocked"||(null==m?void 0:m.lifecycle)==="revoked"||null!==C),Q=null!==m?null!=(t=d.get(m.id))?t:function(e){switch(e){case"blocked":return"blocked";case"stale":return"degraded";default:return"inactive"}}(m.lifecycle):"inactive",$=null!==m?u.get(m.id):void 0;return(0,a.jsxs)("div",{className:"tw-pad","aria-busy":x,"data-testid":"relationship-inspector-panel",children:[null!==b&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:b}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void K(i),children:"Retry"})]}),null!==N&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert","aria-live":"assertive",children:[(0,a.jsx)("span",{children:N}),(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>S(null),children:"Dismiss"})]}),x&&D&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)(iz,{lines:4}),(0,a.jsx)(iz,{lines:3})]}),!x&&null===b&&null===m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)("div",{className:"insp-empty","data-testid":"inspector-not-found",children:"This relationship is no longer available."}),(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)",marginTop:4},children:"It may have been deleted, retired by retention, or it never existed in this workspace."}),void 0!==o&&(0,a.jsx)("button",{type:"button",className:"arun-btn",style:{marginTop:8},onClick:o,children:"Clear focus"})]}),!x&&null!==m&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(iO,{style:{marginTop:0},children:"Relationship"}),(0,a.jsx)(iK,{rel:m}),(0,a.jsx)(iB,{label:"Source",kind:m.source.kind,id:m.source.id}),(0,a.jsx)(iB,{label:"Target",kind:m.target.kind,id:m.target.id}),(0,a.jsx)(iW,{lifecycle:m.lifecycle}),(0,a.jsx)(iU,{type:m.type,lifecycle:m.lifecycle,activity:Q,throughputCount:$,animateBadges:h,highContrast:p,transitions:null!=(n=null==g?void 0:g.lifecycle)?n:[],densityMode:r}),(0,a.jsx)(i_,{}),(0,a.jsx)(iH,{auditRows:null!=(s=null==g?void 0:g.lifecycle)?s:[],loading:!1,error:null,onRetry:()=>void K(i),onLoadMore:()=>{},hasMore:!1}),(0,a.jsx)("div",{ref:J,children:(0,a.jsx)(iG,{rel:m})}),(0,a.jsx)(iJ,{relationshipId:m.id,forwardCount:M,reverseCount:P,outgoing:E,incoming:T,expanded:q,onToggle:H,onSelectRelationship:G}),Z&&null!==Y&&(0,a.jsx)(iV,{codes:Y.codes,messages:Y.messages}),(0,a.jsx)(iY,{rel:m,onReconnect:W,onArchive:U,onRevoke:()=>void _(),onViewImpact:H,onViewEvidence:V,mutating:w})]})]})}let iQ=new Set(["kind","id","state","timestamp","count"]);function i$(e){return"".concat(e.kind,": ").concat(e.id)}function i0(e){let{category:t}=e;return(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)",borderLeft:"2px solid var(--warn)",paddingLeft:8},children:["More ",t," exist than the bounded query returned. Resolve the listed items, then re-run the health check."]})}function i1(e){let{category:t,onSelectRelationship:n}=e;if(0===t.items.length)return null;let l=t.items.slice(0,50),s=t.items.length-l.length;return(0,a.jsxs)("section",{"aria-label":"".concat(t.label," (").concat(String(t.items.length),")"),style:{marginBottom:14},children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:[t.label,(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.items.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:t.help}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:l.map(e=>(0,a.jsx)("li",{style:{marginBottom:2},children:(0,a.jsxs)("button",{type:"button",className:"arun-btn ghost",onClick:()=>n(e.id),"aria-label":"Inspect ".concat(e.type," relationship from ").concat(i$(e.source)," to ").concat(i$(e.target),", lifecycle ").concat(e.lifecycle),style:{display:"flex",width:"100%",gap:6,alignItems:"center",textAlign:"left",fontSize:12},children:[(0,a.jsx)("span",{className:"mono",style:{color:"var(--fg)"},children:e.type}),(0,a.jsxs)("span",{style:{color:"var(--fg-muted)"},children:[i$(e.source)," → ",i$(e.target)]}),(0,a.jsx)("span",{className:"mono",style:{marginLeft:"auto",color:"var(--fg-muted)"},children:e.lifecycle})]})},e.id))}),s>0&&(0,a.jsxs)("p",{role:"note",style:{margin:"4px 0 0",fontSize:11,color:"var(--fg-muted)"},children:["Showing the first ",String(50)," of ",String(t.items.length),"."]}),t.truncated&&(0,a.jsx)(i0,{category:t.label.toLowerCase()})]})}function i2(e){let{findings:t}=e;if(0===t.orphanedEndpoints.length)return null;let n=t.orphanedEndpoints.slice(0,50);return(0,a.jsxs)("section",{"aria-label":"Orphaned endpoints (".concat(String(t.orphanedEndpoints.length),")"),style:{marginBottom:14},children:[(0,a.jsxs)("div",{className:"rb-section-label",role:"heading","aria-level":3,children:["Orphaned endpoints",(0,a.jsx)("span",{className:"rb-count","aria-hidden":"true",children:t.orphanedEndpoints.length})]}),(0,a.jsx)("p",{style:{margin:"0 0 6px",fontSize:11,color:"var(--fg-muted)"},children:"Endpoints that participate in no live relationship."}),(0,a.jsx)("ul",{style:{listStyle:"none",margin:0,padding:0},children:n.map(e=>(0,a.jsx)("li",{className:"rb-row",style:{fontSize:12},children:(0,a.jsx)("span",{className:"mono",children:i$(e)})},"".concat(e.kind,":").concat(e.id)))}),t.orphanedEndpointsTruncated&&(0,a.jsx)(i0,{category:"orphaned endpoints"})]})}function i3(e){var t,n;let{onSelectRelationship:s}=e,[i,r]=(0,l.useState)(null),[o,c]=(0,l.useState)(!0),[d,u]=(0,l.useState)(null),h=(0,l.useCallback)(async()=>{c(!0),u(null);try{let e=await aC();r(e)}catch(e){u(e instanceof af?e.message:"Could not load the graph health check.")}finally{c(!1)}},[]);return(0,l.useEffect)(()=>{h()},[h]),(0,a.jsxs)("div",{style:{padding:12,height:"100%",overflowY:"auto"},"aria-busy":o,children:[(0,a.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:10},children:[(0,a.jsx)("h2",{style:{margin:0,fontSize:13,fontWeight:600,color:"var(--fg)",flexGrow:1},children:"Graph health"}),(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>void h(),"aria-label":"Re-run the graph health check",style:{minHeight:24},children:"Refresh"})]}),o&&(0,a.jsx)("p",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Running health check…"}),null!==d&&(0,a.jsxs)("div",{className:"lk-alert",role:"alert",children:[d,(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>void h(),children:"Retry"})]}),!o&&null===d&&null!==i&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("p",{style:{fontSize:11,color:"var(--fg-faint)",margin:"0 0 10px"},children:["Checked at"," ",(0,a.jsx)("time",{dateTime:new Date(i.checkedAt).toISOString(),children:new Date(i.checkedAt).toLocaleString()}),"."]}),(0,a.jsx)("div",{className:"rb-rows",style:{marginBottom:14},children:au.filter(e=>{var t;return(null!=(t=i.totals[e])?t:0)>0}).map(e=>{var t;return(0,a.jsxs)("div",{className:"rb-row",children:[(0,a.jsx)("span",{className:"rb-row-k",children:e}),(0,a.jsx)("span",{className:"rb-row-v mono",children:String(null!=(t=i.totals[e])?t:0)})]},e)})}),0===(t=i.findings).orphanedEndpoints.length+t.staleRelationships.length+t.blockedRelationships.length+t.failedRelationships.length+t.invalidReferences.length+t.cycleParticipants.length?(0,a.jsxs)("div",{className:"lk-empty",children:[(0,a.jsx)("p",{className:"lk-empty-title",children:"Healthy"}),(0,a.jsx)("p",{className:"lk-empty-body",children:"No relationship-graph defects were found."})]}):(0,a.jsxs)(a.Fragment,{children:[[{key:"invalid",label:"Invalid references",help:"An endpoint no longer resolves to a live workspace object.",items:(n=i.findings).invalidReferences,truncated:n.invalidReferencesTruncated},{key:"blocked",label:"Blocked",help:"A policy or endpoint state is blocking this relationship.",items:n.blockedRelationships,truncated:n.blockedRelationshipsTruncated},{key:"failed",label:"Failed (revoked)",help:"The relationship reached the revoked terminal state.",items:n.failedRelationships,truncated:n.failedRelationshipsTruncated},{key:"cycle",label:"Cycle participants",help:"These relationships take part in a dependency cycle.",items:n.cycleParticipants,truncated:n.cycleScanTruncated},{key:"stale",label:"Stale",help:"A health check flagged at least one endpoint as not currently live.",items:n.staleRelationships,truncated:n.staleRelationshipsTruncated}].map(e=>(0,a.jsx)(i1,{category:e,onSelectRelationship:s},e.key)),(0,a.jsx)(i2,{findings:i.findings})]})]})]})}let i4={draft:["draft","active","archived","superseded","revoked","blocked","stale"],active:["active","archived","superseded","revoked","stale"],archived:["archived","superseded","revoked","stale"],superseded:["superseded","stale"],revoked:["revoked"],blocked:["blocked","draft","active","archived","revoked","stale"],stale:["stale","active","archived","superseded","revoked"]};function i6(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}function i5(e){return"string"==typeof e&&e.length>0}function i8(e,t,n){return void 0===n?{code:e,message:t}:{code:e,field:n,message:t}}function i9(e,t,n){return i6(e)?i5(e.kind)?i5(e.id)?!!i5(e.workspaceId)||(n.push(i8("denied/schema-version-unsupported","".concat(t,".workspaceId must be a non-empty string"),"".concat(t,".workspaceId"))),!1):(n.push(i8("denied/schema-version-unsupported","".concat(t,".id must be a non-empty string"),"".concat(t,".id"))),!1):(n.push(i8("denied/schema-version-unsupported","".concat(t,".kind must be a non-empty string"),"".concat(t,".kind"))),!1):(n.push(i8("denied/schema-version-unsupported","".concat(t," must be an object"),t)),!1)}function i7(e,t,n){i5(e[t])||n.push(i8("denied/schema-version-unsupported","".concat(t," must be a non-empty string"),t))}function re(e,t){let n=e.kind;return ao.includes(n)?null:i8("denied/schema-version-unsupported","".concat(t,".kind is not a known object kind"),"".concat(t,".kind"))}function rt(e,t,n){return"missing"===t?void n.push(i8("source"===e?"denied/non-existent-source":"denied/non-existent-target","".concat(e," endpoint does not exist"),e)):"tombstoned"===t?void n.push(i8("denied/endpoint-tombstoned","".concat(e," endpoint has been tombstoned"),e)):"retired"===t?void n.push(i8("denied/endpoint-retired","".concat(e," endpoint has been retired"),e)):void("unavailable"===t&&n.push(i8("denied/endpoint-unavailable","".concat(e," endpoint is unavailable"),e)))}function rn(e,t){let n=e.kind;return ac.includes(n)?null:i8("denied/object-kind-not-yet-supported","".concat(t,'.kind "').concat(n,'" is reserved for a future release'),"".concat(t,".kind"))}function ra(){return{type:"reads-context",sourceKind:"workflow-run",sourceId:"",targetKind:"memory",targetId:"",summary:""}}let rl=new Set(["denied/path-not-contained","denied/cross-workspace","denied/payload-content-not-permitted"]);function rs(e){return(null==e?void 0:e.codes.some(e=>rl.has(e)))===!0}function ri(e){let{onClose:t}=e,[n,s]=(0,l.useState)(ra),[i,r]=(0,l.useState)([]),[o,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(!1),[h,p]=(0,l.useState)(!1),m=(0,l.useRef)(null),f=(0,l.useRef)(null),g="rel-create-dialog-title",v="rel-create-dialog-desc";(0,l.useEffect)(()=>{var e;null==(e=f.current)||e.focus()},[]);let x=(0,l.useCallback)(e=>{let t=m.current;if(null===t)return;let n=Array.from(t.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter(e=>!e.hasAttribute("disabled")),a=n[0],l=n[n.length-1];"Tab"===e.key&&(e.shiftKey?document.activeElement===a&&(e.preventDefault(),null==l||l.focus()):document.activeElement===l&&(e.preventDefault(),null==a||a.focus()))},[]),y=(0,l.useCallback)(e=>{"Escape"===e.key&&t(null)},[t]);(0,l.useEffect)(()=>(window.addEventListener("keydown",x),window.addEventListener("keydown",y),()=>{window.removeEventListener("keydown",x),window.removeEventListener("keydown",y)}),[x,y]),(0,l.useEffect)(()=>{if(0===n.sourceId.length||0===n.targetId.length)return void r([]);let e=function(e,t){let n=function(e){var t;if(!i6(e))return{errors:[i8("denied/schema-version-unsupported","relationship must be an object")]};let n=[];i7(e,"id",n),i7(e,"workspaceId",n),i7(e,"createdAt",n),i7(e,"updatedAt",n),(!("number"==typeof(t=e.etag)&&Number.isInteger(t)&&Number.isFinite(t))||e.etag<0)&&n.push(i8("denied/schema-version-unsupported","etag must be a non-negative finite integer","etag"));let a=i9(e.source,"source",n),l=i9(e.target,"target",n);return!(n.length>0)&&a&&l?{errors:[],value:{record:e,source:e.source,target:e.target}}:{errors:n}}(e);if(!n.value)return{ok:!1,errors:n.errors};let{record:a,source:l,target:s}=n.value,i=function(e,t,n){let a="1"!==e.schemaVersion?i8("denied/schema-version-unsupported",'schemaVersion must be the literal "'.concat("1",'"'),"schemaVersion"):null;if(a)return[a];let l=function(e){let t=e.type;return i5(t)?ad.includes(t)?null:i8("denied/schema-version-unsupported","type is not a known relationship type","type"):i8("denied/schema-version-unsupported","type must be a non-empty string","type")}(e);if(l)return[l];let s=re(t,"source"),i=re(n,"target");if(null!==s||null!==i){let e=[];return null!==s&&e.push(s),null!==i&&e.push(i),e}let r=function(e){let t=e.lifecycleState;return i5(t)?au.includes(t)?null:i8("denied/schema-version-unsupported","lifecycleState is not a known lifecycle state","lifecycleState"):i8("denied/schema-version-unsupported","lifecycleState must be a non-empty string","lifecycleState")}(e);return r?[r]:null}(a,l,s);if(i)return{ok:!1,errors:i};let r=function(e){if(!(null==e?void 0:e.endpointResolver))return null;let t=[];return"missing"===e.endpointResolver.source&&rt("source",e.endpointResolver.source,t),"missing"===e.endpointResolver.target&&rt("target",e.endpointResolver.target,t),t}(void 0);if(null!==r&&r.length>0)return{ok:!1,errors:r};let o=function(e,t,n,a){var l,s,i;let r=[],o=e.type,c=e.lifecycleState,d=rn(t,"source");d&&r.push(d);let u=rn(n,"target");u&&r.push(u),null===d&&null===u&&function(e,t,n,a){let l=function(e,t,n){let a=ah[e];return a.validSourceKinds.includes(t)?a.validTargetKinds.includes(n)?null:"denied/target-kind-not-allowed":"denied/source-kind-not-allowed"}(e,t.kind,n.kind);"denied/source-kind-not-allowed"===l?a.push(i8("denied/source-kind-not-allowed",'source.kind "'.concat(t.kind,'" is not permitted for type "').concat(e,'"'),"source.kind")):"denied/target-kind-not-allowed"===l&&a.push(i8("denied/target-kind-not-allowed",'target.kind "'.concat(n.kind,'" is not permitted for type "').concat(e,'"'),"target.kind"))}(o,t,n,r);let h=function(e,t){let n=null==t?void 0:t.cardinalityCounts;return n?"produces-evidence"===e&&"number"==typeof n.producesEvidenceForSource&&n.producesEvidenceForSource>=1?i8("denied/cardinality-exceeded","produces-evidence already exists for this source workflow-run"):"starts-workflow"===e&&"number"==typeof n.startsWorkflowForTarget&&n.startsWorkflowForTarget>=1?i8("denied/cardinality-exceeded","starts-workflow already exists for this target workflow-run"):null:null}(o,a);h&&r.push(h),function(e,t,n,a,l){let s=t.kind===n.kind&&t.id===n.id?i8("denied/cycle-forbidden","source and target refer to the same endpoint"):null;s&&l.push(s);let i="depends-on"===e&&(null==a?void 0:a.dependsOnReverseEdgeExists)===!0?i8("denied/cycle-forbidden","depends-on reverse edge already exists for this endpoint pair"):null;i&&l.push(i)}(o,t,n,a,r);let p=(l=e.workspaceId,t.workspaceId!==l||n.workspaceId!==l?i8("denied/cross-workspace","source and target must be in the relationship's workspace"):null);p&&r.push(p);let m=function(e,t){let n=null==t?void 0:t.previousLifecycleState;return void 0===n||i4[n].includes(e)?null:i8("denied/lifecycle-illegal-transition","transition from ".concat(n," to ").concat(e," is not permitted"),"lifecycleState")}(c,a);for(let t of(m&&r.push(m),s=a,i=r,(null==s?void 0:s.endpointResolver)&&("missing"!==s.endpointResolver.source&&rt("source",s.endpointResolver.source,i),"missing"!==s.endpointResolver.target&&rt("target",s.endpointResolver.target,i)),function(e){let t=[];if(void 0===e.metadata||null===e.metadata)return t;if(!i6(e.metadata))return t.push(i8("denied/payload-content-not-permitted","metadata must be an object when set","metadata")),t;for(let n of Object.keys(e.metadata)){let e=n.toLowerCase().replace(/[^a-z0-9]/g,"");for(let a of ap)if(e.includes(a)){t.push(i8("denied/payload-content-not-permitted","metadata may not carry endpoint content","metadata.".concat(n)));break}}return t}(e)))r.push(t);return r}(a,l,s,void 0);return o.length>0?{ok:!1,errors:o}:{ok:!0,value:a}}({id:"candidate",schemaVersion:"1",workspaceId:"preview",source:{kind:n.sourceKind,id:n.sourceId,workspaceId:"preview"},target:{kind:n.targetKind,id:n.targetId,workspaceId:"preview"},type:n.type,lifecycleState:"active",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),etag:0});e.ok?r([]):r(e.errors.map(e=>e.message))},[n]);let b=(0,l.useRef)(null),j=(0,l.useRef)(0);(0,l.useEffect)(()=>{j.current+=1;let e=j.current;return(null!==b.current&&clearTimeout(b.current),0===n.sourceId.length||0===n.targetId.length||i.length>0)?void p(!1):(b.current=setTimeout(async()=>{p(!0);try{if(await ax({type:n.type,source:{kind:n.sourceKind,id:n.sourceId},target:{kind:n.targetKind,id:n.targetId},summary:n.summary.length>0?n.summary:void 0}),e!==j.current)return;c(e=>rs(e)?e:null)}catch(t){if(e!==j.current)return;t instanceof af&&t.reasons.length>0?c({source:"preview",codes:t.reasons.map(e=>e.code),messages:t.reasons.map(e=>e.message)}):c(null)}finally{e===j.current&&p(!1)}},250),()=>{null!==b.current&&clearTimeout(b.current)})},[n,i]),(0,l.useEffect)(()=>{c(e=>(null==e?void 0:e.source)!=="submit"||rs(e)?e:null)},[n]);let w=n.sourceId.trim().length>0&&n.targetId.trim().length>0&&0===i.length&&null===o&&!d,k=(0,l.useCallback)(async()=>{if(w){u(!0),c(null);try{let e=crypto.randomUUID(),{relationship:a}=await ay({type:n.type,source:{kind:n.sourceKind,id:n.sourceId},target:{kind:n.targetKind,id:n.targetId},summary:n.summary.length>0?n.summary:void 0},e);t(a)}catch(e){e instanceof af?e.reasons.length>0?c({source:"submit",codes:e.reasons.map(e=>e.code),messages:e.reasons.map(e=>e.message)}):c({source:"submit",codes:[e.code],messages:[e.message]}):c({source:"submit",codes:["relationship/network-error"],messages:[am]})}finally{u(!1)}}},[w,n,t]),S=(0,l.useCallback)(e=>{"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&k()},[k]),C=ah[n.type],R=rs(o),E=[i.length>0?"rel-create-client-hints":null,null!==o?"rel-create-server-denial":null].filter(e=>null!==e),I=(0,a.jsx)("div",{className:"cmdk-overlay",onPointerDown:()=>t(null),"data-testid":"rel-create-overlay",children:(0,a.jsxs)("div",{ref:m,role:"dialog","aria-modal":"true","aria-labelledby":g,"aria-describedby":v,className:"cmdk",style:{maxWidth:480,width:"100%"},onPointerDown:e=>e.stopPropagation(),onKeyDown:S,"data-testid":"rel-create-dialog",children:[(0,a.jsxs)("div",{className:"cmdk-input",style:{borderBottom:"1px solid var(--line)"},children:[(0,a.jsx)("span",{id:g,style:{fontWeight:600,fontSize:14,color:"var(--fg)"},children:"Create relationship"}),(0,a.jsx)("span",{id:v,className:"visually-hidden",children:"Create a new relationship between two workspace endpoints."}),(0,a.jsx)("button",{type:"button",className:"palette-x",onClick:()=>t(null),"aria-label":"Close",title:"Close",style:{marginLeft:"auto"},children:(0,a.jsx)(N.F.close,{size:16})})]}),(0,a.jsxs)("div",{style:{padding:"12px 16px",display:"flex",flexDirection:"column",gap:10},children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"rel-type",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Type"}),(0,a.jsx)("select",{id:"rel-type",ref:f,value:n.type,onChange:e=>s(t=>({...t,type:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:13},"aria-label":"Relationship type",children:ad.map(e=>(0,a.jsx)("option",{value:e,children:ah[e].displayName},e))}),(0,a.jsx)("div",{style:{fontSize:11,color:"var(--fg-muted)",marginTop:3},children:C.semantics})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,a.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,a.jsx)("label",{htmlFor:"rel-src-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source kind"}),(0,a.jsx)("select",{id:"rel-src-kind",value:n.sourceKind,onChange:e=>s(t=>({...t,sourceKind:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12},"aria-label":"Source endpoint kind",children:ac.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("div",{style:{flex:1},children:[(0,a.jsx)("label",{htmlFor:"rel-src-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Source ID"}),(0,a.jsx)("input",{id:"rel-src-id",type:"text",value:n.sourceId,onChange:e=>s(t=>({...t,sourceId:e.target.value})),placeholder:"endpoint id",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12},"aria-label":"Source endpoint ID","aria-describedby":"rel-src-kind"})]})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:6},children:[(0,a.jsxs)("div",{style:{flex:"0 0 140px"},children:[(0,a.jsx)("label",{htmlFor:"rel-tgt-kind",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target kind"}),(0,a.jsx)("select",{id:"rel-tgt-kind",value:n.targetKind,onChange:e=>s(t=>({...t,targetKind:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12},"aria-label":"Target endpoint kind",children:ac.map(e=>(0,a.jsx)("option",{value:e,children:e},e))})]}),(0,a.jsxs)("div",{style:{flex:1},children:[(0,a.jsx)("label",{htmlFor:"rel-tgt-id",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Target ID"}),(0,a.jsx)("input",{id:"rel-tgt-id",type:"text",value:n.targetId,onChange:e=>s(t=>({...t,targetId:e.target.value})),placeholder:"endpoint id",style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12},"aria-label":"Target endpoint ID","aria-describedby":"rel-tgt-kind"})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("label",{htmlFor:"rel-summary",style:{fontSize:12,color:"var(--fg-muted)",display:"block",marginBottom:3},children:"Summary (optional, ≤240 chars)"}),(0,a.jsx)("textarea",{id:"rel-summary",value:n.summary,maxLength:240,rows:2,onChange:e=>s(t=>({...t,summary:e.target.value})),style:{width:"100%",background:"var(--inset)",border:"1px solid var(--line)",borderRadius:4,padding:"4px 8px",minHeight:24,color:"var(--fg)",fontSize:12,resize:"vertical"},"aria-label":"Relationship summary"})]}),i.length>0&&(0,a.jsx)("div",{id:"rel-create-client-hints",className:"lk-alert",role:"status","aria-live":"polite","data-testid":"client-validation-hints",children:i.map((e,t)=>(0,a.jsx)("div",{style:{fontSize:12},children:e},t))}),h&&(0,a.jsx)("div",{style:{fontSize:12,color:"var(--fg-muted)"},"aria-live":"polite",children:"Validating…"}),null!==o&&(0,a.jsxs)("div",{id:"rel-create-server-denial",className:"lk-alert",role:"alert","aria-live":"assertive","data-testid":"server-denial-banner",children:[o.codes.map((e,t)=>{var n;return(0,a.jsxs)("div",{style:{marginBottom:6*(t<o.codes.length-1)},children:[(0,a.jsx)("div",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--fg-muted)",marginBottom:2},children:e}),(0,a.jsx)("div",{style:{fontSize:13,color:"var(--fg)"},children:null!=(n=o.messages[t])?n:e})]},e)}),R&&(0,a.jsx)("button",{type:"button",className:"lk-alert-retry",onClick:()=>c(null),style:{marginTop:6},children:"Dismiss"})]}),(0,a.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:4},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>t(null),style:{minWidth:24,minHeight:24},children:"Cancel"}),(0,a.jsx)("button",{type:"button",className:"arun-btn".concat(w?" primary":""),"aria-disabled":!w,"aria-describedby":E.length>0?E.join(" "):void 0,onClick:()=>void k(),"aria-busy":d,style:{minWidth:24,minHeight:24},children:d?"Creating…":"Create"})]})]})]})});return"undefined"==typeof document?I:(0,tj.createPortal)(I,document.body)}let rr={};function ro(){var e;let{activityMap:t,throughputMap:n,animate:s}=function(e){let t=(0,l.useRef)(new Map),n=(0,l.useRef)("undefined"==typeof document||"visible"===document.visibilityState),[a,s]=(0,l.useState)(new Map),[i,r]=(0,l.useState)(new Map),o=(0,l.useRef)(new Map),c=(0,l.useRef)(new Map),[d,u]=(0,l.useState)(()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches),[h,p]=(0,l.useState)(!1),m=(0,l.useCallback)(()=>{p(!0)},[]),f=(0,l.useCallback)((e,n)=>{let a=new Map(o.current),l=new Set,i=new Set,d=!1;for(let[s,r]of a){var u;let o=e-(null!=(u=t.current.get(s))?u:0);o>=6e4&&"inactive"!==r&&(a.set(s,"inactive"),i.add(s),d=!0),!n&&o>=12e4&&(a.delete(s),l.add(s),i.add(s),d=!0)}if(a.size>512)for(let e of Array.from(a.keys()).sort((e,n)=>{var l,s;let i=a.get(e),r=a.get(n);return"inactive"===i&&"inactive"!==r?-1:"inactive"!==i&&"inactive"===r?1:(null!=(l=t.current.get(e))?l:0)-(null!=(s=t.current.get(n))?s:0)}).slice(0,a.size-512))a.delete(e),l.add(e),i.add(e),d=!0;if(d&&(o.current=a,s(a)),l.size>0)for(let e of l)t.current.delete(e);if(i.size>0){let e=!1,t=new Map(c.current);for(let n of i)t.delete(n)&&(e=!0);e&&(c.current=t,r(t))}},[]);(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)"),t=e=>{u(e.matches)};return e.addEventListener("change",t),()=>{e.removeEventListener("change",t)}},[]);let g=(0,l.useCallback)(e=>{var a;if(!n.current)return;let l=Date.now();l-(null!=(a=t.current.get(e.id))?a:0)<2e3||(t.current.set(e.id,l),s(t=>{let n=new Map(t);return n.set(e.id,e.state),o.current=n,n}),"high-throughput"===e.state&&void 0!==e.count?r(t=>{let n=new Map(t);return n.set(e.id,e.count),c.current=n,n}):r(t=>{if(!t.has(e.id))return t;let n=new Map(t);return n.delete(e.id),c.current=n,n}))},[]);return(0,l.useEffect)(()=>{let e=setInterval(()=>{n.current&&f(Date.now(),!1)},15e3);return()=>{clearInterval(e)}},[f]),(0,l.useEffect)(()=>{if("undefined"==typeof document)return;let e=()=>{n.current="visible"===document.visibilityState,n.current&&f(Date.now(),!0)};return n.current="visible"===document.visibilityState,document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}},[f]),(0,l.useEffect)(()=>{let e=!1,t=null,a=null;function l(e){let t;try{t=JSON.parse(e)}catch(e){return}let n=function(e){var t;if(null===e||"object"!=typeof e||function e(t){if(null===t||"object"!=typeof t)return!1;for(let n of Object.keys(t))if(function(e){let t=e.toLowerCase();return ap.some(e=>t.includes(e))}(n)||e(t[n]))return!0;return!1}(e))return null;let n={};for(let t of iQ)Object.prototype.hasOwnProperty.call(e,t)&&(n[t]=e[t]);return"string"!=typeof n.id||0===n.id.length?null:"inactive"!==(t=n.state)&&"queued"!==t&&"active"!==t&&"processing"!==t&&"completed"!==t&&"failed"!==t&&"blocked"!==t&&"degraded"!==t&&"high-throughput"!==t||"number"!=typeof n.timestamp?null:{kind:"string"==typeof n.kind?n.kind:"relationship:activity",id:n.id,state:n.state,timestamp:n.timestamp,count:"number"==typeof n.count?n.count:void 0}}(t);null!==n&&g(n)}function s(){null!==a&&(clearTimeout(a),a=null)}function i(){null==t||t.close(),t=null}function r(){!e&&null===a&&n.current&&(a=setTimeout(()=>{a=null,o()},5e3))}function o(){if(!e&&n.current){try{t=new EventSource("/api/relationships/events")}catch(e){r();return}t.addEventListener("relationship:activity",e=>{l(e.data)}),t.onmessage=e=>{l(e.data)},t.onerror=()=>{e||(i(),r())}}}o();let c=()=>{if(n.current="visible"===document.visibilityState,!n.current){s(),i();return}f(Date.now(),!0),null===t&&o()};return document.addEventListener("visibilitychange",c),()=>{e=!0,document.removeEventListener("visibilitychange",c),s(),i()}},[void 0,g,f]),{activityMap:a,throughputMap:i,animate:!d&&!h,disable:m}}(),[i,r]=(0,l.useState)(!1),[o,c]=(0,l.useState)(rr),d=o.relFocus,u=null!=(e=o.relDensity)?e:"minimal",[h,p]=(0,l.useState)(!1),m=(0,l.useRef)(null),f=(0,l.useRef)(!1),g=(0,l.useRef)(null),[v,x]=(0,l.useState)(!1),y=(0,l.useCallback)(e=>{c(t=>{let n={...t,...e},a={};for(let[e,t]of Object.entries(n))void 0!==t&&""!==t&&(a[e]=t);return a})},[]),b=(0,l.useCallback)(e=>{y({relFocus:e})},[y]),j=(0,l.useCallback)(()=>{y({relFocus:void 0})},[y]),w=(0,l.useCallback)(e=>{y({relFocus:e})},[y]),k=(0,l.useCallback)(e=>{f.current=!0,p(!1),null!==e&&y({relFocus:e.id})},[y]);return(0,l.useEffect)(()=>{var e;!h&&f.current&&(f.current=!1,null==(e=m.current)||e.focus())},[h]),(0,l.useEffect)(()=>{let e=window.matchMedia("(prefers-contrast: more)"),t=e=>{r(e)};t(e.matches);let n=e=>{t(e.matches)};return e.addEventListener("change",n),()=>e.removeEventListener("change",n)},[]),(0,l.useEffect)(()=>{let e=g.current;if(null===e)return;let t=e=>{let t=e.target;if(!("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"SELECT"===t.tagName||t.isContentEditable)&&"Escape"===e.key){if(h||null!==document.querySelector('[role="dialog"][aria-modal="true"]'))return;j()}};return e.addEventListener("keydown",t),()=>e.removeEventListener("keydown",t)},[h,j]),(0,a.jsxs)(a.Fragment,{children:[h&&(0,a.jsx)(ri,{onClose:k}),(0,a.jsxs)("div",{ref:g,style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden",background:"var(--bg)"},children:[(0,a.jsxs)("header",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 12px",borderBottom:"1px solid var(--line)",flexShrink:0},children:[(0,a.jsx)("button",{type:"button",className:"arun-btn",onClick:()=>x(e=>!e),"aria-pressed":v,"aria-label":"Toggle the graph health view",style:{flex:"0 0 auto",minHeight:24,marginRight:"auto"},children:v?"Hide health":"Graph health"}),(0,a.jsx)("button",{ref:m,type:"button",className:"arun-btn primary",onClick:()=>p(!0),"aria-label":"Create new relationship",style:{flex:"0 0 auto",minWidth:24,minHeight:24},children:"+ New relationship"})]}),(0,a.jsxs)("div",{style:{display:"flex",flex:1,overflow:"hidden"},children:[(0,a.jsx)("div",{style:{flex:"0 0 280px",borderRight:"1px solid var(--line)",overflowY:"auto"},children:(0,a.jsx)(iq,{filters:o,selectedId:d,onSelect:b,onFilterChange:y,activityMap:t,throughputMap:n,animateBadges:s,highContrast:i})}),(0,a.jsx)("div",{style:{flex:1,overflowY:"auto"},children:v?(0,a.jsx)(i3,{onSelectRelationship:e=>{x(!1),b(e)}}):(0,a.jsx)(iZ,{relationshipId:null!=d?d:null,densityMode:u,onClearFocus:j,onViewImpact:w,activityMap:t,throughputMap:n,animateBadges:s,highContrast:i})})]})]})]})}function rc(e,t){let n=e[t];return"string"==typeof n?n:void 0}es("project",()=>(0,a.jsx)(aP,{})),es("search",()=>(0,a.jsx)(aD,{})),es("plugins",()=>(0,a.jsx)(aK,{})),es("automations",()=>(0,a.jsx)(aH,{})),es("mobile",()=>(0,a.jsx)(aG,{})),es("inspector",()=>(0,a.jsx)(aJ,{})),es("notifications",()=>(0,a.jsx)(aX,{})),es("resources",()=>(0,a.jsx)(aY,{})),es("activity",()=>(0,a.jsx)(a$,{})),es("keiko",()=>(0,a.jsx)(lZ,{})),es("settings",()=>(0,a.jsx)(l4,{})),es("quality",(e,t)=>{var n;return(0,a.jsx)(sG,{openRun:(e,n)=>{let a=void 0!==n&&n.length>0?{connectedSourcesJson:JSON.stringify(n)}:function(e){var t;let n=sO({connectedFilePath:null!=(t=e.linkedFilePath)?t:null,connectedRoot:e.linkedRoot,connectedRoots:e.linkedRoots,connectedCapsuleIds:e.linkedCapsuleIds,connectedCapsuleSetIds:e.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:e.linkedFigmaSnapshotRunIds});return n.length>0?{connectedSourcesJson:JSON.stringify(n)}:{}}(t);t.openWindow("qiRun",{runId:e,...a})},connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds})}),es("qiRun",(e,t)=>{let n=rc(e,"runId");if(void 0===n||""===n)return(0,a.jsx)("div",{className:"lk-empty",children:(0,a.jsx)("p",{className:"lk-empty-body",children:"Open a run from the Quality Intelligence hub."})});let l=function(e){var t,n;let a=rc(e,"connectedSourcesJson");if(void 0!==a&&a.length>0)try{let e=JSON.parse(a);if(Array.isArray(e))return e}catch(e){}return sO({connectedFilePath:null!=(t=rc(e,"connectedFilePath"))?t:null,connectedRoot:null!=(n=rc(e,"connectedRoot"))?n:null})}(e),s=rc(e,"connectedSourcesJson");return(0,a.jsx)(ib,{runId:n,connectedSources:l,onRegenerated:e=>{t.openWindow("qiRun",{runId:e.runId,...void 0!==s&&s.length>0?{connectedSourcesJson:s}:{}})}})}),es("relationships",()=>(0,a.jsx)(ro,{})),es("files",(e,t)=>{let n=rc(e,"root"),l=(e,n)=>{t.updateCfg({activeFilePath:null!=e?e:void 0,resolvedRoot:null!=n?n:void 0})},s=e=>{t.updateCfg({root:e,activeFilePath:void 0,resolvedRoot:void 0})};return void 0!==n?(0,a.jsx)(ll,{root:n,onActiveFileChange:l,onRootChange:s}):(0,a.jsx)(ll,{onActiveFileChange:l,onRootChange:s})}),es("editor",e=>{let t=rc(e,"file");return void 0!==t&&""!==t?(0,a.jsx)(li,{file:t}):(0,a.jsx)(li,{})}),es("browser",e=>{let t=rc(e,"url");return void 0!==t&&""!==t?(0,a.jsx)(lg,{url:t}):(0,a.jsx)(lg,{})}),es("terminal",e=>{let t=rc(e,"cwd"),n=rc(e,"projectPath"),l={};return void 0!==t&&(l.cwd=t),void 0!==n&&(l.projectPath=n),(0,a.jsx)(lk,{...l})}),es("review",(e,t)=>{let n=rc(e,"runId"),l=e=>{t.updateCfg({runId:e})};return void 0!==n&&""!==n?(0,a.jsx)(lA,{runId:n,onRunIdSubmit:l}):(0,a.jsx)(lA,{onRunIdSubmit:l})}),es("agents",(e,t)=>(0,a.jsx)(lL,{cfg:function(e){let t={},n=rc(e,"workflow");void 0!==n&&(t.workflow=n);let a=rc(e,"model");void 0!==a&&(t.model=a);let l=rc(e,"runId");void 0!==l&&(t.runId=l);let s=rc(e,"fingerprint");void 0!==s&&(t.fingerprint=s);let i=rc(e,"workspaceRoot");void 0!==i&&(t.workspaceRoot=i);let r=rc(e,"inputJson");void 0!==r&&(t.inputJson=r);let o=function(e,t){let n=e[t];return"boolean"==typeof n?n:void 0}(e,"keikoMode");void 0!==o&&(t.keikoMode=o);let c=function(e){let t=e.access;return"ask"===t||"full"===t?t:void 0}(e);return void 0!==c&&(t.access=c),t}(e),linkedRoot:t.linkedRoot,linkedFilePath:t.linkedFilePath})),es("integ",()=>(0,a.jsx)(lO,{})),es("figma",(e,t)=>{let n=rc(e,"snapshotRunId");return(0,a.jsx)(sc,{snapshotRunId:n,updateCfg:e=>{t.updateCfg(e)}})}),es("connector",(e,t)=>{let n=rc(e,"selectedKind"),l=rc(e,"selectedId");return(0,a.jsx)(se,{selectedKind:n,selectedId:l,onSelect:e=>{t.updateCfg(e)}})});let rd={supported:{heading:"Install Keiko",body:"Keep Keiko in your app shelf for fast access.",install:"Install Keiko"},"ios-add-to-home":{heading:"Install Keiko",body:'On iOS Safari, tap Share, then "Add to Home Screen".',install:null}};function ru(){let{available:e,triggerInstall:t}=function(){let[e,t]=(0,l.useState)(!1),n=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=e=>{e.preventDefault(),function(e){if("function"!=typeof e.prompt)return!1;let t=e.userChoice;return"object"==typeof t&&null!==t&&"function"==typeof t.then}(e)&&(n.current=e,t(!0))},a=()=>{localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1)};return window.addEventListener("beforeinstallprompt",e,{passive:!1}),window.addEventListener("appinstalled",a),()=>{window.removeEventListener("beforeinstallprompt",e),window.removeEventListener("appinstalled",a)}},[]),{available:e,triggerInstall:(0,l.useCallback)(async()=>{let e=n.current;if(null===e)return;await e.prompt();let{outcome:a}=await e.userChoice;"accepted"===a&&localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1)},[])}}(),[n,s]=(0,l.useState)(!1),[i]=(0,l.useState)(()=>"undefined"!=typeof navigator?function(e){let t=e.toLowerCase();return t.includes("crios/")?"manual":t.includes("chrome/")&&!t.includes("mobile")||t.includes("edg/")||t.includes("chromium/")?"supported":t.includes("firefox/")?"manual":t.includes("safari/")&&(t.includes("iphone")||t.includes("ipad")||t.includes("ipod"))?"ios-add-to-home":(t.includes("safari/")&&t.includes("macintosh"),"manual")}(navigator.userAgent):"manual"),r=(0,l.useRef)(null),o=(0,l.useCallback)(()=>{localStorage.setItem("keiko.pwa.dismissed",new Date().toISOString()),s(!0)},[]),c=(0,l.useCallback)(async()=>{await t()},[t]),d=(0,l.useCallback)(e=>{"Escape"!==e.key||e.defaultPrevented||o()},[o]);if(n||window.matchMedia("(display-mode: standalone)").matches||"true"===localStorage.getItem("keiko.pwa.installed")||function(){let e=localStorage.getItem("keiko.pwa.dismissed");if(null===e)return!1;let t=Date.parse(e);return!!Number.isNaN(t)||Date.now()-t<2592e6}()||"supported"===i&&!e||"supported"!==i&&"ios-add-to-home"!==i)return null;let u=rd[i];return(0,a.jsx)("aside",{className:"install-banner",role:"region","aria-label":"Install Keiko",onKeyDown:d,children:(0,a.jsxs)("div",{className:"install-banner-body",children:[(0,a.jsxs)("div",{className:"install-banner-text",children:[(0,a.jsx)("span",{className:"install-banner-heading",children:u.heading}),(0,a.jsx)("span",{className:"install-banner-desc",children:u.body})]}),(0,a.jsxs)("div",{className:"install-banner-actions",children:[null!==u.install&&(0,a.jsx)("button",{ref:r,type:"button",className:"install-banner-btn-install",onClick:()=>void c(),children:u.install}),(0,a.jsx)("button",{type:"button",className:"install-banner-btn-dismiss",onClick:o,children:"Not now"})]})]})})}let rh=["chat","connector","figma","files","editor","browser","terminal","review","agents","integ"],rp=["keiko","settings","project","search","plugins","automations","mobile","inspector","activity","notifications","resources","quality","relationships"];function rm(){var e,t,n,s,r,o,c,d,u;let{theme:h,toggle:p}=function(){let[e,t]=(0,l.useState)(ar),[n,a]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(ai);return"light"===e||"dark"===e?e:ar}catch(e){return ar}}()),a(!0)},[]),(0,l.useEffect)(()=>{if(n){"undefined"!=typeof document&&(document.documentElement.dataset.theme=e);try{window.localStorage.setItem(ai,e)}catch(e){}}},[e,n]),{theme:e,toggle:(0,l.useCallback)(()=>{t(e=>"light"===e?"dark":"light")},[])}}(),m=w(),f=function(){var e;let[t,n]=(0,l.useState)(t8),[a,s]=(0,l.useState)(""),[i,r]=(0,l.useState)(!0),[o,c]=(0,l.useState)("idle"),d=tQ(o),u=(0,l.useRef)("idle"),h=(0,l.useRef)(null),[p,m]=(0,l.useState)(),[f,g]=(0,l.useState)(),[v,x]=(0,l.useState)(),[y,b]=(0,l.useState)(!0),[j,w]=(0,l.useState)(1200),k=(0,l.useRef)(void 0),N=(0,l.useRef)(0),S=(0,l.useRef)([]),[C,R]=(0,l.useState)([]),[E,I]=(0,l.useState)([]),T=(0,l.useCallback)(async e=>{var n;let a;if(0===e.size)return{ok:!1,reason:"empty"};if(e.size>8388608)return{ok:!1,reason:"oversized"};let l=(n=e.type).startsWith("image/")?"image":tV.some(e=>n.startsWith(e))||tX.has(n)?"document":"unsupported-type";if("unsupported-type"===l)return{ok:!1,reason:"unsupported-type"};let s=t.models.find(e=>e.id===t.selectedModel);if(void 0!==s&&("image"===l&&!s.supportsImageInput||"document"===l&&!s.supportsDocumentInput))return{ok:!1,reason:"text-only-model"};if("image"===l)try{a=await new Promise((t,n)=>{let a=new FileReader;a.onload=()=>t(a.result),a.onerror=()=>n(Error("FileReader error")),a.readAsDataURL(e)})}catch(e){return{ok:!1,reason:"unsupported-type"}}let i={id:crypto.randomUUID(),kind:l,name:e.name,mimeType:e.type,sizeBytes:e.size,previewDataUrl:a,file:e};return R(e=>[...e,i]),{ok:!0}},[t.models,t.selectedModel]),F=(0,l.useCallback)(e=>{R(t=>t.filter(t=>t.id!==e))},[]),q=(0,l.useCallback)(()=>{R([])},[]),A=(0,l.useCallback)(async()=>{let e=C.filter(e=>"document"===e.kind&&void 0!==e.file).map(e=>({id:e.id,name:e.name,mimeType:e.mimeType,sizeBytes:e.sizeBytes,file:e.file}));if(0===e.length)return{entries:[],disclosures:[]};let{entries:t,failures:n}=await tJ(e);n.length>0&&m(n.join(" "));let a=t.map(e=>({id:e.id,displayName:e.displayName,truncated:e.truncated}));return{entries:t,disclosures:a}},[C]),M=(0,l.useCallback)(()=>{x(void 0)},[]),P=(0,l.useCallback)((e,t)=>({enabled:y,budgetTokens:j,context:{userId:"local-operator",workspaceId:t.path,projectId:t.path,conversationId:e.id}}),[j,y]),D=(0,l.useCallback)(async e=>{await (0,tD.mc)(e),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)})},[]),L=(0,l.useCallback)(async e=>{await (0,tD.RT)(e),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)})},[]),z=(0,l.useCallback)(async e=>{await (0,tD.hz)(e,"user-initiated forget from Conversation Center"),x(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"forget"!==t.kind||t.memoryId!==e)})},[]),O=(0,l.useCallback)(e=>{u.current=e,c(e)},[]);(0,l.useEffect)(()=>{var e;k.current=null==(e=t.activeChat)?void 0:e.id},[null==(e=t.activeChat)?void 0:e.id]),(0,l.useEffect)(()=>{S.current=t.models},[t.models]),(0,l.useEffect)(()=>{let e=!1;return async function(){r(!0),m(void 0);try{let t=await t9();e||n(e=>({...e,...t}))}catch(t){e||m(t3(t))}finally{e||r(!1)}}(),()=>{e=!0}},[]),(0,l.useEffect)(()=>()=>{var e;null==(e=h.current)||e.abort()},[]);let K=(0,l.useCallback)(e=>{let t;m(void 0),n(n=>(t={selectedModel:n.selectedModel,activeChat:n.activeChat,chats:n.chats},{...n,selectedModel:e,activeChat:void 0===n.activeChat?n.activeChat:{...n.activeChat,selectedModel:e},chats:n.chats.map(t=>void 0!==n.activeChat&&t.id===n.activeChat.id?{...t,selectedModel:e}:t)})),R(t=>t.filter(t=>(function(e,t,n){let a=n.find(e=>e.id===t);return void 0===a||("image"===e.kind?a.supportsImageInput:a.supportsDocumentInput)})(t,e,S.current)));let a=k.current;if(void 0===a)return;let l=N.current+1;N.current=l,(0,$.wi)(a,{selectedModel:e}).then(e=>{N.current===l&&k.current===e.chat.id&&n(t=>{var n;return{...t,selectedModel:e.chat.selectedModel,activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.chat.id?e.chat:t.activeChat,chats:t.chats.map(t=>t.id===e.chat.id?e.chat:t)}})}).catch(e=>{if(N.current===l&&k.current===a&&(m(t3(e)),void 0!==t)){let e=t;n(t=>{var n,l;return{...t,selectedModel:(null==(n=t.activeChat)?void 0:n.id)===a?e.selectedModel:t.selectedModel,activeChat:(null==(l=t.activeChat)?void 0:l.id)===a?e.activeChat:t.activeChat,chats:t.chats.map(t=>{if(t.id!==a)return t;let n=e.chats.find(e=>e.id===a);return void 0!==n?{...t,selectedModel:n.selectedModel}:t})}})}})},[]),B=(0,l.useCallback)(async(e,a)=>{let l=t5(t.selectedModel,t.models);if(void 0===l)return void m("No conversation-eligible model is configured. Connect a gateway in Settings.");m(void 0);try{var s,i;let r=null==a?void 0:a.trim(),o={modelId:l,title:void 0!==r&&r.length>0?r:tY},c=null!=(i=null==e?void 0:e.path)?i:null==(s=t.activeProject)?void 0:s.path;void 0!==c&&(o.projectPath=c);let d=await (0,$.tA)(o);k.current=d.chat.id,n({projects:Array.from(d.projects),chats:t4(d.chats),messages:Array.from(d.messages),models:t.models,activeProject:d.project,activeChat:d.chat,selectedModel:d.chat.selectedModel})}catch(e){m(t3(e))}},[t.selectedModel,t.activeProject,t.models]),W=(0,l.useCallback)(async e=>{m(void 0),n(t=>({...t,activeProject:e}));try{let a=await (0,$.Oz)(e.path),l=t4(a.chats),s=l[0];if(void 0===s)return void await B(e);let i=await (0,$.T$)(s.id,e.path);k.current=s.id;let r=t5(s.selectedModel,t.models);n(e=>({...e,chats:l,activeChat:s,selectedModel:r,messages:Array.from(i.messages)})),x(void 0)}catch(e){m(t3(e))}},[B,t.models]),U=(0,l.useCallback)(async e=>{var a;m(void 0),null==(a=h.current)||a.abort(),h.current=null,k.current=e.id,g(void 0),x(void 0),I([]);try{let a=await (0,$.T$)(e.id,e.projectPath),l=t5(e.selectedModel,t.models);n(t=>{let n=t.projects.find(t=>t.path===e.projectPath);return{...t,activeProject:n,activeChat:e,selectedModel:l,messages:Array.from(a.messages)}})}catch(e){m(t3(e))}},[t.models]),_=(0,l.useCallback)(async e=>{let t=e.trim();if(0!==t.length){m(void 0);try{let e=await (0,$.gA)({path:t}),a=await (0,$.vj)();n(e=>({...e,projects:Array.from(a.projects)})),await B(e.project)}catch(e){m(t3(e))}}},[B]),H=(0,l.useCallback)(e=>{n(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}))},[]),G=(0,l.useCallback)((e,t,a)=>{let l=!1;return{onToken:t=>{l||(O("streaming"),l=!0),n(n=>({...n,messages:n.messages.map(n=>n.id===e?{...n,content:n.content+t}:n)}))},onDone:l=>{n(n=>({...n,activeChat:l.chat,chats:t4([l.chat,...n.chats.filter(e=>e.id!==l.chat.id)]),messages:[...n.messages.filter(n=>n.id!==t&&n.id!==e),...Array.from(l.messages)]})),void 0!==l.memory&&x(l.memory),a("completed")},onError:t=>{let{message:n}=t;m(n),H(e),a("failed")},onCancelled:()=>{H(e),a("cancelled")}}},[H,O]),J=(0,l.useCallback)((e,t,a,l,s,i,r)=>{let o="stream-".concat(String(Date.now()));n(t=>({...t,messages:[...t.messages,{id:o,chatId:e.id,role:"assistant",content:"",timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0}]}));let c={chatId:e.id,projectPath:t.path,content:a,modelId:s,memory:P(e,t),...r.length>0?{documentContext:r}:{}};return new Promise((e,t)=>{let n=G(o,l,e);(0,$.nk)(c,i,n).catch(n=>{H(o),n instanceof $.ZF?t(n):n instanceof DOMException&&"AbortError"===n.name?e("cancelled"):e("failed")})})},[P,G,H]),V=(0,l.useCallback)(async(e,t,a,l,s,i,r)=>{try{O("contacting");let o=await (0,$.xp)({chatId:e.id,projectPath:t.path,content:a,modelId:s,memory:P(e,t),...r.length>0?{documentContext:r}:{}},i);if(i.aborted)return"cancelled";return n(e=>({...e,activeChat:o.chat,chats:t4([o.chat,...e.chats.filter(e=>e.id!==o.chat.id)]),messages:[...e.messages.filter(e=>e.id!==l),...Array.from(o.messages)]})),x(o.memory),"completed"}catch(a){if(a instanceof DOMException&&"AbortError"===a.name)return"cancelled";m(t3(a));try{let a=await (0,$.T$)(e.id,t.path);n(e=>({...e,messages:Array.from(a.messages)}))}catch(e){n(e=>({...e,messages:e.messages.filter(e=>e.id!==l)}))}return"failed"}},[P,O]),X=(0,l.useCallback)(async(e,n,a,l,s,i,r)=>{var o;if((null==(o=t.models.find(e=>e.id===s))?void 0:o.streaming)!==!0)return V(e,n,a,l,s,i,r);O("contacting");try{return await J(e,n,a,l,s,i,r)}catch(e){if(!(e instanceof $.ZF))throw e}return V(e,n,a,l,s,i,r)},[t.models,V,J,O]),Y=(0,l.useCallback)(async(e,t,a,l,s,i)=>{g(void 0);try{O("contacting");let l=await (0,$.Wk)({chatId:e.id,content:a,modelId:s},i);if(k.current!==e.id)return"completed";if(i.aborted)return"cancelled";g(l),x(void 0);let[r,o]=await Promise.all([(0,$.T$)(e.id,t.path),(0,$.Oz)(t.path)]),c=o.chats.find(t=>t.id===e.id);return n(e=>({...e,messages:Array.from(r.messages),chats:t4(o.chats),activeChat:null!=c?c:e.activeChat})),"completed"}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return"cancelled";return m(t3(e)),n(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),"failed"}},[O]),Z=(0,l.useCallback)(()=>{var e;tQ(u.current)&&(null==(e=h.current)||e.abort(),h.current=null,O("cancelled"))},[O]),Q=(0,l.useCallback)(async()=>{var e,l,i,r;if(tQ(u.current))return;let o=a.trim(),c=t.activeChat,d=t.activeProject,p=t5(t.selectedModel,t.models);if(0===o.length||void 0===c||void 0===d||void 0===p)return;if(t2((0,tL.pk)({modelContextWindow:null!=(i=null==(e=t.models.find(e=>e.id===p))?void 0:e.contextWindow)?i:0,modelMaxOutputTokens:null!=(r=null==(l=t.models.find(e=>e.id===p))?void 0:l.maxOutputTokens)?r:0,userDraftText:o,conversationHistory:t.messages.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({role:e.role,content:e.content}))})))return void m(t$);let f={id:"local-".concat(String(Date.now())),chatId:c.id,role:"user",content:o,timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0};O("queued"),s(""),m(void 0),n(e=>({...e,messages:[...e.messages,f]}));let g=new AbortController;h.current=g,x(void 0);try{let e=void 0!==c.connectedScope||void 0!==c.localKnowledgeScope,{entries:t,disclosures:n}=e?{entries:[],disclosures:[]}:await A(),a=e?await Y(c,d,o,f.id,p,g.signal):await X(c,d,o,f.id,p,g.signal,t);"cancelled"===u.current||O(a),"completed"===a&&(q(),I(n))}finally{h.current=null}},[a,t.activeChat,t.activeProject,t.selectedModel,t.models,t.messages,Y,X,A,q,O]),ee=(0,l.useCallback)(()=>{g(void 0),x(void 0),n(e=>({...e,messages:[]}))},[]),et=(0,l.useMemo)(()=>{let e=t.models.find(e=>e.id===t.selectedModel);if(void 0===e)return;let n=t.messages.filter(e=>"user"===e.role||"assistant"===e.role).map(e=>({role:e.role,content:e.content})),l=0,s=0;void 0!==f&&(("connected-context"===f.groundingKind||"hybrid"===f.groundingKind)&&(l=("hybrid"===f.groundingKind?f.contextPack.folder:f.contextPack).usage.excerptBytes),("local-knowledge"===f.groundingKind||"hybrid"===f.groundingKind)&&(s=4*("hybrid"===f.groundingKind?f.contextPack.knowledge:f.contextPack).referenceBudget));let i=y&&void 0!==v&&v.context.enabled?v.context.text.length:0;return(0,tL.pk)({modelContextWindow:e.contextWindow,modelMaxOutputTokens:e.maxOutputTokens,userDraftText:a,conversationHistory:n,repoContextPackBytes:l,knowledgeCapsuleBytes:s,memoryContextBytes:i})},[t.models,t.selectedModel,t.messages,a,f,v,y]),en=(0,l.useCallback)(async e=>{if(tQ(u.current))return{ok:!1,reason:"request-failed",message:"A request is already in flight."};let a=e.text.trim();if(0===a.length)return{ok:!1,reason:"missing-input"};let l=t.activeChat,s=t.activeProject;if(void 0===l||void 0===s)return{ok:!1,reason:"missing-chat"};let i=t.models.find(t=>t.id===e.modelId);if(void 0===i||!tN(i))return{ok:!1,reason:"not-workflow-eligible"};let r=tk(e.workflowId);if(void 0===r)return{ok:!1,reason:"unknown-workflow"};let o=Date.now(),c=r.buildInput(s.path,a);try{let t=await (0,$.qV)({chatId:l.id,projectPath:s.path,run:{workflowId:e.workflowId,input:c,modelId:e.modelId},user:{content:a,timestamp:o},summary:{content:"Launched: ".concat(r.label),timestamp:o+1}});return n(e=>({...e,messages:Array.from(t.messages)})),{ok:!0,runId:t.run.runId}}catch(t){let e=t3(t);return m(e),{ok:!1,reason:"request-failed",message:e}}},[t.activeChat,t.activeProject,t.models]),ea=(0,l.useCallback)(async e=>{if(tQ(u.current))return{ok:!1,reason:"request-failed",message:"A request is already in flight."};if(void 0===t.activeChat)return{ok:!1,reason:"missing-chat"};if(0===e.modelId.trim().length)return{ok:!1,reason:"missing-model"};try{let t=await (0,$.Is)({assistantMessageId:e.assistantMessageId,modelId:e.modelId,workflowKind:e.workflowKind,input:e.input,editablePaths:e.editablePaths,...void 0===e.expectedChecks?{}:{expectedChecks:e.expectedChecks},...void 0===e.unknowns?{}:{unknowns:e.unknowns},requestedAtMs:Date.now()});return n(e=>({...e,messages:Array.from(t.messages)})),{ok:!0,runId:t.run.runId}}catch(t){let e=t3(t);return m(e),{ok:!1,reason:"request-failed",message:e}}},[t.activeChat]),el=(0,l.useCallback)(e=>{n(t=>{var n;return{...t,chats:t.chats.map(t=>t.id===e.id?e:t),activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.id?e:t.activeChat}})},[]);return{projects:t.projects,chats:t.chats,messages:t.messages,models:t.models,activeProject:t.activeProject,activeChat:t.activeChat,selectedModel:t.selectedModel,noEligibleModels:!i&&void 0===t5(t.selectedModel,t.models),draft:a,loading:i,sending:d,sendStatus:o,error:p,setDraft:s,setSelectedModel:K,openNewChat:B,openProject:W,openChat:U,addProject:_,sendMessage:Q,cancelSend:Z,replaceChat:el,latestGrounded:f,cancelGrounded:Z,pendingAttachments:C,addPendingAttachment:T,removePendingAttachment:F,clearPendingAttachments:q,lastSentDocuments:E,budget:et,memoryEnabled:y,setMemoryEnabled:b,memoryBudgetTokens:j,setMemoryBudgetTokens:w,latestMemory:v,clearLatestMemory:M,acceptMemoryCandidate:D,rejectMemoryCandidate:L,forgetMemoryAction:z,clearHistory:ee,launchWorkflowFromConversation:en,launchGroundedWorkflowHandoff:ea}}(),g=(0,l.useRef)(null),[v,x]=(0,l.useState)(tL.ty);(0,l.useEffect)(()=>{(0,$.Dz)().then(e=>x(e.effectiveGroundingLimits)).catch(()=>void 0)},[]);let y=(0,l.useCallback)(e=>{let t=f.activeChat;if(void 0===t)return;let n=ep(t),a=function(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16;if(!ed(t))return null;if(e.some(e=>e.root===t))return e;let l=[...e,{kind:"workspace-root",relativePaths:[],root:t,connectedAtMs:n}];return l.length>a?l.slice(-a):l}(n,e,Date.now(),v.maxConnectedSources);null!==a&&a!==n&&(0,$.Mr)(t.id,a).then(n=>{var a;f.replaceChat(n.chat),a=t.id,0!==a.length&&0!==e.length&&ay({type:"reads-context",source:{kind:"chat",id:a},target:{kind:"workspace-path",id:e}},function(e,t){let n=0x811c9dc5,a="".concat(e,"|").concat(t);for(let e=0;e<a.length;e+=1)n=Math.imul(n^a.charCodeAt(e),0x1000193);return"rc-".concat((n>>>0).toString(36),"-").concat((65535&a.length).toString(36))}(a,e)).catch(e=>{})}).catch(e=>{console.warn("[keiko] connected-scope bind failed",e)})},[f,v.maxConnectedSources]),b=(0,l.useCallback)(e=>{var t;let n=f.activeChat;if(void 0===n)return;let a=(t=ep(n),t.filter(t=>t.root!==e));(0,$.Mr)(n.id,a.length>0?a:null).then(e=>{f.replaceChat(e.chat)}).catch(e=>{console.warn("[keiko] connected-scope unbind failed",e)})},[f]),j=function(e){var t,n,a,s,i,r;let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[c,d]=(0,l.useState)(null),[u,h]=(0,l.useState)(null),[p,m]=(0,l.useState)(!1),[f,g]=(0,l.useState)([]),[v,x]=(0,l.useState)(null),[y,b]=(0,l.useState)(nH),j=(0,l.useRef)(3),w=(0,l.useRef)(null),k=(0,l.useRef)([]);k.current=null!=c?c:[];let N=(0,l.useRef)([]);N.current=f;let S=(0,l.useRef)(null);S.current=v;let C=(0,l.useRef)(null),R=(0,l.useRef)(()=>void 0),{viewRef:E,worldVP:I,zoomTo:T,resetView:F,panBy:q,rect:A}=function(e){let{wsRef:t,view:n,setView:a}=e,s=(0,l.useRef)(n);s.current=n,(0,l.useEffect)(()=>{nX(n_,n)},[n]),(0,l.useEffect)(()=>{let e=t.current;if(null===e)return;let n=t=>{if(t.metaKey||t.ctrlKey){t.preventDefault();let n=e.getBoundingClientRect(),l=s.current,i=nG(l.zoom*Math.exp(-(.0015*t.deltaY))),r=(t.clientX-n.left-l.x)/l.zoom,o=(t.clientY-n.top-l.y)/l.zoom;a({zoom:i,x:t.clientX-n.left-r*i,y:t.clientY-n.top-o*i});return}let n=t.target;n instanceof Element&&null!==n.closest(".window")||(t.preventDefault(),a(e=>({...e,x:e.x-t.deltaX,y:e.y-t.deltaY})))};return e.addEventListener("wheel",n,{passive:!1}),()=>{e.removeEventListener("wheel",n)}},[t,a]);let i=(0,l.useCallback)(()=>null===t.current?null:t.current.getBoundingClientRect(),[t]),r=(0,l.useCallback)(()=>{let e=i();if(null===e)return null;let t=s.current;return{x:-t.x/t.zoom,y:-t.y/t.zoom,w:e.width/t.zoom,h:e.height/t.zoom}},[i]),o=(0,l.useCallback)(e=>{let t=i();if(null===t)return;let n=s.current,l=t.width/2,r=t.height/2,o=(l-n.x)/n.zoom,c=(r-n.y)/n.zoom,d=nG(e);a({zoom:d,x:l-o*d,y:r-c*d})},[i,a]);return{viewRef:s,worldVP:r,zoomTo:o,resetView:(0,l.useCallback)(()=>a({zoom:1,x:0,y:0}),[a]),panBy:(0,l.useCallback)((e,t)=>a(n=>({...n,x:n.x+e,y:n.y+t})),[a]),rect:i}}({wsRef:e,view:y,setView:b});!function(e){let{wsRef:t,setWins:n,setConns:a,zc:s}=e;(0,l.useLayoutEffect)(()=>{let e=t.current;if(null===e)return;e.getBoundingClientRect();let l=null;try{l=function(e){if(null===e)return null;try{let t=JSON.parse(e);if(!Array.isArray(t)||0===t.length)return null;let n=nK(t);return n.length>0?n:null}catch(e){return null}}(window.localStorage.getItem(nW))}catch(e){l=null}null===l&&(l=[]),s.current=0===l.length?1:Math.max(1,...l.map(e=>e.z)),n(l);try{a(function(e,t){if(null===e)return[];try{let n=JSON.parse(e);if(!Array.isArray(n))return[];return nB(n,t)}catch(e){return[]}}(window.localStorage.getItem(nU),l))}catch(e){}},[t,n,a,s])}({wsRef:e,setWins:d,setConns:g,zc:j}),(0,l.useEffect)(()=>{null!==c&&nX(nU,nB(f,c))},[f,c]),(0,l.useEffect)(()=>{null!==c&&g(e=>{let t=e.filter(e=>void 0!==c.find(t=>t.id===e.a)&&void 0!==c.find(t=>t.id===e.b));return t.length===e.length?e:t})},[c,g]),(0,l.useEffect)(()=>{null!==c&&nX(nW,nK(c))},[c]),function(e){let{setWins:t,rect:n,cancelConnectRef:a}=e;(0,l.useEffect)(()=>{let e=e=>{var l,s;if("Escape"===e.key)return void a.current();if(null!==(l=document.activeElement)&&("INPUT"===l.tagName||"TEXTAREA"===l.tagName||"SELECT"===l.tagName))return;let i=nY[e.code];if((e.metaKey||e.ctrlKey)&&e.altKey&&void 0!==i){e.preventDefault(),t(e=>{var t,n;if(null===e||0===e.length)return e;let a=nV(e),l=(n=null!=(t=a.zoom)?t:1,"0"===i?1:"-"===i||"_"===i?nJ(n-.1):nJ(n+.1));return e.map(e=>e.id===a.id?{...e,zoom:l}:e)});return}if(!/^Arrow/.test(e.key))return;let r=e.metaKey||e.ctrlKey,o=e.altKey;if(!r&&!o)return;e.preventDefault();let c=n();null!==c&&(s={key:e.key,shift:e.shiftKey},t(e=>{if(null===e||0===e.length)return e;let t=nV(e),n=o?function(e,t,n){let a=n.shift?1:16,l=e.w,s=e.h;"ArrowRight"===n.key?l+=a:"ArrowLeft"===n.key?l-=a:"ArrowDown"===n.key?s+=a:"ArrowUp"===n.key&&(s-=a);let i=ei[e.type].min;return l=Math.max(i.w,Math.min(t.width,l)),s=Math.max(i.h,Math.min(t.height,s)),{x:e.x,y:e.y,w:l,h:s}}(t,c,s):function(e,t,n){let a=n.shift?1:16,l=e.x,s=e.y;return"ArrowRight"===n.key?l+=a:"ArrowLeft"===n.key?l-=a:"ArrowDown"===n.key?s+=a:"ArrowUp"===n.key&&(s-=a),{x:l=Math.max(-(e.w-120),Math.min(t.width-120,l)),y:s=Math.max(0,Math.min(t.height-38,s)),w:e.w,h:e.h}}(t,c,s);return e.map(e=>e.id===t.id?{...e,...n,max:!1}:e)}))};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}},[t,n,a])}({setWins:d,rect:A,cancelConnectRef:R}),function(e){let{wsRef:t,viewRef:n,setWins:a}=e;(0,l.useEffect)(()=>{let e=t.current;if(null===e||"undefined"==typeof ResizeObserver)return;let l=new ResizeObserver(()=>{let t=e.getBoundingClientRect(),l=n.current,s={x:-l.x/l.zoom,y:-l.y/l.zoom,w:t.width/l.zoom,h:t.height/l.zoom};a(e=>null===e?e:e.map(e=>(function(e,t){if(e.max)return{...e,x:t.x,y:t.y,w:t.w,h:t.h};let n=Math.max(t.x-(e.w-120),Math.min(t.x+t.w-120,e.x)),a=Math.max(t.y,Math.min(t.y+t.h-38,e.y));return n===e.x&&a===e.y?e:{...e,x:n,y:a}})(e,s)))});return l.observe(e),()=>{l.disconnect()}},[t,n,a])}({wsRef:e,viewRef:E,setWins:d});let{update:M,focus:P,close:D,maximize:L,add:z,toggleTool:O}={update:(n=(t={setWins:d,zc:j,worldVP:I}).setWins,(e,t)=>n(n=>null===n?n:n.map(n=>n.id===e?{...n,...t}:n))),focus:(a=t.setWins,s=t.zc,e=>a(t=>null===t?t:t.map(t=>t.id===e?{...t,z:++s.current}:t))),close:(i=t.setWins,e=>i(t=>null===t?t:t.filter(t=>t.id!==e))),maximize:function(e){let{setWins:t,zc:n,worldVP:a}=e;return e=>t(t=>{if(null===t)return t;let l=a();return null===l?t:t.map(t=>t.id!==e?t:t.max&&void 0!==t.prev?{...t,x:t.prev.x,y:t.prev.y,w:t.prev.w,h:t.prev.h,max:!1,z:++n.current}:{...t,max:!0,prev:{x:t.x,y:t.y,w:t.w,h:t.h},x:l.x,y:l.y,w:l.w,h:l.h,z:++n.current})})}(t),add:function(e){let{setWins:t,zc:n,worldVP:a}=e;return(e,l)=>{let s=ei[e],i=null;return t(t=>{let r=a();if(null===r)return t;let o=null!=t?t:[];if(!0===s.singleton){let t=o.find(t=>t.type===e);if(void 0!==t)return i=t.id,o.map(e=>e.id===t.id?{...e,z:++n.current}:e)}let c="qiRun"===e?null==l?void 0:l.runId:void 0;if("string"==typeof c&&c.length>0){let e=o.find(e=>"qiRun"===e.type&&e.cfg.runId===c);if(void 0!==e)return i=e.id,o.map(t=>t.id===e.id?{...t,z:++n.current}:t)}let{x:d,y:u}=er(r,s.w,s.h,o.length,40),h=!0===s.singleton?e:"".concat(e,"-").concat(Date.now().toString(36));return i=h,[...o,{id:h,type:e,x:d,y:u,w:s.w,h:s.h,z:++n.current,cfg:null!=l?l:{},max:!1,zoom:1}]}),i}}(t),toggleTool:function(e){let{setWins:t,zc:n,worldVP:a}=e;return e=>{let l=ei[e];t(t=>{let s=a();if(null===s)return t;let i=null!=t?t:[];if(void 0!==i.find(t=>t.type===e))return i.filter(t=>t.type!==e);let{x:r,y:o}=er(s,l.w,l.h,i.length,28);return[...i,{id:e,type:e,x:r,y:o,w:l.w,h:l.h,z:++n.current,cfg:{},max:!1,zoom:1}]})}}(t)},{tileAll:K,splitFront:B,cascade:W}={tileAll:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e||0===e.length)return e;let t=n();if(null===t)return e;let a=e.length,l=Math.ceil(Math.sqrt(a)),s=Math.ceil(a/l),i=(t.w-12*(l+1))/l,r=(t.h-12*(s+1))/s;return e.map((e,n)=>{let a=Math.floor(n/l);return{...eo(e),max:!1,x:t.x+12+n%l*(i+12),y:t.y+12+a*(r+12),w:i,h:r}})})}(r={setWins:d,worldVP:I}),splitFront:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e||0===e.length)return e;let t=n();if(null===t)return e;let a=[...e].sort((e,t)=>t.z-e.z).slice(0,2).map(e=>e.id);return e.map(e=>{let n=a.indexOf(e.id);return 0===n?{...eo(e),max:!1,x:t.x,y:t.y,w:t.w/2,h:t.h}:1===n?{...eo(e),max:!1,x:t.x+t.w/2,y:t.y,w:t.w/2,h:t.h}:e})})}(r),cascade:function(e){let{setWins:t,worldVP:n}=e;return()=>t(e=>{if(null===e)return e;let t=n();return null===t?e:e.map((e,n)=>({...eo(e),max:!1,x:t.x+24+30*n,y:t.y+24+30*n,w:Math.min(560,t.w-80),h:Math.min(420,t.h-80),z:n+1}))})}(r)},{setSnap:U,commitSnap:_}=function(e){let{setSnapPrev:t,snapZone:n,worldVP:a,update:l}=e;return{setSnap:e=>{if(n.current=e,null===e)return void t(null);let l=a();null!==l&&t(V(l)[e])},commitSnap:e=>{let s=n.current;if(n.current=null,t(null),null===s)return;let i=a();if(null===i)return;let r={...V(i)[s],max:"maxi"===s};"maxi"===s&&(r.prev={x:i.x+40,y:i.y+40,w:480,h:360}),l(e,r)}}}({setSnapPrev:h,snapZone:w,worldVP:I,update:M}),{startConnect:H,confirmConnect:J,cancelConnect:X,removeConn:Y,connect:Z,linkedFilesRoot:Q,linkedFilesContext:$,linkedAllFilesRoots:ee,linkedConnectorCapsuleIds:et,linkedConnectorCapsuleSetIds:en,linkedFigmaSnapshotRunIds:ea,currentFilesContext:el}=function(e){let{wsRef:t,viewRef:n,winsRef:a,connsRef:l,connectingRef:s,connectCleanupRef:i,focus:r,setConns:o,setConnecting:c,onScopeBind:d,onScopeUnbind:u,onConnectorBind:h,onConnectorUnbind:p}=e,m=()=>{null!==i.current&&(i.current(),i.current=null),s.current=null,c(null)},f=e=>{if("files"!==e.type)return null;let t=e.cfg.resolvedRoot,n=e.cfg.root,a="string"==typeof t&&t.length>0?t:"string"==typeof n&&n.length>0?n:"src",l=e.cfg.activeFilePath;return{id:e.id,root:a,..."string"==typeof l&&l.length>0?{activeFilePath:l}:{}}},g=e=>{let t=[];for(let n of l.current){let l=n.a===e?n.b:n.b===e?n.a:null;if(null===l)continue;let s=a.current.find(e=>e.id===l);void 0!==s&&"files"===s.type&&t.push(s)}if(0===t.length)return null;let n=[...t].sort((e,t)=>t.z-e.z),s=n.find(e=>{let t=e.cfg.activeFilePath;return"string"==typeof t&&t.length>0}),i=null!=s?s:n[0];return void 0===i?null:f(i)},v=(e,t)=>{let n=new Set,s=[];for(let i of l.current){if(s.length>=16)break;let l=i.a===e?i.b:i.b===e?i.a:null;if(null===l)continue;let r=a.current.find(e=>e.id===l);if(void 0===r||"connector"!==r.type||r.cfg.selectedKind!==t)continue;let o=r.cfg.selectedId;"string"==typeof o&&0!==o.length&&(n.has(o)||(n.add(o),s.push(o)))}return s};return{startConnect:(e,a)=>{if(a.preventDefault(),a.stopPropagation(),null!==s.current&&s.current.from===e)return void m();let l=t.current;if(null===l)return;let r=l.getBoundingClientRect(),o=n.current,d=e=>(e-r.left-o.x)/o.zoom,u=e=>(e-r.top-o.y)/o.zoom;null!==i.current&&(i.current(),i.current=null);let h={from:e,x:d(a.clientX),y:u(a.clientY)};s.current=h,c(h);let p=t=>{let n={from:e,x:d(t.clientX),y:u(t.clientY)};s.current=n,c(n)};window.addEventListener("pointermove",p),i.current=()=>{window.removeEventListener("pointermove",p)}},confirmConnect:(e,t)=>{t.preventDefault(),t.stopPropagation();let n=s.current;if(null===n)return;let l=a.current,i=l.find(e=>e.id===n.from),c=l.find(t=>t.id===e);if(void 0!==i&&void 0!==c&&G(i.type,c.type)){o(t=>ec(t,n.from,e)?t:[...t,{id:"".concat(n.from,"~").concat(e),a:n.from,b:e}]),r(e);let t=eh(i,c);null!==t&&(null==d||d(t));let a=eg(i,c);null!==a&&(null==h||h(a))}m()},cancelConnect:m,removeConn:e=>{let t=l.current.find(t=>t.id===e);if(o(t=>t.filter(t=>t.id!==e)),void 0===t)return;let n=a.current,s=n.find(e=>e.id===t.a),i=n.find(e=>e.id===t.b);if(void 0===s||void 0===i)return;let r=eh(s,i);null!==r&&(null==u||u(r));let c=eg(s,i);null!==c&&(null==p||p(c))},connect:(e,t)=>{let n=a.current,l=n.find(t=>t.id===e),s=n.find(e=>e.id===t);void 0!==l&&void 0!==s&&G(l.type,s.type)&&o(n=>ec(n,e,t)?n:[...n,{id:"".concat(e,"~").concat(t),a:e,b:t}])},linkedFilesRoot:e=>{var t,n;return null!=(n=null==(t=g(e))?void 0:t.root)?n:null},linkedFilesContext:g,linkedAllFilesRoots:e=>{let t=new Set,n=[];for(let s of l.current){if(n.length>=16)break;let l=s.a===e?s.b:s.b===e?s.a:null;if(null===l)continue;let i=a.current.find(e=>e.id===l);if(void 0===i)continue;let r=eu(i);null===r||t.has(r)||(t.add(r),n.push(r))}return n},linkedConnectorCapsuleIds:e=>v(e,"capsule"),linkedConnectorCapsuleSetIds:e=>v(e,"capsule-set"),linkedFigmaSnapshotRunIds:e=>{let t=new Set,n=[];for(let s of l.current){if(n.length>=16)break;let l=s.a===e?s.b:s.b===e?s.a:null;if(null===l)continue;let i=a.current.find(e=>e.id===l);if(void 0===i||"figma"!==i.type)continue;let r=i.cfg.snapshotRunId;"string"==typeof r&&0!==r.length&&(t.has(r)||(t.add(r),n.push(r)))}return n},currentFilesContext:()=>{var e;let t=a.current.map(e=>f(e)).filter(e=>null!==e);if(1===t.length)return null!=(e=t[0])?e:null;let n=[...a.current].filter(e=>"files"===e.type).sort((e,t)=>t.z-e.z)[0];return void 0===n?null:f(n)}}}({wsRef:e,viewRef:E,winsRef:k,connsRef:N,connectingRef:S,connectCleanupRef:C,focus:P,setConns:g,setConnecting:x,onScopeBind:o.onScopeBind,onScopeUnbind:o.onScopeUnbind,onConnectorBind:o.onConnectorBind,onConnectorUnbind:o.onConnectorUnbind});return R.current=X,(0,l.useEffect)(()=>()=>{null!==C.current&&(C.current(),C.current=null)},[]),{wins:c,snapPrev:u,palOpen:p,setPalOpen:m,conns:f,connecting:v,view:y,api:{add:z,toggleTool:O,focus:P,close:e=>{let t=k.current.find(t=>t.id===e);if(void 0!==t)for(let l of N.current){var n,a;let s=l.a===e?l.b:l.b===e?l.a:null;if(null===s)continue;let i=k.current.find(e=>e.id===s);if(void 0===i)continue;let r=eh(t,i);null!==r&&(null==(n=o.onScopeUnbind)||n.call(o,r));let c=eg(t,i);null!==c&&(null==(a=o.onConnectorUnbind)||a.call(o,c))}D(e)},maximize:L,update:M,setSnap:U,commitSnap:_,tileAll:K,splitFront:B,cascade:W,startConnect:H,confirmConnect:J,cancelConnect:X,removeConn:Y,connect:Z,linkedFilesRoot:Q,linkedFilesContext:$,linkedAllFilesRoots:ee,linkedConnectorCapsuleIds:et,linkedConnectorCapsuleSetIds:en,linkedFigmaSnapshotRunIds:ea,currentFilesContext:el,zoomTo:T,resetView:F,panBy:q,rect:A}}}(g,{onScopeBind:y,onScopeUnbind:b,onConnectorBind:(0,l.useCallback)(e=>{let t=f.activeChat;if(void 0===t)return;let n=em(t),a=function(e,t,n){let a=ef(t);if(e.some(e=>ef(e)===a))return e;let l=[...e,t];return l.length>n?l.slice(-n):l}(n,e,v.maxLocalKnowledgeSources);a!==n&&(0,$.Cp)(t.id,a).then(e=>{f.replaceChat(e.chat)}).catch(()=>void 0)},[f,v.maxLocalKnowledgeSources]),onConnectorUnbind:(0,l.useCallback)(e=>{var t;let n=f.activeChat;if(void 0===n)return;let a="capsule"===e.kind?"capsule:".concat(e.capsuleId):"set:".concat(e.capsuleSetId),l=(t=em(n),t.filter(e=>ef(e)!==a));(0,$.Cp)(n.id,l.length>0?l:null).then(e=>{f.replaceChat(e.chat)}).catch(()=>void 0)},[f])}),[N,C]=(0,l.useState)(!1),[R,E]=(0,l.useState)(null),[I,T]=(0,l.useState)(!1),F=null!=(r=null==(e=j.wins)?void 0:e.length)?r:0,q=function(e){if(null===e||0===e.length)return null;let t=e[0];for(let n=1;n<e.length;n++){let a=e[n];a.z>t.z&&(t=a)}return t}(j.wins),M=(0,l.useMemo)(()=>(function(e){if(null===e)return new Set;let t=new Set;for(let n of e)!0===ei[n.type].tool&&t.add(n.type);return t})(j.wins),[j.wins]),P=(0,l.useMemo)(()=>{var e;return{wins:null!=(e=j.wins)?e:[],active:q,winCount:F}},[j.wins,q,F]),D=(0,l.useCallback)(()=>C(!0),[]),L=(0,l.useCallback)(()=>C(!1),[]),z=(0,l.useCallback)(()=>{null===q||q.max||j.api.maximize(q.id)},[q,j.api]),K=(0,l.useCallback)(()=>{null!==q&&q.max&&j.api.maximize(q.id)},[q,j.api]),W=(0,l.useCallback)(e=>{C(!1),E(e)},[]),U=(0,l.useCallback)(e=>{if(E(null),null===R)return;let{__connectFilesId:t,...n}=e,a=j.api.add(R,n);if("agents"===R&&null!==a&&"string"==typeof t&&t.length>0&&j.api.connect(a,t),"chat"===R){let e=n.title;f.openNewChat(void 0,"string"==typeof e?e:void 0)}null!==a&&requestAnimationFrame(()=>{var e;let t=document.querySelector('[data-window-id="'.concat(a,'"]'));null!==t&&(null!=(e=t.querySelector("textarea, input, select, button, [tabindex]"))?e:t).focus()})},[R,j.api,f]),_=(0,l.useCallback)(()=>E(null),[]),H=(0,l.useCallback)(()=>T(!1),[]),J=(0,l.useCallback)(()=>T(!0),[]),X=(0,l.useRef)(null),Y=(0,l.useCallback)(e=>{X.current=e},[]),Z=function(e){var t;let{apply:n}=e,a=null!=(t=e.limit)?t:100,[s,i]=(0,l.useState)(aT),r=(0,l.useRef)(n);r.current=n;let o=(0,l.useRef)(s);o.current=s;let c=(0,l.useCallback)(e=>{i(t=>{let n=[...t.undoStack,e];return{undoStack:n.length>a?n.slice(n.length-a):n,redoStack:[]}})},[a]),d=(0,l.useCallback)(()=>{let e=o.current;if(0===e.undoStack.length)return;let t=e.undoStack[e.undoStack.length-1],n=function(e){switch(e.kind){case"ui.window.move":case"ui.window.resize":case"ui.window.zorder":case"ui.workspace.pan":case"ui.workspace.zoom":case"ui.workspace.fit":case"ui.panel.toggle":case"ui.selection.change":case"ui.tab.switch":return{...e,before:e.after,after:e.before};case"ui.window.close":return{...e,kind:"ui.window.open"};case"ui.window.open":return{...e,kind:"ui.window.close"}}}(t);i({undoStack:e.undoStack.slice(0,-1),redoStack:[...e.redoStack,t]}),r.current(n)},[]),u=(0,l.useCallback)(()=>{let e=o.current;if(0===e.redoStack.length)return;let t=e.redoStack[e.redoStack.length-1];i({undoStack:[...e.undoStack,t],redoStack:e.redoStack.slice(0,-1)}),r.current(t)},[]),h=(0,l.useCallback)(()=>{i(aT)},[]);return(0,l.useMemo)(()=>{let e=s.undoStack[s.undoStack.length-1],t=s.redoStack[s.redoStack.length-1];return{canUndo:s.undoStack.length>0,canRedo:s.redoStack.length>0,undoLabel:void 0!==e?aE(e):null,redoLabel:void 0!==t?aE(t):null,push:c,undo:d,redo:u,clear:h}},[s,c,d,u,h])}({apply:(0,l.useCallback)(e=>{var t;return t=j.api,void("ui.panel.toggle"===e.kind&&e.panel in ei&&t.toggleTool(e.panel))},[j.api])}),Q=(0,l.useCallback)(e=>{if(!(e in ei))return;let t=M.has(e);j.api.toggleTool(e),Z.push({kind:"ui.panel.toggle",panel:e,before:t,after:!t})},[j.api,M,Z]),ee=(0,l.useCallback)(()=>W("chat"),[W]),et=(0,l.useRef)(!1);(0,l.useEffect)(()=>{et.current||null===j.wins||(et.current=!0,"/relationships"===window.location.pathname.replace(/\/+$/u,"")&&(j.wins.some(e=>"relationships"===e.type)||Q("relationships"),window.history.replaceState(null,"","/")))},[j.wins,Q]),function(e){var t;let{bindings:n,dispatch:a}=e,s=null!=(t=e.platform)?t:function(){if("undefined"==typeof navigator)return"other";let e=navigator.platform||"";return/Mac|iPhone|iPad|iPod/i.test(e)?"mac":"other"}(),i=(0,l.useRef)(a);i.current=a;let r=(0,l.useMemo)(()=>(function(e){let t=new Map;for(let n of e){let e=aI(n.chord),a=t.get(e);void 0!==a?a.push(n.commandId):t.set(e,[n.commandId])}let n=[];for(let[,a]of t)if(a.length>1){let t=e.find(e=>a.includes(e.commandId));void 0!==t&&n.push({chord:t.chord,commandIds:a})}return n})(n),[n]),o=(0,l.useMemo)(()=>n.filter(e=>(function(e){for(let t of aR)if(aI(e)===aI(t))return!0;return!1})(e.chord)),[n]);if(r.length>0)throw new aF(r);if(o.length>0)throw new aq(o);(0,l.useEffect)(()=>{function e(e){if(!function(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;let t=e.tagName;return"INPUT"===t||"TEXTAREA"===t||"SELECT"===t}(e.target)){for(let t of n)if(function(e,t,n){if(!(e.key.toLowerCase()===t.key.toLowerCase()||t.mod.includes("alt")&&/^[a-z]$/i.test(t.key)&&e.code==="Key".concat(t.key.toUpperCase())))return!1;let a=function(e,t){let n=new Set;for(let a of e)"cmd"===a?n.add("mac"===t?"meta":"ctrl"):"ctrl"===a?n.add("ctrl"):"alt"===a?n.add("alt"):"shift"===a&&n.add("shift");return n}(t.mod,n);return e.metaKey===a.has("meta")&&e.ctrlKey===a.has("ctrl")&&e.altKey===a.has("alt")&&e.shiftKey===a.has("shift")}(e,t.chord,s)){e.preventDefault(),i.current(t.commandId);return}}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[n,s]),(0,l.useMemo)(()=>({bindings:n,conflicts:r,reserved:o}),[n,r,o])}({bindings:aA,dispatch:(0,l.useCallback)(e=>{var t;"undo"===e?Z.undo():"redo"===e?Z.redo():"focus-status"===e&&(null==(t=X.current)||t.focus())},[Z])}),(0,l.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&("k"===e.key||"K"===e.key)&&(e.preventDefault(),T(e=>!e))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let en=(0,l.useMemo)(()=>(function(e,t,n,a,l,s){let i=[];for(let e of rh){let t=ei[e];i.push({id:"new-".concat(e),label:"New ".concat(t.title),group:"Create",icon:t.icon,run:()=>n(e)})}for(let e of rp){let n=ei[e];i.push({id:"open-".concat(e),label:"Open ".concat(n.title),group:"Tools",icon:n.icon,run:()=>t(e)})}return i.push({id:"tile",label:"Tile all windows",group:"Layout",icon:"tile",run:e.tileAll}),i.push({id:"split",label:"Split front windows",group:"Layout",icon:"split",run:e.splitFront}),i.push({id:"cascade",label:"Cascade windows",group:"Layout",icon:"cascade",run:e.cascade}),i.push({id:"theme",label:"Toggle light / dark theme",group:"View",icon:"light"===a?"moon":"sun",run:l}),i.push({id:"undo",label:null!==s.undoLabel?"Undo: ".concat(s.undoLabel):"Undo (window and panel changes only)",group:"Edit",icon:"back",shortcut:"⌘Z",run:s.undo}),i.push({id:"redo",label:null!==s.redoLabel?"Redo: ".concat(s.redoLabel):"Redo (window and panel changes only)",group:"Edit",icon:"fwd",shortcut:"⇧⌘Z",run:s.redo}),i})(j.api,Q,W,h,p,Z),[j.api,Q,W,h,p,Z]),ea=!f.loading&&0===f.models.length,el=(o=null==(t=f.activeProject)?void 0:t.name,f.loading?"Loading project…":void 0!==o&&o.trim().length>0?o:"No project selected"),es=void 0!==f.activeProject,ev=(null==(n=f.activeProject)?void 0:n.available)===!0,ex=(c={loading:f.loading,error:f.error,hasProject:es,projectAvailable:ev,noEligibleModels:f.noEligibleModels}).loading?"Loading shell…":void 0!==c.error?"Shell error":c.hasProject?c.projectAvailable?c.noEligibleModels?"Gateway setup required":"Ready":"Project unavailable":"No project selected",ey=(d={loading:f.loading,error:f.error,hasProject:es,projectAvailable:ev,noEligibleModels:f.noEligibleModels}).loading?{label:"Connecting",tone:"warn"}:void 0!==d.error||d.hasProject&&!d.projectAvailable?{label:"Disconnected",tone:"danger"}:!d.hasProject||d.noEligibleModels?{label:"Setup required",tone:"warn"}:{label:"Connected",tone:"ok"},eb=function(e){let t=(null!=e?e:[]).filter(e=>"review"===e.type);return 0===t.length?"No review open":t.some(e=>"string"==typeof e.cfg.runId&&e.cfg.runId.length>0)?"Evidence ready":"Review window open"}(j.wins),ej=void 0!==(u=null==(s=f.activeChat)?void 0:s.branchLabel)&&u.trim().length>0?u:"No branch selected",ew=N?(0,a.jsx)(as,{types:ei,order:rh,onAdd:W,onClose:L}):null;return(0,a.jsx)(i,{value:f,children:(0,a.jsx)(k.Provider,{value:P,children:(0,a.jsxs)("div",{className:"app",children:[(0,a.jsx)("h1",{className:"visually-hidden",children:"Keiko workspace"}),(0,a.jsx)(A,{mode:m.mode,projectName:el,statusLabel:ey.label,statusTone:ey.tone,onModeChange:m.setMode,openPalette:D,openCommandPalette:J,onTileAll:j.api.tileAll,onSplitFront:j.api.splitFront,onCascade:j.api.cascade,onExpandFront:z,onRestoreFront:K}),(0,a.jsxs)("div",{className:"mid",children:[(0,a.jsx)(O,{openTools:M,onTool:Q,onNewChat:ee,theme:h,onToggleTheme:p}),(0,a.jsx)("div",{className:"stage",children:(0,a.jsx)(n$,{ws:j,wsRef:g,openPalette:D,palette:ew})}),(0,a.jsx)(B,{openTools:M,onTool:Q})]}),(0,a.jsx)(S,{winCount:F,mode:m.mode,selectedModel:f.selectedModel,projectName:el,branchLabel:ej,shellStatusLabel:ex,evidenceStatusLabel:eb,statusRef:Y}),null!==R&&(0,a.jsx)(aa,{type:R,types:ei,filesContext:j.api.currentFilesContext(),onConfirm:U,onClose:_}),I&&(0,a.jsx)(n0,{commands:en,onClose:H}),ea?(0,a.jsx)(n1,{}):null,(0,a.jsx)(ru,{})]})})})}function rf(){let[e,t]=(0,l.useState)(!1);return((0,l.useEffect)(()=>{t(!0)},[]),(0,l.useEffect)(()=>{!function(){if(!("undefined"!=typeof navigator&&"serviceWorker"in navigator))return;let e=navigator.serviceWorker;try{e.register("/sw.js",{scope:"/"}).catch(e=>{})}catch(e){}}()},[]),e)?(0,a.jsx)(j,{children:(0,a.jsx)(rm,{})}):(0,a.jsx)("div",{className:"app","aria-hidden":"true",children:(0,a.jsx)("div",{className:"app-boot",children:(0,a.jsx)("img",{className:"app-boot-logo",src:"/assets/keiko-logo.svg",alt:""})})})}function rg(){return(0,a.jsx)(rf,{})}},9422:(e,t,n)=>{Promise.resolve().then(n.bind(n,7002))}}]);