vskill 1.0.16 → 1.0.18

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 (206) hide show
  1. package/README.md +84 -9
  2. package/agents.json +3 -1
  3. package/dist/agents/agents-registry.d.ts +61 -0
  4. package/dist/agents/agents-registry.js +203 -0
  5. package/dist/agents/agents-registry.js.map +1 -1
  6. package/dist/api/client.d.ts +85 -0
  7. package/dist/api/client.js +193 -24
  8. package/dist/api/client.js.map +1 -1
  9. package/dist/commands/add-lockfile.d.ts +6 -0
  10. package/dist/commands/add-lockfile.js +10 -0
  11. package/dist/commands/add-lockfile.js.map +1 -1
  12. package/dist/commands/add.d.ts +7 -0
  13. package/dist/commands/add.js +110 -2
  14. package/dist/commands/add.js.map +1 -1
  15. package/dist/commands/auth.d.ts +23 -0
  16. package/dist/commands/auth.js +105 -11
  17. package/dist/commands/auth.js.map +1 -1
  18. package/dist/commands/eval/serve.d.ts +2 -0
  19. package/dist/commands/eval/serve.js +126 -4
  20. package/dist/commands/eval/serve.js.map +1 -1
  21. package/dist/commands/orgs.d.ts +21 -0
  22. package/dist/commands/orgs.js +164 -0
  23. package/dist/commands/orgs.js.map +1 -0
  24. package/dist/commands/skill.js +14 -1
  25. package/dist/commands/skill.js.map +1 -1
  26. package/dist/commands/whoami.d.ts +29 -0
  27. package/dist/commands/whoami.js +119 -0
  28. package/dist/commands/whoami.js.map +1 -0
  29. package/dist/discovery/github-tree.d.ts +23 -3
  30. package/dist/discovery/github-tree.js +172 -24
  31. package/dist/discovery/github-tree.js.map +1 -1
  32. package/dist/eval/anthropic-catalog.js +32 -2
  33. package/dist/eval/anthropic-catalog.js.map +1 -1
  34. package/dist/eval/batch-judge.js +1 -0
  35. package/dist/eval/batch-judge.js.map +1 -1
  36. package/dist/eval/llm.d.ts +1 -1
  37. package/dist/eval/llm.js +104 -2
  38. package/dist/eval/llm.js.map +1 -1
  39. package/dist/eval-server/__tests__/helpers/studio-token-test-helpers.d.ts +2 -0
  40. package/dist/eval-server/__tests__/helpers/studio-token-test-helpers.js +20 -0
  41. package/dist/eval-server/__tests__/helpers/studio-token-test-helpers.js.map +1 -0
  42. package/dist/eval-server/active-tenant-routes.d.ts +15 -0
  43. package/dist/eval-server/active-tenant-routes.js +101 -0
  44. package/dist/eval-server/active-tenant-routes.js.map +1 -0
  45. package/dist/eval-server/api-routes.js +17 -2
  46. package/dist/eval-server/api-routes.js.map +1 -1
  47. package/dist/eval-server/desktop-open-routes.d.ts +8 -0
  48. package/dist/eval-server/desktop-open-routes.js +64 -0
  49. package/dist/eval-server/desktop-open-routes.js.map +1 -0
  50. package/dist/eval-server/eval-server.js +82 -5
  51. package/dist/eval-server/eval-server.js.map +1 -1
  52. package/dist/eval-server/export-skill-routes.d.ts +9 -0
  53. package/dist/eval-server/export-skill-routes.js +81 -0
  54. package/dist/eval-server/export-skill-routes.js.map +1 -0
  55. package/dist/eval-server/git-routes.d.ts +1 -0
  56. package/dist/eval-server/git-routes.js +101 -4
  57. package/dist/eval-server/git-routes.js.map +1 -1
  58. package/dist/eval-server/install-engine-routes.d.ts +3 -16
  59. package/dist/eval-server/install-engine-routes.js +9 -124
  60. package/dist/eval-server/install-engine-routes.js.map +1 -1
  61. package/dist/eval-server/install-jobs.d.ts +41 -0
  62. package/dist/eval-server/install-jobs.js +161 -0
  63. package/dist/eval-server/install-jobs.js.map +1 -0
  64. package/dist/eval-server/install-skill-routes.d.ts +74 -11
  65. package/dist/eval-server/install-skill-routes.js +506 -79
  66. package/dist/eval-server/install-skill-routes.js.map +1 -1
  67. package/dist/eval-server/install-state-routes.d.ts +4 -0
  68. package/dist/eval-server/install-state-routes.js +15 -1
  69. package/dist/eval-server/install-state-routes.js.map +1 -1
  70. package/dist/eval-server/oauth-github-routes.d.ts +2 -0
  71. package/dist/eval-server/oauth-github-routes.js +505 -0
  72. package/dist/eval-server/oauth-github-routes.js.map +1 -0
  73. package/dist/eval-server/platform-proxy.d.ts +17 -1
  74. package/dist/eval-server/platform-proxy.js +125 -13
  75. package/dist/eval-server/platform-proxy.js.map +1 -1
  76. package/dist/eval-server/plugin-cli-routes.js +9 -9
  77. package/dist/eval-server/plugin-cli-routes.js.map +1 -1
  78. package/dist/eval-server/remove-skill-routes.d.ts +18 -0
  79. package/dist/eval-server/remove-skill-routes.js +145 -0
  80. package/dist/eval-server/remove-skill-routes.js.map +1 -0
  81. package/dist/eval-server/router.d.ts +17 -3
  82. package/dist/eval-server/router.js +166 -9
  83. package/dist/eval-server/router.js.map +1 -1
  84. package/dist/eval-server/settings-store.js +1 -1
  85. package/dist/eval-server/settings-store.js.map +1 -1
  86. package/dist/eval-server/supported-agents-routes.d.ts +6 -0
  87. package/dist/eval-server/supported-agents-routes.js +41 -0
  88. package/dist/eval-server/supported-agents-routes.js.map +1 -0
  89. package/dist/eval-server/utils/spawn-env.d.ts +1 -0
  90. package/dist/eval-server/utils/spawn-env.js +47 -0
  91. package/dist/eval-server/utils/spawn-env.js.map +1 -0
  92. package/dist/eval-ui/assets/AdvancedTab-D8zbE5fH.js +1 -0
  93. package/dist/eval-ui/assets/{CreateSkillPage-CvdYq8Rr.js → CreateSkillPage-DOBhKdgr.js} +5 -5
  94. package/dist/eval-ui/assets/FindSkillsPalette-CyMmNPr-.js +2 -0
  95. package/dist/eval-ui/assets/GeneralTab-DYR9NWC4.js +1 -0
  96. package/dist/eval-ui/assets/PrivacyTab-CXIqQokl.js +1 -0
  97. package/dist/eval-ui/assets/{SearchPaletteCore-Bf3PBC64.js → SearchPaletteCore-Dn5gQJS_.js} +2 -2
  98. package/dist/eval-ui/assets/SkillDetailPanel-DTrRnyyJ.js +1 -0
  99. package/dist/eval-ui/assets/UpdateDropdown-Cvr2fe0z.js +1 -0
  100. package/dist/eval-ui/assets/UpdatesTab-DwJIUDPX.js +1 -0
  101. package/dist/eval-ui/assets/core-DZAvsxlC.js +1 -0
  102. package/dist/eval-ui/assets/event-CDYWU2X3.js +1 -0
  103. package/dist/eval-ui/assets/globals-BRZwPAPF.js +49 -0
  104. package/dist/eval-ui/assets/globals-C3oEdsJh.css +1 -0
  105. package/dist/eval-ui/assets/index-D7M0Jdss.js +1 -0
  106. package/dist/eval-ui/assets/lifecycle-DSleOV-l.js +1 -0
  107. package/dist/eval-ui/assets/lifecycle-d1Sm9Hts.css +1 -0
  108. package/dist/eval-ui/assets/main-D2shn1dH.js +87 -0
  109. package/dist/eval-ui/assets/preferences-BHZXB5dL.css +1 -0
  110. package/dist/eval-ui/assets/preferences-BKv6X7fK.js +2 -0
  111. package/dist/eval-ui/assets/useDesktopBridge-DxVWbYqK.js +2 -0
  112. package/dist/eval-ui/index.html +4 -2
  113. package/dist/eval-ui/lifecycle.html +33 -0
  114. package/dist/eval-ui/preferences.html +34 -0
  115. package/dist/index.js +47 -1
  116. package/dist/index.js.map +1 -1
  117. package/dist/installer/bundle-files.d.ts +4 -0
  118. package/dist/installer/bundle-files.js +97 -0
  119. package/dist/installer/bundle-files.js.map +1 -0
  120. package/dist/installer/canonical.d.ts +31 -6
  121. package/dist/installer/canonical.js +48 -12
  122. package/dist/installer/canonical.js.map +1 -1
  123. package/dist/installer/clipboard-export.d.ts +19 -0
  124. package/dist/installer/clipboard-export.js +88 -0
  125. package/dist/installer/clipboard-export.js.map +1 -0
  126. package/dist/installer/multi-install.d.ts +43 -0
  127. package/dist/installer/multi-install.js +237 -0
  128. package/dist/installer/multi-install.js.map +1 -0
  129. package/dist/installer/transformers/aider.d.ts +2 -0
  130. package/dist/installer/transformers/aider.js +32 -0
  131. package/dist/installer/transformers/aider.js.map +1 -0
  132. package/dist/installer/transformers/continue-dev.d.ts +2 -0
  133. package/dist/installer/transformers/continue-dev.js +6 -0
  134. package/dist/installer/transformers/continue-dev.js.map +1 -0
  135. package/dist/installer/transformers/cursor.d.ts +2 -0
  136. package/dist/installer/transformers/cursor.js +24 -0
  137. package/dist/installer/transformers/cursor.js.map +1 -0
  138. package/dist/installer/transformers/github-copilot.d.ts +2 -0
  139. package/dist/installer/transformers/github-copilot.js +17 -0
  140. package/dist/installer/transformers/github-copilot.js.map +1 -0
  141. package/dist/installer/transformers/index.d.ts +78 -0
  142. package/dist/installer/transformers/index.js +13 -0
  143. package/dist/installer/transformers/index.js.map +1 -0
  144. package/dist/installer/transformers/junie.d.ts +2 -0
  145. package/dist/installer/transformers/junie.js +6 -0
  146. package/dist/installer/transformers/junie.js.map +1 -0
  147. package/dist/installer/transformers/kiro.d.ts +2 -0
  148. package/dist/installer/transformers/kiro.js +6 -0
  149. package/dist/installer/transformers/kiro.js.map +1 -0
  150. package/dist/installer/transformers/trae.d.ts +2 -0
  151. package/dist/installer/transformers/trae.js +6 -0
  152. package/dist/installer/transformers/trae.js.map +1 -0
  153. package/dist/installer/transformers/windsurf.d.ts +2 -0
  154. package/dist/installer/transformers/windsurf.js +12 -0
  155. package/dist/installer/transformers/windsurf.js.map +1 -0
  156. package/dist/installer/yaml-safe-mutate.d.ts +19 -0
  157. package/dist/installer/yaml-safe-mutate.js +184 -0
  158. package/dist/installer/yaml-safe-mutate.js.map +1 -0
  159. package/dist/lib/active-tenant.d.ts +36 -0
  160. package/dist/lib/active-tenant.js +120 -0
  161. package/dist/lib/active-tenant.js.map +1 -0
  162. package/dist/lib/github-fetch.d.ts +1 -0
  163. package/dist/lib/github-fetch.js +11 -1
  164. package/dist/lib/github-fetch.js.map +1 -1
  165. package/dist/lib/keychain.d.ts +15 -2
  166. package/dist/lib/keychain.js +156 -8
  167. package/dist/lib/keychain.js.map +1 -1
  168. package/dist/lib/migration/keychain-migration.d.ts +35 -0
  169. package/dist/lib/migration/keychain-migration.js +189 -0
  170. package/dist/lib/migration/keychain-migration.js.map +1 -0
  171. package/dist/lib/tenant-resolver.d.ts +38 -0
  172. package/dist/lib/tenant-resolver.js +79 -0
  173. package/dist/lib/tenant-resolver.js.map +1 -0
  174. package/dist/lockfile/types.d.ts +8 -0
  175. package/dist/sidecar/eval-ui-manifest.json +1 -0
  176. package/dist/sidecar/sea-config.json +57 -0
  177. package/dist/sidecar/sea-prep.blob +0 -0
  178. package/dist/sidecar/server.cjs +141627 -0
  179. package/dist/sidecar/vskill-version.txt +1 -0
  180. package/dist/studio/lib/ops-log.js +140 -57
  181. package/dist/studio/lib/ops-log.js.map +1 -1
  182. package/dist/studio/lib/scope-transfer.d.ts +11 -1
  183. package/dist/studio/lib/scope-transfer.js +48 -24
  184. package/dist/studio/lib/scope-transfer.js.map +1 -1
  185. package/dist/studio/routes/index.js +10 -1
  186. package/dist/studio/routes/index.js.map +1 -1
  187. package/dist/studio/routes/ops.js +31 -7
  188. package/dist/studio/routes/ops.js.map +1 -1
  189. package/dist/studio/routes/promote.js +15 -8
  190. package/dist/studio/routes/promote.js.map +1 -1
  191. package/dist/studio/routes/revert.js +12 -1
  192. package/dist/studio/routes/revert.js.map +1 -1
  193. package/dist/studio/routes/test-install.js +13 -8
  194. package/dist/studio/routes/test-install.js.map +1 -1
  195. package/dist/studio-runtime/lockfile.d.ts +51 -0
  196. package/dist/studio-runtime/lockfile.js +216 -0
  197. package/dist/studio-runtime/lockfile.js.map +1 -0
  198. package/dist/updater/source-fetcher.js +2 -2
  199. package/dist/updater/source-fetcher.js.map +1 -1
  200. package/package.json +17 -1
  201. package/dist/eval-ui/assets/FindSkillsPalette-DsSgotS9.js +0 -2
  202. package/dist/eval-ui/assets/SkillDetailPanel-DAD2yJO-.js +0 -1
  203. package/dist/eval-ui/assets/UpdateDropdown-h5Hg3h7Z.js +0 -1
  204. package/dist/eval-ui/assets/index-CKLqBL52.css +0 -1
  205. package/dist/eval-ui/assets/index-JaDg6FlU.js +0 -124
  206. package/dist/eval-ui/assets/skill-studio-logo-CRyKgIrg.png +0 -0
@@ -0,0 +1,87 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/UpdateDropdown-Cvr2fe0z.js","assets/globals-BRZwPAPF.js","assets/globals-C3oEdsJh.css","assets/useDesktopBridge-DxVWbYqK.js","assets/fonts-i7Lkz2zN.css","assets/FindSkillsPalette-CyMmNPr-.js","assets/SkillDetailPanel-DTrRnyyJ.js","assets/skill-url-C4ekwoGs.js","assets/CreateSkillPage-DOBhKdgr.js"])))=>i.map(i=>d[i]);
2
+ import{r as l,a as Qd,g as Zd,j as t,R as me,c as eu}from"./globals-BRZwPAPF.js";import{_ as Lr,u as pn,n as pa,l as Sn}from"./useDesktopBridge-DxVWbYqK.js";/* empty css *//**
3
+ * react-router v7.13.1
4
+ *
5
+ * Copyright (c) Remix Software Inc.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE.md file in the root directory of this source tree.
9
+ *
10
+ * @license MIT
11
+ */var fa="popstate";function ha(e){return typeof e=="object"&&e!=null&&"pathname"in e&&"search"in e&&"hash"in e&&"state"in e&&"key"in e}function tu(e={}){function r(o,a){let{pathname:i="/",search:c="",hash:d=""}=Ar(o.location.hash.substring(1));return!i.startsWith("/")&&!i.startsWith(".")&&(i="/"+i),po("",{pathname:i,search:c,hash:d},a.state&&a.state.usr||null,a.state&&a.state.key||"default")}function n(o,a){let i=o.document.querySelector("base"),c="";if(i&&i.getAttribute("href")){let d=o.location.href,u=d.indexOf("#");c=u===-1?d:d.slice(0,u)}return c+"#"+(typeof a=="string"?a:nn(a))}function s(o,a){Pt(o.pathname.charAt(0)==="/",`relative pathnames are not supported in hash history.push(${JSON.stringify(a)})`)}return nu(r,n,s,e)}function et(e,r){if(e===!1||e===null||typeof e>"u")throw new Error(r)}function Pt(e,r){if(!e){typeof console<"u"&&console.warn(r);try{throw new Error(r)}catch{}}}function ru(){return Math.random().toString(36).substring(2,10)}function ma(e,r){return{usr:e.state,key:e.key,idx:r,masked:e.unstable_mask?{pathname:e.pathname,search:e.search,hash:e.hash}:void 0}}function po(e,r,n=null,s,o){return{pathname:typeof e=="string"?e:e.pathname,search:"",hash:"",...typeof r=="string"?Ar(r):r,state:n,key:r&&r.key||s||ru(),unstable_mask:o}}function nn({pathname:e="/",search:r="",hash:n=""}){return r&&r!=="?"&&(e+=r.charAt(0)==="?"?r:"?"+r),n&&n!=="#"&&(e+=n.charAt(0)==="#"?n:"#"+n),e}function Ar(e){let r={};if(e){let n=e.indexOf("#");n>=0&&(r.hash=e.substring(n),e=e.substring(0,n));let s=e.indexOf("?");s>=0&&(r.search=e.substring(s),e=e.substring(0,s)),e&&(r.pathname=e)}return r}function nu(e,r,n,s={}){let{window:o=document.defaultView,v5Compat:a=!1}=s,i=o.history,c="POP",d=null,u=p();u==null&&(u=0,i.replaceState({...i.state,idx:u},""));function p(){return(i.state||{idx:null}).idx}function f(){c="POP";let v=p(),b=v==null?null:v-u;u=v,d&&d({action:c,location:x.location,delta:b})}function h(v,b){c="PUSH";let y=ha(v)?v:po(x.location,v,b);n&&n(y,v),u=p()+1;let j=ma(y,u),S=x.createHref(y.unstable_mask||y);try{i.pushState(j,"",S)}catch(w){if(w instanceof DOMException&&w.name==="DataCloneError")throw w;o.location.assign(S)}a&&d&&d({action:c,location:x.location,delta:1})}function m(v,b){c="REPLACE";let y=ha(v)?v:po(x.location,v,b);n&&n(y,v),u=p();let j=ma(y,u),S=x.createHref(y.unstable_mask||y);i.replaceState(j,"",S),a&&d&&d({action:c,location:x.location,delta:0})}function g(v){return su(v)}let x={get action(){return c},get location(){return e(o,i)},listen(v){if(d)throw new Error("A history only accepts one active listener");return o.addEventListener(fa,f),d=v,()=>{o.removeEventListener(fa,f),d=null}},createHref(v){return r(o,v)},createURL:g,encodeLocation(v){let b=g(v);return{pathname:b.pathname,search:b.search,hash:b.hash}},push:h,replace:m,go(v){return i.go(v)}};return x}function su(e,r=!1){let n="http://localhost";typeof window<"u"&&(n=window.location.origin!=="null"?window.location.origin:window.location.href),et(n,"No window.location.(origin|href) available to create URL");let s=typeof e=="string"?e:nn(e);return s=s.replace(/ $/,"%20"),!r&&s.startsWith("//")&&(s=n+s),new URL(s,n)}function dl(e,r,n="/"){return ou(e,r,n,!1)}function ou(e,r,n,s){let o=typeof r=="string"?Ar(r):r,a=Yt(o.pathname||"/",n);if(a==null)return null;let i=ul(e);au(i);let c=null;for(let d=0;c==null&&d<i.length;++d){let u=gu(a);c=mu(i[d],u,s)}return c}function ul(e,r=[],n=[],s="",o=!1){let a=(i,c,d=o,u)=>{let p={relativePath:u===void 0?i.path||"":u,caseSensitive:i.caseSensitive===!0,childrenIndex:c,route:i};if(p.relativePath.startsWith("/")){if(!p.relativePath.startsWith(s)&&d)return;et(p.relativePath.startsWith(s),`Absolute route path "${p.relativePath}" nested under path "${s}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`),p.relativePath=p.relativePath.slice(s.length)}let f=Wt([s,p.relativePath]),h=n.concat(p);i.children&&i.children.length>0&&(et(i.index!==!0,`Index routes must not have child routes. Please remove all child routes from route path "${f}".`),ul(i.children,r,h,f,d)),!(i.path==null&&!i.index)&&r.push({path:f,score:fu(f,i.index),routesMeta:h})};return e.forEach((i,c)=>{var d;if(i.path===""||!((d=i.path)!=null&&d.includes("?")))a(i,c);else for(let u of pl(i.path))a(i,c,!0,u)}),r}function pl(e){let r=e.split("/");if(r.length===0)return[];let[n,...s]=r,o=n.endsWith("?"),a=n.replace(/\?$/,"");if(s.length===0)return o?[a,""]:[a];let i=pl(s.join("/")),c=[];return c.push(...i.map(d=>d===""?a:[a,d].join("/"))),o&&c.push(...i),c.map(d=>e.startsWith("/")&&d===""?"/":d)}function au(e){e.sort((r,n)=>r.score!==n.score?n.score-r.score:hu(r.routesMeta.map(s=>s.childrenIndex),n.routesMeta.map(s=>s.childrenIndex)))}var iu=/^:[\w-]+$/,lu=3,cu=2,du=1,uu=10,pu=-2,xa=e=>e==="*";function fu(e,r){let n=e.split("/"),s=n.length;return n.some(xa)&&(s+=pu),r&&(s+=cu),n.filter(o=>!xa(o)).reduce((o,a)=>o+(iu.test(a)?lu:a===""?du:uu),s)}function hu(e,r){return e.length===r.length&&e.slice(0,-1).every((s,o)=>s===r[o])?e[e.length-1]-r[r.length-1]:0}function mu(e,r,n=!1){let{routesMeta:s}=e,o={},a="/",i=[];for(let c=0;c<s.length;++c){let d=s[c],u=c===s.length-1,p=a==="/"?r:r.slice(a.length)||"/",f=Kn({path:d.relativePath,caseSensitive:d.caseSensitive,end:u},p),h=d.route;if(!f&&u&&n&&!s[s.length-1].route.index&&(f=Kn({path:d.relativePath,caseSensitive:d.caseSensitive,end:!1},p)),!f)return null;Object.assign(o,f.params),i.push({params:o,pathname:Wt([a,f.pathname]),pathnameBase:ku(Wt([a,f.pathnameBase])),route:h}),f.pathnameBase!=="/"&&(a=Wt([a,f.pathnameBase]))}return i}function Kn(e,r){typeof e=="string"&&(e={path:e,caseSensitive:!1,end:!0});let[n,s]=xu(e.path,e.caseSensitive,e.end),o=r.match(n);if(!o)return null;let a=o[0],i=a.replace(/(.)\/+$/,"$1"),c=o.slice(1);return{params:s.reduce((u,{paramName:p,isOptional:f},h)=>{if(p==="*"){let g=c[h]||"";i=a.slice(0,a.length-g.length).replace(/(.)\/+$/,"$1")}const m=c[h];return f&&!m?u[p]=void 0:u[p]=(m||"").replace(/%2F/g,"/"),u},{}),pathname:a,pathnameBase:i,pattern:e}}function xu(e,r=!1,n=!0){Pt(e==="*"||!e.endsWith("*")||e.endsWith("/*"),`Route path "${e}" will be treated as if it were "${e.replace(/\*$/,"/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/,"/*")}".`);let s=[],o="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(i,c,d,u,p)=>{if(s.push({paramName:c,isOptional:d!=null}),d){let f=p.charAt(u+i.length);return f&&f!=="/"?"/([^\\/]*)":"(?:/([^\\/]*))?"}return"/([^\\/]+)"}).replace(/\/([\w-]+)\?(\/|$)/g,"(/$1)?$2");return e.endsWith("*")?(s.push({paramName:"*"}),o+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):n?o+="\\/*$":e!==""&&e!=="/"&&(o+="(?:(?=\\/|$))"),[new RegExp(o,r?void 0:"i"),s]}function gu(e){try{return e.split("/").map(r=>decodeURIComponent(r).replace(/\//g,"%2F")).join("/")}catch(r){return Pt(!1,`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${r}).`),e}}function Yt(e,r){if(r==="/")return e;if(!e.toLowerCase().startsWith(r.toLowerCase()))return null;let n=r.endsWith("/")?r.length-1:r.length,s=e.charAt(n);return s&&s!=="/"?null:e.slice(n)||"/"}var vu=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;function yu(e,r="/"){let{pathname:n,search:s="",hash:o=""}=typeof e=="string"?Ar(e):e,a;return n?(n=n.replace(/\/\/+/g,"/"),n.startsWith("/")?a=ga(n.substring(1),"/"):a=ga(n,r)):a=r,{pathname:a,search:ju(s),hash:wu(o)}}function ga(e,r){let n=r.replace(/\/+$/,"").split("/");return e.split("/").forEach(o=>{o===".."?n.length>1&&n.pop():o!=="."&&n.push(o)}),n.length>1?n.join("/"):"/"}function ms(e,r,n,s){return`Cannot include a '${e}' character in a manually specified \`to.${r}\` field [${JSON.stringify(s)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`}function bu(e){return e.filter((r,n)=>n===0||r.route.path&&r.route.path.length>0)}function fl(e){let r=bu(e);return r.map((n,s)=>s===r.length-1?n.pathname:n.pathnameBase)}function Do(e,r,n,s=!1){let o;typeof e=="string"?o=Ar(e):(o={...e},et(!o.pathname||!o.pathname.includes("?"),ms("?","pathname","search",o)),et(!o.pathname||!o.pathname.includes("#"),ms("#","pathname","hash",o)),et(!o.search||!o.search.includes("#"),ms("#","search","hash",o)));let a=e===""||o.pathname==="",i=a?"/":o.pathname,c;if(i==null)c=n;else{let f=r.length-1;if(!s&&i.startsWith("..")){let h=i.split("/");for(;h[0]==="..";)h.shift(),f-=1;o.pathname=h.join("/")}c=f>=0?r[f]:"/"}let d=yu(o,c),u=i&&i!=="/"&&i.endsWith("/"),p=(a||i===".")&&n.endsWith("/");return!d.pathname.endsWith("/")&&(u||p)&&(d.pathname+="/"),d}var Wt=e=>e.join("/").replace(/\/\/+/g,"/"),ku=e=>e.replace(/\/+$/,"").replace(/^\/*/,"/"),ju=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,wu=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e,Su=class{constructor(e,r,n,s=!1){this.status=e,this.statusText=r||"",this.internal=s,n instanceof Error?(this.data=n.toString(),this.error=n):this.data=n}};function Cu(e){return e!=null&&typeof e.status=="number"&&typeof e.statusText=="string"&&typeof e.internal=="boolean"&&"data"in e}function Eu(e){return e.map(r=>r.route.path).filter(Boolean).join("/").replace(/\/\/*/g,"/")||"/"}var hl=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function ml(e,r){let n=e;if(typeof n!="string"||!vu.test(n))return{absoluteURL:void 0,isExternal:!1,to:n};let s=n,o=!1;if(hl)try{let a=new URL(window.location.href),i=n.startsWith("//")?new URL(a.protocol+n):new URL(n),c=Yt(i.pathname,r);i.origin===a.origin&&c!=null?n=c+i.search+i.hash:o=!0}catch{Pt(!1,`<Link to="${n}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}return{absoluteURL:s,isExternal:o,to:n}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");var xl=["POST","PUT","PATCH","DELETE"];new Set(xl);var Nu=["GET",...xl];new Set(Nu);var Pr=l.createContext(null);Pr.displayName="DataRouter";var es=l.createContext(null);es.displayName="DataRouterState";var Ru=l.createContext(!1),gl=l.createContext({isTransitioning:!1});gl.displayName="ViewTransition";var Tu=l.createContext(new Map);Tu.displayName="Fetchers";var Iu=l.createContext(null);Iu.displayName="Await";var Rt=l.createContext(null);Rt.displayName="Navigation";var ts=l.createContext(null);ts.displayName="Location";var Jt=l.createContext({outlet:null,matches:[],isDataRoute:!1});Jt.displayName="Route";var Fo=l.createContext(null);Fo.displayName="RouteError";var vl="REACT_ROUTER_ERROR",Lu="REDIRECT",Au="ROUTE_ERROR_RESPONSE";function Pu(e){if(e.startsWith(`${vl}:${Lu}:{`))try{let r=JSON.parse(e.slice(28));if(typeof r=="object"&&r&&typeof r.status=="number"&&typeof r.statusText=="string"&&typeof r.location=="string"&&typeof r.reloadDocument=="boolean"&&typeof r.replace=="boolean")return r}catch{}}function $u(e){if(e.startsWith(`${vl}:${Au}:{`))try{let r=JSON.parse(e.slice(40));if(typeof r=="object"&&r&&typeof r.status=="number"&&typeof r.statusText=="string")return new Su(r.status,r.statusText,r.data)}catch{}}function Mu(e,{relative:r}={}){et(fn(),"useHref() may be used only in the context of a <Router> component.");let{basename:n,navigator:s}=l.useContext(Rt),{hash:o,pathname:a,search:i}=hn(e,{relative:r}),c=a;return n!=="/"&&(c=a==="/"?n:Wt([n,a])),s.createHref({pathname:c,search:i,hash:o})}function fn(){return l.useContext(ts)!=null}function nr(){return et(fn(),"useLocation() may be used only in the context of a <Router> component."),l.useContext(ts).location}var yl="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function bl(e){l.useContext(Rt).static||l.useLayoutEffect(e)}function Du(){let{isDataRoute:e}=l.useContext(Jt);return e?Yu():Fu()}function Fu(){et(fn(),"useNavigate() may be used only in the context of a <Router> component.");let e=l.useContext(Pr),{basename:r,navigator:n}=l.useContext(Rt),{matches:s}=l.useContext(Jt),{pathname:o}=nr(),a=JSON.stringify(fl(s)),i=l.useRef(!1);return bl(()=>{i.current=!0}),l.useCallback((d,u={})=>{if(Pt(i.current,yl),!i.current)return;if(typeof d=="number"){n.go(d);return}let p=Do(d,JSON.parse(a),o,u.relative==="path");e==null&&r!=="/"&&(p.pathname=p.pathname==="/"?r:Wt([r,p.pathname])),(u.replace?n.replace:n.push)(p,u.state,u)},[r,n,a,o,e])}l.createContext(null);function hn(e,{relative:r}={}){let{matches:n}=l.useContext(Jt),{pathname:s}=nr(),o=JSON.stringify(fl(n));return l.useMemo(()=>Do(e,JSON.parse(o),s,r==="path"),[e,o,s,r])}function zu(e,r,n){et(fn(),"useRoutes() may be used only in the context of a <Router> component.");let{navigator:s}=l.useContext(Rt),{matches:o}=l.useContext(Jt),a=o[o.length-1],i=a?a.params:{},c=a?a.pathname:"/",d=a?a.pathnameBase:"/",u=a&&a.route;{let v=u&&u.path||"";jl(c,!u||v.endsWith("*")||v.endsWith("*?"),`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${c}" (under <Route path="${v}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
12
+
13
+ Please change the parent <Route path="${v}"> to <Route path="${v==="/"?"*":`${v}/*`}">.`)}let p=nr(),f;f=p;let h=f.pathname||"/",m=h;if(d!=="/"){let v=d.replace(/^\//,"").split("/");m="/"+h.replace(/^\//,"").split("/").slice(v.length).join("/")}let g=dl(e,{pathname:m});return Pt(u||g!=null,`No routes matched location "${f.pathname}${f.search}${f.hash}" `),Pt(g==null||g[g.length-1].route.element!==void 0||g[g.length-1].route.Component!==void 0||g[g.length-1].route.lazy!==void 0,`Matched leaf route at location "${f.pathname}${f.search}${f.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`),Hu(g&&g.map(v=>Object.assign({},v,{params:Object.assign({},i,v.params),pathname:Wt([d,s.encodeLocation?s.encodeLocation(v.pathname.replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:v.pathname]),pathnameBase:v.pathnameBase==="/"?d:Wt([d,s.encodeLocation?s.encodeLocation(v.pathnameBase.replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:v.pathnameBase])})),o,n)}function Bu(){let e=qu(),r=Cu(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,s="rgba(200,200,200, 0.5)",o={padding:"0.5rem",backgroundColor:s},a={padding:"2px 4px",backgroundColor:s},i=null;return console.error("Error handled by React Router default ErrorBoundary:",e),i=l.createElement(l.Fragment,null,l.createElement("p",null,"💿 Hey developer 👋"),l.createElement("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",l.createElement("code",{style:a},"ErrorBoundary")," or"," ",l.createElement("code",{style:a},"errorElement")," prop on your route.")),l.createElement(l.Fragment,null,l.createElement("h2",null,"Unexpected Application Error!"),l.createElement("h3",{style:{fontStyle:"italic"}},r),n?l.createElement("pre",{style:o},n):null,i)}var _u=l.createElement(Bu,null),kl=class extends l.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,r){return r.location!==e.location||r.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:r.error,location:r.location,revalidation:e.revalidation||r.revalidation}}componentDidCatch(e,r){this.props.onError?this.props.onError(e,r):console.error("React Router caught the following error during render",e)}render(){let e=this.state.error;if(this.context&&typeof e=="object"&&e&&"digest"in e&&typeof e.digest=="string"){const n=$u(e.digest);n&&(e=n)}let r=e!==void 0?l.createElement(Jt.Provider,{value:this.props.routeContext},l.createElement(Fo.Provider,{value:e,children:this.props.component})):this.props.children;return this.context?l.createElement(Ou,{error:e},r):r}};kl.contextType=Ru;var xs=new WeakMap;function Ou({children:e,error:r}){let{basename:n}=l.useContext(Rt);if(typeof r=="object"&&r&&"digest"in r&&typeof r.digest=="string"){let s=Pu(r.digest);if(s){let o=xs.get(r);if(o)throw o;let a=ml(s.location,n);if(hl&&!xs.get(r))if(a.isExternal||s.reloadDocument)window.location.href=a.absoluteURL||a.to;else{const i=Promise.resolve().then(()=>window.__reactRouterDataRouter.navigate(a.to,{replace:s.replace}));throw xs.set(r,i),i}return l.createElement("meta",{httpEquiv:"refresh",content:`0;url=${a.absoluteURL||a.to}`})}}return e}function Wu({routeContext:e,match:r,children:n}){let s=l.useContext(Pr);return s&&s.static&&s.staticContext&&(r.route.errorElement||r.route.ErrorBoundary)&&(s.staticContext._deepestRenderedBoundaryId=r.route.id),l.createElement(Jt.Provider,{value:e},n)}function Hu(e,r=[],n){let s=n==null?void 0:n.state;if(e==null){if(!s)return null;if(s.errors)e=s.matches;else if(r.length===0&&!s.initialized&&s.matches.length>0)e=s.matches;else return null}let o=e,a=s==null?void 0:s.errors;if(a!=null){let p=o.findIndex(f=>f.route.id&&(a==null?void 0:a[f.route.id])!==void 0);et(p>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(a).join(",")}`),o=o.slice(0,Math.min(o.length,p+1))}let i=!1,c=-1;if(n&&s){i=s.renderFallback;for(let p=0;p<o.length;p++){let f=o[p];if((f.route.HydrateFallback||f.route.hydrateFallbackElement)&&(c=p),f.route.id){let{loaderData:h,errors:m}=s,g=f.route.loader&&!h.hasOwnProperty(f.route.id)&&(!m||m[f.route.id]===void 0);if(f.route.lazy||g){n.isStatic&&(i=!0),c>=0?o=o.slice(0,c+1):o=[o[0]];break}}}}let d=n==null?void 0:n.onError,u=s&&d?(p,f)=>{var h,m;d(p,{location:s.location,params:((m=(h=s.matches)==null?void 0:h[0])==null?void 0:m.params)??{},unstable_pattern:Eu(s.matches),errorInfo:f})}:void 0;return o.reduceRight((p,f,h)=>{let m,g=!1,x=null,v=null;s&&(m=a&&f.route.id?a[f.route.id]:void 0,x=f.route.errorElement||_u,i&&(c<0&&h===0?(jl("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),g=!0,v=null):c===h&&(g=!0,v=f.route.hydrateFallbackElement||null)));let b=r.concat(o.slice(0,h+1)),y=()=>{let j;return m?j=x:g?j=v:f.route.Component?j=l.createElement(f.route.Component,null):f.route.element?j=f.route.element:j=p,l.createElement(Wu,{match:f,routeContext:{outlet:p,matches:b,isDataRoute:s!=null},children:j})};return s&&(f.route.ErrorBoundary||f.route.errorElement||h===0)?l.createElement(kl,{location:s.location,revalidation:s.revalidation,component:x,error:m,children:y(),routeContext:{outlet:null,matches:b,isDataRoute:!0},onError:u}):y()},null)}function zo(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Uu(e){let r=l.useContext(Pr);return et(r,zo(e)),r}function Vu(e){let r=l.useContext(es);return et(r,zo(e)),r}function Gu(e){let r=l.useContext(Jt);return et(r,zo(e)),r}function Bo(e){let r=Gu(e),n=r.matches[r.matches.length-1];return et(n.route.id,`${e} can only be used on routes that contain a unique "id"`),n.route.id}function Ku(){return Bo("useRouteId")}function qu(){var s;let e=l.useContext(Fo),r=Vu("useRouteError"),n=Bo("useRouteError");return e!==void 0?e:(s=r.errors)==null?void 0:s[n]}function Yu(){let{router:e}=Uu("useNavigate"),r=Bo("useNavigate"),n=l.useRef(!1);return bl(()=>{n.current=!0}),l.useCallback(async(o,a={})=>{Pt(n.current,yl),n.current&&(typeof o=="number"?await e.navigate(o):await e.navigate(o,{fromRouteId:r,...a}))},[e,r])}var va={};function jl(e,r,n){!r&&!va[e]&&(va[e]=!0,Pt(!1,n))}l.memo(Ju);function Ju({routes:e,future:r,state:n,isStatic:s,onError:o}){return zu(e,void 0,{state:n,isStatic:s,onError:o})}function Xu({basename:e="/",children:r=null,location:n,navigationType:s="POP",navigator:o,static:a=!1,unstable_useTransitions:i}){et(!fn(),"You cannot render a <Router> inside another <Router>. You should never have more than one in your app.");let c=e.replace(/^\/*/,"/"),d=l.useMemo(()=>({basename:c,navigator:o,static:a,unstable_useTransitions:i,future:{}}),[c,o,a,i]);typeof n=="string"&&(n=Ar(n));let{pathname:u="/",search:p="",hash:f="",state:h=null,key:m="default",unstable_mask:g}=n,x=l.useMemo(()=>{let v=Yt(u,c);return v==null?null:{location:{pathname:v,search:p,hash:f,state:h,key:m,unstable_mask:g},navigationType:s}},[c,u,p,f,h,m,s,g]);return Pt(x!=null,`<Router basename="${c}"> is not able to match the URL "${u}${p}${f}" because it does not start with the basename, so the <Router> won't render anything.`),x==null?null:l.createElement(Rt.Provider,{value:d},l.createElement(ts.Provider,{children:r,value:x}))}var _n="get",On="application/x-www-form-urlencoded";function rs(e){return typeof HTMLElement<"u"&&e instanceof HTMLElement}function Qu(e){return rs(e)&&e.tagName.toLowerCase()==="button"}function Zu(e){return rs(e)&&e.tagName.toLowerCase()==="form"}function ep(e){return rs(e)&&e.tagName.toLowerCase()==="input"}function tp(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function rp(e,r){return e.button===0&&(!r||r==="_self")&&!tp(e)}var Cn=null;function np(){if(Cn===null)try{new FormData(document.createElement("form"),0),Cn=!1}catch{Cn=!0}return Cn}var sp=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function gs(e){return e!=null&&!sp.has(e)?(Pt(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${On}"`),null):e}function op(e,r){let n,s,o,a,i;if(Zu(e)){let c=e.getAttribute("action");s=c?Yt(c,r):null,n=e.getAttribute("method")||_n,o=gs(e.getAttribute("enctype"))||On,a=new FormData(e)}else if(Qu(e)||ep(e)&&(e.type==="submit"||e.type==="image")){let c=e.form;if(c==null)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let d=e.getAttribute("formaction")||c.getAttribute("action");if(s=d?Yt(d,r):null,n=e.getAttribute("formmethod")||c.getAttribute("method")||_n,o=gs(e.getAttribute("formenctype"))||gs(c.getAttribute("enctype"))||On,a=new FormData(c,e),!np()){let{name:u,type:p,value:f}=e;if(p==="image"){let h=u?`${u}.`:"";a.append(`${h}x`,"0"),a.append(`${h}y`,"0")}else u&&a.append(u,f)}}else{if(rs(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');n=_n,s=null,o=On,i=e}return a&&o==="text/plain"&&(i=a,a=void 0),{action:s,method:n.toLowerCase(),encType:o,formData:a,body:i}}Object.getOwnPropertyNames(Object.prototype).sort().join("\0");function _o(e,r){if(e===!1||e===null||typeof e>"u")throw new Error(r)}function ap(e,r,n,s){let o=typeof e=="string"?new URL(e,typeof window>"u"?"server://singlefetch/":window.location.origin):e;return n?o.pathname.endsWith("/")?o.pathname=`${o.pathname}_.${s}`:o.pathname=`${o.pathname}.${s}`:o.pathname==="/"?o.pathname=`_root.${s}`:r&&Yt(o.pathname,r)==="/"?o.pathname=`${r.replace(/\/$/,"")}/_root.${s}`:o.pathname=`${o.pathname.replace(/\/$/,"")}.${s}`,o}async function ip(e,r){if(e.id in r)return r[e.id];try{let n=await import(e.module);return r[e.id]=n,n}catch(n){return console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(n),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode,window.location.reload(),new Promise(()=>{})}}function lp(e){return e==null?!1:e.href==null?e.rel==="preload"&&typeof e.imageSrcSet=="string"&&typeof e.imageSizes=="string":typeof e.rel=="string"&&typeof e.href=="string"}async function cp(e,r,n){let s=await Promise.all(e.map(async o=>{let a=r.routes[o.route.id];if(a){let i=await ip(a,n);return i.links?i.links():[]}return[]}));return fp(s.flat(1).filter(lp).filter(o=>o.rel==="stylesheet"||o.rel==="preload").map(o=>o.rel==="stylesheet"?{...o,rel:"prefetch",as:"style"}:{...o,rel:"prefetch"}))}function ya(e,r,n,s,o,a){let i=(d,u)=>n[u]?d.route.id!==n[u].route.id:!0,c=(d,u)=>{var p;return n[u].pathname!==d.pathname||((p=n[u].route.path)==null?void 0:p.endsWith("*"))&&n[u].params["*"]!==d.params["*"]};return a==="assets"?r.filter((d,u)=>i(d,u)||c(d,u)):a==="data"?r.filter((d,u)=>{var f;let p=s.routes[d.route.id];if(!p||!p.hasLoader)return!1;if(i(d,u)||c(d,u))return!0;if(d.route.shouldRevalidate){let h=d.route.shouldRevalidate({currentUrl:new URL(o.pathname+o.search+o.hash,window.origin),currentParams:((f=n[0])==null?void 0:f.params)||{},nextUrl:new URL(e,window.origin),nextParams:d.params,defaultShouldRevalidate:!0});if(typeof h=="boolean")return h}return!0}):[]}function dp(e,r,{includeHydrateFallback:n}={}){return up(e.map(s=>{let o=r.routes[s.route.id];if(!o)return[];let a=[o.module];return o.clientActionModule&&(a=a.concat(o.clientActionModule)),o.clientLoaderModule&&(a=a.concat(o.clientLoaderModule)),n&&o.hydrateFallbackModule&&(a=a.concat(o.hydrateFallbackModule)),o.imports&&(a=a.concat(o.imports)),a}).flat(1))}function up(e){return[...new Set(e)]}function pp(e){let r={},n=Object.keys(e).sort();for(let s of n)r[s]=e[s];return r}function fp(e,r){let n=new Set;return new Set(r),e.reduce((s,o)=>{let a=JSON.stringify(pp(o));return n.has(a)||(n.add(a),s.push({key:a,link:o})),s},[])}function wl(){let e=l.useContext(Pr);return _o(e,"You must render this element inside a <DataRouterContext.Provider> element"),e}function hp(){let e=l.useContext(es);return _o(e,"You must render this element inside a <DataRouterStateContext.Provider> element"),e}var Oo=l.createContext(void 0);Oo.displayName="FrameworkContext";function Sl(){let e=l.useContext(Oo);return _o(e,"You must render this element inside a <HydratedRouter> element"),e}function mp(e,r){let n=l.useContext(Oo),[s,o]=l.useState(!1),[a,i]=l.useState(!1),{onFocus:c,onBlur:d,onMouseEnter:u,onMouseLeave:p,onTouchStart:f}=r,h=l.useRef(null);l.useEffect(()=>{if(e==="render"&&i(!0),e==="viewport"){let x=b=>{b.forEach(y=>{i(y.isIntersecting)})},v=new IntersectionObserver(x,{threshold:.5});return h.current&&v.observe(h.current),()=>{v.disconnect()}}},[e]),l.useEffect(()=>{if(s){let x=setTimeout(()=>{i(!0)},100);return()=>{clearTimeout(x)}}},[s]);let m=()=>{o(!0)},g=()=>{o(!1),i(!1)};return n?e!=="intent"?[a,h,{}]:[a,h,{onFocus:_r(c,m),onBlur:_r(d,g),onMouseEnter:_r(u,m),onMouseLeave:_r(p,g),onTouchStart:_r(f,m)}]:[!1,h,{}]}function _r(e,r){return n=>{e&&e(n),n.defaultPrevented||r(n)}}function xp({page:e,...r}){let{router:n}=wl(),s=l.useMemo(()=>dl(n.routes,e,n.basename),[n.routes,e,n.basename]);return s?l.createElement(vp,{page:e,matches:s,...r}):null}function gp(e){let{manifest:r,routeModules:n}=Sl(),[s,o]=l.useState([]);return l.useEffect(()=>{let a=!1;return cp(e,r,n).then(i=>{a||o(i)}),()=>{a=!0}},[e,r,n]),s}function vp({page:e,matches:r,...n}){let s=nr(),{future:o,manifest:a,routeModules:i}=Sl(),{basename:c}=wl(),{loaderData:d,matches:u}=hp(),p=l.useMemo(()=>ya(e,r,u,a,s,"data"),[e,r,u,a,s]),f=l.useMemo(()=>ya(e,r,u,a,s,"assets"),[e,r,u,a,s]),h=l.useMemo(()=>{if(e===s.pathname+s.search+s.hash)return[];let x=new Set,v=!1;if(r.forEach(y=>{var S;let j=a.routes[y.route.id];!j||!j.hasLoader||(!p.some(w=>w.route.id===y.route.id)&&y.route.id in d&&((S=i[y.route.id])!=null&&S.shouldRevalidate)||j.hasClientLoader?v=!0:x.add(y.route.id))}),x.size===0)return[];let b=ap(e,c,o.unstable_trailingSlashAwareDataRequests,"data");return v&&x.size>0&&b.searchParams.set("_routes",r.filter(y=>x.has(y.route.id)).map(y=>y.route.id).join(",")),[b.pathname+b.search]},[c,o.unstable_trailingSlashAwareDataRequests,d,s,a,p,r,e,i]),m=l.useMemo(()=>dp(f,a),[f,a]),g=gp(f);return l.createElement(l.Fragment,null,h.map(x=>l.createElement("link",{key:x,rel:"prefetch",as:"fetch",href:x,...n})),m.map(x=>l.createElement("link",{key:x,rel:"modulepreload",href:x,...n})),g.map(({key:x,link:v})=>l.createElement("link",{key:x,nonce:n.nonce,...v,crossOrigin:v.crossOrigin??n.crossOrigin})))}function yp(...e){return r=>{e.forEach(n=>{typeof n=="function"?n(r):n!=null&&(n.current=r)})}}var bp=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";try{bp&&(window.__reactRouterVersion="7.13.1")}catch{}function kp({basename:e,children:r,unstable_useTransitions:n,window:s}){let o=l.useRef();o.current==null&&(o.current=tu({window:s,v5Compat:!0}));let a=o.current,[i,c]=l.useState({action:a.action,location:a.location}),d=l.useCallback(u=>{n===!1?c(u):l.startTransition(()=>c(u))},[n]);return l.useLayoutEffect(()=>a.listen(d),[a,d]),l.createElement(Xu,{basename:e,children:r,location:i.location,navigationType:i.action,navigator:a,unstable_useTransitions:n})}var Cl=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,El=l.forwardRef(function({onClick:r,discover:n="render",prefetch:s="none",relative:o,reloadDocument:a,replace:i,unstable_mask:c,state:d,target:u,to:p,preventScrollReset:f,viewTransition:h,unstable_defaultShouldRevalidate:m,...g},x){let{basename:v,navigator:b,unstable_useTransitions:y}=l.useContext(Rt),j=typeof p=="string"&&Cl.test(p),S=ml(p,v);p=S.to;let w=Mu(p,{relative:o}),R=nr(),k=null;if(c){let T=Do(c,[],R.unstable_mask?R.unstable_mask.pathname:"/",!0);v!=="/"&&(T.pathname=T.pathname==="/"?v:Wt([v,T.pathname])),k=b.createHref(T)}let[E,C,N]=mp(s,g),I=Cp(p,{replace:i,unstable_mask:c,state:d,target:u,preventScrollReset:f,relative:o,viewTransition:h,unstable_defaultShouldRevalidate:m,unstable_useTransitions:y});function P(T){r&&r(T),T.defaultPrevented||I(T)}let L=!(S.isExternal||a),B=l.createElement("a",{...g,...N,href:(L?k:void 0)||S.absoluteURL||w,onClick:L?P:r,ref:yp(x,C),target:u,"data-discover":!j&&n==="render"?"true":void 0});return E&&!j?l.createElement(l.Fragment,null,B,l.createElement(xp,{page:w})):B});El.displayName="Link";var jp=l.forwardRef(function({"aria-current":r="page",caseSensitive:n=!1,className:s="",end:o=!1,style:a,to:i,viewTransition:c,children:d,...u},p){let f=hn(i,{relative:u.relative}),h=nr(),m=l.useContext(es),{navigator:g,basename:x}=l.useContext(Rt),v=m!=null&&Ip(f)&&c===!0,b=g.encodeLocation?g.encodeLocation(f).pathname:f.pathname,y=h.pathname,j=m&&m.navigation&&m.navigation.location?m.navigation.location.pathname:null;n||(y=y.toLowerCase(),j=j?j.toLowerCase():null,b=b.toLowerCase()),j&&x&&(j=Yt(j,x)||j);const S=b!=="/"&&b.endsWith("/")?b.length-1:b.length;let w=y===b||!o&&y.startsWith(b)&&y.charAt(S)==="/",R=j!=null&&(j===b||!o&&j.startsWith(b)&&j.charAt(b.length)==="/"),k={isActive:w,isPending:R,isTransitioning:v},E=w?r:void 0,C;typeof s=="function"?C=s(k):C=[s,w?"active":null,R?"pending":null,v?"transitioning":null].filter(Boolean).join(" ");let N=typeof a=="function"?a(k):a;return l.createElement(El,{...u,"aria-current":E,className:C,ref:p,style:N,to:i,viewTransition:c},typeof d=="function"?d(k):d)});jp.displayName="NavLink";var wp=l.forwardRef(({discover:e="render",fetcherKey:r,navigate:n,reloadDocument:s,replace:o,state:a,method:i=_n,action:c,onSubmit:d,relative:u,preventScrollReset:p,viewTransition:f,unstable_defaultShouldRevalidate:h,...m},g)=>{let{unstable_useTransitions:x}=l.useContext(Rt),v=Rp(),b=Tp(c,{relative:u}),y=i.toLowerCase()==="get"?"get":"post",j=typeof c=="string"&&Cl.test(c),S=w=>{if(d&&d(w),w.defaultPrevented)return;w.preventDefault();let R=w.nativeEvent.submitter,k=(R==null?void 0:R.getAttribute("formmethod"))||i,E=()=>v(R||w.currentTarget,{fetcherKey:r,method:k,navigate:n,replace:o,state:a,relative:u,preventScrollReset:p,viewTransition:f,unstable_defaultShouldRevalidate:h});x&&n!==!1?l.startTransition(()=>E()):E()};return l.createElement("form",{ref:g,method:y,action:b,onSubmit:s?d:S,...m,"data-discover":!j&&e==="render"?"true":void 0})});wp.displayName="Form";function Sp(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Nl(e){let r=l.useContext(Pr);return et(r,Sp(e)),r}function Cp(e,{target:r,replace:n,unstable_mask:s,state:o,preventScrollReset:a,relative:i,viewTransition:c,unstable_defaultShouldRevalidate:d,unstable_useTransitions:u}={}){let p=Du(),f=nr(),h=hn(e,{relative:i});return l.useCallback(m=>{if(rp(m,r)){m.preventDefault();let g=n!==void 0?n:nn(f)===nn(h),x=()=>p(e,{replace:g,unstable_mask:s,state:o,preventScrollReset:a,relative:i,viewTransition:c,unstable_defaultShouldRevalidate:d});u?l.startTransition(()=>x()):x()}},[f,p,h,n,s,o,r,e,a,i,c,d,u])}var Ep=0,Np=()=>`__${String(++Ep)}__`;function Rp(){let{router:e}=Nl("useSubmit"),{basename:r}=l.useContext(Rt),n=Ku(),s=e.fetch,o=e.navigate;return l.useCallback(async(a,i={})=>{let{action:c,method:d,encType:u,formData:p,body:f}=op(a,r);if(i.navigate===!1){let h=i.fetcherKey||Np();await s(h,n,i.action||c,{unstable_defaultShouldRevalidate:i.unstable_defaultShouldRevalidate,preventScrollReset:i.preventScrollReset,formData:p,body:f,formMethod:i.method||d,formEncType:i.encType||u,flushSync:i.flushSync})}else await o(i.action||c,{unstable_defaultShouldRevalidate:i.unstable_defaultShouldRevalidate,preventScrollReset:i.preventScrollReset,formData:p,body:f,formMethod:i.method||d,formEncType:i.encType||u,replace:i.replace,state:i.state,fromRouteId:n,flushSync:i.flushSync,viewTransition:i.viewTransition})},[s,o,r,n])}function Tp(e,{relative:r}={}){let{basename:n}=l.useContext(Rt),s=l.useContext(Jt);et(s,"useFormAction must be used inside a RouteContext");let[o]=s.matches.slice(-1),a={...hn(e||".",{relative:r})},i=nr();if(e==null){a.search=i.search;let c=new URLSearchParams(a.search),d=c.getAll("index");if(d.some(p=>p==="")){c.delete("index"),d.filter(f=>f).forEach(f=>c.append("index",f));let p=c.toString();a.search=p?`?${p}`:""}}return(!e||e===".")&&o.route.index&&(a.search=a.search?a.search.replace(/^\?/,"?index&"):"?index"),n!=="/"&&(a.pathname=a.pathname==="/"?n:Wt([n,a.pathname])),nn(a)}function Ip(e,{relative:r}={}){let n=l.useContext(gl);et(n!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:s}=Nl("useViewTransitionState"),o=hn(e,{relative:r});if(!n.isTransitioning)return!1;let a=Yt(n.currentLocation.pathname,s)||n.currentLocation.pathname,i=Yt(n.nextLocation.pathname,s)||n.nextLocation.pathname;return Kn(o.pathname,i)!=null||Kn(o.pathname,a)!=null}var $r=Qd();const Lp=Zd($r),Ap=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;function En(e){if(typeof e!="string")return null;const r=e.trim();return r===""||!Ap.test(r)||r==="0.0.0"?null:r}function Rl(e){if(e.preferInstalled){const o=En(e.installedCurrentVersion);if(o)return{version:o,versionSource:"registry"}}const r=En(e.frontmatterVersion);if(r)return{version:r,versionSource:"frontmatter"};const n=En(e.registryCurrentVersion);if(n)return{version:n,versionSource:"registry"};const s=En(e.pluginVersion);return s?{version:s,versionSource:"plugin"}:{version:"1.0.0",versionSource:"default"}}const Pp={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},ba={own:"authoring-project",installed:"available-project",global:"available-personal"},fo=new Set(["available-project","available-personal","available-plugin","authoring-project","authoring-plugin"]);function $p(e){if(typeof e=="string"){if(fo.has(e))return e;if(Object.prototype.hasOwnProperty.call(ba,e))return ba[e]}return"authoring-project"}function Mp(e){return e.startsWith("available-")?"available":"authoring"}function Dp(e){const r=e.indexOf("-");return e.slice(r+1)}const yt="";function Nn(e,r){try{let n=!1;const s=Pp;if(s&&(s.VITE_VSKILL_DEBUG_SSE==="1"||s.VITE_VSKILL_DEBUG_SSE==="true")&&(n=!0),!n&&typeof window<"u"&&typeof window.location<"u"&&new URLSearchParams(window.location.search).get("debugSse")==="1"&&(n=!0),!n)return;console.warn(`[vskill api] ${e}`,r)}catch{}}class qt extends Error{constructor(r,n,s){super(r),this.name="ApiError",this.status=n,this.details=s}}async function ye(e,r){const n=await fetch(`${yt}${e}`,r);if(!n.ok){const s=await n.json().catch(()=>({error:n.statusText})),o=s&&typeof s=="object"?s:void 0;throw new qt((s==null?void 0:s.error)||`HTTP ${n.status}`,n.status,o)}return n.json()}async function ka(e,r){const n=await fetch(e,r);return n.status>=502&&n.status<=504?(await new Promise(s=>setTimeout(s,250)),fetch(e,r)):n}const ja=100;function wa(e,r){if(e.length===0||r<=0)return[];const n=[];for(let s=0;s<e.length;s+=r)n.push(e.slice(s,s+r));return n}function Ge(e){return typeof e=="string"&&e.length>0?e:null}function Fp(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Sr(e){if(!Array.isArray(e))return null;const r=e.filter(n=>typeof n=="string"&&n.length>0);return r.length>0?r:null}function zp(e){if(!e||typeof e!="object")return null;const r=e,n=Ge(r.python)??void 0,s=Sr(r.pip)??void 0,o=Ge(r.node)??void 0;return!n&&!s&&!o?null:{python:n,pip:s,node:o}}function Bp(e){if(!e||typeof e!="object")return null;const r=e,n=r.runner;return n!=="vitest"&&n!=="pytest"&&n!=="none"?null:{runner:n,file:Ge(r.file)??void 0,requires:Sr(r.requires)??void 0}}function _p(e){const r=e??{};let n;r.origin==="source"||r.origin==="installed"?n=r.origin:(n="source",console.warn(`[api.getSkills] skill ${String(r.plugin)}/${String(r.skill)} has invalid origin=${JSON.stringify(r.origin)}; defaulting to 'source'`));let s;r.scope==="own"||r.scope==="installed"||r.scope==="global"?s=r.scope:s=n==="installed"?"installed":"own";let o;r.installMethod==="authored"||r.installMethod==="copied"||r.installMethod==="symlinked"?o=r.installMethod:o=s==="own"?"authored":"copied";const a=typeof r.scopeV2=="string"&&fo.has(r.scopeV2)?r.scopeV2:$p(r.scope),i=Mp(a),c=Dp(a),d=typeof r.precedenceRank=="number"?r.precedenceRank:void 0;let u;r.shadowedBy===null?u=null:typeof r.shadowedBy=="string"&&fo.has(r.shadowedBy)?u=r.shadowedBy:u=void 0;const p={plugin:typeof r.plugin=="string"?r.plugin:"",skill:typeof r.skill=="string"?r.skill:"",dir:typeof r.dir=="string"?r.dir:"",hasEvals:!!r.hasEvals,hasBenchmark:!!r.hasBenchmark,evalCount:typeof r.evalCount=="number"?r.evalCount:0,assertionCount:typeof r.assertionCount=="number"?r.assertionCount:0,benchmarkStatus:r.benchmarkStatus==="pass"||r.benchmarkStatus==="fail"||r.benchmarkStatus==="pending"||r.benchmarkStatus==="stale"||r.benchmarkStatus==="missing"?r.benchmarkStatus:"missing",lastBenchmark:typeof r.lastBenchmark=="string"?r.lastBenchmark:null,origin:n,scope:s,isSymlink:typeof r.isSymlink=="boolean"?r.isSymlink:!1,symlinkTarget:Ge(r.symlinkTarget),installMethod:o,sourcePath:Ge(r.sourcePath),scopeV2:a,group:i,source:c,pluginName:Ge(r.pluginName),pluginNamespace:Ge(r.pluginNamespace),pluginMarketplace:Ge(r.pluginMarketplace),pluginManifestPath:Ge(r.pluginManifestPath),pluginVersion:Ge(r.pluginVersion),...typeof r.pluginDisplay=="string"&&r.pluginDisplay?{pluginDisplay:r.pluginDisplay}:{},precedenceRank:d,shadowedBy:u,description:Ge(r.description),version:Ge(r.version),category:Ge(r.category),author:Ge(r.author),license:Ge(r.license),homepage:Ge(r.homepage),repoUrl:Ge(r.repoUrl),skillPath:Ge(r.skillPath),tags:Sr(r.tags),deps:Sr(r.deps),mcpDeps:Sr(r.mcpDeps),entryPoint:Ge(r.entryPoint),lastModified:Ge(r.lastModified),sizeBytes:Fp(r.sizeBytes),sourceAgent:Ge(r.sourceAgent),secrets:Sr(r.secrets),runtime:zp(r.runtime),integrationTests:Bp(r.integrationTests)};if(r.provenance&&typeof r.provenance=="object"){const h=r.provenance;(h.promotedFrom==="installed"||h.promotedFrom==="global")&&typeof h.sourcePath=="string"&&typeof h.promotedAt=="number"?p.provenance={promotedFrom:h.promotedFrom,sourcePath:h.sourcePath,promotedAt:h.promotedAt,sourceSkillVersion:typeof h.sourceSkillVersion=="string"?h.sourceSkillVersion:void 0}:p.provenance=null}else r.provenance===null&&(p.provenance=null);typeof r.updateAvailable=="boolean"&&(p.updateAvailable=r.updateAvailable),typeof r.currentVersion=="string"&&(p.currentVersion=r.currentVersion),typeof r.latestVersion=="string"&&(p.latestVersion=r.latestVersion),typeof r.pinnedVersion=="string"&&(p.pinnedVersion=r.pinnedVersion);const f=Rl({frontmatterVersion:p.version??null,registryCurrentVersion:p.currentVersion??null,pluginVersion:p.pluginVersion??null,installedCurrentVersion:p.currentVersion??null,preferInstalled:p.origin==="installed"});return p.resolvedVersion=f.version,p.versionSource=f.versionSource,p}const ie={getConfig(){return ye("/api/config")},setConfig(e,r){return ye("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:e,model:r})})},revealInEditor(e,r,n){return ye("/api/skills/reveal-in-editor",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n?{plugin:e,skill:r,file:n}:{plugin:e,skill:r})})},async getSkills(e){const r=new URLSearchParams;e!=null&&e.scope&&r.set("scope",e.scope),e!=null&&e.agent&&r.set("agent",e.agent);const n=r.toString(),s=await ye(`/api/skills${n?"?"+n:""}`);return Array.isArray(s)?s.map(_p):[]},getSkillInstallState(e){return ye(`/api/studio/install-state?skill=${encodeURIComponent(e)}`)},async convertToPlugin(e){return ye("/api/authoring/convert-to-plugin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},getAgents(){return ye("/api/agents")},getSkillDetail(e,r){return ye(`/api/skills/${e}/${r}`)},async getEvals(e,r){const n=await ye(`/api/skills/${e}/${r}/evals`);if(n&&typeof n=="object"&&"exists"in n){if(n.exists===!1)return{skill_name:r,evals:[]};const{exists:s,...o}=n;return o}return n},getEvalsEnvelope(e,r){return ye(`/api/skills/${e}/${r}/evals`)},getActivationHistoryEnvelope(e,r){return ye(`/api/skills/${e}/${r}/activation-history`)},saveEvals(e,r,n){return ye(`/api/skills/${e}/${r}/evals`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})},generateEvals(e,r){return ye(`/api/skills/${e}/${r}/generate-evals`,{method:"POST"})},async getLatestBenchmark(e,r){const n=await fetch(`${yt}/api/skills/${e}/${r}/benchmark/latest`);if(!n.ok){const s=await n.json().catch(()=>({error:n.statusText}));throw new qt(s.error||`HTTP ${n.status}`,n.status)}return n.json()},getHistory(e,r,n){const s=new URLSearchParams;n!=null&&n.model&&s.set("model",n.model),n!=null&&n.type&&s.set("type",n.type),n!=null&&n.from&&s.set("from",n.from),n!=null&&n.to&&s.set("to",n.to);const o=s.toString();return ye(`/api/skills/${e}/${r}/history${o?"?"+o:""}`)},getHistoryEntry(e,r,n){return ye(`/api/skills/${e}/${r}/history/${encodeURIComponent(n)}`)},compareRuns(e,r,n,s){return ye(`/api/skills/${e}/${r}/history-compare?a=${encodeURIComponent(n)}&b=${encodeURIComponent(s)}`)},getCaseHistory(e,r,n,s){const o=new URLSearchParams;s&&o.set("model",s);const a=o.toString();return ye(`/api/skills/${e}/${r}/history/case/${n}${a?"?"+a:""}`)},deleteHistoryEntry(e,r,n){return ye(`/api/skills/${e}/${r}/history/${encodeURIComponent(n)}`,{method:"DELETE"})},deleteSkill(e,r){return ye(`/api/skills/${e}/${r}`,{method:"DELETE"})},uninstallSkill(e,r){return ye(`/api/skills/${e}/${r}/uninstall`,{method:"POST"})},improveSkill(e,r,n){return ye(`/api/skills/${e}/${r}/improve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})},instructEdit(e,r,n){return ye(`/api/skills/${e}/${r}/improve`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:"instruct",...n})})},applyImprovement(e,r,n){return ye(`/api/skills/${e}/${r}/apply-improvement`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:n})})},getStats(e,r){return ye(`/api/skills/${e}/${r}/stats`)},getDependencies(e,r){return ye(`/api/skills/${e}/${r}/dependencies`)},getProjectLayout(){return ye("/api/project-layout")},getProjectGitHubStatus(){return ye("/api/project/github-status")},createSkill(e){return ye("/api/skills/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},detectEngines(){return ye("/api/studio/detect-engines")},saveDraft(e){return ye("/api/skills/save-draft",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},getSkillCreatorStatus(){return ye("/api/skill-creator-status")},generateSkill(e){return ye("/api/skills/generate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})},getSkillFiles(e,r){return ye(`/api/skills/${e}/${r}/files`)},getSkillFile(e,r,n){return ye(`/api/skills/${e}/${r}/file?path=${encodeURIComponent(n)}`)},saveSkillFile(e,r,n,s){return ye(`/api/skills/${e}/${r}/file`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n,content:s})})},getLeaderboard(e,r){return ye(`/api/skills/${e}/${r}/leaderboard`)},getLeaderboardEntry(e,r,n){return ye(`/api/skills/${e}/${r}/leaderboard/${encodeURIComponent(n)}`)},startSweep(e,r,n){const s=`${yt}/api/skills/${e}/${r}/sweep`,o=new EventSource(s);return fetch(s,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify(n)}),o},getCredentials(e,r){return ye(`/api/credentials/${e}/${r}`)},setCredential(e,r,n,s){return ye(`/api/credentials/${e}/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n,value:s})})},getParams(e,r){return ye(`/api/credentials/${e}/${r}/params`)},getParamsRevealed(e,r,n){const s=n?`reveal=true&key=${encodeURIComponent(n)}`:"reveal=true";return ye(`/api/credentials/${e}/${r}/params?${s}`)},searchModels(){return ye("/api/openrouter/models")},async getSkillVersions(e,r){const n=await ye(`/api/skills/${e}/${r}/versions`);return Array.isArray(n)?n:Array.isArray(n.versions)?n.versions:[]},getSkillVersionsEnvelope(e,r){return ye(`/api/skills/${e}/${r}/versions`)},getVersionDiff(e,r,n,s){return ye(`/api/skills/${e}/${r}/versions/diff?from=${n}&to=${s}`)},startBatchUpdate(e){const r=`${yt}/api/skills/batch-update`,n=new EventSource(r);return fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify({skills:e})}),n},startSkillUpdate(e,r){const n=`${yt}/api/skills/${e}/${r}/update`,s=new EventSource(n);return fetch(n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream"}}),s},async postSkillUpdate(e,r,n){let s,o;if(n&&typeof n.aborted=="boolean")s=n;else if(n&&typeof n=="object"){const p=n;s=p.signal,o=p.agentId}const a=o?`?agent=${encodeURIComponent(o)}`:"",i=`${yt}/api/skills/${e}/${r}/update${a}`,c=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},signal:s});let d,u="";if(c.body){const p=c.body.getReader(),f=new TextDecoder;let h=!1,m="";for(;!h;){const x=await p.read();if(h=x.done,x.value){const v=f.decode(x.value,{stream:!h});m+=v,u.length<200&&(u+=v)}}const g=m.match(/event:\s*done[\s\S]*?data:\s*(\{[^\n]+\})/);if(g)try{d=JSON.parse(g[1]).version}catch{}u=u.slice(0,200)}else{const p=await c.text();u=p.slice(0,200);const f=p.match(/event:\s*done[\s\S]*?data:\s*(\{[^\n]+\})/);if(f)try{d=JSON.parse(f[1]).version}catch{}}return{ok:c.ok,status:c.status,body:u,version:d}},async rescanSkill(e,r){const n=`${e}/${r}`,s=await fetch(`${yt}/api/v1/skills/${encodeURIComponent(n)}/rescan`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!s.ok)throw new Error(`rescan failed: HTTP ${s.status}`);return await s.json()},async getSkillUpdates(){try{const e=await fetch(`${yt}/api/skills/updates`);return e.ok?await e.json():[]}catch{return[]}},async checkSkillUpdates(e){if(e.length===0)return[];const r=[...e].sort(),n=wa(r,ja),s=async a=>{try{const i=await ka(`${yt}/api/v1/skills/check-updates`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({skills:a.map(d=>({name:d,currentVersion:"0.0.0"}))})});if(!i.ok)return[];const c=await i.json().catch(()=>null);return Array.isArray(c)?c:c&&typeof c=="object"&&Array.isArray(c.results)?c.results.map(d=>({skillId:typeof d.skillId=="string"?d.skillId:typeof d.name=="string"?d.name:"",version:typeof d.version=="string"?d.version:typeof d.latest=="string"?d.latest:"",eventId:typeof d.eventId=="string"?d.eventId:"",publishedAt:typeof d.publishedAt=="string"?d.publishedAt:"",diffSummary:typeof d.diffSummary=="string"?d.diffSummary:void 0,trackedForUpdates:typeof d.trackedForUpdates=="boolean"?d.trackedForUpdates:void 0,updateAvailable:typeof d.updateAvailable=="boolean"?d.updateAvailable:void 0,installed:typeof d.installed=="string"&&d.installed!=="0.0.0"?d.installed:void 0,latest:typeof d.latest=="string"?d.latest:void 0,name:typeof d.name=="string"?d.name:void 0})):[]}catch{return[]}};return(await Promise.all(n.map(s))).flat()},async resolveInstalledSkillIds(e){if(e.length===0)return[];const r=wa(e,ja),n=async a=>{try{const i=await ka(`${yt}/api/v1/skills/check-updates`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({skills:a.map(u=>({name:u.name,currentVersion:u.currentVersion??"0.0.0"}))})});if(!i.ok)return{ok:!1,map:new Map};const c=await i.json().catch(()=>null),d=Array.isArray(c)?c:Array.isArray(c==null?void 0:c.results)?c.results:[];return{ok:!0,map:new Map(d.filter(u=>typeof u.name=="string"&&u.name.length>0).map(u=>[u.name,u]))}}catch{return{ok:!1,map:new Map}}},s=await Promise.all(r.map(n));if(s.length>0&&s.every(a=>!a.ok))throw new Error("resolveInstalledSkillIds: all chunks failed");const o=new Map;for(const a of s)for(const[i,c]of a.map)o.set(i,c);return e.map(a=>{const i=o.get(a.name);return{plugin:a.plugin,skill:a.skill,uuid:typeof(i==null?void 0:i.id)=="string"&&i.id.length>0?i.id:void 0,slug:typeof(i==null?void 0:i.slug)=="string"&&i.slug.length>0?i.slug:void 0}})},async lookupSkillsByName(e){if(!Array.isArray(e)||e.length===0)return[];const r=e.slice(0,50);try{const n=await fetch(`${yt}/api/v1/skills/lookup-by-name`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({entries:r})});if(!n.ok)return Nn("lookup-by-name-error",{status:n.status}),[];const s=await n.json().catch(a=>(Nn("lookup-by-name-parse-error",{message:a instanceof Error?a.message:String(a)}),null)),o=s&&typeof s=="object"&&"results"in s?s.results:null;return Array.isArray(o)?o.filter(a=>a!==null&&typeof a=="object").map(a=>({name:typeof a.name=="string"?a.name:"",author:typeof a.author=="string"?a.author:"",uuid:typeof a.uuid=="string"&&a.uuid.length>0?a.uuid:void 0,slug:typeof a.slug=="string"&&a.slug.length>0?a.slug:void 0})).filter(a=>a.name.length>0):(s!==null&&Nn("lookup-by-name-no-results-array",{}),[])}catch(n){return Nn("lookup-by-name-fetch-error",{message:n instanceof Error?n.message:String(n)}),[]}},promoteSkill(e,r,n){const s=n!=null&&n.overwrite?"?overwrite=true":"";return vs(`/api/skills/${e}/${r}/promote${s}`,n==null?void 0:n.onEvent,n==null?void 0:n.signal)},testInstallSkill(e,r,n){const s=new URLSearchParams;(n==null?void 0:n.dest)==="global"&&s.set("dest","global"),n!=null&&n.overwrite&&s.set("overwrite","true");const o=s.toString();return vs(`/api/skills/${e}/${r}/test-install${o?"?"+o:""}`,n==null?void 0:n.onEvent,n==null?void 0:n.signal)},revertSkill(e,r,n){return vs(`/api/skills/${e}/${r}/revert`,n==null?void 0:n.onEvent,n==null?void 0:n.signal)},listStudioOps(e){const r=new URLSearchParams;(e==null?void 0:e.before)!=null&&r.set("before",String(e.before)),(e==null?void 0:e.limit)!=null&&r.set("limit",String(e.limit));const n=r.toString();return ye(`/api/studio/ops${n?"?"+n:""}`)},deleteStudioOp(e){return ye(`/api/studio/ops/${encodeURIComponent(e)}`,{method:"DELETE"})},studioOpsStream(){return new EventSource(`${yt}/api/studio/ops/stream`)},gitRemote(){return ye("/api/git/remote")},gitDiff(){return ye("/api/git/diff",{method:"POST"})},gitStatus(){return ye("/api/git/status")},gitCommitMessage(e){return ye("/api/git/commit-message",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e??{})})},gitPublish(e){return ye("/api/git/publish",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e??{})})},async getAccountTenants(){return ye("/api/v1/account/tenants")},async getActiveTenant(){return ye("/__internal/active-tenant")},async setActiveTenant(e){return ye("/__internal/active-tenant",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({currentTenant:e})})}};async function vs(e,r,n){const s=await fetch(`${yt}${e}`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream"},signal:n});if(!s.ok||!s.body){let p=`HTTP ${s.status}`,f;try{const m=await s.json();m.error&&(p=m.error),typeof m.code=="string"&&(f=m.code)}catch{}const h=new qt(p,s.status);throw f&&(h.code=f),h}const o=s.body.getReader(),a=new TextDecoder;let i="",c="",d=null,u=null;for(;;){const{done:p,value:f}=await o.read();if(p)break;i+=a.decode(f,{stream:!0});const h=i.split(`
14
+ `);i=h.pop()??"";for(const m of h)if(m.startsWith("event: "))c=m.slice(7).trim();else if(m.startsWith("data: ")){let g={};try{g=JSON.parse(m.slice(6))}catch{c="";continue}if(c==="started"||c==="copied"||c==="deleted"||c==="indexed"||c==="done"||c==="error"){const x={type:c,...g};r==null||r(x),x.type==="done"&&(d=x),x.type==="error"&&(u=x)}c=""}}if(u){const p=new qt(u.message,500);throw p.code=u.code,p}if(!d)throw new qt("Transfer stream ended without 'done' event",500);return d}function Op(e,r){if(!e||!r)return!1;const n=/^(\d+)\.(\d+)\.(\d+)/,s=e.match(n),o=r.match(n);if(!s||!o)return!1;const[,a,i,c]=s.map(Number),[,d,u,p]=o.map(Number);return a!==d?a>d:i!==u?i>u:c>=p}function Wp(e,r){if(!r.length)return e;const n=new Map,s=new Map;for(const o of r){const a=o.name.split("/"),i=a.pop()||o.name;if(s.set(i,o),a.length>=1){const c=a[a.length-1];n.set(`${c}/${i}`,o)}}return e.map(o=>{if(o.origin!=="installed")return o;let a;if(o.pluginName?a=n.get(`${o.pluginName}/${o.skill}`):a=s.get(o.skill),!a)return o;const i=a.updateAvailable&&!Op(o.version,a.latest),c=a.installed&&a.installed!=="0.0.0"?a.installed:null,d={...o,updateAvailable:i,currentVersion:c??o.currentVersion,latestVersion:a.latest??void 0};typeof a.trackedForUpdates=="boolean"&&(d.trackedForUpdates=a.trackedForUpdates);const u=Rl({frontmatterVersion:d.version??null,registryCurrentVersion:d.currentVersion??null,pluginVersion:d.pluginVersion??null,installedCurrentVersion:d.currentVersion??null,preferInstalled:!0});return d.resolvedVersion=u.version,d.versionSource=u.versionSource,d})}const Wn=new Map,cr=new Map,qr=new Map;function ze(e){Wn.delete(e),cr.delete(e);const r=qr.get(e);if(r)for(const n of r)n()}function wt(e,r,n={}){const{ttl:s=3e4,enabled:o=!0}=n,[,a]=l.useState(0),[i,c]=l.useState(void 0),[d,u]=l.useState(0),p=l.useRef(!0),f=l.useRef(e);f.current=e;const h=()=>{c(void 0),ze(e),u(x=>x+1)};l.useEffect(()=>(p.current=!0,()=>{p.current=!1}),[]),l.useEffect(()=>{if(!o)return;const x=()=>{p.current&&u(v=>v+1)};return qr.has(e)||qr.set(e,new Set),qr.get(e).add(x),()=>{var v;(v=qr.get(e))==null||v.delete(x)}},[e,o]),l.useEffect(()=>{if(!o)return;const x=Wn.get(e);if(!(!x||Date.now()-x.fetchedAt>s))return;if(cr.has(e)){const j=cr.get(e),S=()=>{p.current&&f.current===e&&a(w=>w+1)};j.subscribers.push(S);return}const b={promise:Promise.resolve(),subscribers:[]},y=r().then(j=>{Wn.set(e,{data:j,fetchedAt:Date.now()}),cr.delete(e),p.current&&f.current===e&&(c(void 0),a(S=>S+1));for(const S of b.subscribers)S()},j=>{cr.delete(e);const S=j instanceof Error?j:new Error(String(j));p.current&&f.current===e&&(c(S),a(w=>w+1));for(const w of b.subscribers)w()});b.promise=y,cr.set(e,b)},[e,r,s,o,d]);const m=Wn.get(e),g=o&&!m&&!i&&cr.has(e);return{data:m==null?void 0:m.data,loading:g,error:i,revalidate:h}}function Hp(e){const[r,n]=l.useState(()=>typeof window>"u"?!1:window.matchMedia(e).matches);return l.useEffect(()=>{const s=window.matchMedia(e);n(s.matches);const o=a=>n(a.matches);return s.addEventListener("change",o),()=>s.removeEventListener("change",o)},[e]),r}const Up=500,ho="vskill.updates.seenLastId";function Vp(){if(typeof window>"u")return null;try{return window.localStorage.getItem(ho)}catch{return null}}function ys(e){if(!(typeof window>"u"))try{e==null?window.localStorage.removeItem(ho):window.localStorage.setItem(ho,e)}catch{}}function Gp(){let e=new Map;const r=new Set,n=new Set,s=[];let o=Vp();o&&(n.add(o),s.push(o));function a(){e=new Map(e);for(const c of Array.from(r))c()}function i(c){if(!n.has(c)){if(n.add(c),s.push(c),s.length>Up){const d=s.shift();d&&n.delete(d)}o=c,ys(c)}}return{getSnapshot(){return e},subscribe(c){return r.add(c),()=>{r.delete(c)}},ingest(c){return n.has(c.eventId)?"duplicate":(i(c.eventId),e.set(c.skillId,{skillId:c.skillId,version:c.version,diffSummary:c.diffSummary,eventId:c.eventId,publishedAt:c.publishedAt,receivedAt:Date.now()}),a(),"stored")},dismiss(c){e.has(c)&&(e.delete(c),a())},clearSeen(){n.clear(),s.length=0,o=null,ys(null)},mergeBulk(c){if(c.length!==0){for(const d of c)e.set(d.skillId,d);a()}},getSeenLastId(){return o},reset(){e=new Map,n.clear(),s.length=0,o=null,ys(null),a()}}}const Qt=Gp(),Tl="vskill:toast-queue",Kp=10,qp=1800*1e3;function ns(){return typeof window<"u"&&typeof window.localStorage<"u"}function Il(){if(!ns())return[];try{const e=window.localStorage.getItem(Tl);if(!e)return[];const r=JSON.parse(e);return Array.isArray(r)?r.filter(n=>n&&typeof n=="object"&&typeof n.eventId=="string"&&typeof n.skillId=="string"&&typeof n.version=="string"&&typeof n.enqueuedAt=="number"&&typeof n.message=="string"):[]}catch{return[]}}function Ll(e){if(ns())try{window.localStorage.setItem(Tl,JSON.stringify(e))}catch{}}function Yp(e){if(!ns())return"enqueued";const r=Il();if(r.some(o=>o.eventId===e.eventId))return"deduped";let n=!1;const s=[...r,e];for(;s.length>Kp;)s.shift(),n=!0;return Ll(s),n?"evicted":"enqueued"}function Jp(){if(!ns())return[];const e=Il();if(e.length===0)return[];Ll([]);const r=Date.now()-qp;return e.filter(n=>n.enqueuedAt>=r)}const Xp="X-Studio-Token";let ur=null,Or=null,Sa=!1,Rn=null;function Qp(){var e;return typeof window>"u"?!1:!!((e=window.__TAURI_INTERNALS__)!=null&&e.invoke)}function Wo(){if(typeof document>"u")return null;const e=document.getElementById("__vskill_studio_token__");if(!e||!e.textContent)return null;try{const r=JSON.parse(e.textContent);if(typeof r.token=="string"&&r.token.length>0)return r.token}catch{}return null}async function Zp(){var n;if(typeof window>"u")return null;const r=(n=window.__TAURI_INTERNALS__)==null?void 0:n.invoke;if(!r)return null;try{const s=await r("get_studio_token");return typeof s=="string"&&s.length>0?s:null}catch{return null}}async function ef(){if(ur)return ur;const e=Wo();return e?(ur=e,e):Or||(Or=Zp().then(r=>(r&&(ur=r),Or=null,r)),Or)}function tf(e){if(typeof window>"u")return!1;if(e.startsWith("/api/"))return!0;try{const r=window.location.origin;if(e.startsWith(`${r}/api/`))return!0}catch{}return!1}function rf(){Sa||typeof globalThis.fetch!="function"||!(Wo()!==null)&&!Qp()||(Sa=!0,Rn=globalThis.fetch.bind(globalThis),globalThis.fetch=async(r,n)=>{let s;if(typeof r=="string"?s=r:r instanceof URL?s=r.toString():s=r.url,!tf(s))return Rn(r,n);const o=await ef();if(!o)return Rn(r,n);const a={...n??{}},i=new Headers(a.headers??{});return i.set(Xp,o),a.headers=i,Rn(r,a)})}function nf(){if(ur)return ur;const e=Wo();return e?(ur=e,e):null}const sf=3e5,of=500,af=15e3,lf=6e4,cf=6e4,df="/api/v1/skills/stream",uf=250,pf="/api/v1/studio/telemetry/sse",Ca="vskill.studio.sse.sessionId";function Al(){var e;try{const r=(e=import.meta)==null?void 0:e.env;if(r&&typeof r=="object")return r}catch{}return{}}function ff(){if(typeof window>"u")return!1;const e=Al();if(e.VITE_VSKILL_DEBUG_SSE==="1"||e.VITE_VSKILL_DEBUG_SSE==="true")return!0;try{if(new URLSearchParams(window.location.search).get("debugSse")==="1")return!0}catch{}return!1}function hf(){if(typeof window>"u")return!0;const e=Al();if(e.VITE_VSKILL_DISABLE_TELEMETRY==="1"||e.VITE_VSKILL_DISABLE_TELEMETRY==="true")return!0;try{if(new URLSearchParams(window.location.search).get("disableTelemetry")==="1")return!0}catch{}return!1}function Ct(e,r){if(ff())try{const n=new Date().toISOString();r?console.debug(`[sse] ${n} ${e}`,r):console.debug(`[sse] ${n} ${e}`)}catch{}}function Ea(){if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")try{return crypto.randomUUID()}catch{}const e=[];for(let r=0;r<16;r++)e.push(Math.floor(Math.random()*256).toString(16).padStart(2,"0"));return e[6]=(parseInt(e[6],16)&15|64).toString(16).padStart(2,"0"),e[8]=(parseInt(e[8],16)&63|128).toString(16).padStart(2,"0"),e.slice(0,4).join("")+"-"+e.slice(4,6).join("")+"-"+e.slice(6,8).join("")+"-"+e.slice(8,10).join("")+"-"+e.slice(10,16).join("")}function mf(){if(typeof window>"u")return"";try{const e=window.sessionStorage.getItem(Ca);if(e)return e;const r=Ea();return window.sessionStorage.setItem(Ca,r),r}catch{return Ea()}}function Na(e){const r=new Map;for(const s of e)r.set(s.name,s);const n=new Map;for(const s of e){const o=s.name.split("/").pop()||s.name;o!==s.name&&n.set(o,(n.get(o)??0)+1)}for(const s of e){const o=s.name.split("/").pop()||s.name;o!==s.name&&((n.get(o)??0)>1||r.has(o)||r.set(o,s))}return r}function Ra(e){let r=0;for(const n of e)n.updateAvailable&&r++;return r}function xf(e){if(!e||typeof e!="object")return!1;const r=e;return r.type==="skill.updated"&&typeof r.eventId=="string"&&typeof r.skillId=="string"&&typeof r.version=="string"}function gf(e){const r=(e==null?void 0:e.intervalMs)??sf,n=(e==null?void 0:e.debounceMs)??of,s=(e==null?void 0:e.timeoutMs)??af,o=(e==null?void 0:e.staleAfterMs)??lf,a=(e==null?void 0:e.disconnectFallbackMs)??cf,i=(e==null?void 0:e.streamUrlBase)??df,c=(e==null?void 0:e.replayIntervalMs)??uf,d=l.useMemo(()=>!(e!=null&&e.skillIds)||e.skillIds.length===0?"":[...e.skillIds].sort().join(","),[e==null?void 0:e.skillIds]),u=l.useMemo(()=>{const A=(e==null?void 0:e.trackingSkillIds)??(e==null?void 0:e.skillIds)??[];return A.length===0?"":[...A].sort().join(",")},[e==null?void 0:e.trackingSkillIds,e==null?void 0:e.skillIds]),[p,f]=l.useState([]),[h,m]=l.useState(()=>new Map),[g,x]=l.useState(0),[v,b]=l.useState(!1),[y,j]=l.useState(null),[S,w]=l.useState(null),R=l.useRef(null),k=l.useRef(null),E=l.useRef(null),C=l.useRef(null),N=l.useRef(!0),I=l.useRef(new Set),[P,L]=l.useState(()=>d?"connecting":"fallback"),B=l.useRef(P);B.current=P;const T=l.useRef(new Set),$=l.useRef(null),M=l.useSyncExternalStore(A=>Qt.subscribe(A),()=>Qt.getSnapshot(),()=>Qt.getSnapshot()),F=M.size,W=l.useCallback(A=>{if(hf()||T.current.has(A))return;T.current.add(A);const O=mf(),V=Date.now(),re={event:A,sessionId:O,sourceTier:"platform-proxy",timestamp:V};A!=="connected"&&$.current!=null&&(re.durationSinceOpenMs=V-$.current);try{fetch(pf,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(re),keepalive:!0}).catch(()=>{})}catch{}},[]),le=l.useCallback(async()=>{b(!0);const A=new AbortController,O=setTimeout(()=>A.abort(),s);try{const V=await Promise.race([ie.getSkillUpdates(),new Promise((re,ce)=>{A.signal.addEventListener("abort",()=>{ce(new Error("TIMEOUT"))})})]);if(V==="TIMEOUT")throw new Error("TIMEOUT");if(!N.current)return;f(V),m(Na(V)),x(Ra(V)),k.current=Date.now(),j(k.current),w(null)}catch(V){if(!N.current)return;w(V instanceof Error?V:new Error(String(V)))}finally{clearTimeout(O),N.current&&b(!1)}},[s]),U=l.useCallback(()=>{if(R.current)return R.current;const A=le().finally(()=>{R.current=null});return R.current=A,A},[le]),H=l.useCallback(()=>{E.current==null&&(E.current=setInterval(()=>{U()},r))},[r,U]),ee=l.useCallback(()=>{E.current!=null&&(clearInterval(E.current),E.current=null)},[]),K=l.useCallback(()=>{if(typeof window>"u")return;const A=Jp();A.length!==0&&(Ct("queue-drain",{count:A.length}),A.forEach((O,V)=>{let re;re=setTimeout(()=>{if(I.current.delete(re),!N.current)return;const ne=Qt.getSnapshot().get(O.skillId);if(ne&&ne.eventId!==O.eventId){Ct("queue-replay-skip-superseded",{queuedEventId:O.eventId,currentEventId:ne.eventId});return}try{window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:O.message,severity:O.severity,skillId:O.skillId,version:O.version,eventId:O.eventId}})),Ct("queue-replay",{eventId:O.eventId})}catch{}},V*c),I.current.add(re)}))},[c]),X=l.useCallback(()=>{for(const A of I.current)clearTimeout(A);I.current.clear()},[]);l.useEffect(()=>{N.current=!0,(k.current==null||Date.now()-k.current>o)&&U(),(typeof document>"u"||document.visibilityState!=="hidden")&&H();const V=()=>{if(C.current&&(clearTimeout(C.current),C.current=null),document.visibilityState==="hidden"){ee();return}K(),C.current=setTimeout(()=>{C.current=null,(k.current==null||Date.now()-k.current>o)&&U(),H()},n)};return typeof document<"u"&&document.addEventListener("visibilitychange",V),()=>{N.current=!1,typeof document<"u"&&document.removeEventListener("visibilitychange",V),C.current&&clearTimeout(C.current),X(),ee()}},[]);const G=l.useCallback(async A=>{if(A.length!==0)try{const O=await ie.checkSkillUpdates(A);if(!N.current||O.length===0)return;const V=Date.now(),re=O.filter(ne=>ne.skillId&&ne.eventId&&ne.version).map(ne=>({skillId:ne.skillId,version:ne.version,eventId:ne.eventId,publishedAt:ne.publishedAt,diffSummary:ne.diffSummary,receivedAt:V}));re.length>0&&Qt.mergeBulk(re);const ce=O.filter(ne=>typeof ne.trackedForUpdates=="boolean"||typeof ne.updateAvailable=="boolean").map(ne=>({name:ne.name??ne.skillId,installed:ne.installed??"",latest:ne.latest??null,updateAvailable:ne.updateAvailable??!1,trackedForUpdates:typeof ne.trackedForUpdates=="boolean"?ne.trackedForUpdates:void 0}));ce.length>0&&f(ne=>{const ve=new Map;for(const fe of ne)ve.set(fe.name,fe);let ge=0;for(const fe of ce){const z=fe.name,q=ve.get(z);if(q){const Z={...q};q.trackedForUpdates===void 0&&fe.trackedForUpdates!==void 0&&(Z.trackedForUpdates=fe.trackedForUpdates),ve.set(z,Z)}else ve.set(z,{name:fe.name,installed:fe.installed??"",latest:fe.latest??null,updateAvailable:fe.updateAvailable??!1,trackedForUpdates:fe.trackedForUpdates}),ge+=1}if(ge===0&&ve.size===ne.length)return ne;const se=[...ve.values()];return m(Na(se)),x(Ra(se)),se})}catch{}},[]);l.useEffect(()=>{const A=d||u;if(!A){L("fallback");return}if(typeof window>"u"||typeof EventSource>"u"){L("fallback");return}L("connecting");const O=A.split(",");let V=`${i}?skills=${encodeURIComponent(A)}`;const re=nf();re&&(V+=`&studioToken=${encodeURIComponent(re)}`);let ce=null,ne=null,ve=null;const ge=()=>{ne==null&&(ne=setTimeout(()=>{ne=null,N.current&&B.current!=="connected"&&(L("fallback"),Ct("fallback-flipped",{reason:"watchdog-timeout"}),W("fallback"))},a),Ct("fallback-armed",{fallbackMs:a}))},se=()=>{ne!=null&&(clearTimeout(ne),ne=null)};ge();const fe=1e3,z=()=>{N.current&&ve==null&&(ve=setTimeout(()=>{if(ve=null,!!N.current&&!(ce&&ce.readyState!==EventSource.CLOSED)){if(ce)try{ce.close()}catch{}Ct("reconnect-scheduled",{backoffMs:fe}),W("reconnect-scheduled"),J()}},fe))},q=ue=>{if(!N.current)return;let de;try{de=JSON.parse(ue.data)}catch{return}if(!xf(de))return;const we=Qt.ingest(de);if(Ct("message",{eventId:de.eventId,skillId:de.skillId,outcome:we}),we==="duplicate")return;const Ie=typeof document>"u"||document.visibilityState!=="hidden",Fe=`${de.skillId} updated to ${de.version}`;if(Ie)try{window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:Fe,severity:"info",skillId:de.skillId,version:de.version,eventId:de.eventId}}))}catch{}else{const Ke={message:Fe,severity:"info",skillId:de.skillId,version:de.version,eventId:de.eventId,enqueuedAt:Date.now()},Ye=Yp(Ke);Ct("queue-enqueue",{eventId:de.eventId,outcome:Ye})}},Z=()=>{N.current&&(Ct("gone",{skillsCount:O.length}),W("gone-frame-received"),Qt.clearSeen(),G(O))},J=()=>{N.current&&(ce=new EventSource(V),Ct("open-attempt",{url:V}),ce.onopen=()=>{N.current&&(se(),L("connected"),$.current=Date.now(),Ct("open",{url:V}),W("connected"))},ce.onerror=()=>{N.current&&(Ct("error",{readyState:ce==null?void 0:ce.readyState}),ge(),ce&&ce.readyState===EventSource.CLOSED&&z())},ce.onmessage=q,ce.addEventListener("gone",Z))};return J(),()=>{if(se(),ve!=null&&(clearTimeout(ve),ve=null),ce){try{ce.removeEventListener("gone",Z)}catch{}try{ce.close()}catch{}}X()}},[d,u,i,a,G,W,X]),l.useEffect(()=>{if(!u)return;const A=u.split(",");G(A)},[u,G]);const he=l.useCallback(A=>{Qt.dismiss(A)},[]);return{updates:p,updatesMap:h,updateCount:g,isRefreshing:v,lastFetchAt:y,error:S,refresh:U,updatesById:M,pushUpdateCount:F,status:P,dismiss:he}}function Ta(e){return typeof e=="string"&&e.length>0}function vf(e){const r=[];for(const n of e){const s=Ta(n.uuid),o=Ta(n.slug);if(!s&&!o)continue;const a={};s&&(a.uuid=n.uuid),o&&(a.slug=n.slug),r.push(a)}return r}const yf={selectedSkill:null,mode:"browse",searchQuery:"",skills:[],skillsLoading:!0,skillsError:null,isMobile:!1,mobileView:"list",updateNotificationDismissed:!1,revealSkillId:null};function bf(e,r){switch(r.type){case"SELECT_SKILL":return{...e,selectedSkill:r.skill,mode:"browse",mobileView:e.isMobile?"detail":e.mobileView};case"CLEAR_SELECTION":return{...e,selectedSkill:null};case"SET_MODE":return{...e,mode:r.mode,selectedSkill:r.mode==="create"?null:e.selectedSkill};case"SET_SEARCH":return{...e,searchQuery:r.query};case"SET_SKILLS":return{...e,skills:r.skills,skillsLoading:!1,skillsError:null};case"SET_SKILLS_ERROR":return{...e,skillsError:r.error,skillsLoading:!1};case"SET_SKILLS_LOADING":return{...e,skillsLoading:r.loading};case"SET_MOBILE":return{...e,isMobile:r.isMobile};case"SET_MOBILE_VIEW":return{...e,mobileView:r.view};case"DISMISS_UPDATE_NOTIFICATION":return{...e,updateNotificationDismissed:!0};case"REVEAL_SKILL":return{...e,selectedSkill:r.skill,revealSkillId:`${r.skill.plugin}/${r.skill.skill}`,mode:"browse",mobileView:e.isMobile?"detail":e.mobileView};case"CLEAR_REVEAL":return{...e,revealSkillId:null};default:return e}}const Pl=l.createContext(null),$l=Pl;function Mt(){const e=l.useContext($l);if(!e)throw new Error("useStudio must be used within StudioProvider");return e}function kf({children:e}){const[r,n]=l.useReducer(bf,yf),s=Hp("(max-width: 767px)");l.useEffect(()=>{n({type:"SET_MOBILE",isMobile:s})},[s]);const[o,a]=l.useState(()=>{try{const K=window.localStorage.getItem("vskill.studio.prefs");if(!K)return null;const X=JSON.parse(K);return typeof X.activeAgent=="string"?X.activeAgent:null}catch{return null}}),[i,c]=l.useState(o!==null);l.useEffect(()=>{function K(X){if(!(X instanceof CustomEvent))return;const G=X.detail;G!=null&&G.agentId&&(a(G.agentId),c(!0))}return window.addEventListener("studio:agent-changed",K),()=>window.removeEventListener("studio:agent-changed",K)},[]),l.useEffect(()=>{if(i)return;let K=!1;return ie.getAgents().then(X=>{if(K)return;const G=(X==null?void 0:X.suggested)??"claude-code";a(he=>he??G),c(!0)}).catch(()=>{K||(a(X=>X??"claude-code"),c(!0))}),()=>{K=!0}},[i]);const d=l.useCallback(()=>{if(!i||!o)return Promise.resolve();n({type:"SET_SKILLS_LOADING",loading:!0});const K={agent:o};return ie.getSkills(K).then(X=>{n({type:"SET_SKILLS",skills:X});const G=window.location.hash,he=G.match(/^#\/skills\/(project|personal|plugin)\/([^/]+)\/([^/?]+)/);if(he){const[,O,V,re]=he,ce=O,ne=X.find(ge=>ge.plugin===V&&ge.skill===re&&ge.source===ce);if(ne){n({type:"SELECT_SKILL",skill:{plugin:V,skill:re,origin:ne.origin,source:ne.source}});return}const ve=X.find(ge=>ge.plugin===V&&ge.skill===re);ve&&n({type:"SELECT_SKILL",skill:{plugin:V,skill:re,origin:ve.origin,source:ve.source}});return}const A=G.match(/^#\/skills\/([^/]+)\/([^/?]+)/);if(A){const[,O,V]=A,re=X.find(ce=>ce.plugin===O&&ce.skill===V);re&&n({type:"SELECT_SKILL",skill:{plugin:O,skill:V,origin:re.origin,source:re.source}})}}).catch(X=>n({type:"SET_SKILLS_ERROR",error:X.message}))},[o,i]);l.useEffect(()=>{d()},[d]);const u=l.useCallback(K=>{n({type:"SELECT_SKILL",skill:K}),window.location.hash=K.source?`/skills/${K.source}/${K.plugin}/${K.skill}`:`/skills/${K.plugin}/${K.skill}`},[]),p=l.useRef(r.skills);l.useEffect(()=>{p.current=r.skills},[r.skills]);const f=l.useCallback((K,X)=>{const G=p.current,he=K?G.find(re=>re.plugin===K&&re.skill===X):G.find(re=>re.skill===X&&re.source!=="plugin");if(!K&&!he){typeof console<"u"&&console.warn(`[StudioContext] revealSkill: no plugin provided and skill "${X}" not yet in state — skipping reveal`);return}const A=(he==null?void 0:he.plugin)??K,O=(he==null?void 0:he.origin)??"source",V=he==null?void 0:he.source;n({type:"REVEAL_SKILL",skill:{plugin:A,skill:X,origin:O,source:V}}),window.location.hash=V?`/skills/${V}/${A}/${X}`:`/skills/${A}/${X}`},[]),h=l.useCallback(()=>{n({type:"CLEAR_REVEAL"})},[]),m=l.useCallback(()=>{n({type:"CLEAR_SELECTION"}),window.location.hash.startsWith("#/skills/")&&history.replaceState(null,"",window.location.pathname+window.location.search)},[]),g=l.useCallback(K=>{n({type:"SET_MODE",mode:K})},[]),x=l.useCallback(K=>{n({type:"SET_SEARCH",query:K})},[]),v=l.useCallback(K=>{n({type:"SET_MOBILE_VIEW",view:K})},[]),b=l.useCallback(()=>{n({type:"DISMISS_UPDATE_NOTIFICATION"})},[]),y=l.useRef(new Map),j=l.useRef(""),S=l.useRef(!1),[w,R]=l.useState(""),k=l.useRef(""),E=l.useRef(""),[C,N]=l.useState(""),I=l.useMemo(()=>r.skills.map(K=>`${K.plugin}/${K.skill}`),[r.skills]),P=l.useMemo(()=>{const K=w?w.split(",").filter(Boolean):[],X=C?C.split(",").filter(Boolean):[];return K.length===0&&X.length===0?[]:[...new Set([...K,...X])]},[w,C]),L=gf({skillIds:P,trackingSkillIds:I}),B=l.useMemo(()=>P.length,[P]),T=l.useRef("");l.useEffect(()=>{const K=r.skills.filter(O=>O.origin==="installed");if(K.length===0){R(""),T.current="";return}const X=new Map;for(const O of L.updates)X.set(O.name.split("/").pop()||O.name,O);const G=K.map(O=>{const V=X.get(O.skill),re=O.currentVersion??(V==null?void 0:V.installed)??O.version??O.pluginVersion??"1.0.0";return{plugin:O.plugin,skill:O.skill,name:(V==null?void 0:V.name)??O.skill,currentVersion:re}}),he=G.map(O=>`${O.plugin}/${O.skill}@${O.currentVersion}#${O.name}`).sort().join("|");if(he===T.current)return;T.current=he;let A=!1;return ie.resolveInstalledSkillIds(G).then(O=>{if(A)return;const ce=[...vf(O).flatMap(ne=>[ne.uuid,ne.slug].filter(Boolean))].sort().join(",");ce!==j.current&&(j.current=ce,y.current=new Map(O.map(ne=>[`${ne.plugin}/${ne.skill}`,{uuid:ne.uuid,slug:ne.slug}])),R(ce))}).catch(O=>{if(A||(T.current=""),!S.current){S.current=!0;const V=O instanceof Error?O.message:String(O);console.warn("[studio] resolveInstalledSkillIds failed (using polling fallback):",V)}}),()=>{A=!0}},[r.skills,L.updates]),l.useEffect(()=>{const K=r.skills.filter(A=>A.origin==="source"&&typeof A.author=="string"&&A.author.length>0);if(K.length===0){k.current!==""&&(k.current="",N("")),E.current="";return}const X=K.map(A=>({name:A.skill,author:A.author})),G=X.map(A=>`${A.name.toLowerCase()}|${A.author}`).sort().join(`
15
+ `);if(G===E.current)return;E.current=G;let he=!1;return ie.lookupSkillsByName(X).then(A=>{if(he)return;const O=A.flatMap(re=>[re.uuid,re.slug]).filter(re=>typeof re=="string"&&re.length>0),V=[...new Set(O)].sort().join(",");V!==k.current&&(k.current=V,N(V))}).catch(()=>{he||(E.current="")}),()=>{he=!0}},[r.skills]);const $=l.useMemo(()=>{const K=r.skills.map(X=>{if(!X.updateAvailable&&X.latestVersion===void 0&&X.trackedForUpdates===void 0)return X;const G={...X};return delete G.updateAvailable,delete G.currentVersion,delete G.latestVersion,delete G.trackedForUpdates,G});return Wp(K,L.updates)},[r.skills,L.updates]),M=l.useMemo(()=>{const K={source:0,installed:0};for(const X of $)X.updateAvailable&&(K[X.origin]+=1);return K},[$]),F=l.useMemo(()=>({...r,skills:$}),[r,$]),W=L.updateCount,le=L.refresh,U=L.isRefreshing,H=l.useCallback((K,X)=>{le(),d(),ze(`versions/${K}/${X}`),L.dismiss(`${K}/${X}`)},[le,d,L]),ee=l.useMemo(()=>({state:F,selectSkill:u,clearSelection:m,setMode:g,setSearch:x,setMobileView:v,refreshSkills:d,updateCount:W,dismissUpdateNotification:b,updates:L.updates,outdatedByOrigin:M,isRefreshingUpdates:U,refreshUpdates:le,revealSkill:f,clearReveal:h,updatesById:L.updatesById,pushUpdateCount:L.pushUpdateCount,updateStreamStatus:L.status,dismissPushUpdate:L.dismiss,activeAgent:o,onSkillUpdated:H,trackedSkillCount:B}),[F,u,m,g,x,v,d,W,b,L.updates,M,U,le,f,h,L.updatesById,L.pushUpdateCount,L.status,L.dismiss,o,H,B]);return t.jsx($l.Provider,{value:ee,children:e})}const jf={config:null,loading:!0};function wf(e,r){switch(r.type){case"SET_CONFIG":return{config:r.config,loading:!1};case"SET_LOADING":return{...e,loading:!0};default:return e}}const Ml=l.createContext(null);function hr(){const e=l.useContext(Ml);if(!e)throw new Error("useConfig must be used within ConfigProvider");return e}function Sf({children:e}){const[r,n]=l.useReducer(wf,jf),s=l.useCallback(()=>{ie.getConfig().then(i=>n({type:"SET_CONFIG",config:i})).catch(()=>{})},[]);l.useEffect(()=>{s()},[s]);const o=l.useCallback(async(i,c)=>{const d=await ie.setConfig(i,c);return n({type:"SET_CONFIG",config:d}),d},[]),a=l.useMemo(()=>({config:r.config,loading:r.loading,updateConfig:o,refreshConfig:s}),[r,o,s]);return t.jsx(Ml.Provider,{value:a,children:e})}function Cf({topRail:e,sidebar:r,main:n,statusBar:s,resizeHandle:o,banner:a,liveMessage:i,sidebarWidth:c=320,sidebarHidden:d=!1}){const u={"--top-rail-height":"48px","--status-bar-height":"28px","--sidebar-width":`${c}px`,display:"grid",gridTemplateRows:"var(--top-rail-height) 1fr var(--status-bar-height)",height:"100vh",overflow:"hidden",background:"var(--bg-canvas)",color:"var(--text-primary)"},p={display:"grid",gridTemplateColumns:d?"1fr":"var(--sidebar-width) auto 1fr",minHeight:0,overflow:"hidden"};return t.jsxs("div",{className:"studio-shell",style:u,children:[a,t.jsx("header",{style:{borderBottom:"1px solid var(--border-default)",background:"var(--bg-canvas)",display:"flex",alignItems:"center",minHeight:0},children:e}),t.jsxs("div",{style:p,children:[!d&&t.jsx("aside",{"aria-label":"Skills sidebar",style:{minHeight:0,overflow:"hidden",borderRight:o?"none":"1px solid var(--border-default)",background:"var(--bg-canvas)",display:"flex",flexDirection:"column"},children:r}),!d&&o,t.jsx("main",{style:{minHeight:0,overflow:"auto",background:"var(--bg-canvas)"},children:n})]}),t.jsx("footer",{role:"contentinfo",style:{borderTop:"1px solid var(--border-default)",background:"var(--bg-canvas)",display:"flex",alignItems:"center",minHeight:0},children:s}),t.jsx("div",{"aria-live":"polite",role:"status",style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(50%)",whiteSpace:"nowrap",border:0},children:i??""})]})}const Ef={sectionOwn:"Own",sectionInstalled:"Installed",searchPlaceholder:"Search skills",searchShortcutHint:"Press / to search",emptyOwnHeadline:"No skills yet.",emptyOwnBody:"Run vskill new <name> to create one.",emptyInstalledHeadline:"No installed skills.",emptyInstalledBody:"Run vskill install <skill> to add one.",emptyFilteredHeadline:"No matches in this section.",emptyFilteredBody:"Clear the search or try another query.",loadErrorHeadline:"Couldn't load skills.",loadErrorRetry:"Retry",duplicateBadge:"synced from Own",updateAvailableBadge:"Update available",countBadgeFiltered:(e,r)=>`${e} of ${r}`},Nf={appTitle:"Skill Studio",commandPaletteButtonLabel:"Open command palette",commandPaletteHint:"⌘K",themeToggleLight:"Switch to light theme",themeToggleDark:"Switch to dark theme",themeToggleAuto:"Switch to auto theme",projectPathLabel:"Project",modelLabel:"Model",healthLabel:"Health"},Rf={tabOverview:"Overview",tabVersions:"Versions",tabBenchmark:"Benchmark",emptyHeadline:"Select a skill to see details.",emptyBody:"Pick one from the sidebar.",loadErrorHeadline:e=>`Couldn't load SKILL.md for ${e}.`,loadErrorBody:"Check the file path and your workspace permissions.",openInEditor:"Open in editor",copyPath:"Copy path",copyConfigSnippet:"Copy config snippet",depNotInstalledTooltip:"Not installed",missingValue:"—",announceViewingOwn:e=>`Viewing ${e} (Own)`,announceViewingInstalled:e=>`Viewing ${e} (Installed)`,moreFields:"More fields",sourceAgent:"Source agent",noMcpDependencies:"No MCP dependencies.",filesystemGroup:"Filesystem",benchmarkGroup:"Benchmark",metadataGroup:"Frontmatter"},Tf={open:"Open",copyPath:"Copy Path",revealInEditor:"Reveal in Editor",edit:"Edit",duplicate:"Duplicate",cloneToAuthoring:"Clone to authoring…",runBenchmark:"Run Benchmark",update:"Update",uninstall:"Uninstall",retry:"Retry",delete:"Delete",deletePluginTooltip:"Plugin skills are managed by their owning plugin — uninstall the plugin to remove.",undo:"Undo"},If={inputPlaceholder:"Type a command or search",emptyResults:"No matches. Try a different query.",groupNavigation:"Navigation",groupActions:"Actions",groupTheme:"Theme",actionSelectSkill:"Select skill",actionRunBenchmark:"Run benchmark",actionSwitchTheme:"Switch theme",actionNewSkill:"New skill",closeLabel:"Close palette"},Lf={title:"Keyboard shortcuts",closeLabel:"Close shortcuts",groupNavigation:"Navigation",groupActions:"Actions",groupTheme:"Theme",search:"Focus search",moveDown:"Move selection down",moveUp:"Move selection up",openSelected:"Open selected skill",openPalette:"Open command palette",openShortcuts:"Open this cheatsheet",toggleSidebar:"Toggle sidebar",toggleTheme:"Toggle theme"},Af={pathCopied:"Path copied.",configCopied:"Config copied.",skillDuplicated:"Skill duplicated.",cloneStarted:"Cloning to authoring…",cloneSucceeded:"Cloned to authoring.",cloneFailed:"Clone failed. Check eval-server logs.",benchmarkQueued:"Benchmark queued.",themeUpdated:"Theme updated.",skillUpdated:"Skill updated.",openingInEditor:"Opening in editor…",noEditor:"No editor found. Set $VISUAL or $EDITOR, or install code/cursor.",openFailed:"Could not open in editor.",skillNotFound:"Skill not found on disk.",uninstallNotImplemented:"Uninstall is not yet available from this menu.",actionFailed:"Action failed. Retry or check logs.",networkError:"Network error. Check your connection.",permissionDenied:"Permission denied. Check file access.",unknownError:"Something went wrong. Retry or check logs."},Pf={disconnected:"Disconnected — reconnecting…",reconnected:"Reconnected.",loading:"Loading skills…",loadingPlaceholderCount:"—"},$f={fieldRequired:"This field is required.",nameInvalid:"Use letters, numbers, and hyphens.",descriptionRequired:"Description is required.",saveFailed:"Save failed. Check the form for errors."},Mf={boundaryHeadline:"Something broke in this view.",boundaryBody:"Reload the page to recover.",boundaryAction:"Reload"},Df={triggerLabel:"Agent and model",popoverTitle:"Select agent and model",footerHint:"↑↓ navigate · Enter select · Esc close",settingsButton:"Settings",keyboardShortcut:"⌘K",noModelsYet:"No models yet.",searchPlaceholder:"Search 300+ models…",noMatches:e=>`No models match "${e}"`,clearSearch:"Clear",currentlyActive:"Currently active"},Ff={claudeCli:{name:"Claude Code",caption:"Delegates to the `claude` CLI — your existing Claude Code session handles quota.",missingBinary:"Claude Code not found. Install it: `npm install -g @anthropic-ai/claude-code`. Or choose a provider with an API key.",installCta:"Install Claude Code →",installUrl:"https://docs.claude.com/en/docs/claude-code"},anthropic:{name:"Anthropic API",caption:"Direct access via your Anthropic API key.",addKeyCta:"Add API key →",keyIssuanceUrl:"https://platform.claude.com/settings/keys",keyPrefix:"sk-ant-"},openai:{name:"OpenAI",caption:"GPT-4, GPT-5, and the o-series reasoning models.",addKeyCta:"Add API key →",keyIssuanceUrl:"https://platform.openai.com/api-keys",keyPrefix:"sk-",pastePlaceholder:"Paste OpenAI API key (sk-proj-...)"},openrouter:{name:"OpenRouter",caption:"300+ models from every major vendor.",addKeyCta:"Add API key →",emptyCardBody:"Add your OpenRouter API key to browse 300+ models",keyIssuanceUrl:"https://openrouter.ai/settings/keys",keyPrefix:"sk-or-"},cursor:{name:"Cursor",caption:"Cursor IDE composer.",installCta:"Install Cursor →"},codexCli:{name:"Codex CLI",caption:"OpenAI Codex CLI.",installCta:"Install Codex CLI →"},geminiCli:{name:"Gemini CLI",caption:"Google Gemini CLI.",installCta:"Install Gemini CLI →"},copilot:{name:"GitHub Copilot",caption:"GitHub Copilot CLI.",installCta:"Install Copilot →"},zed:{name:"Zed",caption:"Zed editor.",installCta:"Install Zed →"},ollama:{name:"Ollama",caption:"Local models, free.",startServiceCta:"Start service →"},lmStudio:{name:"LM Studio",caption:"Local models, free.",startServiceCta:"Start LM Studio server →",startServiceTooltip:"Open LM Studio → Developer tab → Start Server (default port 1234)."}},zf={subscriptionBilling:"· subscription",free:"· free"},Bf={title:"Settings",sectionApiKeys:"API Keys",banner:"Keys are stored locally on this device only. Never synced, never committed to git, never transmitted off-device except to the provider's own API.",storagePath:e=>`Keys stored at ${e} · protected by file permissions (0600 on macOS/Linux)`,storagePathFallback:"Keys stored locally on this device.",copyPath:"Copy path",pathCopied:"Path copied.",show:"Show",hide:"Hide",paste:"Paste",save:"Save",remove:"Remove",removeConfirm:e=>`Remove ${e} API key?`,keyStoredAt:e=>`Key stored locally — updated ${e}`,noKey:"No key stored",enterNonEmpty:"Enter a non-empty key",prefixWarn:e=>`This doesn't look like a typical ${e} key. Save anyway?`,keySaved:e=>`${e} API key saved (local only, never synced)`,keyRemoved:e=>`${e} API key removed`},_f={providersLabel:"Providers",providerSummary:(e,r)=>`${e}/${r} providers`,locked:e=>`${e} — locked. Click to add a key.`,lockedCli:e=>`${e} — locked. Click for install instructions.`,unlocked:e=>`${e} — unlocked.`},Of={triggerAriaLabel:"Choose active agent for the sidebar",popoverTitle:"Choose active agent",statsInstalled:"Installed",statsGlobal:"Global",statsPlugins:"Plugins",statsLastSync:"Last sync",statsHealthOk:"Fresh",statsHealthStale:"Updates available",statsHealthMissing:"Not detected",switchCta:"Switch for this studio session",notDetectedSubheading:"Not detected",setUpCta:e=>`Set up ${e}`,sharedFolderBanner:e=>`Shared folder — consumed by ${e}`},Wf={ownLabel:"Own",installedLabel:"Installed",globalLabel:"Global",emptyOwn:"No authored skills — run vskill new.",emptyInstalled:e=>`No skills installed for ${e} in this project — run vskill install.`,emptyGlobal:e=>`No global skills for ${e} — run vskill install --global.`},Hf={compactLabel:"Uses your Claude Code session · overflow billed at API rates",tooltip:"vSkill delegates to the `claude` CLI — your existing Claude Code session handles quota. If you've enabled extra usage in your account settings, excess runs at standard API rates. Run /usage in Claude Code or visit claude.com Settings → Usage to see remaining quota — vskill can't display it directly.",firstUseBanner:"Claude Code uses your existing session. No API key needed — vskill just runs the official claude binary on your behalf.",learnMore:"Learn more"},Uf={title:e=>`Set up ${e}`,close:"Close",copy:"Copy",copied:"Copied",requiredEnv:"Required env vars",getKey:"Get a key",installRun:"Install & run",learnMore:"Learn more",fallbackTitle:"No setup guide available",fallbackBody:"We don't ship a setup guide for this provider yet."},Vf={groupAvailable:"Available",groupAuthoring:"Authoring",sourceProject:"Project",sourcePersonal:"Personal",sourcePlugin:"Plugins",authoringSkills:"Skills"},Gf={anthropic:{name:"Anthropic API",description:"Direct API access to Claude via your Anthropic API key. Pay-per-token billing.",envVars:["ANTHROPIC_API_KEY"],keyUrl:"https://platform.claude.com/settings/keys",learnMoreUrl:"https://docs.claude.com/en/docs/get-started"},openai:{name:"OpenAI",description:"Access to GPT-4, GPT-5 and the o-series reasoning models via your OpenAI API key.",envVars:["OPENAI_API_KEY"],keyUrl:"https://platform.openai.com/api-keys",learnMoreUrl:"https://platform.openai.com/docs"},openrouter:{name:"OpenRouter",description:"One API key, 300+ models from Anthropic, OpenAI, Google, Meta, and more.",envVars:["OPENROUTER_API_KEY"],keyUrl:"https://openrouter.ai/keys",learnMoreUrl:"https://openrouter.ai/docs"},gemini:{name:"Gemini",description:"Google Gemini models (2.5 Pro, Flash) via Google AI Studio. Free tier available.",envVars:["GEMINI_API_KEY"],keyUrl:"https://aistudio.google.com/apikey",learnMoreUrl:"https://ai.google.dev/gemini-api/docs"},ollama:{name:"Ollama",description:"Local models on your own machine. Zero external calls, zero cost after download.",envVars:["OLLAMA_HOST"],installCmd:"curl -fsSL https://ollama.com/install.sh | sh",startCmd:"ollama serve",pullExample:"ollama pull llama3.2",learnMoreUrl:"https://ollama.com/download"},lmStudio:{name:"LM Studio",description:"Desktop app + local server for running open models with a GUI. Compatible with the OpenAI API.",envVars:["LM_STUDIO_BASE_URL"],installCmd:"Download from https://lmstudio.ai and launch the app, then start the local server.",startCmd:"# In LM Studio: Developer → Start Server (default port 1234)",pullExample:"# In LM Studio: Discover → download any GGUF model",learnMoreUrl:"https://lmstudio.ai/docs"},claudeCode:{name:"Claude Code",description:"No API key needed if you're logged into Claude Code. vskill just runs the official claude binary on your behalf — your existing Claude Code session handles quota.",loginHint:"If you're not logged in, run claude in your terminal and authenticate with your Anthropic account.",learnMoreUrl:"https://docs.claude.com/en/docs/claude-code"}},_={sidebar:Ef,shell:Nf,detail:Rf,actions:Tf,palette:If,shortcuts:Lf,toasts:Af,connection:Pf,forms:$f,errors:Mf,picker:Df,providers:Ff,models:zf,settings:Bf,statusBar:_f,scopePicker:Of,scopeSection:Wf,claudeCodeLabel:Hf,setupDrawer:Uf,setupProviders:Gf,scopeLabels:Vf},Ia=["claude-cli","anthropic","openai","openrouter","cursor","codex-cli","gemini-cli","copilot","zed","ollama","lm-studio"],Kf={"claude-cli":".claude",cursor:".cursor","codex-cli":".codex","gemini-cli":".gemini",copilot:".github",zed:".zed"},qf={"claude-cli":"claude",cursor:"cursor","codex-cli":"codex","gemini-cli":"gemini"},Yf={"claude-cli":"cli-install",anthropic:"api-key",openai:"api-key",openrouter:"api-key",cursor:"cli-install","codex-cli":"cli-install","gemini-cli":"cli-install",copilot:"cli-install",zed:"cli-install",ollama:"start-service","lm-studio":"start-service"},Jf={"claude-cli":"subscription",anthropic:"per-token",openai:"per-token",openrouter:"per-token",cursor:"subscription","codex-cli":"subscription","gemini-cli":"subscription",copilot:"subscription",zed:"subscription",ollama:"free","lm-studio":"free"};function Xf(e,r){var c,d;const n=Kf[e.id]??null,s=qf[e.id]??null,o=n?!!((c=r==null?void 0:r.wrapperFolders)!=null&&c[n]):!1,a=s?!!((d=r==null?void 0:r.binaries)!=null&&d[s]):!0,i=e.models.map(u=>({id:u.id,displayName:u.label,billingMode:Jf[e.id]??"per-token",...u.pricing?{pricing:u.pricing}:{},...u.resolvedId?{resolvedId:u.resolvedId}:{}}));return{id:e.id,displayName:Qf(e.id,e.label),wrapperFolder:n,wrapperFolderPresent:o,binaryAvailable:a,endpointReachable:e.id==="ollama"||e.id==="lm-studio"?e.available:null,available:e.available,ctaType:e.available?null:Yf[e.id]??null,models:i,resolvedModel:e.resolvedModel??null}}function Qf(e,r){return{"claude-cli":"Claude Code",anthropic:"Anthropic API",openai:"OpenAI API",openrouter:"OpenRouter",cursor:"Cursor","codex-cli":"Codex CLI","gemini-cli":"Gemini CLI",copilot:"GitHub Copilot",zed:"Zed",ollama:"Ollama","lm-studio":"LM Studio"}[e]??r}function Zf(e){const r=new Map(e.map(s=>[s.id,s])),n=[];for(const s of Ia){const o=r.get(s);o&&n.push(o)}for(const s of e)Ia.includes(s.id)||n.push(s);return n}function eh(e){const[r,n]=l.useState(null),[s,o]=l.useState("loading"),[a,i]=l.useState(null),[c,d]=l.useState(null),u=l.useRef(null),p=l.useRef(0),f=l.useRef(e==null?void 0:e.onStaleCatalog),h=l.useRef(e==null?void 0:e.onSetActiveError);l.useEffect(()=>{f.current=e==null?void 0:e.onStaleCatalog,h.current=e==null?void 0:e.onSetActiveError},[e==null?void 0:e.onStaleCatalog,e==null?void 0:e.onSetActiveError]);const m=l.useCallback(async()=>{try{const y=await fetch("/api/config");if(!y.ok)throw new Error(`/api/config returned ${y.status}`);const j=await y.json(),S=Zf((j.providers||[]).map(w=>Xf(w,j.detection)));n({agents:S,activeAgent:j.provider??null,activeModel:j.model??null}),o("ready"),i(null)}catch(y){o("error"),i(y.message)}},[]);l.useEffect(()=>{m()},[m]);const g=l.useCallback(async()=>{var j;const y=Date.now();if(!(y-p.current<5*6e4))try{const S=await fetch("/api/openrouter/models");if(!S.ok){S.status!==400&&d(`OpenRouter catalog fetch failed (${S.status})`);return}const w=await S.json();p.current=y,d(null),n(E=>{if(!E)return E;const C=E.agents.map(N=>{if(N.id!=="openrouter")return N;const I=w.models.map(L=>({id:L.id,displayName:L.name,contextWindow:L.contextWindow,pricing:L.pricing,billingMode:"per-token"}));return{...N,models:I,catalogAgeMs:w.ageSec?w.ageSec*1e3:0,cacheStale:!!w.stale}});return{...E,agents:C}});const R=w.ageSec??0;(w.stale===!0||R>600)&&((j=f.current)==null||j.call(f,"openrouter",R*1e3))}catch(S){d(`OpenRouter catalog unreachable: ${S.message}`)}},[]),x=l.useCallback(y=>{u.current=y,y==="openrouter"&&g()},[g]),v=l.useCallback(()=>{p.current=0,m()},[m]),b=l.useCallback(async(y,j)=>{var R,k;let S;try{S=await fetch("/api/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:y,model:j})})}catch(E){(R=h.current)==null||R.call(h,`Network error while setting ${y}: ${E.message}`);return}if(S.ok){n(E=>E&&{...E,activeAgent:y,activeModel:j});return}let w=`Failed to set ${y} (${S.status})`;try{const E=await S.json();E&&typeof E.error=="string"&&(w=E.error)}catch{}(k=h.current)==null||k.call(h,w)},[]);return{status:s,catalog:r,error:a,openRouterError:c,focusAgent:x,refresh:v,activeAgentId:(r==null?void 0:r.activeAgent)??null,activeModelId:(r==null?void 0:r.activeModel)??null,setActive:b}}function bs({variant:e,label:r,onActivate:n,installUrl:s,tooltip:o}){function a(c){if(c.stopPropagation(),e==="cli-install"&&s){window.open(s,"_blank","noopener,noreferrer");return}n()}function i(c){(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),a(c))}return t.jsx("button",{type:"button","data-testid":`locked-cta-${e}`,onClick:a,onKeyDown:i,className:"inline-flex items-center gap-1.5 px-0 py-0 text-[11px] font-medium",style:{color:"var(--accent, var(--text-primary))",background:"transparent",border:"none",cursor:"pointer"},"aria-label":r,...o?{title:o}:{},children:r})}function mo({unlocked:e=!1,size:r=10}){return e?t.jsxs("svg",{width:r,height:r,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),t.jsx("path",{d:"M5 7V4.5A3 3 0 0 1 11 3.5"})]}):t.jsxs("svg",{width:r,height:r,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("rect",{x:"3",y:"7",width:"10",height:"7",rx:"1"}),t.jsx("path",{d:"M5 7V4.5A3 3 0 0 1 11 4.5V7"})]})}const th=new Set(["claude-cli","claude-code"]);function La(e){return th.has(e)}const Aa=new Set(["claude-cli","claude-code","anthropic","openai","openrouter","cursor","codex-cli","gemini-cli","copilot","zed"]);function rh({agents:e,activeAgentId:r,focusedAgentId:n,onFocus:s,onSelect:o,onOpenSettings:a}){const i=e.filter(d=>Aa.has(d.id)),c=e.filter(d=>!Aa.has(d.id));return t.jsxs("div",{role:"listbox","aria-label":"Agent","data-testid":"agent-list",style:{width:240,borderRight:"1px solid var(--border-default, var(--border-subtle))",display:"flex",flexDirection:"column",overflowY:"auto"},children:[i.map(d=>t.jsx(Pa,{agent:d,isActive:d.id===r,isFocused:d.id===n,onFocus:s,onSelect:o,onOpenSettings:a},d.id)),c.length>0&&t.jsx("div",{style:{borderTop:"1px solid var(--border-default, var(--border-subtle))",margin:"4px 0"},"aria-hidden":"true"}),c.map(d=>t.jsx(Pa,{agent:d,isActive:d.id===r,isFocused:d.id===n,onFocus:s,onSelect:o,onOpenSettings:a},d.id))]})}function Pa({agent:e,isActive:r,isFocused:n,onFocus:s,onSelect:o,onOpenSettings:a}){const{providers:i}=_,c={"claude-cli":i.claudeCli.caption,anthropic:i.anthropic.caption,openrouter:i.openrouter.caption},d={"claude-cli":{label:i.claudeCli.installCta,url:i.claudeCli.installUrl},cursor:{label:i.cursor.installCta},"codex-cli":{label:i.codexCli.installCta},"gemini-cli":{label:i.geminiCli.installCta},copilot:{label:i.copilot.installCta},zed:{label:i.zed.installCta}},u=La(e.id),p={minHeight:36,height:u?"auto":36,padding:u?"6px 12px":"0 12px",display:"flex",alignItems:"center",gap:8,cursor:"pointer",position:"relative",background:n?"var(--surface-muted, var(--surface-3))":"transparent",borderLeft:r?"1px solid var(--accent, var(--color-accent))":"1px solid transparent",fontFamily:"'Inter Tight Variable', 'Inter Tight', system-ui, sans-serif",fontSize:13,fontWeight:r?500:400,color:"var(--text-primary)"};return r&&(p.background="color-mix(in srgb, var(--accent, var(--color-accent)) 10%, transparent)"),t.jsxs("div",{role:"option","aria-selected":r,"data-testid":`agent-row-${e.id}`,"data-focused":n||void 0,tabIndex:n?0:-1,onMouseEnter:()=>s(e.id),onFocus:()=>s(e.id),onClick:()=>o(e.id),style:p,children:[e.wrapperFolder&&t.jsx("span",{"data-testid":`wrapper-dot-${e.id}`,"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",flexShrink:0,background:e.wrapperFolderPresent?"var(--accent, var(--color-accent))":"transparent",border:e.wrapperFolderPresent?"none":"1px solid var(--border-default, var(--border-subtle))"}}),!e.wrapperFolder&&t.jsx("span",{style:{width:6,height:6,flexShrink:0},"aria-hidden":"true"}),t.jsxs("span",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",overflow:"hidden"},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.displayName}),La(e.id)&&t.jsx("span",{"data-testid":"claude-code-billing-label",title:_.claudeCodeLabel.tooltip,style:{fontSize:10,color:"var(--text-secondary, var(--text-tertiary))",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",marginTop:1},children:_.claudeCodeLabel.compactLabel})]}),t.jsx("span",{"aria-label":e.available?"available":"locked",style:{color:e.available?"var(--accent, var(--color-accent))":"var(--text-muted, var(--text-tertiary))",flexShrink:0},children:e.available?t.jsx(mo,{unlocked:!0,size:10}):t.jsx(mo,{size:10})}),r&&t.jsx("span",{style:{fontSize:10,textTransform:"uppercase",letterSpacing:"0.05em",fontWeight:600,color:"var(--accent-ink, var(--accent))",flexShrink:0},"data-testid":`active-badge-${e.id}`,children:_.picker.currentlyActive}),!e.available&&e.ctaType==="api-key"&&t.jsx(bs,{variant:"api-key",label:e.id==="anthropic"?i.anthropic.addKeyCta:i.openrouter.addKeyCta,onActivate:()=>a(e.id)}),!e.available&&e.ctaType==="cli-install"&&d[e.id]&&t.jsx(bs,{variant:"cli-install",label:d[e.id].label,installUrl:d[e.id].url,onActivate:()=>{}}),!e.available&&e.ctaType==="start-service"&&t.jsx(bs,{variant:"start-service",label:e.id==="ollama"?i.ollama.startServiceCta:i.lmStudio.startServiceCta,onActivate:()=>a(e.id)}),c[e.id]&&t.jsx("span",{className:"sr-only","data-testid":`caption-${e.id}`,children:c[e.id]})]})}function nh(e,r,n,s){const i=e>=80,c=l.useRef(null),[d,u]=l.useState(0),p=l.useCallback(m=>{u(m.currentTarget.scrollTop)},[]),{visibleStart:f,visibleEnd:h}=l.useMemo(()=>{if(!i)return{visibleStart:0,visibleEnd:e};const m=Math.max(0,Math.floor(d/r)-4),g=Math.ceil(n/r)+8,x=Math.min(e,m+g);return{visibleStart:m,visibleEnd:x}},[i,d,r,n,e,4]);return{visibleStart:f,visibleEnd:h,totalHeight:e*r,offsetTop:f*r,virtualised:i,containerProps:{onScroll:p,ref:c,style:{overflowY:"auto",maxHeight:n,willChange:i?"transform":void 0}}}}const Dl=44,sh=352,oh=60,$a=480;function ah(e){var a,i;const r=e.contextWindow?e.contextWindow>=1e6?`${Math.round(e.contextWindow/1e6)}M`:e.contextWindow>=1e3?`${Math.round(e.contextWindow/1e3)}k`:String(e.contextWindow):null;if(e.billingMode==="subscription")return r?`${r} ctx ${_.models.subscriptionBilling}`:_.models.subscriptionBilling.trim();if(e.billingMode==="free")return r?`local · ${r} ctx · free`:"local · free";const n=((a=e.pricing)==null?void 0:a.prompt)??0,s=((i=e.pricing)==null?void 0:i.completion)??0,o=`$${n.toFixed(2)} / $${s.toFixed(2)} per 1M tokens`;return r?`${r} ctx · ${o}`:o}function ih(e,r){if(!r)return e;const n=r.toLowerCase();return e.filter(o=>o.displayName.toLowerCase().includes(n)).sort((o,a)=>{const i=o.displayName.toLowerCase().indexOf(n),c=a.displayName.toLowerCase().indexOf(n);return i!==c?i-c:o.displayName.length-a.displayName.length})}function lh({agent:e,activeModelId:r,focusedIndex:n=-1,onSelect:s,onOpenSettings:o}){const[a,i]=l.useState(""),[c,d]=l.useState(""),u=l.useRef(null);if(l.useEffect(()=>{const h=setTimeout(()=>d(a),oh);return()=>clearTimeout(h)},[a]),l.useEffect(()=>{e.id==="openrouter"&&e.available&&u.current&&u.current.focus()},[e.id,e.available]),e.id==="openrouter"&&!e.available)return t.jsxs("div",{"data-testid":"openrouter-empty-card",style:{width:$a,padding:20,display:"flex",flexDirection:"column",gap:12},children:[t.jsx("p",{style:{margin:0,color:"var(--text-primary)",fontSize:13,lineHeight:1.5},children:_.providers.openrouter.emptyCardBody}),t.jsx("button",{type:"button",onClick:()=>o("openrouter"),style:{alignSelf:"flex-start",padding:"6px 10px",borderRadius:6,background:"var(--accent, var(--color-accent))",color:"var(--bg-surface, white)",border:"none",fontSize:12,fontWeight:500,cursor:"pointer"},children:_.providers.openrouter.addKeyCta})]});const p=l.useMemo(()=>ih(e.models,c),[e.models,c]),f=nh(p.length,Dl,sh);return t.jsxs("div",{role:"listbox","aria-label":"Model","data-testid":"model-list",style:{width:$a,display:"flex",flexDirection:"column"},children:[e.id==="openrouter"&&t.jsx("div",{style:{padding:8,borderBottom:"1px solid var(--border-default, var(--border-subtle))"},children:t.jsx("input",{ref:u,type:"text",placeholder:_.picker.searchPlaceholder,value:a,onChange:h=>i(h.target.value),"data-testid":"model-search-input","aria-label":_.picker.searchPlaceholder,style:{width:"100%",padding:"6px 8px",background:"var(--surface-2, var(--bg-surface))",border:"1px solid var(--border-subtle)",borderRadius:4,color:"var(--text-primary)",fontSize:12,fontFamily:"'Inter Tight Variable', 'Inter Tight', system-ui, sans-serif"}})}),p.length===0&&c?t.jsxs("div",{style:{padding:16},"data-testid":"no-matches",children:[t.jsx("div",{style:{color:"var(--text-muted, var(--text-tertiary))",fontSize:12,marginBottom:8},children:_.picker.noMatches(c)}),t.jsx("button",{type:"button",onClick:()=>i(""),style:{padding:"4px 8px",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:4,color:"var(--text-primary)",fontSize:12,cursor:"pointer"},children:_.picker.clearSearch})]}):p.length===0?t.jsx("div",{style:{padding:16,color:"var(--text-muted, var(--text-tertiary))",fontSize:12},children:_.picker.noModelsYet}):t.jsx("div",{...f.containerProps,children:t.jsx("div",{style:{height:f.virtualised?f.totalHeight:"auto",position:"relative"},children:t.jsx("div",{style:{transform:f.virtualised?`translateY(${f.offsetTop}px)`:void 0},children:p.slice(f.visibleStart,f.visibleEnd).map((h,m)=>{const g=f.visibleStart+m;return t.jsx(dh,{model:h,isActive:h.id===r,isFocused:n===g,onSelect:()=>s(h.id),resolvedModel:e.id==="claude-cli"?e.resolvedModel??null:null},h.id)})})})})]})}function ch(e,r,n){return r&&r.toLowerCase().includes(e.toLowerCase())?r:n??null}function dh({model:e,isActive:r,isFocused:n,onSelect:s,resolvedModel:o}){const a=ah(e),i=ch(e.id,o,e.resolvedId),c=i!==null,d=r?"color-mix(in srgb, var(--accent, var(--color-accent)) 10%, transparent)":n?"var(--surface-muted, var(--surface-3))":"transparent",u=r?"1px solid var(--accent, var(--color-accent))":"1px solid transparent";return t.jsxs("button",{type:"button",role:"option","aria-selected":r,"data-testid":`model-row-${e.id}`,"data-focused":n||void 0,onClick:s,title:e.id,style:{width:"100%",minHeight:Dl,padding:"4px 12px",display:"flex",flexDirection:"column",alignItems:"flex-start",justifyContent:"center",gap:2,background:d,borderLeft:u,cursor:"pointer",fontFamily:"'Inter Tight Variable', 'Inter Tight', system-ui, sans-serif",textAlign:"left"},children:[t.jsx("span",{style:{fontSize:14,fontWeight:500,color:"var(--text-primary)"},children:e.displayName}),t.jsx("span",{style:{fontSize:12,fontFamily:"'JetBrains Mono Variable', 'JetBrains Mono', monospace",fontVariantNumeric:"tabular-nums",color:"var(--text-muted, var(--text-tertiary))"},children:a}),c&&t.jsxs("span",{"data-testid":`model-row-${e.id}-resolved`,style:{fontSize:11,fontFamily:"'JetBrains Mono Variable', 'JetBrains Mono', monospace",color:"var(--text-muted, var(--text-tertiary))"},children:["routing to ",i]})]})}const Ma={anthropic:{stored:!1,updatedAt:null},openai:{stored:!1,updatedAt:null},openrouter:{stored:!1,updatedAt:null}};function uh(){const[e,r]=l.useState(null),[n,s]=l.useState(!0),[o,a]=l.useState(null),i=l.useCallback(async()=>{s(!0);try{const u=await fetch("/api/settings/keys");if(!u.ok)throw new Error(`GET /api/settings/keys returned ${u.status}`);const p=await u.json();r({...Ma,...p}),a(null)}catch(u){a(u.message),r(Ma)}finally{s(!1)}},[]);l.useEffect(()=>{i()},[i]);const c=l.useCallback(async(u,p)=>{const f=await fetch("/api/settings/keys",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:u,key:p})});if(!f.ok){const m=await f.json().catch(()=>({error:f.statusText}));throw new Error(m.error||`POST /api/settings/keys returned ${f.status}`)}const h=await f.json();return await i(),h},[i]),d=l.useCallback(async u=>{const p=await fetch(`/api/settings/keys/${u}`,{method:"DELETE"});if(!p.ok)throw new Error(`DELETE /api/settings/keys/${u} returned ${p.status}`);await i()},[i]);return{state:e,loading:n,error:o,save:c,remove:d,refresh:i}}function ph({onMigrated:e,fetchImpl:r}){const[n,s]=l.useState({kind:"loading"}),o=r??globalThis.fetch,a=l.useCallback(async()=>{var u;try{const p=await o("/api/settings/migration-status");if(!p.ok){s({kind:"hidden"});return}const f=await p.json();f.pending&&(((u=f.darwinKeys)==null?void 0:u.length)??0)>0?s({kind:"visible",darwinKeys:f.darwinKeys??[]}):s({kind:"hidden"})}catch{s({kind:"hidden"})}},[o]);l.useEffect(()=>{a()},[a]);const i=l.useCallback(async()=>{s({kind:"working"});try{const u=await o("/api/settings/migration-perform",{method:"POST",headers:{"Content-Type":"application/json"}});if(!u.ok){s({kind:"error",message:`Migration failed (${u.status})`});return}const p=await u.json().catch(()=>({migrated:[]}));e==null||e(p.migrated??[]),await a()}catch(u){s({kind:"error",message:u.message})}},[o,a,e]),c=l.useCallback(async()=>{s({kind:"hidden"});try{await o("/api/settings/migration-acknowledge",{method:"POST",headers:{"Content-Type":"application/json"}})}catch{}},[o]);if(n.kind==="loading"||n.kind==="hidden")return null;if(n.kind==="error")return t.jsxs("div",{role:"status","data-testid":"migration-banner",style:{padding:"10px 12px",borderRadius:6,background:"color-mix(in srgb, var(--danger, #b33) 15%, transparent)",color:"var(--text-primary)",fontSize:12,marginBottom:12,display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{style:{flex:1},children:n.message}),t.jsx("button",{type:"button",onClick:()=>void a(),"data-testid":"migration-retry",style:ks,children:"Retry"})]});const d=n.kind==="working";return t.jsxs("div",{role:"note","data-testid":"migration-banner",style:{padding:"10px 12px",borderRadius:6,background:"color-mix(in srgb, var(--accent, var(--color-accent)) 12%, transparent)",color:"var(--text-primary)",fontSize:12,marginBottom:12,display:"flex",alignItems:"center",gap:8},children:[t.jsxs("div",{style:{flex:1},children:[t.jsx("strong",{style:{display:"block",marginBottom:2},children:"Migrate from macOS Keychain"}),t.jsx("span",{style:{color:"var(--text-muted, var(--text-tertiary))"},children:"We found stored credentials from a previous vskill version. Import them into the new on-disk store."})]}),t.jsx("button",{type:"button",onClick:()=>void i(),disabled:d,"data-testid":"migration-migrate",style:{...ks,background:"var(--accent, var(--color-accent))",color:"white",opacity:d?.6:1},children:d?"Importing…":"Migrate"}),t.jsx("button",{type:"button",onClick:()=>void c(),"data-testid":"migration-dismiss",style:{...ks,background:"transparent",border:"none",color:"var(--text-muted, var(--text-tertiary))",textDecoration:"underline",padding:"4px 6px"},children:"Dismiss for 30 days"})]})}const ks={padding:"4px 10px",background:"var(--surface-2, transparent)",border:"1px solid var(--border-subtle)",borderRadius:4,color:"var(--text-primary)",fontSize:12,cursor:"pointer"},fh=[{id:"anthropic",name:_.providers.anthropic.name,keyIssuanceUrl:_.providers.anthropic.keyIssuanceUrl,prefix:_.providers.anthropic.keyPrefix,placeholder:`Paste ${_.providers.anthropic.name} key`},{id:"openai",name:_.providers.openai.name,keyIssuanceUrl:_.providers.openai.keyIssuanceUrl,prefix:_.providers.openai.keyPrefix,placeholder:_.providers.openai.pastePlaceholder},{id:"openrouter",name:_.providers.openrouter.name,keyIssuanceUrl:_.providers.openrouter.keyIssuanceUrl,prefix:_.providers.openrouter.keyPrefix,placeholder:`Paste ${_.providers.openrouter.name} key`}];function hh(e){const r=Date.now()-new Date(e).getTime();return r<6e4?"just now":r<36e5?`${Math.round(r/6e4)}m ago`:r<864e5?`${Math.round(r/36e5)}h ago`:new Date(e).toLocaleString()}function Fl({open:e,onClose:r,initialProvider:n,onToast:s}){const{state:o,save:a,remove:i,refresh:c}=uh(),d=l.useRef(null),u=l.useRef(null),[p,f]=l.useState(null);l.useEffect(()=>{if(!e)return;let m=!1;return(async()=>{try{const g=await fetch("/api/settings/storage-path");if(!g.ok)throw new Error(`GET /api/settings/storage-path returned ${g.status}`);const x=await g.json();m||f(x.path??null)}catch{m||f(null)}})(),()=>{m=!0}},[e]),l.useEffect(()=>{if(!e)return;const m=document.activeElement,g=setTimeout(()=>{var b;const x=n?`input[data-provider="${n}"]`:"input[data-provider]",v=(b=d.current)==null?void 0:b.querySelector(x);v==null||v.focus()},0);return()=>{var x;clearTimeout(g),(x=m==null?void 0:m.focus)==null||x.call(m)}},[e,n]),l.useEffect(()=>{if(!e)return;const m=g=>{if(g.key==="Escape"){g.preventDefault(),g.stopPropagation(),r();return}if(g.key==="Tab"&&d.current){g.stopPropagation();const x=d.current.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])");if(x.length===0)return;const v=x[0],b=x[x.length-1];g.shiftKey&&document.activeElement===v?(g.preventDefault(),b.focus()):!g.shiftKey&&document.activeElement===b&&(g.preventDefault(),v.focus())}};return document.addEventListener("keydown",m,!0),()=>document.removeEventListener("keydown",m,!0)},[e,r]);const h=l.useCallback(async()=>{var m,g;if(p)try{await((g=(m=navigator.clipboard)==null?void 0:m.writeText)==null?void 0:g.call(m,p)),s==null||s(_.settings.pathCopied)}catch{}},[s,p]);return e?t.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"settings-modal-title","data-testid":"settings-modal",style:{position:"fixed",inset:0,background:"color-mix(in srgb, black 40%, transparent)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:10080},onClick:m=>{m.target===m.currentTarget&&r()},children:t.jsxs("div",{ref:d,style:{background:"var(--bg-surface, var(--surface-1))",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:8,width:560,maxHeight:"80vh",overflowY:"auto",padding:20,fontFamily:"'Inter Tight Variable', 'Inter Tight', system-ui, sans-serif",color:"var(--text-primary)"},onClick:m=>m.stopPropagation(),children:[t.jsx("h2",{id:"settings-modal-title",style:{margin:"0 0 16px 0",fontSize:16,fontWeight:600},children:_.settings.title}),t.jsx(ph,{onMigrated:()=>{c()}}),t.jsx("div",{role:"note","data-testid":"settings-banner",style:{padding:"8px 12px",borderRadius:6,background:"color-mix(in srgb, var(--info, var(--accent-muted)) 20%, transparent)",color:"var(--text-primary)",fontSize:12,marginBottom:16},children:_.settings.banner}),t.jsxs("section",{"aria-labelledby":"settings-api-keys-title",style:{marginBottom:20},children:[t.jsx("h3",{id:"settings-api-keys-title",style:{fontSize:13,fontWeight:600,margin:"0 0 12px 0"},children:_.settings.sectionApiKeys}),fh.map(m=>t.jsx(mh,{providerId:m.id,providerName:m.name,keyIssuanceUrl:m.keyIssuanceUrl,prefix:m.prefix,placeholder:m.placeholder,metadata:o==null?void 0:o[m.id],onSave:async g=>{const x=await a(m.id,g);return s==null||s(_.settings.keySaved(m.name)),x},onRemove:async()=>{await i(m.id),s==null||s(_.settings.keyRemoved(m.name))},inputRef:m.id===(n??"anthropic")?u:void 0},m.id))]}),t.jsxs("div",{"data-testid":"settings-storage-path",style:{fontSize:11,color:"var(--text-muted, var(--text-tertiary))",fontStyle:"italic",display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[t.jsx("span",{style:{flex:1},children:p?_.settings.storagePath(p):_.settings.storagePathFallback}),t.jsx("button",{type:"button",onClick:h,disabled:!p,"data-testid":"settings-copy-path",style:{...dr,opacity:p?1:.5,cursor:p?"pointer":"not-allowed"},children:_.settings.copyPath})]}),t.jsx("div",{style:{marginTop:20,display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{type:"button",onClick:r,style:{padding:"6px 12px",background:"var(--surface-2, transparent)",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:6,color:"var(--text-primary)",fontSize:12,cursor:"pointer"},children:"Close"})})]})}):null}function mh({providerId:e,providerName:r,keyIssuanceUrl:n,prefix:s,placeholder:o,metadata:a,onSave:i,onRemove:c,inputRef:d}){const[u,p]=l.useState(""),[f,h]=l.useState(!1),[m,g]=l.useState(!1),[x,v]=l.useState(!1),[b,y]=l.useState(null),j=u.trim(),S=j.length===0,w=j.length>0&&!j.startsWith(s),R=l.useCallback(async()=>{if(S)return;g(!0);const C=j;p("");try{const N=await i(C);N.warning?y(N.warning):y(null)}finally{g(!1)}},[S,i,j]),k=l.useCallback(async()=>{var C;try{if(!((C=navigator.clipboard)!=null&&C.readText))return;const N=await navigator.clipboard.readText();p(N)}catch{}},[]),E=l.useCallback(async()=>{v(!1),await c()},[c]);return t.jsxs("div",{"data-testid":`provider-row-${e}`,style:{padding:12,border:"1px solid var(--border-subtle)",borderRadius:6,marginBottom:8,display:"flex",flexDirection:"column",gap:8},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("strong",{style:{fontSize:13},children:r}),t.jsx("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:{fontSize:12,color:"var(--accent, var(--color-accent))"},children:"Get a key →"})]}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("input",{ref:d,type:f?"text":"password",value:u,onChange:C=>{p(C.target.value),y(null)},"data-provider":e,placeholder:o,style:{flex:1,padding:"6px 8px",border:"1px solid var(--border-subtle)",borderRadius:4,background:"var(--surface-2, var(--bg-surface))",color:"var(--text-primary)",fontSize:12,fontFamily:"'JetBrains Mono Variable', 'JetBrains Mono', monospace"}}),t.jsx("button",{type:"button",onClick:()=>h(!f),style:dr,children:f?_.settings.hide:_.settings.show}),t.jsx("button",{type:"button",onClick:k,style:dr,children:_.settings.paste})]}),w&&t.jsx("div",{role:"status","data-testid":`prefix-warn-${e}`,style:Da,children:_.settings.prefixWarn(r)}),b&&t.jsx("div",{role:"status",style:Da,children:b}),t.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[t.jsx("button",{type:"button",onClick:R,disabled:S||m,"data-testid":`save-${e}`,style:{...dr,background:S?"var(--surface-2)":"var(--accent, var(--color-accent))",color:S?"var(--text-muted)":"white",cursor:S?"not-allowed":"pointer"},children:_.settings.save}),(a==null?void 0:a.stored)&&t.jsx(t.Fragment,{children:x?t.jsxs(t.Fragment,{children:[t.jsx("span",{style:{fontSize:12},children:_.settings.removeConfirm(r)}),t.jsx("button",{type:"button",onClick:E,"data-testid":`remove-confirm-${e}`,style:{...dr,background:"var(--danger, #b33)",color:"white"},children:"Confirm"}),t.jsx("button",{type:"button",onClick:()=>v(!1),style:dr,children:"Cancel"})]}):t.jsx("button",{type:"button",onClick:()=>v(!0),"data-testid":`remove-${e}`,style:{...dr,color:"var(--text-muted)"},children:_.settings.remove})}),t.jsx("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-muted, var(--text-tertiary))"},"data-testid":`status-${e}`,children:a!=null&&a.stored&&a.updatedAt?_.settings.keyStoredAt(hh(a.updatedAt)):_.settings.noKey})]})]})}const dr={padding:"4px 8px",background:"var(--surface-2, transparent)",border:"1px solid var(--border-subtle)",borderRadius:4,color:"var(--text-primary)",fontSize:12,cursor:"pointer"},Da={fontSize:11,color:"var(--warning, var(--text-muted))"};function xh(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia("(prefers-reduced-motion: reduce)").matches}function gh({onToast:e}){const{status:r,catalog:n,focusAgent:s,setActive:o}=eh({onStaleCatalog:(N,I)=>{const P=Math.round(I/6e4);e==null||e(`Using cached ${N} catalog (${P} min old)`)},onSetActiveError:N=>e==null?void 0:e(N)}),[a,i]=l.useState(!1),[c,d]=l.useState(!1),[u,p]=l.useState(),[f,h]=l.useState(null),[m,g]=l.useState("agents"),[x,v]=l.useState(0),b=l.useRef(null);l.useRef(null),l.useEffect(()=>{var N;n&&!f&&h(n.activeAgent??((N=n.agents[0])==null?void 0:N.id)??null)},[n,f]);const y=(n==null?void 0:n.agents)??[],j=l.useMemo(()=>y.find(N=>N.id===f)??y[0],[y,f]);l.useEffect(()=>{v(0)},[f]);const S=l.useCallback(()=>{var N;i(!0),g("agents"),h((n==null?void 0:n.activeAgent)??((N=y[0])==null?void 0:N.id)??null),v(0)},[n,y]),w=l.useCallback(()=>{var N;i(!1),(N=b.current)==null||N.focus()},[]);l.useEffect(()=>{const N=()=>i(I=>!I);return window.addEventListener("openAgentModelPicker",N),()=>{window.removeEventListener("openAgentModelPicker",N)}},[]),l.useEffect(()=>{if(!a)return;const N=P=>{if(P.key==="Escape"){P.preventDefault(),w();return}if(P.key==="ArrowDown"){P.preventDefault(),I(1);return}if(P.key==="ArrowUp"){P.preventDefault(),I(-1);return}if(P.key==="ArrowRight"&&m==="agents"){P.preventDefault(),g("models"),v(L=>{const B=((j==null?void 0:j.models.length)??1)-1;return Math.max(0,Math.min(L,Math.max(0,B)))});return}if(P.key==="ArrowLeft"&&m==="models"){P.preventDefault(),g("agents");return}if(P.key==="Enter"){if(P.preventDefault(),m==="agents"&&j)g("models"),v(0);else if(m==="models"&&j){const L=Math.max(0,Math.min(j.models.length-1,x)),B=j.models[L];B&&(o(j.id,B.id),w())}return}};function I(P){if(m==="agents"){const L=y.findIndex(T=>T.id===f),B=y[Math.max(0,Math.min(y.length-1,L+P))];B&&(h(B.id),s(B.id));return}if(m==="models"&&j){const L=j.models.length;if(L===0)return;v(B=>{const T=B+P;return Math.max(0,Math.min(L-1,T))})}}return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[a,m,y,f,j,x,w,s,o]);const R=l.useCallback(N=>{p(N==="anthropic"||N==="openrouter"?N:void 0),d(!0),i(!1)},[]),k=y.find(N=>N.id===(n==null?void 0:n.activeAgent)),E=k==null?void 0:k.models.find(N=>N.id===(n==null?void 0:n.activeModel)),C=l.useMemo(()=>{if(r!=="ready"||!n)return"Loading…";const N=(k==null?void 0:k.displayName)??"Agent",I=(E==null?void 0:E.displayName)??n.activeModel??"Model";return`${N} · ${I}`},[r,n,k,E]);return t.jsxs(t.Fragment,{children:[t.jsxs("button",{ref:b,type:"button","data-testid":"agent-model-picker-trigger",onClick:()=>a?w():S(),"aria-haspopup":"listbox","aria-expanded":a,style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 10px",background:"var(--surface-2, var(--bg-surface))",border:"1px solid var(--border-subtle)",borderRadius:6,color:"var(--text-primary)",fontSize:12,cursor:"pointer",fontFamily:"'Inter Tight Variable', 'Inter Tight', system-ui, sans-serif"},children:[t.jsx("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:k!=null&&k.available?"var(--accent, var(--color-accent))":"var(--text-muted, var(--text-tertiary))",flexShrink:0}}),t.jsx("span",{children:C})]}),a&&typeof document<"u"&&$r.createPortal(t.jsxs(vh,{reducedMotion:xh(),onClickOutside:w,children:[t.jsxs("div",{style:{display:"flex",height:440,maxHeight:"60vh"},children:[t.jsx(rh,{agents:y,activeAgentId:(n==null?void 0:n.activeAgent)??null,focusedAgentId:f,onFocus:N=>{h(N),s(N)},onSelect:N=>{h(N),s(N),g("models")},onOpenSettings:R}),j&&t.jsx(lh,{agent:j,activeModelId:(n==null?void 0:n.activeModel)??null,focusedIndex:m==="models"?x:-1,onSelect:N=>{o(j.id,N),w()},onOpenSettings:R})]}),t.jsxs("div",{style:{height:32,borderTop:"1px solid var(--border-default, var(--border-subtle))",padding:"0 12px",display:"flex",alignItems:"center",justifyContent:"space-between",fontSize:11,color:"var(--text-muted, var(--text-tertiary))"},children:[t.jsx("button",{type:"button",onClick:()=>R(),"data-testid":"picker-footer-settings",style:{background:"transparent",border:"none",color:"var(--text-primary)",fontSize:11,cursor:"pointer",padding:"0 4px"},children:_.picker.settingsButton}),t.jsx("span",{style:{fontFamily:"'JetBrains Mono Variable', 'JetBrains Mono', monospace"},children:_.picker.footerHint})]})]}),document.body),t.jsx(Fl,{open:c,onClose:()=>d(!1),initialProvider:u,onToast:e})]})}function vh({children:e,reducedMotion:r,onClickOutside:n}){const s=l.useRef(null);return l.useEffect(()=>{const o=a=>{s.current&&!s.current.contains(a.target)&&n()};return document.addEventListener("mousedown",o),()=>document.removeEventListener("mousedown",o)},[n]),t.jsxs("div",{ref:s,"data-testid":"agent-model-picker-popover",role:"dialog","aria-label":"Select agent and model",style:{position:"fixed",top:56,left:"50%",transform:"translateX(-50%)",width:720,background:"var(--bg-surface, var(--surface-1))",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:8,overflow:"hidden",zIndex:90,animation:r?void 0:"agentPickerFadeIn 120ms cubic-bezier(0.2, 0, 0, 1)"},children:[e,t.jsx("style",{children:`@keyframes agentPickerFadeIn {
16
+ from { opacity: 0; transform: translateX(-50%) translateY(2px); }
17
+ to { opacity: 1; transform: translateX(-50%) translateY(0); }
18
+ }`})]})}const js="#F25F1C";function Fa(){typeof window>"u"||(window.location.hash="#/")}function yh({onHome:e}){const[r,n]=l.useState(!1),[s,o]=l.useState(!1),a=c=>{c.metaKey||c.ctrlKey||c.shiftKey||c.button!==0||(c.preventDefault(),Fa(),e==null||e())},i=c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),Fa(),e==null||e())};return t.jsxs("a",{href:"#/",role:"link","data-testid":"studio-logo","aria-label":"Skill Studio — home",onClick:a,onKeyDown:i,onFocus:()=>n(!0),onBlur:()=>n(!1),onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),style:{display:"inline-flex",alignItems:"center",gap:8,flexShrink:0,padding:"4px 8px",margin:"-4px -8px",borderRadius:8,textDecoration:"none",color:"inherit",cursor:"pointer",outline:r?"2px solid var(--border-focus)":"none",outlineOffset:2,background:s?"color-mix(in srgb, var(--text-primary) 4%, transparent)":"transparent",transition:"background-color var(--duration-fast, 120ms) var(--ease-standard, ease)"},children:[t.jsxs("svg",{width:22,height:22,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",style:{display:"block",flexShrink:0,overflow:"visible"},children:[t.jsx("path",{d:"M12 3.25c-3.59 0-6.5 2.91-6.5 6.5v3.18c0 .67-.21 1.32-.6 1.86l-1.27 1.78c-.49.69 0 1.65.84 1.65h15.06c.84 0 1.33-.96.84-1.65l-1.27-1.78c-.39-.54-.6-1.19-.6-1.86V9.75c0-3.59-2.91-6.5-6.5-6.5z",fill:js}),t.jsx("path",{d:"M9.75 19.4h4.5a2.25 2.25 0 11-4.5 0z",fill:js}),t.jsx("circle",{cx:"18.5",cy:"5.5",r:"2.75",fill:js,stroke:"var(--surface-base, #ffffff)",strokeWidth:"1"})]}),t.jsx("span",{style:{fontSize:13,fontWeight:600,letterSpacing:"-0.01em",lineHeight:1,color:"var(--text-primary)"},children:"Skill Studio"})]})}const za=l.memo(function({message:r,politeness:n="polite",role:s}){const o=s??(n==="assertive"?"alert":"status");return t.jsx("div",{"aria-live":n,"aria-atomic":"true",role:o,"data-testid":"aria-live","data-politeness":n,style:{position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(50%)",whiteSpace:"nowrap",border:0,padding:0,margin:-1},children:r})});function bh({toast:e,onDismiss:r}){const[n,s]=l.useState(!0),o=l.useRef(null);l.useEffect(()=>(o.current=requestAnimationFrame(()=>{o.current=requestAnimationFrame(()=>s(!1))}),()=>{o.current!=null&&cancelAnimationFrame(o.current)}),[]);const a={success:"var(--status-installed)",info:"var(--text-secondary)",error:"var(--color-accent, var(--accent-surface))"};return t.jsxs("div",{role:e.severity==="error"?"alert":"status","data-testid":"toast-item","data-severity":e.severity,style:{display:"flex",alignItems:"center",gap:12,padding:"10px 12px",minWidth:240,maxWidth:360,background:"var(--bg-canvas)",color:"var(--text-primary)",border:"1px solid var(--border-default)",borderLeft:`3px solid ${a[e.severity]}`,borderRadius:6,boxShadow:"0 8px 24px rgba(0,0,0,0.12)",fontFamily:"var(--font-sans)",fontSize:12,transform:n?"translateY(8px)":"translateY(0)",opacity:n?0:1,transition:"transform var(--duration-base, 180ms) var(--ease-standard, ease), opacity var(--duration-base, 180ms) var(--ease-standard, ease)"},children:[t.jsx("span",{style:{flex:1,minWidth:0},children:e.message}),e.action&&t.jsx("button",{type:"button",onClick:()=>{e.action.onInvoke(),r(e.id)},style:{background:"transparent",border:"1px solid var(--border-default)",borderRadius:4,padding:"3px 8px",color:"var(--text-primary)",cursor:"pointer",fontSize:11,fontFamily:"var(--font-sans)"},children:e.action.label}),t.jsx("button",{type:"button","aria-label":"Dismiss",onClick:()=>r(e.id),style:{background:"transparent",border:"none",padding:2,color:"var(--text-secondary)",cursor:"pointer",fontSize:14,lineHeight:1},children:"×"})]})}function kh({toasts:e,onDismiss:r,liveMessage:n,liveAssertiveMessage:s}){return t.jsxs(t.Fragment,{children:[t.jsx(za,{politeness:"polite",message:n}),t.jsx(za,{politeness:"assertive",message:s}),e.length>0&&t.jsx("div",{"data-testid":"toast-stack",style:{position:"fixed",right:16,bottom:16,display:"flex",flexDirection:"column-reverse",gap:8,zIndex:2e4,pointerEvents:"none"},children:e.map(o=>t.jsx("div",{style:{pointerEvents:"auto"},children:t.jsx(bh,{toast:o,onDismiss:r})},o.id))})]})}const zl=l.createContext(null);function ss(){const e=l.useContext(zl);if(!e)throw new Error("useToast must be used inside <ToastProvider>.");return e}function jh({children:e,maxVisible:r=4,defaultDurationMs:n=4e3}){const[s,o]=l.useState([]),[a,i]=l.useState(""),[c,d]=l.useState(""),u=l.useRef(new Map),p=l.useCallback(v=>{const b=u.current.get(v);b&&(clearTimeout(b),u.current.delete(v)),o(y=>y.filter(j=>j.id!==v))},[]),f=l.useCallback((v,b)=>{if(b<=0)return;const y=setTimeout(()=>{p(v)},b);u.current.set(v,y)},[p]),h=l.useCallback(v=>{const b=v.id??`toast-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,y={id:b,message:v.message,severity:v.severity??"info",durationMs:v.durationMs??n,action:v.action};return o(j=>[...j,y]),y.severity==="error"?d(y.message):i(y.message),f(b,y.durationMs),b},[n,f]),m=l.useCallback(()=>{for(const v of u.current.values())clearTimeout(v);u.current.clear(),o([])},[]);l.useEffect(()=>{function v(b){b.key==="Escape"&&o(y=>{if(y.length===0)return y;const j=y.slice(0,r),S=j[j.length-1],w=u.current.get(S.id);return w&&(clearTimeout(w),u.current.delete(S.id)),y.filter(R=>R.id!==S.id)})}return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[r]),l.useEffect(()=>()=>{for(const v of u.current.values())clearTimeout(v);u.current.clear()},[]);const g=s.slice(0,r),x=l.useMemo(()=>({toast:h,dismiss:p,clear:m}),[h,p,m]);return t.jsxs(zl.Provider,{value:x,children:[e,t.jsx(kh,{toasts:g,onDismiss:p,liveMessage:a,liveAssertiveMessage:c})]})}function wh(){const{data:e,loading:r}=wt("platform-health",async()=>{const n=await fetch("/api/platform/health");return n.ok?await n.json():{degraded:!1,reason:"platform-unreachable",statsAgeMs:0,oldestActiveAgeMs:0}},{ttl:6e4});return{data:e,loading:r}}const Sh=l.lazy(()=>Lr(()=>import("./UpdateDropdown-Cvr2fe0z.js"),__vite__mapDeps([0,1,2,3,4])));function Ch(e){switch(e){case"connected":return"connected";case"fallback":return"reconnecting";case"connecting":default:return"connecting"}}function Eh(e){switch(e){case"connected":return"var(--status-success-text)";case"fallback":return"var(--color-own)";case"connecting":default:return"var(--text-secondary)"}}function Nh(){const{updateCount:e,updates:r,isRefreshingUpdates:n,refreshUpdates:s,selectSkill:o,revealSkill:a,skills:i,updatesById:c,activeAgent:d,updateStreamStatus:u,trackedSkillCount:p}=Mt(),{toast:f}=ss(),{data:h}=wh(),m=(h==null?void 0:h.degraded)===!0,g=l.useId(),x=u??"connecting",v=typeof p=="number"?p:null,b=v===null?!0:v>0,y=l.useMemo(()=>{if(!c||c.size===0)return;const P=new Map;for(const[L,B]of c)B.diffSummary&&P.set(L,B.diffSummary);return P.size>0?P:void 0},[c]),[j,S]=l.useState(!1),w=l.useRef(null),R=l.useCallback(()=>S(!1),[]),k=m?"var(--color-own)":e>0?"var(--text-primary)":"var(--text-secondary)",E=e>9?"9+":String(e),C=e===0?"No updates available":`${e} updates available, open summary`,N=m?`${C} — platform crawler degraded`:C,I=m?"Update checks paused — verified-skill.com crawler is degraded. Your submissions are queued.":void 0;return t.jsxs("span",{"data-testid":"update-bell-anchor",style:{position:"relative",display:"inline-flex"},children:[t.jsxs("button",{ref:w,type:"button","data-testid":"update-bell","aria-label":N,"aria-haspopup":"dialog","aria-expanded":j,"aria-describedby":g,title:I,onClick:()=>S(P=>!P),style:{position:"relative",display:"inline-flex",alignItems:"center",justifyContent:"center",height:26,width:26,padding:0,borderRadius:4,border:"1px solid transparent",background:"transparent",color:k,cursor:"pointer"},children:[t.jsxs("svg",{"data-testid":"update-bell-icon",width:18,height:18,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"block",opacity:e>0||m?1:.75,color:k},children:[t.jsx("path",{d:"M5.5 17h11l-1.2-1.8a2 2 0 0 1-.3-1.1V10a4 4 0 1 0-8 0v4.1a2 2 0 0 1-.3 1.1L5.5 17Z"}),t.jsx("path",{d:"M10 20a2 2 0 0 0 4 0"}),t.jsx("circle",{cx:"17",cy:"7",r:"2.2",fill:"currentColor",stroke:"none"})]}),e>0&&t.jsx("span",{"data-testid":"update-bell-badge","aria-hidden":"true",style:{position:"absolute",top:-2,right:-2,minWidth:14,height:14,padding:"0 3px",borderRadius:999,background:"var(--color-own)",color:"var(--color-paper)",fontSize:9,fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums",display:"inline-flex",alignItems:"center",justifyContent:"center",fontWeight:600,lineHeight:1},children:E}),b&&t.jsx("span",{"data-testid":"update-bell-status-pip","aria-hidden":"true",style:{position:"absolute",bottom:-1,right:-1,width:6,height:6,borderRadius:999,background:Eh(x),border:"1px solid var(--color-paper)",display:"inline-block",lineHeight:0}})]}),t.jsx("span",{id:g,"data-testid":"update-bell-status-text",style:{position:"absolute",width:1,height:1,margin:-1,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap",border:0},children:`Live updates: ${Ch(x)}`}),j&&t.jsx(l.Suspense,{fallback:t.jsx("span",{"data-testid":"update-bell-fallback",children:"Loading…"}),children:t.jsx(Sh,{updates:r,isRefreshing:n,diffSummariesById:y,onRefresh:()=>s(),onSelectSkill:P=>{const L=P.localSkill??P.name.split("/").pop()??"",B=P.localPlugin??"";if(a)a(B,L);else{const $=P.name.split("/"),M=$.length>=2?$[$.length-2]:$[0];o({plugin:M,skill:L,origin:"installed"})}if(!(i??[]).some($=>$.skill===L&&(B===""||$.plugin===B))){const $=P.installLocations??[];if($.length>0){const M=d?$.filter(W=>W.agent===d):[],F=d?$.filter(W=>W.agent!==d):$;if(M.length>0&&F.length>0){const W=F.length>=2?`Also installed under ${F.length} other locations.`:`Also installed under ${F[0].agentLabel}.`;f({severity:"info",message:W})}else{const W=$[0].agentLabel;f({severity:"info",message:`Skill installed under ${W} — switch to ${W} to view details.`})}}}R()},onViewAll:()=>{window.location.hash="#/updates",R()},onClose:R,anchorRef:w})})]})}function Ba(e){typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:navigate-scope",{detail:e}))}function Rh(e){return e.source==="project"?_.scopeLabels.sourceProject:e.source==="personal"?_.scopeLabels.sourcePersonal:e.source==="plugin"?_.scopeLabels.sourcePlugin:e.origin==="installed"?_.scopeLabels.sourcePersonal:_.scopeLabels.sourceProject}function Th(e){return e.source==="project"?"var(--status-installed)":e.source==="plugin"?"var(--color-accent-ink)":"var(--status-own)"}function Ih({projectName:e,selected:r,onHome:n,projectPickerSlot:s,onRequestCreateSkill:o,findSkillsSlot:a,userDropdownSlot:i,appUpdateSlot:c}){const d=r?Rh(r):null,u=r?Th(r):"var(--text-secondary)";return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:16,height:"100%",width:"100%",padding:"0 16px",fontFamily:"var(--font-sans)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexShrink:0},children:[t.jsx(yh,{onHome:n}),s?t.jsx("div",{style:{borderLeft:"1px solid var(--border-default)",paddingLeft:10,display:"flex",alignItems:"center"},children:s}):e&&t.jsx("span",{title:e,style:{fontSize:12,color:"var(--text-secondary)",borderLeft:"1px solid var(--border-default)",paddingLeft:10,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e})]}),t.jsx("nav",{"aria-label":"Breadcrumb",style:{flex:1,minWidth:0,display:"flex",alignItems:"center",gap:6,fontSize:12,color:"var(--text-secondary)"},children:r&&d&&t.jsxs(t.Fragment,{children:[t.jsx(_a,{segment:"origin",onClick:()=>Ba({scope:"origin",origin:r.origin}),style:{textTransform:"uppercase",letterSpacing:"0.06em",fontWeight:600,color:u},children:d}),t.jsx(Oa,{}),t.jsx(_a,{segment:"plugin",onClick:()=>Ba({scope:"plugin",plugin:r.plugin}),style:{fontFamily:"var(--font-mono)",fontSize:11},children:r.plugin}),t.jsx(Oa,{}),t.jsx("span",{"data-breadcrumb-segment":"skill","aria-current":"page",style:{color:"var(--text-primary)",fontWeight:500,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.skill})]})}),t.jsxs("div",{"data-toprail-right":"true",style:{display:"flex",alignItems:"center",gap:12,flexShrink:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[a,o&&t.jsxs("button",{type:"button","data-slot":"create-skill-button",onClick:o,"aria-label":"Create a new skill",title:"Create a new skill",style:{display:"inline-flex",alignItems:"center",gap:6,height:28,padding:"0 12px",borderRadius:6,border:"1px solid var(--color-action, #2F5B8E)",background:"var(--color-action, #2F5B8E)",color:"var(--color-action-ink, #FFFFFF)",fontSize:12,fontWeight:600,fontFamily:"var(--font-sans)",cursor:"pointer",letterSpacing:"0.01em",boxShadow:"0 1px 2px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.12)"},children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"New Skill"]})]}),t.jsx("span",{"aria-hidden":"true",style:{width:1,height:18,background:"var(--border-default)"}}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{"data-slot":"agent-model-picker",style:{minWidth:200},children:t.jsx(gh,{})}),c&&t.jsx("span",{"data-slot":"app-update",style:{display:"inline-flex"},children:c}),t.jsx("span",{"data-slot":"update-bell",style:{display:"inline-flex"},children:t.jsx(Nh,{})}),i&&t.jsx("span",{"data-slot":"user-dropdown",style:{display:"inline-flex"},children:i})]})]})]})}function _a({segment:e,onClick:r,style:n,children:s}){return t.jsx("button",{type:"button","data-breadcrumb-segment":e,onClick:r,style:{background:"transparent",border:"none",padding:0,cursor:"pointer",color:"var(--text-secondary)",fontFamily:"inherit",...n},onMouseEnter:o=>{o.currentTarget.style.color="var(--color-accent-ink)"},onMouseLeave:o=>{const a=(n==null?void 0:n.color)??"var(--text-secondary)";o.currentTarget.style.color=a},children:s})}function Oa(){return t.jsx("span",{"aria-hidden":"true",style:{color:"var(--border-default)",fontSize:10},children:"›"})}const os="vskill-theme";function Bl(e){return e==="light"||e==="dark"||e==="auto"?e:"auto"}function Lh(e,r){return e==="light"||e==="dark"?e:r?"dark":"light"}function Ah(e){try{const r=e.getItem(os);return Bl(r)}catch{return"auto"}}function Ph(e,r){try{e.setItem(os,r)}catch{}}function $h(e,r,n){e.dataset.theme=n,e.dataset.themeMode=r}function Mh(e){if(!e)return!1;try{return e("(prefers-color-scheme: dark)").matches}catch{return!1}}const _l=l.createContext(null);function Dh({storage:e,matchMedia:r,target:n,children:s}){const o=e??(typeof window<"u"?window.localStorage:void 0),a=r??(typeof window<"u"?window.matchMedia.bind(window):void 0),i=n??(typeof document<"u"?document.documentElement:void 0),[c,d]=l.useState(()=>o?Ah(o):"auto"),[u,p]=l.useState(()=>Mh(a)),f=l.useMemo(()=>Lh(c,u),[c,u]);l.useEffect(()=>{i&&$h(i,c,f)},[i,c,f]),l.useEffect(()=>{if(!a)return;const g=a("(prefers-color-scheme: dark)"),x=b=>p(b.matches);if(typeof g.addEventListener=="function")return g.addEventListener("change",x),()=>g.removeEventListener("change",x);const v=g;return v.addListener(x),()=>v.removeListener(x)},[a]),l.useEffect(()=>{if(typeof window>"u")return;const g=x=>{x.key===os&&d(Bl(x.newValue))};return window.addEventListener("storage",g),()=>window.removeEventListener("storage",g)},[]),l.useEffect(()=>{if(!a||!i)return;let g;try{g=a("(prefers-contrast: more)")}catch{return}const x=y=>{y?i.dataset.contrast="more":i.dataset.contrast==="more"&&delete i.dataset.contrast};x(g.matches);const v=y=>x(y.matches);if(typeof g.addEventListener=="function")return g.addEventListener("change",v),()=>g.removeEventListener("change",v);const b=g;return b.addListener(v),()=>b.removeListener(v)},[a,i]);const h=l.useCallback(g=>{d(g),o&&Ph(o,g)},[o]),m=l.useMemo(()=>({mode:c,resolvedTheme:f,setTheme:h}),[c,f,h]);return t.jsx(_l.Provider,{value:m,children:s})}function Ol(){const e=l.useContext(_l);if(!e)throw new Error("useTheme must be used inside <ThemeProvider>. Wrap the app root in main.tsx.");return e}const Wa=["claude-cli","anthropic","openrouter","ollama","lm-studio"];function Fh(e){const r=new Map(e.map(s=>[s.id,s])),n=[];for(const s of Wa){const o=r.get(s);o&&n.push(o)}for(const s of e)Wa.includes(s.id)||n.push(s);return n}function zh(e){const[r,n]=l.useState(()=>typeof window>"u"||!window.matchMedia?!1:window.matchMedia(`(max-width: ${e}px)`).matches);return l.useEffect(()=>{var a;if(typeof window>"u"||!window.matchMedia)return;const s=window.matchMedia(`(max-width: ${e}px)`),o=()=>n(s.matches);return(a=s.addEventListener)==null||a.call(s,"change",o),()=>{var i;return(i=s.removeEventListener)==null?void 0:i.call(s,"change",o)}},[e]),r}function Bh({providers:e,onOpenSettings:r,onOpenInstallHelp:n}){const s=Fh(e),o=zh(640),[a,i]=l.useState(!1),c=l.useCallback(d=>{d.available||d.kind==="api-key"?r==null||r(d.id):n==null||n(d.id)},[r,n]);if(o){const d=s.filter(u=>u.available).length;return t.jsxs("div",{"data-testid":"providers-segment",style:{position:"relative",display:"inline-flex",alignItems:"center"},children:[t.jsx("button",{type:"button","data-testid":"providers-summary",onClick:()=>i(!a),"aria-label":_.statusBar.providerSummary(d,s.length),style:{background:"transparent",border:"none",color:"var(--text-secondary)",fontSize:11,cursor:"pointer",padding:"0 4px"},children:_.statusBar.providerSummary(d,s.length)}),a&&t.jsx("div",{role:"menu",style:{position:"absolute",bottom:"120%",right:0,background:"var(--bg-surface, var(--surface-1))",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:6,padding:6,minWidth:180,display:"flex",flexDirection:"column",gap:2,zIndex:80},children:s.map(u=>t.jsx(Ha,{p:u,onClick:c},u.id))})]})}return t.jsx("div",{"data-testid":"providers-segment",style:{display:"inline-flex",alignItems:"center",gap:4},children:s.map(d=>t.jsx(Ha,{p:d,onClick:c,compact:!0},d.id))})}function Ha({p:e,onClick:r,compact:n}){const s=e.available?_.statusBar.unlocked(e.label):e.kind==="cli-install"?_.statusBar.lockedCli(e.label):_.statusBar.locked(e.label);return t.jsxs("button",{type:"button","data-testid":`provider-glyph-${e.id}`,"data-available":e.available,"aria-label":s,title:s,onClick:()=>r(e),style:{display:"inline-flex",alignItems:"center",gap:4,background:"transparent",border:"none",color:e.available?"var(--status-installed)":"var(--text-muted, var(--text-tertiary))",cursor:"pointer",padding:n?"2px":"4px 6px",fontSize:11},children:[t.jsx(mo,{unlocked:e.available,size:10}),!n&&t.jsx("span",{children:e.label})]})}function _h(){try{return typeof localStorage>"u"?null:localStorage.getItem(os)}catch{return null}}function Oh({projectPath:e,modelName:r,health:n="ok",onPathClick:s,providers:o,onOpenProviderSettings:a,onOpenProviderInstallHelp:i}){const{mode:c,resolvedTheme:d,setTheme:u}=Ol(),f=_h()==="auto",h=Wh(c,d,f),m=n==="down"||n==="degraded"?"var(--status-own)":"var(--status-installed)";return t.jsxs("div",{role:"contentinfo",style:{display:"flex",alignItems:"center",gap:12,height:"100%",width:"100%",padding:"0 12px",fontSize:11,fontFamily:"var(--font-sans)",color:"var(--text-secondary)",fontVariantNumeric:"tabular-nums"},children:[t.jsx("span",{title:r??"",style:{fontFamily:"var(--font-mono)"},children:r??"—"}),t.jsx(Ua,{}),t.jsxs("span",{"aria-label":`Health: ${n}`,style:{display:"inline-flex",alignItems:"center",gap:6},children:[t.jsx(Hh,{color:m}),t.jsx("span",{style:{textTransform:"capitalize"},children:n})]}),o&&o.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Ua,{}),t.jsx(Bh,{providers:o,onOpenSettings:a,onOpenInstallHelp:i})]}),t.jsx("div",{style:{flex:1}}),t.jsxs("button",{type:"button","data-testid":"theme-toggle",onClick:()=>u(h),"aria-label":`Switch to ${h} theme`,title:`Theme: ${c} — click for ${h}`,style:{display:"inline-flex",alignItems:"center",gap:6,background:"transparent",border:"1px solid var(--border-default)",padding:"2px 8px",borderRadius:4,color:"var(--text-secondary)",cursor:"pointer",fontSize:11,height:20},children:[t.jsx(Uh,{mode:c}),t.jsx("span",{style:{textTransform:"capitalize"},children:c})]})]})}function Wh(e,r,n){return e==="light"?"dark":e==="dark"?"auto":n?"light":r==="light"?"dark":"light"}function Hh({color:e}){return t.jsx("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:e,display:"inline-block",flexShrink:0}})}function Ua(){return t.jsx("span",{"aria-hidden":"true",style:{color:"var(--border-default)"},children:"|"})}function Uh({mode:e}){return e==="dark"?t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"})}):e==="light"?t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"4"}),t.jsx("path",{d:"M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"})]}):t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"9"}),t.jsx("path",{d:"M12 3a9 9 0 0 0 0 18z",fill:"currentColor"})]})}const xo=new Set;function Wl(){for(const e of xo)e()}const Vh=5,Gh=1e3,Kh=6e4;function qh(){const[e,r]=l.useState(void 0),[n,s]=l.useState(!1),[o,a]=l.useState(!0),i=l.useRef(0),c=l.useRef(null),d=l.useRef(null),u=l.useRef(!0),p=l.useRef(0),[f,h]=l.useState(0),m=()=>{d.current!==null&&(clearTimeout(d.current),d.current=null)},g=l.useCallback(()=>{c.current&&(c.current.abort(),c.current=null)},[]),x=l.useCallback(async()=>{if(!u.current||document.visibilityState==="hidden")return;g();const b=new AbortController;c.current=b;try{const y=await fetch("/api/plugins",{signal:b.signal});if(!u.current)return;const j=await y.json();if(!u.current)return;i.current=0,r(j.plugins??[]),a(!1),s(!1),d.current=setTimeout(()=>{u.current&&h(S=>S+1)},Kh)}catch(y){if(!u.current||y instanceof DOMException&&y.name==="AbortError")return;if(i.current+=1,a(!1),i.current>Vh){s(!0);return}const j=Gh*Math.pow(2,i.current-1);d.current=setTimeout(()=>{u.current&&h(S=>S+1)},j)}},[g]);l.useEffect(()=>(u.current=!0,()=>{u.current=!1,m(),g()}),[g]),l.useEffect(()=>{document.visibilityState!=="hidden"&&(m(),x())},[f,x]),l.useEffect(()=>{const b=()=>{document.visibilityState==="hidden"?(m(),g()):(i.current=0,s(!1),h(y=>y+1))};return document.addEventListener("visibilitychange",b),()=>{document.removeEventListener("visibilitychange",b)}},[g]);const v=l.useCallback(()=>{i.current=0,s(!1),m(),p.current+=1,h(b=>b+1)},[]);return l.useEffect(()=>(xo.add(v),()=>{xo.delete(v)}),[v]),{plugins:e,paused:n,loading:o,retry:v}}const as=0,sr=1,Mr=2,Hl=4;function Va(e){return()=>e}function Yh(e){e()}function Ul(e,r){return n=>e(r(n))}function Ga(e,r){return()=>e(r)}function Jh(e,r){return n=>e(r,n)}function Ho(e){return e!==void 0}function Xh(...e){return()=>{e.map(Yh)}}function Dr(){}function is(e,r){return r(e),e}function Qh(e,r){return r(e)}function _e(...e){return e}function Pe(e,r){return e(sr,r)}function Ee(e,r){e(as,r)}function Uo(e){e(Mr)}function We(e){return e(Hl)}function xe(e,r){return Pe(e,Jh(r,as))}function At(e,r){const n=e(sr,s=>{n(),r(s)});return n}function Ka(e){let r,n;return s=>o=>{r=o,n&&clearTimeout(n),n=setTimeout(()=>{s(r)},e)}}function Vl(e,r){return e===r}function Be(e=Vl){let r;return n=>s=>{e(r,s)||(r=s,n(s))}}function ke(e){return r=>n=>{e(n)&&r(n)}}function pe(e){return r=>Ul(r,e)}function zt(e){return r=>()=>{r(e)}}function Y(e,...r){const n=Zh(...r);return((s,o)=>{switch(s){case Mr:Uo(e);return;case sr:return Pe(e,n(o))}})}function Ot(e,r){return n=>s=>{n(r=e(r,s))}}function fr(e){return r=>n=>{e>0?e--:r(n)}}function Kt(e){let r=null,n;return s=>o=>{r=o,!n&&(n=setTimeout(()=>{n=void 0,s(r)},e))}}function Ne(...e){const r=new Array(e.length);let n=0,s=null;const o=2**e.length-1;return e.forEach((a,i)=>{const c=2**i;Pe(a,d=>{const u=n;n|=c,r[i]=d,u!==o&&n===o&&s&&(s(),s=null)})}),a=>i=>{const c=()=>{a([i].concat(r))};n===o?c():s=c}}function Zh(...e){return r=>e.reduceRight(Qh,r)}function em(e){let r,n;const s=()=>r==null?void 0:r();return function(o,a){switch(o){case sr:return a?n===a?void 0:(s(),n=a,r=Pe(e,a),r):(s(),Dr);case Mr:s(),n=null;return}}}function te(e){let r=e;const n=Te();return((s,o)=>{switch(s){case as:r=o;break;case sr:{o(r);break}case Hl:return r}return n(s,o)})}function at(e,r){return is(te(r),n=>xe(e,n))}function Te(){const e=[];return((r,n)=>{switch(r){case as:e.slice().forEach(s=>{s(n)});return;case Mr:e.splice(0,e.length);return;case sr:return e.push(n),()=>{const s=e.indexOf(n);s>-1&&e.splice(s,1)}}})}function kt(e){return is(Te(),r=>xe(e,r))}function Le(e,r=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:r,id:tm(),singleton:n}}const tm=()=>Symbol();function rm(e){const r=new Map,n=({constructor:s,dependencies:o,id:a,singleton:i})=>{if(i&&r.has(a))return r.get(a);const c=s(o.map(d=>n(d)));return i&&r.set(a,c),c};return n(e)}function qe(...e){const r=Te(),n=new Array(e.length);let s=0;const o=2**e.length-1;return e.forEach((a,i)=>{const c=2**i;Pe(a,d=>{n[i]=d,s|=c,s===o&&Ee(r,n)})}),function(a,i){switch(a){case Mr:{Uo(r);return}case sr:return s===o&&i(n),Pe(r,i)}}}function be(e,r=Vl){return Y(e,Be(r))}function go(...e){return function(r,n){switch(r){case Mr:return;case sr:return Xh(...e.map(s=>Pe(s,n)))}}}const Ze={DEBUG:0,INFO:1,WARN:2,ERROR:3},nm={[Ze.DEBUG]:"debug",[Ze.ERROR]:"error",[Ze.INFO]:"log",[Ze.WARN]:"warn"},sm=()=>typeof globalThis>"u"?window:globalThis,or=Le(()=>{const e=te(Ze.ERROR);return{log:te((r,n,s=Ze.INFO)=>{const o=sm().VIRTUOSO_LOG_LEVEL??We(e);s>=o&&console[nm[s]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",r,n)}),logLevel:e}},[],{singleton:!0});function mr(e,r,n){return Vo(e,r,n).callbackRef}function Vo(e,r,n){const s=me.useRef(null);let o=i=>{};const a=me.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const c=()=>{const d=i[0].target;d.offsetParent!==null&&e(d)};n?c():requestAnimationFrame(c)}):null,[e,n]);return o=i=>{i&&r?(a==null||a.observe(i),s.current=i):(s.current&&(a==null||a.unobserve(s.current)),s.current=null)},{callbackRef:o,ref:s}}function om(e,r,n,s,o,a,i,c,d){const u=me.useCallback(p=>{const f=am(p.children,r,c?"offsetWidth":"offsetHeight",o);let h=p.parentElement;for(;h.dataset.virtuosoScroller===void 0;)h=h.parentElement;const m=h.lastElementChild.dataset.viewportType==="window";let g;m&&(g=h.ownerDocument.defaultView);const x=i?c?i.scrollLeft:i.scrollTop:m?c?g.scrollX||g.document.documentElement.scrollLeft:g.scrollY||g.document.documentElement.scrollTop:c?h.scrollLeft:h.scrollTop,v=i?c?i.scrollWidth:i.scrollHeight:m?c?g.document.documentElement.scrollWidth:g.document.documentElement.scrollHeight:c?h.scrollWidth:h.scrollHeight,b=i?c?i.offsetWidth:i.offsetHeight:m?c?g.innerWidth:g.innerHeight:c?h.offsetWidth:h.offsetHeight;s({scrollHeight:v,scrollTop:Math.max(x,0),viewportHeight:b}),a==null||a(c?qa("column-gap",getComputedStyle(p).columnGap,o):qa("row-gap",getComputedStyle(p).rowGap,o)),f!==null&&e(f)},[e,r,o,a,i,s,c]);return Vo(u,n,d)}function am(e,r,n,s){const o=e.length;if(o===0)return null;const a=[];for(let i=0;i<o;i++){const c=e.item(i);if(c.dataset.index===void 0)continue;const d=parseInt(c.dataset.index),u=parseFloat(c.dataset.knownSize),p=r(c,n);if(p===0&&s("Zero-sized element, this should not happen",{child:c},Ze.ERROR),p===u)continue;const f=a[a.length-1];a.length===0||f.size!==p||f.endIndex!==d-1?a.push({endIndex:d,size:p,startIndex:d}):a[a.length-1].endIndex++}return a}function qa(e,r,n){return r!=="normal"&&(r==null?void 0:r.endsWith("px"))!==!0&&n(`${e} was not resolved to pixel value correctly`,r,Ze.WARN),r==="normal"?0:parseInt(r??"0",10)}function Gl(e,r,n){const s=me.useRef(null),o=me.useCallback(d=>{if(!(d!=null&&d.offsetParent))return;const u=d.getBoundingClientRect(),p=u.width;let f,h;if(r){const m=r.getBoundingClientRect(),g=u.top-m.top;h=m.height-Math.max(0,g),f=g+r.scrollTop}else{const m=i.current.ownerDocument.defaultView;h=m.innerHeight-Math.max(0,u.top),f=u.top+m.scrollY}s.current={listHeight:u.height,offsetTop:f,visibleHeight:h,visibleWidth:p},e(s.current)},[e,r]),{callbackRef:a,ref:i}=Vo(o,!0,n),c=me.useCallback(()=>{o(i.current)},[o,i]);return me.useEffect(()=>{var u;if(r){r.addEventListener("scroll",c);const p=new ResizeObserver(()=>{requestAnimationFrame(c)});return p.observe(r),()=>{r.removeEventListener("scroll",c),p.unobserve(r)}}const d=(u=i.current)==null?void 0:u.ownerDocument.defaultView;return d==null||d.addEventListener("scroll",c),d==null||d.addEventListener("resize",c),()=>{d==null||d.removeEventListener("scroll",c),d==null||d.removeEventListener("resize",c)}},[c,r,i]),a}const dt=Le(()=>{const e=Te(),r=Te(),n=te(0),s=Te(),o=te(0),a=Te(),i=Te(),c=te(0),d=te(0),u=te(0),p=te(0),f=Te(),h=Te(),m=te(!1),g=te(!1),x=te(!1);return xe(Y(e,pe(({scrollTop:v})=>v)),r),xe(Y(e,pe(({scrollHeight:v})=>v)),i),xe(r,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:d,footerHeight:p,headerHeight:c,horizontalDirection:g,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:m,scrollTo:f,scrollTop:r,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:s,statefulScrollTop:o,viewportHeight:a}},[],{singleton:!0}),sn={lvl:0};function Kl(e,r){const n=e.length;if(n===0)return[];let{index:s,value:o}=r(e[0]);const a=[];for(let i=1;i<n;i++){const{index:c,value:d}=r(e[i]);a.push({end:c-1,start:s,value:o}),s=c,o=d}return a.push({end:1/0,start:s,value:o}),a}function Me(e){return e===sn}function on(e,r){if(!Me(e))return r===e.k?e.v:r<e.k?on(e.l,r):on(e.r,r)}function $t(e,r,n="k"){if(Me(e))return[-1/0,void 0];if(Number(e[n])===r)return[e.k,e.v];if(Number(e[n])<r){const s=$t(e.r,r,n);return s[0]===-1/0?[e.k,e.v]:s}return $t(e.l,r,n)}function bt(e,r,n){return Me(e)?Jl(r,n,1):r===e.k?Xe(e,{k:r,v:n}):r<e.k?Ya(Xe(e,{l:bt(e.l,r,n)})):Ya(Xe(e,{r:bt(e.r,r,n)}))}function Er(){return sn}function Nr(e,r,n){if(Me(e))return[];const s=$t(e,r)[0];return im(yo(e,s,n))}function vo(e,r){if(Me(e))return sn;const{k:n,l:s,r:o}=e;if(r===n){if(Me(s))return o;if(Me(o))return s;const[a,i]=Yl(s);return Hn(Xe(e,{k:a,l:ql(s),v:i}))}return r<n?Hn(Xe(e,{l:vo(s,r)})):Hn(Xe(e,{r:vo(o,r)}))}function pr(e){return Me(e)?[]:[...pr(e.l),{k:e.k,v:e.v},...pr(e.r)]}function yo(e,r,n){if(Me(e))return[];const{k:s,l:o,r:a,v:i}=e;let c=[];return s>r&&(c=c.concat(yo(o,r,n))),s>=r&&s<=n&&c.push({k:s,v:i}),s<=n&&(c=c.concat(yo(a,r,n))),c}function Hn(e){const{l:r,lvl:n,r:s}=e;if(s.lvl>=n-1&&r.lvl>=n-1)return e;if(n>s.lvl+1){if(ws(r))return Xl(Xe(e,{lvl:n-1}));if(!Me(r)&&!Me(r.r))return Xe(r.r,{l:Xe(r,{r:r.r.l}),lvl:n,r:Xe(e,{l:r.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}if(ws(e))return bo(Xe(e,{lvl:n-1}));if(!Me(s)&&!Me(s.l)){const o=s.l,a=ws(o)?s.lvl-1:s.lvl;return Xe(o,{l:Xe(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:bo(Xe(s,{l:o.r,lvl:a}))})}throw new Error("Unexpected empty nodes")}function Xe(e,r){return Jl(r.k!==void 0?r.k:e.k,r.v!==void 0?r.v:e.v,r.lvl!==void 0?r.lvl:e.lvl,r.l!==void 0?r.l:e.l,r.r!==void 0?r.r:e.r)}function ql(e){return Me(e.r)?e.l:Hn(Xe(e,{r:ql(e.r)}))}function ws(e){return Me(e)||e.lvl>e.r.lvl}function Yl(e){return Me(e.r)?[e.k,e.v]:Yl(e.r)}function Jl(e,r,n,s=sn,o=sn){return{k:e,l:s,lvl:n,r:o,v:r}}function Ya(e){return bo(Xl(e))}function Xl(e){const{l:r}=e;return!Me(r)&&r.lvl===e.lvl?Xe(r,{r:Xe(e,{l:r.r})}):e}function bo(e){const{lvl:r,r:n}=e;return!Me(n)&&!Me(n.r)&&n.lvl===r&&n.r.lvl===r?Xe(n,{l:Xe(e,{r:n.l}),lvl:r+1}):e}function im(e){return Kl(e,({k:r,v:n})=>({index:r,value:n}))}function Ql(e,r){return!!(e&&e.startIndex===r.startIndex&&e.endIndex===r.endIndex)}function an(e,r){return!!(e&&e[0]===r[0]&&e[1]===r[1])}const Go=Le(()=>({recalcInProgress:te(!1)}),[],{singleton:!0});function Zl(e,r,n){return e[qn(e,r,n)]}function qn(e,r,n,s=0){let o=e.length-1;for(;s<=o;){const a=Math.floor((s+o)/2),i=e[a],c=n(i,r);if(c===0)return a;if(c===-1){if(o-s<2)return a-1;o=a-1}else{if(o===s)return a;s=a+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${r}`)}function lm(e,r,n,s){const o=qn(e,r,s),a=qn(e,n,s,o);return e.slice(o,a+1)}function rr(e,r){return Math.round(e.getBoundingClientRect()[r])}function ls(e){return!Me(e.groupOffsetTree)}function Ko({index:e},r){return r===e?0:r<e?-1:1}function cm(){return{groupIndices:[],groupOffsetTree:Er(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Er()}}function dm(e,r){let n=Me(e)?0:1/0;for(const s of r){const{endIndex:o,size:a,startIndex:i}=s;if(n=Math.min(n,i),Me(e)){e=bt(e,0,a);continue}const c=Nr(e,i-1,o+1);if(c.some(gm(s)))continue;let d=!1,u=!1;for(const{end:p,start:f,value:h}of c)d?(o>=f||a===h)&&(e=vo(e,f)):(u=h!==a,d=!0),p>o&&o>=f&&h!==a&&(e=bt(e,o+1,h));u&&(e=bt(e,i,a))}return[e,n]}function um(e){return typeof e.groupIndex<"u"}function pm({offset:e},r){return r===e?0:r<e?-1:1}function ln(e,r,n){if(r.length===0)return 0;const{index:s,offset:o,size:a}=Zl(r,e,Ko),i=e-s,c=a*i+(i-1)*n+o;return c>0?c+n:c}function ec(e,r){if(!ls(r))return e;let n=0;for(;r.groupIndices[n]<=e+n;)n++;return e+n}function tc(e,r,n){if(um(e))return r.groupIndices[e.groupIndex]+1;const s=e.index==="LAST"?n:e.index;let o=ec(s,r);return o=Math.max(0,o,Math.min(n,o)),o}function fm(e,r,n,s=0){return s>0&&(r=Math.max(r,Zl(e,s,Ko).offset)),Kl(lm(e,r,n,pm),xm)}function hm(e,[r,n,s,o]){r.length>0&&s("received item sizes",r,Ze.DEBUG);const a=e.sizeTree;let i=a,c=0;if(n.length>0&&Me(a)&&r.length===2){const h=r[0].size,m=r[1].size;i=n.reduce((g,x)=>bt(bt(g,x,h),x+1,m),i)}else[i,c]=dm(i,r);if(i===a)return e;const{lastIndex:d,lastOffset:u,lastSize:p,offsetTree:f}=ko(e.offsetTree,c,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,m)=>bt(h,m,ln(m,f,o)),Er()),lastIndex:d,lastOffset:u,lastSize:p,offsetTree:f,sizeTree:i}}function mm(e){return pr(e).map(({k:r,v:n},s,o)=>{const a=o[s+1];return{endIndex:a!==void 0?a.k-1:1/0,size:n,startIndex:r}})}function Ja(e,r){let n=0,s=0;for(;n<e;)n+=r[s+1]-r[s]-1,s++;return s-(n===e?0:1)}function ko(e,r,n,s){let o=e,a=0,i=0,c=0,d=0;if(r!==0){d=qn(o,r-1,Ko),c=o[d].offset;const u=$t(n,r-1);a=u[0],i=u[1],o.length&&o[d].size===$t(n,r)[1]&&(d-=1),o=o.slice(0,d+1)}else o=[];for(const{start:u,value:p}of Nr(n,r,1/0)){const f=u-a,h=f*i+c+f*s;o.push({index:u,offset:h,size:p}),a=u,c=h,i=p}return{lastIndex:a,lastOffset:c,lastSize:i,offsetTree:o}}function xm(e){return{index:e.index,value:e}}function gm(e){const{endIndex:r,size:n,startIndex:s}=e;return o=>o.start===s&&(o.end===r||o.end===1/0)&&o.value===n}const vm={offsetHeight:"height",offsetWidth:"width"},Ut=Le(([{log:e},{recalcInProgress:r}])=>{const n=Te(),s=Te(),o=at(s,0),a=Te(),i=Te(),c=te(0),d=te([]),u=te(void 0),p=te(void 0),f=te(void 0),h=te(void 0),m=te((k,E)=>rr(k,vm[E])),g=te(void 0),x=te(0),v=cm(),b=at(Y(n,Ne(d,e,x),Ot(hm,v),Be()),v),y=at(Y(d,Be(),Ot((k,E)=>({current:E,prev:k.current}),{current:[],prev:[]}),pe(({prev:k})=>k)),[]);xe(Y(d,ke(k=>k.length>0),Ne(b,x),pe(([k,E,C])=>{const N=k.reduce((I,P,L)=>bt(I,P,ln(P,E.offsetTree,C)||L),Er());return{...E,groupIndices:k,groupOffsetTree:N}})),b),xe(Y(s,Ne(b),ke(([k,{lastIndex:E}])=>k<E),pe(([k,{lastIndex:E,lastSize:C}])=>[{endIndex:E,size:C,startIndex:k}])),n),xe(u,p);const j=at(Y(u,pe(k=>k===void 0)),!0);xe(Y(p,ke(k=>k!==void 0&&Me(We(b).sizeTree)),pe(k=>{const E=We(f),C=We(d).length>0;return E!==void 0&&E!==0?C?[{endIndex:0,size:E,startIndex:0},{endIndex:1,size:k,startIndex:1}]:[]:[{endIndex:0,size:k,startIndex:0}]})),n),xe(Y(h,ke(k=>k!==void 0&&k.length>0&&Me(We(b).sizeTree)),pe(k=>{const E=[];let C=k[0],N=0;for(let I=1;I<k.length;I++){const P=k[I];P!==C&&(E.push({endIndex:I-1,size:C,startIndex:N}),C=P,N=I)}return E.push({endIndex:k.length-1,size:C,startIndex:N}),E})),n),xe(Y(d,Ne(f,p),ke(([,k,E])=>k!==void 0&&E!==void 0),pe(([k,E,C])=>{const N=[];for(let I=0;I<k.length;I++){const P=k[I],L=k[I+1];N.push({startIndex:P,endIndex:P,size:E}),L!==void 0&&N.push({startIndex:P+1,endIndex:L-1,size:C})}return N})),n);const S=kt(Y(n,Ne(b),Ot(({sizes:k},[E,C])=>({changed:C!==k,sizes:C}),{changed:!1,sizes:v}),pe(k=>k.changed)));Pe(Y(c,Ot((k,E)=>({diff:k.prev-E,prev:E}),{diff:0,prev:0}),pe(k=>k.diff)),k=>{const{groupIndices:E}=We(b);if(k>0)Ee(r,!0),Ee(a,k+Ja(k,E));else if(k<0){const C=We(y);C.length>0&&(k-=Ja(-k,C)),Ee(i,k)}}),Pe(Y(c,Ne(e)),([k,E])=>{k<0&&E("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:c},Ze.ERROR)});const w=kt(a);xe(Y(a,Ne(b),pe(([k,E])=>{const C=E.groupIndices.length>0,N=[],I=E.lastSize;if(C){const P=on(E.sizeTree,0);let L=0,B=0;for(;L<k;){const $=E.groupIndices[B],M=E.groupIndices.length===B+1?1/0:E.groupIndices[B+1]-$-1;N.push({endIndex:$,size:P,startIndex:$}),N.push({endIndex:$+1+M-1,size:I,startIndex:$+1}),B++,L+=M+1}const T=pr(E.sizeTree);return L!==k&&T.shift(),T.reduce(($,{k:M,v:F})=>{let W=$.ranges;return $.prevSize!==0&&(W=[...$.ranges,{endIndex:M+k-1,size:$.prevSize,startIndex:$.prevIndex}]),{prevIndex:M+k,prevSize:F,ranges:W}},{prevIndex:k,prevSize:0,ranges:N}).ranges}return pr(E.sizeTree).reduce((P,{k:L,v:B})=>({prevIndex:L+k,prevSize:B,ranges:[...P.ranges,{endIndex:L+k-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:I,ranges:[]}).ranges})),n);const R=kt(Y(i,Ne(b,x),pe(([k,{offsetTree:E},C])=>{const N=-k;return ln(N,E,C)})));return xe(Y(i,Ne(b,x),pe(([k,E,C])=>{if(E.groupIndices.length>0){if(Me(E.sizeTree))return E;let I=Er();const P=We(y);let L=0,B=0,T=0;for(;L<-k;){T=P[B];const $=P[B+1]-T-1;B++,L+=$+1}if(I=pr(E.sizeTree).reduce(($,{k:M,v:F})=>bt($,Math.max(0,M+k),F),I),L!==-k){const $=on(E.sizeTree,T);I=bt(I,0,$);const M=$t(E.sizeTree,-k+1)[1];I=bt(I,1,M)}return{...E,sizeTree:I,...ko(E.offsetTree,0,I,C)}}const N=pr(E.sizeTree).reduce((I,{k:P,v:L})=>bt(I,Math.max(0,P+k),L),Er());return{...E,sizeTree:N,...ko(E.offsetTree,0,N,C)}})),b),{beforeUnshiftWith:w,data:g,defaultItemSize:p,firstItemIndex:c,fixedItemSize:u,fixedGroupSize:f,gap:x,groupIndices:d,heightEstimates:h,itemSize:m,listRefresh:S,shiftWith:i,shiftWithOffset:R,sizeRanges:n,sizes:b,statefulTotalCount:o,totalCount:s,trackItemSizes:j,unshiftWith:a}},_e(or,Go),{singleton:!0});function ym(e){return e.reduce((r,n)=>(r.groupIndices.push(r.totalCount),r.totalCount+=n+1,r),{groupIndices:[],totalCount:0})}const rc=Le(([{groupIndices:e,sizes:r,totalCount:n},{headerHeight:s,scrollTop:o}])=>{const a=Te(),i=Te(),c=kt(Y(a,pe(ym)));return xe(Y(c,pe(d=>d.totalCount)),n),xe(Y(c,pe(d=>d.groupIndices)),e),xe(Y(qe(o,r,s),ke(([d,u])=>ls(u)),pe(([d,u,p])=>$t(u.groupOffsetTree,Math.max(d-p,0),"v")[0]),Be(),pe(d=>[d])),i),{groupCounts:a,topItemsIndexes:i}},_e(Ut,dt)),ar=Le(([{log:e}])=>{const r=te(!1),n=kt(Y(r,ke(s=>s),Be()));return Pe(r,s=>{s&&We(e)("props updated",{},Ze.DEBUG)}),{didMount:n,propsReady:r}},_e(or),{singleton:!0}),bm=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function nc(e){const r=typeof e=="number"?{index:e}:e;return r.align||(r.align="start"),(!r.behavior||!bm)&&(r.behavior="auto"),r.offset===void 0&&(r.offset=0),r}const mn=Le(([{gap:e,listRefresh:r,sizes:n,totalCount:s},{fixedFooterHeight:o,fixedHeaderHeight:a,footerHeight:i,headerHeight:c,scrollingInProgress:d,scrollTo:u,smoothScrollTargetReached:p,viewportHeight:f},{log:h}])=>{const m=Te(),g=Te(),x=te(0);let v=null,b=null,y=null;function j(){v!==null&&(v(),v=null),y!==null&&(y(),y=null),b&&(clearTimeout(b),b=null),Ee(d,!1)}return xe(Y(m,Ne(n,f,s,x,c,i,h),Ne(e,a,o),pe(([[S,w,R,k,E,C,N,I],P,L,B])=>{const T=nc(S),{align:$,behavior:M,offset:F}=T,W=k-1,le=tc(T,w,W);let U=ln(le,w.offsetTree,P)+C;$==="end"?(U+=L+$t(w.sizeTree,le)[1]-R+B,le===W&&(U+=N)):$==="center"?U+=(L+$t(w.sizeTree,le)[1]-R+B)/2:U-=E,F!==void 0&&F!==0&&(U+=F);const H=ee=>{j(),ee?(I("retrying to scroll to",{location:S},Ze.DEBUG),Ee(m,S)):(Ee(g,!0),I("list did not change, scroll successful",{},Ze.DEBUG))};if(j(),M==="smooth"){let ee=!1;y=Pe(r,K=>{ee=ee||K}),v=At(p,()=>{H(ee)})}else v=At(Y(r,km(150)),H);return b=setTimeout(()=>{j()},1200),Ee(d,!0),I("scrolling from index to",{behavior:M,index:le,top:U},Ze.DEBUG),{behavior:M,top:U}})),u),{scrollTargetReached:g,scrollToIndex:m,topListHeight:x}},_e(Ut,dt,or),{singleton:!0});function km(e){return r=>{const n=setTimeout(()=>{r(!1)},e);return s=>{s&&(r(!0),clearTimeout(n))}}}function qo(e,r){e===0?r():requestAnimationFrame(()=>{qo(e-1,r)})}function Yo(e,r){const n=r-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const xn=Le(([{defaultItemSize:e,listRefresh:r,sizes:n},{scrollTop:s},{scrollTargetReached:o,scrollToIndex:a},{didMount:i}])=>{const c=te(!0),d=te(0),u=te(!0);return xe(Y(i,Ne(d),ke(([p,f])=>f!==0),zt(!1)),c),xe(Y(i,Ne(d),ke(([p,f])=>f!==0),zt(!1)),u),Pe(Y(qe(r,i),Ne(c,n,e,u),ke(([[,p],f,{sizeTree:h},m,g])=>p&&(!Me(h)||Ho(m))&&!f&&!g),Ne(d)),([,p])=>{At(o,()=>{Ee(u,!0)}),qo(4,()=>{At(s,()=>{Ee(c,!0)}),Ee(a,p)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:d,scrolledToInitialItem:c}},_e(Ut,dt,mn,ar),{singleton:!0});function sc(e,r){return Math.abs(e-r)<1.01}const cn="up",Qr="down",jm="none",wm={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Sm=0,gn=Le(([{footerHeight:e,headerHeight:r,scrollBy:n,scrollContainerState:s,scrollTop:o,viewportHeight:a}])=>{const i=te(!1),c=te(!0),d=Te(),u=Te(),p=te(4),f=te(Sm),h=at(Y(go(Y(be(o),fr(1),zt(!0)),Y(be(o),fr(1),zt(!1),Ka(100))),Be()),!1),m=at(Y(go(Y(n,zt(!0)),Y(n,zt(!1),Ka(200))),Be()),!1);xe(Y(qe(be(o),be(f)),pe(([y,j])=>y<=j),Be()),c),xe(Y(c,Kt(50)),u);const g=kt(Y(qe(s,be(a),be(r),be(e),be(p)),Ot((y,[{scrollHeight:j,scrollTop:S},w,R,k,E])=>{const C=S+w-j>-E,N={scrollHeight:j,scrollTop:S,viewportHeight:w};if(C){let P,L;return S>y.state.scrollTop?(P="SCROLLED_DOWN",L=y.state.scrollTop-S):(P="SIZE_DECREASED",L=y.state.scrollTop-S||y.scrollTopDelta),{atBottom:!0,atBottomBecause:P,scrollTopDelta:L,state:N}}let I;return N.scrollHeight>y.state.scrollHeight?I="SIZE_INCREASED":w<y.state.viewportHeight?I="VIEWPORT_HEIGHT_DECREASING":S<y.state.scrollTop?I="SCROLLING_UPWARDS":I="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:I,state:N}},wm),Be((y,j)=>y!==void 0&&y.atBottom===j.atBottom))),x=at(Y(s,Ot((y,{scrollHeight:j,scrollTop:S,viewportHeight:w})=>{if(!sc(y.scrollHeight,j)){const R=j-(S+w)<1;return y.scrollTop!==S&&R?{changed:!0,jump:y.scrollTop-S,scrollHeight:j,scrollTop:S}:{changed:!0,jump:0,scrollHeight:j,scrollTop:S}}return{changed:!1,jump:0,scrollHeight:j,scrollTop:S}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),ke(y=>y.changed),pe(y=>y.jump)),0);xe(Y(g,pe(y=>y.atBottom)),i),xe(Y(i,Kt(50)),d);const v=te(Qr);xe(Y(s,pe(({scrollTop:y})=>y),Be(),Ot((y,j)=>We(m)?{direction:y.direction,prevScrollTop:j}:{direction:j<y.prevScrollTop?cn:Qr,prevScrollTop:j},{direction:Qr,prevScrollTop:0}),pe(y=>y.direction)),v),xe(Y(s,Kt(50),zt(jm)),v);const b=te(0);return xe(Y(h,ke(y=>!y),zt(0)),b),xe(Y(o,Kt(100),Ne(h),ke(([y,j])=>j),Ot(([y,j],[S])=>[j,S],[0,0]),pe(([y,j])=>j-y)),b),{atBottomState:g,atBottomStateChange:d,atBottomThreshold:p,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:c,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:v,scrollVelocity:b}},_e(dt)),dn="top",un="bottom",Xa="none";function Qa(e,r,n){return typeof e=="number"?n===cn&&r===dn||n===Qr&&r===un?e:0:n===cn?r===dn?e.main:e.reverse:r===un?e.main:e.reverse}function Za(e,r){return typeof e=="number"?e:e[r]??0}const Jo=Le(([{deviation:e,fixedHeaderHeight:r,headerHeight:n,scrollTop:s,viewportHeight:o}])=>{const a=Te(),i=te(0),c=te(0),d=te(0),u=at(Y(qe(be(s),be(o),be(n),be(a,an),be(d),be(i),be(r),be(e),be(c)),pe(([p,f,h,[m,g],x,v,b,y,j])=>{const S=p-y,w=v+b,R=Math.max(h-S,0);let k=Xa;const E=Za(j,dn),C=Za(j,un);return m-=y,m+=h+b,g+=h+b,g-=y,m>p+w-E&&(k=cn),g<p-R+f+C&&(k=Qr),k!==Xa?[Math.max(S-h-Qa(x,dn,k)-E,0),S-R-b+f+Qa(x,un,k)+C]:null}),ke(p=>p!==null),Be(an)),[0,0]);return{increaseViewportBy:c,listBoundary:a,overscan:d,topListHeight:i,visibleRange:u}},_e(dt),{singleton:!0});function Cm(e,r,n){if(ls(r)){const s=ec(e,r);return[{index:$t(r.groupOffsetTree,s)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:s,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const Ss={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Un(e,r,n,s,o,a){const{lastIndex:i,lastOffset:c,lastSize:d}=o;let u=0,p=0;if(e.length>0){u=e[0].offset;const x=e[e.length-1];p=x.offset+x.size}const f=n-i,h=c+f*d+(f-1)*s,m=u,g=h-p;return{bottom:p,firstItemIndex:a,items:ei(e,o,a),offsetBottom:g,offsetTop:u,top:m,topItems:ei(r,o,a),topListHeight:r.reduce((x,v)=>v.size+x,0),totalCount:n}}function oc(e,r,n,s,o,a){let i=0;if(n.groupIndices.length>0)for(const p of n.groupIndices){if(p-i>=e)break;i++}const c=e+i,d=Yo(r,c),u=Array.from({length:c}).map((p,f)=>({data:a[f+d],index:f+d,offset:0,size:0}));return Un(u,[],c,o,n,s)}function ei(e,r,n){if(e.length===0)return[];if(!ls(r))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const s=e[0].index,o=e[e.length-1].index,a=[],i=Nr(r.groupOffsetTree,s,o);let c,d=0;for(const u of e){(!c||c.end<u.index)&&(c=i.shift(),d=r.groupIndices.indexOf(c.start));let p;u.index===c.start?p={index:d,type:"group"}:p={groupIndex:d,index:u.index-(d+1)+n},a.push({...p,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return a}function ti(e,r){return e===void 0?0:typeof e=="number"?e:e[r]??0}const xr=Le(([{data:e,firstItemIndex:r,gap:n,sizes:s,totalCount:o},a,{listBoundary:i,topListHeight:c,visibleRange:d},{initialTopMostItemIndex:u,scrolledToInitialItem:p},{topListHeight:f},h,{didMount:m},{recalcInProgress:g}])=>{const x=te([]),v=te(0),b=Te(),y=te(0);xe(a.topItemsIndexes,x);const j=at(Y(qe(m,g,be(d,an),be(o),be(s),be(u),p,be(x),be(r),be(n),be(y),e),ke(([k,E,,C,,,,,,,,N])=>{const I=N!==void 0&&N.length!==C;return k&&!E&&!I}),pe(([,,[k,E],C,N,I,P,L,B,T,$,M])=>{var O,V;const F=N,{offsetTree:W,sizeTree:le}=F,U=We(v);if(C===0)return{...Ss,totalCount:C};if(k===0&&E===0)return U===0?{...Ss,totalCount:C}:oc(U,I,N,B,T,M||[]);if(Me(le))return U>0?null:Un(Cm(Yo(I,C),F,M),[],C,T,F,B);const H=[];if(L.length>0){const re=L[0],ce=L[L.length-1];let ne=0;for(const ve of Nr(le,re,ce)){const ge=ve.value,se=Math.max(ve.start,re),fe=Math.min(ve.end,ce);for(let z=se;z<=fe;z++)H.push({data:M==null?void 0:M[z],index:z,offset:ne,size:ge}),ne+=ge}}if(!P)return Un([],H,C,T,F,B);const ee=L.length>0?L[L.length-1]+1:0,K=fm(W,k,E,ee);if(K.length===0)return null;const X=C-1,G=is([],re=>{for(const ce of K){const ne=ce.value;let ve=ne.offset,ge=ce.start;const se=ne.size;if(ne.offset<k){ge+=Math.floor((k-ne.offset+T)/(se+T));const z=ge-ce.start;ve+=z*se+z*T}ge<ee&&(ve+=(ee-ge)*se,ge=ee);const fe=Math.min(ce.end,X);for(let z=ge;z<=fe&&!(ve>=E);z++)re.push({data:M==null?void 0:M[z],index:z,offset:ve,size:se}),ve+=se+T}}),he=ti($,dn),A=ti($,un);if(G.length>0&&(he>0||A>0)){const re=G[0],ce=G[G.length-1];if(he>0&&re.index>ee){const ne=Math.min(he,re.index-ee),ve=[];let ge=re.offset;for(let se=re.index-1;se>=re.index-ne;se--){const fe=((O=Nr(le,se,se)[0])==null?void 0:O.value)??re.size;ge-=fe+T,ve.unshift({data:M==null?void 0:M[se],index:se,offset:ge,size:fe})}G.unshift(...ve)}if(A>0&&ce.index<X){const ne=Math.min(A,X-ce.index);let ve=ce.offset+ce.size+T;for(let ge=ce.index+1;ge<=ce.index+ne;ge++){const se=((V=Nr(le,ge,ge)[0])==null?void 0:V.value)??ce.size;G.push({data:M==null?void 0:M[ge],index:ge,offset:ve,size:se}),ve+=se+T}}}return Un(G,H,C,T,F,B)}),ke(k=>k!==null),Be()),Ss);xe(Y(e,ke(Ho),pe(k=>k==null?void 0:k.length)),o),xe(Y(j,pe(k=>k.topListHeight)),f),xe(f,c),xe(Y(j,pe(k=>[k.top,k.bottom])),i),xe(Y(j,pe(k=>k.items)),b);const S=kt(Y(j,ke(({items:k})=>k.length>0),Ne(o,e),ke(([{items:k},E])=>k[k.length-1].originalIndex===E-1),pe(([,k,E])=>[k-1,E]),Be(an),pe(([k])=>k))),w=kt(Y(j,Kt(200),ke(({items:k,topItems:E})=>k.length>0&&k[0].originalIndex===E.length),pe(({items:k})=>k[0].index),Be())),R=kt(Y(j,ke(({items:k})=>k.length>0),pe(({items:k})=>{let E=0,C=k.length-1;for(;k[E].type==="group"&&E<C;)E++;for(;k[C].type==="group"&&C>E;)C--;return{endIndex:k[C].index,startIndex:k[E].index}}),Be(Ql)));return{endReached:S,initialItemCount:v,itemsRendered:b,listState:j,minOverscanItemCount:y,rangeChanged:R,startReached:w,topItemsIndexes:x,...h}},_e(Ut,rc,Jo,xn,mn,gn,ar,Go),{singleton:!0}),ac=Le(([{fixedFooterHeight:e,fixedHeaderHeight:r,footerHeight:n,headerHeight:s},{listState:o}])=>{const a=Te(),i=at(Y(qe(n,e,s,r,o),pe(([c,d,u,p,f])=>c+d+u+p+f.offsetBottom+f.bottom)),0);return xe(be(i),a),{totalListHeight:i,totalListHeightChanged:a}},_e(dt,xr),{singleton:!0}),Em=Le(([{viewportHeight:e},{totalListHeight:r}])=>{const n=te(!1),s=at(Y(qe(n,e,r),ke(([o])=>o),pe(([,o,a])=>Math.max(0,o-a)),Kt(0),Be()),0);return{alignToBottom:n,paddingTopAddition:s}},_e(dt,ac),{singleton:!0}),ic=Le(()=>({context:te(null)})),Nm=({itemBottom:e,itemTop:r,locationParams:{align:n,behavior:s,...o},viewportBottom:a,viewportTop:i})=>r<i?{...o,align:n??"start",...s!==void 0?{behavior:s}:{}}:e>a?{...o,align:n??"end",...s!==void 0?{behavior:s}:{}}:null,lc=Le(([{gap:e,sizes:r,totalCount:n},{fixedFooterHeight:s,fixedHeaderHeight:o,headerHeight:a,scrollingInProgress:i,scrollTop:c,viewportHeight:d},{scrollToIndex:u}])=>{const p=Te();return xe(Y(p,Ne(r,d,n,a,o,s,c),Ne(e),pe(([[f,h,m,g,x,v,b,y],j])=>{const{calculateViewLocation:S=Nm,done:w,...R}=f,k=tc(f,h,g-1),E=ln(k,h.offsetTree,j)+x+v,C=E+$t(h.sizeTree,k)[1],N=y+v,I=y+m-b,P=S({itemBottom:C,itemTop:E,locationParams:R,viewportBottom:I,viewportTop:N});return P!==null?w&&At(Y(i,ke(L=>!L),fr(We(i)?1:2)),w):w==null||w(),P}),ke(f=>f!==null)),u),{scrollIntoView:p}},_e(Ut,dt,mn,xr,or),{singleton:!0});function ri(e){return e===!1?!1:e==="smooth"?"smooth":"auto"}const Rm=(e,r)=>typeof e=="function"?ri(e(r)):r&&ri(e),Tm=Le(([{listRefresh:e,totalCount:r,fixedItemSize:n,data:s},{atBottomState:o,isAtBottom:a},{scrollToIndex:i},{scrolledToInitialItem:c},{didMount:d,propsReady:u},{log:p},{scrollingInProgress:f},{context:h},{scrollIntoView:m}])=>{const g=te(!1),x=Te();let v=null;function b(w){Ee(i,{align:"end",behavior:w,index:"LAST"})}Pe(Y(qe(Y(be(r),fr(1)),d),Ne(be(g),a,c,f),pe(([[w,R],k,E,C,N])=>{let I=R&&C,P="auto";return I&&(P=Rm(k,E||N),I=I&&P!==!1),{followOutputBehavior:P,shouldFollow:I,totalCount:w}}),ke(({shouldFollow:w})=>w)),({followOutputBehavior:w,totalCount:R})=>{v!==null&&(v(),v=null),We(n)!==void 0?requestAnimationFrame(()=>{We(p)("following output to ",{totalCount:R},Ze.DEBUG),b(w)}):v=At(e,()=>{We(p)("following output to ",{totalCount:R},Ze.DEBUG),b(w),v=null})});function y(w){const R=At(o,k=>{w&&!k.atBottom&&k.notAtBottomBecause==="SIZE_INCREASED"&&v===null&&(We(p)("scrolling to bottom due to increased size",{},Ze.DEBUG),b("auto"))});setTimeout(R,100)}Pe(Y(qe(be(g),r,u),ke(([w,,R])=>w!==!1&&R),Ot(({value:w},[,R])=>({refreshed:w===R,value:R}),{refreshed:!1,value:0}),ke(({refreshed:w})=>w),Ne(g,r)),([,w])=>{We(c)&&y(w!==!1)}),Pe(x,()=>{y(We(g)!==!1)}),Pe(qe(be(g),o),([w,R])=>{w!==!1&&!R.atBottom&&R.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&b("auto")});const j=te(null),S=Te();return xe(go(Y(be(s),pe(w=>(w==null?void 0:w.length)??0)),Y(be(r))),S),Pe(Y(qe(Y(S,fr(1)),d),Ne(be(j),c,f,h),pe(([[w,R],k,E,C,N])=>R&&E&&(k==null?void 0:k({context:N,totalCount:w,scrollingInProgress:C}))),ke(w=>!!w),Kt(0)),w=>{v!==null&&(v(),v=null),We(n)!==void 0?requestAnimationFrame(()=>{We(p)("scrolling into view",{}),Ee(m,w)}):v=At(e,()=>{We(p)("scrolling into view",{}),Ee(m,w),v=null})}),{autoscrollToBottom:x,followOutput:g,scrollIntoViewOnChange:j}},_e(Ut,gn,mn,xn,ar,or,dt,ic,lc)),Im=Le(([{data:e,firstItemIndex:r,gap:n,sizes:s},{initialTopMostItemIndex:o},{initialItemCount:a,listState:i},{didMount:c}])=>(xe(Y(c,Ne(a),ke(([,d])=>d!==0),Ne(o,s,r,n,e),pe(([[,d],u,p,f,h,m=[]])=>oc(d,u,p,f,h,m))),i),{}),_e(Ut,xn,xr,ar),{singleton:!0}),Lm=Le(([{didMount:e},{scrollTo:r},{listState:n}])=>{const s=te(0);return Pe(Y(e,Ne(s),ke(([,o])=>o!==0),pe(([,o])=>({top:o}))),o=>{At(Y(n,fr(1),ke(a=>a.items.length>1)),()=>{requestAnimationFrame(()=>{Ee(r,o)})})}),{initialScrollTop:s}},_e(ar,dt,xr),{singleton:!0}),cc=Le(([{scrollVelocity:e}])=>{const r=te(!1),n=Te(),s=te(!1);return xe(Y(e,Ne(s,r,n),ke(([o,a])=>a!==!1&&a!==void 0),pe(([o,a,i,c])=>{const{enter:d,exit:u}=a;if(i){if(u(o,c))return!1}else if(d(o,c))return!0;return i}),Be()),r),Pe(Y(qe(r,e,n),Ne(s)),([[o,a,i],c])=>{o&&c!==!1&&c!==void 0&&c.change&&c.change(a,i)}),{isSeeking:r,scrollSeekConfiguration:s,scrollSeekRangeChanged:n,scrollVelocity:e}},_e(gn),{singleton:!0}),Xo=Le(([{scrollContainerState:e,scrollTo:r}])=>{const n=Te(),s=Te(),o=Te(),a=te(!1),i=te(void 0);return xe(Y(qe(n,s),pe(([{scrollTop:c,viewportHeight:d},{offsetTop:u,listHeight:p}])=>({scrollHeight:p,scrollTop:Math.max(0,c-u),viewportHeight:d}))),e),xe(Y(r,Ne(s),pe(([c,{offsetTop:d}])=>({...c,top:c.top+d}))),o),{customScrollParent:i,useWindowScroll:a,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:s}},_e(dt)),Am=Le(([{sizeRanges:e,sizes:r},{headerHeight:n,scrollTop:s},{initialTopMostItemIndex:o},{didMount:a},{useWindowScroll:i,windowScrollContainerState:c,windowViewportRect:d}])=>{const u=Te(),p=te(void 0),f=te(null),h=te(null);return xe(c,f),xe(d,h),Pe(Y(u,Ne(r,s,i,f,h,n)),([m,g,x,v,b,y,j])=>{const S=mm(g.sizeTree);v&&b!==null&&y!==null&&(x=b.scrollTop-y.offsetTop),x-=j,m({ranges:S,scrollTop:x})}),xe(Y(p,ke(Ho),pe(Pm)),o),xe(Y(a,Ne(p),ke(([,m])=>m!==void 0),Be(),pe(([,m])=>m.ranges)),e),{getState:u,restoreStateFrom:p}},_e(Ut,dt,xn,ar,Xo));function Pm(e){return{align:"start",index:0,offset:e.scrollTop}}const $m=Le(([{topItemsIndexes:e}])=>{const r=te(0);return xe(Y(r,ke(n=>n>=0),pe(n=>Array.from({length:n}).map((s,o)=>o))),e),{topItemCount:r}},_e(xr));function dc(e){let r=!1,n;return(()=>(r||(r=!0,n=e()),n))}const Mm=dc(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Dm=Le(([{deviation:e,scrollBy:r,scrollingInProgress:n,scrollTop:s},{isAtBottom:o,isScrolling:a,lastJumpDueToItemResize:i,scrollDirection:c},{listState:d},{beforeUnshiftWith:u,gap:p,shiftWithOffset:f,sizes:h},{log:m},{recalcInProgress:g}])=>{const x=kt(Y(d,Ne(i),Ot(([,b,y,j],[{bottom:S,items:w,offsetBottom:R,totalCount:k},E])=>{const C=S+R;let N=0;return y===k&&b.length>0&&w.length>0&&(w[0].originalIndex===0&&b[0].originalIndex===0||(N=C-j,N!==0&&(N+=E))),[N,w,k,C]},[0,[],0,0]),ke(([b])=>b!==0),Ne(s,c,n,o,m,g),ke(([,b,y,j,,,S])=>!S&&!j&&b!==0&&y===cn),pe(([[b],,,,,y])=>(y("Upward scrolling compensation",{amount:b},Ze.DEBUG),b))));function v(b){b>0?(Ee(r,{behavior:"auto",top:-b}),Ee(e,0)):(Ee(e,0),Ee(r,{behavior:"auto",top:-b}))}return Pe(Y(x,Ne(e,a)),([b,y,j])=>{j&&Mm()?Ee(e,y-b):v(-b)}),Pe(Y(qe(at(a,!1),e,g),ke(([b,y,j])=>!b&&!j&&y!==0),pe(([b,y])=>y),Kt(1)),v),xe(Y(f,pe(b=>({top:-b}))),r),Pe(Y(u,Ne(h,p),pe(([b,{groupIndices:y,lastSize:j,sizeTree:S},w])=>{function R(I){return I*(j+w)}if(y.length===0)return R(b);let k=0;const E=on(S,0);let C=0,N=0;for(;C<b;){C++,k+=E;let I=y.length===N+1?1/0:y[N+1]-y[N]-1;C+I>b&&(k-=E,I=b-C+1),C+=I,k+=R(I),N++}return k})),b=>{Ee(e,b),requestAnimationFrame(()=>{Ee(r,{top:b}),requestAnimationFrame(()=>{Ee(e,0),Ee(g,!1)})})}),{deviation:e}},_e(dt,gn,xr,Ut,or,Go)),Fm=Le(([e,r,n,s,o,a,i,c,d,u,p])=>({...e,...r,...n,...s,...o,...a,...i,...c,...d,...u,...p}),_e(Jo,Im,ar,cc,ac,Lm,Em,Xo,lc,or,ic)),uc=Le(([{data:e,defaultItemSize:r,firstItemIndex:n,fixedItemSize:s,fixedGroupSize:o,gap:a,groupIndices:i,heightEstimates:c,itemSize:d,sizeRanges:u,sizes:p,statefulTotalCount:f,totalCount:h,trackItemSizes:m},{initialItemFinalLocationReached:g,initialTopMostItemIndex:x,scrolledToInitialItem:v},b,y,j,S,{scrollToIndex:w},R,{topItemCount:k},{groupCounts:E},C])=>{const{listState:N,minOverscanItemCount:I,topItemsIndexes:P,rangeChanged:L,...B}=S;return xe(L,C.scrollSeekRangeChanged),xe(Y(C.windowViewportRect,pe(T=>T.visibleHeight)),b.viewportHeight),{data:e,defaultItemHeight:r,firstItemIndex:n,fixedItemHeight:s,fixedGroupHeight:o,gap:a,groupCounts:E,heightEstimates:c,initialItemFinalLocationReached:g,initialTopMostItemIndex:x,scrolledToInitialItem:v,sizeRanges:u,topItemCount:k,topItemsIndexes:P,totalCount:h,...j,groupIndices:i,itemSize:d,listState:N,minOverscanItemCount:I,scrollToIndex:w,statefulTotalCount:f,trackItemSizes:m,rangeChanged:L,...B,...C,...b,sizes:p,...y}},_e(Ut,xn,dt,Am,Tm,xr,mn,Dm,$m,rc,Fm));function zm(e,r){const n={},s={};let o=0;const a=e.length;for(;o<a;)s[e[o]]=1,o+=1;for(const i in r)Object.hasOwn(s,i)||(n[i]=r[i]);return n}const Tn=typeof document<"u"?me.useLayoutEffect:me.useEffect;function pc(e,r,n){const s=Object.keys(r.required||{}),o=Object.keys(r.optional||{}),a=Object.keys(r.methods||{}),i=Object.keys(r.events||{}),c=me.createContext({});function d(v,b){v.propsReady!==void 0&&Ee(v.propsReady,!1);for(const y of s){const j=v[r.required[y]];Ee(j,b[y])}for(const y of o)if(y in b){const j=v[r.optional[y]];Ee(j,b[y])}v.propsReady!==void 0&&Ee(v.propsReady,!0)}function u(v){return a.reduce((b,y)=>(b[y]=j=>{const S=v[r.methods[y]];Ee(S,j)},b),{})}function p(v){return i.reduce((b,y)=>(b[y]=em(v[r.events[y]]),b),{})}const f=me.forwardRef(function(v,b){const{children:y,...j}=v,[S]=me.useState(()=>is(rm(e),k=>{d(k,j)})),[w]=me.useState(Ga(p,S));Tn(()=>{for(const k of i)k in j&&Pe(w[k],j[k]);return()=>{Object.values(w).map(Uo)}},[j,w,S]),Tn(()=>{d(S,j)}),me.useImperativeHandle(b,Va(u(S)));const R=n;return t.jsx(c.Provider,{value:S,children:n!==void 0?t.jsx(R,{...zm([...s,...o,...i],j),children:y}):y})}),h=v=>{const b=me.useContext(c);return me.useCallback(y=>{Ee(b[v],y)},[b,v])},m=v=>{const b=me.useContext(c)[v],y=me.useCallback(j=>Pe(b,j),[b]);return me.useSyncExternalStore(y,()=>We(b),()=>We(b))},g=v=>{const b=me.useContext(c)[v],[y,j]=me.useState(Ga(We,b));return Tn(()=>Pe(b,S=>{S!==y&&j(Va(S))}),[b,y]),y},x=parseInt(me.version)>=18?m:g;return{Component:f,useEmitter:(v,b)=>{const y=me.useContext(c)[v];Tn(()=>Pe(y,b),[b,y])},useEmitterValue:x,usePublisher:h}}const fc=me.createContext(void 0),hc=me.createContext(void 0),Cs="-webkit-sticky",ni="sticky",Qo=dc(()=>{if(typeof document>"u")return ni;const e=document.createElement("div");return e.style.position=Cs,e.style.position===Cs?Cs:ni}),mc=typeof document<"u"?me.useLayoutEffect:me.useEffect;function Es(e){return"self"in e}function Bm(e){return"body"in e}function xc(e,r,n,s=Dr,o,a){const i=me.useRef(null),c=me.useRef(null),d=me.useRef(null),u=me.useCallback(h=>{let m,g,x;const v=h.target;if(Bm(v)||Es(v)){const y=Es(v)?v:v.defaultView;x=a===!0?y.scrollX:y.scrollY,m=a===!0?y.document.documentElement.scrollWidth:y.document.documentElement.scrollHeight,g=a===!0?y.innerWidth:y.innerHeight}else x=a===!0?v.scrollLeft:v.scrollTop,m=a===!0?v.scrollWidth:v.scrollHeight,g=a===!0?v.offsetWidth:v.offsetHeight;const b=()=>{e({scrollHeight:m,scrollTop:Math.max(x,0),viewportHeight:g})};h.suppressFlushSync===!0?b():Lp.flushSync(b),c.current!==null&&(x===c.current||x<=0||x===m-g)&&(c.current=null,r(!0),d.current&&(clearTimeout(d.current),d.current=null))},[e,r,a]);me.useEffect(()=>{const h=o||i.current;return s(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{s(null),h.removeEventListener("scroll",u)}},[i,u,n,s,o]);function p(h){const m=i.current;if(!m||(a===!0?"offsetWidth"in m&&m.offsetWidth===0:"offsetHeight"in m&&m.offsetHeight===0))return;const g=h.behavior==="smooth";let x,v,b;Es(m)?(v=Math.max(rr(m.document.documentElement,a===!0?"width":"height"),a===!0?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight),x=a===!0?m.innerWidth:m.innerHeight,b=a===!0?window.scrollX:window.scrollY):(v=m[a===!0?"scrollWidth":"scrollHeight"],x=rr(m,a===!0?"width":"height"),b=m[a===!0?"scrollLeft":"scrollTop"]);const y=v-x;if(h.top=Math.ceil(Math.max(Math.min(y,h.top),0)),sc(x,v)||h.top===b){e({scrollHeight:v,scrollTop:b,viewportHeight:x}),g&&r(!0);return}g?(c.current=h.top,d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,c.current=null,r(!0)},1e3)):c.current=null,a===!0&&(h={...h.behavior!==void 0?{behavior:h.behavior}:{},left:h.top}),m.scrollTo(h)}function f(h){a===!0&&(h={...h.behavior!==void 0?{behavior:h.behavior}:{},...h.top!==void 0?{left:h.top}:{}}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:p}}function Zo(e){return e}const _m=Le(()=>{const e=te(c=>`Item ${c}`),r=te(c=>`Group ${c}`),n=te({}),s=te(Zo),o=te("div"),a=te(Dr),i=(c,d=null)=>at(Y(n,pe(u=>u[c]),Be()),d);return{components:n,computeItemKey:s,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:r,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),Om=Le(([e,r])=>({...e,...r}),_e(uc,_m)),Wm=({height:e})=>t.jsx("div",{style:{height:e}}),Hm={overflowAnchor:"none",position:Qo(),zIndex:1},gc={overflowAnchor:"none"},Um={...gc,display:"inline-block",height:"100%"},si=me.memo(function({showTopList:e=!1}){const r=Se("listState"),n=Et("sizeRanges"),s=Se("useWindowScroll"),o=Se("customScrollParent"),a=Et("windowScrollContainerState"),i=Et("scrollContainerState"),c=o||s?a:i,d=Se("itemContent"),u=Se("context"),p=Se("groupContent"),f=Se("trackItemSizes"),h=Se("itemSize"),m=Se("log"),g=Et("gap"),x=Se("horizontalDirection"),{callbackRef:v}=om(n,h,f,e?Dr:c,m,g,o,x,Se("skipAnimationFrameInResizeObserver")),[b,y]=me.useState(0);ea("deviation",B=>{b!==B&&y(B)});const j=Se("EmptyPlaceholder"),S=Se("ScrollSeekPlaceholder")??Wm,w=Se("ListComponent"),R=Se("ItemComponent"),k=Se("GroupComponent"),E=Se("computeItemKey"),C=Se("isSeeking"),N=Se("groupIndices").length>0,I=Se("alignToBottom"),P=Se("initialItemFinalLocationReached"),L=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:b!==0?b:I?"auto":0,paddingLeft:r.offsetTop,paddingRight:r.offsetBottom,whiteSpace:"nowrap"}:{marginTop:b!==0?b:I?"auto":0,paddingBottom:r.offsetBottom,paddingTop:r.offsetTop},...P?{}:{visibility:"hidden"}};return!e&&r.totalCount===0&&j!==null&&j!==void 0?t.jsx(j,{...ot(j,u)}):t.jsx(w,{...ot(w,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:v,style:L,children:(e?r.topItems:r.items).map(B=>{const T=B.originalIndex,$=E(T+r.firstItemIndex,B.data,u);return C?l.createElement(S,{...ot(S,u),height:B.size,index:B.index,key:$,type:B.type||"item",...B.type==="group"?{}:{groupIndex:B.groupIndex}}):B.type==="group"?l.createElement(k,{...ot(k,u),"data-index":T,"data-item-index":B.index,"data-known-size":B.size,key:$,style:Hm},p(B.index,u)):l.createElement(R,{...ot(R,u),...qm(R,B.data),"data-index":T,"data-item-group-index":B.groupIndex,"data-item-index":B.index,"data-known-size":B.size,key:$,style:x?Um:gc},N?d(B.index,B.groupIndex,B.data,u):d(B.index,B.data,u))})})}),Vm={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Gm={outline:"none",overflowX:"auto",position:"relative"},cs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:void 0}),Km={position:Qo(),top:0,width:"100%",zIndex:1};function ot(e,r){if(typeof e!="string")return{context:r}}function qm(e,r){return{item:typeof e=="string"?void 0:r}}const Ym=me.memo(function(){const e=Se("HeaderComponent"),r=Et("headerHeight"),n=Se("HeaderFooterTag"),s=mr(me.useMemo(()=>a=>{r(rr(a,"height"))},[r]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e!=null?t.jsx(n,{ref:s,children:t.jsx(e,{...ot(e,o)})}):null}),Jm=me.memo(function(){const e=Se("FooterComponent"),r=Et("footerHeight"),n=Se("HeaderFooterTag"),s=mr(me.useMemo(()=>a=>{r(rr(a,"height"))},[r]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e!=null?t.jsx(n,{ref:s,children:t.jsx(e,{...ot(e,o)})}):null});function vc({useEmitter:e,useEmitterValue:r,usePublisher:n}){return me.memo(function({children:s,style:o,context:a,...i}){const c=n("scrollContainerState"),d=r("ScrollerComponent"),u=n("smoothScrollTargetReached"),p=r("scrollerRef"),f=r("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:m,scrollToCallback:g}=xc(c,u,d,p,void 0,f);return e("scrollTo",g),e("scrollBy",h),t.jsx(d,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:m,style:{...f?Gm:Vm,...o},tabIndex:0,...i,...ot(d,a),children:s})})}function yc({useEmitter:e,useEmitterValue:r,usePublisher:n}){return me.memo(function({children:s,style:o,context:a,...i}){const c=n("windowScrollContainerState"),d=r("ScrollerComponent"),u=n("smoothScrollTargetReached"),p=r("totalListHeight"),f=r("deviation"),h=r("customScrollParent"),m=me.useRef(null),g=r("scrollerRef"),{scrollByCallback:x,scrollerRef:v,scrollToCallback:b}=xc(c,u,d,g,h);return mc(()=>{var y;return v.current=h||((y=m.current)==null?void 0:y.ownerDocument.defaultView),()=>{v.current=null}},[v,h]),e("windowScrollTo",b),e("scrollBy",x),t.jsx(d,{ref:m,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...p!==0?{height:p+f}:void 0},...i,...ot(d,a),children:s})})}const Xm=({children:e})=>{const r=me.useContext(fc),n=Et("viewportHeight"),s=Et("fixedItemHeight"),o=Se("alignToBottom"),a=Se("horizontalDirection"),i=me.useMemo(()=>Ul(n,d=>rr(d,a?"width":"height")),[n,a]),c=mr(i,!0,Se("skipAnimationFrameInResizeObserver"));return me.useEffect(()=>{r&&(n(r.viewportHeight),s(r.itemHeight))},[r,n,s]),t.jsx("div",{"data-viewport-type":"element",ref:c,style:cs(o),children:e})},Qm=({children:e})=>{const r=me.useContext(fc),n=Et("windowViewportRect"),s=Et("fixedItemHeight"),o=Se("customScrollParent"),a=Gl(n,o,Se("skipAnimationFrameInResizeObserver")),i=Se("alignToBottom");return me.useEffect(()=>{r&&(s(r.itemHeight),n({listHeight:0,offsetTop:0,visibleHeight:r.viewportHeight,visibleWidth:100}))},[r,n,s]),t.jsx("div",{"data-viewport-type":"window",ref:a,style:cs(i),children:e})},Zm=({children:e})=>{const r=Se("TopItemListComponent")??"div",n=Se("headerHeight"),s={...Km,marginTop:`${n}px`},o=Se("context");return t.jsx(r,{style:s,...ot(r,o),children:e})},ex=me.memo(function(e){const r=Se("useWindowScroll"),n=Se("topItemsIndexes").length>0,s=Se("customScrollParent"),o=Se("context");return t.jsxs(s||r?nx:rx,{...e,context:o,children:[n&&t.jsx(Zm,{children:t.jsx(si,{showTopList:!0})}),t.jsxs(s||r?Qm:Xm,{children:[t.jsx(Ym,{}),t.jsx(si,{}),t.jsx(Jm,{})]})]})}),{Component:tx,useEmitter:ea,useEmitterValue:Se,usePublisher:Et}=pc(Om,{optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",minOverscanItemCount:"minOverscanItemCount",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedGroupHeight:"fixedGroupHeight",fixedItemHeight:"fixedItemHeight",heightEstimates:"heightEstimates",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},ex),rx=vc({useEmitter:ea,useEmitterValue:Se,usePublisher:Et}),nx=yc({useEmitter:ea,useEmitterValue:Se,usePublisher:Et}),sx=tx,ox=Le(()=>{const e=te(u=>t.jsxs("td",{children:["Item $",u]})),r=te(null),n=te(u=>t.jsxs("td",{colSpan:1e3,children:["Group ",u]})),s=te(null),o=te(null),a=te({}),i=te(Zo),c=te(Dr),d=(u,p=null)=>at(Y(a,pe(f=>f[u]),Be()),p);return{components:a,computeItemKey:i,context:r,EmptyPlaceholder:d("EmptyPlaceholder"),FillerRow:d("FillerRow"),fixedFooterContent:o,fixedHeaderContent:s,itemContent:e,groupContent:n,ScrollerComponent:d("Scroller","div"),scrollerRef:c,ScrollSeekPlaceholder:d("ScrollSeekPlaceholder"),TableBodyComponent:d("TableBody","tbody"),TableComponent:d("Table","table"),TableFooterComponent:d("TableFoot","tfoot"),TableHeadComponent:d("TableHead","thead"),TableRowComponent:d("TableRow","tr"),GroupComponent:d("Group","tr")}});_e(uc,ox);Qo();const oi={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},ax={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:ai,floor:Yn,max:Zr,min:Ns,round:ii}=Math;function li(e,r,n){return Array.from({length:r-e+1}).map((s,o)=>({data:n===null?null:n[o+e],index:o+e}))}function ix(e){return{...ax,items:e}}function In(e,r){return e!==void 0&&e.width===r.width&&e.height===r.height}function lx(e,r){return e!==void 0&&e.column===r.column&&e.row===r.row}const cx=Le(([{increaseViewportBy:e,listBoundary:r,overscan:n,visibleRange:s},{footerHeight:o,headerHeight:a,scrollBy:i,scrollContainerState:c,scrollTo:d,scrollTop:u,smoothScrollTargetReached:p,viewportHeight:f},h,m,{didMount:g,propsReady:x},{customScrollParent:v,useWindowScroll:b,windowScrollContainerState:y,windowScrollTo:j,windowViewportRect:S},w])=>{const R=te(0),k=te(0),E=te(oi),C=te({height:0,width:0}),N=te({height:0,width:0}),I=Te(),P=Te(),L=te(0),B=te(null),T=te({column:0,row:0}),$=Te(),M=Te(),F=te(!1),W=te(0),le=te(!0),U=te(!1),H=te(!1);Pe(Y(g,Ne(W),ke(([A,O])=>O!==0)),()=>{Ee(le,!1)}),Pe(Y(qe(g,le,N,C,W,U),ke(([A,O,V,re,,ce])=>A&&!O&&V.height!==0&&re.height!==0&&!ce)),([,,,,A])=>{Ee(U,!0),qo(1,()=>{Ee(I,A)}),At(Y(u),()=>{Ee(r,[0,0]),Ee(le,!0)})}),xe(Y(M,ke(A=>A!=null&&A.scrollTop>0),zt(0)),k),Pe(Y(g,Ne(M),ke(([,A])=>A!=null)),([,A])=>{A&&(Ee(C,A.viewport),Ee(N,A.item),Ee(T,A.gap),A.scrollTop>0&&(Ee(F,!0),At(Y(u,fr(1)),O=>{Ee(F,!1)}),Ee(d,{top:A.scrollTop})))}),xe(Y(C,pe(({height:A})=>A)),f),xe(Y(qe(be(C,In),be(N,In),be(T,(A,O)=>A!==void 0&&A.column===O.column&&A.row===O.row),be(u)),pe(([A,O,V,re])=>({gap:V,item:O,scrollTop:re,viewport:A}))),$),xe(Y(qe(be(R),s,be(T,lx),be(N,In),be(C,In),be(B),be(k),be(F),be(le),be(W)),ke(([,,,,,,,A])=>!A),pe(([A,[O,V],re,ce,ne,ve,ge,,se,fe])=>{const{column:z,row:q}=re,{height:Z,width:J}=ce,{width:ue}=ne;if(ge===0&&(A===0||ue===0))return oi;if(J===0){const je=Yo(fe,A),$e=je+Math.max(ge-1,0);return ix(li(je,$e,ve))}const de=bc(ue,J,z);let we,Ie;se?O===0&&V===0&&ge>0?(we=0,Ie=ge-1):(we=de*Yn((O+q)/(Z+q)),Ie=de*ai((V+q)/(Z+q))-1,Ie=Ns(A-1,Zr(Ie,de-1)),we=Ns(Ie,Zr(0,we))):(we=0,Ie=-1);const Fe=li(we,Ie,ve),{bottom:Ke,top:Ye}=ci(ne,re,ce,Fe),Q=ai(A/de),Re=Q*Z+(Q-1)*q-Ke;return{bottom:Ke,itemHeight:Z,items:Fe,itemWidth:J,offsetBottom:Re,offsetTop:Ye,top:Ye}})),E),xe(Y(B,ke(A=>A!==null),pe(A=>A.length)),R),xe(Y(qe(C,N,E,T),ke(([A,O,{items:V}])=>V.length>0&&O.height!==0&&A.height!==0),pe(([A,O,{items:V},re])=>{const{bottom:ce,top:ne}=ci(A,re,O,V);return[ne,ce]}),Be(an)),r);const ee=te(!1);xe(Y(u,Ne(ee),pe(([A,O])=>O||A!==0)),ee);const K=kt(Y(qe(E,R),ke(([{items:A}])=>A.length>0),Ne(ee),ke(([[A,O],V])=>{const re=A.items[A.items.length-1].index===O-1;return(V||A.bottom>0&&A.itemHeight>0&&A.offsetBottom===0&&A.items.length===O)&&re}),pe(([[,A]])=>A-1),Be())),X=kt(Y(be(E),ke(({items:A})=>A.length>0&&A[0].index===0),zt(0),Be())),G=kt(Y(be(E),Ne(F),ke(([{items:A},O])=>A.length>0&&!O),pe(([{items:A}])=>({endIndex:A[A.length-1].index,startIndex:A[0].index})),Be(Ql),Kt(0)));xe(G,m.scrollSeekRangeChanged),xe(Y(I,Ne(C,N,R,T),pe(([A,O,V,re,ce])=>{const ne=nc(A),{align:ve,behavior:ge,offset:se}=ne;let fe=ne.index;fe==="LAST"&&(fe=re-1),fe=Zr(0,fe,Ns(re-1,fe));let z=jo(O,ce,V,fe);return ve==="end"?z=ii(z-O.height+V.height):ve==="center"&&(z=ii(z-O.height/2+V.height/2)),se!==void 0&&se!==0&&(z+=se),{behavior:ge,top:z}})),d);const he=at(Y(E,pe(A=>A.offsetBottom+A.bottom)),0);return xe(Y(S,pe(A=>({height:A.visibleHeight,width:A.visibleWidth}))),C),{customScrollParent:v,data:B,deviation:L,footerHeight:o,gap:T,headerHeight:a,increaseViewportBy:e,initialItemCount:k,itemDimensions:N,overscan:n,restoreStateFrom:M,scrollBy:i,scrollContainerState:c,scrollHeight:P,scrollTo:d,scrollToIndex:I,scrollTop:u,smoothScrollTargetReached:p,totalCount:R,useWindowScroll:b,viewportDimensions:C,windowScrollContainerState:y,windowScrollTo:j,windowViewportRect:S,...m,gridState:E,horizontalDirection:H,initialTopMostItemIndex:W,totalListHeight:he,...h,endReached:K,propsReady:x,rangeChanged:G,startReached:X,stateChanged:$,stateRestoreInProgress:F,...w}},_e(Jo,dt,gn,cc,ar,Xo,or));function bc(e,r,n){return Zr(1,Yn((e+n)/(Yn(r)+n)))}function ci(e,r,n,s){const{height:o}=n;if(o===void 0||s.length===0)return{bottom:0,top:0};const a=jo(e,r,n,s[0].index);return{bottom:jo(e,r,n,s[s.length-1].index)+o,top:a}}function jo(e,r,n,s){const o=bc(e.width,n.width,r.column),a=Yn(s/o),i=a*n.height+Zr(0,a-1)*r.row;return i>0?i+r.row:i}const dx=Le(()=>{const e=te(f=>`Item ${f}`),r=te({}),n=te(null),s=te("virtuoso-grid-item"),o=te("virtuoso-grid-list"),a=te(Zo),i=te("div"),c=te(Dr),d=(f,h=null)=>at(Y(r,pe(m=>m[f]),Be()),h),u=te(!1),p=te(!1);return xe(be(p),u),{components:r,computeItemKey:a,context:n,FooterComponent:d("Footer"),HeaderComponent:d("Header"),headerFooterTag:i,itemClassName:s,ItemComponent:d("Item","div"),itemContent:e,listClassName:o,ListComponent:d("List","div"),readyStateChanged:u,reportReadyState:p,ScrollerComponent:d("Scroller","div"),scrollerRef:c,ScrollSeekPlaceholder:d("ScrollSeekPlaceholder","div")}}),ux=Le(([e,r])=>({...e,...r}),_e(cx,dx)),px=me.memo(function(){const e=Oe("gridState"),r=Oe("listClassName"),n=Oe("itemClassName"),s=Oe("itemContent"),o=Oe("computeItemKey"),a=Oe("isSeeking"),i=Nt("scrollHeight"),c=Oe("ItemComponent"),d=Oe("ListComponent"),u=Oe("ScrollSeekPlaceholder"),p=Oe("context"),f=Nt("itemDimensions"),h=Nt("gap"),m=Oe("log"),g=Oe("stateRestoreInProgress"),x=Nt("reportReadyState"),v=mr(me.useMemo(()=>b=>{const y=b.parentElement.parentElement.scrollHeight;i(y);const j=b.firstChild;if(j!==null){const{height:S,width:w}=j.getBoundingClientRect();f({height:S,width:w})}h({column:di("column-gap",getComputedStyle(b).columnGap,m),row:di("row-gap",getComputedStyle(b).rowGap,m)})},[i,f,h,m]),!0,!1);return mc(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),g?null:t.jsx(d,{className:r,ref:v,...ot(d,p),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(b=>{const y=o(b.index,b.data,p);return a?t.jsx(u,{...ot(u,p),height:e.itemHeight,index:b.index,width:e.itemWidth},y):l.createElement(c,{...ot(c,p),className:n,"data-index":b.index,key:y},s(b.index,b.data,p))})})}),fx=me.memo(function(){const e=Oe("HeaderComponent"),r=Nt("headerHeight"),n=Oe("headerFooterTag"),s=mr(me.useMemo(()=>a=>{r(rr(a,"height"))},[r]),!0,!1),o=Oe("context");return e!=null?t.jsx(n,{ref:s,children:t.jsx(e,{...ot(e,o)})}):null}),hx=me.memo(function(){const e=Oe("FooterComponent"),r=Nt("footerHeight"),n=Oe("headerFooterTag"),s=mr(me.useMemo(()=>a=>{r(rr(a,"height"))},[r]),!0,!1),o=Oe("context");return e!=null?t.jsx(n,{ref:s,children:t.jsx(e,{...ot(e,o)})}):null}),mx=({children:e})=>{const r=me.useContext(hc),n=Nt("itemDimensions"),s=Nt("viewportDimensions"),o=mr(me.useMemo(()=>a=>{s(a.getBoundingClientRect())},[s]),!0,!1);return me.useEffect(()=>{r&&(s({height:r.viewportHeight,width:r.viewportWidth}),n({height:r.itemHeight,width:r.itemWidth}))},[r,s,n]),t.jsx("div",{ref:o,style:cs(!1),children:e})},xx=({children:e})=>{const r=me.useContext(hc),n=Nt("windowViewportRect"),s=Nt("itemDimensions"),o=Oe("customScrollParent"),a=Gl(n,o,!1);return me.useEffect(()=>{r&&(s({height:r.itemHeight,width:r.itemWidth}),n({listHeight:0,offsetTop:0,visibleHeight:r.viewportHeight,visibleWidth:r.viewportWidth}))},[r,n,s]),t.jsx("div",{ref:a,style:cs(!1),children:e})},gx=me.memo(function({...e}){const r=Oe("useWindowScroll"),n=Oe("customScrollParent"),s=n||r?yx:vx,o=n||r?xx:mx,a=Oe("context");return t.jsx(s,{...e,...ot(s,a),children:t.jsxs(o,{children:[t.jsx(fx,{}),t.jsx(px,{}),t.jsx(hx,{})]})})}),{useEmitter:kc,useEmitterValue:Oe,usePublisher:Nt}=pc(ux,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},gx),vx=vc({useEmitter:kc,useEmitterValue:Oe,usePublisher:Nt}),yx=yc({useEmitter:kc,useEmitterValue:Oe,usePublisher:Nt});function di(e,r,n){return r!=="normal"&&(r==null?void 0:r.endsWith("px"))!==!0&&n(`${e} was not resolved to pixel value correctly`,r,Ze.WARN),r==="normal"?0:parseInt(r??"0",10)}const bx={source:"vskill-sidebar-own-collapsed",installed:"vskill-sidebar-installed-collapsed"},jc={source:"Own",installed:"Installed"};function kx(e){try{const r=localStorage.getItem(e);if(r!=null)return r==="true"}catch{}try{if(typeof sessionStorage<"u"){const r=sessionStorage.getItem(e);if(r!=null)return r==="true"}}catch{}return!1}function jx(e,r){const n=r?"true":"false";try{localStorage.setItem(e,n)}catch{}try{typeof sessionStorage<"u"&&sessionStorage.setItem(e,n)}catch{}}function ui({origin:e,count:r,filteredCount:n,updateCount:s,children:o}){const a=bx[e],[i,c]=l.useState(()=>kx(a)),d=l.useCallback(()=>{c(h=>{const m=!h;return jx(a,m),m})},[a]),u=jc[e],p=`sidebar-section-${e}-header`,f=`sidebar-section-${e}-group`;return t.jsxs("section",{"aria-labelledby":p,style:{display:"flex",flexDirection:"column",minHeight:0},children:[t.jsxs("button",{id:p,type:"button","data-testid":"sidebar-section-header","aria-expanded":!i,"aria-controls":f,onClick:d,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 12px 6px 14px",background:"transparent",border:"none",cursor:"pointer",color:"var(--text-primary)",fontFamily:"var(--font-sans)",textAlign:"left"},children:[t.jsx(Sx,{collapsed:i}),t.jsx("h2",{"aria-level":2,style:{fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:"var(--text-primary)",margin:0},children:u}),t.jsx("span",{style:{fontSize:10,color:"var(--text-secondary)",fontVariantNumeric:"tabular-nums",fontFamily:"var(--font-mono)"},children:n!=null&&n!==r?`(${n} of ${r})`:`(${r})`}),s!=null&&s>0&&t.jsx(wx,{origin:e,updateCount:s})]}),!i&&t.jsx("div",{id:f,role:"group","aria-labelledby":p,style:{display:"flex",flexDirection:"column",minHeight:0},children:o})]})}function wx({origin:e,updateCount:r}){const[n,s]=l.useState(!1),o=jc[e].toLowerCase(),a=`${r} updates available in ${o} section, view all`;return t.jsxs("span",{role:"link",tabIndex:0,"data-testid":"sidebar-section-update-chip","aria-label":a,onClick:i=>{i.stopPropagation(),window.location.hash="#/updates"},onKeyDown:i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),i.stopPropagation(),window.location.hash="#/updates")},onFocus:()=>s(!0),onBlur:()=>s(!1),style:{display:"inline-flex",alignItems:"center",gap:2,fontSize:10,color:"var(--color-own)",fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums",cursor:"pointer",padding:"0 4px",borderRadius:3,outline:n?"2px solid var(--border-focus)":"none",outlineOffset:2},children:[r," updates",t.jsx("span",{"aria-hidden":"true",style:{fontSize:9,marginLeft:2},children:"▾"})]})}function Sx({collapsed:e}){return t.jsx("svg",{"aria-hidden":"true",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-secondary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:e?"rotate(0deg)":"rotate(90deg)",transition:"transform var(--duration-fast, 120ms) var(--ease-standard, ease)",flexShrink:0},children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})}function ta(e,r){const n=r.trim().toLowerCase();return n?e.skill.toLowerCase().includes(n)||e.plugin.toLowerCase().includes(n)||e.dir.toLowerCase().includes(n):!0}function Cx({value:e,onChange:r,placeholder:n="Filter skills…",validationPattern:s,validationMessage:o="Invalid filter expression"}){const a=l.useRef(null),i=l.useId(),c=!!s&&e.trim()!==""&&!s.test(e);return l.useEffect(()=>{function d(u){var h;if(u.key!=="/")return;const p=u.target;if(!p)return;const f=p.tagName;f==="INPUT"||f==="TEXTAREA"||p.isContentEditable||(u.preventDefault(),(h=a.current)==null||h.focus())}return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[]),t.jsxs("div",{role:"search",style:{display:"flex",alignItems:"center",gap:6,padding:"6px 12px",borderBottom:"1px solid var(--border-default)"},children:[t.jsxs("svg",{"aria-hidden":"true",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-secondary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0},children:[t.jsx("circle",{cx:"11",cy:"11",r:"8"}),t.jsx("path",{d:"M21 21l-4.35-4.35"})]}),t.jsx("input",{ref:a,type:"search","aria-label":"Filter skills","aria-invalid":c?!0:void 0,"aria-describedby":c?i:void 0,value:e,placeholder:n,onChange:d=>r(d.currentTarget.value),onKeyDown:d=>{d.key==="Escape"&&(r(""),d.currentTarget.blur())},style:{flex:1,minWidth:0,border:"none",outline:"none",background:"transparent",color:"var(--text-primary)",fontFamily:"var(--font-sans)",fontSize:12,padding:"2px 0"}}),c&&t.jsx("span",{id:i,role:"alert","aria-live":"polite",style:{fontFamily:"var(--font-sans)",fontSize:10,color:"var(--text-error, #B42318)",marginLeft:4,whiteSpace:"nowrap"},children:o}),t.jsx("kbd",{"aria-hidden":"true",style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-secondary)",border:"1px solid var(--border-default)",padding:"1px 5px",borderRadius:3,display:e?"none":"inline-block"},children:"/"})]})}function Ex({target:e}){const r=typeof e=="string"&&e.length>0,n=r?`symlinked → ${e}`:"symlinked — cycle detected or target unresolved",s=r?`symlinked from ${e}`:"symlinked, target unresolved";return t.jsx("span",{"data-testid":"symlink-chip",role:"img","aria-label":s,title:n,tabIndex:0,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,borderRadius:3,color:"var(--text-secondary)",flexShrink:0},children:t.jsxs("svg",{"data-testid":"symlink-glyph",width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),t.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})})}function Nx({skill:e}){if(!e.updateAvailable)return null;const r=e.currentVersion??"",n=e.latestVersion,s=n?`Update available: ${r} → ${n}`.trim():"Update available";return t.jsx("span",{"data-testid":"skill-row-update-glyph",title:s,"aria-label":"Update available",style:{color:"var(--color-own)",display:"inline-flex",flexShrink:0},children:t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M12 19V5"}),t.jsx("path",{d:"M5 12l7-7 7 7"})]})})}function Rx({skillId:e,trackedForUpdates:r}){let n=null;try{n=l.useContext(Pl)}catch{n=null}const s=n==null?void 0:n.updatesById.get(e);if(s){const o=`Update available → ${s.version}${s.diffSummary?` — ${s.diffSummary}`:""}`;return t.jsx("span",{"data-testid":"update-chip-update-dot","aria-label":`Update available: ${s.version}`,title:o,style:{display:"inline-block",width:8,height:8,borderRadius:999,background:"var(--color-accent, #2563eb)",flexShrink:0}})}return r?null:t.jsx("span",{"data-testid":"update-chip-untracked-dot","aria-label":"Not tracked for updates",title:"Not tracked — run `vskill outdated` manually",style:{display:"inline-block",width:6,height:6,borderRadius:999,background:"var(--text-muted, var(--text-secondary))",opacity:.55,flexShrink:0}})}function Tx(e,r,n){if(!(!e||e==="frontmatter"))return e==="plugin"?`Inherited from ${n&&n.trim()!==""?n:"plugin"} plugin v${r}`:e==="registry"?"Inherited from registry":"No version declared"}function vn(e){const{version:r,showPrefix:n=!0,size:s="md",source:o,pluginName:a}=e,i=typeof r=="string"?r.trim():"",c=i===""||i==="0.0.0"?"1.0.0":i,d=n&&!c.startsWith("v")?`v${c}`:c,u=s==="sm"?10:12,p=s==="sm"?1:2,f=s==="sm"?5:8,h=o==="registry"||o==="plugin",m=Tx(o,c,a),g=e.title??m,x={display:"inline-flex",alignItems:"center",padding:`${p}px ${f}px`,border:"1px solid var(--border, var(--border-default))",borderRadius:4,background:"var(--bg-subtle, var(--surface-1, transparent))",color:"var(--text-secondary)",fontFamily:"var(--font-mono, var(--font-geist-mono))",fontSize:u,fontVariantNumeric:"tabular-nums",lineHeight:1.2,whiteSpace:"nowrap",flexShrink:0};return h&&(x.fontStyle="italic"),t.jsx("span",{"data-testid":e["data-testid"]??"version-badge","data-version":c,"data-version-source":o,title:g,style:x,children:d})}function Ix({size:e}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:[t.jsx("rect",{x:"2.75",y:"7",width:"10.5",height:"6.75",rx:"1.25",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1.25"}),t.jsx("path",{d:"M5 7V5.25C5 3.59 6.34 2.25 8 2.25C9.66 2.25 11 3.59 11 5.25V7",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",fill:"none"}),t.jsx("circle",{cx:"8",cy:"10.25",r:"0.9",fill:"currentColor"})]})}function Lx({repoFullName:e,variant:r="row"}){const n=e?`From private repo: ${e}`:"From a private repo",s={display:"inline-flex",alignItems:"center",gap:r==="tag"?4:0,height:18,padding:r==="tag"?"0 6px":"0 3px",borderRadius:4,color:"var(--private-fg, #92400e)",backgroundColor:"var(--private-bg, rgba(245,158,11,0.12))",border:"1px solid var(--private-border-soft, rgba(245,158,11,0.35))",fontFamily:"var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)",fontSize:10,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",lineHeight:1,flexShrink:0};return t.jsxs("span",{role:"status","aria-label":n,title:n,"data-testid":"skill-row-private-chip","data-private":"true","data-variant":r,style:s,children:[t.jsx(Ix,{size:11}),r==="tag"?t.jsx("span",{children:"Private"}):null]})}function Ax({skill:e,isSelected:r,onSelect:n,onContextMenu:s,dirty:o,repoVisibility:a,repoFullName:i}){const c=e.origin==="installed"?"var(--status-installed)":"var(--status-own)";return t.jsxs("button",{type:"button",onClick:n,onContextMenu:s?d=>{d.preventDefault(),s(d,e)}:void 0,"aria-current":r?"true":void 0,"aria-selected":!!r,"data-testid":"skill-row","data-selected":r,"data-origin":e.origin,"data-skill-id":`${e.plugin}/${e.skill}`,style:{display:"flex",alignItems:"center",gap:8,width:"100%",height:36,padding:"0 12px 0 14px",background:r?"color-mix(in srgb, var(--accent-surface) 10%, transparent)":"transparent",boxShadow:r?"inset 2px 0 0 var(--color-accent, var(--accent-surface))":"none",border:"none",borderRadius:0,color:"var(--text-primary)",cursor:"pointer",fontFamily:"var(--font-sans)",fontSize:13,textAlign:"left",transition:"background-color var(--duration-fast, 120ms) var(--ease-standard, ease), box-shadow var(--duration-base, 180ms) var(--ease-standard, ease)"},children:[t.jsx("span",{"aria-hidden":"true","aria-label":e.updateAvailable?"Update available":void 0,title:e.updateAvailable?`Update available${e.latestVersion?` → ${e.latestVersion}`:""}`:void 0,style:{width:e.updateAvailable?10:6,height:e.updateAvailable?10:6,borderRadius:"50%",background:c,display:"inline-block",flexShrink:0,boxShadow:e.updateAvailable?"0 0 0 2px var(--color-own, #d97706)":"none",transition:"box-shadow 180ms ease, width 180ms ease, height 180ms ease"}}),t.jsx("span",{title:e.skill,style:{minWidth:0,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.skill}),o&&t.jsx("span",{"aria-label":"Uncommitted changes","data-testid":"skill-row-dirty-dot",title:"Uncommitted changes — open this skill, click Publish to commit & push",style:{width:7,height:7,borderRadius:"50%",background:"var(--color-warning, #f59e0b)",display:"inline-block",flexShrink:0,boxShadow:"0 0 0 1px rgba(245,158,11,0.25)"}}),t.jsx(vn,{version:e.resolvedVersion??e.version??"1.0.0",source:e.versionSource??(e.version?"frontmatter":"default"),pluginName:e.pluginName??null,size:"sm",showPrefix:!1,"data-testid":"skill-row-version"}),a==="private"&&t.jsx(Lx,{repoFullName:i??null}),e.isSymlink&&t.jsx(Ex,{target:e.symlinkTarget??null}),t.jsx(Nx,{skill:e}),t.jsx(Rx,{skillId:`${e.plugin}/${e.skill}`,trackedForUpdates:e.trackedForUpdates??!0})]})}const en=l.memo(Ax),wc={platformBaseUrl:"",authMode:"cookie",getAuthHeader:async()=>null},Sc=l.createContext(wc);function Px({value:e,children:r}){const n=l.useMemo(()=>({...wc,...e??{}}),[e==null?void 0:e.platformBaseUrl,e==null?void 0:e.authMode,e==null?void 0:e.getAuthHeader,e==null?void 0:e.fetchImpl]);return t.jsx(Sc.Provider,{value:n,children:r})}function ut(){return l.useContext(Sc)}function $x(e,r){const n=e.platformBaseUrl.replace(/\/+$/,""),s=r.startsWith("/")?r:`/${r}`;return`${n}${s}`}const Fr=6e4,Qe={profile:()=>"account:profile",repos:()=>"account:repos",tokens:()=>"account:tokens",skills:()=>"account:skills",notifications:()=>"account:notifications",exports:()=>"account:exports"};async function pt(e,r,n={}){const s=e.fetchImpl??globalThis.fetch.bind(globalThis),o=new Headers(n.headers??{});if(n.body&&!o.has("Content-Type")&&o.set("Content-Type","application/json"),e.authMode==="bearer"){const c=await e.getAuthHeader();c&&o.set("Authorization",c)}const a=e.authMode==="cookie"?"include":"omit",i=await s($x(e,r),{...n,headers:o,credentials:a});if(!i.ok){let c="";try{c=await i.text()}catch{}const d=new Error(`Request to ${r} failed (${i.status}): ${c.slice(0,240)}`);throw d.status=i.status,d}if(i.status!==204)return await i.json()}function yn(){const e=ut();return wt(Qe.profile(),()=>pt(e,"/api/v1/account/profile"),{ttl:Fr})}function Cc(){const e=ut();return l.useCallback(async r=>{const n=await pt(e,"/api/v1/account/profile",{method:"PATCH",body:JSON.stringify(r)});return ze(Qe.profile()),n},[e])}function ra(){const e=ut();return wt(Qe.repos(),async()=>Mx(await pt(e,"/api/v1/account/repos")),{ttl:Fr})}function Ec(e){return(e==null?void 0:e.repos)??[]}function Mx(e){if(Array.isArray(e))return{repos:e,totalCount:e.length,publicCount:e.filter(n=>!n.isPrivate).length,privateCount:e.filter(n=>n.isPrivate).length};const r=Array.isArray(e==null?void 0:e.repos)?e.repos:[];return{repos:r,totalCount:(e==null?void 0:e.totalCount)??r.length,publicCount:(e==null?void 0:e.publicCount)??r.filter(n=>!n.isPrivate).length,privateCount:(e==null?void 0:e.privateCount)??r.filter(n=>n.isPrivate).length}}function Nc(){const e=ut();return l.useCallback(async r=>{await pt(e,`/api/v1/account/repos/${r}/resync`,{method:"POST"}),ze(Qe.repos())},[e])}function Rc(){const e=ut();return l.useCallback(async r=>{await pt(e,`/api/v1/account/repos/${r}`,{method:"DELETE"}),ze(Qe.repos())},[e])}function Tc(){const e=ut();return wt(Qe.tokens(),async()=>Dx(await pt(e,"/api/v1/account/tokens")),{ttl:Fr})}function Dx(e){return Array.isArray(e)?e:e.tokens??[]}function Ic(){const e=ut();return l.useCallback(async r=>{const n=await pt(e,"/api/v1/account/tokens",{method:"POST",body:JSON.stringify(r)});return ze(Qe.tokens()),n},[e])}function Lc(){const e=ut();return l.useCallback(async r=>{await pt(e,`/api/v1/account/tokens/${r}`,{method:"DELETE"}),ze(Qe.tokens())},[e])}function Ac(){const e=ut();return wt(Qe.notifications(),()=>pt(e,"/api/v1/account/notifications"),{ttl:Fr})}function Pc(){const e=ut();return l.useCallback(async r=>{const n=await pt(e,"/api/v1/account/notifications",{method:"PATCH",body:JSON.stringify(r)});return ze(Qe.notifications()),n},[e])}function Fx(){const e=ut();return wt(Qe.skills(),()=>pt(e,"/api/v1/account/skills/summary"),{ttl:Fr})}function $c(){const e=ut();return wt(Qe.exports(),async()=>(await pt(e,"/api/v1/account/export")).exports,{ttl:Fr})}function Mc(){const e=ut();return l.useCallback(async()=>{await pt(e,"/api/v1/account/sign-out-all",{method:"POST"}),ze(Qe.profile()),ze(Qe.repos()),ze(Qe.tokens()),ze(Qe.notifications()),ze(Qe.skills()),ze(Qe.exports())},[e])}function Dc(){const e=ut();return l.useCallback(async()=>{const r=await pt(e,"/api/v1/account/export",{method:"POST"});return ze(Qe.exports()),r},[e])}function Fc(){const e=ut();return l.useCallback(async r=>{await pt(e,"/api/v1/account/delete",{method:"POST",body:JSON.stringify({confirmHandle:r})})},[e])}function zx(){return{profile:yn(),repos:ra(),tokens:Tc(),skills:Fx(),notifications:Ac(),exports:$c(),updateProfile:Cc(),resyncRepo:Nc(),disconnectRepo:Rc(),createToken:Ic(),revokeToken:Lc(),updateNotificationPrefs:Pc(),signOutAll:Mc(),requestExport:Dc(),deleteAccount:Fc()}}const Bx=/^https?:\/\/(?:www\.)?github\.com\/([^/]+)\/([^/?#]+?)(?:\.git)?\/?$/i,_x=/^git@github\.com:([^/]+)\/([^/?#]+?)(?:\.git)?$/i;function zc(e){if(!e)return null;const r=e.trim(),n=Bx.exec(r);if(n)return`${n[1].toLowerCase()}/${n[2].toLowerCase()}`;const s=_x.exec(r);return s?`${s[1].toLowerCase()}/${s[2].toLowerCase()}`:null}function Ox(e){const r=new Map;for(const n of e)r.set(n.repoFullName.toLowerCase(),n);return r}function Wx(){const{data:e,loading:r}=ra(),n=Ec(e);return{lookup:l.useMemo(()=>Ox(n),[n]),repos:n,loading:!!r,privateCount:(e==null?void 0:e.privateCount)??n.filter(o=>o.isPrivate).length,publicCount:(e==null?void 0:e.publicCount)??n.filter(o=>!o.isPrivate).length}}function Hx({plugin:e,skills:r,selectedKey:n,onSelect:s,onContextMenu:o,dirtySkillIds:a,repoVisibilityLookup:i}){var p;const c=[...r].sort((f,h)=>f.skill.localeCompare(h.skill)),d=(p=r[0])==null?void 0:p.pluginDisplay,u=!!d&&d.toLowerCase()!==e.toLowerCase();return t.jsxs("div",{role:"group","aria-label":`${e} (${r.length})`,children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,padding:"8px 12px 4px 14px"},children:[t.jsx("span",{style:{fontSize:10,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-secondary)",fontFamily:"var(--font-sans)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e,children:e}),t.jsxs("span",{style:{fontSize:10,color:"var(--text-secondary)",fontVariantNumeric:"tabular-nums",fontFamily:"var(--font-mono)"},children:["(",r.length,")"]}),u&&t.jsx("span",{style:{fontSize:9,color:"var(--text-tertiary, var(--text-secondary))",opacity:.75,fontFamily:"var(--font-sans)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:d,children:d})]}),t.jsx("div",{role:"list",children:c.map(f=>{const h=!!n&&n.plugin===f.plugin&&n.skill===f.skill,m=i?zc(f.repoUrl):null,g=m?i.get(m)??null:null,x=g?g.isPrivate?"private":"public":"unknown";return t.jsx("div",{role:"listitem",children:t.jsx(en,{skill:f,isSelected:h,onSelect:()=>s(f),onContextMenu:o,dirty:a==null?void 0:a.has(`${f.plugin}/${f.skill}`),repoVisibility:x,repoFullName:(g==null?void 0:g.repoFullName)??null})},`${f.plugin}/${f.skill}`)})})]})}function Ux(e,r){if(!e||typeof window>"u")return r;try{const n=window.localStorage.getItem(e);return n===null?r:n==="true"}catch{return r}}function Rs({skills:e,pluginName:r,initialCollapsed:n=!1,persistKey:s,renderSkill:o,headerActionSlot:a,forceOpen:i=!1}){var m;const c=r??((m=e[0])==null?void 0:m.pluginName)??"unknown-plugin",[d,u]=l.useState(()=>Ux(s,n)),p=i?!1:d,f=l.useCallback(()=>{u(g=>{const x=!g;if(s&&typeof window<"u")try{window.localStorage.setItem(s,String(x))}catch{}return x})},[s]),h=p?"▸":"▾";return t.jsxs("div",{"data-vskill-plugin-tree":c,role:"group","aria-label":`${c} (${e.length})`,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",paddingRight:6},children:[t.jsxs("button",{type:"button",onClick:f,"aria-expanded":!p,style:{display:"flex",alignItems:"center",gap:6,flex:1,padding:"4px 4px 4px 18px",background:"transparent",border:"none",cursor:"pointer",textAlign:"left",color:"var(--text-primary)",fontSize:12,fontWeight:500},children:[t.jsx("span",{"aria-hidden":!0,className:"vskill-chevron tabular-nums",style:{width:16,display:"inline-block",textAlign:"center",fontSize:14,fontWeight:700,color:"var(--color-ink, var(--text-primary))"},children:h}),t.jsx("span",{className:"vskill-plugin-name",style:{fontFamily:"var(--font-mono)"},children:c}),t.jsxs("span",{className:"vskill-plugin-count tabular-nums",style:{marginLeft:"auto",fontSize:11,color:"var(--text-tertiary)",fontFamily:"var(--font-mono)"},children:["(",e.length,")"]})]}),a&&t.jsx("div",{style:{display:"inline-flex",alignItems:"center",flexShrink:0},children:a})]}),!p&&t.jsx("div",{className:"vskill-plugin-tree-children",style:{paddingLeft:36,borderLeft:"1px solid var(--border-subtle, rgba(128,128,128,0.2))",marginLeft:24},children:e.map(g=>t.jsx("div",{"data-vskill-plugin-skill":g.pluginNamespace??g.skill,children:o(g)},`${g.pluginNamespace??g.skill}`))})]})}function Vn({open:e,title:r,body:n,confirmLabel:s="Confirm",cancelLabel:o="Cancel",variant:a="default",onConfirm:i,onCancel:c}){const d=l.useRef(null),u=l.useRef(null),p=l.useRef(null);if(l.useEffect(()=>{if(e)return p.current=document.activeElement??null,requestAnimationFrame(()=>{var g;(g=u.current)==null||g.focus()}),()=>{var g,x;(x=(g=p.current)==null?void 0:g.focus)==null||x.call(g),p.current=null}},[e]),l.useEffect(()=>{if(!e)return;function g(x){if(x.key==="Escape"){x.preventDefault(),c();return}if(x.key==="Tab"&&d.current){const v=d.current.querySelectorAll("button:not([disabled])");if(v.length===0)return;const b=v[0],y=v[v.length-1];x.shiftKey&&document.activeElement===b?(x.preventDefault(),y.focus()):!x.shiftKey&&document.activeElement===y&&(x.preventDefault(),b.focus())}}return window.addEventListener("keydown",g,!0),()=>window.removeEventListener("keydown",g,!0)},[e,c]),!e)return null;const f="confirm-dialog-title",h="confirm-dialog-body",m=a==="destructive"?{background:"var(--red, #d92d20)",color:"#fff",border:"1px solid var(--red, #d92d20)"}:{background:"var(--accent-surface)",color:"var(--text-primary)",border:"1px solid var(--border-default)"};return t.jsx("div",{"data-testid":"confirm-dialog-overlay",onMouseDown:g=>{g.target===g.currentTarget&&c()},style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:100},children:t.jsxs("div",{ref:d,role:"alertdialog","aria-modal":"true","aria-labelledby":f,"aria-describedby":h,"data-testid":"confirm-dialog",style:{background:"var(--bg-canvas)",color:"var(--text-primary)",border:"1px solid var(--border-default)",borderRadius:8,padding:20,width:"min(440px, 92vw)",boxShadow:"0 20px 48px rgba(0,0,0,0.32)",fontFamily:"var(--font-sans)"},children:[t.jsx("h2",{id:f,style:{margin:0,fontSize:16,fontWeight:600,marginBottom:8},children:r}),t.jsx("p",{id:h,style:{margin:0,fontSize:13,color:"var(--text-secondary)",marginBottom:16,lineHeight:1.5},children:n}),t.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[t.jsx("button",{ref:u,type:"button","data-testid":"confirm-dialog-cancel",onClick:c,style:{padding:"6px 14px",borderRadius:6,cursor:"pointer",background:"transparent",color:"var(--text-primary)",border:"1px solid var(--border-default)",fontSize:13},children:o}),t.jsx("button",{type:"button","data-testid":"confirm-dialog-confirm",onClick:i,style:{padding:"6px 14px",borderRadius:6,cursor:"pointer",fontSize:13,...m},children:s})]})]})})}function Vx(e){const r=(typeof navigator<"u"?navigator.platform:"").toLowerCase();return r.includes("mac")?"system Trash":r.includes("win")?"Recycle Bin":"Trash"}function Ts(e,r){typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:e,severity:r}}))}function Gx({pluginName:e,enabled:r,onAfterAction:n}){const[s,o]=l.useState(!1),[a,i]=l.useState(null),[c,d]=l.useState(null),[u,p]=l.useState(!1),f=l.useRef(null);l.useEffect(()=>{if(!s)return;function g(x){f.current&&!f.current.contains(x.target)&&o(!1)}return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[s]);async function h(g){i(g),d(null);try{const x=await fetch(`/api/plugins/${encodeURIComponent(e)}/${g}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}),v=await x.json().catch(()=>({}));if(!x.ok||!v.ok){const b=v.error??`${g} failed (${x.status})`;d(b),g==="uninstall"&&Ts(`Failed to uninstall ${e}: ${b}`,"error");return}if(g==="uninstall"){const b=v.fallback==="orphan-cache-removed"?`Removed orphaned ${e}`:`Uninstalled ${e}`;Ts(b,"success")}ze("skills"),Wl(),n==null||n(),o(!1)}catch(x){const v=x instanceof Error?x.message:String(x);d(v),g==="uninstall"&&Ts(`Failed to uninstall ${e}: ${v}`,"error")}finally{i(null)}}function m(){p(!0)}return t.jsxs("div",{ref:f,style:{position:"relative",display:"inline-flex"},children:[t.jsx("button",{type:"button","aria-label":`Manage ${e}`,title:`Manage ${e}`,onClick:g=>{g.stopPropagation(),o(x=>!x)},"data-vskill-plugin-action-trigger":e,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:22,height:22,padding:0,marginLeft:4,border:"none",background:s?"var(--surface-2, rgba(0,0,0,0.08))":"transparent",color:"var(--text-tertiary)",borderRadius:4,cursor:"pointer",fontSize:14,lineHeight:1},onMouseEnter:g=>{g.currentTarget.style.color="var(--text-primary)",g.currentTarget.style.background="var(--surface-2, rgba(0,0,0,0.06))"},onMouseLeave:g=>{g.currentTarget.style.color="var(--text-tertiary)",g.currentTarget.style.background=s?"var(--surface-2, rgba(0,0,0,0.08))":"transparent"},children:"⋯"}),s&&t.jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 2px)",right:0,minWidth:160,background:"var(--color-paper, #fff)",border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:6,boxShadow:"0 4px 6px -1px rgba(0,0,0,0.08), 0 8px 14px -4px rgba(0,0,0,0.12)",padding:4,zIndex:30,fontFamily:"var(--font-sans)"},children:[r?t.jsx(Is,{onClick:()=>void h("disable"),disabled:a!==null,busy:a==="disable",label:"Disable",hint:"Keep installed, turn off"}):t.jsx(Is,{onClick:()=>void h("enable"),disabled:a!==null,busy:a==="enable",label:"Enable",hint:"Activate plugin"}),t.jsx(Is,{onClick:m,disabled:a!==null,busy:a==="uninstall",label:"Uninstall",hint:"Remove plugin + skills",danger:!0}),c&&t.jsx("div",{style:{padding:"6px 8px",fontSize:11,color:"var(--color-error, #b91c1c)",background:"color-mix(in oklch, var(--color-error, #b91c1c) 8%, transparent)",borderRadius:4,marginTop:4,lineHeight:1.4,maxWidth:240,wordBreak:"break-word"},children:c})]}),t.jsx(Vn,{open:u,title:`Uninstall ${e}?`,body:`This removes the ${e} plugin and all of its skills. You can reinstall it later from the marketplace.`,confirmLabel:"Uninstall",cancelLabel:"Cancel",variant:"destructive",onCancel:()=>{p(!1),o(!1)},onConfirm:()=>{p(!1),h("uninstall")}})]})}function Is({onClick:e,disabled:r,busy:n,label:s,hint:o,danger:a}){return t.jsxs("button",{type:"button",onClick:i=>{i.stopPropagation(),e()},disabled:r,role:"menuitem",style:{display:"block",width:"100%",padding:"6px 10px",textAlign:"left",border:"none",background:"transparent",borderRadius:4,cursor:r?"not-allowed":"pointer",color:a?"var(--color-error, #b91c1c)":"var(--text-primary)",opacity:r&&!n?.5:1,fontFamily:"inherit"},onMouseEnter:i=>{r||(i.currentTarget.style.background="var(--surface-2, rgba(0,0,0,0.05))")},onMouseLeave:i=>{i.currentTarget.style.background="transparent"},children:[t.jsx("div",{style:{fontSize:12,fontWeight:500},children:n?`${s}…`:s}),t.jsx("div",{style:{fontSize:10,color:"var(--text-tertiary)"},children:o})]})}const Kx=/^[a-z][a-z0-9-]{0,62}[a-z0-9]$/;function qx({anchorSkillDir:e,candidateLabel:r,initialName:n,initialDescription:s,onConverted:o,onCancel:a}){const[i,c]=l.useState(n),[d,u]=l.useState(s??""),[p,f]=l.useState(!1),[h,m]=l.useState(null),[g,x]=l.useState(null),v=Kx.test(i),b=p||!v,y=l.useCallback(async j=>{if(j.preventDefault(),!b){f(!0),m(null),x(null);try{const S=await ie.convertToPlugin({anchorSkillDir:e,pluginName:i.trim(),description:d.trim()});o({pluginDir:S.pluginDir,manifestPath:S.manifestPath,validation:S.validation})}catch(S){if(S instanceof qt){m(S.message);const w=S.details;w&&typeof w.stderr=="string"&&x(w.stderr)}else m(S instanceof Error?S.message:String(S));f(!1)}}},[b,e,i,d,o]);return t.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"vskill-convert-dialog-title",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},onClick:j=>{j.target===j.currentTarget&&!p&&a()},children:t.jsxs("form",{onSubmit:y,style:{background:"var(--bg-primary, #fff)",color:"var(--text-primary, #111)",borderRadius:8,padding:20,width:"min(540px, 92vw)",boxShadow:"0 12px 48px rgba(0,0,0,0.25)",fontFamily:"var(--font-sans)"},children:[t.jsxs("h2",{id:"vskill-convert-dialog-title",style:{margin:0,fontSize:16,fontWeight:600},children:["Convert ",t.jsxs("span",{style:{fontFamily:"var(--font-mono)"},children:[r,"/"]})," to a plugin"]}),t.jsxs("p",{style:{marginTop:8,marginBottom:16,fontSize:13,color:"var(--text-secondary)"},children:["Writes ",t.jsx("span",{style:{fontFamily:"var(--font-mono)"},children:".claude-plugin/plugin.json"})," into this folder and validates it via ",t.jsx("span",{style:{fontFamily:"var(--font-mono)"},children:"claude plugin validate"}),". The skills already on disk will appear nested under the new plugin."]}),t.jsx("label",{style:{display:"block",fontSize:12,fontWeight:500,marginBottom:4},children:"Plugin name"}),t.jsx("input",{type:"text",value:i,onChange:j=>c(j.target.value),disabled:p,autoFocus:!0,style:{width:"100%",padding:"6px 8px",fontSize:13,fontFamily:"var(--font-mono)",boxSizing:"border-box",border:"1px solid var(--border-subtle)",borderRadius:4}}),!v&&t.jsx("div",{style:{fontSize:11,color:"var(--color-error, #c00)",marginTop:4},children:"Must be kebab-case (lowercase letters, digits, hyphens; 2–64 chars)."}),t.jsx("label",{style:{display:"block",fontSize:12,fontWeight:500,marginTop:12,marginBottom:4},children:"Description"}),t.jsx("input",{type:"text",value:d,onChange:j=>u(j.target.value),disabled:p,style:{width:"100%",padding:"6px 8px",fontSize:13,boxSizing:"border-box",border:"1px solid var(--border-subtle)",borderRadius:4}}),h&&t.jsxs("div",{role:"alert",style:{marginTop:12,padding:8,fontSize:12,background:"var(--color-error-bg, #fee)",color:"var(--color-error, #c00)",borderRadius:4},children:[t.jsx("div",{style:{fontWeight:500},children:h}),g&&t.jsx("pre",{style:{marginTop:6,padding:6,fontSize:11,fontFamily:"var(--font-mono)",whiteSpace:"pre-wrap",background:"rgba(0,0,0,0.04)",borderRadius:3,maxHeight:160,overflow:"auto"},children:g})]}),t.jsxs("div",{style:{marginTop:16,display:"flex",justifyContent:"flex-end",gap:8},children:[t.jsx("button",{type:"button",onClick:a,disabled:p,style:{padding:"6px 12px",fontSize:13,background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:4,cursor:p?"not-allowed":"pointer"},children:"Cancel"}),t.jsx("button",{type:"submit",disabled:b,style:{padding:"6px 12px",fontSize:13,background:"var(--color-accent, #2b6cb0)",color:"white",border:"none",borderRadius:4,cursor:b?"not-allowed":"pointer",opacity:b?.5:1},children:p?"Converting…":"Convert"})]})]})})}function pi({name:e,count:r,className:n,variant:s,collapsed:o,onToggle:a,action:i}){const c=s==="authoring"?"var(--color-own, #f59e0b)":"var(--color-accent, #2f6f8f)",d=s==="authoring"?"color-mix(in oklch, var(--color-own, #f59e0b) 10%, var(--color-paper, #fff))":"color-mix(in oklch, var(--color-accent, #2f6f8f) 8%, var(--color-paper, #fff))",u=typeof a=="function",p={position:"sticky",top:0,zIndex:4,backdropFilter:"saturate(1.4) blur(10px)",WebkitBackdropFilter:"saturate(1.4) blur(10px)",background:d,borderLeft:`3px solid ${c}`,borderBottom:"1px solid var(--border-subtle, rgba(128,128,128,0.2))",padding:"7px 10px 7px 9px",fontFamily:"var(--font-serif, ui-serif)",fontSize:13,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-primary)",display:"flex",alignItems:"center",gap:8,width:"100%",cursor:u?"pointer":"default",border:"none",textAlign:"left"},f=o?"▸":"▾",h=t.jsxs(t.Fragment,{children:[u&&t.jsx("span",{"aria-hidden":!0,style:{fontSize:15,fontWeight:700,color:c,width:16,display:"inline-block",textAlign:"center",letterSpacing:0,textTransform:"none"},children:f}),t.jsx("span",{className:"vskill-group-header-name",children:e}),t.jsxs("span",{className:"vskill-group-header-count tabular-nums",style:{fontFamily:"var(--font-mono)",fontSize:11,fontWeight:500,color:"var(--text-secondary)",letterSpacing:0,textTransform:"none"},children:["(",r,")"]}),i&&t.jsx("span",{style:{marginLeft:"auto"},children:t.jsx(Yx,{label:i.label,title:i.title,icon:i.icon,onClick:i.onClick,accent:c})})]});return u?t.jsx("button",{type:"button","data-vskill-group-header":e,className:["vskill-group-header select-none",n??""].join(" ").trim(),style:p,onClick:()=>a(!o),"aria-expanded":!o,children:h}):t.jsx("div",{"data-vskill-group-header":e,role:"heading","aria-level":3,className:["vskill-group-header select-none",n??""].join(" ").trim(),style:p,children:h})}function Yx({label:e,title:r,icon:n,onClick:s,accent:o}){return t.jsxs("button",{type:"button","aria-label":e,title:r??e,onClick:a=>{a.stopPropagation(),s()},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:4,height:22,padding:"0 7px",border:`1px solid ${o}`,background:"transparent",color:o,borderRadius:4,fontSize:10,fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",cursor:"pointer",fontFamily:"inherit"},onMouseEnter:a=>{a.currentTarget.style.background=`color-mix(in oklch, ${o} 15%, transparent)`},onMouseLeave:a=>{a.currentTarget.style.background="transparent"},children:[n,e]})}function Jx(){return t.jsxs("div",{"aria-hidden":"true",role:"presentation",style:{display:"flex",alignItems:"center",gap:8,height:36,padding:"0 12px 0 14px"},children:[t.jsx("span",{className:"placeholder",style:{width:6,height:6,borderRadius:"50%",flexShrink:0}}),t.jsx("span",{className:"placeholder",style:{height:10,flex:1,borderRadius:3,maxWidth:180}})]})}function Xx(e){const r=e.key.split("+").map(c=>c.trim()).filter(Boolean);let n=!!e.meta,s=!!e.ctrl,o=!!e.shift,a=!!e.alt,i=e.key;if(r.length>1){for(const c of r.slice(0,-1)){const d=c.toLowerCase();d==="cmd"||d==="meta"||d==="⌘"?n=!0:d==="ctrl"||d==="control"?s=!0:d==="shift"?o=!0:(d==="alt"||d==="option")&&(a=!0)}i=r[r.length-1]}return{key:i.length===1?i.toLowerCase():i,meta:n,ctrl:s,shift:o,alt:a,allowInInputs:!!e.allowInInputs,handler:e.handler}}function Qx(e){if(!e||!(e instanceof HTMLElement))return!1;const r=e.tagName;if(r==="INPUT"||r==="TEXTAREA"||e.isContentEditable)return!0;const n=e.getAttribute("contenteditable");return n!=null&&n!=="false"||e.getAttribute("role")==="textbox"}function Zx(e,r){const n=!!e.metaKey,s=!!e.ctrlKey,o=!!e.shiftKey,a=!!e.altKey;return n!==r.meta||s!==r.ctrl||o!==r.shift||a!==r.alt?!1:(e.key.length===1?e.key.toLowerCase():e.key)===r.key}function wo(e,r={}){const{enabled:n=!0,target:s}=r,o=l.useRef([]),a=Array.isArray(e)?e:[e];o.current=a.map(Xx),l.useEffect(()=>{if(!n)return;const i=s??(typeof window<"u"?window:void 0);if(!i)return;function c(d){const u=d,p=Qx(u.target);for(const f of o.current){if(!Zx(u,f))continue;const h=f.meta||f.ctrl||f.alt;if(!(p&&!f.allowInInputs&&!h)){f.handler(u);return}}}return i.addEventListener("keydown",c),()=>{i.removeEventListener("keydown",c)}},[n,s])}function Bc(){const{data:e,loading:r,error:n,revalidate:s}=wt("project-github-status",()=>ie.getProjectGitHubStatus());return{status:e,loading:r,error:n,revalidate:s}}function eg(e){if(typeof window>"u")return!1;try{return window.localStorage.getItem(`vskill-github-hint-dismissed-${e}`)==="true"}catch{return!1}}function tg({projectRoot:e}){const{status:r,loading:n}=Bc();if(n||!r||r.status==="github"||eg(e))return null;const s=r.status==="no-git"?"GitHub not connected — run `gh repo create ...` to publish your skills":"Origin is not GitHub — add a github.com remote to publish",o=()=>{typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:focus-publish-row"))};return t.jsx("button",{type:"button","data-testid":"sidebar-github-not-connected","aria-label":"GitHub not connected — click for help",title:s,onClick:o,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:20,height:20,padding:0,background:"transparent",border:"none",cursor:"pointer",color:"var(--color-own, #f59e0b)"},children:t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("path",{d:"m2 2 20 20"}),t.jsx("path",{d:"M5.782 5.782A7 7 0 0 0 9 19h8.5a4.5 4.5 0 0 0 1.307-.193"}),t.jsx("path",{d:"M21.532 16.5A4.5 4.5 0 0 0 17.5 10h-1.79A7.008 7.008 0 0 0 10 5.07"})]})})}const rg=3e4;async function ng(e){const r={name:null,branch:null,is_private:null,sync_state:{kind:"no_remote"}};if(typeof window>"u")return r;try{const n=await fetch(`/api/git/repo-info?folder=${encodeURIComponent(e)}`);return n.ok?await n.json():r}catch{return r}}const _c=l.forwardRef(function({folder:r,fetchRepoInfo:n=ng,pollIntervalMs:s=rg,tier:o,onUpgradeClick:a,onConnectPrivateClick:i},c){const d=o==="pro"||o==="enterprise"?o:"free",u=d!=="free",[p,f]=l.useState(null),[h,m]=l.useState(!1),[g,x]=l.useState(null),v=l.useRef(n);v.current=n;const b=async()=>{if(!r){f(null);return}m(!0),x(null);try{const y=await v.current(r);f(y)}catch(y){x(y instanceof Error?y.message:String(y))}finally{m(!1)}};return l.useImperativeHandle(c,()=>({refresh:b}),[r]),l.useEffect(()=>{if(!r){f(null);return}let y=!1,j=null;const S=async()=>{if(!y&&!(typeof document<"u"&&document.visibilityState!=="visible"))try{const R=await v.current(r);y||f(R)}catch(R){y||x(R instanceof Error?R.message:String(R))}};S(),j=setInterval(S,s);const w=()=>{typeof document<"u"&&document.visibilityState==="visible"&&S()};return typeof document<"u"&&document.addEventListener("visibilitychange",w),()=>{y=!0,j!==null&&clearInterval(j),typeof document<"u"&&document.removeEventListener("visibilitychange",w)}},[r,s]),r?g?t.jsx("div",{"data-testid":"connected-repo-widget","data-state":"error",style:Wr,children:t.jsxs("span",{style:{color:"var(--color-error, #c0392b)",fontSize:12},children:["Couldn't load repo info: ",g]})}):p?!p.name&&p.sync_state.kind==="no_remote"?t.jsx("div",{"data-testid":"connected-repo-widget","data-state":"not-git",style:Wr,children:t.jsx("span",{style:{color:"var(--color-muted, #999)",fontSize:12},children:"No git remote"})}):t.jsxs("div",{"data-testid":"connected-repo-widget","data-state":"connected","data-tier":d,style:Wr,children:[t.jsx("span",{style:cg,"data-testid":"repo-name",children:p.name??"Local-only"}),p.branch?t.jsxs("span",{style:dg,"data-testid":"repo-branch",children:[t.jsx(og,{})," ",p.branch]}):null,t.jsx(lg,{state:p.sync_state}),t.jsx(sg,{isPrivate:p.is_private,isPaid:u,onUpgradeClick:a,onConnectPrivateClick:i})]}):t.jsx("div",{"data-testid":"connected-repo-widget","data-state":"loading","aria-busy":h||void 0,style:Wr,children:t.jsx("span",{style:{color:"var(--color-muted, #999)",fontSize:12},children:"Loading…"})}):t.jsx("div",{"data-testid":"connected-repo-widget","data-state":"empty",style:Wr,children:t.jsx("span",{style:{color:"var(--color-muted, #999)",fontSize:12},children:"No project folder selected"})})});function sg({isPrivate:e,isPaid:r,onUpgradeClick:n,onConnectPrivateClick:s}){return e!==!0?t.jsx(ig,{isPrivate:e}):r?t.jsxs("span",{style:{..._t,color:"var(--color-private, #b58900)"},"data-testid":"visibility-pill","data-visibility":"private","aria-label":"Private repository",children:[t.jsx(So,{})," private",s?t.jsx("button",{type:"button",onClick:s,"data-testid":"repo-connect-private",title:"Install the verified-skill GitHub App to enable read/write access on this private repo.","aria-label":"Connect private repos via GitHub App",style:pg,children:"Connect"}):null]}):t.jsxs("span",{style:{..._t,color:"var(--color-private, #b58900)"},"data-testid":"visibility-pill","data-visibility":"private-locked","aria-label":"Private repository — Pro feature",children:[t.jsx(So,{})," private",t.jsx("button",{type:"button",onClick:n,"data-testid":"repo-upgrade-chip",title:"Upgrade for private repo connections.","aria-label":"Upgrade to Pro for private repository connections",style:ug,children:"Pro"})]})}function og(){return t.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,style:{verticalAlign:"middle",marginRight:4},children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function So(){return t.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function ag(){return t.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:t.jsx("polyline",{points:"20 6 9 17 4 12"})})}function ig({isPrivate:e}){return e===null?t.jsx("span",{style:{..._t,color:"var(--color-muted, #999)"},"data-testid":"visibility-pill","data-visibility":"unknown",children:"unknown"}):e?t.jsxs("span",{style:{..._t,color:"var(--color-private, #b58900)"},"data-testid":"visibility-pill","data-visibility":"private","aria-label":"Private repository",children:[t.jsx(So,{})," private"]}):t.jsxs("span",{style:{..._t,color:"var(--color-public, #2aa198)"},"data-testid":"visibility-pill","data-visibility":"public","aria-label":"Public repository",children:[t.jsx(ag,{})," public"]})}function lg({state:e}){return e.kind==="clean"?t.jsx("span",{style:{..._t,color:"var(--color-clean, #859900)"},"data-testid":"sync-state-pill","data-sync":"clean",children:"in sync"}):e.kind==="no_remote"?t.jsx("span",{style:{..._t,color:"var(--color-muted, #999)"},"data-testid":"sync-state-pill","data-sync":"no_remote",children:"no remote"}):e.kind==="dirty"?t.jsxs("span",{style:{..._t,color:"var(--color-warn, #cb4b16)"},"data-testid":"sync-state-pill","data-sync":"dirty",title:`${e.count} uncommitted ${e.count===1?"change":"changes"}`,children:[e.count," dirty"]}):e.kind==="ahead"?t.jsxs("span",{style:{..._t,color:"var(--color-ahead, #268bd2)"},"data-testid":"sync-state-pill","data-sync":"ahead",children:["+",e.count," ahead"]}):t.jsxs("span",{style:{..._t,color:"var(--color-behind, #6c71c4)"},"data-testid":"sync-state-pill","data-sync":"behind",children:["-",e.count," behind"]})}const Wr={display:"inline-flex",alignItems:"center",gap:6,flexWrap:"wrap",fontSize:12,fontFamily:"var(--font-system, -apple-system, system-ui)"},cg={fontWeight:500,color:"var(--color-text, #333)"},dg={display:"inline-flex",alignItems:"center",gap:2,padding:"1px 6px",borderRadius:9999,background:"var(--color-pill-bg, rgba(0,0,0,0.05))",color:"var(--color-text-soft, #555)",fontSize:11},_t={display:"inline-flex",alignItems:"center",gap:3,padding:"1px 6px",borderRadius:9999,background:"var(--color-pill-bg, rgba(0,0,0,0.05))",fontSize:11,fontWeight:500},ug={marginLeft:4,padding:"0px 5px",borderRadius:9999,border:"none",background:"var(--color-pro-bg, #cb4b16)",color:"var(--color-pro-fg, #ffffff)",fontSize:9,fontWeight:600,letterSpacing:.4,textTransform:"uppercase",cursor:"pointer",fontFamily:"inherit"},pg={marginLeft:4,padding:"0px 6px",borderRadius:9999,border:"1px solid currentColor",background:"transparent",color:"inherit",fontSize:10,fontWeight:500,cursor:"pointer",fontFamily:"inherit"};async function fg(){return Oc("account_get_platform_url"),{platformBaseUrl:"",authMode:"cookie",getAuthHeader:async()=>null}}async function hg(){const e=await Oc("account_get_user_summary");return e&&typeof e=="object"?e:{signedIn:!1,login:null,avatarUrl:null,tier:"free"}}async function Oc(e){var s;if(typeof window>"u")return null;const n=(s=window.__TAURI_INTERNALS__)==null?void 0:s.invoke;if(!n)return null;try{return await n(e)}catch(o){return console.warn(`[AccountTauriBridge] ${e} failed:`,o),null}}function mg(){var e;return typeof window>"u"?!1:!!((e=window.__TAURI_INTERNALS__)!=null&&e.invoke)}const xg={signedIn:!1,login:null,avatarUrl:null,tier:"free"};function gg(){const[e,r]=l.useState(xg);return l.useEffect(()=>{let n=!1;const s=()=>{hg().then(o=>{n||r(o)})};return s(),typeof window>"u"?()=>{n=!0}:(window.addEventListener("studio:account-summary-refresh",s),()=>{n=!0,window.removeEventListener("studio:account-summary-refresh",s)})},[]),e}const vg=200;function yg(e){return e.scope==="own"||e.scope==="installed"||e.scope==="global"?e.scope:e.origin==="installed"?"installed":"own"}function bg(e,r){const n={availableProject:[],availablePersonal:[],availablePlugin:[],authoringProject:[],authoringPlugin:[]};for(const i of e){const c=i.scopeV2??(i.scope==="installed"?"available-project":i.scope==="global"?"available-personal":"authoring-project");c==="available-project"?n.availableProject.push(i):c==="available-personal"?n.availablePersonal.push(i):c==="available-plugin"?n.availablePlugin.push(i):c==="authoring-plugin"?n.authoringPlugin.push(i):n.authoringProject.push(i)}function s(i){const c=i.filter(p=>ta(p,r)),d={};for(const p of c){const f=p.pluginName??p.plugin;(d[f]||(d[f]=[])).push(p)}const u=Object.entries(d).sort((p,f)=>p[0].localeCompare(f[0]));return{total:i.length,filtered:c.length,byPlugin:u}}const o=s(n.authoringProject),a=o.byPlugin.filter(([i,c])=>c.length>=2&&i.trim().length>=2).map(([i,c])=>({groupKey:i,skills:c,anchorSkillDir:c[0].dir}));return{availableProject:s(n.availableProject),availablePersonal:s(n.availablePersonal),availablePlugin:s(n.availablePlugin),authoringProject:o,authoringPlugin:s(n.authoringPlugin),authoringCandidatePlugins:a}}function kg(e,r){const n=[],s=[],o=[];for(const i of e){const c=yg(i);c==="global"?o.push(i):c==="installed"?s.push(i):n.push(i)}function a(i){var p;const c=i.filter(f=>ta(f,r)),d={};for(const f of c)(d[p=f.plugin]||(d[p]=[])).push(f);const u=Object.entries(d).sort((f,h)=>f[0].localeCompare(h[0]));return{total:i.length,filtered:c.length,byPlugin:u}}return{own:a(n),installed:a(s),global:a(o)}}function jg(e,r){const n=[],s=[];for(const a of e)(a.origin==="installed"?s:n).push(a);function o(a){var u;const i=a.filter(p=>ta(p,r)),c={};for(const p of i)(c[u=p.plugin]||(c[u]=[])).push(p);const d=Object.entries(c).sort((p,f)=>p[0].localeCompare(f[0]));return{total:a.length,filtered:i.length,byPlugin:d}}return{own:o(n),installed:o(s)}}function wg({skills:e,selectedKey:r,onSelect:n,isLoading:s,error:o,onRetry:a,onContextMenu:i,outdatedByOrigin:c,activeAgentId:d,outdatedByScope:u,topSlot:p,revealSkillId:f,onRevealComplete:h,dirtySkillIds:m,onSkillsChanged:g}){const[x,v]=l.useState(null),b=!!d||e.some(A=>A.scope!==void 0&&A.scope!==null),y=d??"claude-cli",[j,S]=l.useState(""),w=l.useDeferredValue(j),R=l.useMemo(()=>kg(e,w),[e,w]),k=l.useMemo(()=>bg(e,w),[e,w]),E=y==="claude-code",{plugins:C}=qh(),N=E?{plugins:C??[]}:void 0,I=l.useMemo(()=>{const A=new Map;for(const O of(N==null?void 0:N.plugins)??[]){const V=A.get(O.name);A.set(O.name,!!V||!!O.enabled)}return A},[N==null?void 0:N.plugins]),[P,L]=l.useState(()=>Co(`vskill-sidebar-${y}-group-available-collapsed`)),[B,T]=l.useState(()=>Co(`vskill-sidebar-${y}-group-authoring-collapsed`)),$=l.useCallback(A=>{L(A);try{window.localStorage.setItem(`vskill-sidebar-${y}-group-available-collapsed`,String(A))}catch{}},[y]),M=l.useCallback(A=>{T(A);try{window.localStorage.setItem(`vskill-sidebar-${y}-group-authoring-collapsed`,String(A))}catch{}},[y]),{own:F,installed:W}=l.useMemo(()=>jg(e,w),[e,w]),U=R.own.filtered+R.installed.filtered+R.global.filtered>=vg,{lookup:H}=Wx(),ee=l.useMemo(()=>{const A=O=>{const V=[];for(const[,re]of O){const ce=[...re].sort((ne,ve)=>ne.skill.localeCompare(ve.skill));V.push(...ce)}return V};return b?[...A(R.own.byPlugin),...A(R.installed.byPlugin),...A(R.global.byPlugin)]:[...A(F.byPlugin),...A(W.byPlugin)]},[b,R.own.byPlugin,R.installed.byPlugin,R.global.byPlugin,F.byPlugin,W.byPlugin]),K=l.useMemo(()=>r?ee.findIndex(A=>A.plugin===r.plugin&&A.skill===r.skill):-1,[ee,r]),X=l.useCallback(A=>{if(ee.length===0)return;const O=K<0?A>0?0:ee.length-1:Math.min(Math.max(K+A,0),ee.length-1);n(ee[O])},[ee,K,n]),G=l.useMemo(()=>{if(!f)return null;const[A,O]=f.split("/");if(!A||!O)return null;const V=e.find(ne=>ne.plugin===A&&ne.skill===O);if(!V)return{plugin:A,skill:O,bucket:null,pluginName:null};const re=V.source==="plugin"?"plugin":"project",ce=re==="plugin"?V.pluginName??A:null;return{plugin:A,skill:O,bucket:re,pluginName:ce}},[f,e]),he=l.useRef(null);return l.useEffect(()=>{if(!f){he.current=null;return}if(he.current===f)return;const A=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(f):f.replace(/["\\]/g,"\\$&"),O=document.querySelector(`[data-skill-id="${A}"]`);O&&(he.current=f,O.scrollIntoView({behavior:"smooth",block:"nearest"}),h==null||h())},[f,h,e]),wo([{key:"j",handler:()=>X(1)},{key:"k",handler:()=>X(-1)},{key:"Enter",handler:()=>{K>=0&&n(ee[K])}}],{enabled:!s&&!o}),t.jsxs("div",{"data-testid":"sidebar",style:{display:"flex",flexDirection:"column",minHeight:0,height:"100%",fontFamily:"var(--font-sans)"},children:[p,t.jsx(Cx,{value:j,onChange:S}),s&&t.jsx(Ig,{}),!s&&o&&t.jsx(Lg,{error:o,onRetry:a}),!s&&!o&&b&&t.jsxs("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:[t.jsx(pi,{name:_.scopeLabels.groupAvailable.toUpperCase(),variant:"available",collapsed:P,onToggle:$,count:k.availableProject.total+k.availablePersonal.total+k.availablePlugin.total}),!P&&t.jsxs(t.Fragment,{children:[t.jsx(Hr,{label:_.scopeLabels.sourceProject,storageKey:`vskill-sidebar-${y}-available-project-collapsed`,count:k.availableProject.total,filteredCount:j?k.availableProject.filtered:null,updateCount:(u==null?void 0:u.installed)??(c==null?void 0:c.installed),headerRightSlot:E?t.jsx(Pg,{projectRoot:y}):null,children:k.availableProject.filtered===0?t.jsx(hi,{queryActive:!!j,agentId:y}):t.jsx(Ur,{items:k.availableProject.byPlugin,selectedKey:r,onSelect:n,onContextMenu:i,useVirtual:U,dirtySkillIds:m,repoVisibilityLookup:H})}),t.jsx(Hr,{label:_.scopeLabels.sourcePersonal,storageKey:`vskill-sidebar-${y}-available-personal-collapsed`,count:k.availablePersonal.total,filteredCount:j?k.availablePersonal.filtered:null,updateCount:u==null?void 0:u.global,children:k.availablePersonal.filtered===0?t.jsx(Cg,{queryActive:!!j,agentId:y}):t.jsx(Ur,{items:k.availablePersonal.byPlugin,selectedKey:r,onSelect:n,onContextMenu:i,useVirtual:U,dirtySkillIds:m,repoVisibilityLookup:H})}),E&&t.jsxs(Hr,{label:_.scopeLabels.sourcePlugin,storageKey:`vskill-sidebar-${y}-available-plugin-collapsed`,count:k.availablePlugin.total,filteredCount:j?k.availablePlugin.filtered:null,children:[t.jsxs("button",{type:"button",onClick:()=>window.dispatchEvent(new CustomEvent("studio:open-marketplace")),style:{display:"flex",alignItems:"center",gap:6,margin:"4px 14px 6px",padding:"4px 8px",fontSize:11,fontWeight:500,border:"1px dashed var(--color-accent, #2f6f8f)",borderRadius:4,background:"transparent",color:"var(--color-accent, #2f6f8f)",cursor:"pointer"},children:[t.jsx("span",{"aria-hidden":!0,children:"🛒"})," Browse marketplaces…"]}),k.availablePlugin.filtered===0?t.jsx(Eg,{queryActive:!!j,hasInstalled:k.availablePlugin.total>0}):k.availablePlugin.byPlugin.map(([A,O])=>t.jsx(Rs,{pluginName:A,skills:O,persistKey:`vskill-plugin-available-${A}-collapsed`,headerActionSlot:E?t.jsx(Gx,{pluginName:A,enabled:I.get(A)??!0}):void 0,renderSkill:V=>t.jsx(en,{skill:V,isSelected:(r==null?void 0:r.plugin)===V.plugin&&(r==null?void 0:r.skill)===V.skill,onSelect:()=>n(V),onContextMenu:i,dirty:m==null?void 0:m.has(`${V.plugin}/${V.skill}`)})},`available-${A}`))]})]}),t.jsx(Tg,{}),t.jsx(pi,{name:_.scopeLabels.groupAuthoring.toUpperCase(),variant:"authoring",collapsed:G?!1:B,onToggle:M,count:k.authoringProject.total+k.authoringPlugin.total,action:{label:"New",title:"Create a new skill (standalone or plugin)",icon:t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),onClick:()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("studio:request-create-skill",{detail:{mode:"standalone"}}))}}}),(!B||G)&&t.jsxs(t.Fragment,{children:[t.jsx(Hr,{label:_.scopeLabels.authoringSkills,storageKey:`vskill-sidebar-${y}-authoring-project-collapsed`,count:k.authoringProject.total,filteredCount:j?k.authoringProject.filtered:null,updateCount:(u==null?void 0:u.own)??(c==null?void 0:c.source),forceOpen:(G==null?void 0:G.bucket)==="project",children:k.authoringProject.filtered===0?t.jsx(fi,{queryActive:!!j}):t.jsxs(t.Fragment,{children:[k.authoringCandidatePlugins.map(A=>t.jsx(Rs,{pluginName:A.groupKey,skills:A.skills,persistKey:`vskill-candidate-plugin-${A.groupKey}-collapsed`,headerActionSlot:t.jsx("button",{type:"button",onClick:O=>{O.stopPropagation(),v({candidateLabel:A.groupKey,initialName:A.groupKey,anchorSkillDir:A.anchorSkillDir})},title:"Write .claude-plugin/plugin.json into this folder so Claude Code recognizes it as a plugin",style:{fontSize:10,fontWeight:500,padding:"2px 8px",borderRadius:10,border:"1px solid var(--border-subtle, rgba(128,128,128,0.3))",background:"transparent",color:"var(--text-secondary)",cursor:"pointer",fontFamily:"var(--font-sans)"},children:"Not a plugin yet · Convert →"}),renderSkill:O=>t.jsx(en,{skill:O,isSelected:(r==null?void 0:r.plugin)===O.plugin&&(r==null?void 0:r.skill)===O.skill,onSelect:()=>n(O),onContextMenu:i,dirty:m==null?void 0:m.has(`${O.plugin}/${O.skill}`)})},`candidate-${A.groupKey}`)),t.jsx(Ur,{items:k.authoringProject.byPlugin.filter(([A])=>!k.authoringCandidatePlugins.some(O=>O.groupKey===A)),selectedKey:r,onSelect:n,onContextMenu:i,useVirtual:U,dirtySkillIds:m,repoVisibilityLookup:H})]})}),E&&t.jsx(Hr,{label:_.scopeLabels.sourcePlugin,storageKey:`vskill-sidebar-${y}-authoring-plugin-collapsed`,count:k.authoringPlugin.total,filteredCount:j?k.authoringPlugin.filtered:null,forceOpen:(G==null?void 0:G.bucket)==="plugin",children:k.authoringPlugin.filtered===0?t.jsx(Ng,{queryActive:!!j,hasSources:k.authoringPlugin.total>0,candidates:k.authoringCandidatePlugins,onPromote:A=>v({candidateLabel:A.groupKey,initialName:A.groupKey,anchorSkillDir:A.anchorSkillDir})}):k.authoringPlugin.byPlugin.map(([A,O])=>t.jsx(Rs,{pluginName:A,skills:O,persistKey:`vskill-plugin-authoring-${A}-collapsed`,forceOpen:(G==null?void 0:G.bucket)==="plugin"&&G.pluginName===A,renderSkill:V=>t.jsx(en,{skill:V,isSelected:(r==null?void 0:r.plugin)===V.plugin&&(r==null?void 0:r.skill)===V.skill,onSelect:()=>n(V),onContextMenu:i,dirty:m==null?void 0:m.has(`${V.plugin}/${V.skill}`)})},`authoring-${A}`))})]})]}),!s&&!o&&!b&&t.jsxs("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:[t.jsx(ui,{origin:"source",count:F.total,filteredCount:j?F.filtered:null,updateCount:c==null?void 0:c.source,children:F.filtered===0?t.jsx(fi,{queryActive:!!j}):t.jsx(Ur,{items:F.byPlugin,selectedKey:r,onSelect:n,onContextMenu:i,useVirtual:U,dirtySkillIds:m,repoVisibilityLookup:H})}),t.jsx(Rg,{}),t.jsx(ui,{origin:"installed",count:W.total,filteredCount:j?W.filtered:null,updateCount:c==null?void 0:c.installed,children:W.filtered===0?t.jsx(hi,{queryActive:!!j}):t.jsx(Ur,{items:W.byPlugin,selectedKey:r,onSelect:n,onContextMenu:i,useVirtual:U,dirtySkillIds:m,repoVisibilityLookup:H})})]}),x&&t.jsx(qx,{anchorSkillDir:x.anchorSkillDir,candidateLabel:x.candidateLabel,initialName:x.initialName,onCancel:()=>v(null),onConverted:A=>{v(null),g==null||g(),A.validation==="skipped"&&window.alert("Plugin manifest written, but schema validation was skipped because the 'claude' CLI is not on PATH. Install Claude Code to enable plugin schema validation.")}})]})}function Co(e){if(typeof window>"u")return!1;try{return window.localStorage.getItem(e)==="true"}catch{return!1}}function Hr({label:e,storageKey:r,count:n,filteredCount:s,updateCount:o,children:a,forceOpen:i=!1,headerRightSlot:c}){const[d,u]=l.useState(()=>Co(r)),p=i?!1:d,f=l.useCallback(()=>{u(m=>{const g=!m;if(typeof window<"u")try{window.localStorage.setItem(r,String(g))}catch{}return g})},[r]),h=s!=null&&s!==n?`${s} of ${n}`:String(n);return t.jsxs("section",{"data-vskill-named-scope":e,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 12px",gap:8},children:[t.jsxs("button",{type:"button",onClick:f,"aria-expanded":!p,style:{display:"flex",alignItems:"center",gap:8,flex:1,minWidth:0,padding:0,background:"transparent",border:"none",cursor:"pointer",fontFamily:"var(--font-sans)",textAlign:"left"},children:[t.jsx("span",{"aria-hidden":!0,style:{fontSize:14,fontWeight:700,color:"var(--color-ink, var(--text-primary))",width:16,display:"inline-block",textAlign:"center"},children:p?"▸":"▾"}),t.jsx("span",{style:{fontSize:12,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:"var(--text-primary)"},children:e}),t.jsxs("span",{style:{fontSize:11,color:"var(--text-tertiary)",fontVariantNumeric:"tabular-nums",fontFamily:"var(--font-mono)"},children:["(",h,")"]}),o!=null&&o>0&&t.jsxs("span",{style:{marginLeft:"auto",fontSize:10,color:"var(--color-own, #f59e0b)"},children:[o," update",o!==1?"s":""]})]}),c]}),!p&&t.jsx("div",{style:{paddingLeft:18},children:a})]})}function Sg(e){const r=[];for(const[n,s]of e){const o=[...s].sort((a,i)=>a.skill.localeCompare(i.skill));r.push({kind:"header",plugin:n,count:o.length});for(const a of o)r.push({kind:"row",skill:a})}return r}function Ur({items:e,selectedKey:r,onSelect:n,onContextMenu:s,useVirtual:o,dirtySkillIds:a,repoVisibilityLookup:i}){if(o){const c=Sg(e);return t.jsx("div",{"data-virtualized":"true",style:{height:420,minHeight:200},children:t.jsx(sx,{overscan:4,totalCount:c.length,itemContent:d=>{const u=c[d];if(!u)return null;if(u.kind==="header")return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"8px 12px 4px 14px"},children:[t.jsx("span",{style:{fontSize:10,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-secondary)",fontFamily:"var(--font-sans)"},children:u.plugin}),t.jsxs("span",{style:{fontSize:10,color:"var(--text-secondary)",fontVariantNumeric:"tabular-nums",fontFamily:"var(--font-mono)"},children:["(",u.count,")"]})]});const p=u.skill,f=!!r&&r.plugin===p.plugin&&r.skill===p.skill,h=i?zc(p.repoUrl):null,m=h?i.get(h)??null:null,g=m?m.isPrivate?"private":"public":"unknown";return t.jsx(en,{skill:p,isSelected:f,onSelect:()=>n(p),onContextMenu:s,dirty:a==null?void 0:a.has(`${p.plugin}/${p.skill}`),repoVisibility:g,repoFullName:(m==null?void 0:m.repoFullName)??null})}})})}return t.jsx("div",{"data-virtualized":"false",children:e.map(([c,d])=>t.jsx(Hx,{plugin:c,skills:d,selectedKey:r,onSelect:n,onContextMenu:s,dirtySkillIds:a,repoVisibilityLookup:i},c))})}function fi({queryActive:e}){return e?t.jsx(Ht,{headline:"No matches in this section.",body:"Adjust the filter or press Escape to clear."}):t.jsx(Ht,{headline:"No skills yet.",body:t.jsxs(t.Fragment,{children:["Create one with ",t.jsx(Tr,{children:"vskill new"})," or the"," ",t.jsx("strong",{style:{color:"var(--text-primary)"},children:"New skill"})," action in the top rail."]})})}function hi({queryActive:e,agentId:r}){return e?t.jsx(Ht,{headline:"No matches in this section.",body:"Adjust the filter or press Escape to clear."}):t.jsx(Ht,{headline:r?`No skills installed for ${r} in this project.`:"No installed skills.",body:t.jsxs(t.Fragment,{children:["Run ",t.jsx(Tr,{children:"vskill install <skill>"})," to add one."]})})}function Cg({queryActive:e,agentId:r}){return e?t.jsx(Ht,{headline:"No matches in this section.",body:"Adjust the filter or press Escape to clear."}):t.jsx(Ht,{headline:`No global skills for ${r}.`,body:t.jsxs(t.Fragment,{children:["Run ",t.jsx(Tr,{children:"vskill install --global <skill>"})," to add one."]})})}function Eg({queryActive:e,hasInstalled:r}){return e&&r?t.jsx(Ht,{headline:"No matches in this section.",body:"Adjust the filter or press Escape to clear."}):t.jsx(Ht,{headline:"No plugin skills installed yet.",body:t.jsxs(t.Fragment,{children:["Click ",t.jsx(Tr,{children:"Browse marketplaces…"})," above to add one."]})})}function Ng({queryActive:e,hasSources:r,candidates:n,onPromote:s}){return e&&r?t.jsx(Ht,{headline:"No matches in this section.",body:"Adjust the filter or press Escape to clear."}):t.jsxs(t.Fragment,{children:[t.jsx(Ht,{headline:"No plugin sources in this project.",body:t.jsxs(t.Fragment,{children:["Add ",t.jsx(Tr,{children:"<plugin>/.claude-plugin/plugin.json"})," to author one, or ",t.jsx(Tr,{children:"vskill plugin new"})," from the terminal."]})}),n&&n.length>0&&t.jsxs("div",{style:{padding:"0 14px 12px",display:"flex",flexDirection:"column",gap:6},children:[t.jsxs("div",{style:{fontSize:11,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:2},children:["Candidate folders (",n.length,")"]}),n.map(o=>t.jsxs("button",{type:"button",onClick:()=>s==null?void 0:s(o),title:`Promote ${o.groupKey}/ to a Claude Code plugin`,style:{display:"flex",justifyContent:"space-between",alignItems:"center",gap:8,padding:"6px 8px",fontSize:12,background:"transparent",border:"1px dashed var(--border-subtle, rgba(128,128,128,0.35))",borderRadius:4,color:"var(--text-primary)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-mono)"},children:[t.jsxs("span",{children:[o.groupKey,"/ ",t.jsxs("span",{style:{color:"var(--text-tertiary)"},children:["(",o.skills.length," skills)"]})]}),t.jsx("span",{style:{fontFamily:"var(--font-sans)",fontSize:11,color:"var(--text-secondary)"},children:"Promote →"})]},`promote-${o.groupKey}`))]})]})}function Ht({headline:e,body:r}){return t.jsxs("div",{style:{padding:"12px 14px 16px",fontSize:12,color:"var(--text-secondary)",lineHeight:1.5},children:[t.jsx("div",{style:{fontWeight:500,color:"var(--text-primary)",marginBottom:4},children:e}),t.jsx("div",{children:r})]})}function Tr({children:e}){return t.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-primary)",background:"color-mix(in srgb, var(--border-default) 45%, transparent)",padding:"1px 4px",borderRadius:3},children:e})}function Rg(){return t.jsx("div",{"aria-hidden":"true",style:{height:1,background:"var(--border-default)",margin:"4px 14px"}})}function Tg(){return t.jsx("div",{"aria-hidden":"true","data-testid":"scope-bold-divider",style:{height:3,background:"var(--color-rule)",boxShadow:"inset 0 1px 0 color-mix(in srgb, var(--color-rule) 50%, transparent)",margin:"12px 0"}})}function Ig(){return t.jsx("div",{style:{padding:"8px 0"},children:[0,1,2,3,4,5].map(e=>t.jsx(Jx,{},e))})}function Lg({error:e,onRetry:r}){return t.jsxs("div",{role:"alert",style:{margin:"12px 14px",padding:12,border:"1px solid var(--border-default)",borderRadius:6,background:"var(--bg-canvas)",color:"var(--text-primary)",fontSize:12},children:[t.jsx("div",{style:{fontWeight:600,marginBottom:4},children:"Couldn't load skills."}),t.jsxs("details",{children:[t.jsx("summary",{style:{cursor:"pointer",color:"var(--text-secondary)",fontSize:11,marginBottom:4},children:Ag(e)}),t.jsx("pre",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-secondary)",margin:"6px 0 0"},children:e})]}),r&&t.jsx("button",{type:"button",onClick:r,style:{marginTop:8,background:"transparent",border:"1px solid var(--border-default)",borderRadius:4,padding:"4px 10px",color:"var(--text-primary)",cursor:"pointer",fontSize:11,fontFamily:"var(--font-sans)"},children:"Retry"})]})}function Ag(e){const r=e.split(`
19
+ `)[0]??e;return r.length>80?r.slice(0,77)+"…":r}function Pg({projectRoot:e}){const{signedIn:r,tier:n}=gg();return r?t.jsx("span",{"data-testid":"sidebar-connected-repo-widget",onClick:()=>{typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:open-account-tab",{detail:{tab:"repos",initialPath:e}}))},style:{display:"inline-flex",cursor:"pointer"},children:t.jsx(_c,{folder:e,tier:n})}):t.jsx(tg,{projectRoot:e})}const Wc=240,Hc=480,Uc="vskill-sidebar-width",tn=320;function na(e){return Number.isFinite(e)?Math.round(Math.max(Wc,Math.min(Hc,e))):tn}function $g(){try{const e=localStorage.getItem(Uc);if(!e)return tn;const r=Number(e);return Number.isFinite(r)?na(r):tn}catch{return tn}}function Mg(e){try{localStorage.setItem(Uc,String(na(e)))}catch{}}function Dg({initialWidth:e,onChange:r}){const n=l.useRef({startX:0,startWidth:e,pointerId:null}),s=l.useRef(e);return l.useEffect(()=>{s.current=e},[e]),l.useEffect(()=>{function o(i){if(n.current.pointerId==null||i.pointerId!==n.current.pointerId)return;const c=i.clientX-n.current.startX,d=na(n.current.startWidth+c);s.current=d,r(d)}function a(i){n.current.pointerId==null||i.pointerId!==n.current.pointerId||(n.current.pointerId=null,Mg(s.current))}return window.addEventListener("pointermove",o),window.addEventListener("pointerup",a),window.addEventListener("pointercancel",a),()=>{window.removeEventListener("pointermove",o),window.removeEventListener("pointerup",a),window.removeEventListener("pointercancel",a)}},[r]),t.jsx("div",{role:"separator","aria-orientation":"vertical","aria-valuemin":Wc,"aria-valuemax":Hc,"aria-valuenow":e,"aria-label":"Resize sidebar",title:"Drag to resize sidebar",onPointerDown:o=>{const a=o.currentTarget;n.current.startX=o.clientX,n.current.startWidth=s.current,n.current.pointerId=o.pointerId;try{a.setPointerCapture(o.pointerId)}catch{}},style:{width:4,alignSelf:"stretch",cursor:"col-resize",background:"var(--border-default)",userSelect:"none",touchAction:"none"}})}const Fg=/^[ MADRCU?!]{1,2} +/;function zg(e){return e.replace(Fg,"")}function Bg(e,r){const n=e.endsWith("/")?e:e+"/";return r===e?"":r.startsWith(n)?r.slice(n.length):null}function _g(e,r,n){const s=new Set;if(r.length===0||e.length===0)return s;const o=r.map(a=>zg(a).trim()).filter(a=>a.length>0);for(const a of e){const i=a.dir;if(!i)continue;const c=Bg(n,i);if(c===null)continue;const d=`${a.plugin}/${a.skill}`;if(c===""){o.length>0&&s.add(d);continue}const u=c+"/";for(const p of o)if(p===c||p.startsWith(u)){s.add(d);break}}return s}const Og=5e3;function Wg(e,r,n=Og){const[s,o]=l.useState([]),a=l.useRef(e);return a.current=e,l.useEffect(()=>{if(!r){o([]);return}let i=!1,c=null;const d=async()=>{try{const p=await ie.gitStatus();i||o(p.paths??[])}catch{i||o([])}i||(c=setTimeout(d,n))};d();const u=()=>{d()};return typeof window<"u"&&window.addEventListener("studio:content-saved",u),()=>{i=!0,c&&clearTimeout(c),typeof window<"u"&&window.removeEventListener("studio:content-saved",u)}},[r,n]),r?_g(a.current,s,r):new Set}function Hg({connected:e,hint:r,onRetry:n}){return e?null:t.jsxs("aside",{"aria-live":"assertive",role:"alert",style:{display:"flex",alignItems:"center",gap:10,padding:"6px 12px",background:"color-mix(in srgb, var(--status-own) 15%, transparent)",borderBottom:"1px solid var(--border-default)",color:"var(--text-primary)",fontFamily:"var(--font-sans)",fontSize:12},children:[t.jsx("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:"var(--status-own)",display:"inline-block",flexShrink:0}}),t.jsx("span",{style:{fontWeight:500},children:"Disconnected — reconnecting…"}),r&&t.jsx("span",{style:{color:"var(--text-secondary)",fontSize:11},children:r}),t.jsx("div",{style:{flex:1}}),n&&t.jsx("button",{type:"button",onClick:n,style:{background:"transparent",border:"1px solid var(--border-default)",borderRadius:4,padding:"2px 8px",color:"var(--text-primary)",cursor:"pointer",fontSize:11,fontFamily:"var(--font-sans)"},children:"Retry now"})]})}function Vc(e,r){if(e!==401||typeof window>"u"||!r||typeof r!="object")return;const n=r;n.error==="invalid_api_key"&&(n.provider!=="anthropic"&&n.provider!=="openai"&&n.provider!=="openrouter"||window.dispatchEvent(new CustomEvent("studio:api-key-error",{detail:{provider:n.provider}})))}function Gc(e){if(e!==void 0)try{return JSON.stringify(e)}catch(r){console.error("Failed to serialize request body:",r);try{const n=new WeakSet;return JSON.stringify(e,(s,o)=>{if(typeof o=="object"&&o!==null){if(n.has(o))return"[Circular]";n.add(o)}return o})}catch{return JSON.stringify({error:"Request body could not be serialized"})}}}function Ls(){const[e,r]=l.useState([]),[n,s]=l.useState(!1),[o,a]=l.useState(!1),[i,c]=l.useState(null),d=l.useRef(null),u=l.useCallback(async(f,h)=>{r([]),s(!0),a(!1),c(null);const m=new AbortController;d.current=m;try{const g=Gc(h),x=await fetch(f,{method:"POST",headers:{"Content-Type":"application/json"},body:g,signal:m.signal});if(!x.ok||!x.body){let S=`HTTP ${x.status}`,w;try{w=await x.json(),w&&typeof w=="object"&&"error"in w&&typeof w.error=="string"&&(S=w.error)}catch{}throw Vc(x.status,w),new Error(S)}const v=x.body.getReader(),b=new TextDecoder;let y="",j="";for(;;){const{done:S,value:w}=await v.read();if(S)break;y+=b.decode(w,{stream:!0});const R=y.split(`
20
+ `);y=R.pop()||"";for(const k of R)if(k.startsWith("event: "))j=k.slice(7).trim();else if(k.startsWith("data: ")){try{const E=JSON.parse(k.slice(6)),C={event:j,data:E};j==="done"?(a(!0),r(N=>[...N,C])):r(N=>[...N,C])}catch{}j=""}}}catch(g){g.name!=="AbortError"&&c(g.message)}finally{s(!1),d.current=null}},[]),p=l.useCallback(()=>{var f;(f=d.current)==null||f.abort()},[]);return{events:e,running:n,done:o,error:i,start:u,stop:p}}function Ug(e){const r=l.useRef(e);r.current=e;const[n,s]=l.useState(new Set),o=l.useRef(new Map),a=l.useCallback(async(u,p,f)=>{var m;(m=o.current.get(u))==null||m.abort();const h=new AbortController;o.current.set(u,h),s(g=>{const x=new Set(g);return x.add(u),x});try{const g=Gc(f),x=await fetch(p,{method:"POST",headers:{"Content-Type":"application/json"},body:g,signal:h.signal});if(!x.ok||!x.body){let S=`HTTP ${x.status}`,w;try{w=await x.json(),w&&typeof w=="object"&&"error"in w&&typeof w.error=="string"&&(S=w.error)}catch{}throw Vc(x.status,w),new Error(S)}const v=x.body.getReader(),b=new TextDecoder;let y="",j="";for(;;){const{done:S,value:w}=await v.read();if(S)break;y+=b.decode(w,{stream:!0});const R=y.split(`
21
+ `);y=R.pop()||"";for(const k of R)if(k.startsWith("event: "))j=k.slice(7).trim();else if(k.startsWith("data: ")){try{const E=JSON.parse(k.slice(6)),C={event:j,data:E};r.current.onEvent(u,C)}catch{}j=""}}r.current.onDone(u)}catch(g){g.name!=="AbortError"&&r.current.onError(u,g.message)}finally{s(g=>{const x=new Set(g);return x.delete(u),x}),o.current.delete(u)}},[]),i=l.useCallback(u=>{var p;(p=o.current.get(u))==null||p.abort()},[]),c=l.useCallback(()=>{for(const u of o.current.values())u.abort()},[]),d=n.size>0;return{runningSet:n,startCase:a,stopCase:i,stopAll:c,isAnyCaseRunning:d}}const Vg={plugin:"",skill:"",skillContent:"",savedContent:"",isDirty:!1,evals:null,evalsError:null,activePanel:"tests",selectedCaseId:null,caseRunStates:new Map,bulkRunActive:!1,runMode:null,latestBenchmark:null,inlineResults:new Map,improveTarget:null,aiEditOpen:!1,aiEditLoading:!1,aiEditResult:null,aiEditError:null,aiEditClassifiedError:null,aiEditProgress:[],aiEditEvalChanges:[],aiEditEvalSelections:new Map,aiEditEvalsRetry:null,generateEvalsLoading:!1,generateEvalsProgress:[],generateEvalsError:null,regressions:[],iterationCount:0,activationPrompts:"",activationResults:[],activationSummary:null,activationRunning:!1,activationError:null,activationTotalPrompts:0,activationStartedAt:null,activationClassifyingStatus:null,generatingPrompts:!1,generatingPromptsError:null,activationPromptsSource:null,activationPromptsCanonical:"",savingTestCases:!1,savingTestCasesError:null,savingTestCasesSuccess:null,activationHistory:null,activationHistoryLoading:!1,loading:!0,error:null};function Gg(e,r){var n,s;switch(r.type){case"SET_LOADING":return{...e,loading:r.loading};case"SET_ERROR":return{...e,error:r.error};case"INIT_DATA":{const o=new Map;if(r.benchmark)for(const i of r.benchmark.cases)o.set(i.eval_id,{status:i.status,passRate:i.pass_rate,errorMessage:i.error_message||void 0,durationMs:i.durationMs,tokens:i.tokens,output:i.output,assertions:i.assertions.map(c=>({assertion_id:c.id,text:c.text,pass:c.pass,reasoning:c.reasoning}))});const a=((s=(n=r.evals)==null?void 0:n.evals[0])==null?void 0:s.id)??null;return{...e,skillContent:r.skillContent,savedContent:r.skillContent,isDirty:!1,evals:r.evals,evalsError:r.evalsError??null,latestBenchmark:r.benchmark,inlineResults:o,selectedCaseId:a,loading:!1,error:null}}case"SET_PANEL":return{...e,activePanel:r.panel};case"SET_CONTENT":return{...e,skillContent:r.content,isDirty:r.content!==e.savedContent};case"CONTENT_SAVED":return{...e,savedContent:e.skillContent,isDirty:!1};case"SET_EVALS":return{...e,evals:r.evals};case"SELECT_CASE":return{...e,selectedCaseId:r.caseId};case"CASE_RUN_START":{const o=new Map(e.caseRunStates);return o.set(r.caseId,{status:"running",startedAt:Date.now(),mode:r.mode}),{...e,caseRunStates:o,runMode:r.mode,activePanel:"run"}}case"CASE_RUN_COMPLETE":{const o=new Map(e.caseRunStates),a=o.get(r.caseId);o.set(r.caseId,{status:"complete",mode:a==null?void 0:a.mode});const i=new Map(e.inlineResults);return i.set(r.caseId,r.result),{...e,caseRunStates:o,inlineResults:i}}case"CASE_RUN_ERROR":{const o=new Map(e.caseRunStates),a=o.get(r.caseId);o.set(r.caseId,{status:"error",mode:a==null?void 0:a.mode});const i=new Map(e.inlineResults);return i.set(r.caseId,{status:"error",errorMessage:r.error,assertions:[]}),{...e,caseRunStates:o,inlineResults:i}}case"CASE_RUN_CANCEL":{const o=new Map(e.caseRunStates),a=o.get(r.caseId);return o.set(r.caseId,{status:"cancelled",mode:a==null?void 0:a.mode}),{...e,caseRunStates:o}}case"BULK_RUN_START":{const o=new Map(e.caseRunStates);for(const a of r.caseIds)o.set(a,{status:"queued",mode:r.mode});return{...e,caseRunStates:o,bulkRunActive:!0,runMode:r.mode,activePanel:"run"}}case"BULK_RUN_COMPLETE":return{...e,bulkRunActive:!1,latestBenchmark:r.benchmark??e.latestBenchmark,iterationCount:e.iterationCount+1};case"CANCEL_ALL":{const o=new Map(e.caseRunStates);for(const[a,i]of o)(i.status==="running"||i.status==="queued")&&o.set(a,{status:"cancelled"});return{...e,caseRunStates:o,bulkRunActive:!1}}case"UPDATE_INLINE_RESULT":{const o=new Map(e.inlineResults);return o.set(r.evalId,r.result),{...e,inlineResults:o}}case"OPEN_IMPROVE":return{...e,improveTarget:r.evalId,activePanel:"editor"};case"CLOSE_IMPROVE":return{...e,improveTarget:null};case"OPEN_AI_EDIT":return{...e,aiEditOpen:!0,aiEditResult:null,aiEditError:null,aiEditClassifiedError:null,aiEditProgress:[],aiEditEvalChanges:[],aiEditEvalSelections:new Map,aiEditEvalsRetry:null};case"CLOSE_AI_EDIT":return{...e,aiEditOpen:!1,aiEditLoading:!1,aiEditResult:null,aiEditError:null,aiEditClassifiedError:null,aiEditProgress:[],aiEditEvalChanges:[],aiEditEvalSelections:new Map,aiEditEvalsRetry:null};case"AI_EDIT_LOADING":return{...e,aiEditLoading:!0,aiEditError:null,aiEditClassifiedError:null,aiEditProgress:[]};case"AI_EDIT_PROGRESS":return{...e,aiEditProgress:[...e.aiEditProgress,r.entry]};case"AI_EDIT_RESULT":{const o=r.evalChanges??[],a=new Map;for(let i=0;i<o.length;i++)a.set(i,!0);return{...e,aiEditLoading:!1,aiEditResult:{improved:r.improved,reasoning:r.reasoning,evalChanges:o},aiEditEvalChanges:o,aiEditEvalSelections:a}}case"AI_EDIT_ERROR":return{...e,aiEditLoading:!1,aiEditError:r.message,aiEditClassifiedError:r.classified??null};case"GENERATE_EVALS_START":return{...e,generateEvalsLoading:!0,generateEvalsProgress:[],generateEvalsError:null};case"GENERATE_EVALS_PROGRESS":return{...e,generateEvalsProgress:[...e.generateEvalsProgress,r.entry]};case"GENERATE_EVALS_DONE":return{...e,generateEvalsLoading:!1,evals:r.evals};case"GENERATE_EVALS_ERROR":return{...e,generateEvalsLoading:!1,generateEvalsError:r.classified};case"TOGGLE_EVAL_CHANGE":{const o=new Map(e.aiEditEvalSelections);return o.set(r.index,!o.get(r.index)),{...e,aiEditEvalSelections:o}}case"SELECT_ALL_EVAL_CHANGES":{const o=new Map(e.aiEditEvalSelections);for(const a of o.keys())o.set(a,!0);return{...e,aiEditEvalSelections:o}}case"DESELECT_ALL_EVAL_CHANGES":{const o=new Map(e.aiEditEvalSelections);for(const a of o.keys())o.set(a,!1);return{...e,aiEditEvalSelections:o}}case"SET_EVALS_RETRY":return{...e,aiEditEvalsRetry:r.evalsFile};case"SET_REGRESSIONS":return{...e,regressions:r.regressions};case"INCREMENT_ITERATION":return{...e,iterationCount:e.iterationCount+1};case"SET_ACTIVATION_PROMPTS":{const o=r.prompts===e.activationPromptsCanonical;return{...e,activationPrompts:r.prompts,activationPromptsSource:o?e.activationPromptsSource:e.activationPromptsSource===null||e.activationPromptsSource==="skill-md"||e.activationPromptsSource==="ai-generated"?"user-typed":e.activationPromptsSource}}case"SET_PROMPTS_SOURCE":return{...e,activationPromptsSource:r.source,activationPromptsCanonical:r.canonical??e.activationPromptsCanonical};case"ACTIVATION_START":return{...e,activationRunning:!0,activationResults:[],activationSummary:null,activationError:null,activationClassifyingStatus:null,activationStartedAt:Date.now()};case"ACTIVATION_RESULT":return{...e,activationResults:[...e.activationResults,r.result]};case"ACTIVATION_DONE":return{...e,activationRunning:!1,activationSummary:r.summary,activationClassifyingStatus:null};case"ACTIVATION_CLASSIFYING":return{...e,activationClassifyingStatus:`Classifying prompt ${r.index}/${r.total}...`};case"ACTIVATION_ERROR":return{...e,activationRunning:!1,activationError:r.error,activationClassifyingStatus:null};case"ACTIVATION_RESET":return{...e,activationResults:[],activationSummary:null,activationError:null};case"ACTIVATION_TIMEOUT":return{...e,activationRunning:!1,activationError:"Activation test timed out after 120 seconds"};case"ACTIVATION_CANCEL":return{...e,activationRunning:!1};case"GENERATE_PROMPTS_START":return{...e,generatingPrompts:!0,generatingPromptsError:null};case"GENERATE_PROMPTS_DONE":return{...e,generatingPrompts:!1};case"GENERATE_PROMPTS_ERROR":return{...e,generatingPrompts:!1,generatingPromptsError:r.error};case"SAVE_TEST_CASES_START":return{...e,savingTestCases:!0,savingTestCasesError:null,savingTestCasesSuccess:null};case"SAVE_TEST_CASES_SUCCESS":return{...e,savingTestCases:!1,savingTestCasesSuccess:`Saved ${r.count} test case${r.count===1?"":"s"} to SKILL.md`,activationPromptsSource:"skill-md",activationPromptsCanonical:e.activationPrompts};case"SAVE_TEST_CASES_ERROR":return{...e,savingTestCases:!1,savingTestCasesError:r.error};case"CLEAR_SAVE_TEST_CASES_FEEDBACK":return{...e,savingTestCasesSuccess:null,savingTestCasesError:null};case"ACTIVATION_HISTORY_LOADED":return{...e,activationHistory:r.runs,activationHistoryLoading:!1};default:return e}}function Kg(e,r){if(!e)return{canEdit:!1,canRun:!1};const n=e.origin==="source",s=r.exists&&r.cases.length>0;return{canEdit:n,canRun:s}}function qg(e){if(e==="unit"||e==="integration")return e}function Yg(e,r){const n=r.data;if(r.event==="output_ready"&&(e.output=n.output,n.durationMs!=null&&(e.durationMs=n.durationMs),n.tokens!=null&&(e.tokens=n.tokens)),r.event==="outputs_ready"&&(e.output=n.skillOutput,n.skillDurationMs!=null&&(e.durationMs=n.skillDurationMs),n.skillTokens!=null&&(e.tokens=n.skillTokens)),r.event==="assertion_result"){const s={assertion_id:n.assertion_id,text:n.text,pass:n.pass,reasoning:n.reasoning};e.assertions.find(o=>o.assertion_id===s.assertion_id)||e.assertions.push(s)}r.event==="case_complete"&&(e.status=n.status,e.passRate=n.pass_rate,e.errorMessage=n.error_message||void 0,e.classifiedError=n.classified_error||void 0)}const Kc=l.createContext(null);function ft(){const e=l.useContext(Kc);if(!e)throw new Error("useWorkspace must be used within WorkspaceProvider");return e}function Jg({plugin:e,skill:r,origin:n,children:s}){var fe;const o=n==="installed",{config:a}=hr(),[i,c]=l.useReducer(Gg,{...Vg,plugin:e,skill:r}),d=Kg({origin:n},{exists:i.evals!=null,cases:((fe=i.evals)==null?void 0:fe.evals)??[]}),u=d.canEdit,p=d.canRun,f=l.useRef(new Set),h=l.useRef(new Set),m=l.useRef(new Map),g=l.useCallback((z,q)=>{let Z=m.current.get(z);Z||(Z={assertions:[]},m.current.set(z,Z)),Yg(Z,q),c({type:"UPDATE_INLINE_RESULT",evalId:z,result:{...Z,assertions:[...Z.assertions]}})},[]),x=l.useCallback(z=>{if(h.current.has(z))return;h.current.add(z);const q=m.current.get(z)??{assertions:[]};c({type:"CASE_RUN_COMPLETE",caseId:z,result:{...q,assertions:[...q.assertions]}}),f.current.has(z)&&(f.current.delete(z),f.current.size===0&&ie.getLatestBenchmark(e,r).then(Z=>c({type:"BULK_RUN_COMPLETE",benchmark:Z})).catch(()=>c({type:"BULK_RUN_COMPLETE",benchmark:null})))},[e,r]),v=l.useCallback((z,q)=>{h.current.has(z)||(h.current.add(z),c({type:"CASE_RUN_ERROR",caseId:z,error:q}),f.current.has(z)&&(f.current.delete(z),f.current.size===0&&ie.getLatestBenchmark(e,r).then(Z=>c({type:"BULK_RUN_COMPLETE",benchmark:Z})).catch(()=>c({type:"BULK_RUN_COMPLETE",benchmark:null}))))},[e,r]),{startCase:b,stopCase:y,stopAll:j}=Ug({onEvent:g,onDone:x,onError:v});l.useEffect(()=>()=>{j()},[j]);const S=l.useCallback(async()=>{try{const z=await fetch(`/api/skills/${e}/${r}/activation-history`);if(!z.ok){if(z.status===404){c({type:"ACTIVATION_HISTORY_LOADED",runs:[]});return}return}const q=await z.json();c({type:"ACTIVATION_HISTORY_LOADED",runs:q.runs||[]})}catch{}},[e,r]);l.useEffect(()=>{let z=!1;async function q(){try{const[Z,J,ue]=await Promise.allSettled([ie.getSkillDetail(e,r),ie.getEvals(e,r),ie.getLatestBenchmark(e,r)]);if(z)return;let de=null,we=null;if(J.status==="fulfilled")de=J.value;else{const Ie=J.reason;we=(Ie==null?void 0:Ie.message)??"Failed to load test cases"}c({type:"INIT_DATA",skillContent:Z.status==="fulfilled"?Z.value.skillContent:"",evals:de,evalsError:we,benchmark:ue.status==="fulfilled"?ue.value:null})}catch(Z){z||c({type:"SET_ERROR",error:Z.message})}}return q(),S(),()=>{z=!0}},[e,r,S]);const w=l.useCallback(async z=>{if(o)return;const q=z??i.skillContent;try{await ie.applyImprovement(e,r,q),z!==void 0&&z!==i.skillContent&&c({type:"SET_CONTENT",content:z}),c({type:"CONTENT_SAVED"})}catch(Z){c({type:"SET_ERROR",error:Z.message})}},[o,e,r,i.skillContent]),R=l.useCallback(async z=>{if(!o)try{const q=await ie.saveEvals(e,r,z);c({type:"SET_EVALS",evals:q})}catch(q){c({type:"SET_ERROR",error:q.message})}},[o,e,r]),k=l.useCallback((z,q="benchmark")=>{const Z=i.caseRunStates.get(z);if((Z==null?void 0:Z.status)==="running")return;m.current.delete(z),h.current.delete(z),c({type:"CASE_RUN_START",caseId:z,mode:q});const J=q==="comparison"?{eval_ids:[z]}:q==="baseline"?{mode:"baseline"}:{};if(a!=null&&a.provider&&(J.provider=a.provider),a!=null&&a.model&&(J.model=a.model),q==="comparison"){const ue=`/api/skills/${e}/${r}/compare`;b(z,ue,J)}else{const ue=`/api/skills/${e}/${r}/benchmark/case/${z}`;b(z,ue,Object.keys(J).length>0?J:void 0)}},[e,r,i.caseRunStates,b,a]),E=l.useCallback((z="benchmark")=>{var J;const q=((J=i.evals)==null?void 0:J.evals)??[];if(q.length===0)return;const Z=q.map(ue=>ue.id);for(const ue of Z)m.current.delete(ue),h.current.delete(ue);c({type:"BULK_RUN_START",caseIds:Z,mode:z}),f.current=new Set(Z);for(const ue of Z){const de=z==="comparison"?{eval_ids:[ue]}:z==="baseline"?{mode:"baseline"}:{};if(a!=null&&a.provider&&(de.provider=a.provider),a!=null&&a.model&&(de.model=a.model),z==="comparison")b(ue,`/api/skills/${e}/${r}/compare`,de);else{const we=`/api/skills/${e}/${r}/benchmark/case/${ue}`;b(ue,we,Object.keys(de).length>0?de:void 0)}}},[e,r,i.evals,b,a]),C=l.useCallback(z=>{y(z),c({type:"CASE_RUN_CANCEL",caseId:z}),f.current.delete(z),h.current.add(z)},[y]),N=l.useCallback(()=>{j(),c({type:"CANCEL_ALL"}),f.current.clear()},[j]),I=l.useCallback(async(z,q)=>{c({type:"OPEN_IMPROVE",evalId:z})},[]),P=l.useCallback(async(z,q)=>{try{await ie.applyImprovement(e,r,q),c({type:"SET_CONTENT",content:q}),c({type:"CONTENT_SAVED"}),c({type:"CLOSE_IMPROVE"}),k(z,"benchmark")}catch(Z){c({type:"SET_ERROR",error:Z.message})}},[e,r,k]),L=Ls(),B=l.useRef(null),T=l.useRef(0);l.useEffect(()=>{const z=L.events;for(let q=T.current;q<z.length;q++){const Z=z[q],J=Z.data;if(Z.event==="progress"&&c({type:"AI_EDIT_PROGRESS",entry:{timestamp:Date.now(),phase:J.phase,message:J.message}}),Z.event==="done"){const ue=J.improved,de=J.reasoning,we=J.evalChanges??[];c({type:"AI_EDIT_RESULT",improved:ue,reasoning:de,evalChanges:we})}if(Z.event==="error"){const ue=J;c({type:"AI_EDIT_ERROR",message:ue.description||"Unknown error",classified:ue})}}T.current=z.length},[L.events]),l.useEffect(()=>{L.error&&c({type:"AI_EDIT_ERROR",message:L.error})},[L.error]),l.useEffect(()=>()=>{L.stop()},[L.stop]);const $=l.useCallback(async(z,q,Z)=>{o||(T.current=0,c({type:"AI_EDIT_LOADING"}),B.current=L.stop,L.start(`/api/skills/${e}/${r}/improve?sse`,{mode:"instruct",instruction:z,content:i.skillContent,evals:i.evals??{skill_name:r,evals:[]},provider:q,model:Z}))},[o,e,r,i.skillContent,i.evals,L]),M=l.useCallback(()=>{L.stop(),c({type:"AI_EDIT_ERROR",message:"Cancelled"})},[L]),F=l.useCallback(async()=>{const z=i.aiEditResult;if(z!=null&&z.improved)try{if(await ie.applyImprovement(e,r,z.improved),c({type:"SET_CONTENT",content:z.improved}),c({type:"CONTENT_SAVED"}),i.aiEditEvalChanges.length>0&&Array.from(i.aiEditEvalSelections.values()).some(Boolean)){const{mergeEvalChanges:Z}=await Lr(async()=>{const{mergeEvalChanges:de}=await import("./mergeEvalChanges-Dpbbs4d4.js");return{mergeEvalChanges:de}},[]),J=i.evals??{skill_name:r,evals:[]},ue=Z(J,i.aiEditEvalChanges,i.aiEditEvalSelections);try{const de=await ie.saveEvals(e,r,ue);c({type:"SET_EVALS",evals:de})}catch(de){c({type:"SET_EVALS_RETRY",evalsFile:ue}),c({type:"SET_ERROR",error:`SKILL.md saved, but test cases failed to save: ${de.message}. You can retry from the AI Edit panel.`});return}}c({type:"CLOSE_AI_EDIT"})}catch(q){c({type:"SET_ERROR",error:q.message})}},[e,r,i.aiEditResult,i.evals,i.aiEditEvalChanges,i.aiEditEvalSelections]),W=l.useCallback(()=>{c({type:"CLOSE_AI_EDIT"})},[]),le=l.useCallback(z=>{c({type:"TOGGLE_EVAL_CHANGE",index:z})},[]),U=l.useCallback(()=>{c({type:"SELECT_ALL_EVAL_CHANGES"})},[]),H=l.useCallback(()=>{c({type:"DESELECT_ALL_EVAL_CHANGES"})},[]),ee=l.useCallback(async()=>{const z=i.aiEditEvalsRetry;if(z)try{const q=await ie.saveEvals(e,r,z);c({type:"SET_EVALS",evals:q}),c({type:"SET_ERROR",error:null}),c({type:"CLOSE_AI_EDIT"})}catch(q){c({type:"SET_ERROR",error:`Retry failed: ${q.message}`})}},[e,r,i.aiEditEvalsRetry]),K=l.useCallback(async()=>{try{const z=await ie.getSkillDetail(e,r);c({type:"SET_CONTENT",content:z.skillContent}),c({type:"CONTENT_SAVED"})}catch{}},[e,r]),X=Ls(),G=l.useRef(0);l.useEffect(()=>{const z=X.events;for(let q=G.current;q<z.length;q++){const Z=z[q],J=Z.data;if(Z.event==="progress"&&c({type:"GENERATE_EVALS_PROGRESS",entry:{timestamp:Date.now(),phase:J.phase,message:J.message}}),Z.event==="done"){const ue=J;ie.saveEvals(e,r,ue).then(de=>c({type:"GENERATE_EVALS_DONE",evals:de})).catch(de=>c({type:"SET_ERROR",error:de.message}))}Z.event==="error"&&c({type:"GENERATE_EVALS_ERROR",classified:J})}G.current=z.length},[X.events,e,r]),l.useEffect(()=>{X.error&&c({type:"SET_ERROR",error:X.error})},[X.error]),l.useEffect(()=>()=>{X.stop()},[X.stop]);const he=l.useCallback(async z=>{if(o)return;G.current=0,c({type:"GENERATE_EVALS_START"});const q={};a!=null&&a.provider&&(q.provider=a.provider),a!=null&&a.model&&(q.model=a.model);const Z=qg(z==null?void 0:z.testType);Z&&(q.testType=Z),X.start(`/api/skills/${e}/${r}/generate-evals?sse`,Object.keys(q).length>0?q:void 0)},[o,e,r,X,a]),A=Ls(),O=l.useRef(0);l.useEffect(()=>()=>{A.stop()},[A.stop]),l.useEffect(()=>{const z=A.events;for(let q=O.current;q<z.length;q++){const Z=z[q];if(Z.event==="classifying"){const J=Z.data;c({type:"ACTIVATION_CLASSIFYING",index:J.index,total:J.total})}if(Z.event==="prompt_result"&&c({type:"ACTIVATION_RESULT",result:Z.data}),Z.event==="done"){V.current&&(clearTimeout(V.current),V.current=null);const J=Z.data;if(J.error)c({type:"ACTIVATION_ERROR",error:J.error});else{c({type:"ACTIVATION_DONE",summary:J});const ue={id:`run-${Date.now()}`,timestamp:new Date().toISOString(),model:(a==null?void 0:a.model)||"unknown",provider:(a==null?void 0:a.provider)||"unknown",promptCount:J.total,summary:{precision:J.precision,recall:J.recall,reliability:J.reliability,tp:J.tp,tn:J.tn,fp:J.fp,fn:J.fn}};c({type:"ACTIVATION_HISTORY_LOADED",runs:[ue,...i.activationHistory??[]]})}}}O.current=z.length},[A.events,a,i.activationHistory]),l.useEffect(()=>{A.error&&(V.current&&(clearTimeout(V.current),V.current=null),c({type:"ACTIVATION_ERROR",error:A.error}))},[A.error]);const V=l.useRef(null),re=l.useCallback(()=>{V.current&&(clearTimeout(V.current),V.current=null),A.stop(),c({type:"ACTIVATION_CANCEL",totalPrompts:0})},[A]),ce=l.useCallback(z=>{const Z=z.trim().split(`
22
+ `).filter(Boolean).map(ue=>ue.startsWith("!")?{prompt:ue.slice(1).trim(),expected:"should_not_activate"}:ue.startsWith("+")?{prompt:ue.slice(1).trim(),expected:"should_activate"}:{prompt:ue.trim(),expected:"auto"});O.current=0,c({type:"ACTIVATION_START"}),c({type:"SET_ACTIVATION_PROMPTS",prompts:z});const J={prompts:Z};a!=null&&a.provider&&(J.provider=a.provider),a!=null&&a.model&&(J.model=a.model),A.start(`/api/skills/${e}/${r}/activation-test`,J),V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{A.stop(),c({type:"ACTIVATION_TIMEOUT"}),V.current=null},12e4)},[e,r,A,a]),ne=l.useCallback(async(z=8)=>{c({type:"GENERATE_PROMPTS_START"});try{const q={count:z};a!=null&&a.provider&&(q.provider=a.provider),a!=null&&a.model&&(q.model=a.model);const Z=await fetch(`/api/skills/${e}/${r}/activation-prompts`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(q)});if(!Z.ok){let Ke=`HTTP ${Z.status}`;try{const Ye=await Z.json();Ye.error&&(Ke=Ye.error)}catch{}throw new Error(Ke)}const J=Z.body.getReader(),ue=new TextDecoder;let de="",we="",Ie=[];for(;;){const{done:Ke,value:Ye}=await J.read();if(Ke)break;de+=ue.decode(Ye,{stream:!0});const Q=de.split(`
23
+ `);de=Q.pop()||"";for(const Re of Q)if(Re.startsWith("event: "))we=Re.slice(7).trim();else if(Re.startsWith("data: ")){try{const je=JSON.parse(Re.slice(6));if(we==="done"){if(je.error)throw new Error(je.error);Ie=je.prompts||[]}if(we==="error")throw new Error(je.message||je.description||"Generation failed")}catch(je){if(!(je instanceof SyntaxError))throw je}we=""}}const Fe=Ie.map(Ke=>`${Ke.expected==="should_activate"?"+":"!"}${Ke.prompt}`).join(`
24
+ `);c({type:"SET_PROMPTS_SOURCE",source:"ai-generated",canonical:Fe}),c({type:"SET_ACTIVATION_PROMPTS",prompts:Fe}),c({type:"GENERATE_PROMPTS_DONE"})}catch(q){c({type:"GENERATE_PROMPTS_ERROR",error:q.message})}},[e,r,a]),ve=l.useCallback(async()=>{try{const z=await fetch(`/api/skills/${e}/${r}/test-cases`);if(!z.ok)return;const q=await z.json();if(!q.prompts||q.prompts.length===0)return;const Z=q.prompts.map(J=>J.expected==="should_activate"?`+${J.prompt}`:J.expected==="should_not_activate"?`!${J.prompt}`:J.prompt).join(`
25
+ `);c({type:"SET_PROMPTS_SOURCE",source:"skill-md",canonical:Z}),c({type:"SET_ACTIVATION_PROMPTS",prompts:Z})}catch{}},[e,r]),ge=l.useCallback(async()=>{c({type:"SAVE_TEST_CASES_START"});try{const q=i.activationPrompts.split(`
26
+ `).map(ue=>ue.trim()).filter(Boolean).map(ue=>ue.startsWith("!")?{prompt:ue.slice(1).trim(),expected:"should_not_activate"}:ue.startsWith("+")?{prompt:ue.slice(1).trim(),expected:"should_activate"}:{prompt:ue,expected:"auto"}),Z=await fetch(`/api/skills/${e}/${r}/test-cases`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompts:q})}),J=await Z.json().catch(()=>({}));if(!Z.ok||!J.ok)throw new Error(J.error||`HTTP ${Z.status}`);c({type:"SAVE_TEST_CASES_SUCCESS",count:J.count??q.length}),setTimeout(()=>c({type:"CLEAR_SAVE_TEST_CASES_FEEDBACK"}),3e3)}catch(z){c({type:"SAVE_TEST_CASES_ERROR",error:z.message})}},[e,r,i.activationPrompts]),se=l.useMemo(()=>({state:i,dispatch:c,isReadOnly:o,canEdit:u,canRun:p,saveContent:w,saveEvals:R,runCase:k,runAll:E,cancelCase:C,cancelAll:N,improveForCase:I,applyImproveAndRerun:P,refreshSkillContent:K,generateEvals:he,runActivationTest:ce,cancelActivation:re,generateActivationPrompts:ne,fetchActivationHistory:S,loadTestCasesFromSkillMd:ve,saveTestCasesToSkillMd:ge,submitAiEdit:$,cancelAiEdit:M,applyAiEdit:F,discardAiEdit:W,toggleEvalChange:le,selectAllEvalChanges:U,deselectAllEvalChanges:H,retryEvalsSave:ee}),[i,o,u,p,w,R,k,E,C,N,I,P,K,he,ce,re,ne,S,ve,ge,$,M,F,W,le,U,H,ee]);return t.jsx(Kc.Provider,{value:se,children:s})}function qc(e){const r=e.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);if(!r)return{metadata:{},body:e};const n=r[1],s=r[2].trim(),o={},a=n.split(`
27
+ `);let i="",c=!1;for(const d of a){const u=d.match(/^[ \t]+([\w-]+):\s*(.*)$/);if(u&&i&&c){const h=u[1],m=u[2].trim();let g=o[i];if((typeof g!="object"||Array.isArray(g))&&(g={},o[i]=g),!m)g[h]=[];else{const x=m.match(/^\[(.+)\]$/);x?g[h]=x[1].split(",").map(v=>v.trim().replace(/^["']|["']$/g,"")).filter(Boolean):g[h]=m.replace(/^["']|["']$/g,"")}continue}const p=d.match(/^\s+-\s+(.+)$/);if(p&&i){c=!1;const h=o[i];Array.isArray(h)?h.push(p[1].trim().replace(/^["']|["']$/g,"")):o[i]=[p[1].trim().replace(/^["']|["']$/g,"")];continue}const f=d.match(/^([\w-]+):\s*(.*)$/);if(f){i=f[1];const h=f[2].trim();if(c=!1,!h){o[i]={},c=!0;continue}const m=h.match(/^\[(.+)\]$/);if(m){o[i]=m[1].split(",").map(g=>g.trim().replace(/^["']|["']$/g,"")).filter(Boolean);continue}o[i]=h.replace(/^["']|["']$/g,"")}}return{metadata:o,body:s}}function bn(e){if(!e)return"";try{let r=e.replace(/^---\n[\s\S]*?\n---\n?/,""),n=Xg(r);return n=n.replace(/```(\w*)\n([\s\S]*?)```/g,'<pre style="background:var(--surface-2);padding:0.75rem;border-radius:6px;overflow-x:auto;font-size:12px;line-height:1.5;margin:0.5rem 0;border:1px solid var(--border-subtle)"><code>$2</code></pre>'),n=n.replace(/^### (.+)$/gm,'<div style="font-weight:600;font-size:14px;margin:0.75rem 0 0.25rem;color:var(--text-primary)">$1</div>'),n=n.replace(/^## (.+)$/gm,'<div style="font-weight:700;font-size:15px;margin:0.75rem 0 0.25rem;color:var(--text-primary)">$1</div>'),n=n.replace(/^# (.+)$/gm,'<div style="font-weight:700;font-size:1rem;margin:0.75rem 0 0.25rem;color:var(--text-primary)">$1</div>'),n=n.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer" style="color:var(--accent);text-decoration:underline">$1</a>'),n=n.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>"),n=n.replace(/\*([^*]+)\*/g,"<em>$1</em>"),n=n.replace(/`([^`]+)`/g,'<code style="background:var(--surface-3);padding:0.1rem 0.3rem;border-radius:3px;font-size:0.85em">$1</code>'),n=n.replace(/^- (.+)$/gm,'<div style="padding-left:1rem;margin:0.15rem 0">• $1</div>'),n=n.replace(/^(\d+)\. (.+)$/gm,'<div style="padding-left:1rem;margin:0.15rem 0">$1. $2</div>'),n=n.replace(/\n\n/g,'<div style="height:0.5rem"></div>'),n=n.replace(/\n/g,"<br/>"),n}catch{return`<pre style="white-space:pre-wrap;font-size:12px;line-height:1.5">${e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}</pre>`}}function Xg(e){const r=e.split(`
28
+ `),n=[];let s=0;for(;s<r.length;)if(r[s].trim().startsWith("|")&&s+1<r.length&&r[s+1].trim().startsWith("|")&&/\|[\s-:]+\|/.test(r[s+1])){const o=mi(r[s]);s+=2;const a=[];for(;s<r.length&&r[s].trim().startsWith("|");)a.push(mi(r[s])),s++;const i='style="text-align:left;padding:0.4rem 0.6rem;font-weight:600;font-size:12px;color:var(--text-primary);border-bottom:1px solid var(--border-default)"',c='style="padding:0.4rem 0.6rem;font-size:12px;color:var(--text-secondary);border-bottom:1px solid var(--border-subtle)"';let d='<table style="width:100%;border-collapse:collapse;margin:0.5rem 0;border:1px solid var(--border-subtle);border-radius:6px;overflow:hidden">';d+="<thead><tr>";for(const u of o)d+=`<th ${i}>${u}</th>`;d+="</tr></thead><tbody>";for(const u of a){d+="<tr>";for(const p of u)d+=`<td ${c}>${p}</td>`;d+="</tr>"}d+="</tbody></table>",n.push(d)}else n.push(r[s]),s++;return n.join(`
29
+ `)}function mi(e){return e.split("|").map(r=>r.trim()).filter(r=>r.length>0)}function ds(e,r){const n=e.split(`
30
+ `),s=r.split(`
31
+ `);if(n.length>1e3||s.length>1e3)return[...n.map(p=>({type:"unchanged",content:p}))];const o=n.length,a=s.length,i=Array.from({length:o+1},()=>new Array(a+1).fill(0));for(let p=1;p<=o;p++)for(let f=1;f<=a;f++)n[p-1]===s[f-1]?i[p][f]=i[p-1][f-1]+1:i[p][f]=Math.max(i[p-1][f],i[p][f-1]);const c=[];let d=o,u=a;for(;d>0||u>0;)d>0&&u>0&&n[d-1]===s[u-1]?(c.push({type:"unchanged",content:n[d-1]}),d--,u--):u>0&&(d===0||i[d][u-1]>=i[d-1][u])?(c.push({type:"added",content:s[u-1]}),u--):(c.push({type:"removed",content:n[d-1]}),d--);return c.reverse()}function Qg(e,r){if(r&&new Set(["generating","comparing","judging","judging_assertion","preparing","parsing","generating_skill","generating_baseline","scoring","action_items"]).has(e))return t.jsx("div",{className:"spinner",style:{width:10,height:10,flexShrink:0}});const s=new Set(["generating","comparing","preparing","generating_skill","generating_baseline","scoring","action_items"]);return t.jsx("div",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:s.has(e)?"var(--accent)":"var(--green)"}})}function kn({entries:e,isRunning:r}){const[n,s]=l.useState(!1),o=l.useRef(null);return l.useEffect(()=>{o.current&&!n&&(o.current.scrollTop=o.current.scrollHeight)},[e,n]),e.length===0&&!r?null:t.jsxs("div",{className:"mt-2 animate-fade-in",style:{borderTop:"1px solid var(--border-subtle)"},children:[t.jsxs("button",{onClick:()=>s(!n),className:"w-full flex items-center justify-between px-3 py-2 text-[11px] font-medium transition-colors duration-150",style:{color:"var(--text-tertiary)"},onMouseEnter:a=>{a.currentTarget.style.color="var(--text-primary)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--text-tertiary)"},children:[t.jsxs("span",{className:"flex items-center gap-2",children:[r&&t.jsx("div",{className:"spinner",style:{width:10,height:10}}),"Progress Log (",e.length,")"]}),t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",style:{transform:n?"rotate(0)":"rotate(180deg)",transition:"transform 0.2s ease"},children:t.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),!n&&t.jsx("div",{ref:o,className:"px-3 pb-3 space-y-1 max-h-48 overflow-y-auto",children:e.map((a,i)=>{const c=i===e.length-1&&r,d=i===0?"0s":`+${((a.timestamp-e[0].timestamp)/1e3).toFixed(1)}s`;return t.jsxs("div",{className:"flex items-center gap-2 text-[11px] animate-fade-in",style:{opacity:c?1:.7},children:[Qg(a.phase,c),t.jsx("span",{className:"font-mono flex-shrink-0",style:{color:"var(--text-tertiary)",width:40},children:d}),t.jsx("span",{style:{color:c?"var(--text-primary)":"var(--text-secondary)"},children:a.message}),a.current!=null&&a.total!=null&&t.jsxs("span",{className:"font-mono flex-shrink-0",style:{color:"var(--text-tertiary)"},children:["[",a.current,"/",a.total,"]"]})]},i)})})]})}const xi={rate_limit:{icon:"⏱",color:"var(--amber, #f59e0b)"},context_window:{icon:"⚠",color:"var(--amber, #f59e0b)"},auth:{icon:"🔒",color:"var(--red, #ef4444)"},timeout:{icon:"⌛",color:"var(--amber, #f59e0b)"},model_not_found:{icon:"🔍",color:"var(--red, #ef4444)"},provider_unavailable:{icon:"⚡",color:"var(--red, #ef4444)"},parse_error:{icon:"❓",color:"var(--amber, #f59e0b)"},unknown:{icon:"❌",color:"var(--red, #ef4444)"}};function us({error:e,onRetry:r,onDismiss:n}){const[s,o]=l.useState(null),a=l.useRef(null);l.useEffect(()=>(e.category==="rate_limit"&&e.retryAfterMs?o(Math.ceil(e.retryAfterMs/1e3)):o(null),()=>{a.current&&clearInterval(a.current)}),[e]),l.useEffect(()=>{if(!(s==null||s<=0))return a.current=setInterval(()=>{o(d=>d==null||d<=1?(a.current&&clearInterval(a.current),0):d-1)},1e3),()=>{a.current&&clearInterval(a.current)}},[s!=null&&s>0]);const i=xi[e.category]||xi.unknown,c=s!=null&&s>0;return t.jsxs("div",{className:"rounded-lg overflow-hidden animate-fade-in",style:{border:`1px solid color-mix(in srgb, ${i.color} 30%, transparent)`,background:`color-mix(in srgb, ${i.color} 6%, var(--surface-1))`},children:[t.jsxs("div",{className:"flex items-center justify-between px-3.5 py-2.5",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{style:{fontSize:14},children:i.icon}),t.jsx("span",{className:"text-[12px] font-semibold",style:{color:i.color},children:e.title})]}),n&&t.jsx("button",{onClick:n,className:"w-5 h-5 rounded flex items-center justify-center",style:{color:"var(--text-tertiary)"},children:t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),t.jsxs("div",{className:"px-3.5 pb-3",children:[t.jsx("p",{className:"text-[11.5px] mb-1.5",style:{color:"var(--text-secondary)"},children:e.description}),t.jsx("p",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:e.hint}),(r||s!=null)&&t.jsx("div",{className:"flex items-center gap-2 mt-2.5",children:r&&t.jsx("button",{onClick:r,disabled:c,className:"btn btn-secondary text-[11px]",style:{padding:"4px 10px",opacity:c?.5:1},children:c?`Retry in ${s}s`:"Retry"})})]})]})}function Zg({plugin:e,skill:r,skillContent:n,onApplied:s}){const[o,a]=l.useState("closed"),{config:i}=hr(),[c,d]=l.useState("claude-cli"),[u,p]=l.useState("opus"),[f,h]=l.useState([]),[m,g]=l.useState(""),[x,v]=l.useState(""),[b,y]=l.useState(null),[j,S]=l.useState(null),[w,R]=l.useState([]),[k,E]=l.useState(!1),C=l.useRef(null);l.useEffect(()=>{if(!i)return;i.providers.find(M=>M.id==="claude-cli"&&M.available)&&(d("claude-cli"),p("opus"))},[i]),l.useEffect(()=>()=>{var $;($=C.current)==null||$.abort()},[]);function N(){return i==null?void 0:i.providers.find($=>$.id===c&&$.available)}const I=l.useCallback(()=>{var $;($=C.current)==null||$.abort(),a("open")},[]);async function P(){a("loading"),y(null),S(null),R([]);const $=new AbortController;C.current=$;try{const M=await fetch(`/api/skills/${encodeURIComponent(e)}/${encodeURIComponent(r)}/improve?sse`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:c,model:u}),signal:$.signal});if(!M.ok||!M.body){let H=`HTTP ${M.status}`;try{const ee=await M.json();ee.error&&(H=ee.error)}catch{}throw new Error(H)}const F=M.body.getReader(),W=new TextDecoder;let le="",U="";for(;;){const{done:H,value:ee}=await F.read();if(H)break;le+=W.decode(ee,{stream:!0});const K=le.split(`
32
+ `);le=K.pop()||"";for(const X of K)if(X.startsWith("event: "))U=X.slice(7).trim();else if(X.startsWith("data: ")){try{const G=JSON.parse(X.slice(6));U==="progress"?R(he=>[...he,{phase:G.phase,message:G.message,timestamp:Date.now()}]):U==="done"||U==="complete"?(g(G.improved),v(G.reasoning||""),h(ds(G.original||n,G.improved)),a("diff_shown")):U==="error"&&(y(G.message||G.description||"Unknown error"),G.category&&S(G),a("open"))}catch{}U=""}}}catch(M){M.name!=="AbortError"&&(y(M.message),a("open"))}finally{C.current=null}}async function L(){E(!0);try{await ie.applyImprovement(e,r,m),s(m),a("closed")}catch($){y($.message)}finally{E(!1)}}function B(){a("closed"),h([]),g(""),v(""),y(null)}if(o==="closed")return t.jsxs("button",{onClick:()=>a("open"),className:"btn btn-secondary mb-5",disabled:!n,children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),t.jsx("path",{d:"M2 17l10 5 10-5"}),t.jsx("path",{d:"M2 12l10 5 10-5"})]}),"Improve Skill"]});const T=N();return t.jsxs("div",{className:"mb-5 rounded-xl overflow-hidden animate-fade-in",style:{border:"1px solid var(--border-subtle)",background:"var(--surface-1)"},children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5",style:{background:"var(--surface-2)",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{background:"rgba(168,85,247,0.15)"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#a855f7",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),t.jsx("path",{d:"M2 17l10 5 10-5"}),t.jsx("path",{d:"M2 12l10 5 10-5"})]})}),t.jsx("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:"AI Skill Improvement"})]}),t.jsx("button",{onClick:B,className:"w-7 h-7 rounded-lg flex items-center justify-center transition-colors duration-150",style:{color:"var(--text-tertiary)"},onMouseEnter:$=>{$.currentTarget.style.background="var(--surface-3)"},onMouseLeave:$=>{$.currentTarget.style.background="transparent"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),t.jsxs("div",{className:"px-5 py-4",children:[(o==="open"||o==="loading")&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-end gap-3 mb-4",children:[t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"text-[11px] font-medium mb-1 block",style:{color:"var(--text-tertiary)"},children:"Provider"}),t.jsx("select",{className:"input-field text-[12px] py-1.5",value:c,onChange:$=>{d($.target.value);const M=i==null?void 0:i.providers.find(F=>F.id===$.target.value);M!=null&&M.models[0]&&p(M.models[0].id)},disabled:o==="loading",children:i==null?void 0:i.providers.filter($=>$.available).map($=>t.jsx("option",{value:$.id,children:$.label},$.id))})]}),t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"text-[11px] font-medium mb-1 block",style:{color:"var(--text-tertiary)"},children:"Model"}),t.jsx("select",{className:"input-field text-[12px] py-1.5",value:u,onChange:$=>p($.target.value),disabled:o==="loading",children:T==null?void 0:T.models.map($=>t.jsx("option",{value:$.id,children:$.label},$.id))})]}),o==="loading"?t.jsx("button",{onClick:I,className:"btn btn-secondary flex-shrink-0",children:"Cancel"}):t.jsx("button",{onClick:P,className:"btn btn-primary flex-shrink-0",children:"Improve"})]}),o==="loading"&&w.length>0&&t.jsx("div",{className:"mt-3",children:t.jsx(kn,{entries:w,isRunning:!0})})]}),b&&t.jsx("div",{className:"mb-4",children:j?t.jsx(us,{error:j,onRetry:P,onDismiss:()=>{y(null),S(null)}}):t.jsx("div",{className:"px-4 py-3 rounded-lg text-[13px]",style:{background:"var(--red-muted)",color:"var(--red)"},children:b})}),o==="diff_shown"&&t.jsxs(t.Fragment,{children:[x&&t.jsxs("div",{className:"mb-4 px-4 py-3 rounded-lg text-[12px]",style:{background:"rgba(168,85,247,0.08)",color:"var(--text-secondary)",border:"1px solid rgba(168,85,247,0.2)"},children:[t.jsx("span",{className:"font-semibold",style:{color:"#a855f7"},children:"AI Reasoning: "}),x]}),t.jsx("div",{className:"rounded-lg overflow-hidden mb-4",style:{border:"1px solid var(--border-subtle)",maxHeight:"400px",overflowY:"auto"},children:f.map(($,M)=>t.jsxs("div",{className:"px-3 py-0.5 text-[11px] font-mono",style:{background:$.type==="added"?"rgba(34,197,94,0.1)":$.type==="removed"?"rgba(239,68,68,0.1)":"transparent",color:$.type==="added"?"var(--green)":$.type==="removed"?"var(--red)":"var(--text-secondary)",borderLeft:$.type==="added"?"3px solid var(--green)":$.type==="removed"?"3px solid var(--red)":"3px solid transparent"},children:[t.jsx("span",{style:{userSelect:"none",opacity:.5,marginRight:8},children:$.type==="added"?"+":$.type==="removed"?"-":" "}),$.content]},M))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{onClick:L,disabled:k,className:"btn btn-primary",children:k?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"spinner",style:{width:12,height:12}})," Applying..."]}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})})," Apply"]})}),t.jsx("button",{onClick:B,className:"btn btn-secondary",children:"Discard"})]})]})]})]})}const gi={remove:{bg:"var(--red-muted)",color:"var(--red)",label:"REMOVE"},modify:{bg:"rgba(251,191,36,0.15)",color:"#fbbf24",label:"MODIFY"},add:{bg:"var(--green-muted)",color:"var(--green)",label:"ADD"}},ev={remove:"var(--red)",modify:"#fbbf24",add:"var(--green)"};function tv({change:e,index:r,selected:n,onToggle:s,originalEval:o}){var f;const[a,i]=l.useState(!1),c=gi[e.action]??gi.add,d=ev[e.action]??"var(--border-subtle)",u=e.action==="remove"?(o==null?void 0:o.name)??`Eval #${e.evalId}`:((f=e.eval)==null?void 0:f.name)??"Unnamed",p=l.useCallback(()=>s(r),[s,r]);return t.jsxs("div",{className:"rounded-lg transition-all duration-150",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)",borderLeft:`3px solid ${d}`,opacity:n?1:.5},children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:p,className:"flex-shrink-0",style:{accentColor:"var(--accent)"}}),t.jsx("span",{className:"pill text-[9px] font-bold flex-shrink-0",style:{background:c.bg,color:c.color,padding:"1px 6px"},children:c.label}),t.jsx("span",{className:"text-[12px] font-medium truncate",style:{color:"var(--text-primary)"},children:u}),t.jsx("span",{className:"text-[11px] truncate flex-1",style:{color:"var(--text-tertiary)"},children:e.reason}),t.jsx("button",{onClick:()=>i(!a),className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded transition-colors duration-150",style:{color:"var(--text-tertiary)"},onMouseEnter:h=>{h.currentTarget.style.background="var(--surface-3)"},onMouseLeave:h=>{h.currentTarget.style.background="transparent"},children:t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{transform:a?"rotate(90deg)":"rotate(0)",transition:"transform 0.15s ease"},children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})})]}),a&&t.jsxs("div",{className:"px-4 pb-3 animate-fade-in",style:{borderTop:"1px solid var(--border-subtle)"},children:[e.action==="add"&&e.eval&&t.jsx(rv,{evalCase:e.eval}),e.action==="modify"&&e.eval&&o&&t.jsx(nv,{original:o,proposed:e.eval}),e.action==="remove"&&o&&t.jsx(sv,{evalCase:o})]})]})}function rv({evalCase:e}){var r;return t.jsxs("div",{className:"pt-2.5 space-y-2",children:[t.jsx(Eo,{label:"Prompt",value:e.prompt}),t.jsx(Eo,{label:"Expected",value:e.expected_output}),t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)"},children:["Assertions (",((r=e.assertions)==null?void 0:r.length)??0,")"]}),t.jsx("div",{className:"mt-1 space-y-1",children:(e.assertions??[]).map(n=>t.jsxs("div",{className:"text-[11px] flex items-start gap-1.5",style:{color:"var(--text-secondary)"},children:[t.jsx("span",{style:{color:"var(--green)"},children:"+"})," ",n.text]},n.id))})]})]})}function nv({original:e,proposed:r}){const n=[];e.name!==r.name&&n.push({label:"Name",old:e.name,new:r.name}),e.prompt!==r.prompt&&n.push({label:"Prompt",old:e.prompt,new:r.prompt}),e.expected_output!==r.expected_output&&n.push({label:"Expected",old:e.expected_output,new:r.expected_output});const s=e.assertions??[],o=r.assertions??[],a=new Set(s.map(u=>u.text)),i=new Set(o.map(u=>u.text)),c=o.filter(u=>!a.has(u.text)),d=s.filter(u=>!i.has(u.text));return t.jsxs("div",{className:"pt-2.5 space-y-2",children:[n.map(u=>t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)"},children:u.label}),t.jsxs("div",{className:"mt-1 text-[11px] font-mono rounded p-2",style:{background:"var(--surface-1)"},children:[t.jsxs("div",{style:{color:"var(--red)",textDecoration:"line-through"},children:["- ",No(u.old,120)]}),t.jsxs("div",{style:{color:"var(--green)"},children:["+ ",No(u.new,120)]})]})]},u.label)),(c.length>0||d.length>0)&&t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)"},children:"Assertions"}),t.jsxs("div",{className:"mt-1 space-y-0.5",children:[d.map(u=>t.jsxs("div",{className:"text-[11px]",style:{color:"var(--red)"},children:["- ",u.text]},u.id)),c.map(u=>t.jsxs("div",{className:"text-[11px]",style:{color:"var(--green)"},children:["+ ",u.text]},u.id))]})]}),n.length===0&&c.length===0&&d.length===0&&t.jsx("div",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:"No visible field changes"})]})}function sv({evalCase:e}){var r;return t.jsxs("div",{className:"pt-2.5 space-y-2",style:{opacity:.7},children:[t.jsx(Eo,{label:"Prompt",value:e.prompt}),t.jsxs("div",{children:[t.jsxs("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)"},children:["Assertions (",((r=e.assertions)==null?void 0:r.length)??0,")"]}),t.jsx("div",{className:"mt-1 space-y-0.5",children:(e.assertions??[]).map(n=>t.jsx("div",{className:"text-[11px]",style:{color:"var(--red)",textDecoration:"line-through"},children:n.text},n.id))})]})]})}function Eo({label:e,value:r}){return t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)"},children:e}),t.jsx("div",{className:"mt-0.5 text-[11px] p-2 rounded font-mono",style:{background:"var(--surface-1)",color:"var(--text-secondary)",whiteSpace:"pre-wrap"},children:No(r,300)})]})}function No(e,r){return e.length>r?e.slice(0,r)+"...":e}const vi={remove:0,modify:1,add:2};function ov({changes:e,selections:r,currentEvals:n,onToggle:s,onSelectAll:o,onDeselectAll:a}){if(e.length===0)return null;const i=e.map((d,u)=>({change:d,originalIndex:u}));i.sort((d,u)=>(vi[d.change.action]??2)-(vi[u.change.action]??2));const c=Array.from(r.values()).filter(Boolean).length;return t.jsxs("div",{className:"mt-3 animate-fade-in",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[11px] font-semibold",style:{color:"var(--text-primary)"},children:"Test Case Changes"}),t.jsxs("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)"},children:["(",c,"/",e.length," selected)"]})]}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx("button",{onClick:o,className:"text-[10px] px-2 py-0.5 rounded transition-colors duration-150",style:{color:"var(--accent)",background:"transparent"},onMouseEnter:d=>{d.currentTarget.style.background="var(--accent-muted)"},onMouseLeave:d=>{d.currentTarget.style.background="transparent"},children:"Select All"}),t.jsx("button",{onClick:a,className:"text-[10px] px-2 py-0.5 rounded transition-colors duration-150",style:{color:"var(--text-tertiary)",background:"transparent"},onMouseEnter:d=>{d.currentTarget.style.background="var(--surface-3)"},onMouseLeave:d=>{d.currentTarget.style.background="transparent"},children:"Deselect All"})]})]}),t.jsx("div",{className:"space-y-1.5 overflow-auto",style:{maxHeight:240},children:i.map(({change:d,originalIndex:u})=>t.jsx(tv,{change:d,index:u,selected:r.get(u)??!1,onToggle:s,originalEval:d.evalId!=null?n.find(p=>p.id===d.evalId):void 0},u))})]})}function av(){var $;const{state:e,dispatch:r,submitAiEdit:n,applyAiEdit:s,discardAiEdit:o,cancelAiEdit:a,toggleEvalChange:i,selectAllEvalChanges:c,deselectAllEvalChanges:d,retryEvalsSave:u}=ft(),{aiEditLoading:p,aiEditResult:f,aiEditError:h,aiEditClassifiedError:m,aiEditProgress:g,aiEditEvalChanges:x,aiEditEvalSelections:v,aiEditEvalsRetry:b}=e,[y,j]=l.useState(""),{config:S}=hr(),[w,R]=l.useState("claude-cli"),[k,E]=l.useState("opus"),C=l.useRef(null);l.useEffect(()=>{var M;(M=C.current)==null||M.focus()},[]),l.useEffect(()=>{if(!S)return;S.providers.find(F=>F.id==="claude-cli"&&F.available)&&(R("claude-cli"),E("opus"))},[S]);const N=S==null?void 0:S.providers.find(M=>M.id===w&&M.available),I=l.useCallback(()=>{const M=y.trim();!M||p||n(M,w,k)},[y,p,n,w,k]),P=l.useCallback(M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),I()),M.key==="Escape"&&(M.preventDefault(),p?a():o())},[I,p,a,o]),L=l.useCallback(()=>{r({type:"CLOSE_AI_EDIT"}),r({type:"OPEN_AI_EDIT"})},[r]),B=f?ds(e.skillContent,f.improved):[],T=(($=e.evals)==null?void 0:$.evals)??[];return t.jsxs("div",{className:"animate-fade-in",style:{background:"var(--surface-1)",borderTop:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5",style:{borderBottom:"1px solid var(--border-subtle)",background:"var(--surface-2)"},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("div",{className:"w-6 h-6 rounded-md flex items-center justify-center",style:{background:"rgba(168,85,247,0.15)"},children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#a855f7",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M15 4V2"}),t.jsx("path",{d:"M15 16v-2"}),t.jsx("path",{d:"M8 9h2"}),t.jsx("path",{d:"M20 9h2"}),t.jsx("path",{d:"M17.8 11.8L19 13"}),t.jsx("path",{d:"M15 9h.01"}),t.jsx("path",{d:"M17.8 6.2L19 5"}),t.jsx("path",{d:"M11 6.2L9.7 5"}),t.jsx("path",{d:"M3 21l9-9"})]})}),t.jsx("span",{className:"text-[12px] font-semibold",style:{color:"var(--text-primary)"},children:"AI Edit"}),t.jsx("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)"},children:"Describe what to change — Enter to submit, Esc to dismiss"})]}),t.jsx("button",{onClick:o,className:"w-6 h-6 rounded-md flex items-center justify-center transition-colors duration-150",style:{color:"var(--text-tertiary)"},onMouseEnter:M=>{M.currentTarget.style.background="var(--surface-3)"},onMouseLeave:M=>{M.currentTarget.style.background="transparent"},children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),t.jsxs("div",{className:"px-4 py-3",children:[!f&&t.jsxs(t.Fragment,{children:[t.jsx("textarea",{ref:C,value:y,onChange:M=>j(M.target.value),onKeyDown:P,placeholder:"e.g., Add an error handling section...",disabled:p,rows:4,className:"w-full resize-y outline-none",style:{background:"var(--surface-0)",color:"var(--text-primary)",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"10px 12px",fontSize:12.5,lineHeight:1.5,fontFamily:"var(--font-mono, 'JetBrains Mono', ui-monospace, monospace)",minHeight:96,maxHeight:240}}),t.jsxs("div",{className:"flex items-end gap-2.5 mt-2",children:[t.jsxs("div",{style:{minWidth:200},children:[t.jsx("label",{className:"text-[10px] font-medium mb-0.5 block",style:{color:"var(--text-tertiary)"},children:"Provider"}),t.jsx("select",{className:"input-field text-[11px] py-1",value:w,onChange:M=>{R(M.target.value);const F=S==null?void 0:S.providers.find(W=>W.id===M.target.value);F!=null&&F.models[0]&&E(F.models[0].id)},disabled:p,style:{width:"100%"},children:S==null?void 0:S.providers.filter(M=>M.available).map(M=>t.jsx("option",{value:M.id,children:M.label},M.id))})]}),t.jsxs("div",{style:{minWidth:200},children:[t.jsx("label",{className:"text-[10px] font-medium mb-0.5 block",style:{color:"var(--text-tertiary)"},children:"Model"}),t.jsx("select",{className:"input-field text-[11px] py-1",value:k,onChange:M=>E(M.target.value),disabled:p,style:{width:"100%"},children:N==null?void 0:N.models.map(M=>t.jsx("option",{value:M.id,children:M.label},M.id))})]}),t.jsx("div",{className:"flex-1"}),p?t.jsx("button",{onClick:a,className:"btn btn-secondary flex-shrink-0 text-[11px]",style:{padding:"6px 14px"},children:"Cancel"}):t.jsx("button",{onClick:I,disabled:!y.trim(),className:"btn btn-primary flex-shrink-0 text-[11px]",style:{padding:"6px 14px"},children:"Submit"})]}),p&&g.length>0&&t.jsx("div",{className:"mt-2.5",children:t.jsx(kn,{entries:g,isRunning:!0})})]}),h&&t.jsx("div",{className:"mt-3",children:m?t.jsx(us,{error:m,onRetry:L,onDismiss:o}):t.jsx("div",{className:"px-3 py-2.5 rounded-lg text-[12px]",style:{background:"var(--red-muted)",color:"var(--red)"},children:h})}),f&&t.jsxs("div",{className:"animate-fade-in",children:[f.reasoning&&t.jsxs("div",{className:"mb-3 px-3 py-2.5 rounded-lg text-[11.5px]",style:{background:"rgba(168,85,247,0.08)",color:"var(--text-secondary)",border:"1px solid rgba(168,85,247,0.2)"},children:[t.jsx("span",{className:"font-semibold",style:{color:"#a855f7"},children:"AI Reasoning: "}),f.reasoning]}),t.jsx("div",{className:"mb-1",children:t.jsx("span",{className:"text-[11px] font-semibold",style:{color:"var(--text-primary)"},children:"SKILL.md Changes"})}),t.jsx("div",{className:"rounded-lg overflow-hidden mb-3",style:{border:"1px solid var(--border-subtle)",maxHeight:300,overflowY:"auto"},children:B.map((M,F)=>t.jsxs("div",{className:"px-3 py-0.5 text-[10.5px] font-mono",style:{background:M.type==="added"?"rgba(34,197,94,0.1)":M.type==="removed"?"rgba(239,68,68,0.1)":"transparent",color:M.type==="added"?"var(--green)":M.type==="removed"?"var(--red)":"var(--text-secondary)",borderLeft:M.type==="added"?"3px solid var(--green)":M.type==="removed"?"3px solid var(--red)":"3px solid transparent"},children:[t.jsx("span",{style:{userSelect:"none",opacity:.5,marginRight:8},children:M.type==="added"?"+":M.type==="removed"?"-":" "}),M.content]},F))}),t.jsx(ov,{changes:x,selections:v,currentEvals:T,onToggle:i,onSelectAll:c,onDeselectAll:d}),b&&t.jsxs("div",{className:"mt-3 px-3 py-2.5 rounded-lg text-[12px] flex items-center justify-between",style:{background:"rgba(251,191,36,0.12)",border:"1px solid rgba(251,191,36,0.3)",color:"#fbbf24"},children:[t.jsx("span",{children:"Test case save failed. SKILL.md was saved successfully."}),t.jsx("button",{onClick:u,className:"btn text-[11px]",style:{background:"rgba(251,191,36,0.2)",color:"#fbbf24",padding:"3px 10px"},children:"Retry Save"})]}),t.jsxs("div",{className:"flex gap-2 mt-3",children:[t.jsxs("button",{onClick:s,className:"btn btn-primary text-[11px]",style:{padding:"5px 12px"},children:[t.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Apply"]}),t.jsx("button",{onClick:o,className:"btn btn-secondary text-[11px]",style:{padding:"5px 12px"},children:"Discard"}),t.jsx("button",{onClick:L,className:"btn btn-ghost text-[11px]",style:{padding:"5px 12px"},children:"Try Again"})]})]})]})]})}function iv(e,r){const[n,s]=l.useState([]),[o,a]=l.useState("SKILL.md"),[i,c]=l.useState(null),[d,u]=l.useState(!1),[p,f]=l.useState(null),[h,m]=l.useState(null),g=l.useCallback(async()=>{try{const b=await ie.getSkillFiles(e,r);s(b.files),m(null)}catch(b){s([]),m(b.message??"Unable to load skill files")}},[e,r]);l.useEffect(()=>{a("SKILL.md"),c(null),f(null),m(null),g()},[e,r,g]);const x=l.useCallback(async b=>{if(a(b),b==="SKILL.md"){c(null),f(null);return}u(!0),f(null);try{const y=await ie.getSkillFile(e,r,b);c(y)}catch(y){f(`Unable to open file: ${y.message}`),c(null)}finally{u(!1)}},[e,r]),v=l.useCallback(()=>{g()},[g]);return{files:n,activeFile:o,secondaryContent:i,loading:d,error:p,loadError:h,selectFile:x,refresh:v,isSkillMd:o==="SKILL.md"}}function lv(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function cv(e){const r=[],n=new Map;for(const s of e){const o=s.path.split("/"),i={name:o[o.length-1],path:s.path,type:s.type,size:s.size,children:[]};n.set(s.path,i)}for(const s of e){const o=s.path.split("/");if(o.length===1){const a=n.get(s.path);a&&r.push(a)}else{const a=o.slice(0,-1).join("/"),i=n.get(a),c=n.get(s.path);i&&c&&i.children.push(c)}}return r}function Yc({expanded:e}){return t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:e?"rotate(90deg)":"rotate(0deg)",transition:"transform 0.15s"},children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})}function Jc(){return t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function dv(){return t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),t.jsx("polyline",{points:"14 2 14 8 20 8"})]})}function uv(){return t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"23 4 23 10 17 10"}),t.jsx("polyline",{points:"1 20 1 14 7 14"}),t.jsx("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]})}function Xc({node:e,depth:r,activeFile:n,onSelect:s}){const[o,a]=l.useState(!0),i=e.path===n;return e.type==="dir"?t.jsxs("div",{children:[t.jsxs("button",{onClick:()=>a(!o),style:{display:"flex",alignItems:"center",gap:4,width:"100%",paddingLeft:`${4+r*14}px`,paddingTop:2,paddingBottom:2,background:"none",border:"none",cursor:"pointer",color:"var(--text-secondary)",fontSize:11,fontFamily:"var(--font-mono, monospace)",textAlign:"left"},children:[t.jsx(Yc,{expanded:o}),t.jsx(Jc,{}),t.jsxs("span",{children:[e.name,"/"]})]}),o&&e.children.map(c=>t.jsx(Xc,{node:c,depth:r+1,activeFile:n,onSelect:s},c.path))]}):t.jsxs("button",{onClick:()=>s(e.path),style:{display:"flex",alignItems:"center",gap:4,width:"100%",paddingLeft:`${4+r*14}px`,paddingTop:2,paddingBottom:2,background:i?"var(--accent-muted)":"none",border:"none",cursor:"pointer",color:i?"var(--accent)":"var(--text-tertiary)",fontSize:11,fontFamily:"var(--font-mono, monospace)",textAlign:"left",borderRadius:3},children:[t.jsx("span",{style:{width:10}}),t.jsx(dv,{}),t.jsx("span",{style:{flex:1},children:e.name}),t.jsx("span",{style:{fontSize:9,color:"var(--text-tertiary)",marginRight:4,whiteSpace:"nowrap"},children:lv(e.size)})]})}function pv({files:e,activeFile:r,onSelect:n,onRefresh:s,loadError:o}){const[a,i]=l.useState(!1),c=l.useMemo(()=>cv(e),[e]);return t.jsxs("div",{style:{borderBottom:"1px solid var(--border-subtle)",background:"var(--surface-0)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",cursor:"pointer",userSelect:"none"},onClick:()=>i(!a),children:[t.jsx(Yc,{expanded:a}),t.jsx(Jc,{}),t.jsx("span",{style:{fontSize:11,fontFamily:"var(--font-mono, monospace)",color:"var(--text-secondary)",flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r}),t.jsx("button",{onClick:d=>{d.stopPropagation(),s()},style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-tertiary)",padding:"2px 4px",display:"flex",alignItems:"center",borderRadius:3},title:"Refresh file list",children:t.jsx(uv,{})})]}),a&&t.jsx("div",{style:{maxHeight:240,overflowY:"auto",padding:"2px 4px 4px"},children:o?t.jsx("div",{style:{fontSize:11,color:"var(--text-warning, var(--text-tertiary))",padding:"4px 8px"},title:o,children:"Skill files not accessible from this workspace"}):c.length===0?t.jsx("div",{style:{fontSize:11,color:"var(--text-tertiary)",padding:"4px 8px"},children:"No files found"}):c.map(d=>t.jsx(Xc,{node:d,depth:0,activeFile:r,onSelect:n},d.path))})]})}function Ln(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function fv(e){try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function hv(e){const r=e.toLowerCase();return r.endsWith(".json")?"json":r.endsWith(".md")?"md":"other"}function yi({content:e}){return t.jsx("textarea",{readOnly:!0,value:e,style:{flex:1,width:"100%",resize:"none",background:"var(--surface-1)",color:"var(--text-primary)",border:"none",outline:"none",padding:"12px 16px",fontSize:12,fontFamily:"var(--font-mono, monospace)",lineHeight:1.6}})}function bi({content:e,fileType:r}){if(r==="json"){const n=fv(e);return t.jsx("pre",{style:{flex:1,margin:0,padding:"12px 16px",overflow:"auto",background:"var(--surface-0)",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font-mono, monospace)",lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:n})}return r==="md"?t.jsx("div",{style:{flex:1,overflow:"auto",padding:"16px 20px",background:"var(--surface-0)",color:"var(--text-primary)",fontSize:13,lineHeight:1.6},dangerouslySetInnerHTML:{__html:bn(e)}}):t.jsx("pre",{style:{flex:1,margin:0,padding:"12px 16px",overflow:"auto",background:"var(--surface-0)",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font-mono, monospace)",lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e})}function ki(e){try{return JSON.stringify(JSON.parse(e),null,2).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"([^"\\]|\\.)*"\s*:/g,n=>`<span style="color:#6383ff">${n}</span>`).replace(/:\s*"([^"\\]|\\.)*"/g,n=>`<span style="color:#22c55e">${n.slice(0,2)}<span style="color:#22c55e">${n.slice(2)}</span></span>`).replace(/:\s*(-?\d+\.?\d*)/g,(n,s)=>`: <span style="color:#fb923c">${s}</span>`).replace(/:\s*(true|false|null)/g,(n,s)=>`: <span style="color:#a855f7">${s}</span>`)}catch{return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}}function mv({file:e,loading:r,error:n,viewMode:s,plugin:o,skill:a,onSaved:i,onDirtyChange:c}){const[d,u]=l.useState(s),[p,f]=l.useState(!1),[h,m]=l.useState(""),[g,x]=l.useState(!1),[v,b]=l.useState(null),y=s!==d?s:d;l.useEffect(()=>{c==null||c(p)},[p,c]);const j=l.useCallback(()=>{(e==null?void 0:e.content)!=null&&(m(e.content),f(!0))},[e]),S=l.useCallback(()=>{f(!1)},[]),w=l.useCallback(async()=>{if(!(!o||!a||!e)){x(!0);try{await ie.saveSkillFile(o,a,e.path,h),b("Saved"),f(!1),i==null||i(),setTimeout(()=>b(null),2e3)}catch(E){b(`Save failed: ${E.message}`),setTimeout(()=>b(null),3e3)}finally{x(!1)}}},[o,a,e,h,i]);if(l.useEffect(()=>{if(!p)return;const E=C=>{(C.ctrlKey||C.metaKey)&&C.key==="s"&&(C.preventDefault(),w())};return document.addEventListener("keydown",E),()=>document.removeEventListener("keydown",E)},[p,w]),r)return t.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-tertiary)",fontSize:13},children:"Loading…"});if(n)return t.jsx("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",padding:24},children:t.jsxs("div",{style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)",borderRadius:8,padding:"16px 20px",maxWidth:400,textAlign:"center"},children:[t.jsx("div",{style:{fontSize:13,color:"var(--text-primary)",fontWeight:600,marginBottom:6},children:"Unable to open file"}),t.jsx("div",{style:{fontSize:12,color:"var(--text-tertiary)"},children:n})]})});if(!e)return null;if(e.binary)return t.jsxs("div",{style:{flex:1,display:"flex",alignItems:"center",justifyContent:"center",color:"var(--text-tertiary)",fontSize:13},children:["Binary file (",Ln(e.size),") — cannot be displayed"]});const R=e.content??"",k=hv(e.path);return t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:[e.truncated&&t.jsxs("div",{style:{padding:"4px 12px",background:"var(--warning-muted, #fef3c7)",borderBottom:"1px solid var(--border-subtle)",fontSize:11,color:"var(--warning-text, #92400e)"},children:["File truncated at ",Ln(512*1024)," — ",Ln(e.size)," total"]}),t.jsxs("div",{style:{display:"flex",gap:4,padding:"4px 8px",borderBottom:"1px solid var(--border-subtle)",background:"var(--surface-0)"},children:[(k==="md"||k==="json")&&["raw","split","preview"].map(E=>t.jsx("button",{onClick:()=>u(E),style:{padding:"2px 8px",fontSize:11,background:y===E?"var(--accent-muted)":"none",color:y===E?"var(--accent)":"var(--text-tertiary)",border:"none",borderRadius:3,cursor:"pointer",textTransform:"capitalize"},children:E},E)),t.jsxs("span",{style:{marginLeft:"auto",fontSize:11,color:"var(--text-tertiary)",display:"flex",alignItems:"center",gap:6},children:[Ln(e.size),o&&a&&!e.binary&&!p&&t.jsx("button",{onClick:j,style:{padding:"1px 6px",fontSize:10,background:"var(--accent-muted)",color:"var(--accent)",border:"none",borderRadius:3,cursor:"pointer"},children:"Edit"}),p&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:w,disabled:g,style:{padding:"1px 6px",fontSize:10,background:"var(--accent)",color:"#fff",border:"none",borderRadius:3,cursor:"pointer",opacity:g?.6:1},children:g?"Saving...":"Save"}),t.jsx("button",{onClick:S,style:{padding:"1px 6px",fontSize:10,background:"var(--surface-3)",color:"var(--text-tertiary)",border:"none",borderRadius:3,cursor:"pointer"},children:"Cancel"})]})]})]}),v&&t.jsx("div",{style:{padding:"4px 12px",background:v.startsWith("Save failed")?"var(--red-muted)":"var(--green-muted)",borderBottom:"1px solid var(--border-subtle)",fontSize:11,color:v.startsWith("Save failed")?"var(--red)":"var(--green)"},children:v}),t.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column",minHeight:0},children:p?t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:[t.jsx("textarea",{value:h,onChange:E=>m(E.target.value),style:{flex:1,width:"100%",resize:"none",background:"var(--surface-0)",color:"var(--text-primary)",border:"none",outline:"none",padding:"12px 16px",fontSize:12,fontFamily:"var(--font-mono, monospace)",lineHeight:1.6}}),t.jsxs("div",{style:{position:"sticky",bottom:0,display:"flex",alignItems:"center",gap:8,padding:"6px 12px",background:"var(--surface-1)",borderTop:"1px solid var(--border-subtle)"},children:[t.jsx("span",{style:{flex:1,fontSize:11,color:"var(--text-tertiary)"},children:"Unsaved changes"}),t.jsx("button",{onClick:w,disabled:g,style:{padding:"3px 12px",fontSize:11,background:"var(--accent)",color:"#fff",border:"none",borderRadius:4,cursor:"pointer",opacity:g?.6:1},children:g?"Saving...":"Save"}),t.jsx("button",{onClick:S,style:{padding:"3px 12px",fontSize:11,background:"var(--surface-3)",color:"var(--text-tertiary)",border:"none",borderRadius:4,cursor:"pointer"},children:"Cancel"})]})]}):y==="split"&&k!=="other"?t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column",borderRight:"1px solid var(--border-subtle)"},children:t.jsx(yi,{content:R})}),t.jsx("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"auto"},children:k==="json"?t.jsx("pre",{style:{flex:1,margin:0,padding:"12px 16px",overflow:"auto",background:"var(--surface-0)",fontSize:12,fontFamily:"var(--font-mono, monospace)",lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word"},dangerouslySetInnerHTML:{__html:ki(R)}}):t.jsx(bi,{content:R,fileType:k})})]}):y==="preview"&&k!=="other"?k==="json"?t.jsx("pre",{style:{flex:1,margin:0,padding:"12px 16px",overflow:"auto",background:"var(--surface-0)",fontSize:12,fontFamily:"var(--font-mono, monospace)",lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word"},dangerouslySetInnerHTML:{__html:ki(R)}}):t.jsx(bi,{content:R,fileType:k}):t.jsx(yi,{content:R})})]})}const xv=/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/,gv=/^https:\/\/github\.com\/([^/]+)\/(.+?)(?:\.git)?$/;function vv(e){const r=e.trim();if(!r)throw new Error("normalizeRemoteUrl: empty input");let n=r.match(xv);if(n)return`https://github.com/${n[1]}/${n[2]}`;if(n=r.match(gv),n)return`https://github.com/${n[1]}/${n[2]}`;throw new Error(`normalizeRemoteUrl: unrecognized remote URL: ${e}`)}function Qc(e){const r=vv(e);return`https://verified-skill.com/submit?repo=${encodeURIComponent(r)}`}function ji(e,r){typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:e,severity:r}}))}function yv({remoteUrl:e,fileCount:r,provider:n,model:s,onClose:o,defaultMode:a="manual"}){const[i,c]=l.useState(a),[d,u]=l.useState(""),[p,f]=l.useState(!1),[h,m]=l.useState(!1),[g,x]=l.useState(null),[v,b]=l.useState(null),y=l.useCallback(async()=>{f(!0),x(null);try{const B=await ie.gitCommitMessage({provider:n,model:s});u(B.message)}catch(B){const T=B instanceof Error?B.message:String(B);x(T)}finally{f(!1)}},[n,s]);l.useEffect(()=>{a==="ai"&&!d&&y()},[]);const j=l.useCallback(()=>{c("ai"),b(null),d.trim()||y()},[d,y]),S=l.useCallback(()=>{c("manual"),x(null)},[]),w=l.useCallback(async()=>{const B=d.trim();if(!(!B||h)){m(!0),b(null);try{const T=await ie.gitPublish({commitMessage:B}),$=T.remoteUrl??e,M=Qc($);window.open(M,"_blank","noopener,noreferrer");const F=(T.commitSha??"").slice(0,7),W=T.branch??"";ji(`Opening verified-skill.com — ${F} on ${W}`,"info"),o()}catch(T){const $=T instanceof Error?T.message:String(T),M=$.length>200?$.slice(0,200)+"…":$;b(M),ji(`Publish failed: ${M}`,"error")}finally{m(!1)}}},[d,h,e,o]),R=d.trim().length>0&&!h&&!p,k="#E6EDF3",E="#9CA3AF",C="rgba(255,255,255,0.12)",N="#0F1115",I={fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:E,fontFamily:"var(--font-mono, monospace)",marginBottom:6,display:"block"},P={flex:1,height:32,display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,fontSize:12,fontFamily:"var(--font-mono, monospace)",background:"transparent",color:E,border:"none",cursor:"pointer",transition:"background 120ms ease, color 120ms ease"},L={...P,background:"rgba(255,255,255,0.08)",color:k,fontWeight:600};return t.jsxs(t.Fragment,{children:[t.jsx("div",{"aria-hidden":"true",onClick:h?void 0:o,style:{position:"fixed",inset:0,background:"rgba(0, 0, 0, 0.55)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",zIndex:999,animation:"publishDrawerBackdropIn 150ms ease-out"}}),t.jsx("div",{role:"presentation",style:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:24,pointerEvents:"none"},children:t.jsxs("div",{role:"dialog","aria-label":"Publish","aria-modal":"true",style:{pointerEvents:"auto",width:520,maxWidth:"calc(100vw - 48px)",maxHeight:"80vh",overflowY:"auto",background:"#1A1D24",border:`1px solid ${C}`,borderRadius:10,padding:24,boxShadow:"0 24px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.05)",color:k,fontFamily:"var(--font-mono, monospace)",animation:"publishDrawerIn 180ms cubic-bezier(0.2, 0.8, 0.2, 1)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",marginBottom:4},children:[t.jsx("strong",{style:{fontSize:16,fontWeight:700,letterSpacing:"-0.01em",color:k,fontFamily:"var(--font-sans, var(--font-mono, sans-serif))"},children:"Publish skill"}),t.jsx("button",{type:"button","aria-label":"Dismiss",onClick:h?void 0:o,disabled:h,style:{background:"none",border:"none",color:E,fontSize:22,lineHeight:1,cursor:h?"not-allowed":"pointer",padding:0,opacity:h?.4:1},children:"×"})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:12,color:E,fontVariantNumeric:"tabular-nums",marginBottom:18},children:[t.jsx("span",{"aria-hidden":"true",style:{color:"#F59E0B",fontFamily:"monospace"},children:"▮"}),t.jsxs("span",{children:[r," file",r===1?"":"s"," changed"]})]}),t.jsx("div",{style:{height:1,background:C,margin:"0 -24px 18px"}}),t.jsx("span",{style:I,children:"Mode"}),t.jsxs("div",{role:"tablist","aria-label":"Commit message mode","data-testid":"publish-mode-toggle",style:{display:"flex",border:`1px solid ${C}`,borderRadius:6,overflow:"hidden",marginBottom:16,background:N},children:[t.jsx("button",{type:"button",role:"tab","aria-selected":i==="manual","data-testid":"publish-mode-manual",onClick:S,disabled:h,style:i==="manual"?L:P,children:"Write yourself"}),t.jsx("div",{style:{width:1,background:C}}),t.jsx("button",{type:"button",role:"tab","aria-selected":i==="ai","data-testid":"publish-mode-ai",onClick:j,disabled:h,style:i==="ai"?L:P,children:p&&i==="ai"?"Generating…":"Generate with AI"})]}),t.jsx("label",{htmlFor:"commit-message",style:I,children:"Commit message"}),t.jsx("textarea",{id:"commit-message",value:d,onChange:B=>u(B.target.value),rows:5,disabled:p||h,placeholder:p?"Generating with AI…":i==="ai"?"Click Generate to draft a message":"Type your commit message…",style:{width:"100%",background:N,border:`1px solid ${C}`,borderRadius:6,padding:"10px 12px",fontFamily:"var(--font-mono, monospace)",fontSize:13,lineHeight:1.6,color:k,resize:"vertical",outline:"none"}}),i==="ai"&&t.jsx("button",{type:"button",onClick:y,disabled:p||h,"data-testid":"publish-generate-button",style:{marginTop:10,padding:"8px 14px",background:p?"rgba(255,255,255,0.06)":"#2563EB",color:p?E:"#FFFFFF",border:"1px solid "+(p?C:"#2563EB"),borderRadius:6,fontFamily:"var(--font-mono, monospace)",fontSize:12,fontWeight:600,cursor:p||h?"not-allowed":"pointer",display:"inline-flex",alignItems:"center",gap:6},children:p?"Generating…":"Generate with AI"}),g&&i==="ai"&&t.jsxs("div",{role:"alert","data-testid":"publish-error-generate",style:{marginTop:10,padding:"8px 12px",border:"1px solid oklch(65% 0.14 25 / 0.35)",background:"oklch(65% 0.14 25 / 0.06)",borderRadius:4,fontSize:11,color:"oklch(70% 0.14 25)",fontFamily:"var(--font-mono, monospace)",lineHeight:1.5},children:[t.jsx("strong",{style:{fontWeight:600},children:"AI generation failed."})," ",g," ",t.jsx("button",{type:"button",onClick:y,disabled:p,style:{background:"none",border:"none",color:"var(--color-accent)",cursor:p?"not-allowed":"pointer",fontFamily:"inherit",fontSize:"inherit",textDecoration:"underline",padding:0},children:"Retry"})]}),v&&t.jsxs("div",{role:"alert","data-testid":"publish-error-push",style:{marginTop:10,padding:"8px 12px",border:"1px solid oklch(65% 0.14 25 / 0.35)",background:"oklch(65% 0.14 25 / 0.06)",borderRadius:4,fontSize:11,color:"oklch(70% 0.14 25)",fontFamily:"var(--font-mono, monospace)",lineHeight:1.5},children:[t.jsx("strong",{style:{fontWeight:600},children:"Publish failed."})," ",v]}),t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:18,gap:6},children:[t.jsx("div",{style:{minHeight:28},children:i==="ai"&&t.jsx("button",{type:"button","aria-label":"Regenerate",onClick:y,disabled:p||h,className:"btn btn-ghost text-[11px]",style:{padding:"4px 10px"},children:p?"Generating…":"Regenerate"})}),t.jsxs("div",{style:{display:"flex",gap:8},children:[t.jsx("button",{type:"button","aria-label":"Cancel",onClick:o,disabled:h,style:{padding:"8px 14px",background:"transparent",color:k,border:`1px solid ${C}`,borderRadius:6,fontFamily:"var(--font-mono, monospace)",fontSize:12,fontWeight:500,cursor:h?"not-allowed":"pointer",opacity:h?.5:1},children:"Cancel"}),t.jsx("button",{type:"button","aria-label":"Commit & Push",onClick:w,disabled:!R,"data-testid":"publish-commit-push",style:{padding:"8px 16px",background:R?"#22C55E":"rgba(255,255,255,0.06)",color:R?"#0B0F12":E,border:"1px solid "+(R?"#22C55E":C),borderRadius:6,fontFamily:"var(--font-mono, monospace)",fontSize:12,fontWeight:700,cursor:R?"pointer":"not-allowed"},children:h?"Publishing…":"Commit & Push"})]})]})]})}),t.jsx("style",{children:`
33
+ @keyframes publishDrawerBackdropIn { from { opacity: 0 } to { opacity: 1 } }
34
+ @keyframes publishDrawerIn {
35
+ from { opacity: 0; transform: translateY(4px) }
36
+ to { opacity: 1; transform: translateY(0) }
37
+ }
38
+ @media (prefers-reduced-motion: reduce) {
39
+ [role="dialog"][aria-label="Publish"],
40
+ [role="dialog"][aria-label="Publish"] + * { animation: none !important }
41
+ }
42
+ `})]})}function wi(e,r){typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:e,severity:r}}))}function Zc({remoteUrl:e,provider:r,model:n}){const[s,o]=l.useState(!1),[a,i]=l.useState(!1),[c,d]=l.useState(0),u=l.useCallback(async()=>{if(!(s||a)){o(!0);try{let f=!1,h=0;try{const y=await ie.gitDiff();f=!!y.hasChanges,h=y.fileCount??0}catch{}if(f){d(h),i(!0);return}const m=await ie.gitPublish(),g=m.remoteUrl??e,x=Qc(g);window.open(x,"_blank","noopener,noreferrer");const v=(m.commitSha??"").slice(0,7),b=m.branch??"";wi(`Opening verified-skill.com — ${v} on ${b}`,"info")}catch(f){const h=f instanceof Error?f.message:String(f),m=h.length>200?h.slice(0,200)+"…":h;wi(`Publish failed: ${m}`,"error")}finally{o(!1)}}},[s,a,e]),p=l.useCallback(()=>i(!1),[]);return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button","aria-label":"Publish",onClick:u,disabled:s,className:"btn btn-primary text-[11px]",style:{padding:"5px 14px"},title:"Push committed changes and open verified-skill.com to submit",children:s?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"spinner",style:{width:11,height:11,borderWidth:1.5}})," Publishing…"]}):"Publish"}),a&&t.jsx(yv,{remoteUrl:e,fileCount:c,provider:r,model:n,onClose:p})]})}const bv={hasRemote:!1,remoteUrl:null,branch:null,loading:!0,error:null};function kv(){const[e,r]=l.useState(bv);return l.useEffect(()=>{let n=!1;return ie.gitRemote().then(s=>{n||r({hasRemote:!!s.hasRemote,remoteUrl:s.remoteUrl??null,branch:s.branch??null,loading:!1,error:null})}).catch(s=>{n||r({hasRemote:!1,remoteUrl:null,branch:null,loading:!1,error:s instanceof Error?s:new Error(String(s))})}),()=>{n=!0}},[]),e}const jv=/^v?(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;function Ro(e){if(typeof e!="string")return null;const r=e.trim().match(jv);return r?{major:Number(r[1]),minor:Number(r[2]),patch:Number(r[3])}:null}function Yr(e,r){const n=Ro(e);if(!n)throw new Error(`bumpVersion: not a valid semver: ${JSON.stringify(e)}`);switch(r){case"patch":return`${n.major}.${n.minor}.${n.patch+1}`;case"minor":return`${n.major}.${n.minor+1}.0`;case"major":return`${n.major+1}.0.0`}}function wv(e,r){const n=Ro(r);if(!n)return{valid:!1,reason:`Invalid semver: ${JSON.stringify(r)}`};if(e==null)return{valid:!0};const s=Ro(e);return s?s.major===n.major&&s.minor===n.minor&&s.patch===n.patch?{valid:!0}:n.major<s.major||n.major===s.major&&n.minor<s.minor||n.major===s.major&&n.minor===s.minor&&n.patch<s.patch?{valid:!1,reason:`Version cannot decrease (from ${e} → ${r}). Use the same or higher version.`}:n.major!==s.major?n.major!==s.major+1?{valid:!1,reason:`Major version can only increase by 1 at a time (got ${s.major} → ${n.major}).`}:n.minor!==0||n.patch!==0?{valid:!1,reason:`When bumping major, minor and patch must be reset to 0 (got ${r}; expected ${n.major}.0.0).`}:{valid:!0}:n.minor!==s.minor?n.minor!==s.minor+1?{valid:!1,reason:`Minor version can only increase by 1 at a time (got ${s.minor} → ${n.minor}).`}:n.patch!==0?{valid:!1,reason:`When bumping minor, patch must be reset to 0 (got ${r}; expected ${n.major}.${n.minor}.0).`}:{valid:!0}:n.patch!==s.patch+1?{valid:!1,reason:`Patch version can only increase by 1 at a time (got ${s.patch} → ${n.patch}).`}:{valid:!0}:{valid:!0}}const ed=/^---\n([\s\S]*?)\n---(?:\n|$)/,To=/^version:\s*["']?([^"'\n]+?)["']?\s*$/m;function Jn(e){const r=e.match(ed);if(!r)return null;const n=r[1].match(To);return n&&n[1].trim()||null}function td(e,r){const n=`version: "${r}"`,s=e.match(ed);if(!s)return`---
43
+ ${n}
44
+ ---
45
+ ${e}`;const o=s[1],a=(s.index??0)+s[0].length,i=e.slice(a),c=e.slice(0,s.index??0);let d;To.test(o)?d=o.replace(To,n):d=`${n}
46
+ ${o}`;const u=s[0].endsWith(`---
47
+ `)?`---
48
+ `:"---";return`${c}---
49
+ ${d}
50
+ ${u}${i}`}function Sv(e,r){const n=Jn(r),s=Jn(e);if(n!==null&&s!==null&&n===s)try{const o=Yr(n,"patch");return{contentToSave:td(e,o),version:o,fromVersion:n}}catch{return{contentToSave:e,version:s,fromVersion:n}}return{contentToSave:e,version:s,fromVersion:n}}function jr(e){return e.testType==="integration"?"integration":"unit"}function Ir(e){return e>=.8?"var(--green)":e>=.5?"var(--yellow)":"var(--red)"}function rd(e){const r=new Date(e);return r.toLocaleDateString(void 0,{month:"short",day:"numeric"})+", "+r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function nd(e){return e==null?"--":e>=1e3?`${(e/1e3).toFixed(1)}s`:`${e}ms`}const Cv=new Set(["benchmark","comparison","baseline"]);function Si(e,r,n,s){return e.map(({rate:o,idx:a,total:i})=>{const c=s+a/(i-1)*(r-s*2),d=s+(n-s*2)-o*(n-s*2);return`${c},${d}`})}function sd({entries:e}){const r=e.filter(f=>Cv.has(f.type)).slice().reverse(),n=r.map((f,h,m)=>({rate:f.pass_rate,idx:h,total:m.length})).filter((f,h)=>{const m=r[h].type;return m==="benchmark"||m==="comparison"}),s=r.flatMap((f,h)=>f.type==="baseline"?[{rate:f.pass_rate,idx:h,total:r.length}]:f.type==="comparison"&&f.baselinePassRate!=null?[{rate:f.baselinePassRate,idx:h,total:r.length}]:[]);if(n.length<2&&s.length<2)return null;const o=80,a=24,i=2,c=n.length>=2?Si(n,o,a,i):[],d=s.length>=2?Si(s,o,a,i):[],u=c[c.length-1],p=d[d.length-1];return t.jsxs("svg",{width:o,height:a,style:{display:"block",flexShrink:0},children:[d.length>0&&t.jsx("polyline",{points:d.join(" "),fill:"none",stroke:"var(--text-tertiary)",strokeWidth:1.5,strokeLinejoin:"round",strokeDasharray:"3 2"}),c.length>0&&t.jsx("polyline",{points:c.join(" "),fill:"none",stroke:"var(--accent)",strokeWidth:1.5,strokeLinejoin:"round"}),p&&t.jsx("circle",{cx:parseFloat(p.split(",")[0]),cy:parseFloat(p.split(",")[1]),r:2.5,fill:"var(--text-tertiary)"}),u&&t.jsx("circle",{cx:parseFloat(u.split(",")[0]),cy:parseFloat(u.split(",")[1]),r:2.5,fill:"var(--accent)"})]})}function od(e,r,n){const s=isNaN(r)?0:r,o=[],a=[],i=[];if((e==="PASS"||e==="EFFECTIVE")&&s>=.7){const u=o.length>0?` Met criteria: ${o.map(p=>p.criterion).join(", ")}.`:"";return{explanation:`${e} (score ${s.toFixed(2)}): evaluation met expectations.${u}`}}if(e==="FAIL"||e==="DEGRADING"){const u=a.length>0?` Failed criteria: ${a.map(f=>f.criterion).join(", ")}.`:"",p=[...a.map(f=>`Improve "${f.criterion}" (score: ${f.score.toFixed(2)})`),...i.map(f=>`Strengthen "${f.criterion}" (score: ${f.score.toFixed(2)})`)];return p.length===0&&p.push("Review prompt instructions and add more specific guidance"),{explanation:`${e} (score ${s.toFixed(2)}): evaluation did not meet expectations.${u}`,recommendations:p}}if(e==="INEFFECTIVE"){if(s<.2){const p=[...a.map(f=>`Rework "${f.criterion}" — currently at ${f.score.toFixed(2)}`),"Consider adding examples to your system prompt","Review the rubric criteria for achievability"];return{explanation:`${e} (score ${s.toFixed(2)}): evaluation is significantly below expectations.`,recommendations:p}}const u=[...a.map(p=>`Rework "${p.criterion}" — currently at ${p.score.toFixed(2)}`),...i.map(p=>`Strengthen "${p.criterion}" (score: ${p.score.toFixed(2)})`)];return u.length===0&&u.push("Consider restructuring your prompt approach"),{explanation:`${e} (score ${s.toFixed(2)}): below expectations but showing some capability.`,recommendations:u}}if(e==="MARGINAL"){const u=[...i.map(p=>`Strengthen "${p.criterion}" (score: ${p.score.toFixed(2)})`),...a.map(p=>`Improve "${p.criterion}" (score: ${p.score.toFixed(2)})`)];return u.length===0&&u.push(o.length>0?"Assertion pass rate is below target despite strong rubric scores — review test case alignment":"Review prompt instructions for areas of improvement"),{explanation:`${e} (score ${s.toFixed(2)}): moderate improvement detected.`,recommendations:u}}if(e==="EMERGING"){const u=[...a.map(p=>`Improve "${p.criterion}" (score: ${p.score.toFixed(2)})`),...i.map(p=>`Strengthen "${p.criterion}" (score: ${p.score.toFixed(2)})`)];return u.length===0&&u.push(o.length>0?"Assertion pass rate is below target despite strong rubric scores — review test case alignment":"Add more specific guidance to your prompt instructions"),{explanation:`${e} (score ${s.toFixed(2)}): early promise — focus on weak areas to improve.`,recommendations:u}}const c=o.length>0?` Passing: ${o.map(u=>u.criterion).join(", ")}.`:"",d=i.length>0?` Needs improvement: ${i.map(u=>u.criterion).join(", ")}.`:"";return{explanation:`${e} (score ${s.toFixed(2)}): mixed results.${c}${d}`}}const ad={EFFECTIVE:"Strong Improvement",MARGINAL:"Moderate Improvement",EMERGING:"Early Promise",INEFFECTIVE:"Needs Work",DEGRADING:"Regression"};function Ev(e){return Object.hasOwn(ad,e)}function Nv(e){return Ev(e)?ad[e]:e}function Rv(){const{state:e}=ft(),{plugin:r,skill:n}=e,[s,o]=l.useState([]),[a,i]=l.useState([]),[c,d]=l.useState(!0),[u,p]=l.useState(null),[f,h]=l.useState(new Set),[m,g]=l.useState({}),[x,v]=l.useState(null),[b,y]=l.useState(""),[j,S]=l.useState(!1),[w,R]=l.useState(""),[k,E]=l.useState(""),C=l.useCallback(async()=>{d(!0),p(null);try{const[T,$]=await Promise.all([ie.getCredentials(r,n),ie.getParams(r,n)]);o(T.credentials),i($.params)}catch(T){p(T instanceof Error?T.message:"Failed to load parameters"),o([]),i([])}finally{d(!1)}},[r,n]);l.useEffect(()=>{C()},[C]);const N=l.useCallback(async(T,$)=>{S(!0),p(null);try{await ie.setCredential(r,n,T,$),v(null),y(""),await C()}catch(M){p(M instanceof Error?M.message:`Failed to save ${T}`)}finally{S(!1)}},[r,n,C]),I=l.useCallback(async()=>{const T=w.trim().toUpperCase(),$=k.trim();if(!(!T||!$)){S(!0),p(null);try{await ie.setCredential(r,n,T,$),R(""),E(""),await C()}catch(M){p(M instanceof Error?M.message:`Failed to add ${T}`)}finally{S(!1)}}},[r,n,w,k,C]),P=l.useCallback(async T=>{if(f.has(T)){h($=>{const M=new Set($);return M.delete(T),M}),g($=>{const M={...$};return delete M[T],M});return}try{const M=(await ie.getParamsRevealed(r,n,T)).params.find(F=>F.name===T);M!=null&&M.value&&(g(F=>({...F,[T]:M.value})),h(F=>new Set(F).add(T)))}catch{}},[r,n,f]),L=new Set(s.map(T=>T.name)),B=[...s.map(T=>{const $=a.find(M=>M.name===T.name);return{name:T.name,status:T.status,maskedValue:($==null?void 0:$.maskedValue)??""}}),...a.filter(T=>!L.has(T.name)).map(T=>({name:T.name,status:T.status,maskedValue:T.maskedValue}))];return t.jsxs("div",{className:"py-2 px-3",children:[t.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider mb-2",style:{color:"var(--text-tertiary)"},children:"Parameters"}),u&&t.jsx("div",{className:"text-[10px] px-2 py-1.5 rounded mb-2",style:{background:"var(--red-muted)",color:"var(--red)",border:"1px solid var(--red-muted)"},role:"alert",children:u}),c&&B.length===0&&t.jsx("div",{className:"text-[11px] py-2",style:{color:"var(--text-tertiary)"},children:"Loading..."}),!c&&B.length===0&&!u&&t.jsx("div",{className:"text-[11px] py-2",style:{color:"var(--text-tertiary)"},children:"No parameters configured"}),B.map(T=>t.jsxs("div",{className:"flex items-center gap-2 py-1.5",style:{borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("span",{className:"text-[10px] font-mono flex-1 truncate",style:{color:"var(--text-primary)"},children:T.name}),t.jsx("span",{className:"text-[9px] font-semibold px-1.5 py-0.5 rounded-full",style:{background:T.status==="ready"?"var(--green-muted)":"var(--red-muted)",color:T.status==="ready"?"var(--green)":"var(--red)"},children:T.status}),(T.maskedValue||T.status==="ready")&&t.jsxs("span",{className:"text-[10px] font-mono",style:{color:"var(--text-secondary)"},children:[f.has(T.name)?m[T.name]??T.maskedValue:T.maskedValue||"***",t.jsx("button",{onClick:()=>P(T.name),className:"text-[9px] ml-1",style:{color:"var(--accent)",cursor:"pointer",background:"none",border:"none"},"aria-label":`${f.has(T.name)?"Hide":"Reveal"} value for ${T.name}`,children:f.has(T.name)?"hide":"show"})]}),x===T.name?t.jsxs("div",{className:"flex gap-1",children:[t.jsx("input",{value:b,onChange:$=>y($.target.value),onKeyDown:$=>{$.key==="Enter"&&b.trim()&&N(T.name,b)},className:"input-field text-[10px] font-mono",style:{width:120},placeholder:"New value...","aria-label":`New value for ${T.name}`,autoFocus:!0}),t.jsx("button",{onClick:()=>N(T.name,b),disabled:j||!b.trim(),className:"text-[10px] font-medium",style:{color:"var(--green)",background:"none",border:"none",cursor:"pointer"},children:"Save"}),t.jsx("button",{onClick:()=>{v(null),y("")},className:"text-[10px]",style:{color:"var(--text-tertiary)",background:"none",border:"none",cursor:"pointer"},children:"Cancel"})]}):t.jsx("button",{onClick:()=>{v(T.name),y("")},className:"text-[10px]",style:{color:"var(--accent)",background:"none",border:"none",cursor:"pointer"},children:"Edit"})]},T.name)),t.jsxs("div",{className:"mt-3 pt-2",style:{borderTop:"1px solid var(--border-subtle)"},children:[t.jsx("div",{className:"text-[10px] font-medium mb-1.5",style:{color:"var(--text-secondary)"},children:"Add New Parameter"}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx("input",{value:w,onChange:T=>R(T.target.value),className:"input-field text-[10px] font-mono flex-1",placeholder:"KEY_NAME","aria-label":"Parameter key name"}),t.jsx("input",{value:k,onChange:T=>E(T.target.value),onKeyDown:T=>{T.key==="Enter"&&w.trim()&&k.trim()&&I()},className:"input-field text-[10px] font-mono flex-1",placeholder:"value",type:"password","aria-label":"Parameter value"}),t.jsx("button",{onClick:I,disabled:j||!w.trim()||!k.trim(),className:"text-[10px] font-medium px-2 py-1 rounded",style:{background:"var(--accent-muted)",color:"var(--accent)",border:"none",cursor:j?"not-allowed":"pointer"},children:"Add"})]})]})]})}function id(e,r,n){const[s,o]=l.useState(null),[a,i]=l.useState(!1),c=l.useRef("");l.useEffect(()=>{const u=`${e}/${r}/${n}`;c.current!==u&&(c.current=u,i(!0),ie.getCaseHistory(e,r,n).then(p=>o(p)).catch(()=>o([])).finally(()=>i(!1)))},[e,r,n]);const d=l.useCallback(()=>{i(!0),c.current="",ie.getCaseHistory(e,r,n).then(u=>o(u)).catch(()=>o([])).finally(()=>i(!1))},[e,r,n]);return{entries:s,loading:a,refetch:d}}function Tv(e,r,n){const s={flaky:!1,nonDiscriminating:!1,regression:!1};if(!n||n.length===0)return s;const a=n.slice(0,10).map(d=>d.assertions.find(u=>u.id===e)).filter(Boolean);if(a.length>=2){const u=a.filter(p=>p.pass).length/a.length;u>=.3&&u<=.7&&(s.flaky=!0)}const i=n.find(d=>d.type==="benchmark"),c=n.find(d=>d.type==="baseline");if(i&&c){const d=i.assertions.find(p=>p.id===e),u=c.assertions.find(p=>p.id===e);d!=null&&d.pass&&(u!=null&&u.pass)&&(s.nonDiscriminating=!0)}if(r&&!r.pass&&n.length>=1){const u=n[0].assertions.find(p=>p.id===e);u!=null&&u.pass&&(s.regression=!0)}return s}function ld({embedded:e=!1}={}){var U;const{state:r,dispatch:n,saveEvals:s,runCase:o,runAll:a,cancelCase:i,cancelAll:c,generateEvals:d,canEdit:u,canRun:p}=ft(),{evals:f,evalsError:h,selectedCaseId:m,inlineResults:g,caseRunStates:x,generateEvalsLoading:v,generateEvalsProgress:b,generateEvalsError:y}=r,j=l.useMemo(()=>{for(const H of x.values())if(H.status==="running"||H.status==="queued")return!0;return!1},[x]),[S,w]=l.useState(!1),[R,k]=l.useState("all"),E={skill_name:r.skill,evals:[]},C=f??E,N=C.evals,I=l.useMemo(()=>R==="all"?N:N.filter(H=>jr(H)===R),[R,N]),P=I.find(H=>H.id===m)??null;l.useEffect(()=>{m!==null&&!I.find(H=>H.id===m)&&n({type:"SELECT_CASE",caseId:I.length>0?I[0].id:null})},[I,m,n]);const[L,B]=l.useState([]),T=l.useMemo(()=>N.some(H=>jr(H)==="integration"),[N]);l.useEffect(()=>{T&&ie.getCredentials(r.plugin,r.skill).then(H=>B(H.credentials)).catch(()=>B([]))},[r.plugin,r.skill,T]);const $=l.useMemo(()=>new Set(L.filter(H=>H.status==="missing").map(H=>H.name)),[L]),[M,F]=l.useState(!1),W=l.useCallback(H=>{F(!1),d(H?{testType:H}:void 0)},[d]);if(!f||N.length===0)return t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 px-8",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center",style:{background:h?"var(--red-muted)":"var(--accent-muted)"},children:h?t.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--red)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),t.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}):t.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M9 11l3 3L22 4"}),t.jsx("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}),t.jsx("div",{className:"text-center",children:h?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-[14px] font-medium mb-1",style:{color:"var(--red)"},children:"Invalid evals.json"}),t.jsx("div",{className:"text-[11px] font-mono px-3 py-2 rounded mt-1 max-w-sm text-left break-words",style:{color:"var(--text-secondary)",background:"var(--surface-2)"},children:h}),t.jsx("div",{className:"text-[12px] mt-2",style:{color:"var(--text-tertiary)"},children:"Fix the evals.json file and reload, or regenerate test cases with AI"})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-[14px] font-medium mb-1",style:{color:"var(--text-primary)"},children:"No test cases yet"}),t.jsx("div",{className:"text-[12px]",style:{color:"var(--text-tertiary)"},children:"Create test cases to start evaluating your skill"})]})}),u&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx("button",{onClick:()=>w(!0),className:"btn btn-primary text-[12px]",children:"Create Test Case"}),t.jsxs("div",{style:{position:"relative"},children:[t.jsxs("div",{className:"flex",children:[t.jsx("button",{onClick:()=>W("unit"),disabled:v,className:"btn btn-secondary text-[12px]",style:{borderTopRightRadius:0,borderBottomRightRadius:0},children:v?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"spinner",style:{width:12,height:12,borderWidth:1.5}})," Generating..."]}):"Generate Unit Tests"}),t.jsx("button",{onClick:()=>F(!M),disabled:v,className:"btn btn-secondary text-[12px]",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeft:"1px solid var(--border-default)",padding:"4px 6px"},children:t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:t.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),M&&t.jsx("div",{className:"absolute right-0 mt-1 rounded-lg py-1 z-50",style:{background:"var(--surface-1)",border:"1px solid var(--border-default)",minWidth:180,boxShadow:"0 4px 12px rgba(0,0,0,0.3)"},children:t.jsx("button",{onClick:()=>W("integration"),className:"w-full text-left px-3 py-2 text-[12px] transition-colors duration-100",style:{color:"var(--text-secondary)",background:"transparent"},onMouseEnter:H=>{H.currentTarget.style.background="var(--surface-2)"},onMouseLeave:H=>{H.currentTarget.style.background="transparent"},children:"Generate Integration Tests"})})]})]}),v&&b.length>0&&t.jsx("div",{className:"w-full max-w-md mt-3",children:t.jsx(kn,{entries:b,isRunning:!0})}),y&&t.jsx("div",{className:"w-full max-w-md mt-3",children:t.jsx(us,{error:y,onRetry:()=>W()})}),S&&t.jsx(Ci,{evals:C,onSave:H=>{s(H),w(!1)},onCancel:()=>w(!1)})]});const le=!u&&!e&&f!=null&&t.jsxs("div",{role:"status","data-testid":"tests-readonly-banner",style:{padding:"10px 16px",background:"var(--surface-2)",borderBottom:"1px solid var(--border-subtle)",fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-secondary)",lineHeight:1.5},children:["Read-only — to author or modify tests, install this skill as source via"," ",t.jsx("code",{style:{background:"var(--surface-1)",padding:"1px 5px",borderRadius:3,fontFamily:"var(--font-mono)"},children:"vskill plugin new"}),"."]});return t.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",overflow:"hidden"},children:[le,t.jsxs("div",{className:"eval-cases-grid",children:[t.jsxs("div",{className:"overflow-auto",style:{borderRight:"1px solid var(--border-subtle)",background:"var(--surface-1)"},children:[t.jsxs("div",{className:"px-3 py-2",style:{borderBottom:"1px solid var(--border-subtle)",display:"flex",flexWrap:"wrap",alignItems:"center",rowGap:6,columnGap:8},children:[t.jsxs("span",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)",flex:"1 1 auto",minWidth:0},children:["Test Cases (",I.length,")"]}),t.jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:6,marginLeft:"auto",flexShrink:0},children:!e&&(j?t.jsx("button",{onClick:c,className:"btn text-[10px] px-2 py-0.5",style:{background:"var(--red-muted)",color:"var(--red)",border:"1px solid var(--red-muted)",whiteSpace:"nowrap"},children:"Cancel All"}):t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>a("benchmark"),disabled:!p,className:"btn btn-primary text-[10px] px-2 py-0.5",style:{whiteSpace:"nowrap"},children:"Run All"}),u&&t.jsx("button",{onClick:()=>a("comparison"),disabled:!p,className:"btn btn-secondary text-[10px] px-2 py-0.5",style:{whiteSpace:"nowrap"},children:"Compare All"})]}))})]}),t.jsx("div",{className:"flex px-3 py-1.5 gap-1",style:{borderBottom:"1px solid var(--border-subtle)"},children:["all","unit","integration"].map(H=>t.jsx("button",{onClick:()=>k(H),style:{padding:"2px 8px",fontSize:10,fontWeight:R===H?600:400,background:R===H?"var(--accent-muted)":"transparent",color:R===H?"var(--accent)":"var(--text-tertiary)",border:"none",borderRadius:4,cursor:"pointer",textTransform:"capitalize"},children:H==="all"?`All (${N.length})`:H==="unit"?`Unit (${N.filter(ee=>jr(ee)==="unit").length})`:`Integration (${N.filter(ee=>jr(ee)==="integration").length})`},H))}),t.jsxs("div",{className:"py-1",children:[I.length===0&&N.length>0&&t.jsxs("div",{className:"flex items-center justify-center py-8 px-3 text-[12px]",style:{color:"var(--text-tertiary)"},children:["No ",R==="all"?"":R+" ","tests yet"]}),I.map(H=>{var G;const ee=g.get(H.id),K=m===H.id,X=jr(H);return t.jsxs("button",{onClick:()=>n({type:"SELECT_CASE",caseId:H.id}),className:"w-full text-left px-3 py-2.5 transition-all duration-150",style:{background:K?"var(--accent-muted)":"transparent",borderLeft:K?"3px solid var(--accent)":"3px solid transparent"},onMouseEnter:he=>{K||(he.currentTarget.style.background="var(--surface-2)")},onMouseLeave:he=>{K||(he.currentTarget.style.background="transparent")},children:[t.jsxs("div",{className:"flex items-center justify-between gap-2 mb-0.5 min-w-0",children:[t.jsxs("span",{className:"text-[12px] font-medium flex items-center gap-1.5 min-w-0 flex-1",style:{color:K?"var(--text-primary)":"var(--text-secondary)"},children:[t.jsxs("span",{className:"truncate min-w-0 flex-1",children:["#",H.id," ",H.name]}),t.jsx("span",{title:X==="unit"?"Unit test":"Integration test","aria-label":X==="unit"?"Unit test":"Integration test",style:{flexShrink:0,fontSize:9,fontWeight:600,padding:"1px 5px",borderRadius:9999,background:X==="unit"?"var(--accent-muted)":"var(--orange-muted)",color:X==="unit"?"var(--accent)":"var(--orange)",whiteSpace:"nowrap",letterSpacing:"0.02em"},children:X==="unit"?"U":"I"}),X==="integration"&&((G=H.requiredCredentials)==null?void 0:G.some(he=>$.has(he)))&&t.jsx("span",{title:"Configure credentials to run",style:{flexShrink:0,display:"inline-flex"},children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--orange)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})})]}),t.jsx(cd,{result:ee})]}),t.jsxs("div",{className:"text-[11px] flex items-center gap-2",style:{color:"var(--text-tertiary)"},children:[H.assertions.length," assertion",H.assertions.length!==1?"s":"",(ee==null?void 0:ee.passRate)!=null&&t.jsx(Av,{passRate:ee.passRate})]})]},H.id)})]}),t.jsx("div",{className:"px-3 py-2",children:u&&t.jsx("button",{onClick:()=>w(!0),className:"w-full py-2 rounded-lg text-[12px] font-medium transition-all duration-150",style:{border:"1px dashed var(--border-default)",color:"var(--text-tertiary)",background:"transparent"},onMouseEnter:H=>{H.currentTarget.style.borderColor="var(--accent)",H.currentTarget.style.color="var(--accent)"},onMouseLeave:H=>{H.currentTarget.style.borderColor="var(--border-default)",H.currentTarget.style.color="var(--text-tertiary)"},children:"+ Add Test Case"})}),t.jsx("div",{style:{borderTop:"1px solid var(--border-subtle)"},children:t.jsx(Rv,{})})]}),t.jsx("div",{className:"overflow-auto",children:P?t.jsx(Iv,{evalCase:P,result:g.get(P.id),evals:f,caseStatus:((U=x.get(P.id))==null?void 0:U.status)??"idle",onSaveEvals:s,onRun:H=>o(H,"benchmark"),onCompare:H=>o(H,"comparison"),onCancel:H=>i(H),onImprove:H=>n({type:"OPEN_IMPROVE",evalId:H}),embedded:e}):t.jsx("div",{className:"flex items-center justify-center h-full text-[13px]",style:{color:"var(--text-tertiary)"},children:"Select a test case"})}),S&&t.jsx(Ci,{evals:C,onSave:H=>{s(H),w(!1)},onCancel:()=>w(!1)})]})]})}function Iv({evalCase:e,result:r,evals:n,caseStatus:s,onSaveEvals:o,onRun:a,onCompare:i,onCancel:c,onImprove:d,embedded:u=!1}){const{state:p,canEdit:f,canRun:h}=ft(),{plugin:m,skill:g}=p,{entries:x,loading:v}=id(m,g,e.id),[b,y]=l.useState(!1),[j,S]=l.useState(e.prompt),[w,R]=l.useState(!1),[k,E]=l.useState(e.expected_output);l.useState(()=>{S(e.prompt),E(e.expected_output)});const C=l.useCallback(U=>{o({...n,evals:n.evals.map(H=>H.id===U.id?U:H)})},[n,o]),N=l.useCallback(()=>{C({...e,prompt:j}),y(!1)},[e,j,C]),I=l.useCallback(()=>{C({...e,expected_output:k}),R(!1)},[e,k,C]),P=l.useCallback(()=>{C({...e,assertions:[...e.assertions,{id:`assert-${Date.now()}`,text:"New assertion",type:"boolean"}]})},[e,C]),L=l.useCallback((U,H)=>{C({...e,assertions:e.assertions.map(ee=>ee.id===U?{...ee,text:H}:ee)})},[e,C]),B=l.useCallback(U=>{C({...e,assertions:e.assertions.filter(H=>H.id!==U)})},[e,C]),T=l.useCallback(()=>{confirm("Delete this test case?")&&o({...n,evals:n.evals.filter(U=>U.id!==e.id)})},[n,e.id,o]),$=r&&r.assertions.length>0&&r.assertions.every(U=>U.pass),M=r&&r.assertions.some(U=>!U.pass),F=jr(e),W=e.requiredCredentials??[],le=F==="integration"&&W.length>0;return t.jsxs("div",{className:"p-5 animate-fade-in",children:[t.jsxs("div",{className:"mb-4",style:{display:"flex",flexWrap:"wrap",alignItems:"center",rowGap:8,columnGap:12},children:[t.jsxs("div",{className:"flex items-center gap-2",style:{flex:"1 1 240px",minWidth:0},children:[t.jsxs("span",{className:"text-[16px] font-semibold",title:`#${e.id} ${e.name}`,style:{color:"var(--text-primary)",minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:["#",e.id," ",e.name]}),f?t.jsx("button",{onClick:()=>{if((F==="unit"?"integration":"unit")==="unit"){const{requiredCredentials:H,requirements:ee,cleanup:K,...X}=e;C({...X,testType:"unit"})}else C({...e,testType:"integration"})},title:`Click to switch to ${F==="unit"?"integration":"unit"}`,style:{fontSize:10,fontWeight:600,padding:"2px 7px",borderRadius:9999,background:F==="unit"?"var(--accent-muted)":"var(--orange-muted)",color:F==="unit"?"var(--accent)":"var(--orange)",border:"none",cursor:"pointer"},children:F==="unit"?"Unit":"Integration"}):t.jsx("span",{style:{fontSize:10,fontWeight:600,padding:"2px 7px",borderRadius:9999,background:F==="unit"?"var(--accent-muted)":"var(--orange-muted)",color:F==="unit"?"var(--accent)":"var(--orange)"},children:F==="unit"?"Unit":"Integration"}),t.jsx(cd,{result:r})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:8,marginLeft:"auto",flexShrink:0},children:[!u&&(s==="running"||s==="queued"?t.jsxs("button",{onClick:()=>c(e.id),className:"btn text-[12px]",style:{background:"var(--red-muted)",color:"var(--red)",border:"1px solid var(--red-muted)",whiteSpace:"nowrap"},children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",style:{marginRight:4},children:t.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1"})}),"Cancel"]}):t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:()=>a(e.id),disabled:!h,className:"btn btn-primary text-[12px]",style:{whiteSpace:"nowrap"},children:"Run"}),f&&t.jsx("button",{onClick:()=>i(e.id),disabled:!h,className:"btn btn-secondary text-[12px]",style:{whiteSpace:"nowrap"},children:"A/B Compare"})]})),M&&f&&s!=="running"&&s!=="queued"&&t.jsx("button",{onClick:()=>d(e.id),className:"btn btn-secondary text-[12px]",style:{whiteSpace:"nowrap"},children:"Fix with AI"}),f&&s!=="running"&&s!=="queued"&&t.jsx("button",{onClick:T,className:"btn btn-ghost text-[12px]","aria-label":"Delete test case",title:"Delete test case",style:{color:"var(--red)"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]})})]})]}),!f&&F==="integration"&&t.jsxs("div",{"data-testid":"platform-integration-note",className:"mb-4 px-4 py-3 rounded-xl flex items-center gap-3",style:{background:"var(--accent-muted)",border:"1px solid var(--accent-muted)"},children:[t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),t.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),t.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]}),t.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--accent)"},children:"Run locally in Skill Studio"})]}),$&&t.jsxs("div",{className:"mb-4 px-4 py-3 rounded-xl flex items-center gap-3",style:{background:"var(--green-muted)",border:"1px solid var(--green-muted)"},children:[t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--green)",strokeWidth:"2.5",children:[t.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),t.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),t.jsx("span",{className:"text-[13px] font-medium",style:{color:"var(--green)"},children:"All assertions passing"})]}),le&&t.jsxs("div",{className:"mb-4 px-4 py-3 rounded-xl",style:{background:"var(--orange-muted)",border:"1px solid var(--orange-muted)"},children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--orange)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),t.jsx("span",{className:"text-[12px] font-semibold",style:{color:"var(--orange)"},children:"Required Credentials"})]}),t.jsx("div",{className:"text-[11px]",style:{color:"var(--text-secondary)"},children:"This integration test requires the following environment variables:"}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mt-1.5",children:W.map(U=>t.jsx("span",{style:{fontSize:10,fontFamily:"var(--font-mono, monospace)",padding:"2px 6px",borderRadius:4,background:"var(--orange-muted)",color:"var(--orange)"},children:U},U))})]}),f&&F==="integration"&&t.jsx($v,{evalCase:e,onUpdate:C}),t.jsx(An,{title:"Prompt",children:b?t.jsxs("div",{children:[t.jsx("textarea",{value:j,onChange:U=>S(U.target.value),className:"input-field w-full",rows:4,style:{fontFamily:"var(--font-mono, ui-monospace, monospace)",fontSize:12},autoFocus:!0}),t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("button",{onClick:N,className:"btn btn-primary text-[12px]",children:"Save"}),t.jsx("button",{onClick:()=>{S(e.prompt),y(!1)},className:"btn btn-ghost text-[12px]",children:"Cancel"})]})]}):t.jsx("div",{className:"p-3 rounded-lg text-[12px] transition-all duration-150",style:{background:"var(--surface-2)",color:"var(--text-secondary)",fontFamily:"var(--font-mono, ui-monospace, monospace)",whiteSpace:"pre-wrap",border:"1px solid var(--border-subtle)",maxHeight:200,overflowY:"auto",cursor:f?"pointer":"default"},onClick:()=>{f&&y(!0)},onMouseEnter:U=>{f&&(U.currentTarget.style.borderColor="var(--border-hover)")},onMouseLeave:U=>{U.currentTarget.style.borderColor="var(--border-subtle)"},children:e.prompt||t.jsx("span",{style:{color:"var(--text-tertiary)",fontStyle:"italic"},children:f?"Click to edit prompt...":"No prompt"})})}),t.jsx(An,{title:"Expected Output",children:w?t.jsxs("div",{children:[t.jsx("textarea",{value:k,onChange:U=>E(U.target.value),className:"input-field w-full",rows:3,style:{fontFamily:"var(--font-mono, ui-monospace, monospace)",fontSize:12},autoFocus:!0}),t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx("button",{onClick:I,className:"btn btn-primary text-[12px]",children:"Save"}),t.jsx("button",{onClick:()=>{E(e.expected_output),R(!1)},className:"btn btn-ghost text-[12px]",children:"Cancel"})]})]}):t.jsx("div",{className:"p-3 rounded-lg text-[12px] transition-all duration-150",style:{background:"var(--surface-2)",color:"var(--text-tertiary)",fontFamily:"var(--font-mono, ui-monospace, monospace)",whiteSpace:"pre-wrap",border:"1px solid var(--border-subtle)",maxHeight:200,overflowY:"auto",cursor:f?"pointer":"default"},onClick:()=>{f&&R(!0)},onMouseEnter:U=>{f&&(U.currentTarget.style.borderColor="var(--border-hover)")},onMouseLeave:U=>{U.currentTarget.style.borderColor="var(--border-subtle)"},children:e.expected_output||t.jsx("span",{style:{fontStyle:"italic"},children:f?"Click to edit expected output...":"No expected output"})})}),t.jsx(An,{title:`Assertions (${e.assertions.length})`,action:f?t.jsx("button",{onClick:P,className:"btn btn-ghost text-[11px]",children:"+ Add"}):void 0,children:e.assertions.length===0?t.jsx("div",{className:"text-[12px] text-center py-4",style:{color:"var(--text-tertiary)"},children:'No assertions. Click "+ Add" to create one.'}):t.jsx("div",{className:"space-y-2",children:e.assertions.map(U=>{const H=r==null?void 0:r.assertions.find(K=>K.assertion_id===U.id),ee=Tv(U.id,H,x);return t.jsx(Lv,{assertion:U,result:H,badges:ee,isReadOnly:!f,onUpdate:K=>L(U.id,K),onDelete:()=>B(U.id)},U.id)})})}),(r==null?void 0:r.output)&&t.jsx(Pv,{output:r.output,durationMs:r.durationMs,tokens:r.tokens}),r&&r.passRate!=null&&r.passRate<.2&&(()=>{const U=od("INEFFECTIVE",r.passRate);return U.recommendations&&U.recommendations.length>0?t.jsx(An,{title:"Recommendations",children:t.jsxs("div",{className:"rounded-xl p-4",style:{background:"var(--orange-muted)",border:"1px solid var(--orange-muted)"},children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--orange)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),t.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),t.jsx("span",{className:"text-[12px] font-semibold",style:{color:"var(--orange)"},children:"This eval is significantly below expectations"})]}),t.jsx("ul",{className:"space-y-1.5 ml-1",children:U.recommendations.map((H,ee)=>t.jsxs("li",{className:"flex items-start gap-2 text-[12px]",style:{color:"var(--text-secondary)"},children:[t.jsx("span",{style:{color:"var(--orange)",fontWeight:600,flexShrink:0},children:"•"}),H]},ee))})]})}):null})(),!u&&t.jsx(dd,{evalId:e.id,sharedEntries:x,sharedLoading:v})]},e.id)}function Lv({assertion:e,result:r,badges:n,isReadOnly:s,onUpdate:o,onDelete:a}){const[i,c]=l.useState(!1),[d,u]=l.useState(e.text),[p,f]=l.useState(!1),h=()=>{o(d),c(!1)};return t.jsx("div",{className:"rounded-lg px-3 py-2.5 transition-all duration-150",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)"},children:t.jsxs("div",{className:"flex items-start gap-2",children:[r?t.jsx("span",{className:"mt-0.5 rounded-full flex-shrink-0",style:{width:18,height:18,display:"flex",alignItems:"center",justifyContent:"center",background:r.pass?"var(--green-muted)":"var(--red-muted)"},children:r.pass?t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--green)",strokeWidth:"3",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})}):t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--red)",strokeWidth:"3",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}):t.jsx("span",{className:"mt-0.5 rounded-full flex-shrink-0",style:{width:18,height:18,border:"1.5px dashed var(--text-tertiary)",background:"transparent"},title:"Not run yet"}),(n==null?void 0:n.regression)&&t.jsx("span",{className:"mt-0.5 flex-shrink-0",title:"Regression: was passing, now failing",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:16,height:18,color:"var(--red)",fontSize:14,fontWeight:700,lineHeight:1},children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--red)",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("polyline",{points:"19 12 12 19 5 12"})]})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[t.jsx("span",{className:"text-[10px] font-mono font-semibold",style:{color:"var(--text-tertiary)"},children:e.id}),(n==null?void 0:n.flaky)&&t.jsx("span",{title:"Flaky: 30-70% pass rate across recent runs",style:{display:"inline-block",fontSize:9,fontWeight:600,lineHeight:1,padding:"2px 6px",borderRadius:9999,background:"var(--yellow-muted)",color:"var(--yellow)",whiteSpace:"nowrap"},children:"Flaky"}),(n==null?void 0:n.nonDiscriminating)&&t.jsx("span",{title:"Non-discriminating: passes on both skill and baseline runs",style:{display:"inline-block",fontSize:9,fontWeight:600,lineHeight:1,padding:"2px 6px",borderRadius:9999,background:"var(--surface-3)",color:"var(--text-tertiary)",whiteSpace:"nowrap"},children:"Non-Discrim."})]}),i?t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{value:d,onChange:m=>u(m.target.value),onKeyDown:m=>{m.key==="Enter"&&h(),m.key==="Escape"&&c(!1)},className:"input-field flex-1 text-[12px]",autoFocus:!0}),t.jsx("button",{onClick:h,className:"btn btn-primary text-[11px]",children:"Save"})]}):t.jsx("div",{className:"text-[12px]",style:{color:"var(--text-secondary)",cursor:s?"default":"pointer"},onClick:()=>{s||(u(e.text),c(!0))},children:e.text}),(r==null?void 0:r.reasoning)&&t.jsx("button",{onClick:()=>f(!p),className:"text-[11px] mt-1 transition-colors duration-150",style:{color:"var(--text-tertiary)"},children:p?"Hide reasoning":"Show reasoning"}),p&&(r==null?void 0:r.reasoning)&&t.jsx("div",{className:"mt-1 text-[11px] p-2 rounded",style:{background:"var(--surface-1)",color:"var(--text-tertiary)"},children:r.reasoning})]}),!s&&t.jsx("button",{onClick:a,className:"btn btn-ghost p-1 opacity-0 group-hover:opacity-100",style:{color:"var(--text-tertiary)"},onMouseEnter:m=>{m.currentTarget.style.color="var(--red)",m.currentTarget.style.opacity="1"},onMouseLeave:m=>{m.currentTarget.style.color="var(--text-tertiary)",m.currentTarget.style.opacity=""},children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})})}function An({title:e,action:r,children:n}){return t.jsxs("div",{className:"mb-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)"},children:e}),r]}),n]})}function cd({result:e}){const[r,n]=l.useState(!1),s={padding:"2px 8px",borderRadius:9999,flexShrink:0,minWidth:44,justifyContent:"center",position:"relative",cursor:"default"};if(!e||e.status==null)return t.jsx("span",{className:"pill text-[10px]",title:"Not run yet","aria-label":"Not run yet",style:{...s,background:"var(--surface-3)",color:"var(--text-tertiary)"},children:"--"});const o=e.status==="pass",a=e.passRate??0,i=o?"PASS":"FAIL",c=od(i,a),d=e.passRate!=null?`${Math.round(e.passRate*100)}%`:i;return t.jsxs("span",{className:"pill text-[10px]",style:{...s,background:o?"var(--green-muted)":"var(--red-muted)",color:o?"var(--green)":"var(--red)",fontWeight:600},onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),"aria-label":`${i} ${d}`,"aria-describedby":r?"verdict-tooltip":void 0,children:[d,r&&t.jsx("div",{id:"verdict-tooltip",role:"tooltip",style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,padding:"6px 10px",background:"var(--surface-4)",border:"1px solid var(--border-subtle)",borderRadius:6,fontSize:11,color:"var(--text-secondary)",whiteSpace:"nowrap",zIndex:50,maxWidth:300,width:"max-content",boxShadow:"0 4px 12px rgba(0,0,0,0.15)"},children:c.explanation})]})}function Av({passRate:e}){const r=Math.round(e*100);return t.jsx("div",{className:"flex items-center gap-1",children:t.jsx("div",{className:"rounded-full overflow-hidden",style:{width:32,height:4,background:"var(--surface-4)"},children:t.jsx("div",{className:"h-full rounded-full",style:{width:`${r}%`,background:r>=80?"var(--green)":r>=50?"var(--yellow)":"var(--red)"}})})})}function Pv({output:e,durationMs:r,tokens:n}){const[s,o]=l.useState(!1);return t.jsxs("div",{className:"mb-5",children:[t.jsxs("button",{onClick:()=>o(!s),className:"flex items-center gap-2 text-[11px] font-semibold uppercase tracking-wider mb-2 transition-colors duration-150",style:{color:"var(--text-tertiary)"},children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{transform:s?"rotate(90deg)":"rotate(0)",transition:"transform 0.2s ease"},children:t.jsx("polyline",{points:"9 18 15 12 9 6"})}),"LLM Output",r!=null&&t.jsxs("span",{style:{fontWeight:400},children:["(",(r/1e3).toFixed(1),"s)"]}),n!=null&&t.jsxs("span",{style:{fontWeight:400},children:["(",n," tokens)"]})]}),s&&t.jsx("pre",{className:"text-[12px] p-4 rounded-lg overflow-auto animate-fade-in",style:{background:"var(--surface-1)",color:"var(--text-secondary)",border:"1px solid var(--border-subtle)",maxHeight:400,fontFamily:"var(--font-mono, ui-monospace, monospace)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e})]})}function As(e){return e==="baseline"?"right":e==="comparison"?"full":"left"}function Ps({entry:e}){return t.jsxs("div",{className:"rounded-lg px-3 py-2.5",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--text-primary)"},children:rd(e.timestamp)}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:e.model}),t.jsx("span",{className:"pill",style:{fontSize:9,padding:"1px 6px",background:e.type==="benchmark"?"var(--accent-muted)":e.type==="comparison"?"var(--purple-muted)":"var(--orange-muted)",color:e.type==="benchmark"?"var(--accent)":e.type==="comparison"?"var(--purple)":"var(--orange)"},children:e.type}),t.jsxs("span",{className:"text-[12px] font-semibold ml-auto",style:{color:Ir(e.pass_rate)},children:[Math.round(e.pass_rate*100),"%"]})]}),t.jsxs("div",{className:"flex items-center gap-4 mb-1.5 text-[10px]",style:{fontFamily:"var(--font-mono, monospace)",color:"var(--text-tertiary)"},children:[e.durationMs!=null&&t.jsx("span",{children:nd(e.durationMs)}),e.tokens!=null&&t.jsxs("span",{children:[e.tokens>=1e3?`${(e.tokens/1e3).toFixed(1)}k`:e.tokens," tok"]})]}),e.type==="comparison"&&e.baselinePassRate!=null&&(()=>{const r=e.pass_rate-e.baselinePassRate,n=r>.001?"skill":r<-.001?"baseline":"tie",s=r>0?"+":"",o=n==="skill"?"var(--green)":n==="baseline"?"var(--red)":"var(--text-tertiary)";return t.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:"vs baseline:"}),t.jsxs("span",{className:"text-[11px] font-semibold",style:{color:r>=0?"var(--green)":"var(--red)"},children:[s,(r*100).toFixed(1),"%"]}),t.jsx("span",{className:"pill text-[9px]",style:{padding:"1px 5px",background:"var(--surface-3)",color:o},children:n})]})})(),t.jsx("div",{className:"space-y-0.5",children:e.assertions.map(r=>t.jsxs("div",{className:"flex items-start gap-1.5",children:[t.jsx("span",{className:"mt-0.5 rounded-full flex-shrink-0",style:{width:14,height:14,display:"flex",alignItems:"center",justifyContent:"center",background:r.pass?"var(--green-muted)":"var(--red-muted)"},children:r.pass?t.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"var(--green)",strokeWidth:"3",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})}):t.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"var(--red)",strokeWidth:"3",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-secondary)"},children:r.text})]},r.id))})]})}function dd({evalId:e,sharedEntries:r,sharedLoading:n}){const{state:s,dispatch:o}=ft(),{plugin:a,skill:i}=s,[c,d]=l.useState(!0),u=r??null,p=n??!1,f=l.useCallback(()=>{d(x=>!x)},[]),h=u?u.slice(0,10):[],m=h.some(x=>{const v=As(x.type);return v==="left"||v==="full"}),g=h.some(x=>{const v=As(x.type);return v==="right"||v==="full"});return t.jsxs("div",{className:"mb-5",children:[t.jsxs("button",{onClick:f,className:"flex items-center gap-2 text-[11px] font-semibold uppercase tracking-wider mb-2 transition-colors duration-150",style:{color:"var(--text-tertiary)"},children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{transform:c?"rotate(90deg)":"rotate(0)",transition:"transform 0.2s ease"},children:t.jsx("polyline",{points:"9 18 15 12 9 6"})}),"Execution History",u&&u.length>0&&t.jsxs("span",{style:{fontWeight:400},children:["(",u.length," run",u.length!==1?"s":"",")"]})]}),c&&t.jsx("div",{className:"animate-fade-in",children:p?t.jsxs("div",{className:"flex items-center gap-2 py-3",children:[t.jsx("div",{className:"spinner",style:{width:14,height:14,borderWidth:1.5}}),t.jsx("span",{className:"text-[12px]",style:{color:"var(--text-tertiary)"},children:"Loading history..."})]}):!u||u.length===0?t.jsx("div",{className:"text-[12px] py-3",style:{color:"var(--text-tertiary)"},children:"No history for this case"}):t.jsxs("div",{children:[h.length>=2&&t.jsx("div",{className:"mb-2",children:t.jsx(sd,{entries:h})}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[t.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)",gridColumn:"1"},children:"Skill"}),t.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)",gridColumn:"2"},children:"Baseline"}),!m&&t.jsx("div",{style:{gridColumn:"1",fontSize:12,color:"var(--text-tertiary)"},children:"No skill runs"}),!g&&t.jsx("div",{style:{gridColumn:"2",fontSize:12,color:"var(--text-tertiary)"},children:"No baseline runs"}),h.map((x,v)=>{const b=As(x.type);return b==="full"?t.jsx("div",{style:{gridColumn:"1 / -1"},children:t.jsx(Ps,{entry:x})},v):b==="left"?t.jsxs(l.Fragment,{children:[t.jsx("div",{style:{gridColumn:"1"},children:t.jsx(Ps,{entry:x})}),t.jsx("div",{style:{gridColumn:"2"}})]},v):t.jsxs(l.Fragment,{children:[t.jsx("div",{style:{gridColumn:"1"}}),t.jsx("div",{style:{gridColumn:"2"},children:t.jsx(Ps,{entry:x})})]},v)})]}),t.jsx("button",{onClick:()=>o({type:"SET_PANEL",panel:"history"}),className:"mt-2 text-[11px] font-medium transition-colors duration-150",style:{color:"var(--accent)"},onMouseEnter:x=>{x.currentTarget.style.textDecoration="underline"},onMouseLeave:x=>{x.currentTarget.style.textDecoration="none"},children:"View full history →"})]})})]})}function Ci({evals:e,onSave:r,onCancel:n}){const[s,o]=l.useState(""),[a,i]=l.useState(""),[c,d]=l.useState(""),[u,p]=l.useState([{id:`assert-${Date.now()}`,text:"",type:"boolean"}]),[f,h]=l.useState("unit"),[m,g]=l.useState(""),[x,v]=l.useState([]),[b,y]=l.useState(""),[j,S]=l.useState(""),w=Math.max(0,...e.evals.map(C=>C.id))+1,R=C=>{h(C),C==="unit"&&(v([]),g(""),y(""),S(""))},k=()=>{const C=m.trim().toUpperCase();C&&!x.includes(C)&&v([...x,C]),g("")},E=()=>{if(!s.trim()||!a.trim())return;const C={id:w,name:s.trim(),prompt:a.trim(),expected_output:c.trim(),files:[],assertions:u.filter(N=>N.text.trim()),...f==="integration"?{testType:"integration",...x.length>0?{requiredCredentials:x}:{},...b||j?{requirements:{...b?{platform:b}:{},...j?{chromeProfile:j}:{}}}:{}}:{}};r({...e,evals:[...e.evals,C]})};return t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center animate-overlay-in",style:{background:"rgba(0,0,0,0.6)"},children:t.jsxs("div",{className:"w-full max-w-lg rounded-xl p-6 animate-modal-in",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)",maxHeight:"85vh",overflowY:"auto"},children:[t.jsx("div",{className:"text-[15px] font-semibold mb-4",style:{color:"var(--text-primary)"},children:"New Test Case"}),t.jsxs("div",{className:"mb-3",children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider mb-1.5 block",style:{color:"var(--text-tertiary)"},children:"Type"}),t.jsx("div",{className:"flex gap-1 p-0.5 rounded-lg",style:{background:"var(--surface-2)",display:"inline-flex"},children:["unit","integration"].map(C=>t.jsx("button",{onClick:()=>R(C),className:"px-3 py-1 rounded-md text-[12px] font-medium transition-all duration-150",style:{background:f===C?C==="unit"?"var(--accent-muted)":"var(--orange-muted)":"transparent",color:f===C?C==="unit"?"var(--accent)":"var(--orange)":"var(--text-tertiary)",border:"none",cursor:"pointer",textTransform:"capitalize"},children:C},C))})]}),t.jsxs("label",{className:"block mb-3",children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider mb-1 block",style:{color:"var(--text-tertiary)"},children:"Name"}),t.jsx("input",{value:s,onChange:C=>o(C.target.value),className:"input-field",placeholder:"e.g., auth-check",autoFocus:!0})]}),t.jsxs("label",{className:"block mb-3",children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider mb-1 block",style:{color:"var(--text-tertiary)"},children:"Prompt"}),t.jsx("textarea",{value:a,onChange:C=>i(C.target.value),className:"input-field",rows:3,placeholder:"User prompt to test..."})]}),t.jsxs("label",{className:"block mb-3",children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider mb-1 block",style:{color:"var(--text-tertiary)"},children:"Expected Output"}),t.jsx("textarea",{value:c,onChange:C=>d(C.target.value),className:"input-field",rows:2,placeholder:"Description of expected behavior..."})]}),t.jsxs("div",{className:"mb-4",children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider mb-2 block",style:{color:"var(--text-tertiary)"},children:"Assertions"}),u.map((C,N)=>t.jsxs("div",{className:"flex gap-2 mb-2",children:[t.jsx("input",{value:C.text,onChange:I=>p(u.map((P,L)=>L===N?{...P,text:I.target.value}:P)),className:"input-field flex-1 text-[12px]",placeholder:"e.g., Output includes a greeting"}),u.length>1&&t.jsx("button",{onClick:()=>p(u.filter((I,P)=>P!==N)),className:"btn btn-ghost p-1",style:{color:"var(--text-tertiary)"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},C.id)),t.jsx("button",{onClick:()=>p([...u,{id:`assert-${Date.now()}`,text:"",type:"boolean"}]),className:"text-[11px] mt-1 transition-colors duration-150",style:{color:"var(--accent)"},children:"+ Add Assertion"})]}),f==="integration"&&t.jsxs("div",{className:"mb-4 p-3 rounded-lg",style:{background:"var(--orange-muted)",border:"1px solid var(--orange-muted)"},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider mb-2 block",style:{color:"var(--orange)"},children:"Integration Settings"}),t.jsxs("div",{className:"mb-3",children:[t.jsx("span",{className:"text-[11px] mb-1 block",style:{color:"var(--text-secondary)"},children:"Required Credentials"}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1.5",children:x.map(C=>t.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-mono",style:{background:"var(--orange-muted)",color:"var(--orange)"},children:[C,t.jsx("button",{onClick:()=>v(x.filter(N=>N!==C)),style:{color:"var(--orange)",lineHeight:1},children:t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},C))}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx("input",{value:m,onChange:C=>g(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),k())},className:"input-field flex-1 text-[11px] font-mono",placeholder:"e.g., SLACK_BOT_TOKEN"}),t.jsx("button",{onClick:k,className:"btn btn-ghost text-[11px]",style:{color:"var(--orange)"},children:"Add"})]})]}),t.jsxs("label",{className:"block mb-3",children:[t.jsx("span",{className:"text-[11px] mb-1 block",style:{color:"var(--text-secondary)"},children:"Platform"}),t.jsx("input",{value:b,onChange:C=>y(C.target.value),className:"input-field text-[11px]",placeholder:"e.g., linkedin, twitter"})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-[11px] mb-1 block",style:{color:"var(--text-secondary)"},children:"Chrome Profile"}),t.jsx("input",{value:j,onChange:C=>S(C.target.value),className:"input-field text-[11px]",placeholder:"e.g., Default"})]})]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx("button",{onClick:n,className:"btn btn-secondary text-[12px]",children:"Cancel"}),t.jsx("button",{onClick:E,disabled:!s.trim()||!a.trim(),className:"btn btn-primary text-[12px]",children:"Save"})]})]})})}function $v({evalCase:e,onUpdate:r}){var i,c;const[n,s]=l.useState(""),o=()=>{const d=n.trim().toUpperCase();d&&!(e.requiredCredentials??[]).includes(d)&&r({...e,requiredCredentials:[...e.requiredCredentials??[],d]}),s("")},a=d=>{const u=(e.requiredCredentials??[]).filter(p=>p!==d);r({...e,requiredCredentials:u.length>0?u:void 0})};return t.jsxs("div",{className:"mb-4 p-3 rounded-lg",style:{background:"var(--orange-muted)",border:"1px solid var(--orange-muted)"},children:[t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider mb-2 block",style:{color:"var(--orange)"},children:"Integration Settings"}),t.jsxs("div",{className:"mb-2.5",children:[t.jsx("span",{className:"text-[10px] mb-1 block",style:{color:"var(--text-secondary)"},children:"Required Credentials"}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-1.5",children:(e.requiredCredentials??[]).map(d=>t.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-mono",style:{background:"var(--orange-muted)",color:"var(--orange)"},children:[d,t.jsx("button",{onClick:()=>a(d),style:{color:"var(--orange)",lineHeight:1},children:t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},d))}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx("input",{value:n,onChange:d=>s(d.target.value),onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),o())},className:"input-field flex-1 text-[11px] font-mono",placeholder:"e.g., GITHUB_TOKEN"}),t.jsx("button",{onClick:o,className:"btn btn-ghost text-[11px]",style:{color:"var(--orange)"},children:"Add"})]})]}),t.jsxs("div",{className:"mb-2.5",children:[t.jsx("span",{className:"text-[10px] mb-1 block",style:{color:"var(--text-secondary)"},children:"Platform"}),t.jsx("input",{value:((i=e.requirements)==null?void 0:i.platform)??"",onChange:d=>r({...e,requirements:{...e.requirements,platform:d.target.value||void 0}}),className:"input-field text-[11px]",placeholder:"e.g., linkedin, twitter"})]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-[10px] mb-1 block",style:{color:"var(--text-secondary)"},children:"Chrome Profile"}),t.jsx("input",{value:((c=e.requirements)==null?void 0:c.chromeProfile)??"",onChange:d=>r({...e,requirements:{...e.requirements,chromeProfile:d.target.value||void 0}}),className:"input-field text-[11px]",placeholder:"e.g., Default"})]})]})}function $s(e,r){typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:e,severity:r}}))}function Mv({size:e=15}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"16 18 22 12 16 6"}),t.jsx("polyline",{points:"8 6 2 12 8 18"})]})}function Dv({size:e=15}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"3"}),t.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"21"})]})}function Fv({size:e=15}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function zv({size:e=15}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M15 4V2"}),t.jsx("path",{d:"M15 16v-2"}),t.jsx("path",{d:"M8 9h2"}),t.jsx("path",{d:"M20 9h2"}),t.jsx("path",{d:"M17.8 11.8L19 13"}),t.jsx("path",{d:"M15 9h.01"}),t.jsx("path",{d:"M17.8 6.2L19 5"}),t.jsx("path",{d:"M11 6.2L9.7 5"}),t.jsx("path",{d:"M3 21l9-9"})]})}function Ms({size:e=15}){return t.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M12 3l1.5 5.5L19 10l-5.5 1.5L12 17l-1.5-5.5L5 10l5.5-1.5L12 3z"})})}function Bv(){const{state:e,dispatch:r,saveContent:n,isReadOnly:s}=ft(),{plugin:o,skill:a,skillContent:i,isDirty:c,improveTarget:d,aiEditOpen:u}=e,[p,f]=l.useState("split"),[h,m]=l.useState(!1),g=l.useRef(null),[x,v]=l.useState(!1),[b,y]=l.useState(""),[j,S]=l.useState(!1),[w,R]=l.useState(null),[k,E]=l.useState([]),[C,N]=l.useState([]),[I,P]=l.useState(null),L=l.useRef(null),{config:B}=hr(),T=kv(),{files:$,activeFile:M,secondaryContent:F,loading:W,error:le,loadError:U,selectFile:H,refresh:ee,isSkillMd:K}=iv(o??"",a??""),[X,G]=l.useState(!1),he=l.useCallback(Q=>{X&&!window.confirm("You have unsaved changes. Discard?")||H(Q)},[X,H]);l.useEffect(()=>()=>{var Q;(Q=L.current)==null||Q.abort()},[]);const{metadata:A,body:O}=qc(i),V=A["allowed-tools"],re=Array.isArray(V)?V:typeof V=="string"?[V]:[],ce=A.name,ne=A.description,ve=A.metadata,ge=typeof ve=="object"&&!Array.isArray(ve)?ve:null,se=A.version||(ge==null?void 0:ge.version),fe=A.tags||(ge==null?void 0:ge.tags),z=Array.isArray(fe)?fe:typeof fe=="string"?fe.split(",").map(Q=>Q.trim()).filter(Boolean):[],q=new Set(["name","description","metadata","allowed-tools","version","tags"]),Z=Object.entries(A).filter(([Q])=>!q.has(Q)),J=l.useCallback(async()=>{const{contentToSave:Q,version:Re,fromVersion:je}=Sv(i,e.savedContent);if(Re!==null){const $e=wv(je,Re);if(!$e.valid){$s(`Save blocked: ${$e.reason??"invalid version transition"}`,"error");return}}m(!0),await n(Q),m(!1),typeof window<"u"&&window.dispatchEvent(new CustomEvent("studio:content-saved",{detail:{plugin:o,skill:a,version:Re}}))},[n,i,e.savedContent,o,a]),ue=l.useCallback(Q=>{const Re=Jn(i)??"1.0.0";let je;try{je=Yr(Re,Q)}catch(He){const nt=He instanceof Error?He.message:String(He);$s(`Bump failed: ${nt}`,"error");return}const $e=td(i,je);r({type:"SET_CONTENT",content:$e}),$s(`Bumped to v${je} (${Q}). Click Save to commit.`,"info")},[i,r]),de=l.useCallback(Q=>{(Q.ctrlKey||Q.metaKey)&&Q.key==="s"&&(Q.preventDefault(),Q.stopPropagation(),c&&J()),(Q.ctrlKey||Q.metaKey)&&Q.key==="i"&&(Q.preventDefault(),Q.stopPropagation(),r({type:u?"CLOSE_AI_EDIT":"OPEN_AI_EDIT"}))},[c,J,u,r]),we=l.useCallback(async()=>{var Re,je;if(!b.trim())return;(Re=L.current)==null||Re.abort();const Q=new AbortController;L.current=Q,S(!0),P(null),N([]),R(null),E([]);try{const $e=(B==null?void 0:B.provider)||"claude-cli",He=(B==null?void 0:B.model)||"sonnet",nt=await fetch("/api/skills/generate?sse",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:b,provider:$e,model:He}),signal:Q.signal});if(!nt.ok||!nt.body){let tt=`HTTP ${nt.status}`;try{const mt=await nt.json();mt.error&&(tt=mt.error)}catch{}throw new Error(tt)}const St=nt.body.getReader(),vr=new TextDecoder;let Xt="",Ue="";for(;;){const{done:tt,value:mt}=await St.read();if(tt)break;Xt+=vr.decode(mt,{stream:!0});const Tt=Xt.split(`
51
+ `);Xt=Tt.pop()||"";for(const xt of Tt)if(xt.startsWith("event: "))Ue=xt.slice(7).trim();else if(xt.startsWith("data: ")){try{const rt=JSON.parse(xt.slice(6));if(Ue==="progress")N(ht=>[...ht,{phase:rt.phase,message:rt.message,timestamp:Date.now()}]);else if(Ue==="done"||Ue==="complete"){const ht=["---"];rt.name&&ht.push(`name: ${rt.name}`),rt.description&&ht.push(`description: "${rt.description.replace(/"/g,'\\"')}"`),rt.model&&ht.push(`model: ${rt.model}`),(je=rt.allowedTools)!=null&&je.trim()&&ht.push(`allowed-tools: ${rt.allowedTools.trim()}`),ht.push("---","",rt.body||"");const Ce=ht.join(`
52
+ `);R(Ce),E(ds(i,Ce)),S(!1)}else Ue==="error"&&(P(rt.message||rt.description||"Generation failed"),S(!1))}catch{}Ue=""}}}catch($e){$e.name!=="AbortError"&&P($e.message)}finally{S(!1),L.current=null}},[b,B,i]),Ie=l.useCallback(()=>{w&&r({type:"SET_CONTENT",content:w}),v(!1),R(null),E([]),y(""),N([])},[w,r]),Fe=l.useCallback(()=>{v(!1),R(null),E([]),y(""),N([]),P(null)},[]),Ke=l.useCallback(()=>{var Q;x?((Q=L.current)==null||Q.abort(),Fe()):(u&&r({type:"CLOSE_AI_EDIT"}),v(!0))},[x,u,r,Fe]),Ye=[{mode:"raw",icon:t.jsx(Mv,{}),label:"Editor"},{mode:"split",icon:t.jsx(Dv,{}),label:"Split"},{mode:"preview",icon:t.jsx(Fv,{}),label:"Preview"}];return t.jsxs("div",{className:"flex flex-col",style:{height:"100%",overflow:"auto"},onKeyDown:de,tabIndex:-1,children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5",style:{borderBottom:"1px solid var(--border-subtle)",background:"var(--surface-1)"},children:[t.jsx("div",{className:"flex items-center",style:{background:"var(--surface-2)",borderRadius:8,padding:2,gap:1},children:Ye.map(({mode:Q,icon:Re,label:je})=>t.jsxs("button",{onClick:()=>f(Q),title:je,className:"flex items-center gap-1.5 rounded-md transition-all duration-150",style:{padding:"5px 10px",background:p===Q?"var(--surface-4)":"transparent",color:p===Q?"var(--text-primary)":"var(--text-tertiary)",fontSize:11,fontWeight:p===Q?600:400,border:"none",cursor:"pointer"},children:[Re,t.jsx("span",{style:{letterSpacing:"0.01em"},children:je})]},Q))}),K?s?t.jsx("div",{className:"flex items-center gap-2",children:t.jsxs("span",{className:"flex items-center gap-1.5 text-[11px]",style:{color:"var(--text-tertiary)"},children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),"Read-only"]})}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("button",{onClick:()=>{u?r({type:"CLOSE_AI_EDIT"}):(x&&Fe(),r({type:"OPEN_AI_EDIT"}))},title:"Edit with AI (Ctrl+K)",className:"flex items-center gap-1.5 rounded-md transition-all duration-150",style:{padding:"4px 10px",fontSize:11,fontWeight:u?600:400,border:"none",cursor:"pointer",color:u?"var(--purple)":"var(--text-tertiary)",background:u?"var(--purple-muted)":"transparent"},children:[t.jsx(zv,{size:13}),t.jsx("span",{children:"AI Edit"})]}),t.jsxs("button",{onClick:Ke,title:"Regenerate skill from prompt",className:"flex items-center gap-1.5 rounded-md transition-all duration-150",style:{padding:"4px 10px",fontSize:11,fontWeight:x?600:400,border:"none",cursor:"pointer",color:x?"var(--purple)":"var(--text-tertiary)",background:x?"var(--purple-muted)":"transparent"},children:[t.jsx(Ms,{size:13}),t.jsx("span",{children:"Regenerate"})]}),t.jsx("div",{style:{width:1,height:16,background:"var(--border-subtle)"}}),!s&&(()=>{const Q=Jn(i)??"1.0.0";let Re=Q,je=Q,$e=Q;try{Re=Yr(Q,"patch"),je=Yr(Q,"minor"),$e=Yr(Q,"major")}catch{}const He={padding:"4px 8px"};return t.jsxs("div",{style:{display:"inline-flex",gap:2,alignItems:"center"},"aria-label":"Version bump","data-testid":"version-bump-controls",children:[t.jsx("button",{type:"button",onClick:()=>ue("patch"),title:`Bump patch: ${Q} → ${Re}`,"aria-label":"Bump patch version",className:"btn btn-ghost text-[11px]",style:He,children:"+patch"}),t.jsx("button",{type:"button",onClick:()=>ue("minor"),title:`Bump minor: ${Q} → ${je}`,"aria-label":"Bump minor version",className:"btn btn-ghost text-[11px]",style:He,children:"+minor"}),t.jsx("button",{type:"button",onClick:()=>ue("major"),title:`Bump major: ${Q} → ${$e}`,"aria-label":"Bump major version",className:"btn btn-ghost text-[11px]",style:He,children:"+major"})]})})(),c&&t.jsx("button",{onClick:()=>r({type:"SET_CONTENT",content:e.savedContent}),className:"btn btn-ghost text-[11px]",style:{padding:"4px 8px"},children:"Discard"}),t.jsx("button",{onClick:J,disabled:!c||h,className:"btn btn-primary text-[11px]",style:{padding:"5px 14px"},children:h?t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"spinner",style:{width:11,height:11,borderWidth:1.5}})," Saving..."]}):"Save"}),T.hasRemote&&T.remoteUrl&&t.jsx(Zc,{remoteUrl:T.remoteUrl,provider:B==null?void 0:B.provider,model:B==null?void 0:B.model})]}):null]}),o&&a&&t.jsx(pv,{files:$,activeFile:M,onSelect:he,onRefresh:ee,loadError:U}),!K&&t.jsx(mv,{file:F,loading:W,error:le,viewMode:p,plugin:o??void 0,skill:a??void 0,onSaved:()=>{H(M),ee()},onDirtyChange:G}),K&&t.jsxs("div",{className:"flex-1 overflow-hidden",style:{display:"grid",gridTemplateColumns:p==="raw"||p==="preview"?"1fr":"1fr 1fr",minHeight:"60vh"},children:[p!=="preview"&&t.jsx("div",{className:"flex flex-col overflow-hidden",style:{borderRight:p==="split"?"1px solid var(--border-subtle)":"none"},children:t.jsx("textarea",{ref:g,value:i,onChange:Q=>{!s&&!h&&r({type:"SET_CONTENT",content:Q.target.value})},onKeyDown:de,spellCheck:!1,readOnly:s||h,className:"flex-1 w-full resize-none outline-none",style:{background:"var(--surface-0)",color:"var(--text-primary)",fontFamily:"var(--font-mono, 'JetBrains Mono', ui-monospace, monospace)",fontSize:12.5,lineHeight:1.7,tabSize:2,border:"none",padding:"16px 20px",opacity:s?.7:1}})}),p!=="raw"&&t.jsx("div",{className:"overflow-auto",style:{background:"var(--surface-0)"},children:t.jsxs("div",{className:"animate-fade-in",style:{padding:"20px 24px",maxWidth:720},children:[(ce||se||ne)&&t.jsxs("div",{style:{marginBottom:20},children:[t.jsxs("div",{className:"flex items-baseline gap-3",style:{marginBottom:8},children:[ce&&t.jsx("h2",{style:{fontSize:18,fontWeight:700,color:"var(--text-primary)",letterSpacing:"-0.02em",lineHeight:1.2,margin:0},children:ce}),se&&t.jsxs("span",{style:{fontSize:10,fontWeight:600,color:"var(--accent)",background:"var(--accent-muted)",padding:"2px 7px",borderRadius:4,letterSpacing:"0.03em",fontFamily:"var(--font-mono, ui-monospace, monospace)"},children:["v",se]})]}),ne&&t.jsx("p",{style:{fontSize:12.5,lineHeight:1.65,color:"var(--text-secondary)",margin:0,paddingLeft:12,borderLeft:"2px solid var(--accent)",maxWidth:600},children:ne})]}),z.length>0&&t.jsx("div",{className:"flex flex-wrap items-center gap-1.5",style:{marginBottom:16},children:z.map(Q=>t.jsx("span",{style:{fontSize:10,fontWeight:500,color:"var(--text-tertiary)",background:"var(--surface-2)",padding:"3px 8px",borderRadius:4,letterSpacing:"0.02em"},children:Q},Q))}),re.length>0&&t.jsx("div",{style:{marginBottom:16},children:t.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[t.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--text-tertiary)",marginRight:4},children:"Tools"}),re.map(Q=>t.jsx("span",{style:{fontSize:10.5,fontFamily:"var(--font-mono, ui-monospace, monospace)",color:"var(--accent)",background:"var(--accent-muted)",padding:"2px 7px",borderRadius:4},children:Q},Q))]})}),Z.length>0&&t.jsx("div",{style:{marginBottom:16,padding:"8px 0",borderTop:"1px solid var(--border-subtle)",borderBottom:"1px solid var(--border-subtle)"},children:Z.map(([Q,Re],je)=>{const $e=Array.isArray(Re)?Re.join(", "):typeof Re=="object"?Object.entries(Re).map(([He,nt])=>`${He}: ${Array.isArray(nt)?nt.join(", "):nt}`).join(" | "):Re;return t.jsxs("div",{className:"flex items-baseline gap-3",style:{padding:"4px 0",borderTop:je>0?"1px solid var(--border-subtle)":"none"},children:[t.jsx("span",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.06em",color:"var(--text-tertiary)",minWidth:80,flexShrink:0},children:Q}),t.jsx("span",{style:{fontSize:12,color:"var(--text-secondary)"},children:$e})]},Q)})}),(ce||ne||z.length>0||re.length>0||Z.length>0)&&O&&t.jsx("div",{style:{height:1,background:"linear-gradient(90deg, var(--accent) 0%, var(--border-subtle) 40%, transparent 100%)",marginBottom:20,opacity:.5}}),O&&t.jsx("div",{className:"text-[13px] leading-relaxed overflow-x-auto",style:{color:"var(--text-secondary)",wordBreak:"break-word"},dangerouslySetInnerHTML:{__html:bn(O)}})]})})]}),K&&u&&t.jsx(av,{}),K&&x&&t.jsx("div",{className:"animate-fade-in",style:{borderTop:"1px solid var(--border-subtle)",background:"var(--surface-1)"},children:t.jsxs("div",{className:"px-4 py-3",children:[!w&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx(Ms,{size:14}),t.jsx("span",{className:"text-[12px] font-semibold",style:{color:"var(--text-primary)"},children:"Regenerate Skill"})]}),t.jsx("div",{className:"flex gap-2 mb-2",children:t.jsx("textarea",{value:b,onChange:Q=>y(Q.target.value),placeholder:"Describe what this skill should do...",rows:2,disabled:j,className:"flex-1 px-3 py-2 rounded-lg text-[12px] resize-none",style:{background:"var(--surface-0)",color:"var(--text-primary)",border:"1px solid var(--border-subtle)",outline:"none",opacity:j?.5:1},onKeyDown:Q=>{Q.key==="Enter"&&(Q.ctrlKey||Q.metaKey)&&b.trim()&&!j&&(Q.preventDefault(),we())}})}),t.jsxs("div",{className:"flex items-center gap-2",children:[j?t.jsx("button",{onClick:()=>{var Q;(Q=L.current)==null||Q.abort(),S(!1)},className:"btn btn-secondary text-[11px]",style:{padding:"4px 12px"},children:"Cancel"}):t.jsx("button",{onClick:we,disabled:!b.trim(),className:"btn btn-primary text-[11px]",style:{padding:"4px 12px"},children:"Generate"}),t.jsx("button",{onClick:Fe,className:"btn btn-ghost text-[11px]",style:{padding:"4px 8px"},children:"Close"})]}),j&&C.length>0&&t.jsx("div",{className:"mt-2",children:t.jsx(kn,{entries:C,isRunning:!0})}),I&&t.jsxs("div",{className:"mt-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"var(--red-muted)",color:"var(--red)"},children:[I,t.jsx("button",{onClick:we,className:"ml-2 underline",style:{color:"var(--red)"},children:"Retry"})]})]}),w&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[t.jsx(Ms,{size:14}),t.jsx("span",{className:"text-[12px] font-semibold",style:{color:"var(--text-primary)"},children:"Regenerated — Review Changes"})]}),t.jsx("div",{className:"rounded-lg overflow-hidden mb-3",style:{border:"1px solid var(--border-subtle)",maxHeight:"300px",overflowY:"auto"},children:k.map((Q,Re)=>t.jsxs("div",{className:"px-3 py-0.5 text-[11px] font-mono",style:{background:Q.type==="added"?"var(--green-muted)":Q.type==="removed"?"var(--red-muted)":"transparent",color:Q.type==="added"?"var(--green)":Q.type==="removed"?"var(--red)":"var(--text-secondary)",borderLeft:Q.type==="added"?"3px solid var(--green)":Q.type==="removed"?"3px solid var(--red)":"3px solid transparent"},children:[t.jsx("span",{style:{userSelect:"none",opacity:.5,marginRight:8},children:Q.type==="added"?"+":Q.type==="removed"?"-":" "}),Q.content]},Re))}),t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("button",{onClick:Ie,className:"btn btn-primary text-[11px]",style:{padding:"4px 12px"},children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Apply"]}),t.jsx("button",{onClick:Fe,className:"btn btn-secondary text-[11px]",style:{padding:"4px 12px"},children:"Discard"})]})]})]})}),K&&d!==null&&o&&a&&t.jsx("div",{style:{borderTop:"1px solid var(--border-subtle)"},children:t.jsx(Zg,{plugin:o,skill:a,skillContent:i,onApplied:Q=>{r({type:"SET_CONTENT",content:Q}),r({type:"CONTENT_SAVED"}),r({type:"CLOSE_IMPROVE"})}})}),K&&t.jsx(_v,{})]})}function _v(){var d;const[e,r]=l.useState(()=>{var u;return typeof window>"u"?!1:((u=window.localStorage)==null?void 0:u.getItem("vskill:editor-eval-cases-open"))==="1"}),{state:n,canEdit:s}=ft(),o=((d=n.evals)==null?void 0:d.evals)??[],a=u=>{var f;const p=u.currentTarget.open;if(r(p),typeof window<"u")try{(f=window.localStorage)==null||f.setItem("vskill:editor-eval-cases-open",p?"1":"0")}catch{}},i=l.useCallback(u=>{var h;if((h=u.preventDefault)==null||h.call(u),typeof window>"u")return;const p=new URLSearchParams(window.location.search);p.set("tab","run"),p.set("mode","benchmark"),p.set("autorun","1");const f=`${window.location.pathname}?${p.toString()}${window.location.hash}`;window.history.replaceState(null,"",f),window.dispatchEvent(new PopStateEvent("popstate"))},[]),c=s&&o.length>0;return t.jsxs("details",{"data-testid":"editor-eval-cases-section",open:e,onToggle:a,style:{borderTop:"1px solid var(--border-subtle)",background:"var(--bg-canvas)"},children:[t.jsxs("summary",{style:{padding:"10px 16px",fontFamily:"var(--font-sans)",fontSize:13,fontWeight:500,color:"var(--text-primary)",cursor:"pointer",userSelect:"none",background:"var(--surface-1)",borderBottom:e?"1px solid var(--border-subtle)":"none",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[t.jsx("span",{children:"Eval cases"}),c&&t.jsx("button",{type:"button","data-testid":"editor-eval-cases-run-all",onClick:i,title:"Run all → opens Run tab",className:"btn btn-primary text-[11px] px-2 py-0.5",style:{whiteSpace:"nowrap"},children:"Run all"})]}),e&&t.jsx("div",{"data-testid":"editor-eval-cases-body",style:{height:520,overflow:"hidden"},children:t.jsx(ld,{embedded:!0})})]})}function Ov(e){if(e==null||!Number.isFinite(e))return"—";if(e<1024)return`${e} B`;const r=e/1024;if(r<1024)return r>=10?`${Math.round(r)} KB`:`${r.toFixed(1).replace(/\.0$/,"")} KB`;const n=r/1024;return n>=10?`${Math.round(n)} MB`:`${n.toFixed(1).replace(/\.0$/,"")} MB`}const Wv={vskill:{label:"vskill",bg:"var(--accent-muted, #e0f2fe)",fg:"var(--accent, #0369a1)",border:"var(--accent, #0369a1)"},anthropic:{label:"Anthropic",bg:"var(--orange-muted, #fff1e0)",fg:"var(--orange, #c2410c)",border:"var(--orange, #c2410c)"},local:{label:"Local",bg:"var(--surface-3, #e5e5e5)",fg:"var(--text-tertiary, #666)",border:"var(--border-default, #ccc)"}};function Io({provider:e,size:r="sm"}){if(!e)return null;const n=Wv[e],s=r==="md"?11:9;return t.jsx("span",{"data-testid":`provider-chip-${e}`,"data-provider":e,style:{display:"inline-flex",alignItems:"center",padding:r==="md"?"2px 8px":"1.5px 6px",fontSize:s,fontWeight:500,fontFamily:"var(--font-sans)",background:n.bg,color:n.fg,border:`1px solid ${n.border}`,borderRadius:999,lineHeight:1.4,whiteSpace:"nowrap"},children:n.label})}function Hv({content:e,defaultExpanded:r=!0}){const[n,s]=l.useState(r),{metadata:o,body:a}=qc(e);if(!e.trim())return null;const i=Object.keys(o).length>0,c=o["allowed-tools"],d=Array.isArray(c)?c:typeof c=="string"?[c]:[],u=Object.entries(o).filter(([p])=>p!=="allowed-tools");return t.jsxs("div",{className:"mb-5 rounded-xl overflow-hidden",style:{border:"1px solid var(--border-subtle)",background:"var(--surface-1)"},children:[t.jsxs("button",{onClick:()=>s(!n),className:"w-full flex items-center justify-between px-5 py-3.5 text-left transition-colors duration-150",style:{background:"var(--surface-2)"},onMouseEnter:p=>{p.currentTarget.style.background="var(--surface-3)"},onMouseLeave:p=>{p.currentTarget.style.background="var(--surface-2)"},children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{background:"var(--accent-muted)"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),t.jsx("polyline",{points:"14 2 14 8 20 8"}),t.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),t.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),t.jsxs("div",{children:[t.jsx("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:"SKILL.md"}),t.jsx("span",{className:"text-[11px] ml-2",style:{color:"var(--text-tertiary)"},children:"Skill Definition"})]})]}),t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2",style:{transform:n?"rotate(180deg)":"rotate(0)",transition:"transform 0.2s ease"},children:t.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),n&&t.jsxs("div",{className:"px-5 py-4 animate-fade-in",children:[i&&t.jsx("div",{className:"grid grid-cols-2 gap-3 mb-4",children:u.map(([p,f])=>{const h=Array.isArray(f)?f.join(", "):typeof f=="object"?Object.entries(f).map(([m,g])=>`${m}: ${Array.isArray(g)?g.join(", "):g}`).join(" | "):f;return t.jsxs("div",{className:"px-3 py-2.5 rounded-lg",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)"},children:[t.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider mb-1",style:{color:"var(--text-tertiary)"},children:p}),t.jsx("div",{className:"text-[12px]",style:{color:"var(--text-primary)"},children:h})]},p)})}),d.length>0&&t.jsxs("div",{className:"mb-4",children:[t.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider mb-2",style:{color:"var(--text-tertiary)"},children:"Allowed Tools"}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:d.map(p=>t.jsx("span",{className:"px-2 py-1 rounded-md text-[11px] font-mono",style:{background:"var(--accent-muted)",color:"var(--accent)"},children:p},p))})]}),a&&t.jsx("div",{className:"text-[12px] leading-relaxed p-4 rounded-lg overflow-x-auto",style:{background:"var(--surface-0)",color:"var(--text-secondary)",border:"1px solid var(--border-subtle)",maxHeight:"400px",overflowY:"auto"},dangerouslySetInnerHTML:{__html:bn(a)}})]})]})}function Uv(e){const r={name:"",path:"",type:"dir",size:0,children:[]};for(const s of e){if(s.type!=="file")continue;const o=s.path.split("/");let a=r;for(let i=0;i<o.length;i++){const c=o[i],d=i===o.length-1;let u=a.children.find(p=>p.name===c);u||(u={name:c,path:o.slice(0,i+1).join("/"),type:d?"file":"dir",size:d?s.size:0,children:[]},a.children.push(u)),a=u}}const n=s=>{s.children.sort((o,a)=>o.type!==a.type?o.type==="dir"?-1:1:o.name.localeCompare(a.name)),s.children.forEach(n)};return n(r),r}function Vv(e){const r=e.lastIndexOf(".");return r>=0?e.slice(r+1).toLowerCase():""}function Gv(e){const r=Vv(e);return e==="SKILL.md"?"📘":r==="md"?"📄":r==="ts"||r==="tsx"||r==="js"||r==="jsx"?"📜":r==="json"||r==="yaml"||r==="yml"||r==="toml"?"🔧":r==="sh"||r==="bash"?"🖥":r==="png"||r==="jpg"||r==="jpeg"||r==="gif"||r==="webp"||r==="svg"?"🖼":"📄"}function ud({node:e,depth:r,activePath:n,focusedPath:s,onSelect:o,expanded:a,onToggle:i}){if(e.type==="dir"){const u=a.has(e.path),p=e.path===s;return t.jsxs("div",{children:[t.jsxs("button",{type:"button","data-testid":"source-tree-item","data-path":e.path,"data-type":"dir","data-focused":p?"true":"false",role:"treeitem","aria-expanded":u,onClick:()=>i(e.path),style:{width:"100%",textAlign:"left",background:p?"var(--surface-2)":"transparent",border:"none",padding:`4px 8px 4px ${r*12+8}px`,color:"var(--text-secondary)",fontFamily:"var(--font-sans)",fontSize:12,cursor:"pointer",display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{width:10,display:"inline-block"},children:u?"▾":"▸"}),t.jsx("span",{children:"📁"}),t.jsx("span",{children:e.name})]}),u&&t.jsx("div",{role:"group",children:e.children.map(f=>t.jsx(ud,{node:f,depth:r+1,activePath:n,focusedPath:s,onSelect:o,expanded:a,onToggle:i},f.path))})]})}const c=e.path===n,d=e.path===s;return t.jsxs("button",{type:"button","data-testid":"source-tree-item","data-path":e.path,"data-type":"file","data-active":c?"true":"false","data-focused":d?"true":"false",role:"treeitem","aria-selected":c,onClick:()=>o(e.path),style:{width:"100%",textAlign:"left",background:c?"var(--surface-3)":d?"var(--surface-2)":"transparent",border:"none",padding:`4px 8px 4px ${r*12+8}px`,color:c?"var(--text-primary)":"var(--text-secondary)",fontFamily:"var(--font-sans)",fontSize:12,fontWeight:c?600:400,cursor:"pointer",display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:{width:10,display:"inline-block"},children:" "}),t.jsx("span",{children:Gv(e.name)}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:e.name})]})}function Kv({files:e,activePath:r,onSelect:n}){const s=l.useMemo(()=>Uv(e),[e]),o=l.useMemo(()=>{const m=new Set;if(r&&r.includes("/")){const g=r.split("/");for(let x=1;x<g.length;x++)m.add(g.slice(0,x).join("/"))}return s.children.forEach(g=>{g.type==="dir"&&m.add(g.path)}),m},[s,r]),[a,i]=l.useState(o);l.useEffect(()=>{i(m=>{const g=new Set(m);let x=!1;return o.forEach(v=>{g.has(v)||(g.add(v),x=!0)}),x?g:m})},[o]);const c=m=>{i(g=>{const x=new Set(g);return x.has(m)?x.delete(m):x.add(m),x})},d=l.useMemo(()=>{const m=[],g=x=>{for(const v of x)m.push({path:v.path,type:v.type}),v.type==="dir"&&a.has(v.path)&&g(v.children)};return g(s.children),m},[s,a]),u=l.useRef(null),[p,f]=l.useState(()=>Math.max(0,d.findIndex(m=>m.path===r)));l.useEffect(()=>{const m=d.findIndex(g=>g.path===r);m>=0&&f(m)},[r,d]);const h=m=>{var g;if(d.length!==0)if(m.key==="ArrowDown")m.preventDefault(),f(x=>Math.min(d.length-1,x+1));else if(m.key==="ArrowUp")m.preventDefault(),f(x=>Math.max(0,x-1));else if(m.key==="Enter"){m.preventDefault();const x=d[p];if(!x)return;x.type==="dir"?c(x.path):n(x.path)}else m.key==="Escape"&&(m.preventDefault(),(g=u.current)==null||g.blur())};return s.children.length===0?t.jsx("div",{"data-testid":"source-tree-empty",style:{padding:16,fontSize:12,color:"var(--text-tertiary)",fontFamily:"var(--font-sans)"},children:"No files found."}):t.jsx("div",{"data-testid":"source-file-tree",ref:u,tabIndex:0,onKeyDown:h,role:"tree","aria-label":"Skill files",style:{paddingTop:4,paddingBottom:4,outline:"none"},children:s.children.map(m=>{var g;return t.jsx(ud,{node:m,depth:0,activePath:r,focusedPath:(g=d[p])==null?void 0:g.path,onSelect:n,expanded:a,onToggle:c},m.path)})})}const qv=new Set(["md","txt","json","yaml","yml","toml","ini","env","ts","tsx","js","jsx","mjs","cjs","py","rb","go","rs","java","c","cc","cpp","h","hpp","sh","bash","zsh","fish","html","css","scss","less","xml","csv","tsv","log","diff","patch","lock","gitignore","dockerfile"]),Yv=new Set(["png","jpg","jpeg","gif","webp","ico"]);function Jv(e){const r=e.lastIndexOf(".");return r>=0?e.slice(r+1).toLowerCase():""}function Xv(e){const r=Jv(e);return r==="md"?"markdown":Yv.has(r)?"image":qv.has(r)?"text":"binary"}function Qv({content:e}){return t.jsx("div",{"data-testid":"source-md-viewer",children:t.jsx(Hv,{content:e})})}function Zv({content:e,path:r}){const n=e.split(`
53
+ `),s=n.length>5e3,o=s?n.slice(0,5e3).join(`
54
+ `):e;return t.jsxs("div",{"data-testid":"source-text-viewer",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:"70vh"},children:[t.jsxs("div",{style:{padding:"8px 12px",background:"var(--surface-2)",borderBottom:"1px solid var(--border-subtle)",fontFamily:"var(--font-sans)",fontSize:11,color:"var(--text-tertiary)"},children:[r," · ",n.length," ",n.length===1?"line":"lines",s&&" (truncated for display)"]}),t.jsx("pre",{style:{margin:0,padding:12,fontFamily:"var(--font-mono, monospace)",fontSize:12,lineHeight:1.5,color:"var(--text-primary)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:o})]})}function ey({plugin:e,skill:r,path:n}){const s=`/api/skills/${e}/${r}/file?path=${encodeURIComponent(n)}&raw=1`;return t.jsxs("div",{"data-testid":"source-image-viewer",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)",borderRadius:8,padding:16,display:"flex",flexDirection:"column",alignItems:"center",gap:8},children:[t.jsx("img",{src:s,alt:n,style:{maxWidth:"100%",maxHeight:"60vh",objectFit:"contain"}}),t.jsx("div",{style:{fontSize:11,color:"var(--text-tertiary)",fontFamily:"var(--font-sans)"},children:n})]})}function ty({path:e,size:r}){return t.jsxs("div",{"data-testid":"source-binary-placeholder",style:{background:"var(--surface-1)",border:"1px dashed var(--border-default)",borderRadius:8,padding:24,textAlign:"center",color:"var(--text-secondary)",fontFamily:"var(--font-sans)",fontSize:13},children:[t.jsxs("div",{style:{fontSize:14,fontWeight:500,marginBottom:6},children:["Binary file — ",Ov(r)]}),t.jsx("div",{style:{fontSize:11,color:"var(--text-tertiary)"},children:e})]})}function ry({plugin:e,skill:r,provider:n}){const[s,o]=l.useState([]),[a,i]=l.useState("SKILL.md"),[c,d]=l.useState(null),[u,p]=l.useState(!0),[f,h]=l.useState(null),[m,g]=l.useState(null),x=n??m;l.useEffect(()=>{if(n!==void 0)return;let b=!1;return ie.getSkillVersionsEnvelope(e,r).then(y=>{b||g(y.provider??null)}).catch(()=>{}),()=>{b=!0}},[e,r,n]),l.useEffect(()=>{let b=!1;return p(!0),h(null),ie.getSkillFiles(e,r).then(y=>{var w;if(b)return;o(y.files);const S=y.files.some(R=>R.path==="SKILL.md")?"SKILL.md":((w=y.files.find(R=>R.type==="file"))==null?void 0:w.path)??"";i(S),S||p(!1)}).catch(y=>{b||(h(y instanceof Error?y.message:String(y)),p(!1))}),()=>{b=!0}},[e,r]),l.useEffect(()=>{if(!a)return;let b=!1;return p(!0),h(null),ie.getSkillFile(e,r,a).then(y=>{b||(d(y),p(!1))}).catch(y=>{b||(h(y instanceof Error?y.message:String(y)),p(!1))}),()=>{b=!0}},[e,r,a]);const v=()=>{if(f)return t.jsxs("div",{"data-testid":"source-error",style:{padding:16,color:"var(--danger, #c00)",fontFamily:"var(--font-sans)",fontSize:13},children:["Failed to load: ",f]});if(u||!c)return t.jsx("div",{"data-testid":"source-loading",style:{padding:16,color:"var(--text-tertiary)",fontFamily:"var(--font-sans)",fontSize:13},children:"Loading…"});const b=Xv(a);return b==="markdown"?t.jsx(Qv,{content:c.content??""}):b==="text"&&!c.binary?t.jsx(Zv,{content:c.content??"",path:a}):b==="image"?t.jsx(ey,{plugin:e,skill:r,path:a}):t.jsx(ty,{path:a,size:c.size})};return t.jsxs("div",{"data-testid":"source-panel",style:{display:"flex",flexDirection:"column",height:"100%",minHeight:400,gap:12},children:[x&&t.jsxs("div",{"data-testid":"source-panel-header",style:{display:"flex",alignItems:"center",gap:8,paddingLeft:4},children:[t.jsx("span",{style:{fontSize:11,color:"var(--text-tertiary)",fontFamily:"var(--font-sans)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Provider:"}),t.jsx(Io,{provider:x})]}),t.jsxs("div",{style:{display:"grid",gridTemplateColumns:"260px 1fr",gap:16,flex:1,minHeight:0},children:[t.jsx("aside",{style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)",borderRadius:8,overflow:"auto",maxHeight:"75vh"},children:t.jsx(Kv,{files:s,activePath:a,onSelect:i})}),t.jsx("main",{style:{minWidth:0},children:v()})]})]})}function jt(e,r){return r==="free"?"Free":r==="subscription"&&e==null?"Included":e==null?"N/A":e>=1?`$${e.toFixed(2)}`:e===0?"$0.00":e>=.001?`$${e.toFixed(4)}`:`$${e.toPrecision(3).replace(/0+$/,"").replace(/\.$/,"")}`}function pd(e,r){return e==null||r==null?"N/A":`${e.toLocaleString("en-US")} in / ${r.toLocaleString("en-US")} out`}function ny({evalId:e}){const{state:r}=ft(),{entries:n,loading:s}=id(r.plugin,r.skill,e),o=!!n&&n.length>0;return!s&&!o?null:t.jsx("div",{"data-testid":`run-case-history-${e}`,className:"mt-2 ml-3 pl-3",style:{borderLeft:"1px solid var(--border-subtle)"},children:t.jsx(dd,{evalId:e,sharedEntries:n,sharedLoading:s})})}function sy(e){return e==="baseline"?"Baseline Pass Rate":"Skill Pass Rate"}function oy(e,r){let n="";if(r){const o=new Date(r);isNaN(o.getTime())||(n=o.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}))}return[e,n].filter(Boolean).join(" · ")}function ay(e,r,n){const s=n===1?"test case":"test cases";if(e===0)return`Your skill performs the same as the baseline across ${n} ${s}`;const o=Math.round(Math.abs(e)*r);if(o===0)return`Your skill performs the same as the baseline across ${n} ${s}`;const a=e>0?"more":"fewer";return`Your skill passes ${o} ${a} assertions across ${n} ${s}`}function Ei(e,r){const n=s=>{const o=s/5*100;return isFinite(o)?Math.round(Math.min(100,Math.max(0,o))):0};return{skill:n(e),baseline:n(r)}}function iy(e){return e==="skill"?{text:"Skill wins",isSkill:!0}:e==="baseline"?{text:"Baseline wins",isSkill:!1}:{text:"Tie",isSkill:!1}}function ly(e,r){const n=e+r,s=n*10,o=n*25,a=i=>i>=60?`${Math.round(i/60)}m`:`${i}s`;return`${a(s)}–${a(o)}`}const cy={anthropic:.01,openrouter:.01,ollama:0,"lm-studio":0,"claude-cli":0,"codex-cli":0,"gemini-cli":0};function dy(e,r){if(!e)return null;const n=cy[e];if(n==null||n===0)return null;const s=n*r*.5,o=n*r*2;return`${jt(s)}–${jt(o)}`}function uy(){const{state:e,runCase:r,runAll:n,cancelCase:s,cancelAll:o,canEdit:a,canRun:i}=ft(),{evals:c,caseRunStates:d,bulkRunActive:u,latestBenchmark:p,inlineResults:f}=e,{config:h}=hr(),m=(c==null?void 0:c.evals)??[],g=l.useMemo(()=>{for(const E of d.values())if(E.status==="running"||E.status==="queued")return!0;return!1},[d]),x=m.filter(E=>{const C=d.get(E.id);return C&&(C.status==="complete"||C.status==="error"||C.status==="cancelled")}).length,v=m.filter(E=>{const C=d.get(E.id);return C&&(C.status==="running"||C.status==="queued")}).length,b=l.useRef(null),[y,j]=l.useState(0);l.useEffect(()=>{if(g&&!b.current&&(b.current=Date.now()),!g){b.current=null,j(0);return}const E=setInterval(()=>{b.current&&j(Math.round((Date.now()-b.current)/1e3))},1e3);return()=>clearInterval(E)},[g]);const S=m.reduce((E,C)=>E+C.assertions.length,0),w=m.length+S,R=l.useMemo(()=>ly(m.length,S),[m.length,S]),k=l.useMemo(()=>dy((h==null?void 0:h.provider)??null,w),[h==null?void 0:h.provider,w]);return t.jsxs("div",{className:"p-5",children:[!a&&c!=null&&t.jsxs("div",{role:"status","data-testid":"tests-readonly-banner",className:"flex items-center gap-2 px-3 py-2 rounded-lg mb-4 text-[11px]",style:{background:"var(--surface-2)",color:"var(--text-tertiary)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),t.jsxs("span",{children:["Read-only — to author or modify tests, install this skill as source via"," ",t.jsx("code",{style:{background:"var(--surface-1)",padding:"1px 5px",borderRadius:3,fontFamily:"var(--font-mono)"},children:"vskill plugin new"}),"."]})]}),t.jsxs("div",{className:"rounded-xl p-4 mb-5",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsx("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:"Benchmark"}),g&&t.jsxs("span",{className:"text-[11px] font-medium",style:{color:"var(--accent)"},children:[v," running"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[g&&t.jsxs("button",{onClick:o,className:"btn text-[12px]",style:{background:"var(--red-muted)",color:"var(--red)",border:"1px solid var(--red-muted)"},children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",style:{marginRight:4},children:t.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1"})}),"Cancel All"]}),a&&t.jsx("button",{onClick:()=>n("comparison"),disabled:!i||g,className:"btn btn-primary text-[12px]",title:"Runs both your skill and the baseline, then compares results side by side",children:"Run A/B Test"}),t.jsx("button",{onClick:()=>n("benchmark"),disabled:!i||g,className:a?"btn btn-secondary text-[12px]":"btn btn-primary text-[12px]",title:a?"Runs benchmark using your skill only":"Run all author-shipped eval cases",children:a?"Test Skill":"Run All"}),a&&t.jsx("button",{onClick:()=>n("baseline"),disabled:!i||g,className:"btn btn-secondary text-[12px]",title:"Runs benchmark using the baseline (no skill) for reference",children:"Test Baseline"})]}),!g&&m.length>0&&t.jsxs("div",{className:"flex items-center gap-3 mt-2 text-[10px]",style:{color:"var(--text-tertiary)"},children:[t.jsxs("span",{children:["Est. duration: ",R]}),k&&t.jsxs("span",{children:["Est. cost: ",k]}),!k&&(h==null?void 0:h.provider)&&(h.provider==="claude-cli"||h.provider==="codex-cli")&&t.jsx("span",{children:"Cost: Included"}),!k&&(h==null?void 0:h.provider)&&(h.provider==="ollama"||h.provider==="lm-studio"||h.provider==="gemini-cli")&&t.jsx("span",{children:"Cost: Free"})]})]}),g&&m.length>0&&t.jsxs("div",{className:"mb-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("span",{className:"text-[12px] font-medium",style:{color:"var(--text-secondary)"},children:["Progress: ",x,"/",m.length," cases"]}),t.jsxs("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:[Math.round(x/m.length*100),"%"]})]}),t.jsx("div",{className:"rounded-full overflow-hidden",style:{height:6,background:"var(--surface-3)"},children:t.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${x/m.length*100}%`,background:"var(--accent)"}})}),t.jsxs("div",{className:"flex items-center justify-between mt-1.5",children:[t.jsxs("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)"},children:["Elapsed: ",y>=60?`${Math.floor(y/60)}m ${y%60}s`:`${y}s`]}),t.jsxs("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)"},children:["Est. total: ",R]})]})]}),t.jsx("div",{className:"space-y-3 stagger-children",children:m.map(E=>{const C=f.get(E.id),N=d.get(E.id),I=(N==null?void 0:N.status)??"idle",P=p==null?void 0:p.cases.find(L=>L.eval_id===E.id);return t.jsxs(l.Fragment,{children:[t.jsx(fy,{name:E.name,evalId:E.id,result:C,caseCost:P==null?void 0:P.cost,caseBillingMode:P==null?void 0:P.billingMode,caseInputTokens:P==null?void 0:P.inputTokens,caseOutputTokens:P==null?void 0:P.outputTokens,caseStatus:I,runMode:(N==null?void 0:N.mode)??null,comparisonDetail:P==null?void 0:P.comparisonDetail,canEdit:a,onRun:L=>r(L,"benchmark"),onBaseline:L=>r(L,"baseline"),onCompare:L=>r(L,"comparison"),onCancel:L=>s(L)}),t.jsx(ny,{evalId:E.id})]},E.id)})}),!g&&p&&p.cases.length>0&&t.jsxs("div",{className:"mt-5",children:[t.jsxs("div",{className:"rounded-xl p-4 mb-4",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:sy(p.type)}),t.jsx("span",{className:"text-[20px] font-bold",style:{color:(p.overall_pass_rate??0)>=.8?"var(--green)":(p.overall_pass_rate??0)>=.5?"var(--yellow)":"var(--red)"},children:p.overall_pass_rate!=null?`${Math.round(p.overall_pass_rate*100)}%`:"--"})]}),p.totalDurationMs!=null&&t.jsxs("div",{className:"text-[11px] mt-1",style:{color:"var(--text-tertiary)"},children:["Total: ",(p.totalDurationMs/1e3).toFixed(1),"s",p.model&&` | Model: ${p.model}`,p.totalInputTokens!=null&&p.totalOutputTokens!=null&&` | Tokens: ${pd(p.totalInputTokens,p.totalOutputTokens)}`,p.totalCost!=null&&` | Cost: ${jt(p.totalCost)}`]}),a&&p.overall_pass_rate>=.9999&&!p.comparison&&t.jsx("button",{onClick:()=>n("comparison"),disabled:!i,className:"text-[13px] font-semibold mt-3 w-full rounded-lg transition-opacity duration-150",style:{padding:"10px 0",background:"var(--green)",color:"var(--color-paper)",border:"none",cursor:"pointer",opacity:m.length===0?.5:1},children:"Run Final A/B Comparison"})]}),p.comparison&&t.jsxs("div",{className:"rounded-xl p-4",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:[t.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)"},children:"Skill vs Baseline"}),(()=>{const E=oy(p.model,p.timestamp);return E?t.jsx("div",{className:"text-[10px] mt-0.5 mb-3",style:{color:"var(--text-tertiary)"},children:E}):t.jsx("div",{className:"mb-3"})})(),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsx(Ni,{label:"Skill",value:p.comparison.skillPassRate,color:"var(--accent)"}),t.jsx(Ni,{label:"Baseline",value:p.comparison.baselinePassRate,color:"var(--text-tertiary)"})]}),t.jsxs("div",{className:"mt-3 text-[12px] font-medium",style:{color:p.comparison.delta>0?"var(--green)":p.comparison.delta<0?"var(--red)":"var(--text-tertiary)"},children:["Delta: ",p.comparison.delta>0?"+":"",(p.comparison.delta*100).toFixed(1),"%",p.verdict&&` | ${Nv(p.verdict)}`]}),(()=>{const E=p.cases.reduce((N,I)=>N+I.assertions.length,0),C=ay(p.comparison.delta,E,p.cases.length);return t.jsx("div",{className:"mt-1 text-[11px]",style:{color:"var(--text-tertiary)"},children:C})})()]})]})]})}const py={benchmark:{label:"Skill",bg:"var(--accent-muted)",color:"var(--accent)"},baseline:{label:"Baseline",bg:"var(--surface-3)",color:"var(--text-tertiary)"},comparison:{label:"Compare",bg:"var(--purple-muted)",color:"var(--purple)"}};function fy({name:e,evalId:r,result:n,caseCost:s,caseBillingMode:o,caseInputTokens:a,caseOutputTokens:i,caseStatus:c,runMode:d,comparisonDetail:u,canEdit:p=!1,onRun:f,onBaseline:h,onCompare:m,onCancel:g}){const[x,v]=l.useState(!1),b=c==="running"||c==="queued",y=c==="complete"||c==="error";return t.jsxs("div",{className:"rounded-xl overflow-hidden transition-all duration-200",style:{background:"var(--surface-1)",border:b?"1px solid var(--accent)":"1px solid var(--border-subtle)",boxShadow:b?"0 0 12px rgba(99, 131, 255, 0.15)":"none"},children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[c==="running"&&t.jsx("span",{className:"spinner",style:{width:14,height:14,borderWidth:1.5}}),c==="queued"&&t.jsx("span",{className:"text-[10px] font-medium",style:{color:"var(--text-tertiary)"},children:"queued"}),t.jsxs("span",{className:"text-[13px] font-medium",style:{color:"var(--text-primary)"},children:["#",r," ",e]}),d&&(b||y)&&(()=>{const j=py[d];return j?t.jsx("span",{className:"pill text-[9px] font-semibold",style:{background:j.bg,color:j.color,padding:"1px 6px"},children:j.label}):null})()]}),t.jsxs("div",{className:"flex items-center gap-2",children:[b?t.jsx("button",{onClick:()=>g(r),className:"btn text-[10px] px-2 py-1",style:{background:"var(--red-muted)",color:"var(--red)",border:"1px solid var(--red-muted)"},children:"Cancel"}):t.jsxs(t.Fragment,{children:[p&&t.jsx("button",{onClick:()=>m(r),className:"btn btn-primary text-[10px] px-2 py-1",children:"Compare"}),t.jsx("button",{onClick:()=>f(r),className:p?"btn btn-secondary text-[10px] px-2 py-1":"btn btn-primary text-[10px] px-2 py-1",children:p?"Skill":"Run"}),p&&t.jsx("button",{onClick:()=>h(r),className:"btn btn-secondary text-[10px] px-2 py-1",children:"Base"})]}),n&&n.status!=null&&t.jsx("span",{className:"pill text-[10px]",style:{background:n.status==="pass"?"var(--green-muted)":"var(--red-muted)",color:n.status==="pass"?"var(--green)":"var(--red)"},children:n.passRate!=null?`${Math.round(n.passRate*100)}%`:n.status}),a!=null&&i!=null&&t.jsx("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)",fontFamily:"var(--font-mono, monospace)"},children:pd(a,i)}),s!=null&&t.jsx("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)",fontFamily:"var(--font-mono, monospace)"},children:jt(s,o)}),c==="cancelled"&&t.jsx("span",{className:"pill text-[10px]",style:{background:"var(--surface-3)",color:"var(--text-tertiary)"},children:"cancelled"})]})]}),n&&n.assertions.length>0&&t.jsxs("div",{className:"px-4 pb-3",children:[t.jsx("div",{className:"space-y-1",children:n.assertions.map(j=>t.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[t.jsx("span",{style:{color:j.pass?"var(--green)":"var(--red)"},children:j.pass?"PASS":"FAIL"}),t.jsx("span",{style:{color:"var(--text-secondary)"},children:j.text})]},j.assertion_id))}),n.output&&t.jsx("button",{onClick:()=>v(!x),className:"text-[11px] mt-2 transition-colors duration-150",style:{color:"var(--text-tertiary)"},children:x?"Hide output":"Show output"}),x&&n.output&&t.jsx("pre",{className:"text-[11px] mt-2 p-3 rounded-lg overflow-auto",style:{background:"var(--surface-0)",color:"var(--text-secondary)",border:"1px solid var(--border-subtle)",maxHeight:200,fontFamily:"var(--font-mono, ui-monospace, monospace)",whiteSpace:"pre-wrap"},children:n.output})]}),u&&t.jsx("div",{className:"px-4 pb-3",children:t.jsx("div",{className:"rounded-lg px-3 py-2",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)"},children:t.jsx("div",{className:"flex items-center gap-4 text-[11px] flex-wrap",children:(()=>{const j=Ei(u.skillContentScore,u.baselineContentScore),S=Ei(u.skillStructureScore,u.baselineStructureScore),w=iy(u.winner);return t.jsxs(t.Fragment,{children:[t.jsxs("span",{style:{color:"var(--text-secondary)"},children:["Content: Skill ",j.skill,"% / Baseline ",j.baseline,"%"]}),t.jsx("span",{style:{color:"var(--text-tertiary)"},children:"·"}),t.jsxs("span",{style:{color:"var(--text-secondary)"},children:["Structure: Skill ",S.skill,"% / Baseline ",S.baseline,"%"]}),t.jsx("span",{style:{color:"var(--text-tertiary)"},children:"·"}),t.jsx("span",{style:{color:w.isSkill?"var(--accent)":"var(--text-tertiary)",fontWeight:500},children:w.text})]})})()})})}),n&&n.errorMessage&&t.jsx(hy,{errorMessage:n.errorMessage,classifiedError:n.classifiedError})]})}const Ds={rate_limit:"⏱",context_window:"⚠",auth:"🔒",timeout:"⌛",provider_unavailable:"⚡",parse_error:"❓",unknown:"❌"};function hy({errorMessage:e,classifiedError:r}){const[n,s]=l.useState(!1),o=(r==null?void 0:r.title)??"Error",a=r==null?void 0:r.hint,i=r?Ds[r.category]??Ds.unknown:Ds.unknown;return t.jsx("div",{className:"px-4 pb-3",children:t.jsxs("div",{className:"rounded-lg overflow-hidden",style:{background:"var(--red-muted)",border:"1px solid var(--red-muted)"},children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[t.jsx("span",{style:{fontSize:12},children:i}),t.jsx("span",{className:"text-[11.5px] font-semibold flex-1",style:{color:"var(--red)"},children:o}),t.jsx("button",{onClick:()=>s(!n),className:"text-[10px] px-1.5 py-0.5 rounded transition-colors duration-150",style:{color:"var(--text-tertiary)",background:"transparent"},children:n?"Hide details":"Details"})]}),a&&t.jsx("div",{className:"px-3 pb-2 text-[10.5px]",style:{color:"var(--text-secondary)"},children:a}),n&&t.jsx("pre",{className:"text-[10px] px-3 pb-2.5 overflow-auto",style:{color:"var(--text-tertiary)",maxHeight:120,fontFamily:"var(--font-mono, ui-monospace, monospace)",whiteSpace:"pre-wrap",wordBreak:"break-all",margin:0},children:e})]})})}function Ni({label:e,value:r,color:n}){return t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-secondary)"},children:e}),t.jsxs("span",{className:"text-[12px] font-semibold",style:{color:n},children:[Math.round(r*100),"%"]})]}),t.jsx("div",{className:"rounded-full overflow-hidden",style:{height:6,background:"var(--surface-3)"},children:t.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${r*100}%`,background:n}})})]})}const Ri={TP:{bg:"var(--green-muted)",text:"var(--green)"},TN:{bg:"var(--green-muted)",text:"var(--green)"},FP:{bg:"var(--red-muted)",text:"var(--red)"},FN:{bg:"var(--red-muted)",text:"var(--red)"},SCOPE_WARNING:{bg:"var(--yellow-muted)",text:"var(--yellow)"},DRIFT_WARNING:{bg:"var(--yellow-muted)",text:"var(--yellow)"}},my={scope_warning:"Description claims broader scope than name+tags suggest. Either narrow the description or add explicit '+' prefix to confirm intended scope.",drift_warning:"Description omits intent that classifier inferred from name+tags. Description may need to mention this case explicitly."};function xy(){const{state:e,dispatch:r,runActivationTest:n,cancelActivation:s,generateActivationPrompts:o,loadTestCasesFromSkillMd:a,saveTestCasesToSkillMd:i}=ft(),{plugin:c,skill:d,activationPrompts:u,activationResults:p,activationSummary:f,activationRunning:h,activationError:m,activationStartedAt:g,activationClassifyingStatus:x,generatingPrompts:v,generatingPromptsError:b,activationPromptsSource:y,savingTestCases:j,savingTestCasesError:S,savingTestCasesSuccess:w,activationHistory:R}=e,{state:k}=Mt(),E=k.skills.find(G=>G.plugin===c&&G.skill===d),C=(E==null?void 0:E.resolvedVersion)??(E==null?void 0:E.version)??null,[N,I]=l.useState(u),[P,L]=l.useState(null),[B,T]=l.useState(!1);l.useEffect(()=>{u&&u!==N&&I(u)},[u]),l.useEffect(()=>{r({type:"SET_ACTIVATION_PROMPTS",prompts:N})},[N,r]),l.useEffect(()=>{fetch(`/api/skills/${c}/${d}/description`).then(G=>G.json()).then(G=>L(G.rawContent||G.description||null)).catch(()=>L(null))},[c,d]),l.useEffect(()=>{(!u||u.trim().length===0)&&a()},[c,d]);function $(){n(N)}function M(){o(8)}function F(){i()}const W=N.trim().split(`
55
+ `).filter(Boolean).length,le=G=>G.verdict==="scope_warning"||G.verdict==="drift_warning",U=p.filter(G=>(G.classification==="TP"||G.classification==="TN")&&!le(G)),H=p.filter(G=>(G.classification==="FP"||G.classification==="FN")&&!le(G));p.filter(le);const ee=(P==null?void 0:P.replace(/^---[\s\S]*?---\s*/,"").trim())??null,K=N.trim().length>0,X=ee?bn(ee):"";return t.jsxs("div",{className:"p-5 space-y-5",children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-[14px] font-semibold",style:{color:"var(--text-primary)"},children:"Activation Test"}),t.jsx("div",{className:"text-[12px] mt-0.5",style:{color:"var(--text-tertiary)"},children:"Test whether this skill's description activates for relevant prompts and stays silent for irrelevant ones."})]}),t.jsxs("div",{className:"grid grid-cols-[3fr_2fr] gap-4 items-stretch",children:[t.jsxs("div",{className:"glass-card p-4 flex flex-col gap-3",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("label",{className:"text-[11px] font-semibold uppercase tracking-widest",style:{color:"var(--text-tertiary)"},children:"Test Prompts"}),y==="skill-md"&&t.jsx("span",{className:"pill",style:{background:"var(--green-muted)",color:"var(--green)",fontSize:"9px",padding:"1px 5px"},title:"Loaded from the ## Test Cases block in SKILL.md. Save back any edits to persist them.",children:"from SKILL.md"}),y==="ai-generated"&&t.jsx("span",{className:"pill",style:{background:"var(--purple-muted)",color:"var(--purple)",fontSize:"9px",padding:"1px 5px"},title:"AI-generated. Save as test cases to persist into SKILL.md.",children:"AI-generated"})]}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx("button",{onClick:F,disabled:j||!K||h,className:"text-[10px] px-2.5 py-1 rounded-md transition-colors duration-150 flex items-center gap-1.5",style:{background:j?"var(--surface-3)":"var(--surface-2)",color:K?"var(--green)":"var(--text-tertiary)",border:"1px solid var(--border-subtle)",opacity:K?1:.5,cursor:K?"pointer":"not-allowed"},title:K?"Write the current prompts back to SKILL.md as a ## Test Cases block":"No prompts to save",onMouseEnter:G=>{K&&!j&&(G.currentTarget.style.background="var(--surface-3)")},onMouseLeave:G=>{j||(G.currentTarget.style.background="var(--surface-2)")},children:j?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"spinner",style:{borderTopColor:"var(--green)",borderColor:"var(--border-subtle)",width:10,height:10}}),"Saving..."]}):t.jsxs(t.Fragment,{children:[t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"}),t.jsx("polyline",{points:"17 21 17 13 7 13 7 21"}),t.jsx("polyline",{points:"7 3 7 8 15 8"})]}),"Save as test cases"]})}),t.jsx("button",{onClick:M,disabled:v||!ee||h,className:"text-[10px] px-2.5 py-1 rounded-md transition-colors duration-150 flex items-center gap-1.5",style:{background:v?"var(--surface-3)":"var(--surface-2)",color:ee?"var(--accent)":"var(--text-tertiary)",border:"1px solid var(--border-subtle)",opacity:ee?1:.5,cursor:ee?"pointer":"not-allowed"},title:ee?void 0:"No skill description available",onMouseEnter:G=>{ee&&!v&&(G.currentTarget.style.background="var(--surface-3)")},onMouseLeave:G=>{v||(G.currentTarget.style.background="var(--surface-2)")},children:v?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"spinner",style:{borderTopColor:"var(--accent)",borderColor:"var(--border-subtle)",width:10,height:10}}),"Generating..."]}):t.jsxs(t.Fragment,{children:[t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M12 3v3m6.36.64l-2.12 2.12M21 12h-3m-.64 6.36l-2.12-2.12M12 21v-3m-4.24.64l2.12-2.12M3 12h3m.64-6.36l2.12 2.12"})}),K?"Regenerate":"Generate"," Test Prompts"]})})]})]}),w&&t.jsx("div",{className:"text-[11px] px-2 py-1 rounded",style:{color:"var(--green)",background:"var(--green-muted)"},"aria-live":"polite",children:w}),S&&t.jsxs("div",{className:"text-[11px] px-2 py-1 rounded",style:{color:"var(--red)",background:"var(--red-muted)"},"aria-live":"polite",children:["Save failed: ",S]}),!ee&&!h&&t.jsx("div",{className:"text-[11px] mt-1",style:{color:"var(--text-tertiary)"},"aria-live":"polite",children:"Add a description to your skill's frontmatter to enable prompt generation."}),b&&t.jsx("div",{className:"text-[11px] px-2 py-1 rounded",style:{color:"var(--red)",background:"var(--red-muted)"},children:b}),t.jsx("textarea",{className:"input-field resize-y font-mono text-[12px]",style:{minHeight:140,height:140},value:N,onChange:G=>I(G.target.value),placeholder:`How do I write a unit test?
56
+ What edge cases should I test?
57
+ +Deploy this to production
58
+ !What's the weather like today?
59
+ !Write me a poem about flowers`}),t.jsxs("div",{className:"flex items-center flex-wrap gap-x-3 gap-y-1 text-[11px]",style:{color:"var(--text-tertiary)"},children:[t.jsx("span",{children:"One prompt per line"}),t.jsx(Pn,{}),t.jsx("span",{children:"No prefix = auto-classify"}),t.jsx(Pn,{}),t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("code",{className:"px-1 rounded",style:{background:"var(--surface-2)"},children:"+"}),"= must activate"]}),t.jsx(Pn,{}),t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("code",{className:"px-1 rounded",style:{background:"var(--surface-2)"},children:"!"}),"= must NOT activate"]}),t.jsx(Pn,{}),t.jsxs("span",{style:{fontVariantNumeric:"tabular-nums"},children:[W," prompt",W!==1?"s":""]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:$,disabled:h||!N.trim(),className:"btn btn-primary",children:h?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"spinner",style:{borderTopColor:"var(--color-paper)",borderColor:"var(--border-default)",width:14,height:14}}),"Testing..."]}):t.jsxs(t.Fragment,{children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("circle",{cx:"12",cy:"12",r:"6"}),t.jsx("circle",{cx:"12",cy:"12",r:"2"})]}),"Run Activation Test"]})}),h&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:s,className:"btn btn-secondary text-[12px]",children:"Cancel"}),t.jsxs("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:[x||`${p.length} / ${W} prompts tested`,g&&t.jsx(by,{startedAt:g})]})]})]})]}),t.jsxs("div",{className:"glass-card flex flex-col overflow-hidden",children:[t.jsx("div",{className:"px-4 pt-3.5 pb-2.5 flex-shrink-0",style:{borderBottom:"1px solid var(--border-subtle)"},children:t.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-widest",style:{color:"var(--text-tertiary)"},children:"Skill Description"})}),t.jsx("div",{className:"flex-1 overflow-auto px-4 py-3",style:{minHeight:0},children:ee?t.jsx("div",{className:"text-[12px] leading-relaxed",style:{color:"var(--text-secondary)"},dangerouslySetInnerHTML:{__html:X}}):t.jsx("div",{className:"text-[12px]",style:{color:"var(--text-tertiary)"},children:"No description available"})})]})]}),m&&t.jsx("div",{className:"px-4 py-3 rounded-lg text-[13px]",style:{background:"var(--red-muted)",color:"var(--red)",border:"1px solid var(--red-muted)"},children:m}),h&&p.length===0&&t.jsxs("div",{className:"text-center py-12 animate-fade-in",children:[t.jsx("div",{className:"spinner-lg mx-auto mb-4"}),t.jsx("p",{className:"text-[14px]",style:{color:"var(--text-secondary)"},children:"Testing activation against skill description..."})]}),p.length>0&&t.jsxs("div",{className:"space-y-5",children:[H.length>0&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--red)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),t.jsx("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}),t.jsxs("span",{className:"text-[12px] font-semibold",style:{color:"var(--red)"},children:["Incorrect (",H.length,")"]}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:"— These need attention"})]}),t.jsx("div",{className:"space-y-1.5 stagger-children",children:H.map((G,he)=>t.jsx(Ti,{result:G},`incorrect-${he}`))})]}),U.length>0&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--green)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("polyline",{points:"16 10 11 15 8 12"})]}),t.jsxs("span",{className:"text-[12px] font-semibold",style:{color:"var(--green)"},children:["Correct (",U.length,")"]})]}),t.jsx("div",{className:"space-y-1.5 stagger-children",children:U.map((G,he)=>t.jsx(Ti,{result:G},`correct-${he}`))})]})]}),f&&t.jsxs("div",{className:"glass-card p-6 animate-fade-in-scale",style:{borderColor:"var(--border-active)",borderWidth:2},children:[t.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-widest mb-2",style:{color:"var(--text-tertiary)"},children:"Summary"}),f.autoClassifiedCount!=null&&f.autoClassifiedCount>0&&t.jsxs("div",{className:"text-[11px] mb-3",style:{color:"var(--text-tertiary)"},children:[f.autoClassifiedCount," of ",f.total," prompts auto-classified from skill name and tags"]}),t.jsxs("div",{className:"grid grid-cols-3 gap-6 mb-5",children:[t.jsx(Fs,{label:"Precision",value:f.precision,description:"Of all activations, how many were correct?",detail:`${f.tp} true / ${f.tp+f.fp} total activations`}),t.jsx(Fs,{label:"Recall",value:f.recall,description:"Of expected activations, how many fired?",detail:`${f.tp} activated / ${f.tp+f.fn} expected`}),t.jsx(Fs,{label:"Reliability",value:f.reliability,description:"Overall correct classification rate",detail:`${f.tp+f.tn} correct / ${f.total} total`})]}),t.jsxs("div",{className:"pt-4",style:{borderTop:"1px solid var(--border-subtle)"},children:[t.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-widest mb-3 text-center",style:{color:"var(--text-tertiary)"},children:"Confusion Matrix"}),t.jsxs("div",{className:"grid grid-cols-2 gap-2 max-w-xs mx-auto",children:[t.jsx($n,{label:"True Positive",abbr:"TP",count:f.tp,bg:"var(--green-muted)",color:"var(--green)",description:"Correctly activated"}),t.jsx($n,{label:"False Positive",abbr:"FP",count:f.fp,bg:"var(--red-muted)",color:"var(--red)",description:"Wrongly activated"}),t.jsx($n,{label:"False Negative",abbr:"FN",count:f.fn,bg:"var(--red-muted)",color:"var(--red)",description:"Missed activation"}),t.jsx($n,{label:"True Negative",abbr:"TN",count:f.tn,bg:"var(--green-muted)",color:"var(--green)",description:"Correctly silent"})]}),t.jsxs("div",{className:"mt-3 max-w-xs mx-auto text-center text-[11px]",style:{color:"var(--text-tertiary)"},title:"Auto-classified disagreements: not real failures, but worth reviewing. Hover a yellow row for details.",children:["Warnings:"," ",t.jsxs("span",{style:{color:(f.scopeWarnings??0)>0?"var(--yellow)":"var(--text-tertiary)"},children:[f.scopeWarnings??0," scope"]}),", ",t.jsxs("span",{style:{color:(f.driftWarnings??0)>0?"var(--yellow)":"var(--text-tertiary)"},children:[f.driftWarnings??0," drift"]})]})]})]}),t.jsx(gy,{history:R,expanded:B,onToggle:()=>T(!B),skillVersion:C})]})}function gy({history:e,expanded:r,onToggle:n,skillVersion:s}){return e===null?null:t.jsxs("div",{className:"glass-card overflow-hidden",children:[t.jsxs("button",{className:"w-full px-4 py-3 flex items-center justify-between text-left",style:{borderBottom:r?"1px solid var(--border-subtle)":"none"},onClick:n,children:[t.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-widest",style:{color:"var(--text-tertiary)"},children:["Test History",e.length>0&&t.jsxs("span",{className:"ml-2 font-normal",style:{color:"var(--text-tertiary)"},children:["(",e.length," run",e.length!==1?"s":"",")"]})]}),t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{transform:r?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children:t.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),r&&t.jsx("div",{className:"px-4 py-3",children:e.length===0?t.jsx("div",{className:"text-[12px] py-4 text-center",style:{color:"var(--text-tertiary)"},children:"No test runs yet"}):t.jsx("div",{className:"space-y-2",children:e.map(o=>t.jsx(vy,{run:o,skillVersion:s},o.id))})})]})}function vy({run:e,skillVersion:r}){const n=Math.round(e.summary.reliability*100),s=n>=80?"var(--green)":n>=60?"var(--yellow)":"var(--red)",o=n>=80?"Good":n>=60?"Needs Work":"Poor",a=s;return t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-lg",style:{background:"var(--surface-1)"},children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-secondary)"},children:yy(e.timestamp)}),t.jsx(vn,{version:r??null,size:"sm","data-testid":"activation-row-version"}),t.jsx("span",{className:"pill text-[9px] px-1.5",style:{background:"var(--surface-2)",color:"var(--text-tertiary)"},children:e.model||e.provider}),t.jsxs("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)"},children:[e.promptCount," prompts"]})]})}),t.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[t.jsxs("span",{className:"text-[12px] font-semibold",style:{color:s,fontVariantNumeric:"tabular-nums"},children:[n,"%"]}),t.jsx("span",{className:"text-[10px] font-medium px-2 py-0.5 rounded",style:{color:a,background:`color-mix(in srgb, ${a} 10%, transparent)`},children:o})]})]})}function yy(e){const r=Date.now(),n=new Date(e).getTime(),s=Math.floor((r-n)/1e3);if(s<60)return"just now";const o=Math.floor(s/60);if(o<60)return`${o}m ago`;const a=Math.floor(o/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);return i<7?`${i}d ago`:new Date(e).toLocaleDateString()}function Pn(){return t.jsx("span",{style:{color:"var(--border-subtle)",userSelect:"none"},children:"·"})}function Ti({result:e}){const r=e.verdict==="scope_warning"||e.verdict==="drift_warning",n=r?e.verdict==="scope_warning"?"SCOPE_WARNING":"DRIFT_WARNING":e.classification,s=Ri[n]||Ri.FN,o=!r&&(e.classification==="TP"||e.classification==="TN"),a=e.verdict==="scope_warning"?"scope warn":e.verdict==="drift_warning"?"drift warn":null,i=e.verdict&&e.verdict!=="ok"?my[e.verdict]:void 0;return t.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-xl transition-all duration-200",style:{background:s.bg,border:"1px solid transparent"},children:[t.jsx("div",{className:"flex-shrink-0 mt-0.5",children:t.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{background:`color-mix(in srgb, ${s.text} 20%, transparent)`},children:o?t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:s.text,strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})}):r?t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:s.text,strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),t.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),t.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}):t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:s.text,strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"flex items-center gap-2 mb-1",children:t.jsx("span",{className:"text-[13px] font-medium",style:{color:"var(--text-primary)"},children:e.prompt})}),t.jsxs("div",{className:"flex items-center gap-3 text-[12px]",children:[t.jsx("span",{className:"pill",style:{background:"var(--surface-3)",color:s.text,fontWeight:700,fontSize:"10px",padding:"1px 6px"},title:i,children:a??e.classification}),t.jsx("span",{style:{color:e.activate?"var(--green)":"var(--text-tertiary)"},children:e.activate?"Activated":"Silent"}),t.jsxs("span",{style:{color:"var(--text-tertiary)"},children:["Expected: ",e.expected==="should_activate"?"activate":"stay silent"]}),t.jsxs("span",{style:{color:"var(--text-tertiary)"},children:[e.confidence," confidence"]}),e.autoClassified&&t.jsx("span",{className:"pill",style:{background:"var(--purple-muted)",color:"var(--purple)",fontSize:"9px",padding:"1px 5px"},children:"auto"})]}),e.reasoning&&t.jsx("div",{className:"text-[11px] mt-1.5",style:{color:"var(--text-tertiary)"},children:e.reasoning})]})]})}function Fs({label:e,value:r,description:n,detail:s}){const o=Math.round(r*100),a=o>=80?"var(--green)":o>=60?"var(--yellow)":"var(--red)";return t.jsxs("div",{className:"text-center",children:[t.jsxs("div",{className:"text-[28px] font-bold tracking-tight",style:{color:a},children:[o,"%"]}),t.jsx("div",{className:"text-[12px] font-medium mt-0.5",style:{color:"var(--text-secondary)"},children:e}),t.jsx("div",{className:"text-[10px] mt-1",style:{color:"var(--text-tertiary)"},children:n}),t.jsx("div",{className:"text-[10px] mt-0.5 font-mono",style:{color:"var(--text-tertiary)"},children:s})]})}function $n({abbr:e,count:r,bg:n,color:s,description:o}){return t.jsxs("div",{className:"text-center p-3 rounded-lg",style:{background:n},children:[t.jsx("div",{className:"text-[20px] font-bold",style:{color:s},children:r}),t.jsx("div",{className:"text-[11px] font-semibold",style:{color:s},children:e}),t.jsx("div",{className:"text-[9px] mt-0.5",style:{color:"var(--text-tertiary)"},children:o})]})}function by({startedAt:e}){const[r,n]=l.useState(0);return l.useEffect(()=>{const s=setInterval(()=>n(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(s)},[e]),t.jsxs("span",{className:"ml-2",children:["(",r,"s)"]})}function ky(e){return e==="benchmark"||e==="activation"||e==="ab"}function jy({mode:e}){var c;const{state:r,runAll:n}=ft(),s=l.useRef(!1),a=(((c=r.evals)==null?void 0:c.evals)??[]).length,i=r.evals!=null;return l.useEffect(()=>{if(e!=="benchmark"||typeof window>"u"||s.current)return;const d=new URLSearchParams(window.location.search);if(d.get("autorun")!=="1"||!i||a===0)return;s.current=!0,n("benchmark"),d.delete("autorun");const u=d.toString(),p=`${window.location.pathname}${u?"?"+u:""}${window.location.hash}`;window.history.replaceState(null,"",p)},[e,i,a,n]),e==="activation"?t.jsx(xy,{}):t.jsx(uy,{})}const zs={benchmark:"#6383ff",comparison:"#a78bfa",baseline:"#fb923c"},Ii={benchmark:"Benchmark",comparison:"Comparison",baseline:"Baseline"},Lo=600,Ao=180,lt=40,Bs=Lo-lt*2,Zt=Ao-lt*2,wy=[25,50,75,100];function Li(e){return new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Sy(e){return e==null?"--":`${(e/1e3).toFixed(1)}s`}function Cy({entries:e,onPointClick:r}){const[n,s]=l.useState(null),o=l.useMemo(()=>[...e].reverse(),[e]);if(o.length<2)return null;const a=o.length,i=o.map((u,p)=>{const f=lt+p/(a-1)*Bs,h=u.passRate*100,m=lt+Zt-h/100*Zt;return{x:f,y:m,pct:h,entry:u}}),c=i.map(u=>`${u.x},${u.y}`).join(" "),d=Array.from(new Set(o.map(u=>u.type)));return t.jsxs("div",{className:"glass-card p-5 animate-fade-in",style:{position:"relative",overflowX:a>=20?"auto":void 0},children:[t.jsx("div",{className:"text-[13px] font-semibold mb-2",style:{color:"var(--text-primary)"},children:"Pass Rate Trend"}),t.jsx("div",{className:"flex items-center gap-5 mb-3",children:d.map(u=>t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("div",{className:"w-3 h-3 rounded-full",style:{background:zs[u]??"var(--text-tertiary)"}}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-secondary)"},children:Ii[u]??u})]},u))}),t.jsxs("svg",{width:Lo,height:Ao,viewBox:`0 0 ${Lo} ${Ao}`,style:{display:"block",overflow:"visible"},children:[wy.map(u=>{const p=lt+Zt-u/100*Zt;return t.jsxs("g",{children:[t.jsx("line",{x1:lt,y1:p,x2:lt+Bs,y2:p,stroke:"var(--border-subtle)",strokeWidth:.5,strokeDasharray:"4 4"}),t.jsxs("text",{x:lt-8,y:p+3.5,textAnchor:"end",style:{fill:"var(--text-tertiary)",fontSize:10},children:[u,"%"]})]},u)}),t.jsx("line",{x1:lt,y1:lt+Zt,x2:lt+Bs,y2:lt+Zt,stroke:"var(--border-subtle)",strokeWidth:1}),t.jsx("text",{x:lt-8,y:lt+Zt+3.5,textAnchor:"end",style:{fill:"var(--text-tertiary)",fontSize:10},children:"0%"}),t.jsx("polyline",{points:c,fill:"none",stroke:"var(--border-subtle)",strokeWidth:1.5,strokeLinejoin:"round"}),i.map((u,p)=>t.jsx("circle",{cx:u.x,cy:u.y,r:5,fill:zs[u.entry.type]??"var(--text-tertiary)",stroke:"var(--surface-2)",strokeWidth:2,style:{cursor:"pointer",transition:"r 0.15s ease"},onMouseEnter:f=>{f.currentTarget.setAttribute("r","7"),s({x:u.x,y:u.y,entry:u.entry})},onMouseLeave:f=>{f.currentTarget.setAttribute("r","5"),s(null)},onClick:()=>r==null?void 0:r(u.entry)},p)),Ey(a).map(u=>t.jsx("text",{x:i[u].x,y:lt+Zt+16,textAnchor:"middle",style:{fill:"var(--text-tertiary)",fontSize:10},children:Li(o[u].timestamp)},u))]}),n&&t.jsxs("div",{style:{position:"absolute",left:n.x,top:n.y-12,transform:"translate(-50%, -100%)",background:"var(--surface-3)",border:"1px solid var(--border-subtle)",borderRadius:8,padding:"8px 12px",pointerEvents:"none",zIndex:10,whiteSpace:"nowrap"},children:[t.jsx("div",{className:"text-[11px] font-medium",style:{color:"var(--text-primary)"},children:Li(n.entry.timestamp)}),t.jsx("div",{className:"text-[11px] mt-0.5",style:{color:"var(--text-tertiary)"},children:n.entry.model}),t.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[t.jsx("span",{className:"text-[9px] font-semibold px-1.5 py-0.5 rounded-full",style:{background:zs[n.entry.type]??"var(--text-tertiary)",color:"#fff"},children:Ii[n.entry.type]??n.entry.type}),t.jsxs("span",{className:"text-[12px] font-semibold",style:{color:"var(--text-primary)"},children:[Math.round(n.entry.passRate*100),"%"]})]}),t.jsxs("div",{className:"text-[10px] mt-1.5 flex items-center gap-3",style:{color:"var(--text-tertiary)"},children:[t.jsx("span",{children:Sy(n.entry.totalDurationMs)}),t.jsx("span",{children:n.entry.totalTokens!=null?`${n.entry.totalTokens} tokens`:"--"})]})]})]})}function Ey(e){if(e<=3)return Array.from({length:e},(s,o)=>o);if(e<=6)return[0,Math.floor(e/2),e-1];if(e<20)return[0,Math.floor(e/3),Math.floor(2*e/3),e-1];const r=Math.ceil(e/10),n=[0];for(let s=r;s<e-1;s+=r)n.push(s);return n.push(e-1),n}const Jr=new Map;let ct=null,Gn=null,Mn=1e3,wr=0;function fd(){if(ct)return;ct=new EventSource("/api/events");const e=r=>n=>{let s={};try{s=n.data?JSON.parse(n.data):{}}catch{}const o=Jr.get(r);if(o)for(const a of o)a(s)};ct.addEventListener("benchmark:complete",e("benchmark:complete")),ct.addEventListener("history:written",e("history:written")),ct.addEventListener("leaderboard:updated",e("leaderboard:updated")),ct.onerror=()=>{ct==null||ct.close(),ct=null,wr>0&&(Gn=setTimeout(()=>{Mn=Math.min(Mn*2,3e4),fd()},Mn))},ct.onopen=()=>{Mn=1e3}}function Ny(){Gn!=null&&(clearTimeout(Gn),Gn=null),ct==null||ct.close(),ct=null}function Ry(e,r){return Jr.has(e)||Jr.set(e,new Set),Jr.get(e).add(r),wr++,fd(),()=>{var n;(n=Jr.get(e))==null||n.delete(r),wr--,wr<=0&&(wr=0,queueMicrotask(()=>{wr<=0&&Ny()}))}}function Xn(e,r){const n=l.useRef(r);n.current=r,l.useEffect(()=>Ry(e,o=>n.current(o)),[e])}function Qn(e){return e>=.8?"var(--green)":e>=.5?"var(--yellow)":"var(--red)"}function Ty(e){return e>=1e3?`${(e/1e3).toFixed(1)}s`:`${Math.round(e)}ms`}function Iy({rate:e,label:r}){const n=Math.round(e*100);return t.jsx("div",{className:"flex items-center gap-3",children:t.jsxs("div",{className:"flex-1",children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-[11px] truncate",style:{color:"var(--text-primary)",maxWidth:"70%"},children:r}),t.jsxs("span",{className:"text-[11px] font-semibold",style:{color:Qn(e)},children:[n,"%"]})]}),t.jsx("div",{className:"h-1.5 rounded-full overflow-hidden",style:{background:"var(--surface-3)"},children:t.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${n}%`,background:Qn(e)}})})]})})}function Ly({points:e}){if(e.length<2)return null;const r=200,n=48,s=4,o=e.length,a=e.map((d,u)=>{const p=s+u/(o-1)*(r-s*2),f=s+(n-s*2)-d.passRate*(n-s*2);return{x:p,y:f}}),i=`M ${a[0].x},${n-s} `+a.map(d=>`L ${d.x},${d.y}`).join(" ")+` L ${a[a.length-1].x},${n-s} Z`,c=a.map((d,u)=>`${u===0?"M":"L"} ${d.x},${d.y}`).join(" ");return t.jsxs("svg",{width:r,height:n,style:{display:"block"},children:[t.jsx("path",{d:i,fill:"var(--accent-muted)"}),t.jsx("path",{d:c,fill:"none",stroke:"var(--accent)",strokeWidth:1.5,strokeLinejoin:"round"}),t.jsx("circle",{cx:a[a.length-1].x,cy:a[a.length-1].y,r:3,fill:"var(--accent)"})]})}function Ay({plugin:e,skill:r}){const n=`stats/${e}/${r}`,s=l.useCallback(()=>ie.getStats(e,r),[e,r]),{data:o,loading:a}=wt(n,s),i=l.useCallback(()=>ze(n),[n]);if(Xn("benchmark:complete",i),Xn("history:written",i),a)return t.jsxs("div",{className:"space-y-4",children:[t.jsx("div",{className:"skeleton h-24 rounded-xl"}),t.jsx("div",{className:"skeleton h-48 rounded-xl"}),t.jsx("div",{className:"skeleton h-36 rounded-xl"})]});if(!o||o.totalRuns===0)return t.jsxs("div",{className:"text-center py-12",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center mx-auto mb-3",style:{background:"var(--surface-2)"},children:t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"1.5",children:[t.jsx("path",{d:"M18 20V10"}),t.jsx("path",{d:"M12 20V4"}),t.jsx("path",{d:"M6 20v-6"})]})}),t.jsx("p",{className:"text-[13px]",style:{color:"var(--text-tertiary)"},children:"No benchmark data yet"}),t.jsx("p",{className:"text-[11px] mt-1",style:{color:"var(--text-tertiary)"},children:"Run some benchmarks to see statistics"})]});const c=o.trendPoints.length>0?o.trendPoints[o.trendPoints.length-1].passRate:0,d=o.trendPoints.length>0?o.trendPoints[0].passRate:0,u=c-d,p=o.assertionStats.slice(0,10);return t.jsxs("div",{className:"space-y-4 stagger-children",children:[t.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[t.jsxs("div",{className:"glass-card p-4",children:[t.jsx("div",{className:"text-[10px] uppercase tracking-widest font-semibold mb-1",style:{color:"var(--text-tertiary)"},children:"Total Runs"}),t.jsx("div",{className:"text-[24px] font-bold",style:{color:"var(--text-primary)"},children:o.totalRuns})]}),t.jsxs("div",{className:"glass-card p-4",children:[t.jsx("div",{className:"text-[10px] uppercase tracking-widest font-semibold mb-1",style:{color:"var(--text-tertiary)"},children:"Latest Pass Rate"}),t.jsxs("div",{className:"text-[24px] font-bold",style:{color:Qn(c)},children:[Math.round(c*100),"%"]})]}),t.jsxs("div",{className:"glass-card p-4",children:[t.jsx("div",{className:"text-[10px] uppercase tracking-widest font-semibold mb-1",style:{color:"var(--text-tertiary)"},children:"Trend"}),t.jsxs("div",{className:"text-[24px] font-bold",style:{color:u>=0?"var(--green)":"var(--red)"},children:[u>=0?"+":"",Math.round(u*100),"%"]})]}),t.jsxs("div",{className:"glass-card p-4",children:[t.jsx("div",{className:"text-[10px] uppercase tracking-widest font-semibold mb-1",style:{color:"var(--text-tertiary)"},children:"Models Tested"}),t.jsx("div",{className:"text-[24px] font-bold",style:{color:"var(--text-primary)"},children:o.modelStats.length})]}),o.totalCost!=null&&t.jsxs("div",{className:"glass-card p-4",children:[t.jsx("div",{className:"text-[10px] uppercase tracking-widest font-semibold mb-1",style:{color:"var(--text-tertiary)"},children:"Total Cost"}),t.jsx("div",{className:"text-[20px] font-bold",style:{color:"var(--text-primary)"},children:jt(o.totalCost)})]}),o.costPerRun!=null&&t.jsxs("div",{className:"glass-card p-4",children:[t.jsx("div",{className:"text-[10px] uppercase tracking-widest font-semibold mb-1",style:{color:"var(--text-tertiary)"},children:"Avg Cost/Run"}),t.jsx("div",{className:"text-[20px] font-bold",style:{color:"var(--text-primary)"},children:jt(o.costPerRun)})]})]}),o.trendPoints.length>=2&&t.jsxs("div",{className:"glass-card p-5",children:[t.jsx("div",{className:"text-[13px] font-semibold mb-3",style:{color:"var(--text-primary)"},children:"Pass Rate Over Time"}),t.jsx(Ly,{points:o.trendPoints})]}),o.modelStats.length>0&&t.jsxs("div",{className:"glass-card p-5",children:[t.jsx("div",{className:"text-[13px] font-semibold mb-3",style:{color:"var(--text-primary)"},children:"Model Performance"}),t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("th",{style:{textAlign:"left",padding:"6px 8px",color:"var(--text-tertiary)",fontWeight:600,fontSize:11},children:"Model"}),t.jsx("th",{style:{textAlign:"center",padding:"6px 8px",color:"var(--text-tertiary)",fontWeight:600,fontSize:11},children:"Runs"}),t.jsx("th",{style:{textAlign:"center",padding:"6px 8px",color:"var(--text-tertiary)",fontWeight:600,fontSize:11},children:"Avg Pass Rate"}),t.jsx("th",{style:{textAlign:"center",padding:"6px 8px",color:"var(--text-tertiary)",fontWeight:600,fontSize:11},children:"Avg Duration"}),t.jsx("th",{style:{textAlign:"center",padding:"6px 8px",color:"var(--text-tertiary)",fontWeight:600,fontSize:11},children:"Avg Cost"})]})}),t.jsx("tbody",{children:o.modelStats.map(f=>t.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("td",{style:{padding:"8px",color:"var(--text-primary)",fontWeight:500},children:f.model}),t.jsx("td",{style:{padding:"8px",textAlign:"center",fontFamily:"var(--font-mono, monospace)",color:"var(--text-secondary)"},children:f.runs}),t.jsx("td",{style:{padding:"8px",textAlign:"center"},children:t.jsxs("span",{className:"font-semibold",style:{color:Qn(f.avgPassRate)},children:[Math.round(f.avgPassRate*100),"%"]})}),t.jsx("td",{style:{padding:"8px",textAlign:"center",fontFamily:"var(--font-mono, monospace)",color:"var(--text-secondary)"},children:Ty(f.avgDurationMs)}),t.jsx("td",{style:{padding:"8px",textAlign:"center",fontFamily:"var(--font-mono, monospace)",color:"var(--text-secondary)"},children:f.avgCost!=null?jt(f.avgCost):"N/A"})]},f.model))})]})]}),p.length>0&&t.jsxs("div",{className:"glass-card p-5",children:[t.jsx("div",{className:"text-[13px] font-semibold mb-3",style:{color:"var(--text-primary)"},children:"Weakest Assertions"}),t.jsx("div",{className:"space-y-3",children:p.map(f=>t.jsxs("button",{className:"block w-full text-left rounded-lg p-2 -mx-2 transition-colors duration-150",style:{background:"transparent"},onMouseEnter:h=>{h.currentTarget.style.background="var(--surface-2)"},onMouseLeave:h=>{h.currentTarget.style.background="transparent"},onClick:()=>{},children:[t.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[t.jsxs("span",{className:"text-[10px] font-mono px-1 py-0.5 rounded flex-shrink-0",style:{background:"var(--surface-3)",color:"var(--text-tertiary)"},children:["#",f.evalId]}),t.jsx("span",{className:"text-[10px] truncate",style:{color:"var(--text-tertiary)"},children:f.evalName}),t.jsxs("span",{className:"text-[10px] ml-auto flex-shrink-0",style:{color:"var(--text-tertiary)",fontFamily:"var(--font-mono, monospace)"},children:[f.totalRuns," runs"]})]}),t.jsx(Iy,{rate:f.passRate,label:f.text})]},`${f.evalId}:${f.id}`))})]})]})}function Py({plugin:e,skill:r}){const[n,s]=l.useState(null),[o,a]=l.useState(null),[i,c]=l.useState({}),[d,u]=l.useState({});l.useEffect(()=>{ie.getEvals(e,r).then(s).catch(()=>s(null))},[e,r]);async function p(f){if(o===f){a(null);return}if(a(f),!i[f]){u(h=>({...h,[f]:!0}));try{const h=await ie.getCaseHistory(e,r,f);c(m=>({...m,[f]:h}))}catch{c(h=>({...h,[f]:[]}))}finally{u(h=>({...h,[f]:!1}))}}}return n?t.jsx("div",{className:"space-y-2 stagger-children",children:n.evals.map(f=>{const h=i[f.id]||[],m=o===f.id,g=d[f.id],x=h.length>0?h[0].pass_rate:null;return t.jsxs("div",{className:"glass-card overflow-hidden",children:[t.jsxs("button",{onClick:()=>p(f.id),className:"w-full text-left p-4 flex items-center gap-3 transition-colors duration-150",style:{background:m?"var(--surface-2)":"transparent"},onMouseEnter:v=>{m||(v.currentTarget.style.background="var(--surface-2)")},onMouseLeave:v=>{m||(v.currentTarget.style.background="transparent")},children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2.5",strokeLinecap:"round",style:{transform:m?"rotate(90deg)":"rotate(0)",transition:"transform 0.2s ease",flexShrink:0},children:t.jsx("polyline",{points:"9 18 15 12 9 6"})}),t.jsxs("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded flex-shrink-0",style:{background:"var(--surface-3)",color:"var(--text-tertiary)"},children:["#",f.id]}),t.jsx("span",{className:"text-[13px] font-medium flex-1 truncate",style:{color:"var(--text-primary)"},children:f.name}),h.length>=2&&t.jsx(sd,{entries:h}),x!=null&&t.jsxs("span",{className:"text-[12px] font-semibold flex-shrink-0",style:{color:Ir(x)},children:[Math.round(x*100),"%"]}),h.length>0&&t.jsxs("span",{className:"text-[10px] flex-shrink-0",style:{color:"var(--text-tertiary)",fontFamily:"var(--font-mono, monospace)"},children:[h.length," runs"]})]}),m&&t.jsx("div",{className:"border-t animate-fade-in",style:{borderColor:"var(--border-subtle)"},children:g?t.jsxs("div",{className:"p-4 flex items-center gap-2",children:[t.jsx("div",{className:"spinner",style:{width:14,height:14}}),t.jsx("span",{className:"text-[12px]",style:{color:"var(--text-tertiary)"},children:"Loading history..."})]}):h.length===0?t.jsx("div",{className:"p-4",children:t.jsx("p",{className:"text-[12px]",style:{color:"var(--text-tertiary)"},children:"No history for this eval case"})}):t.jsx("div",{className:"divide-y",style:{borderColor:"var(--border-subtle)"},children:h.map((v,b)=>t.jsxs("div",{className:"p-4",style:{background:b===0?"var(--surface-2)":"transparent"},children:[t.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[t.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--text-primary)"},children:rd(v.timestamp)}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:v.model}),t.jsx("span",{className:"pill",style:{fontSize:9,padding:"1px 6px",background:v.type==="benchmark"?"rgba(99,131,255,0.15)":v.type==="comparison"?"var(--purple-muted)":"rgba(251,146,60,0.15)",color:v.type==="benchmark"?"#6383ff":v.type==="comparison"?"var(--purple)":"#fb923c"},children:v.type}),t.jsxs("span",{className:"text-[12px] font-semibold ml-auto",style:{color:Ir(v.pass_rate)},children:[Math.round(v.pass_rate*100),"%"]})]}),t.jsxs("div",{className:"flex items-center gap-4 mb-2 text-[10px]",style:{fontFamily:"var(--font-mono, monospace)",color:"var(--text-tertiary)"},children:[v.durationMs!=null&&t.jsx("span",{children:nd(v.durationMs)}),v.tokens!=null&&t.jsxs("span",{children:[v.tokens>=1e3?`${(v.tokens/1e3).toFixed(1)}k`:v.tokens," tok"]})]}),t.jsx("div",{className:"space-y-1",children:v.assertions.map(y=>t.jsxs("div",{className:"flex items-start gap-2 py-0.5",children:[t.jsx("div",{className:"w-3.5 h-3.5 rounded-full flex items-center justify-center flex-shrink-0 mt-0.5",style:{background:y.pass?"var(--green)":"var(--red)"},children:t.jsx("svg",{width:"7",height:"7",viewBox:"0 0 24 24",fill:"none",stroke:"#fff",strokeWidth:"3.5",strokeLinecap:"round",strokeLinejoin:"round",children:y.pass?t.jsx("polyline",{points:"20 6 9 17 4 12"}):t.jsxs(t.Fragment,{children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-[11px]",style:{color:"var(--text-primary)"},children:y.text}),y.reasoning&&t.jsx("div",{className:"text-[10px] mt-0.5",style:{color:"var(--text-tertiary)"},children:y.reasoning})]})]},y.id))})]},b))})})]},f.id)})}):t.jsx("div",{className:"text-center py-12",children:t.jsx("p",{className:"text-[13px]",style:{color:"var(--text-tertiary)"},children:"No eval cases found"})})}function $y(){const{state:e,dispatch:r}=ft(),{plugin:n,skill:s}=e,{state:o}=Mt(),a=o.skills.find(F=>F.plugin===n&&F.skill===s),i=(a==null?void 0:a.resolvedVersion)??(a==null?void 0:a.version)??null,[c,d]=l.useState("timeline"),[u,p]=l.useState(""),[f,h]=l.useState(""),[m,g]=l.useState(!1),[x,v]=l.useState([]),[b,y]=l.useState(null),[j,S]=l.useState(!1),[w,R]=l.useState(null),[k,E]=l.useState(!1),C=`history/${n}/${s}?model=${u}&type=${f}`,N=l.useCallback(()=>ie.getHistory(n,s,{model:u||void 0,type:f||void 0}),[n,s,u,f]),{data:I,loading:P}=wt(C,N),L=I??[];l.useEffect(()=>{!I||I.length<2||ie.compareRuns(n,s,I[0].timestamp,I[1].timestamp).then(F=>{const W=F.regressions.filter(le=>le.change==="regression");r({type:"SET_REGRESSIONS",regressions:W})}).catch(()=>{})},[I,n,s,r]);const B=l.useCallback(()=>ze(C),[C]);Xn("history:written",B);const T=l.useCallback(async F=>{if(m){v(W=>W.includes(F)?W.filter(le=>le!==F):W.length>=2?[W[1],F]:[...W,F]);return}E(!0);try{const W=await ie.getHistoryEntry(n,s,F);R(W)}catch{}finally{E(!1)}},[n,s,m]),$=l.useCallback(async()=>{if(x.length===2){S(!0);try{const F=await ie.compareRuns(n,s,x[0],x[1]);y(F)}catch{}finally{S(!1)}}},[n,s,x]),M=[...new Set(L.map(F=>F.model))];return P?t.jsxs("div",{className:"p-5",children:[t.jsx("div",{className:"skeleton h-5 w-32 mb-4"}),t.jsx("div",{className:"skeleton h-48 rounded-xl mb-4"}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("div",{className:"skeleton h-12 rounded-lg"}),t.jsx("div",{className:"skeleton h-12 rounded-lg"})]})]}):t.jsxs("div",{className:"p-5",children:[t.jsx("div",{className:"flex items-center gap-1 mb-4",children:["timeline","per-eval","statistics"].map(F=>t.jsx("button",{onClick:()=>d(F),className:"px-4 py-2 rounded-lg text-[12px] font-medium transition-all duration-150",style:{background:c===F?"var(--accent-muted)":"transparent",color:c===F?"var(--accent)":"var(--text-tertiary)"},children:F==="timeline"?"Timeline":F==="per-eval"?"Per Eval":"Statistics"},F))}),c==="timeline"&&t.jsxs("div",{children:[L.length>0&&t.jsx("div",{className:"mb-5 rounded-xl p-4",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:t.jsx(Cy,{entries:L,onPointClick:F=>T(F.timestamp)})}),t.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[t.jsxs("select",{value:u,onChange:F=>p(F.target.value),className:"input-field text-[12px]",style:{width:150},children:[t.jsx("option",{value:"",children:"All Models"}),M.map(F=>t.jsx("option",{value:F,children:F},F))]}),t.jsxs("select",{value:f,onChange:F=>h(F.target.value),className:"input-field text-[12px]",style:{width:150},children:[t.jsx("option",{value:"",children:"All Types"}),t.jsx("option",{value:"benchmark",children:"Benchmark"}),t.jsx("option",{value:"comparison",children:"Comparison"}),t.jsx("option",{value:"baseline",children:"Baseline"}),t.jsx("option",{value:"model-compare",children:"Model Compare"}),t.jsx("option",{value:"improve",children:"AI Improve"}),t.jsx("option",{value:"instruct",children:"AI Edit"}),t.jsx("option",{value:"ai-generate",children:"AI Generate"}),t.jsx("option",{value:"eval-generate",children:"Eval Generate"})]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{onClick:()=>{g(!m),v([]),y(null)},className:`btn text-[12px] ${m?"btn-primary":"btn-secondary"}`,children:m?"Exit Compare":"Compare Runs"}),m&&x.length===2&&t.jsx("button",{onClick:$,disabled:j,className:"btn btn-primary text-[12px]",children:j?"Comparing...":"Compare"})]}),t.jsx("div",{className:"space-y-2",children:L.length===0?t.jsx("div",{className:"text-center py-8 text-[13px]",style:{color:"var(--text-tertiary)"},children:"No benchmark runs yet"}):L.map(F=>{const W=x.includes(F.timestamp);return t.jsx("button",{onClick:()=>T(F.timestamp),className:"w-full text-left rounded-lg px-4 py-3 transition-all duration-150",style:{background:W?"var(--accent-muted)":"var(--surface-1)",border:W?"1px solid var(--accent)":"1px solid var(--border-subtle)"},onMouseEnter:le=>{W||(le.currentTarget.style.borderColor="var(--border-hover)")},onMouseLeave:le=>{W||(le.currentTarget.style.borderColor="var(--border-subtle)")},children:t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[m&&t.jsx("span",{className:"w-4 h-4 rounded border flex items-center justify-center",style:{borderColor:W?"var(--accent)":"var(--border-default)",background:W?"var(--accent)":"transparent"},children:W&&t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-paper)",strokeWidth:"3",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})})}),t.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--text-primary)"},children:new Date(F.timestamp).toLocaleString()}),t.jsx("span",{className:"pill text-[9px]",style:{background:F.type==="comparison"?"var(--purple-muted)":F.type==="baseline"?"var(--surface-3)":F.type==="model-compare"?"var(--accent-muted)":F.type==="improve"||F.type==="instruct"?"var(--purple-muted)":F.type==="ai-generate"?"var(--green-muted)":F.type==="eval-generate"?"var(--orange-muted)":"var(--accent-muted)",color:F.type==="comparison"?"var(--purple)":F.type==="baseline"?"var(--text-tertiary)":F.type==="model-compare"?"var(--accent)":F.type==="improve"||F.type==="instruct"?"var(--purple)":F.type==="ai-generate"?"var(--green)":F.type==="eval-generate"?"var(--orange)":"var(--accent)"},children:F.type==="model-compare"?"model compare":F.type==="improve"?"ai improve":F.type==="instruct"?"ai edit":F.type==="ai-generate"?"ai generate":F.type==="eval-generate"?"eval generate":F.type})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(vn,{version:i,size:"sm","data-testid":"history-row-version"}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:F.model}),F.totalCost!=null&&F.totalCost>0&&t.jsx("span",{className:"text-[11px] font-mono",style:{color:"var(--text-tertiary)"},children:jt(F.totalCost)}),t.jsxs("span",{className:"text-[12px] font-semibold",style:{color:F.passRate>=.8?"var(--green)":F.passRate>=.5?"var(--yellow)":"var(--red)"},children:[Math.round(F.passRate*100),"%"]})]})]})},F.timestamp)})}),b&&t.jsx(My,{result:b}),w&&!m&&t.jsx(Dy,{run:w,onClose:()=>R(null)})]}),c==="per-eval"&&t.jsx(Py,{plugin:n,skill:s}),c==="statistics"&&t.jsx(Ay,{plugin:n,skill:s})]})}function My({result:e}){const r=e.regressions.filter(s=>s.change==="regression"),n=e.regressions.filter(s=>s.change==="improvement");return t.jsxs("div",{className:"mt-4 rounded-xl p-4",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"text-[13px] font-semibold mb-3",style:{color:"var(--text-primary)"},children:["Comparison: ",new Date(e.runA.timestamp).toLocaleDateString()," vs ",new Date(e.runB.timestamp).toLocaleDateString()]}),(e.runA.totalCost!=null||e.runB.totalCost!=null)&&t.jsxs("div",{className:"flex items-center gap-4 mb-3 text-[11px]",style:{color:"var(--text-secondary)"},children:[t.jsxs("span",{children:["Run A cost: ",jt(e.runA.totalCost??null)]}),t.jsxs("span",{children:["Run B cost: ",jt(e.runB.totalCost??null)]}),e.runA.totalCost!=null&&e.runB.totalCost!=null&&t.jsxs("span",{style:{color:e.runB.totalCost<=e.runA.totalCost?"var(--green)":"var(--red)"},children:["Delta: ",jt(e.runB.totalCost-e.runA.totalCost)]})]}),r.length>0&&t.jsxs("div",{className:"mb-3",children:[t.jsxs("div",{className:"text-[11px] font-semibold uppercase tracking-wider mb-1",style:{color:"var(--red)"},children:["Regressions (",r.length,")"]}),r.map(s=>t.jsxs("div",{className:"text-[12px] py-1",style:{color:"var(--text-secondary)"},children:["#",s.evalId," ",s.evalName,": ",t.jsx("span",{style:{color:"var(--red)"},children:s.assertionId})," (was passing, now failing)"]},`${s.evalId}-${s.assertionId}`))]}),n.length>0&&t.jsxs("div",{className:"mb-3",children:[t.jsxs("div",{className:"text-[11px] font-semibold uppercase tracking-wider mb-1",style:{color:"var(--green)"},children:["Improvements (",n.length,")"]}),n.map(s=>t.jsxs("div",{className:"text-[12px] py-1",style:{color:"var(--text-secondary)"},children:["#",s.evalId," ",s.evalName,": ",t.jsx("span",{style:{color:"var(--green)"},children:s.assertionId})," (was failing, now passing)"]},`${s.evalId}-${s.assertionId}`))]}),t.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider mb-2 mt-3",style:{color:"var(--text-tertiary)"},children:"Case Diffs"}),t.jsx("div",{className:"rounded-lg overflow-hidden",style:{border:"1px solid var(--border-subtle)"},children:t.jsxs("table",{className:"w-full text-[12px]",children:[t.jsx("thead",{children:t.jsxs("tr",{style:{background:"var(--surface-2)"},children:[t.jsx("th",{className:"text-left px-3 py-2 font-medium",style:{color:"var(--text-tertiary)"},children:"Case"}),t.jsx("th",{className:"text-right px-3 py-2 font-medium",style:{color:"var(--text-tertiary)"},children:"Run A"}),t.jsx("th",{className:"text-right px-3 py-2 font-medium",style:{color:"var(--text-tertiary)"},children:"Run B"})]})}),t.jsx("tbody",{children:e.caseDiffs.map(s=>t.jsxs("tr",{style:{borderTop:"1px solid var(--border-subtle)"},children:[t.jsxs("td",{className:"px-3 py-2",style:{color:"var(--text-secondary)"},children:["#",s.eval_id," ",s.eval_name]}),t.jsx("td",{className:"text-right px-3 py-2",style:{color:s.passRateA!=null?s.passRateA>=.8?"var(--green)":s.passRateA>=.5?"var(--yellow)":"var(--red)":"var(--text-tertiary)"},children:s.passRateA!=null?`${Math.round(s.passRateA*100)}%`:s.statusA}),t.jsx("td",{className:"text-right px-3 py-2",style:{color:s.passRateB!=null?s.passRateB>=.8?"var(--green)":s.passRateB>=.5?"var(--yellow)":"var(--red)":"var(--text-tertiary)"},children:s.passRateB!=null?`${Math.round(s.passRateB*100)}%`:s.statusB})]},s.eval_id))})]})})]})}function Dy({run:e,onClose:r}){return(e.type==="improve"||e.type==="instruct")&&e.improve?t.jsx(Fy,{run:e,onClose:r}):t.jsxs("div",{className:"mt-4 rounded-xl p-4",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:["Run: ",new Date(e.timestamp).toLocaleString()]}),t.jsx("button",{onClick:r,className:"btn btn-ghost text-[11px]",children:"Close"})]}),t.jsxs("div",{className:"text-[11px] mb-3",style:{color:"var(--text-tertiary)"},children:["Model: ",e.model," | Cases: ",e.cases.length," | Pass Rate: ",e.overall_pass_rate!=null?`${Math.round(e.overall_pass_rate*100)}%`:"--",e.totalCost!=null&&e.totalCost>0&&` | Cost: ${jt(e.totalCost)}`]}),t.jsx("div",{className:"space-y-2",children:e.cases.map(n=>t.jsx("div",{className:"rounded-lg px-3 py-2",style:{background:"var(--surface-2)"},children:t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("span",{className:"text-[12px]",style:{color:"var(--text-secondary)"},children:["#",n.eval_id," ",n.eval_name]}),t.jsxs("div",{className:"flex items-center gap-2",children:[n.cost!=null&&n.cost>0&&t.jsx("span",{className:"text-[10px] font-mono",style:{color:"var(--text-tertiary)"},children:jt(n.cost)}),t.jsx("span",{className:"text-[11px] font-semibold",style:{color:n.status==="pass"?"var(--green)":"var(--red)"},children:n.pass_rate!=null?`${Math.round(n.pass_rate*100)}%`:n.status})]})]})},n.eval_id))})]})}function Fy({run:e,onClose:r}){var a;const n=l.useMemo(()=>e.improve?ds(e.improve.original,e.improve.improved):[],[e.improve]),s=l.useMemo(()=>{const i=n.filter(d=>d.type==="added").length,c=n.filter(d=>d.type==="removed").length;return{added:i,removed:c}},[n]),o=l.useMemo(()=>{let i=0,c=0;return n.map(d=>d.type==="removed"?(i++,{...d,origNum:i,newNum:null}):d.type==="added"?(c++,{...d,origNum:null,newNum:c}):(i++,c++,{...d,origNum:i,newNum:c}))},[n]);return t.jsxs("div",{className:"mt-4 rounded-xl overflow-hidden animate-fade-in",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5",style:{background:"var(--surface-2)",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"w-8 h-8 rounded-lg flex items-center justify-center",style:{background:"var(--purple-muted)"},children:t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--purple)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),t.jsx("path",{d:"M2 17l10 5 10-5"}),t.jsx("path",{d:"M2 12l10 5 10-5"})]})}),t.jsxs("div",{children:[t.jsx("div",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:"SKILL.md Changes"}),t.jsxs("div",{className:"text-[10px]",style:{color:"var(--text-tertiary)"},children:[new Date(e.timestamp).toLocaleString()," · ",e.model]})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[t.jsxs("span",{style:{color:"var(--green)"},children:["+",s.added]}),t.jsxs("span",{style:{color:"var(--red)"},children:["-",s.removed]})]}),t.jsx("button",{onClick:r,className:"w-7 h-7 rounded-lg flex items-center justify-center transition-colors duration-150",style:{color:"var(--text-tertiary)"},onMouseEnter:i=>{i.currentTarget.style.background="var(--surface-3)"},onMouseLeave:i=>{i.currentTarget.style.background="transparent"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),((a=e.improve)==null?void 0:a.reasoning)&&t.jsxs("div",{className:"mx-4 mt-4 px-4 py-3 rounded-lg text-[12px]",style:{background:"var(--purple-muted)",border:"1px solid var(--purple-muted)",color:"var(--text-secondary)"},children:[t.jsx("span",{className:"font-semibold",style:{color:"var(--purple)"},children:"AI Reasoning: "}),e.improve.reasoning]}),t.jsx("div",{className:"mx-4 my-4 rounded-lg overflow-hidden",style:{border:"1px solid var(--border-subtle)",maxHeight:480,overflowY:"auto"},children:t.jsx("table",{className:"w-full",style:{borderCollapse:"collapse",fontFamily:"var(--font-mono, monospace)"},children:t.jsx("tbody",{children:o.map((i,c)=>t.jsxs("tr",{style:{background:i.type==="added"?"var(--green-muted)":i.type==="removed"?"var(--red-muted)":"transparent"},children:[t.jsx("td",{className:"text-right select-none px-2",style:{width:40,fontSize:10,color:i.type==="removed"?"var(--red)":"var(--text-tertiary)",opacity:i.origNum?.6:.2,borderRight:"1px solid var(--border-subtle)"},children:i.origNum??""}),t.jsx("td",{className:"text-right select-none px-2",style:{width:40,fontSize:10,color:i.type==="added"?"var(--green)":"var(--text-tertiary)",opacity:i.newNum?.6:.2,borderRight:"1px solid var(--border-subtle)"},children:i.newNum??""}),t.jsx("td",{className:"select-none text-center",style:{width:20,fontSize:11,fontWeight:700,color:i.type==="added"?"var(--green)":i.type==="removed"?"var(--red)":"transparent",borderRight:i.type==="added"?"2px solid var(--green)":i.type==="removed"?"2px solid var(--red)":"2px solid transparent"},children:i.type==="added"?"+":i.type==="removed"?"-":" "}),t.jsx("td",{className:"px-3 py-px whitespace-pre-wrap",style:{fontSize:11,lineHeight:1.6,color:i.type==="added"?"var(--green)":i.type==="removed"?"var(--red)":"var(--text-secondary)"},children:i.content||"​"})]},c))})})})]})}function hd({data:e}){if(e.length<2)return t.jsx("span",{style:{color:"var(--text-tertiary)",fontSize:10},children:"--"});const r=e.slice(-10),n=80,s=24,o=2,a=n-o*2,i=s-o*2,c=r.length,d=Math.min(...r),p=Math.max(...r)-d||1,f=r.map((g,x)=>{const v=o+x/(c-1)*a,b=o+i-(g-d)/p*i;return`${v.toFixed(1)},${b.toFixed(1)}`}),h=r[r.length-1],m=Ir(h);return t.jsxs("svg",{width:n,height:s,viewBox:`0 0 ${n} ${s}`,style:{display:"block"},children:[t.jsx("polyline",{points:f.join(" "),fill:"none",stroke:m,strokeWidth:1.5,strokeLinejoin:"round",strokeLinecap:"round"}),(()=>{const[g,x]=f[f.length-1].split(",");return t.jsx("circle",{cx:g,cy:x,r:2.5,fill:m})})()]})}function zy(){return t.jsxs("span",{className:"pill",style:{background:"var(--yellow-muted)",color:"var(--yellow)",fontSize:9,fontWeight:700,gap:3},children:[t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"var(--yellow)",stroke:"none",children:t.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),"Best Model"]})}function By({pct:e}){const r=e>=10?"var(--green)":e>=0?"var(--yellow)":"var(--red)",n=e>=10?"var(--green-muted)":e>=0?"var(--yellow-muted)":"var(--red-muted)",s=e>=0?"+":"";return t.jsxs("span",{className:"pill",style:{background:n,color:r,fontSize:10,fontWeight:600},children:[s,e.toFixed(1),"%"]})}function _y({score:e,rating:r}){const n={excellent:{bg:"var(--green-muted)",fg:"var(--green)"},good:{bg:"var(--green-muted)",fg:"var(--green)"},marginal:{bg:"var(--yellow-muted)",fg:"var(--yellow)"},minimal:{bg:"var(--yellow-muted)",fg:"var(--yellow)"},harmful:{bg:"var(--red-muted)",fg:"var(--red)"}},s=n[r]??n.minimal,o=e>=0?"+":"";return t.jsxs("div",{className:"flex items-center gap-2 mt-3",children:[t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:"Skill Quality:"}),t.jsxs("span",{className:"pill",style:{background:s.bg,color:s.fg,fontSize:11,fontWeight:600},children:[o,e.toFixed(1),"% (",r.toUpperCase(),")"]})]})}function Oy({warning:e}){return t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg mb-3",style:{background:"var(--yellow-muted)",border:"1px solid var(--yellow-muted)"},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--yellow)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),t.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),t.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--yellow)"},children:e})]})}function Wy({active:e,onChange:r,hasBaseline:n}){return t.jsxs("div",{className:"flex gap-1 p-0.5 rounded-lg",style:{background:"var(--surface-2)"},children:[t.jsx("button",{onClick:()=>r("rankings"),className:"px-3 py-1 rounded-md text-[11px] font-medium transition-all",style:{background:e==="rankings"?"var(--surface-3)":"transparent",color:e==="rankings"?"var(--text-primary)":"var(--text-tertiary)"},children:"Rankings"}),t.jsx("button",{onClick:()=>r("amplification"),disabled:!n,className:"px-3 py-1 rounded-md text-[11px] font-medium transition-all",style:{background:e==="amplification"?"var(--surface-3)":"transparent",color:n&&e==="amplification"?"var(--text-primary)":"var(--text-tertiary)",opacity:n?1:.5,cursor:n?"pointer":"not-allowed"},title:n?"View skill amplification data":"Run sweep with --baseline to see amplification data",children:"Skill Amplification"})]})}function Hy(e){var s,o,a;if(e.length===0)return[];const r=new Map;for(const i of e)for(const c of i.models){if(c.status==="error")continue;const d=`${c.provider}/${c.model}`;r.has(d)||r.set(d,{provider:c.provider,passRates:[],lastRubric:null,lastDuration:0,lastCost:null,lastBaselinePassRate:void 0,lastSkillDelta:void 0,lastAmplificationPct:void 0,lastCompositeScore:void 0,hasBaseline:!1});const u=r.get(d);u.passRates.push(c.passRate.mean),u.lastRubric=((s=c.rubricScore)==null?void 0:s.mean)??null,u.lastDuration=c.duration.mean,u.lastCost=((o=c.cost)==null?void 0:o.total)??null,u.lastCompositeScore=c.compositeScore,c.baselinePassRate!=null&&(u.lastBaselinePassRate=c.baselinePassRate.mean,u.lastSkillDelta=(a=c.skillDelta)==null?void 0:a.mean,u.lastAmplificationPct=c.amplificationPct,u.hasBaseline=!0)}const n=[];for(const[i,c]of r){const[d,...u]=i.split("/");n.push({rank:0,model:u.join("/"),provider:d,passRate:c.passRates[c.passRates.length-1],rubricScore:c.lastRubric,duration:c.lastDuration,cost:c.lastCost,sparklineData:c.passRates,isBest:!1,baselinePassRate:c.lastBaselinePassRate,skillDelta:c.lastSkillDelta,amplificationPct:c.lastAmplificationPct,compositeScore:c.lastCompositeScore,hasBaseline:c.hasBaseline})}return n.sort((i,c)=>{const d=i.compositeScore??i.passRate;return(c.compositeScore??c.passRate)-d}),n.forEach((i,c)=>{i.rank=c+1}),n.length>0&&(n[0].isBest=!0),n}const md=(e="left")=>({padding:"10px 12px",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:"var(--text-tertiary)",textAlign:e,whiteSpace:"nowrap"});function Uy({entries:e}){return t.jsx("div",{className:"glass-card",style:{overflow:"hidden"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[t.jsx("thead",{children:t.jsx("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:["#","Model","Pass Rate","Rubric","Duration","Cost","Trend"].map(r=>t.jsx("th",{style:md(r==="#"?"center":"left"),children:r},r))})}),t.jsx("tbody",{children:e.map(r=>t.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},onMouseEnter:n=>{n.currentTarget.style.background="var(--surface-2)"},onMouseLeave:n=>{n.currentTarget.style.background="transparent"},children:[t.jsx("td",{style:{padding:"10px 12px",textAlign:"center",fontSize:12,fontWeight:600,color:"var(--text-tertiary)",width:40},children:r.rank}),t.jsx("td",{style:{padding:"10px 12px"},children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--text-primary)"},children:r.model}),t.jsx("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)"},children:r.provider}),r.isBest&&t.jsx(zy,{})]})}),t.jsx("td",{style:{padding:"10px 12px"},children:t.jsxs("span",{className:"pill",style:{background:r.passRate>=.7?"var(--green-muted)":r.passRate>=.4?"var(--yellow-muted)":"var(--red-muted)",color:Ir(r.passRate),fontSize:11,fontWeight:600},children:[Math.round(r.passRate*100),"%"]})}),t.jsx("td",{style:{padding:"10px 12px",fontSize:12,color:"var(--text-secondary)"},children:r.rubricScore!=null?r.rubricScore.toFixed(1):"--"}),t.jsx("td",{style:{padding:"10px 12px",fontSize:12,color:"var(--text-secondary)"},children:r.duration<1e3?`${Math.round(r.duration)}ms`:`${(r.duration/1e3).toFixed(1)}s`}),t.jsx("td",{style:{padding:"10px 12px",fontSize:12,color:"var(--text-secondary)"},children:r.cost!=null?`$${r.cost.toFixed(4)}`:"N/A"}),t.jsx("td",{style:{padding:"10px 12px"},children:t.jsx(hd,{data:r.sparklineData})})]},`${r.provider}/${r.model}`))})]})})}function Vy({entries:e}){const r=[...e].filter(n=>n.hasBaseline).sort((n,s)=>(s.amplificationPct??0)-(n.amplificationPct??0));return r.length===0?t.jsx("div",{className:"flex items-center justify-center py-8",children:t.jsx("div",{className:"text-center",children:t.jsxs("div",{className:"text-[12px]",style:{color:"var(--text-tertiary)"},children:["No baseline data available. Run sweep with ",t.jsx("code",{children:"--baseline"})," flag."]})})}):t.jsx("div",{className:"glass-card",style:{overflow:"hidden"},children:t.jsxs("table",{style:{width:"100%",borderCollapse:"collapse"},children:[t.jsx("thead",{children:t.jsx("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},children:["#","Model","With Skill","Without Skill","Delta","Amplification","Trend"].map(n=>t.jsx("th",{style:md(n==="#"?"center":"left"),children:n},n))})}),t.jsx("tbody",{children:r.map((n,s)=>t.jsxs("tr",{style:{borderBottom:"1px solid var(--border-subtle)"},onMouseEnter:o=>{o.currentTarget.style.background="var(--surface-2)"},onMouseLeave:o=>{o.currentTarget.style.background="transparent"},children:[t.jsx("td",{style:{padding:"10px 12px",textAlign:"center",fontSize:12,fontWeight:600,color:"var(--text-tertiary)",width:40},children:s+1}),t.jsx("td",{style:{padding:"10px 12px"},children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--text-primary)"},children:n.model}),t.jsx("span",{className:"text-[10px]",style:{color:"var(--text-tertiary)"},children:n.provider})]})}),t.jsx("td",{style:{padding:"10px 12px"},children:t.jsxs("span",{className:"pill",style:{background:n.passRate>=.7?"var(--green-muted)":n.passRate>=.4?"var(--yellow-muted)":"var(--red-muted)",color:Ir(n.passRate),fontSize:11,fontWeight:600},children:[Math.round(n.passRate*100),"%"]})}),t.jsx("td",{style:{padding:"10px 12px"},children:n.baselinePassRate!=null?t.jsxs("span",{className:"text-[11px]",style:{color:"var(--text-secondary)"},children:[Math.round(n.baselinePassRate*100),"%"]}):"--"}),t.jsx("td",{style:{padding:"10px 12px"},children:n.skillDelta!=null?t.jsxs("span",{className:"text-[11px] font-medium",style:{color:n.skillDelta>=0?"var(--green)":"var(--red)"},children:[n.skillDelta>=0?"+":"",(n.skillDelta*100).toFixed(1),"pp"]}):"--"}),t.jsx("td",{style:{padding:"10px 12px"},children:n.amplificationPct!=null&&isFinite(n.amplificationPct)?t.jsx(By,{pct:n.amplificationPct}):"--"}),t.jsx("td",{style:{padding:"10px 12px"},children:t.jsx(hd,{data:n.sparklineData})})]},`${n.provider}/${n.model}`))})]})})}function Gy(){const{state:e}=ft(),{plugin:r,skill:n}=e,[s,o]=l.useState("rankings"),a=`leaderboard/${r}/${n}`,i=l.useCallback(()=>ie.getLeaderboard(r,n),[r,n]),{data:c,loading:d,error:u}=wt(a,i),p=(c==null?void 0:c.entries)??[],f=(u==null?void 0:u.message)??null;l.useEffect(()=>{o("rankings")},[r,n]);const h=l.useCallback(()=>ze(a),[a]);Xn("leaderboard:updated",h);const m=l.useMemo(()=>Hy(p),[p]),g=m.some(b=>b.hasBaseline),x=p[0],v=x==null?void 0:x.judgeBiasWarning;return d?t.jsx("div",{className:"flex items-center justify-center h-full",children:t.jsx("div",{className:"spinner spinner-lg"})}):f?t.jsx("div",{className:"flex items-center justify-center h-full px-8",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"text-[14px] font-medium mb-1",style:{color:"var(--red)"},children:"Failed to load leaderboard"}),t.jsx("div",{className:"text-[12px]",style:{color:"var(--text-tertiary)"},children:f})]})}):m.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 px-8",children:[t.jsx("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center",style:{background:"var(--accent-muted)"},children:t.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M18 20V10"}),t.jsx("path",{d:"M12 20V4"}),t.jsx("path",{d:"M6 20v-6"})]})}),t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"text-[14px] font-medium mb-1",style:{color:"var(--text-primary)"},children:"No sweep results yet"}),t.jsx("div",{className:"text-[12px] mb-3",style:{color:"var(--text-tertiary)"},children:"Run your first model sweep to compare performance across models:"}),t.jsx("div",{className:"text-[11px] font-mono px-4 py-3 rounded-lg text-left",style:{background:"var(--surface-2)",color:"var(--text-secondary)",border:"1px solid var(--border-subtle)"},children:'vskill eval sweep --models "anthropic/claude-sonnet-4,openrouter/meta-llama/llama-3.1-70b" --judge "anthropic/claude-sonnet-4"'}),t.jsxs("div",{className:"text-[11px] mt-2",style:{color:"var(--text-tertiary)"},children:["Add ",t.jsx("code",{children:"--baseline"})," to measure skill amplification per model."]})]})]}):t.jsxs("div",{className:"p-5 animate-fade-in",children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"text-[15px] font-semibold",style:{color:"var(--text-primary)"},children:"Model Leaderboard"}),t.jsx(Wy,{active:s,onChange:o,hasBaseline:g})]}),t.jsxs("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:[p.length," sweep",p.length!==1?"s":""," · ",m.length," model",m.length!==1?"s":""]})]}),v&&t.jsx(Oy,{warning:v}),s==="rankings"?t.jsx(Uy,{entries:m}):t.jsx(Vy,{entries:m}),s==="amplification"&&(x==null?void 0:x.skillQualityScore)!=null&&(x==null?void 0:x.skillQualityRating)&&t.jsx(_y,{score:x.skillQualityScore,rating:x.skillQualityRating})]})}function Ky(e){if(!e)return[];const r=e.split(`
60
+ `),n=[];for(const s of r)if(!(s.startsWith("--- ")||s.startsWith("+++ "))){if(s.startsWith("@@")){n.push({type:"header",content:s});continue}if(s.startsWith("+")){n.push({type:"add",content:s.slice(1)});continue}if(s.startsWith("-")){n.push({type:"remove",content:s.slice(1)});continue}(s.startsWith(" ")||s===""&&n.length>0)&&n.push({type:"context",content:s.startsWith(" ")?s.slice(1):""})}return n}function sa({contentDiff:e,fromLabel:r,toLabel:n,diffSummary:s,maxHeight:o=480,collapsible:a=!1,renderContext:i="inline",onRetry:c}){const[d,u]=l.useState(a),[p,f]=l.useState("unified"),h=l.useRef(null),m=l.useRef(null),g=l.useMemo(()=>Ky(e),[e]),x=l.useMemo(()=>{const w=g.filter(k=>k.type==="add").length,R=g.filter(k=>k.type==="remove").length;return{added:w,removed:R}},[g]),v=l.useMemo(()=>{let w=0,R=0;return g.filter(k=>k.type!=="header").map(k=>k.type==="remove"?(w++,{...k,origNum:w,newNum:null}):k.type==="add"?(R++,{...k,origNum:null,newNum:R}):(w++,R++,{...k,origNum:w,newNum:R}))},[g]),b=l.useMemo(()=>{const w=[],R=[];for(const k of v)if(k.type==="remove")w.push(k);else if(k.type==="add")R.push(k);else{for(;w.length<R.length;)w.push({type:"context",content:"",origNum:null,newNum:null});for(;R.length<w.length;)R.push({type:"context",content:"",origNum:null,newNum:null});w.push(k),R.push(k)}for(;w.length<R.length;)w.push({type:"context",content:"",origNum:null,newNum:null});for(;R.length<w.length;)R.push({type:"context",content:"",origNum:null,newNum:null});return{left:w,right:R}},[v]),y=l.useCallback(w=>{const R=w==="left"?h.current:m.current,k=w==="left"?m.current:h.current;R&&k&&(k.scrollTop=R.scrollTop)},[]);if(!e||g.length===0)return t.jsxs("div",{className:"rounded-lg p-6 text-center",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:[t.jsx("div",{className:"text-[13px] mb-2",style:{color:"var(--text-tertiary)"},children:"Unable to load diff. Try again."}),c&&t.jsx("button",{onClick:c,className:"btn btn-secondary text-[12px]",children:"Retry"})]});const j=i==="modal"?"fixed inset-0 z-50 flex items-center justify-center bg-black/50":"",S=t.jsxs("div",{className:"rounded-xl overflow-hidden animate-fade-in",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3",style:{background:"var(--surface-2)",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:[r," → ",n]}),t.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[t.jsxs("span",{style:{color:"var(--green)"},children:["+",x.added]}),t.jsxs("span",{style:{color:"var(--red)"},children:["-",x.removed]})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:()=>f(p==="unified"?"side-by-side":"unified"),className:"btn btn-ghost text-[11px]",children:p==="unified"?"Side-by-side":"Unified"}),a&&t.jsx("button",{onClick:()=>u(!d),className:"btn btn-ghost text-[11px]",children:d?"Expand":"Collapse"})]})]}),s&&t.jsx("div",{className:"mx-4 mt-3 px-4 py-2 rounded-lg text-[12px]",style:{background:"var(--accent-muted)",color:"var(--text-secondary)"},children:s}),!d&&(p==="unified"?t.jsx("div",{className:"mx-4 my-4 rounded-lg overflow-hidden",style:{border:"1px solid var(--border-subtle)",maxHeight:o,overflowY:"auto"},children:t.jsx("table",{className:"w-full",style:{borderCollapse:"collapse",fontFamily:"var(--font-mono, monospace)"},children:t.jsx("tbody",{children:v.map((w,R)=>t.jsxs("tr",{style:{background:w.type==="add"?"rgba(34,197,94,0.08)":w.type==="remove"?"rgba(239,68,68,0.08)":"transparent"},children:[t.jsx("td",{className:"text-right select-none px-2",style:{width:40,fontSize:10,color:w.type==="remove"?"rgba(239,68,68,0.5)":"var(--text-tertiary)",opacity:w.origNum?.6:.2,borderRight:"1px solid var(--border-subtle)"},children:w.origNum??""}),t.jsx("td",{className:"text-right select-none px-2",style:{width:40,fontSize:10,color:w.type==="add"?"rgba(34,197,94,0.5)":"var(--text-tertiary)",opacity:w.newNum?.6:.2,borderRight:"1px solid var(--border-subtle)"},children:w.newNum??""}),t.jsx("td",{className:"select-none text-center",style:{width:20,fontSize:11,fontWeight:700,color:w.type==="add"?"var(--green)":w.type==="remove"?"var(--red)":"transparent",borderRight:w.type==="add"?"2px solid var(--green)":w.type==="remove"?"2px solid var(--red)":"2px solid transparent"},children:w.type==="add"?"+":w.type==="remove"?"-":" "}),t.jsx("td",{className:"px-3 py-px whitespace-pre-wrap",style:{fontSize:11,lineHeight:1.6,color:w.type==="add"?"var(--green)":w.type==="remove"?"var(--red)":"var(--text-secondary)"},children:w.content||"​"})]},R))})})}):t.jsxs("div",{className:"mx-4 my-4 grid grid-cols-2 gap-0 rounded-lg overflow-hidden",style:{border:"1px solid var(--border-subtle)"},children:[t.jsx("div",{ref:h,style:{maxHeight:o,overflowY:"auto",borderRight:"1px solid var(--border-subtle)"},onScroll:()=>y("left"),children:t.jsx("table",{className:"w-full",style:{borderCollapse:"collapse",fontFamily:"var(--font-mono, monospace)"},children:t.jsx("tbody",{children:b.left.map((w,R)=>t.jsxs("tr",{style:{background:w.type==="remove"?"rgba(239,68,68,0.08)":"transparent"},children:[t.jsx("td",{className:"text-right select-none px-2",style:{width:35,fontSize:10,color:"var(--text-tertiary)",opacity:.6,borderRight:"1px solid var(--border-subtle)"},children:w.origNum??""}),t.jsx("td",{className:"px-3 py-px whitespace-pre-wrap",style:{fontSize:11,lineHeight:1.6,color:w.type==="remove"?"var(--red)":"var(--text-secondary)"},children:w.content||"​"})]},R))})})}),t.jsx("div",{ref:m,style:{maxHeight:o,overflowY:"auto"},onScroll:()=>y("right"),children:t.jsx("table",{className:"w-full",style:{borderCollapse:"collapse",fontFamily:"var(--font-mono, monospace)"},children:t.jsx("tbody",{children:b.right.map((w,R)=>t.jsxs("tr",{style:{background:w.type==="add"?"rgba(34,197,94,0.08)":"transparent"},children:[t.jsx("td",{className:"text-right select-none px-2",style:{width:35,fontSize:10,color:"var(--text-tertiary)",opacity:.6,borderRight:"1px solid var(--border-subtle)"},children:w.newNum??""}),t.jsx("td",{className:"px-3 py-px whitespace-pre-wrap",style:{fontSize:11,lineHeight:1.6,color:w.type==="add"?"var(--green)":"var(--text-secondary)"},children:w.content||"​"})]},R))})})})]}))]});return i==="modal"?t.jsx("div",{className:j,children:t.jsx("div",{style:{width:"80%",maxWidth:900},children:S})}):S}const _s="https://verified-skill.com/submit",qy=/^https:\/\/github\.com\/[^/?#@:]+\/[^/?#@:]+(?:[/?#].*)?$/;function Yy(e){if(!e)return _s;const r=e.trim();return!r||!qy.test(r)?_s:`${_s}?repo=${encodeURIComponent(r)}`}const Jy={sm:{icon:12,fontSize:"0.625rem",gap:"0.25rem",px:"0.375rem",py:"0.125rem",height:"18px",radius:"3px"},md:{icon:14,fontSize:"0.6875rem",gap:"0.3rem",px:"0.5rem",py:"0.15rem",height:"22px",radius:"4px"},lg:{icon:16,fontSize:"0.75rem",gap:"0.375rem",px:"0.625rem",py:"0.2rem",height:"26px",radius:"4px"}};function Xy({size:e}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[t.jsx("path",{d:"M10 1L3 4.5V9.5C3 13.64 5.99 17.52 10 18.5C14.01 17.52 17 13.64 17 9.5V4.5L10 1Z",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"}),t.jsx("path",{d:"M7.5 10.5L9.5 12.5L13 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function Qy({size:e}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[t.jsx("path",{d:"M10 1L11.9 4.1L15.5 3.5L14.2 7L17 9.5L14.2 12L15.5 15.5L11.9 14.9L10 18L8.1 14.9L4.5 15.5L5.8 12L3 9.5L5.8 7L4.5 3.5L8.1 4.1L10 1Z",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1.1",strokeLinejoin:"round"}),t.jsx("path",{d:"M10 6.5L10.9 8.6L13.1 8.8L11.4 10.3L11.9 12.5L10 11.3L8.1 12.5L8.6 10.3L6.9 8.8L9.1 8.6L10 6.5Z",fill:"currentColor",stroke:"currentColor",strokeWidth:"0.4",strokeLinejoin:"round"})]})}const Ai={VERIFIED:{color:"var(--tier-verified)",bg:"var(--tier-verified-bg)",border:"var(--tier-verified-border)"},CERTIFIED:{color:"var(--tier-certified)",bg:"var(--tier-certified-bg)",border:"var(--tier-certified-border)"},TAINTED:{color:"var(--tier-tainted)",bg:"var(--tier-tainted-bg)",border:"var(--tier-tainted-border)"}},Zy={VERIFIED:"Security-Scanned",CERTIFIED:"Trusted Publisher",TAINTED:"Tainted"};function xd(e){return Zy[e]??e}function eb({size:e}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[t.jsx("path",{d:"M10 2L1.5 17.5H18.5L10 2Z",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"}),t.jsx("path",{d:"M10 8V12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),t.jsx("circle",{cx:"10",cy:"14.5",r:"1",fill:"currentColor"})]})}function tb({tier:e,size:r}){return e==="TAINTED"?t.jsx(eb,{size:r}):e==="CERTIFIED"?t.jsx(Qy,{size:r}):t.jsx(Xy,{size:r})}function Lj({tier:e,size:r="md",isTainted:n}){const s=Jy[r],o=n?"TAINTED":e,a=Ai[o]??Ai.VERIFIED;return t.jsxs("span",{"data-testid":"tier-badge","data-tier":o,style:{display:"inline-flex",alignItems:"center",gap:s.gap,padding:`${s.py} ${s.px}`,height:s.height,borderRadius:s.radius,fontFamily:"var(--font-geist-mono)",fontSize:s.fontSize,fontWeight:600,letterSpacing:"0.03em",whiteSpace:"nowrap",color:a.color,backgroundColor:a.bg,border:`1px solid ${a.border}`,lineHeight:1},children:[t.jsx(tb,{tier:o,size:s.icon}),xd(o)]})}const Pi={CERTIFIED:{bg:"var(--yellow-muted)",text:"var(--yellow)"},VERIFIED:{bg:"var(--accent-muted)",text:"var(--accent)"},COMMUNITY:{bg:"var(--surface-3)",text:"var(--text-tertiary)"}};function rb(e,r){return e?e.length>r?e.slice(0,r)+"…":e:""}function nb(e){if(!e)return"";const r=e.trim();if(!r)return"";const n=r.toLowerCase();return n==="0 files"||n==="no files"||n==="no file changes"?"Metadata-only release — no file changes":r}function sb(){const{state:e}=ft(),{plugin:r,skill:n}=e,s=Mt(),{onSkillUpdated:o,updateCount:a}=s,i=l.useMemo(()=>s.state.skills.find(W=>W.plugin===r&&W.skill===n)??null,[s.state.skills,r,n]),c=`versions-envelope/${r}/${n}`,d=l.useCallback(()=>ie.getSkillVersionsEnvelope(r,n),[r,n]),{data:u,loading:p}=wt(c,d),f=(u==null?void 0:u.versions)??[],h=(u==null?void 0:u.provider)??"local",m=(u==null?void 0:u.source)==="none",[g,x]=l.useState(null),[v,b]=l.useState(null),[y,j]=l.useState(null),[S,w]=l.useState(!1),[R,k]=l.useState("idle"),[E,C]=l.useState(null),N=l.useRef(null),I=l.useRef(null),P=l.useMemo(()=>(f==null?void 0:f.find(W=>W.isInstalled))??null,[f]),L=l.useMemo(()=>(f==null?void 0:f[0])??null,[f]),B=P&&L&&P.version!==L.version,T=l.useCallback(W=>{g?!v&&W!==g?b(W):(x(W),b(null),j(null)):(x(W),j(null))},[g,v]),$=l.useCallback(async(W,le)=>{w(!0);try{const U=await ie.getVersionDiff(r,n,W,le);j(U)}catch{j(null)}finally{w(!1)}},[r,n]);l.useEffect(()=>{if(g&&v){const W=f||[],le=W.findIndex(K=>K.version===g),U=W.findIndex(K=>K.version===v),[H,ee]=le>U?[g,v]:[v,g];$(H,ee)}},[g,v,f,$]);const M=l.useCallback(()=>{!P||!L||(x(P.version),b(L.version))},[P,L]),F=l.useCallback(async()=>{k("updating"),C(null);const W=new AbortController;N.current=W;try{const le=await ie.postSkillUpdate(r,n,W.signal);if(le.ok)k("done"),o(r,n);else{const U=`Update failed (HTTP ${le.status}): ${le.body||"no response body"}`;k("error"),C(U)}}catch(le){if(le instanceof DOMException&&le.name==="AbortError")return;const U=le instanceof Error?le.message:"Network error";k("error"),C(U)}finally{N.current===W&&(N.current=null)}},[r,n,o]);if(l.useEffect(()=>()=>{var W;(W=N.current)==null||W.abort(),N.current=null},[]),p)return t.jsxs("div",{className:"p-5",children:[t.jsx("div",{className:"skeleton h-5 w-40 mb-4"}),t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"skeleton h-14 rounded-lg"}),t.jsx("div",{className:"skeleton h-14 rounded-lg"}),t.jsx("div",{className:"skeleton h-14 rounded-lg"})]})]});if(!f||f.length===0){if((i==null?void 0:i.origin)==="source"){const le=Yy((i==null?void 0:i.homepage)??null);return t.jsxs("div",{className:"flex flex-col items-center justify-center h-full py-16 px-8","data-testid":"versions-empty-state-local",children:[t.jsx("div",{className:"text-[14px] font-semibold mb-2",style:{color:"var(--text-primary)"},children:"No published versions yet"}),t.jsx("div",{className:"text-[13px] text-center mb-5 max-w-md",style:{color:"var(--text-tertiary)",lineHeight:1.5},children:"This skill is local-only — the version history shown here is sourced from verified-skill.com. Submit your skill to start tracking versions and share it with others."}),t.jsx("a",{href:le,target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary text-[12px]","data-testid":"versions-empty-state-cta",children:"Submit on verified-skill.com"})]})}return i!=null&&i.version?t.jsxs("div",{className:"p-5",children:[t.jsx("div",{className:"text-[14px] font-semibold mb-4",style:{color:"var(--text-primary)"},children:"Version History"}),t.jsxs("div",{className:"relative",children:[t.jsx("div",{className:"absolute left-3 top-0 bottom-0",style:{width:2,background:"var(--border-subtle)"}}),t.jsxs("div",{"data-testid":"version-row-local",className:"w-full text-left pl-8 pr-4 py-3 relative rounded-lg",style:{background:"transparent",border:"1px solid transparent"},children:[t.jsx("span",{className:"absolute left-1.5 top-4 rounded-full",style:{width:10,height:10,background:"var(--accent)",border:"2px solid var(--accent)"}}),t.jsx("div",{className:"flex items-center justify-between",children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:i.version}),t.jsx(Io,{provider:h}),t.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full",style:{background:"var(--accent-muted)",color:"var(--accent)"},children:"installed"})]})}),t.jsx("div",{className:"text-[11px] mt-1",style:{color:"var(--text-tertiary)"},"data-testid":"versions-no-upstream-message",children:m?"No upstream registry — this skill ships without origin metadata, so update tracking is unavailable.":"Local-only — this skill is not registered on verified-skill.com, so no upstream history is available."})]})]})]}):t.jsx("div",{className:"flex flex-col items-center justify-center h-full py-16","data-testid":"versions-empty-state-installed",children:t.jsx("div",{className:"text-[13px]",style:{color:"var(--text-tertiary)"},children:"No version history available"})})}return t.jsxs("div",{className:"p-5",children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsx("div",{className:"text-[14px] font-semibold",style:{color:"var(--text-primary)"},children:"Version History"}),t.jsxs("div",{className:"flex items-center gap-2",children:[B&&t.jsx("button",{onClick:M,className:"btn btn-secondary text-[11px]",children:"View changes since installed"}),B&&R!=="done"&&(R==="error"?t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-[11px]",style:{color:"var(--red)"},children:E||"Update failed"}),t.jsx("button",{onClick:F,className:"btn btn-secondary text-[11px]",children:"Retry"})]}):t.jsx("button",{onClick:F,disabled:R!=="idle",className:"btn btn-primary text-[11px]",children:R==="idle"?`Update to ${L==null?void 0:L.version}`:R==="updating"?"Starting update...":R==="scanning"?"Scanning...":"Installing..."})),a>1&&t.jsxs("button",{onClick:()=>{window.location.hash="#/updates"},className:"text-[11px] hover:underline",style:{color:"var(--text-tertiary)",background:"transparent",border:"none",cursor:"pointer"},children:["Manage all updates (",a,")"]})]})]}),g&&!v&&t.jsxs("div",{className:"text-[11px] mb-3 px-3 py-2 rounded-lg",style:{background:"var(--accent-muted)",color:"var(--accent)"},children:["Click another version to compare with ",g]}),t.jsxs("div",{className:"relative",children:[t.jsx("div",{className:"absolute left-3 top-0 bottom-0",style:{width:2,background:"var(--border-subtle)"}}),t.jsx("div",{className:"space-y-1",children:f.map(W=>{const le=Pi[W.certTier]||Pi.COMMUNITY,U=W.version===g||W.version===v,H=W.isInstalled;return t.jsxs("button",{onClick:()=>T(W.version),className:"w-full text-left pl-8 pr-4 py-3 relative rounded-lg transition-all duration-150",style:{background:U?"var(--accent-muted)":"transparent",border:U?"1px solid var(--accent)":"1px solid transparent",cursor:"pointer"},onMouseEnter:ee=>{U||(ee.currentTarget.style.background="var(--surface-1)")},onMouseLeave:ee=>{U||(ee.currentTarget.style.background="transparent")},children:[t.jsx("span",{className:"absolute left-1.5 top-4 rounded-full",style:{width:H?10:8,height:H?10:8,background:H?"var(--accent)":"var(--surface-3)",border:H?"2px solid var(--accent)":"2px solid var(--border-default)"}}),t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:W.version}),t.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full",style:{background:le.bg,color:le.text},children:xd(W.certTier)}),t.jsx(Io,{provider:h}),H&&t.jsx("span",{className:"text-[9px] font-medium px-1.5 py-0.5 rounded-full",style:{background:"var(--accent-muted)",color:"var(--accent)"},children:"installed"})]}),t.jsx("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:new Date(W.createdAt).toLocaleDateString()})]}),(()=>{const ee=nb(W.diffSummary);return ee?t.jsx("div",{"data-testid":"version-row-diff-summary",className:"text-[11px] mt-1",style:{color:"var(--text-tertiary)"},children:rb(ee,80)}):null})()]},W.version)})}),t.jsx("div",{ref:I,style:{height:1}})]}),S&&t.jsx("div",{className:"mt-4",children:t.jsx("div",{className:"skeleton h-48 rounded-xl"})}),y&&!S&&t.jsx("div",{className:"mt-4",children:t.jsx(sa,{contentDiff:y.contentDiff,fromLabel:y.from,toLabel:y.to,diffSummary:y.diffSummary,renderContext:"inline",onRetry:()=>g&&v&&$(y.from,y.to)})})]})}function ob(e){return e==="timeline"||e==="models"||e==="versions"}function ab({view:e}){return e==="models"?t.jsx(Gy,{}):e==="versions"?t.jsx(sb,{}):t.jsx($y,{})}function ib(e){const r={prompt:e.prompt,provider:e.provider,model:e.model};return e.targetAgents&&e.targetAgents.length>0&&(r.targetAgents=e.targetAgents),r}function lb(e){var o;const r=e.userName.trim().length>0,n=e.userPlugin.trim().length>0||e.userNewPlugin.trim().length>0,s=e.forceLayout===3;return{applyName:r?null:e.aiName??null,applySuggestedPlugin:!s&&!n&&!!((o=e.aiSuggestedPlugin)!=null&&o.plugin),suggestedPluginValue:s||n?null:e.aiSuggestedPlugin??null}}function Cr(e,r=!0){let n=e.toLowerCase().replace(/[^a-z0-9]+/g,"-");return r&&(n=n.replace(/^-+|-+$/g,"")),n}function cb(e,r,n,s){const a=`.../${e.split("/").slice(-2).join("/")}`;switch(r){case 1:return`${a}/${n}/skills/${s}/SKILL.md`;case 2:return`${a}/plugins/${n}/skills/${s}/SKILL.md`;case 3:return`${a}/skills/${s}/SKILL.md`}}function db({onCreated:e,resolveAiConfigOverride:r,forceLayout:n,flushPendingForSkillName:s}){const[o,a]=l.useState("ai"),[i,c]=l.useState(null),[d,u]=l.useState(!0),{config:p}=hr(),[f,h]=l.useState(""),[m,g]=l.useState(n??3),[x,v]=l.useState(""),[b,y]=l.useState(""),[j,S]=l.useState(""),[w,R]=l.useState(""),[k,E]=l.useState(""),[C,N]=l.useState(""),[I,P]=l.useState("write"),[L,B]=l.useState([]),[T,$]=l.useState(!1),[M,F]=l.useState(null),[W,le]=l.useState(null),[U,H]=l.useState(null),[ee,K]=l.useState("vskill"),[X,G]=l.useState("1.0.0"),[he,A]=l.useState(!0),O=l.useCallback(async()=>{try{const Ce=await ie.detectEngines();H(Ce),K(Ae=>Ae!=="vskill"?Ae:Ce.vskillSkillBuilder?"vskill":Ce.anthropicSkillCreator?"anthropic-skill-creator":"none")}catch{H({vskillSkillBuilder:!1,anthropicSkillCreator:!1,vskillVersion:null,anthropicPath:null})}},[]);l.useEffect(()=>{O()},[O]);const[V,re]=l.useState(""),[ce,ne]=l.useState(!1),[ve,ge]=l.useState(!1),[se,fe]=l.useState(null),[z,q]=l.useState(null),[Z,J]=l.useState([]),ue=l.useRef(null),de=l.useRef(null),we=l.useRef(null),Ie=l.useRef(null),Fe=l.useRef(null),[Ke,Ye]=l.useState(!1),[Q,Re]=l.useState(!1),je=l.useRef(f),$e=l.useRef(x),He=l.useRef(b);l.useEffect(()=>{je.current=f},[f]),l.useEffect(()=>{$e.current=x},[x]),l.useEffect(()=>{He.current=b},[b]),l.useEffect(()=>{ie.getProjectLayout().then(Ce=>{if(c(Ce),n)return;g(Ce.suggestedLayout);const Ae=Ce.detectedLayouts.find(st=>st.layout===Ce.suggestedLayout);Ae!=null&&Ae.existingPlugins.length&&v(Ae.existingPlugins[0])}).catch(()=>{}).finally(()=>u(!1))},[n]),l.useEffect(()=>{var Ce;o==="ai"&&((Ce=ue.current)==null||Ce.focus())},[o]),l.useEffect(()=>()=>{var Ce;(Ce=de.current)==null||Ce.abort()},[]);const nt=l.useMemo(()=>{var Ce;return i?((Ce=i.detectedLayouts.find(Ae=>Ae.layout===m))==null?void 0:Ce.existingPlugins)||[]:[]},[i,m]),St=x==="__new__"?b:x,vr=i?cb(i.root,m,St||"{plugin}",f||"{skill}"):"",Xt=l.useMemo(()=>i?i.detectedLayouts.filter(Ce=>Ce.layout!==4):[],[i]),Ue=l.useMemo(()=>{if(!i)return null;const Ce=i.detectedLayouts.find(gt=>gt.layout===2&&gt.existingPlugins.length>0),Ae=i.detectedLayouts.find(gt=>gt.layout===1&&gt.existingPlugins.length>0),st=Ce||Ae;return st?{layout:st.layout,plugins:st.existingPlugins}:null},[i]),tt=l.useCallback(()=>{if(r)return r();if(!p)return{provider:"claude-cli",model:"sonnet"};const Ce=p.provider||"claude-cli",Ae=p.model||"sonnet";return{provider:Ce,model:Ae}},[p,r]),mt=l.useCallback(()=>{var Ce;(Ce=de.current)==null||Ce.abort(),ne(!1)},[]),Tt=l.useCallback(()=>{fe(null),q(null)},[]),xt=l.useCallback(async()=>{var gt,jn;if(fe(null),q(null),J([]),we.current=null,Ie.current=null,!V.trim()){fe("Describe what your skill should do");return}ne(!0);const Ce=new AbortController;de.current=Ce;const{provider:Ae,model:st}=tt();try{const Dt=await fetch("/api/skills/generate?sse",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ib({prompt:V.trim(),provider:Ae,model:st,targetAgents:L})),signal:Ce.signal});if(!Dt.ok||!Dt.body){let yr=`HTTP ${Dt.status}`;try{const Je=await Dt.json();Je.error&&(yr=Je.error)}catch{}throw new Error(yr)}const ps=Dt.body.getReader(),fs=new TextDecoder;let zr="",It="";for(;;){const{done:yr,value:Je}=await ps.read();if(yr)break;zr+=fs.decode(Je,{stream:!0});const Br=zr.split(`
61
+ `);zr=Br.pop()||"";for(const ir of Br)if(ir.startsWith("event: "))It=ir.slice(7).trim();else if(ir.startsWith("data: ")){try{const De=JSON.parse(ir.slice(6));if(It==="progress")J(lr=>[...lr,{phase:De.phase,message:De.message,timestamp:Date.now()}]);else if(It==="provenance")Ie.current={resolvedModelId:typeof De.resolvedModelId=="string"?De.resolvedModelId:null,snapshotDate:typeof De.snapshotDate=="string"?De.snapshotDate:null};else if(It==="done"||It==="complete"){const lr={prompt:V.trim(),provider:tt().provider,model:tt().model,resolvedModelId:((gt=Ie.current)==null?void 0:gt.resolvedModelId)??null,snapshotDate:((jn=Ie.current)==null?void 0:jn.snapshotDate)??null,reasoning:De.reasoning||""},Vt=lb({userName:je.current,userPlugin:$e.current,userNewPlugin:He.current,aiName:De.name,aiSuggestedPlugin:De.suggestedPlugin&&De.suggestedPlugin.plugin?{plugin:De.suggestedPlugin.plugin,layout:De.suggestedPlugin.layout}:null,forceLayout:n});if(Vt.applyName!==null&&h(Vt.applyName),S(De.description),R(De.model||""),E(De.allowedTools||""),N(De.body),ge(!0),we.current=lr,a("manual"),n===3)g(3),v(""),y("");else if(Vt.applySuggestedPlugin&&Vt.suggestedPluginValue){const it=Vt.suggestedPluginValue;if(((i==null?void 0:i.detectedLayouts.flatMap(Gt=>Gt.existingPlugins))??[]).includes(it.plugin))if(v(it.plugin),it.layout&&(it.layout===1||it.layout===2))g(it.layout);else{const Gt=i==null?void 0:i.detectedLayouts.find(wn=>wn.existingPlugins.includes(it.plugin));Gt&&(Gt.layout===1||Gt.layout===2)&&g(Gt.layout)}else v("__new__"),y(it.plugin)}else!Vt.applySuggestedPlugin&&$e.current.trim().length===0&&He.current.trim().length===0&&m===3&&Ue&&Re(!0);const hs={name:De.name,plugin:St||"",layout:m,description:De.description,model:De.model||void 0,allowedTools:De.allowedTools||void 0,body:De.body,aiMeta:lr};ie.saveDraft(hs).then(it=>{Ye(!0),it!=null&&it.dir&&(Fe.current=it.dir)}).catch(()=>{})}else It==="error"&&(fe(De.message||De.description||"Unknown error"),De.category&&q(De))}catch{}It=""}}}catch(Dt){Dt.name!=="AbortError"&&fe(Dt.message)}finally{ne(!1),de.current=null}},[V,tt,m,Ue,St,i,L,n]),rt=l.useCallback(async()=>{var Ce;if(F(null),le(null),!f.trim()){F("Skill name is required");return}if(!j.trim()){F("Description is required");return}if(m!==3&&!St.trim()){F("Plugin name is required");return}if(!he){F("Version is not valid semver");return}$(!0);try{if(s)try{await s(Cr(f))}catch(st){F(`Could not finalize previous delete of ${Cr(f)}: ${st.message}. Cancel the pending delete and try again.`),$(!1);return}const Ae=await ie.createSkill({name:Cr(f),plugin:St||"",layout:m,description:j,model:w||void 0,allowedTools:k||void 0,body:C,aiMeta:we.current||void 0,draftDir:Fe.current||void 0,version:X.trim()||void 0,engine:ee});Fe.current=null,e(Ae.plugin,Ae.skill)}catch(Ae){if(Ae instanceof qt&&Ae.status===409&&((Ce=Ae.details)==null?void 0:Ce.code)==="skill-already-exists"){const st=typeof Ae.details.plugin=="string"?Ae.details.plugin:"",gt=typeof Ae.details.skill=="string"?Ae.details.skill:Cr(f);le("Skill already existed — opened it."),Fe.current=null,e(st,gt)}else F(Ae.message)}finally{$(!1)}},[f,j,m,St,w,k,C,X,he,ee,e,s]),ht=l.useCallback(()=>{Ue&&(g(Ue.layout),v(Ue.plugins[0]),Re(!1))},[Ue]);return{mode:o,setMode:a,layout:i,layoutLoading:d,selectedLayout:m,setSelectedLayout:g,creatableLayouts:Xt,availablePlugins:nt,pathPreview:vr,plugin:x,setPlugin:v,newPlugin:b,setNewPlugin:y,effectivePlugin:St,name:f,setName:h,description:j,setDescription:S,model:w,setModel:R,allowedTools:k,setAllowedTools:E,body:C,setBody:N,bodyViewMode:I,setBodyViewMode:P,aiPrompt:V,setAiPrompt:re,generating:ce,aiGenerated:ve,aiError:se,aiClassifiedError:z,aiProgress:Z,promptRef:ue,handleGenerate:xt,handleCancelGenerate:mt,clearAiError:Tt,targetAgents:L,setTargetAgents:B,draftSaved:Ke,showPluginRecommendation:Q,setShowPluginRecommendation:Re,pluginLayoutInfo:Ue,applyPluginRecommendation:ht,creating:T,error:M,info:W,handleCreate:rt,engineDetection:U,refreshEngineDetection:O,engine:ee,setEngine:K,version:X,setVersion:G,versionValid:he,setVersionValid:A,standaloneLocked:n===3}}const ub={flushBySkillName:async()=>{}},gd=l.createContext(ub);function pb(){return l.useContext(gd)}function vd(){return t.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function fb(){return t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),t.jsx("polyline",{points:"14 2 14 8 20 8"})]})}function yd({node:e,depth:r=0}){var n;return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center gap-1.5 py-0.5",style:{paddingLeft:`${r*16}px`,color:e.type==="dir"?"var(--text-secondary)":"var(--text-tertiary)",fontSize:12,fontFamily:"var(--font-mono, monospace)"},children:[e.type==="dir"?t.jsx(vd,{}):t.jsx(fb,{}),t.jsxs("span",{children:[e.name,e.type==="dir"?"/":""]})]}),(n=e.children)==null?void 0:n.map(s=>t.jsx(yd,{node:s,depth:r+1},s.name))]})}function hb(e,r,n){const s=[];r&&s.push({name:"evals.json",type:"file"}),s.push({name:"history",type:"dir"});const o=[{name:"SKILL.md",type:"file"},{name:"evals",type:"dir",children:s}];return n&&o.push({name:"draft.json",type:"file"}),{name:e||"{skill}",type:"dir",children:o}}function mb({skillName:e,hasEvals:r,isDraft:n}){const s=hb(e,r,n);return t.jsxs("div",{className:"glass-card p-4",children:[t.jsxs("h3",{className:"text-[13px] font-semibold mb-3 flex items-center gap-2",style:{color:"var(--text-primary)"},children:[t.jsx("div",{className:"w-5 h-5 rounded-md flex items-center justify-center",style:{background:"var(--accent-muted)"},children:t.jsx(vd,{})}),"Skill Structure"]}),t.jsx("div",{className:"rounded-lg px-3 py-2",style:{background:"var(--surface-0)",border:"1px solid var(--border-subtle)"},children:t.jsx(yd,{node:s})})]})}const er={background:"var(--surface-3)",color:"var(--text-primary)",border:"1px solid var(--border-subtle)"};function Os({size:e=14,color:r="currentColor"}){return t.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M12 3l1.912 5.813a2 2 0 001.275 1.275L21 12l-5.813 1.912a2 2 0 00-1.275 1.275L12 21l-1.912-5.813a2 2 0 00-1.275-1.275L3 12l5.813-1.912a2 2 0 001.275-1.275L12 3z"})})}function xb({onCreated:e,onCancel:r}){const{flushBySkillName:n}=pb(),s=db({onCreated:e,flushPendingForSkillName:n});return t.jsxs("div",{className:"px-8 py-6 max-w-4xl animate-fade-in overflow-auto h-full",children:[t.jsxs("div",{className:"mb-5",children:[t.jsx("h2",{className:"text-[20px] font-semibold tracking-tight",style:{color:"var(--text-primary)"},children:"Create a New Skill"}),t.jsx("div",{className:"flex items-center justify-between mt-2",children:t.jsxs("div",{className:"inline-flex rounded-lg p-0.5",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)"},children:[t.jsx("button",{onClick:()=>s.setMode("ai"),className:"px-3 py-1.5 rounded-md text-[12px] font-medium transition-all duration-200",style:{background:s.mode==="ai"?"rgba(168,85,247,0.15)":"transparent",color:s.mode==="ai"?"#a855f7":"var(--text-tertiary)",boxShadow:s.mode==="ai"?"0 1px 3px rgba(168,85,247,0.15)":"none",cursor:"pointer",border:"none"},children:t.jsxs("span",{className:"flex items-center gap-1.5",children:[t.jsx(Os,{size:12}),"AI-Assisted"]})}),t.jsx("button",{onClick:()=>s.setMode("manual"),className:"px-3 py-1.5 rounded-md text-[12px] font-medium transition-all duration-200",style:{background:s.mode==="manual"?"var(--surface-4, var(--surface-3))":"transparent",color:s.mode==="manual"?"var(--text-primary)":"var(--text-tertiary)",boxShadow:s.mode==="manual"?"0 1px 3px rgba(0,0,0,0.1)":"none",cursor:"pointer",border:"none"},children:"Manual"})]})})]}),s.layoutLoading&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"skeleton h-10 w-full rounded-lg"}),t.jsx("div",{className:"skeleton h-10 w-full rounded-lg"})]}),!s.layoutLoading&&s.layout&&s.mode==="ai"&&t.jsxs("div",{className:"space-y-4 animate-fade-in",children:[t.jsxs("div",{className:"glass-card p-4",children:[t.jsxs("h3",{className:"text-[13px] font-semibold mb-3 flex items-center gap-2",style:{color:"var(--text-primary)"},children:[t.jsx("div",{className:"w-5 h-5 rounded-md flex items-center justify-center",style:{background:"rgba(168,85,247,0.15)"},children:t.jsx(Os,{size:11,color:"#a855f7"})}),"Describe Your Skill"]}),t.jsx("textarea",{ref:s.promptRef,value:s.aiPrompt,onChange:o=>s.setAiPrompt(o.target.value),placeholder:`e.g., A skill that helps format SQL queries, optimize them for performance, and explain query execution plans.
62
+
63
+ Include any specific behaviors, constraints, or output formats you want.`,rows:5,disabled:s.generating,className:"w-full px-3 py-2.5 rounded-lg text-[13px] resize-y",style:{...er,minHeight:"120px"},onKeyDown:o=>{o.key==="Enter"&&(o.metaKey||o.ctrlKey)&&(o.preventDefault(),s.handleGenerate())}}),t.jsx("p",{className:"text-[11px] mt-2",style:{color:"var(--text-quaternary, var(--text-tertiary))"},children:"Cmd+Enter to generate"})]}),s.generating&&s.aiProgress.length>0&&t.jsx(kn,{entries:s.aiProgress,isRunning:!0}),s.aiError&&t.jsx("div",{children:s.aiClassifiedError?t.jsx(us,{error:s.aiClassifiedError,onRetry:s.handleGenerate,onDismiss:s.clearAiError}):t.jsxs("div",{children:[t.jsx("div",{className:"px-4 py-3 rounded-lg text-[13px]",style:{background:"var(--red-muted)",color:"var(--red)",border:"1px solid rgba(248,113,113,0.2)"},children:s.aiError}),t.jsx("button",{onClick:s.handleGenerate,className:"mt-2 text-[12px] font-medium",style:{color:"#a855f7",background:"none",border:"none",cursor:"pointer"},children:"Retry"})]})}),t.jsxs("div",{className:"flex items-center gap-3",children:[s.generating?t.jsx("button",{onClick:s.handleCancelGenerate,className:"px-5 py-2.5 rounded-lg text-[13px] font-medium transition-all duration-150 flex items-center gap-2",style:{background:"var(--surface-3)",color:"var(--text-secondary)",border:"none",cursor:"pointer"},children:"Cancel Generation"}):t.jsxs("button",{onClick:s.handleGenerate,disabled:!s.aiPrompt.trim(),className:"px-5 py-2.5 rounded-lg text-[13px] font-medium transition-all duration-150 flex items-center gap-2",style:{background:s.aiPrompt.trim()?"#a855f7":"var(--surface-3)",color:s.aiPrompt.trim()?"#fff":"var(--text-tertiary)",cursor:s.aiPrompt.trim()?"pointer":"not-allowed",border:"none"},children:[t.jsx(Os,{size:14}),"Generate"]}),t.jsx("button",{onClick:r,className:"px-4 py-2.5 rounded-lg text-[13px] font-medium",style:{color:"var(--text-secondary)",background:"none",border:"none",cursor:"pointer"},children:"Cancel"}),!s.generating&&t.jsxs("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:["or fill in the form manually",t.jsx("button",{onClick:()=>s.setMode("manual"),className:"ml-1 font-medium",style:{color:"var(--accent)",background:"none",border:"none",cursor:"pointer"},children:"below"})]})]})]}),!s.layoutLoading&&s.layout&&s.mode==="manual"&&t.jsxs("div",{className:"space-y-4 animate-fade-in",children:[t.jsxs("div",{className:"glass-card p-4",children:[t.jsx("h3",{className:"text-[13px] font-semibold mb-3",style:{color:"var(--text-primary)"},children:"Location"}),s.creatableLayouts.length>1&&t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"text-[11px] font-medium uppercase tracking-wider mb-2 block",style:{color:"var(--text-tertiary)"},children:"Layout"}),t.jsx("div",{className:"flex gap-2",children:s.creatableLayouts.map(o=>t.jsx("button",{onClick:()=>{s.setSelectedLayout(o.layout),s.setPlugin(o.existingPlugins[0]||""),s.setNewPlugin("")},className:"px-3 py-1.5 rounded-lg text-[12px] font-medium transition-all duration-150",style:{background:s.selectedLayout===o.layout?"var(--accent)":"var(--surface-3)",color:s.selectedLayout===o.layout?"#fff":"var(--text-secondary)",border:`1px solid ${s.selectedLayout===o.layout?"var(--accent)":"var(--border-subtle)"}`,cursor:"pointer"},children:o.label},o.layout))})]}),s.selectedLayout!==3&&t.jsxs("div",{className:"mb-3",children:[t.jsx("label",{className:"text-[11px] font-medium uppercase tracking-wider mb-2 block",style:{color:"var(--text-tertiary)"},children:"Plugin"}),t.jsxs("select",{value:s.plugin,onChange:o=>{s.setPlugin(o.target.value),s.setNewPlugin("")},className:"w-full px-3 py-2 rounded-lg text-[13px]",style:er,children:[s.availablePlugins.map(o=>t.jsx("option",{value:o,children:o},o)),t.jsx("option",{value:"__new__",children:"+ New plugin..."})]}),s.plugin==="__new__"&&t.jsx("input",{type:"text",value:s.newPlugin,onChange:o=>s.setNewPlugin(Cr(o.target.value)),placeholder:"my-plugin",className:"w-full mt-2 px-3 py-2 rounded-lg text-[13px]",style:er})]}),t.jsx("div",{className:"px-3 py-2 rounded-lg text-[11px] font-mono",style:{background:"var(--surface-0)",color:"var(--text-tertiary)",border:"1px solid var(--border-subtle)"},children:s.pathPreview})]}),s.showPluginRecommendation&&s.pluginLayoutInfo&&s.selectedLayout===3&&t.jsxs("div",{className:"px-4 py-3 rounded-lg text-[12px] animate-fade-in flex items-center justify-between gap-3",style:{background:"rgba(59,130,246,0.08)",color:"var(--text-secondary)",border:"1px solid rgba(59,130,246,0.2)"},children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),t.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]}),t.jsxs("span",{children:["Plugins detected (",t.jsx("strong",{children:s.pluginLayoutInfo.plugins.slice(0,3).join(", ")}),"). Add this skill to a plugin for better organization."]})]}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[t.jsx("button",{onClick:s.applyPluginRecommendation,className:"px-3 py-1 rounded-md text-[11px] font-medium",style:{background:"#3b82f6",color:"#fff",border:"none",cursor:"pointer"},children:"Use plugin"}),t.jsx("button",{onClick:()=>s.setShowPluginRecommendation(!1),className:"w-5 h-5 rounded flex items-center justify-center",style:{color:"var(--text-tertiary)",background:"none",border:"none",cursor:"pointer"},children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),t.jsxs("div",{className:"glass-card p-4",children:[t.jsx("h3",{className:"text-[13px] font-semibold mb-3",style:{color:"var(--text-primary)"},children:"Skill Details"}),t.jsxs("div",{className:"mb-3",children:[t.jsxs("label",{className:"text-[11px] font-medium uppercase tracking-wider mb-1 block",style:{color:"var(--text-tertiary)"},children:["Name ",t.jsx("span",{style:{color:"var(--red)"},children:"*"})]}),t.jsx("input",{type:"text",value:s.name,onChange:o=>s.setName(Cr(o.target.value,!1)),placeholder:"my-skill",className:"w-full px-3 py-2 rounded-lg text-[13px]",style:er})]}),t.jsxs("div",{className:"mb-3",children:[t.jsxs("label",{className:"text-[11px] font-medium uppercase tracking-wider mb-1 block",style:{color:"var(--text-tertiary)"},children:["Description ",t.jsx("span",{style:{color:"var(--red)"},children:"*"})]}),t.jsx("textarea",{value:s.description,onChange:o=>s.setDescription(o.target.value),placeholder:"Brief description",rows:3,className:"w-full px-3 py-2 rounded-lg text-[13px] resize-y",style:{...er,minHeight:"72px"}})]}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"text-[11px] font-medium uppercase tracking-wider mb-1 block",style:{color:"var(--text-tertiary)"},children:"Model"}),t.jsxs("select",{value:s.model,onChange:o=>s.setModel(o.target.value),className:"w-full px-3 py-2 rounded-lg text-[13px]",style:er,children:[t.jsx("option",{value:"",children:"Any"}),t.jsx("option",{value:"opus",children:"Opus"}),t.jsx("option",{value:"sonnet",children:"Sonnet"}),t.jsx("option",{value:"haiku",children:"Haiku"})]})]}),t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"text-[11px] font-medium uppercase tracking-wider mb-1 block",style:{color:"var(--text-tertiary)"},children:"Allowed Tools"}),t.jsx("input",{type:"text",value:s.allowedTools,onChange:o=>s.setAllowedTools(o.target.value),placeholder:"Read, Write, Edit...",className:"w-full px-3 py-2 rounded-lg text-[13px]",style:er})]})]})]}),t.jsxs("div",{className:"glass-card p-4",children:[t.jsxs("div",{className:"flex items-center justify-between mb-3",children:[t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{background:"var(--accent-muted)"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),t.jsx("polyline",{points:"14 2 14 8 20 8"}),t.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),t.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),t.jsxs("div",{children:[t.jsx("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:"SKILL.md"}),t.jsx("span",{className:"text-[11px] ml-2",style:{color:"var(--text-tertiary)"},children:"Skill Definition"})]})]}),t.jsx("div",{className:"flex items-center",style:{background:"var(--surface-2)",borderRadius:8,padding:2,gap:1},children:["write","preview"].map(o=>t.jsxs("button",{onClick:()=>s.setBodyViewMode(o),className:"flex items-center gap-1 rounded-md transition-all duration-150",style:{padding:"4px 10px",background:s.bodyViewMode===o?"var(--surface-4)":"transparent",color:s.bodyViewMode===o?"var(--text-primary)":"var(--text-tertiary)",fontSize:11,fontWeight:s.bodyViewMode===o?600:400,border:"none",cursor:"pointer"},children:[o==="write"?t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"16 18 22 12 16 6"}),t.jsx("polyline",{points:"8 6 2 12 8 18"})]}):t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),t.jsx("span",{children:o==="write"?"Write":"Preview"})]},o))})]}),s.bodyViewMode==="write"?t.jsx("textarea",{value:s.body,onChange:o=>s.setBody(o.target.value),placeholder:`# /my-skill
64
+
65
+ You are an expert at...
66
+ `,rows:8,className:"w-full px-3 py-2 rounded-lg text-[13px] font-mono resize-y",style:{...er,minHeight:"150px"}}):s.body.trim()?t.jsx("div",{className:"text-[13px] leading-relaxed overflow-x-auto rounded-lg px-4 py-3",style:{background:"var(--surface-0)",color:"var(--text-secondary)",border:"1px solid var(--border-subtle)",minHeight:"150px",maxHeight:"400px",overflowY:"auto"},dangerouslySetInnerHTML:{__html:bn(s.body)}}):t.jsx("div",{className:"text-[13px] leading-relaxed overflow-x-auto rounded-lg px-4 py-3",style:{background:"var(--surface-0)",color:"var(--text-secondary)",border:"1px solid var(--border-subtle)",minHeight:"150px",maxHeight:"400px",overflowY:"auto"},children:t.jsx("span",{style:{color:"var(--text-tertiary)"},children:"Start writing to see preview"})})]}),t.jsx(mb,{skillName:s.name||"{skill}",hasEvals:!1,isDraft:s.draftSaved}),s.error&&t.jsx("div",{className:"px-4 py-3 rounded-lg text-[13px]",style:{background:"var(--red-muted)",color:"var(--red)",border:"1px solid rgba(248,113,113,0.2)"},children:s.error}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:s.handleCreate,disabled:s.creating||!s.name||!s.description,className:"px-5 py-2.5 rounded-lg text-[13px] font-medium transition-all duration-150",style:{background:s.creating||!s.name||!s.description?"var(--surface-3)":"var(--accent)",color:s.creating||!s.name||!s.description?"var(--text-tertiary)":"#fff",cursor:s.creating||!s.name||!s.description?"not-allowed":"pointer",border:"none"},children:s.creating?"Creating...":"Create Skill"}),t.jsx("button",{onClick:r,className:"px-4 py-2.5 rounded-lg text-[13px] font-medium",style:{color:"var(--text-secondary)",background:"none",border:"none",cursor:"pointer"},children:"Cancel"})]})]})]})}function $i(){return t.jsx("div",{className:"w-16 h-16 rounded-2xl flex items-center justify-center",style:{background:"var(--surface-2)"},children:t.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),t.jsx("polyline",{points:"3.27 6.96 12 12.01 20.73 6.96"}),t.jsx("line",{x1:"12",y1:"22.08",x2:"12",y2:"12"})]})})}function Xr({variant:e,message:r,onRetry:n}){const{setMode:s,setSearch:o}=Mt(),[a,i]=l.useState(!1);return e==="no-selection"?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-8 animate-fade-in",children:[t.jsx("div",{className:"mb-5",children:a?t.jsx($i,{}):t.jsx("img",{src:"/images/empty-studio.webp",width:128,height:128,alt:"",onError:()=>i(!0),style:{objectFit:"contain"}})}),t.jsx("p",{className:"text-[14px] font-medium mb-1",style:{color:"var(--text-secondary)"},children:"Select a skill to view details"}),t.jsx("p",{className:"text-[12px]",style:{color:"var(--text-tertiary)"},children:"Choose a skill from the list to edit, test, and evaluate"})]}):e==="no-skills"?t.jsxs("div",{className:"text-center py-12 px-4 animate-fade-in-scale",children:[t.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center mx-auto mb-4",style:{background:"var(--surface-2)"},children:t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"})})}),t.jsx("p",{className:"text-[14px] font-medium",style:{color:"var(--text-secondary)"},children:"No skills found"}),t.jsxs("p",{className:"text-[12px] mt-1 mb-4",style:{color:"var(--text-tertiary)"},children:["Check your ",t.jsx("code",{className:"px-1.5 py-0.5 rounded text-[11px]",style:{background:"var(--surface-2)"},children:"--root"})," directory, or create your first skill"]}),t.jsxs("button",{onClick:()=>s("create"),className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-lg text-[13px] font-medium transition-all duration-150",style:{background:"var(--accent)",color:"#fff",border:"none",cursor:"pointer"},onMouseEnter:c=>{c.currentTarget.style.opacity="0.9"},onMouseLeave:c=>{c.currentTarget.style.opacity="1"},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Create Your First Skill"]})]}):e==="no-project-skills"?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full px-8 animate-fade-in","data-testid":"empty-state-no-project-skills",children:[t.jsx("div",{className:"mb-5",children:a?t.jsx($i,{}):t.jsx("img",{src:"/images/empty-studio.webp",width:128,height:128,alt:"",onError:()=>i(!0),style:{objectFit:"contain"}})}),t.jsx("p",{className:"text-[15px] font-medium mb-1",style:{color:"var(--text-primary)"},children:"No skills installed for this project yet."}),t.jsx("p",{className:"text-[12px] mb-5",style:{color:"var(--text-tertiary)",maxWidth:360,textAlign:"center"},children:"Browse the marketplace to install one, or author a new skill from scratch."}),t.jsxs("div",{className:"flex gap-3",children:[t.jsxs("button",{type:"button","data-testid":"empty-state-browse-marketplaces",onClick:()=>{window.dispatchEvent(new CustomEvent("studio:open-marketplace"))},className:"inline-flex items-center gap-2 px-4 py-2 rounded-lg text-[13px] font-medium transition-all duration-150",style:{background:"var(--accent)",color:"#fff",border:"none",cursor:"pointer"},"aria-label":"Browse marketplaces",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("circle",{cx:"9",cy:"21",r:"1"}),t.jsx("circle",{cx:"20",cy:"21",r:"1"}),t.jsx("path",{d:"M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"})]}),"Browse marketplaces"]}),t.jsxs("button",{type:"button","data-testid":"empty-state-create-skill",onClick:()=>s("create"),className:"inline-flex items-center gap-2 px-4 py-2 rounded-lg text-[13px] font-medium transition-all duration-150",style:{background:"var(--surface-2)",color:"var(--text-primary)",border:"1px solid var(--border-default, var(--border-subtle))",cursor:"pointer"},"aria-label":"Create new skill",children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Create new skill"]})]})]}):e==="error"?t.jsx("div",{className:"flex flex-col items-center justify-center h-full px-8 animate-fade-in",children:t.jsxs("div",{className:"px-5 py-4 rounded-lg text-center max-w-sm",style:{background:"var(--red-muted)",border:"1px solid rgba(248,113,113,0.2)"},children:[t.jsx("p",{className:"text-[13px] mb-3",style:{color:"var(--red)"},children:r||"Failed to load skill data"}),n&&t.jsx("button",{onClick:n,className:"px-4 py-2 rounded-lg text-[12px] font-medium",style:{background:"var(--surface-3)",color:"var(--text-primary)",border:"none",cursor:"pointer"},children:"Retry"})]})}):t.jsxs("div",{className:"px-4 py-8 text-center animate-fade-in",children:[t.jsx("p",{className:"text-[13px] mb-2",style:{color:"var(--text-tertiary)"},children:"No skills match your search"}),t.jsx("button",{onClick:()=>o(""),className:"text-[12px] font-medium",style:{color:"var(--accent)",background:"none",border:"none",cursor:"pointer",textDecoration:"underline"},children:"Clear search"})]})}function gb(e,r){const[n,s]=e.split(".").map(Number),[o,a]=r.split(".").map(Number);return o>n?"major":a>s?"minor":"patch"}const vb={major:{bg:"var(--red-muted)",text:"var(--red)"},minor:{bg:"var(--yellow-muted)",text:"var(--yellow)"},patch:{bg:"var(--green-muted)",text:"var(--green)"}};function bd(){const[e,r]=l.useState([]),[n,s]=l.useState(!0),[o,a]=l.useState(new Set),[i,c]=l.useState(new Map),[d,u]=l.useState(!1),[p,f]=l.useState(new Set),[h,m]=l.useState(new Map),[g,x]=l.useState(null),[v,b]=l.useState(null),[y,j]=l.useState(!1),S=l.useCallback(async()=>{s(!0);try{const I=await ie.getSkillUpdates();r(I.filter(P=>P.updateAvailable))}catch{r([])}finally{s(!1)}},[]);l.useEffect(()=>{S()},[S]);const w=l.useMemo(()=>e.filter(I=>!I.pinned),[e]),R=l.useCallback(I=>{a(P=>{const L=new Set(P);return L.has(I)?L.delete(I):L.add(I),L})},[]),k=l.useCallback(()=>{o.size===w.length?a(new Set):a(new Set(w.map(I=>I.name)))},[o,w]),E=l.useCallback(()=>{const I=[...o];if(!I.length)return;u(!0),c(new Map(I.map(L=>[L,{skill:L,status:"pending"}])));const P=ie.startBatchUpdate(I);P.addEventListener("progress",L=>{try{const B=JSON.parse(L.data);c(T=>new Map(T).set(B.skill,B))}catch{}}),P.addEventListener("done",L=>{P.close(),u(!1);try{const B=JSON.parse(L.data);x(`Updated ${B.updated??0} skills, ${B.failed??0} failed`),setTimeout(()=>x(null),5e3)}catch{}S()}),P.addEventListener("error",()=>{P.close(),u(!1),x("Batch update failed"),setTimeout(()=>x(null),5e3)})},[o,S]),C=l.useCallback(async I=>{const P=I.name.split("/"),L=P.length>=3?P[P.length-2]:P[0],B=P[P.length-1];f(T=>new Set(T).add(I.name)),m(T=>{const $=new Map(T);return $.delete(I.name),$});try{const T=await ie.postSkillUpdate(L,B);if(T.ok)S();else{const $=`Update failed (HTTP ${T.status}): ${T.body}`;m(M=>new Map(M).set(I.name,$)),x(`Couldn't update ${B} — HTTP ${T.status}`),setTimeout(()=>x(null),5e3)}}catch(T){const $=T instanceof Error?T.message:"Network error";m(M=>new Map(M).set(I.name,$)),x(`Couldn't update ${B} — ${$}`),setTimeout(()=>x(null),5e3)}finally{f(T=>{const $=new Set(T);return $.delete(I.name),$})}},[S]),N=l.useCallback(async I=>{if(!I.latest)return;const P=I.name.split("/"),L=P.length>=3?P[P.length-2]:P[0],B=P[P.length-1];j(!0);try{const T=await ie.getVersionDiff(L,B,I.installed,I.latest);b({skill:I,diff:T})}catch{b(null)}finally{j(!1)}},[]);return n?t.jsxs("div",{"data-testid":"updates-panel",className:"p-6",children:[t.jsx("div",{className:"skeleton h-6 w-48 mb-4"}),t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"skeleton h-16 rounded-lg"}),t.jsx("div",{className:"skeleton h-16 rounded-lg"})]})]}):e.length===0?t.jsxs("div",{"data-testid":"updates-panel",className:"flex flex-col items-center justify-center h-full py-16",children:[t.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"var(--green)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"mb-4",children:[t.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),t.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),t.jsx("div",{className:"text-[15px] font-semibold mb-2",style:{color:"var(--text-primary)"},children:"All skills are up to date"}),t.jsx("div",{className:"text-[12px] mb-4",style:{color:"var(--text-tertiary)"},children:"No updates available for installed skills."}),t.jsx("button",{onClick:S,className:"btn btn-secondary text-[12px]",children:"Refresh"})]}):t.jsxs("div",{"data-testid":"updates-panel",className:"p-6",children:[g&&t.jsx("div",{className:"fixed top-4 right-4 z-50 px-4 py-3 rounded-lg text-[13px] font-medium animate-fade-in",style:{background:"var(--surface-3)",color:"var(--text-primary)",border:"1px solid var(--border-subtle)"},children:g}),t.jsxs("div",{className:"flex items-center justify-between mb-5",children:[t.jsxs("div",{className:"text-[16px] font-semibold",style:{color:"var(--text-primary)"},children:["Available Updates (",w.length,")"]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:S,className:"btn btn-ghost text-[12px]",disabled:d,children:"Refresh"}),t.jsx("button",{onClick:E,disabled:o.size===0||d,className:"btn btn-primary text-[12px]",children:d?"Updating...":`Update Selected (${o.size})`})]})]}),t.jsx("div",{className:"flex items-center gap-2 mb-3",children:t.jsxs("button",{onClick:k,className:"flex items-center gap-2 text-[12px] font-medium",style:{color:"var(--text-secondary)",background:"transparent",border:"none",cursor:"pointer"},children:[t.jsx("span",{className:"w-4 h-4 rounded border flex items-center justify-center",style:{borderColor:o.size===w.length&&w.length>0?"var(--accent)":"var(--border-default)",background:o.size===w.length&&w.length>0?"var(--accent)":"transparent"},children:o.size===w.length&&w.length>0&&t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-paper)",strokeWidth:"3",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})})}),"Select All"]})}),t.jsx("div",{className:"space-y-2",children:e.map(I=>{const P=I.name.split("/").pop()||I.name,L=I.latest?gb(I.installed,I.latest):"patch",B=vb[L],T=!!I.pinned,$=p.has(I.name),M=i.get(I.name),F=o.has(I.name);return t.jsx("div",{className:"rounded-lg px-4 py-3 transition-all duration-150",style:{background:"var(--surface-1)",border:"1px solid var(--border-subtle)",opacity:T?.7:1},children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("button",{onClick:()=>!T&&R(I.name),disabled:T,className:"flex-shrink-0",style:{background:"transparent",border:"none",cursor:T?"not-allowed":"pointer"},children:t.jsx("span",{className:"w-4 h-4 rounded border flex items-center justify-center",style:{borderColor:F?"var(--accent)":"var(--border-default)",background:F?"var(--accent)":"transparent",opacity:T?.4:1},children:F&&t.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"var(--color-paper)",strokeWidth:"3",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})})})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[t.jsx("span",{className:"text-[13px] font-medium",style:{color:"var(--text-primary)"},children:P}),T&&t.jsx("span",{className:"text-[10px]",title:"Pinned — unpin from CLI to update",children:"📌"}),t.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{background:B.bg,color:B.text},children:L})]}),t.jsxs("div",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:[I.installed," → ",I.latest||"?",T&&` (pinned at ${I.pinnedVersion||I.installed})`]})]}),M&&t.jsxs("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded-full",style:{background:M.status==="done"?"var(--green-muted)":M.status==="error"?"var(--red-muted)":"var(--yellow-muted)",color:M.status==="done"?"var(--green)":M.status==="error"?"var(--red)":"var(--yellow)"},children:[M.status,M.error&&`: ${M.error}`]}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[t.jsx("button",{onClick:()=>N(I),className:"btn btn-ghost text-[11px]",disabled:y,children:"View Changes"}),t.jsx("button",{onClick:()=>C(I),disabled:T||$||d,title:T?"Pinned — unpin from CLI to update":"",className:`btn ${T?"btn-ghost":"btn-primary"} text-[11px]`,children:$?t.jsxs("span",{className:"flex items-center gap-1",children:[t.jsx("span",{className:"spinner spinner-sm"})," Updating"]}):(M==null?void 0:M.status)==="done"?t.jsx("span",{style:{color:"var(--green)"},children:"✓"}):"Update"})]})]})},I.name)})}),v&&t.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)"},onClick:()=>b(null),children:t.jsxs("div",{style:{width:"80%",maxWidth:900},onClick:I=>I.stopPropagation(),children:[t.jsx("div",{className:"mb-2 flex justify-end",children:t.jsx("button",{onClick:()=>b(null),className:"btn btn-ghost text-[12px]",children:"Close"})}),t.jsx(sa,{contentDiff:v.diff.contentDiff,fromLabel:v.diff.from,toLabel:v.diff.to,diffSummary:v.diff.diffSummary,renderContext:"inline"})]})})]})}const yb=Object.freeze(Object.defineProperty({__proto__:null,UpdatesPanel:bd},Symbol.toStringTag,{value:"Module"}));function bb(e){return e==null?"var(--text-tertiary)":e>=.7?"var(--green)":e>=.4?"var(--yellow)":"var(--red)"}function kb(e){return e==null?"var(--surface-3)":e>=.7?"var(--green-muted)":e>=.4?"var(--yellow-muted)":"var(--red-muted)"}function jb(e){if(!e||typeof e!="string")return null;const r=e.trim();if(!r)return null;if(!r.includes("://")){const[n]=r.split("/");return n&&/^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/.test(n)?n:null}try{const n=new URL(r),s=n.hostname.toLowerCase();if(s!=="github.com"&&s!=="www.github.com"&&s!=="raw.githubusercontent.com")return null;const a=n.pathname.split("/").filter(Boolean)[0];return!a||!/^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/.test(a)?null:a}catch{return null}}function kd(e){const{author:r,repoUrl:n}=e,s=jb(n??null),o=r&&r.trim()!==""?r:s??"—",[a,i]=l.useState(!1),c=l.useCallback(async()=>{var d;try{await((d=navigator.clipboard)==null?void 0:d.writeText(o)),i(!0),setTimeout(()=>i(!1),1500)}catch{}},[o]);return s?t.jsx("a",{"data-testid":e["data-testid"]??"author-link",href:`https://github.com/${s}`,target:"_blank",rel:"noopener noreferrer",style:{fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-accent, var(--text-primary))",textDecoration:"none",borderBottom:"1px dotted var(--border-default, var(--border))",whiteSpace:"nowrap"},children:o}):!r||r.trim()===""?t.jsx("span",{"data-testid":e["data-testid"]??"author-link-empty",style:{fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-secondary)"},children:"—"}):t.jsxs("button",{type:"button","data-testid":e["data-testid"]??"author-copy",title:`Copy "${o}"`,onClick:c,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 6px",border:"1px solid var(--border-default, var(--border))",borderRadius:4,background:"transparent",fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-secondary)",cursor:"pointer",whiteSpace:"nowrap"},children:[o,t.jsx("span",{"aria-hidden":"true",style:{fontSize:10,opacity:.7},children:a?"✓":"⧉"})]})}function jd(e){let r=e.split("#")[0].split("?")[0].replace(/\/+$/,"");return r=r.replace(/\/(?:tree|blob)\/[^/]+(?:\/.*)?$/,""),r}function wb(e,r){const n=jd(e),s=(r??"").replace(/^\/+/,"").replace(/\/+$/,"");return s?`${n}/blob/HEAD/${s}`:`${n}/blob/HEAD/`}function Mi(e){if(!e)return"source";const r=e.replace(/\/+$/,""),n=r.lastIndexOf("/");return n===-1?r:r.slice(n+1)}function wd(e){const{repoUrl:r,skillPath:n,absolutePath:s}=e,[o,a]=l.useState(!1),i=typeof r=="string"&&r.trim()!==""&&/^https?:\/\//.test(r.trim()),c=n?Mi(n):s?Mi(s):"source",d=l.useCallback(async()=>{var f;const p=s??n??"";if(p)try{await((f=navigator.clipboard)==null?void 0:f.writeText(p)),a(!0),setTimeout(()=>a(!1),1500)}catch{}},[s,n]);if(i){const p=wb(r,n);return t.jsxs("a",{"data-testid":e["data-testid"]??"source-file-link",href:p,target:"_blank",rel:"noopener noreferrer",title:p,style:{display:"inline-flex",alignItems:"center",gap:4,fontFamily:"var(--font-mono, var(--font-geist-mono))",fontSize:12,color:"var(--text-accent, var(--text-primary))",textDecoration:"none",whiteSpace:"nowrap",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis"},children:[t.jsx("span",{children:c}),t.jsx("span",{"aria-hidden":"true",children:"↗"})]})}if(!s&&!n)return t.jsx("span",{"data-testid":e["data-testid"]??"source-file-empty",style:{fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-secondary)"},children:"—"});const u=s??n??"";return t.jsxs("button",{type:"button","data-testid":e["data-testid"]??"source-file-copy",title:`Copy ${u}`,onClick:d,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 6px",border:"1px solid var(--border-default, var(--border))",borderRadius:4,background:"transparent",fontFamily:"var(--font-mono, var(--font-geist-mono))",fontSize:12,color:"var(--text-secondary)",cursor:"pointer",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[t.jsx("span",{children:c}),t.jsx("span",{"aria-hidden":"true",style:{fontSize:10,opacity:.7},children:o?"✓":"⧉"})]})}const Sb=/^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/,Cb=/^[A-Za-z0-9._-]+$/;function Eb(e){if(!e||typeof e!="string")return null;const r=e.trim();if(!r)return null;let n;try{n=jd(r)}catch{return null}let s;try{s=new URL(n)}catch{return null}const o=s.hostname.toLowerCase();if(o!=="github.com"&&o!=="www.github.com")return null;const a=s.pathname.split("/").filter(Boolean);if(a.length!==2)return null;const i=a[0],c=a[1].replace(/\.git$/i,"");return!Sb.test(i)||!c||!Cb.test(c)?null:{owner:i,repo:c}}function Nb(e){const r=Eb(e.repoUrl??null);if(!r)return null;const n=`https://github.com/${r.owner}/${r.repo}`;return t.jsxs("a",{"data-testid":e["data-testid"]??"repo-link",href:n,target:"_blank",rel:"noopener noreferrer",title:n,style:{fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-accent, var(--text-primary))",textDecoration:"none",borderBottom:"1px dotted var(--border-default, var(--border))",whiteSpace:"nowrap"},children:[r.owner,"/",r.repo]})}function Di(e,r="info"){typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:e,severity:r}}))}function Sd(e){return e.skill?Tb({skill:e.skill}):Lb({state:e.state,isReadOnly:e.isReadOnly,onDelete:e.onDelete})}function Rb(e,r=48){if(e.length<=r)return e;const n=e.slice(0,12),s=e.slice(e.length-(r-12-1));return`${n}…${s}`}function Tb({skill:e}){const[r,n]=l.useState(!1),s=(e.sourcePath??e.dir)||"—",o=l.useCallback(async()=>{var c;try{await((c=navigator.clipboard)==null?void 0:c.writeText(s)),n(!0),setTimeout(()=>n(!1),1500),Di(_.toasts.pathCopied,"info")}catch{Di(_.toasts.permissionDenied,"error")}},[s]),a=e.source==="project"?"Project":e.source==="personal"?"Personal":e.source==="plugin"?"Plugins":e.origin==="installed"?"Personal":"Skills",i=e.source==="project"?"var(--status-installed)":e.source==="plugin"?"var(--color-accent-ink)":"var(--status-own)";return t.jsxs("div",{"data-testid":"detail-header",style:{background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:8,padding:"14px 16px",boxShadow:"none"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-secondary)",marginBottom:4},children:[t.jsx("span",{"data-testid":"detail-header-plugin",children:e.plugin}),t.jsx("span",{"aria-hidden":"true",style:{color:"var(--text-secondary)"},children:"›"}),t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,color:"var(--text-secondary)",fontSize:11,letterSpacing:.3,textTransform:"uppercase"},children:[t.jsx("span",{"data-origin-dot":e.origin,"aria-label":`Origin: ${a}`,style:{display:"inline-block",width:7,height:7,borderRadius:999,background:i}}),a]})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,marginBottom:8},children:[t.jsx("h2",{"data-testid":"detail-header-name",style:{fontFamily:"var(--font-serif)",fontSize:20,fontWeight:500,lineHeight:1.25,color:"var(--text-primary)",margin:0},children:e.skill}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("span",{"data-testid":"detail-header-version",children:t.jsx(vn,{version:e.resolvedVersion??e.version??null,source:e.versionSource,pluginName:e.pluginName??null})}),e.pluginName&&e.pluginVersion&&t.jsxs("span",{"data-testid":"detail-header-plugin-chip",title:`This skill ships in plugin ${e.pluginName} v${e.pluginVersion}. The plugin version is independent of this skill's own version track.`,style:{display:"inline-flex",alignItems:"baseline",gap:4,fontFamily:"var(--font-sans)",fontSize:11,color:"var(--text-tertiary)",padding:"2px 6px",borderRadius:4,background:"var(--surface-1, transparent)",border:"1px solid var(--border-subtle, transparent)",whiteSpace:"nowrap"},children:[t.jsx("span",{children:"from"}),t.jsx("span",{style:{color:"var(--text-secondary)"},children:e.pluginName}),t.jsx("span",{"aria-hidden":"true",children:"@"}),t.jsx("span",{style:{fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums",color:"var(--text-secondary)"},children:e.pluginVersion})]}),e.origin==="source"&&t.jsx("button",{type:"button","data-testid":"detail-header-delete","aria-label":"Delete skill",title:"Delete skill",onClick:()=>{typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:request-delete",{detail:{skill:e}}))},className:"flex items-center justify-center transition-colors duration-150",style:{background:"none",border:"none",cursor:"pointer",color:"var(--text-tertiary)",padding:4,borderRadius:4},onMouseEnter:c=>{c.currentTarget.style.color="var(--red)"},onMouseLeave:c=>{c.currentTarget.style.color="var(--text-tertiary)"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),t.jsx("path",{d:"M10 11v6"}),t.jsx("path",{d:"M14 11v6"}),t.jsx("path",{d:"M9 6V4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2"})]})})]})]}),t.jsxs("div",{"data-testid":"detail-header-byline",style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:10,margin:"0 0 8px",fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-secondary)"},children:[t.jsx(kd,{author:e.author??null,repoUrl:e.repoUrl??e.homepage??null}),t.jsx(Nb,{repoUrl:e.repoUrl??null}),t.jsx(wd,{repoUrl:e.repoUrl??null,skillPath:e.skillPath??null,absolutePath:e.dir})]}),t.jsx(Ib,{skill:e}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[t.jsx("button",{type:"button","data-testid":"detail-header-path-chip",title:s,"aria-label":`Copy path ${s} to clipboard`,onClick:o,style:{display:"inline-flex",alignItems:"center",padding:"2px 8px",border:"1px solid var(--border-default)",borderRadius:4,background:"transparent",fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-secondary)",maxWidth:"100%",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",cursor:"pointer"},children:Rb(s)}),t.jsxs("button",{"data-testid":"detail-header-copy-path",type:"button",onClick:o,"aria-label":"Copy skill path to clipboard",style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",background:"transparent",border:"1px solid var(--border-default)",borderRadius:4,color:"var(--text-secondary)",fontFamily:"var(--font-sans)",fontSize:11,cursor:"pointer"},children:[t.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),t.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),r?"Copied":"Copy"]})]})]})}function Ib({skill:e}){const r=e.installMethod,n=e.symlinkTarget;if(!r)return null;let s="";switch(r){case"symlinked":s=n?`Symlinked from ${n}`:"Symlinked (target unresolved)";break;case"copied":s="Copied (independent)";break;case"authored":s="Authored";break;default:return null}return t.jsxs("div",{"data-testid":"detail-header-install-method",style:{display:"flex",alignItems:"center",gap:6,fontSize:11,color:"var(--text-secondary)",fontFamily:"var(--font-sans)",margin:"6px 0 8px"},children:[t.jsx("span",{style:{fontWeight:600,letterSpacing:"0.04em",textTransform:"uppercase",fontSize:10,color:"var(--text-tertiary)"},children:"Install method"}),t.jsx("span",{style:{fontFamily:"var(--font-mono)"},children:s})]})}function Lb({state:e,isReadOnly:r,onDelete:n}){const{plugin:s,skill:o,evals:a,latestBenchmark:i,isDirty:c,caseRunStates:d,regressions:u,iterationCount:p}=e,f=Array.from(d.values()).some(b=>b.status==="running"||b.status==="queued"),h=i==null?void 0:i.overall_pass_rate,m=(a==null?void 0:a.evals.reduce((b,y)=>b+y.assertions.length,0))??0,g=(a==null?void 0:a.evals.length)??0,x=bb(h),v=kb(h);return t.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5",style:{borderBottom:"1px solid var(--border-subtle)",background:"var(--surface-1)",flexShrink:0},children:[t.jsxs("div",{className:"flex items-center gap-2 text-[13px]",children:[t.jsx("span",{style:{color:"var(--text-tertiary)"},children:s}),t.jsx(Ab,{}),t.jsx("span",{className:"font-medium",style:{color:"var(--text-primary)"},children:o}),r&&t.jsxs("span",{className:"ml-2 flex items-center gap-1 text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded",style:{background:"var(--surface-3)",color:"var(--text-tertiary)"},children:[t.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),"installed"]}),c&&t.jsx("span",{className:"ml-2 text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded",style:{background:"var(--yellow-muted)",color:"var(--yellow)"},children:"unsaved"}),f&&t.jsxs("span",{className:"ml-2 flex items-center gap-1.5 text-[11px]",style:{color:"var(--accent)"},children:[t.jsx("span",{className:"spinner",style:{width:12,height:12,borderWidth:1.5}}),"Running..."]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[!r&&n&&t.jsx("button",{disabled:f,onClick:()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("studio:request-delete",{detail:{skill:{plugin:s,skill:o,dir:"",hasEvals:!1,hasBenchmark:!1,evalCount:0,assertionCount:0,benchmarkStatus:"missing",lastBenchmark:null,origin:"source"}}}))},title:"Delete skill",className:"flex items-center justify-center transition-colors duration-150",style:{background:"none",border:"none",cursor:f?"not-allowed":"pointer",color:"var(--text-tertiary)",padding:4,opacity:f?.4:1,borderRadius:4},onMouseEnter:b=>{f||(b.currentTarget.style.color="var(--red)")},onMouseLeave:b=>{b.currentTarget.style.color="var(--text-tertiary)"},children:t.jsx(Pb,{})}),u.length>0&&t.jsxs("span",{className:"pill",style:{background:"var(--red-muted)",color:"var(--red)"},children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[t.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),t.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),t.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),u.length," regression",u.length>1?"s":""]}),p>0&&t.jsxs("span",{className:"pill",style:{background:"var(--purple-muted)",color:"var(--purple)"},children:["Iter ",p]}),t.jsx("span",{className:"pill",style:{background:v,color:x},children:h!=null?`${Math.round(h*100)}%`:"--"}),t.jsxs("span",{className:"text-[11px]",style:{color:"var(--text-tertiary)"},children:[g," case",g!==1?"s":""," / ",m," assert",m!==1?"s":""]})]})]})}function Ab(){return t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2",children:t.jsx("polyline",{points:"9 18 15 12 9 6"})})}function Pb(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),t.jsx("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),t.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function tr(e){const{title:r,label:n,value:s,subtitle:o,description:a,linkLabel:i,children:c,onClick:d}=e,u=r??n??"",p=typeof d=="function",f=h=>{p&&(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),d==null||d())};return t.jsxs("div",{className:p?"metric-card metric-card-link":"metric-card","data-testid":e["data-testid"],role:p?"button":void 0,tabIndex:p?0:void 0,onClick:p?()=>d==null?void 0:d():void 0,onKeyDown:p?f:void 0,style:{background:"var(--card-bg, var(--bg-surface))",border:"1px solid var(--border, var(--border-default))",borderRadius:6,padding:"1rem",display:"flex",flexDirection:"column",gap:"0.375rem",minWidth:0,height:"100%",cursor:p?"pointer":void 0,wordBreak:"break-word",overflowWrap:"anywhere"},children:[u?t.jsx("div",{"data-testid":e["data-testid"]?`${e["data-testid"]}-title`:void 0,style:{fontFamily:"var(--font-geist-mono, var(--font-mono))",fontSize:"0.5625rem",fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--card-text-muted, var(--text-secondary))"},children:u}):null,t.jsx("div",{"data-testid":e["data-testid"]?`${e["data-testid"]}-value`:void 0,style:{fontFamily:"var(--font-geist-mono, var(--font-mono))",fontSize:"1.375rem",fontWeight:700,color:"var(--card-text, var(--text-primary))",lineHeight:1,fontVariantNumeric:"tabular-nums"},children:String(s)}),o?t.jsx("div",{style:{fontFamily:"var(--font-geist-mono, var(--font-mono))",fontSize:"0.625rem",color:"var(--card-text-muted, var(--text-secondary))"},children:o}):null,a?t.jsx("div",{style:{fontFamily:"var(--font-geist-mono, var(--font-mono))",fontSize:"0.5625rem",color:"var(--card-text-muted, var(--text-secondary))",lineHeight:1.4,opacity:.7},children:a}):null,c?t.jsx("div",{style:{flex:1,marginTop:"0.25rem"},children:c}):null,i?t.jsx("div",{style:{marginTop:"auto",paddingTop:"0.375rem",borderTop:"1px solid var(--border, var(--border-default))",fontFamily:"var(--font-geist-mono, var(--font-mono))",fontSize:"0.625rem",color:"var(--card-text-muted, var(--text-secondary))"},children:i}):null]})}const $b="Benchmarks are the aggregated score of this skill's evals (evals.yaml) run against its tests (tests/). Each test case produces a verdict; the benchmark is the mean pass rate.";function Mb(e){const{onNavigate:r}=e,[n,s]=l.useState(e.open??!1),o=l.useCallback(()=>s(!1),[]);l.useEffect(()=>{if(!n)return;const i=c=>{c.key==="Escape"&&o()};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[n,o]);const a=l.useCallback(i=>{r==null||r(i),s(!1)},[r]);return t.jsxs("span",{"data-testid":e["data-testid"]??"benchmark-info",style:{position:"relative",display:"inline-flex",alignItems:"center"},children:[t.jsx("button",{type:"button","data-testid":"benchmark-info-trigger","aria-label":"About benchmarks","aria-expanded":!!n,onClick:()=>s(i=>!i),style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:18,height:18,padding:0,border:"1px solid var(--border-default, var(--border))",borderRadius:999,background:"transparent",color:"var(--text-secondary)",fontSize:11,fontFamily:"var(--font-sans)",cursor:"pointer",lineHeight:1},children:"ℹ"}),n&&t.jsxs("div",{role:"dialog","data-testid":"benchmark-info-popover",style:{position:"absolute",top:"100%",right:0,marginTop:6,zIndex:20,width:280,padding:"10px 12px",background:"var(--bg-surface, var(--surface-1))",border:"1px solid var(--border-default, var(--border))",borderRadius:6,fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-primary)",boxShadow:"0 4px 16px rgba(0,0,0,0.08)"},children:[t.jsx("p",{style:{margin:"0 0 8px",lineHeight:1.45},children:$b}),t.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[t.jsx("button",{type:"button","data-testid":"benchmark-info-link-tests",onClick:()=>a("tests"),style:Ws,children:"Tests →"}),t.jsx("button",{type:"button","data-testid":"benchmark-info-link-run",onClick:()=>a("run"),style:Ws,children:"Run →"}),t.jsx("button",{type:"button","data-testid":"benchmark-info-close",onClick:o,style:{...Ws,marginLeft:"auto",color:"var(--text-secondary)"},children:"Close"})]})]})]})}const Ws={background:"transparent",border:"none",padding:0,fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-accent, var(--text-primary))",cursor:"pointer",textDecoration:"underline"};function Db(e){return`gh repo create ${e.trim()||"<repo-name>"} --public --source=. --remote=origin --push`}const Fb="Add a GitHub remote: `gh repo create --public --source=.` (replace existing origin if needed).";function zb({value:e}){const[r,n]=l.useState(!1),s=l.useCallback(async()=>{try{await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)}catch{}},[e]);return t.jsx("button",{type:"button","data-testid":"publish-status-copy","aria-label":"Copy GitHub setup command",onClick:s,style:{fontSize:11,padding:"3px 8px",borderRadius:4,border:"1px solid var(--border-default, var(--border-subtle))",background:"var(--surface-2)",color:"var(--text-primary)",cursor:"pointer"},children:r?"Copied":"Copy"})}function Fi({tone:e,label:r}){const n=e==="ok"?"color-mix(in srgb, var(--color-ok, #22c55e) 18%, transparent)":"color-mix(in srgb, var(--color-own, #f59e0b) 18%, transparent)",s=e==="ok"?"var(--color-ok, #22c55e)":"var(--color-own, #f59e0b)";return t.jsx("span",{style:{display:"inline-flex",alignItems:"center",padding:"2px 8px",borderRadius:999,fontSize:11,fontWeight:500,color:s,background:n},children:r})}function Bb(e={}){const{status:r,loading:n}=Bc();if(n||!r)return null;if(r.status==="github")return t.jsxs("div",{"data-testid":"publish-status-row","data-status":"github",style:{display:"flex",alignItems:"center",gap:12,flexWrap:"wrap",padding:"10px 12px",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:8,background:"var(--bg-surface, var(--surface-1))"},children:[t.jsx(Fi,{tone:"ok",label:"Publish-ready"}),t.jsxs("span",{style:{fontSize:12,color:"var(--text-secondary)"},children:["GitHub origin: ",r.githubOrigin]}),t.jsx("div",{style:{marginLeft:"auto"},children:t.jsx(Zc,{remoteUrl:r.githubOrigin??"",provider:e.provider,model:e.model})})]});const s=r.status==="no-git"?Db(e.projectBasename??""):Fb;return t.jsxs("div",{"data-testid":"publish-status-row","data-status":r.status,style:{display:"flex",flexDirection:"column",gap:8,padding:"10px 12px",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:8,background:"var(--bg-surface, var(--surface-1))"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx(Fi,{tone:"warn",label:r.status==="no-git"?"No GitHub repo yet":"Origin is not GitHub"}),t.jsx("span",{style:{fontSize:12,color:"var(--text-secondary)"},children:"Connect GitHub to publish your skills."})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[t.jsx("code",{"data-testid":"publish-status-command",style:{flex:1,minWidth:0,padding:"6px 10px",borderRadius:4,background:"var(--surface-2)",color:"var(--text-primary)",fontFamily:"var(--font-mono)",fontSize:12,whiteSpace:"pre-wrap",wordBreak:"break-all"},children:s}),t.jsx(zb,{value:s})]})]})}function _b({plugin:e,skill:r}){const[n,s]=l.useState([]),[o,a]=l.useState([]),[i,c]=l.useState(!0),[d,u]=l.useState(null);l.useEffect(()=>{ie.getDependencies(e,r).then(f=>{s(f.mcpDependencies),a(f.skillDependencies)}).catch(()=>{}).finally(()=>c(!1))},[e,r]);async function p(f,h){try{await navigator.clipboard.writeText(h),u(f),setTimeout(()=>u(null),2e3)}catch{}}return i?null:n.length===0&&o.length===0?t.jsx("div",{className:"mb-5 px-4 py-3 rounded-lg text-[12px]",style:{background:"var(--surface-2)",color:"var(--text-tertiary)",border:"1px solid var(--border-subtle)"},children:"No dependencies detected"}):t.jsxs("div",{className:"mb-5 rounded-xl overflow-hidden",style:{border:"1px solid var(--border-subtle)",background:"var(--surface-1)"},children:[t.jsxs("div",{className:"flex items-center gap-2.5 px-5 py-3.5",style:{background:"var(--surface-2)",borderBottom:"1px solid var(--border-subtle)"},children:[t.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center",style:{background:"rgba(234,179,8,0.15)"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#eab308",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),t.jsx("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}),t.jsx("span",{className:"text-[13px] font-semibold",style:{color:"var(--text-primary)"},children:"Dependencies"}),t.jsx("span",{className:"pill text-[10px]",style:{background:"var(--surface-3)",color:"var(--text-tertiary)"},children:n.length+o.length})]}),t.jsxs("div",{className:"px-5 py-4",children:[n.length>0&&t.jsxs("div",{className:"space-y-3 mb-4",children:[t.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider",style:{color:"var(--text-tertiary)"},children:"MCP Servers"}),n.map(f=>t.jsxs("div",{className:"p-3 rounded-lg",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-[13px] font-medium",style:{color:"var(--text-primary)"},children:f.server}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{background:"var(--surface-3)",color:"var(--text-tertiary)"},children:f.transport})]}),t.jsx("button",{onClick:()=>p(f.server,f.configSnippet),className:"btn btn-ghost text-[11px] py-1 px-2",style:{color:d===f.server?"var(--green)":"var(--accent)"},children:d===f.server?t.jsxs(t.Fragment,{children:[t.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"20 6 9 17 4 12"})})," Copied!"]}):t.jsxs(t.Fragment,{children:[t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),t.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})," Copy Config"]})})]}),t.jsx("div",{className:"text-[11px] mb-2 font-mono",style:{color:"var(--text-tertiary)"},children:f.url}),t.jsx("div",{className:"flex flex-wrap gap-1.5",children:f.matchedTools.map(h=>t.jsx("span",{className:"px-2 py-0.5 rounded text-[10px] font-mono",style:{background:"var(--surface-3)",color:"var(--text-secondary)"},children:h},h))})]},f.server))]}),o.length>0&&t.jsxs("div",{children:[t.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-wider mb-2",style:{color:"var(--text-tertiary)"},children:"Skill Dependencies"}),t.jsx("div",{className:"space-y-1.5",children:o.map(f=>t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)"},children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--text-tertiary)",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"})}),t.jsx("span",{className:"text-[12px] font-medium",style:{color:"var(--text-primary)"},children:f.name}),t.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{background:"var(--surface-3)",color:"var(--text-tertiary)"},children:f.source==="frontmatter"?"frontmatter":"referenced"})]},f.name))})]})]})]})}const Ob="https://verified-skill.com/docs/parameters-and-secrets",Wb="Stored as KEY=value in this skill's local .env.local (gitignored). Resolved from process.env first, then .env.local.";function zi({onToggleAdd:e,addFormOpen:r}){return t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsxs("span",{className:"text-[11px] font-semibold uppercase tracking-wider flex items-center gap-1.5",style:{color:"var(--text-tertiary)"},children:["Parameters & Secrets",t.jsx("span",{"aria-label":"About Parameters & Secrets",title:Wb,style:{cursor:"help",fontSize:11,color:"var(--text-tertiary)",opacity:.7,display:"inline-block",lineHeight:1},children:"ⓘ"})]}),t.jsx("button",{onClick:e,"aria-pressed":r,className:"text-[11px] transition-colors duration-150",style:{color:"var(--accent)",background:"none",border:"none",cursor:"pointer"},children:"+ Add Parameter"})]})}function Hb(){return t.jsxs("div",{className:"px-4 py-5 rounded-xl flex flex-col gap-2",style:{background:"var(--surface-2)"},children:[t.jsx("div",{className:"text-[13px] font-semibold",style:{color:"var(--text-secondary)"},children:"No parameters yet"}),t.jsxs("div",{className:"text-[12px]",style:{color:"var(--text-tertiary)",lineHeight:1.5},children:["Values are stored as ",t.jsx("code",{style:{fontSize:11},children:"KEY=value"})," in this skill's local"," ",t.jsx("code",{style:{fontSize:11},children:".env.local"})," (auto-added to"," ",t.jsx("code",{style:{fontSize:11},children:".gitignore"}),"). They appear here when declared as"," ",t.jsx("code",{style:{fontSize:11},children:"requiredCredentials"})," in"," ",t.jsx("code",{style:{fontSize:11},children:"evals.json"}),", or when you add custom ones below."]}),t.jsx("a",{href:Ob,target:"_blank",rel:"noopener noreferrer",className:"text-[11px]",style:{color:"var(--accent)",textDecoration:"none"},children:"Learn more →"})]})}function Ub({plugin:e,skill:r}){const[n,s]=l.useState([]),[o,a]=l.useState(!0),[i,c]=l.useState(null),[d,u]=l.useState(""),[p,f]=l.useState(!1),[h,m]=l.useState(null),[g,x]=l.useState(""),[v,b]=l.useState(""),[y,j]=l.useState(!1),[S,w]=l.useState(new Set),R=l.useCallback(async()=>{a(!0);try{const[N,I]=await Promise.all([ie.getCredentials(e,r).catch(()=>({credentials:[]})),ie.getParams(e,r).catch(()=>({params:[]}))]),P=new Map(I.params.map(T=>[T.name,T])),L=new Set,B=[];for(const T of N.credentials){L.add(T.name);const $=P.get(T.name);B.push({name:T.name,status:T.status==="ready"||T.status==="resolved"?"ready":"missing",source:T.source,maskedValue:$==null?void 0:$.maskedValue})}for(const T of I.params)L.has(T.name)||B.push({name:T.name,status:T.status,maskedValue:T.maskedValue});s(B)}finally{a(!1)}},[e,r]);l.useEffect(()=>{R()},[R]);const k=l.useCallback(async N=>{if(S.has(N)){w(I=>{const P=new Set(I);return P.delete(N),P}),s(I=>I.map(P=>P.name===N?{...P,revealedValue:void 0}:P));return}try{const P=(await ie.getParamsRevealed(e,r,N)).params.find(L=>L.name===N);P&&(s(L=>L.map(B=>B.name===N?{...B,revealedValue:P.value}:B)),w(L=>new Set(L).add(N)))}catch{}},[e,r,S]),E=async(N,I)=>{if(!(!N.trim()||!I.trim())){f(!0),m(null);try{await ie.setCredential(e,r,N,I),c(null),u(""),w(new Set),R()}catch(P){m(P.message)}finally{f(!1)}}},C=async()=>{if(!(!g.trim()||!v.trim())){f(!0),m(null);try{await ie.setCredential(e,r,g.trim().toUpperCase(),v),x(""),b(""),j(!1),R()}catch(N){m(N.message)}finally{f(!1)}}};return o?t.jsxs("div",{className:"mt-6",children:[t.jsx(zi,{onToggleAdd:()=>{},addFormOpen:!1}),t.jsx("div",{className:"skeleton h-20 rounded-xl"})]}):t.jsxs("div",{className:"mt-6",children:[t.jsx(zi,{onToggleAdd:()=>j(!y),addFormOpen:y}),h&&t.jsx("div",{className:"mb-2 px-3 py-2 rounded-lg text-[11px]",style:{background:"var(--red-muted)",color:"var(--red)"},children:h}),n.length===0&&!y?t.jsx(Hb,{}):t.jsx("div",{className:"rounded-xl overflow-hidden",style:{border:"1px solid var(--border-subtle)"},children:n.map(N=>t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",style:{borderBottom:"1px solid var(--border-subtle)",background:"var(--surface-1)"},children:[t.jsx("span",{className:"text-[11px] font-mono font-medium truncate",style:{color:"var(--text-primary)",minWidth:80},children:N.name}),N.maskedValue&&t.jsx("span",{className:"text-[10px] font-mono truncate",style:{color:"var(--text-tertiary)",maxWidth:120},children:S.has(N.name)&&N.revealedValue!=null?N.revealedValue:N.maskedValue}),N.maskedValue&&t.jsx("button",{onClick:()=>k(N.name),className:"btn btn-ghost px-1",title:S.has(N.name)?"Hide value":"Reveal value",style:{color:"var(--text-tertiary)",lineHeight:1},children:S.has(N.name)?t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"}),t.jsx("path",{d:"M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"}),t.jsx("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}):t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),t.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),t.jsx("span",{className:"text-[10px] font-semibold px-2 py-0.5 rounded-full",style:{background:N.status==="ready"?"var(--green-muted)":"var(--orange-muted)",color:N.status==="ready"?"var(--green)":"var(--orange)"},children:N.status==="ready"?"ready":"missing"}),N.source&&t.jsx("span",{className:"text-[9px]",style:{color:"var(--text-tertiary)"},children:N.source}),i===N.name?t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("input",{value:d,onChange:I=>u(I.target.value),onKeyDown:I=>{I.key==="Enter"&&E(N.name,d)},className:"input-field text-[11px] font-mono",style:{width:160},placeholder:"Value...",autoFocus:!0}),t.jsx("button",{onClick:()=>E(N.name,d),disabled:p||!d.trim(),className:"btn btn-primary text-[10px] px-2 py-0.5",children:p?"...":"Save"}),t.jsx("button",{onClick:()=>{c(null),u("")},className:"btn btn-ghost text-[10px] px-1",children:t.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}):t.jsx("button",{onClick:()=>{c(N.name),u("")},className:"btn btn-ghost text-[10px] px-2 py-0.5",style:{color:"var(--accent)"},children:"Edit"})]},N.name))}),y&&t.jsxs("div",{className:"mt-2 p-3 rounded-lg",style:{background:"var(--surface-2)",border:"1px solid var(--border-subtle)"},children:[t.jsxs("div",{className:"flex gap-2 mb-2",children:[t.jsx("input",{value:g,onChange:N=>x(N.target.value),className:"input-field flex-1 text-[11px] font-mono",placeholder:"KEY_NAME",autoFocus:!0}),t.jsx("input",{value:v,onChange:N=>b(N.target.value),onKeyDown:N=>{N.key==="Enter"&&C()},className:"input-field flex-1 text-[11px] font-mono",placeholder:"Value",type:"password"})]}),t.jsxs("div",{className:"flex justify-end gap-1.5",children:[t.jsx("button",{onClick:()=>{j(!1),x(""),b("")},className:"btn btn-ghost text-[10px]",children:"Cancel"}),t.jsx("button",{onClick:C,disabled:p||!g.trim()||!v.trim(),className:"btn btn-primary text-[10px]",children:p?"Saving...":"Save"})]})]})]})}function Bi({children:e}){return t.jsx("h3",{style:{fontFamily:"var(--font-sans)",fontSize:12,fontWeight:600,textTransform:"uppercase",letterSpacing:.6,color:"var(--text-tertiary)",margin:"0 0 8px"},children:e})}function Vb({plugin:e,skill:r}){return t.jsxs("aside",{"data-testid":"skill-overview-rightrail",style:{display:"flex",flexDirection:"column",gap:16},children:[t.jsxs("section",{"data-testid":"overview-rightrail-setup",children:[t.jsx(Bi,{children:"Setup"}),t.jsx(_b,{plugin:e,skill:r})]}),t.jsxs("section",{"data-testid":"overview-rightrail-credentials",children:[t.jsx(Bi,{children:"Credentials"}),t.jsx(Ub,{plugin:e,skill:r})]})]})}function Gb(e){if(e==null||!Number.isFinite(e))return"—";if(e<1024)return`${e} B`;const r=e/1024;if(r<1024)return r>=10?`${Math.round(r)} KB`:`${r.toFixed(1).replace(/\.0$/,"")} KB`;const n=r/1024;return n>=10?`${Math.round(n)} MB`:`${n.toFixed(1).replace(/\.0$/,"")} MB`}function Vr(e){if(!e)return"—";const r=new Date(e);if(Number.isNaN(r.getTime()))return e;const n=Date.now()-r.getTime(),s=Math.floor(n/1e3);if(s<60)return"just now";const o=Math.floor(s/60);if(o<60)return`${o} min ago`;const a=Math.floor(o/60);if(a<24)return`${a} hr ago`;const i=Math.floor(a/24);if(i<30)return`${i} day${i===1?"":"s"} ago`;const c=Math.floor(i/30);if(c<12)return`${c} month${c===1?"":"s"} ago`;const d=Math.floor(c/12);return`${d} year${d===1?"":"s"} ago`}function Kb(e){switch(e.benchmarkStatus){case"pass":case"fail":case"stale":return e.benchmarkStatus==="pass"?"100%":e.benchmarkStatus==="fail"?"0%":"—";default:return"—"}}function qb(e){const r=e.installMethod;if(!r)return null;const n=r==="authored"?"Authored":r==="copied"?"Copied":"Symlinked";return t.jsx("span",{"data-testid":"overview-install-method",style:{display:"inline-flex",alignItems:"center",padding:"1px 6px",border:"1px solid var(--border-default, var(--border))",borderRadius:4,fontFamily:"var(--font-mono, var(--font-geist-mono))",fontSize:10,color:"var(--text-secondary)",textTransform:"uppercase",letterSpacing:.4},children:n})}function Yb(e,r){const n=e.evalCount??0;return!e.hasEvals||n<=0?null:t.jsxs("button",{type:"button","data-testid":"overview-tests-chip",onClick:r?()=>r("run"):void 0,title:`Open Run tab — ${n} test case${n===1?"":"s"}`,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"2px 8px",border:"1px solid var(--border-default, var(--border))",borderRadius:9999,fontFamily:"var(--font-sans)",fontSize:11,color:"var(--text-secondary)",background:"transparent",cursor:r?"pointer":"default"},children:[n," ",n===1?"test":"tests"]})}function Jb(e){var f,h;const{skill:r,onNavigate:n,activationsCount:s=0,lastRunIso:o=null,repoUrl:a,skillPathInRepo:i}=e,c=a??(Xb(r.homepage)?r.homepage??null:null),d=((f=r.mcpDeps)==null?void 0:f.length)??0,u=((h=r.deps)==null?void 0:h.length)??0,p=t.jsxs("div",{"data-testid":"skill-overview-main",style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("header",{"data-testid":"skill-overview-header",style:{position:"sticky",top:0,zIndex:5,display:"flex",flexDirection:"column",gap:6,padding:"10px 12px",background:"var(--bg-surface, var(--surface-1))",border:"1px solid var(--border-default, var(--border))",borderRadius:8},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[t.jsx("h2",{"data-testid":"skill-overview-name",style:{fontFamily:"var(--font-serif, var(--font-sans))",fontSize:18,fontWeight:500,color:"var(--text-primary)",margin:0,lineHeight:1.2},children:r.skill}),t.jsx(vn,{version:r.resolvedVersion??r.version??null,source:r.versionSource,pluginName:r.pluginName??null}),qb(r),Yb(r,n)]}),t.jsxs("div",{"data-testid":"skill-overview-byline",style:{display:"flex",flexWrap:"wrap",alignItems:"center",gap:10,fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-secondary)"},children:[t.jsx(kd,{author:r.author??null,repoUrl:c}),r.category?t.jsxs("span",{children:["· ",r.category]}):null,t.jsx(wd,{repoUrl:c,skillPath:i??null,absolutePath:r.dir}),r.lastModified?t.jsxs("span",{title:r.lastModified,children:["· Updated ",Vr(r.lastModified)]}):null]})]}),r.origin!=="installed"&&!r.pluginMarketplace&&r.installMethod!=="copied"&&r.installMethod!=="symlinked"&&t.jsx(Bb,{}),t.jsxs("div",{"data-testid":"skill-overview-grid",className:"skill-overview-grid",style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"0.75rem",alignItems:"stretch"},children:[t.jsx(tr,{title:"Benchmark",value:Kb(r),subtitle:r.lastBenchmark?Vr(r.lastBenchmark):"Never run","data-testid":"metric-benchmark",onClick:n?()=>n("run"):void 0,children:t.jsx("div",{style:{marginTop:4,display:"inline-flex",alignItems:"center"},children:t.jsx(Mb,{onNavigate:n})})}),t.jsx(tr,{title:"Tests",value:r.evalCount??0,subtitle:`${r.assertionCount??0} assertions`,"data-testid":"metric-tests",onClick:n?()=>n("tests"):void 0}),t.jsx(tr,{title:"Activations",value:s,subtitle:o?`Last: ${Vr(o)}`:"Never","data-testid":"metric-activations",onClick:n?()=>n("activation"):void 0}),t.jsx(tr,{title:"Last run",value:Vr(o??r.lastBenchmark??null),"data-testid":"metric-last-run",onClick:n?()=>n("history"):void 0}),t.jsx(tr,{title:"MCP deps",value:d,subtitle:d>0&&r.mcpDeps?r.mcpDeps.slice(0,3).join(", "):"None","data-testid":"metric-mcp-deps",onClick:n?()=>n("deps"):void 0}),t.jsx(tr,{title:"Skill deps",value:u,subtitle:u>0&&r.deps?r.deps.slice(0,3).join(", "):"None","data-testid":"metric-skill-deps",onClick:n?()=>n("deps"):void 0}),t.jsx(tr,{title:"Size",value:Gb(r.sizeBytes),"data-testid":"metric-size"}),t.jsx(tr,{title:"Last modified",value:Vr(r.lastModified),subtitle:r.lastModified??void 0,"data-testid":"metric-last-modified"})]})]});return t.jsxs("div",{"data-testid":"skill-overview",className:"skill-overview",style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) 280px",gap:16,padding:16,alignItems:"start"},children:[p,t.jsx(Vb,{plugin:r.plugin,skill:r.skill})]})}function Xb(e){return e?/^https?:\/\/(?:www\.)?(?:github\.com|raw\.githubusercontent\.com)\//.test(e):!1}function Qb({skill:e}){const{onSkillUpdated:r}=Mt(),{toast:n}=ss(),[s,o]=l.useState("idle"),[a,i]=l.useState(null),[c,d]=l.useState(!1),[u,p]=l.useState(null),[f,h]=l.useState(!1),m=l.useRef(null),g=l.useCallback(async()=>{if(!e||s==="updating")return;const y=new AbortController;m.current=y,o("updating"),i(null);try{const j=await ie.postSkillUpdate(e.plugin,e.skill,y.signal);if(j.ok)o("done"),r(e.plugin,e.skill),n({message:`Updated ${e.skill}.`,severity:"success",durationMs:4e3});else{const S=`Update failed (HTTP ${j.status}): ${j.body}`;o("idle"),i(S),n({message:`Couldn't update ${e.skill} — HTTP ${j.status}`,severity:"error",durationMs:0,action:{label:"Retry",onInvoke:()=>{g()}}})}}catch(j){if(j instanceof DOMException&&j.name==="AbortError")return;const S=j instanceof Error?j.message:"Network error";o("idle"),i(S),n({message:`Couldn't update ${e.skill} — ${S}`,severity:"error",durationMs:0,action:{label:"Retry",onInvoke:()=>{g()}}})}finally{m.current===y&&(m.current=null)}},[e,s,r,n]);if(l.useEffect(()=>{if(!c||u!=null||!e||!e.latestVersion)return;let y=!1;return h(!0),ie.getVersionDiff(e.plugin,e.skill,e.currentVersion??"",e.latestVersion).then(j=>{y||p(j)}).catch(()=>{y||p(null)}).finally(()=>{y||h(!1)}),()=>{y=!0}},[c,u,e==null?void 0:e.plugin,e==null?void 0:e.skill,e==null?void 0:e.latestVersion,e==null?void 0:e.currentVersion,e]),l.useEffect(()=>()=>{var y;(y=m.current)==null||y.abort()},[]),!e||e.updateAvailable!==!0)return null;const x=e.latestVersion,v=s==="updating"?"Updating…":x?`Update to ${x}`:"Update",b=s==="updating";return t.jsxs("div",{"data-testid":"update-action",style:{display:"flex",flexDirection:"column",gap:6,padding:"12px 16px",borderTop:"1px solid var(--border-default)",borderBottom:"1px solid var(--border-default)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[t.jsx("button",{type:"button","data-testid":"update-action-button",onClick:()=>{g()},disabled:b,style:{height:36,padding:"0 14px",background:"var(--color-ink)",color:"var(--color-paper)",border:"none",borderRadius:4,cursor:b?"not-allowed":"pointer",fontFamily:"var(--font-sans)",fontSize:13,fontWeight:500},children:v}),t.jsx("button",{type:"button","data-testid":"update-action-toggle-changelog",onClick:()=>d(y=>!y),disabled:b||!x,style:{background:"transparent",border:"none",color:"var(--text-secondary)",fontSize:12,fontFamily:"var(--font-sans)",cursor:"pointer",textDecoration:"underline"},children:c?"Hide changelog":"Preview changelog"})]}),s==="updating"&&t.jsx("div",{"data-testid":"update-action-progress",role:"status",style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-muted, var(--text-secondary))"},children:"Updating…"}),a&&s!=="updating"&&t.jsx("div",{"data-testid":"update-action-error",role:"alert",style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--color-error, #d32f2f)"},children:a}),c&&x&&t.jsxs("div",{"data-testid":"update-action-changelog",style:{paddingTop:8},children:[f&&t.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:"Loading changelog…"}),!f&&u&&t.jsx(sa,{contentDiff:u.contentDiff,fromLabel:u.from,toLabel:u.to,diffSummary:u.diffSummary??void 0,renderContext:"inline"}),!f&&!u&&t.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:"Couldn't load changelog."})]})]})}const Zb=3e4;function e1({plugin:e,skill:r,trackedForUpdates:n=!0,discoveryBackedOff:s=!1}){const o=Mt(),[a,i]=l.useState(!1),[c,d]=l.useState(!1),[,u]=l.useState(0),p=l.useRef(null),f=l.useRef(null),h=`${e}/${r}`,m=o.updatesById.get(h);if(l.useEffect(()=>{if(!a)return;const x=setInterval(()=>u(v=>(v+1)%1e6),250);return()=>clearInterval(x)},[a]),l.useEffect(()=>{if(!a||!m)return;const x=f.current??0;m.receivedAt<x||(p.current&&(clearTimeout(p.current),p.current=null),i(!1),d(!1),f.current=null)},[a,m]),l.useEffect(()=>()=>{p.current&&clearTimeout(p.current)},[]),n===!1||s)return null;const g=async()=>{if(!a){d(!1),i(!0),f.current=Date.now(),p.current=setTimeout(()=>{i(!1),d(!0),p.current=null,f.current=null},Zb);try{await ie.rescanSkill(e,r),p.current&&(clearTimeout(p.current),p.current=null);const x=o.updatesById.get(h),v=f.current??0,b=!!x&&x.receivedAt>=v;i(!1),b||d(!0),f.current=null}catch{p.current&&(clearTimeout(p.current),p.current=null),i(!1),f.current=null}}};return t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[t.jsx("button",{type:"button","data-testid":"check-now-button",onClick:g,disabled:a,style:{height:26,padding:"0 10px",background:"transparent",border:"1px solid var(--border-default)",borderRadius:4,color:"var(--text-secondary)",fontFamily:"var(--font-sans)",fontSize:12,cursor:a?"not-allowed":"pointer"},children:"Check now"}),a&&t.jsx("span",{"data-testid":"check-now-spinner","aria-label":"Checking for updates",role:"status",style:{display:"inline-block",width:10,height:10,borderRadius:"50%",border:"2px solid var(--text-secondary)",borderTopColor:"transparent",animation:"check-now-spin 800ms linear infinite"}}),c&&t.jsx("span",{"data-testid":"check-now-no-changes",style:{fontSize:11,color:"var(--text-secondary)",fontFamily:"var(--font-sans)"},children:"No changes detected"})]})}function t1(e,r){var n;typeof process<"u"&&((n=process==null?void 0:process.env)==null?void 0:n.NODE_ENV)==="production"||console.warn(`[SubTabBar] sub-tab "${r}" clicked under "${e}" but no onChange handler was wired. Pass an onChange prop or this click is a no-op.`)}function r1({tabs:e,active:r,onChange:n,parentTabId:s}){const[o,a]=l.useState(null),i=c=>{n?n(c):t1(s,c)};return t.jsx("div",{role:"tablist","aria-label":`${s} sub-sections`,"data-testid":`detail-subtab-bar-${s}`,style:{display:"flex",alignItems:"stretch",gap:2,borderBottom:"1px solid var(--border-subtle, var(--border-default))",padding:"0 16px",background:"var(--bg-canvas)",overflowX:"auto"},children:e.map(c=>{const d=c.id===r,u=o===c.id&&!d;return t.jsx("button",{type:"button",role:"tab","aria-selected":d,tabIndex:d?0:-1,id:`detail-subtab-${s}-${c.id}`,"data-testid":`detail-subtab-${s}-${c.id}`,onClick:()=>i(c.id),onMouseEnter:()=>a(c.id),onMouseLeave:()=>a(p=>p===c.id?null:p),style:{background:u?"var(--surface-2, rgba(0,0,0,0.04))":"transparent",border:"none",borderBottom:d?"2px solid var(--text-primary)":"2px solid var(--border-subtle, transparent)",padding:"8px 10px",marginBottom:-1,fontFamily:"var(--font-sans)",fontSize:13,fontWeight:d?500:400,color:d?"var(--text-primary)":"var(--text-secondary)",cursor:"pointer",whiteSpace:"nowrap",transition:"background 80ms ease"},children:c.label},c.id)})})}const n1=[{id:"overview",label:"Overview"},{id:"source",label:"Source"},{id:"edit",label:"Edit",visibleWhen:({isReadOnly:e})=>!e},{id:"tests",label:"Tests"},{id:"run",label:"Run"},{id:"history",label:"History"}];function Cd(e){return n1.filter(r=>r.visibleWhen?r.visibleWhen({isReadOnly:e}):!0)}const s1={tests:{tab:"tests"},trigger:{tab:"run",mode:"activation"},activation:{tab:"run",mode:"activation"},versions:{tab:"history",view:"versions"},leaderboard:{tab:"history",view:"models"},editor:{tab:"edit"},overview:{tab:"overview"},source:{tab:"source"},edit:{tab:"edit"},run:{tab:"run"},history:{tab:"history"}};function Zn(e){return e?s1[e]??null:null}function Po(e){const r=new URLSearchParams(e),n=r.get("tab"),s=r.get("panel");return Zn(n)??Zn(s)??{tab:"overview"}}function Ed(e,r){return!r||new Set(Cd(!0).map(s=>s.id)).has(e)?e:"source"}const Rr={run:[{id:"benchmark",label:"Benchmark"},{id:"activation",label:"Activation"},{id:"ab",label:"A/B"}],history:[{id:"timeline",label:"Timeline"},{id:"models",label:"Models"},{id:"versions",label:"Versions"}]};function rn(e){const r=Rr[e];return r&&r.length>0?r[0].id:""}function Nd(e,r){const n=Rr[e];if(!n)return"";const s=new URLSearchParams(r),o=e==="run"?"mode":e==="history"?"view":"sub",a=s.get(o)??s.get("sub");return a&&n.some(i=>i.id===a)?a:n[0].id}function o1(e){return e==="run"?"mode":e==="history"?"view":null}function a1(e){switch(e){case"editor":case"tests":case"deps":return{tab:"edit"};case"run":return{tab:"run",mode:"benchmark"};case"activation":return{tab:"run",mode:"activation"};case"history":return{tab:"history",view:"timeline"};case"leaderboard":return{tab:"history",view:"models"};case"versions":return{tab:"history",view:"versions"};default:return{tab:"overview"}}}function Hs(){const{state:e,setMobileView:r}=Mt();return e.isMobile?t.jsxs("button",{onClick:()=>r("list"),className:"flex items-center gap-1.5 px-3 py-2 text-[12px] font-medium",style:{background:"var(--surface-1)",color:"var(--text-secondary)",border:"none",borderBottom:"1px solid var(--border-subtle)",cursor:"pointer",width:"100%"},children:[t.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("polyline",{points:"15 18 9 12 15 6"})}),"Back to skills"]}):null}function i1(e={}){if(e.selectedSkillInfo!==void 0||e.loadError!==void 0)return l1(e);const{state:r,selectSkill:n,setMode:s,refreshSkills:o}=Mt(),[a,i]=l.useState(typeof window<"u"?window.location.hash:"");if(l.useEffect(()=>{const u=()=>i(window.location.hash);return window.addEventListener("hashchange",u),()=>window.removeEventListener("hashchange",u)},[]),a==="#/updates")return t.jsxs("div",{className:"h-full overflow-auto animate-fade-in",children:[t.jsx(Hs,{}),t.jsx(bd,{})]});if(r.mode==="create")return t.jsxs("div",{className:"h-full overflow-auto animate-fade-in",children:[t.jsx(Hs,{}),t.jsx(xb,{onCreated:async(u,p)=>{s("browse"),await o(),n({plugin:u,skill:p,origin:"source",source:"project"})},onCancel:()=>s("browse")})]});if(!r.selectedSkill)return r.skillsError?t.jsx(Xr,{variant:"error",message:r.skillsError,onRetry:o}):!r.skillsLoading&&r.skills.length===0?t.jsx(Xr,{variant:"no-skills"}):!r.skillsLoading&&r.skills.length>0&&!r.skills.some(u=>u.scopeV2==="available-project")?t.jsx(Xr,{variant:"no-project-skills"}):t.jsx(Xr,{variant:"no-selection"});const c=r.selectedSkill,d=r.skills.find(u=>u.plugin===c.plugin&&u.skill===c.skill)??null;return t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx(Hs,{}),t.jsx(c1,{skillInfo:d,allSkills:r.skills,onSelectSkill:u=>n(u)})]})}function l1(e){const r=e.selectedSkillInfo??null,n=e.activeDetailTab??"overview";if(r==null)return u1();if(e.loadError)return p1(r,e.loadError);const s=e.allSkills&&e.onSelectSkill?{allSkills:e.allSkills,onSelectSkill:e.onSelectSkill}:void 0,o=e.activeDetailSub??rn(n);return Rd(r,n,e.onDetailTabChange,o,e.onDetailSubChange,s)}function c1({skillInfo:e,allSkills:r,onSelectSkill:n}){const s=l.useMemo(()=>typeof window>"u"?{tab:"overview"}:Po(window.location.search),[]),[o,a]=l.useState(s.tab),[i,c]=l.useState(()=>s.mode?s.mode:s.view?s.view:Nd(s.tab,typeof window<"u"?window.location.search:""));l.useEffect(()=>{if(!e||!(e.origin==="installed"))return;const p=Ed(o,!0);p!==o&&(a(p),typeof window<"u"&&window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:"This skill is read-only — workbench tabs are hidden.",severity:"info"}})))},[e,o]),l.useEffect(()=>{c(rn(o))},[o]),l.useEffect(()=>{if(typeof window>"u")return;const u=new URLSearchParams(window.location.search);u.delete("panel"),u.delete("sub"),o==="overview"?u.delete("tab"):u.set("tab",o);const p=o1(o),f=Rr[o];u.delete("mode"),u.delete("view"),p&&f&&i&&i!==f[0].id&&u.set(p,i);const h=u.toString(),m=`${window.location.pathname}${h?"?"+h:""}${window.location.hash}`;window.history.replaceState(null,"",m)},[o,i]);const d=l.useMemo(()=>e?Rd(e,o,a,i,c,{}):t.jsx(Xr,{variant:"no-selection"}),[e,o,i,r,n]);return t.jsx("div",{className:"flex flex-col h-full",style:{background:"var(--bg-canvas)"},children:d})}function d1(e,r,n){const s=Cd(n);return t.jsx("div",{role:"tablist","aria-label":"Detail sections","data-testid":"detail-tab-bar",style:{display:"flex",alignItems:"stretch",gap:4,borderBottom:"1px solid var(--border-default)",padding:"0 16px",background:"var(--bg-canvas)",overflowX:"auto"},children:s.map(({id:o,label:a})=>{const i=o===e;return t.jsx("button",{type:"button",role:"tab","aria-selected":i,tabIndex:i?0:-1,id:`detail-tab-${o}`,"aria-controls":`detail-panel-${o}`,"data-testid":`detail-tab-${o}`,onClick:()=>r==null?void 0:r(o),style:{background:"transparent",border:"none",borderBottom:i?"2px solid var(--text-primary)":"2px solid transparent",padding:"10px 8px",marginBottom:-1,fontFamily:"var(--font-sans)",fontSize:13,fontWeight:i?500:400,color:i?"var(--text-primary)":"var(--text-secondary)",cursor:"pointer",whiteSpace:"nowrap"},children:a},o)})})}function u1(){return t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",padding:32,background:"var(--bg-canvas)"},children:[t.jsx("h2",{style:{fontFamily:"var(--font-serif)",fontSize:20,fontWeight:500,color:"var(--text-primary)",margin:0,marginBottom:8},children:"Select a skill to view details"}),t.jsx("p",{style:{fontFamily:"var(--font-sans)",fontSize:13,color:"var(--text-secondary)",margin:0,maxWidth:420,textAlign:"center"},children:"Choose a skill from the sidebar — its frontmatter, filesystem info, and benchmark status will appear here."})]})}function p1(e,r){return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12,padding:24,background:"var(--bg-canvas)",height:"100%"},children:[Sd({skill:e}),t.jsxs("section",{role:"alert",style:{background:"var(--bg-surface)",border:"1px solid var(--border-default)",borderRadius:8,padding:"14px 16px"},children:[t.jsxs("h3",{style:{fontFamily:"var(--font-serif)",fontSize:15,fontWeight:500,color:"var(--text-primary)",margin:"0 0 8px"},children:["Couldn't load SKILL.md for ",e.skill]}),t.jsx("p",{style:{fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-secondary)",margin:"0 0 12px",wordBreak:"break-word"},children:r})]})]})}function f1({active:e,sub:r}){if(e==="edit")return t.jsx(Bv,{});if(e==="tests")return t.jsx(ld,{});if(e==="run"){const n=ky(r)?r:"benchmark";return t.jsx(jy,{mode:n})}if(e==="history"){const n=ob(r)?r:"timeline";return t.jsx(ab,{view:n})}return null}function h1({active:e,sub:r}){const{state:n,dispatch:s}=ft();return l.useEffect(()=>{if(e==="overview")return;const o=e==="edit"?"editor":e==="tests"?"tests":e==="run"?r==="activation"?"activation":"run":e==="history"?r==="models"?"leaderboard":r==="versions"?"versions":"history":"editor";n.activePanel!==o&&s({type:"SET_PANEL",panel:o})},[e,r,n.activePanel,s]),null}function Rd(e,r,n,s="",o,a){var h;const i=e.origin==="installed",c=Ed(r,i),d=m=>{const g=a1(m);n==null||n(g.tab),o&&(g.mode?o(g.mode):g.view&&o(g.view))},u=t.jsx(Jb,{skill:e,onNavigate:d,repoUrl:e.homepage??null}),p=a!=null?t.jsxs(Jg,{plugin:e.plugin,skill:e.skill,origin:e.origin,children:[t.jsx(h1,{active:c,sub:s}),t.jsx(f1,{active:c,sub:s})]},`${e.plugin}/${e.skill}`):t.jsxs("div",{style:{padding:16,fontFamily:"var(--font-sans)",color:"var(--text-secondary)",fontSize:13},children:["Select a skill from the sidebar to load its ",c," view."]}),f=e.origin==="installed"&&t.jsxs("div",{"data-testid":"read-only-banner",style:{display:"flex",alignItems:"center",gap:8,padding:"8px 16px",background:"var(--surface-2)",color:"var(--text-secondary)",borderBottom:"1px solid var(--border-subtle)",fontFamily:"var(--font-sans)",fontSize:12},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{flexShrink:0,color:"var(--text-tertiary)"},children:[t.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),t.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),t.jsx("span",{style:{flex:1,minWidth:0},children:"This is an installed copy of the skill. Editing and generating tests are disabled — running author-shipped evals is allowed. Open the source skill to make changes."}),e.trackedForUpdates&&t.jsx("button",{type:"button","data-testid":"uninstall-button","aria-label":`Uninstall ${e.skill}`,onClick:()=>{typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:request-uninstall",{detail:{skill:{plugin:e.plugin,skill:e.skill,dir:e.dir??"",hasEvals:!1,hasBenchmark:!1,evalCount:0,assertionCount:0,benchmarkStatus:"missing",lastBenchmark:null,origin:"installed"}}}))},style:{flexShrink:0,marginLeft:8,padding:"3px 10px",fontSize:11,fontWeight:500,fontFamily:"var(--font-sans)",color:"var(--text-primary)",background:"transparent",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:4,cursor:"pointer"},children:"Uninstall"})]});return t.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",background:"var(--bg-canvas)"},children:[t.jsx("div",{style:{padding:16,paddingBottom:12},children:Sd({skill:e})}),t.jsx(Qb,{skill:e}),f,e.origin==="installed"&&e.scopeV2!=="available-plugin"&&t.jsx("div",{style:{padding:"8px 16px",borderBottom:"1px solid var(--border-default)"},children:t.jsx(e1,{plugin:e.plugin,skill:e.skill,trackedForUpdates:e.trackedForUpdates})}),d1(c,n,i),Rr[c]&&t.jsx(r1,{parentTabId:c,tabs:Rr[c],active:s||(((h=Rr[c][0])==null?void 0:h.id)??""),onChange:o}),t.jsx("div",{role:"tabpanel",id:`detail-panel-${c}`,"aria-labelledby":`detail-tab-${c}`,"data-testid":`detail-panel-${c}`,style:{flex:1,minHeight:0,overflow:"auto"},children:c==="overview"?u:c==="source"?t.jsx(ry,{plugin:e.plugin,skill:e.skill}):p})]})}function m1(){const{updateCount:e,state:r,dismissUpdateNotification:n}=Mt(),s=e>0&&!r.updateNotificationDismissed;return l.useEffect(()=>{if(!s)return;const o=setTimeout(()=>n(),1e4);return()=>clearTimeout(o)},[s,n]),s?t.jsxs("div",{className:"fixed bottom-4 right-4 z-50 flex items-center gap-3 px-4 py-3 rounded-lg text-[13px] font-medium animate-fade-in",style:{background:"var(--yellow-muted)",border:"1px solid var(--yellow)",color:"var(--text-primary)"},children:[t.jsxs("span",{children:[e," update",e===1?"":"s"," available"]}),t.jsx("button",{onClick:()=>{window.location.hash="#/updates"},className:"px-2 py-0.5 rounded text-[12px] font-semibold",style:{background:"var(--yellow)",color:"var(--surface-0)",border:"none",cursor:"pointer"},children:"View Updates"}),t.jsx("button",{onClick:n,className:"text-[14px] leading-none",style:{background:"transparent",border:"none",color:"var(--text-secondary)",cursor:"pointer",padding:"0 2px"},"aria-label":"Dismiss",children:"✕"})]}):null}const Td=l.createContext(null);function x1(e,r){if(!e||!r)return!1;if(e.updates.skippedVersion===r)return!0;if(!e.updates.snoozedUntil)return!1;const n=new Date(e.updates.snoozedUntil).getTime();return!Number.isNaN(n)&&n>Date.now()}function g1({children:e}){const r=pn(),n=l.useRef("unknown"),[s,o]=l.useState(null),[a,i]=l.useState("idle"),[c,d]=l.useState(null),[u,p]=l.useState({bytes:0,total:null}),[f,h]=l.useState(null),m=l.useCallback((R,k=null)=>R.available&&R.latestVersion&&!x1(k,R.latestVersion)?(o(R),i(E=>E==="ready"||E==="restarting"?E:"idle"),h(null),R):(o(null),i("idle"),h(null),null),[]),g=l.useCallback((R,k=null)=>m(pa(R,n.current),k),[m]),x=l.useCallback(async()=>{if(!r.available)return null;i(R=>R==="installing"||R==="restarting"?R:"checking"),h(null);try{const[R,k]=await Promise.all([r.getSettings().catch(()=>null),r.checkForUpdates()]);return m(k,R)}catch(R){const k=R instanceof Error?R.message:String(R);return i("error"),h(k),null}},[m,r]);l.useEffect(()=>{if(!r.available)return;let R=!1;const k=[];return r.getAppMetadata().then(E=>{n.current=E.version}).catch(()=>{}),(async()=>{const[E,C,N,I]=await Promise.all([Sn("updater://available",L=>{R||g(L.payload)}),Sn("updater://check-result",L=>{R||g(L.payload)}),Sn("updater://restart-required",L=>{R||(i("ready"),o(B=>{var T,$;return B??pa({available:!0,version:((T=L.payload)==null?void 0:T.version)??null,notes:(($=L.payload)==null?void 0:$.notes)??null},n.current)}))}),Sn("updater://error",L=>{var B;R||(i("error"),h(((B=L.payload)==null?void 0:B.message)??"Update failed."))})]);for(const L of[E,C,N,I])L&&k.push(L);const P=await r.getSettings().catch(()=>null);!R&&((P==null?void 0:P.updates.autoCheck)??!0)&&await x()})(),()=>{R=!0;for(const E of k)E()}},[g,r,x]);const v=l.useCallback(async()=>{if(!s||a==="installing"||a==="restarting")return!1;i("installing"),h(null),p({bytes:0,total:null});try{return await r.downloadAndInstallUpdate((R,k)=>{p({bytes:R,total:k})}),i("ready"),!0}catch(R){return i("error"),h(R instanceof Error?R.message:String(R)),!1}},[r,a,s]),b=l.useCallback(async()=>{if(a==="restarting")return!1;i("restarting"),h(null);try{return await r.restartApp(),!0}catch(R){return i("error"),h(R instanceof Error?R.message:String(R)),!1}},[r,a]),y=l.useCallback(async()=>{if(!s||a==="installing"||a==="restarting")return;if(a==="ready"){await b();return}await v()&&await b()},[v,a,b,s]),j=l.useCallback(()=>{d((s==null?void 0:s.latestVersion)??"unknown")},[s]),S=l.useCallback(()=>r.openPreferences("updates").catch(()=>{}),[r]),w=l.useMemo(()=>{const R=(s==null?void 0:s.latestVersion)!=null&&c===s.latestVersion;return{update:s,phase:a,progress:u,error:f,available:!!(s&&!R),dismissed:R,dismiss:j,checkNow:x,install:v,restart:b,installAndRestart:y,openDetails:S}},[s,c,a,u,f,j,x,v,b,y,S]);return t.jsx(Td.Provider,{value:w,children:e})}function Id(){const e=l.useContext(Td);if(!e)throw new Error("useAppUpdater must be used inside AppUpdaterProvider");return e}function v1(){const e=Id(),{update:r,phase:n,progress:s,error:o}=e;if(!e.available||!r)return null;const a=s.total&&s.total>0?Math.min(100,Math.round(s.bytes/s.total*100)):null;return t.jsxs("div",{"data-testid":"app-update-toast",role:"status","aria-live":"polite",className:"fixed left-1/2 top-[56px] z-50 flex w-[min(720px,calc(100vw-24px))] -translate-x-1/2 flex-col gap-2 rounded-md px-4 py-3 text-[13px] shadow-lg animate-fade-in",style:{background:"var(--bg-surface)",border:"1px solid var(--color-own)",color:"var(--text-primary)"},children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[t.jsx("span",{"data-testid":"app-update-badge",className:"mt-0.5 shrink-0 rounded px-2 py-0.5 text-[11px] font-semibold",style:{background:"var(--color-own)",color:"var(--color-paper)"},children:"Update"}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"font-semibold",children:["Skill Studio ",r.latestVersion," is available"]}),t.jsx("div",{className:"mt-1 line-clamp-3 text-[12px]",style:{color:"var(--text-secondary)"},children:n==="ready"?"Ready to restart and finish installing.":r.releaseNotes??"Install the new desktop version now."}),n==="installing"?t.jsx("div",{className:"mt-2 h-1.5 overflow-hidden rounded-full",style:{background:"var(--border-default)"},children:t.jsx("div",{className:"h-full rounded-full",style:{width:a===null?"35%":`${a}%`,background:"var(--color-own)"}})}):null,n==="error"&&o?t.jsx("div",{className:"mt-1 text-[12px]",style:{color:"var(--status-danger-text)"},children:o}):null]})]}),t.jsx("button",{type:"button","aria-label":"Dismiss app update",onClick:e.dismiss,className:"text-[14px] leading-none",style:{background:"transparent",border:"none",color:"var(--text-secondary)",cursor:"pointer",padding:"0 2px"},children:"✕"})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2",children:[t.jsx("button",{type:"button",className:"px-2 py-1 text-[12px] font-semibold",style:{background:"transparent",border:"1px solid var(--border-default)",borderRadius:4,color:"var(--text-secondary)",cursor:"pointer"},onClick:()=>{e.openDetails()},children:"Details"}),t.jsx("button",{type:"button","data-testid":n==="ready"?"app-update-restart":"app-update-install",className:"px-2 py-1 text-[12px] font-semibold",disabled:n==="installing"||n==="restarting",style:{background:"var(--color-own)",border:"1px solid var(--color-own)",borderRadius:4,color:"var(--color-paper)",cursor:n==="installing"||n==="restarting"?"not-allowed":"pointer"},onClick:()=>{n==="ready"?e.restart():e.install()},children:n==="ready"?"Restart now":n==="restarting"?"Restarting...":n==="installing"?"Installing...":"Update and install"})]})]})}function y1(){var o;const e=Id(),r=l.useMemo(()=>e.phase==="installing"?"Installing...":e.phase==="restarting"?"Restarting...":e.phase==="ready"?"Restart":e.phase==="error"?"Update failed":"Update",[e.phase]);if(!e.available&&!(e.update&&e.phase==="error"))return null;const n=e.phase==="installing"||e.phase==="restarting",s=e.error?`Update failed: ${e.error}`:(o=e.update)!=null&&o.latestVersion?`Install Skill Studio ${e.update.latestVersion} and restart`:"Install the latest Skill Studio update";return t.jsxs("button",{type:"button","data-testid":"app-update-header-button","aria-label":s,title:s,disabled:n,onClick:()=>{e.installAndRestart()},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,height:28,minWidth:76,padding:"0 12px",borderRadius:999,border:e.phase==="error"?"1px solid var(--status-danger-text)":"1px solid var(--color-own)",background:e.phase==="error"?"var(--bg-surface)":n?"var(--bg-muted)":"var(--color-own)",color:e.phase==="error"?"var(--status-danger-text)":n?"var(--text-secondary)":"var(--color-paper)",fontSize:12,fontWeight:700,fontFamily:"var(--font-sans)",cursor:n?"wait":"pointer",whiteSpace:"nowrap",boxShadow:e.phase==="error"?"none":"0 1px 2px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.12)"},children:[t.jsx("span",{"aria-hidden":"true",style:{width:7,height:7,borderRadius:999,background:"currentColor",opacity:e.phase==="installing"||e.phase==="restarting"?.55:1}}),r]})}const b1=[{name:_.shortcuts.groupNavigation,items:[{keys:"/",label:_.shortcuts.search},{keys:"j",label:_.shortcuts.moveDown},{keys:"k",label:_.shortcuts.moveUp},{keys:"Enter",label:_.shortcuts.openSelected},{keys:"Esc",label:"Close / clear"}]},{name:_.shortcuts.groupActions,items:[{keys:"⌘K",label:_.shortcuts.openPalette},{keys:"?",label:_.shortcuts.openShortcuts},{keys:"⌘B",label:_.shortcuts.toggleSidebar},{keys:"E",label:_.actions.edit}]},{name:_.shortcuts.groupTheme,items:[{keys:"⌘⇧D",label:_.shortcuts.toggleTheme}]}];function k1({open:e,onClose:r,groups:n=b1,title:s=_.shortcuts.title}){const o=l.useRef(null),a=l.useRef(null);return l.useEffect(()=>{var i;if(e)return o.current=document.activeElement??null,(i=a.current)==null||i.focus(),()=>{var c,d;(d=(c=o.current)==null?void 0:c.focus)==null||d.call(c),o.current=null}},[e]),l.useEffect(()=>{if(!e)return;function i(c){var d;if(c.key==="Escape"){c.preventDefault(),r();return}c.key==="Tab"&&(c.preventDefault(),(d=a.current)==null||d.focus())}return window.addEventListener("keydown",i,!0),()=>window.removeEventListener("keydown",i,!0)},[e,r]),e?t.jsx("div",{role:"presentation","data-testid":"shortcut-modal",style:{position:"fixed",inset:0,background:"color-mix(in srgb, var(--bg-canvas) 70%, transparent)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:60},onClick:i=>{i.target===i.currentTarget&&r()},children:t.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"shortcut-modal-title",style:{width:"min(480px, 92vw)",maxHeight:"80vh",overflow:"auto",background:"var(--bg-canvas)",border:"1px solid var(--border-default)",borderRadius:8,boxShadow:"0 16px 48px rgba(0,0,0,0.18)",padding:"16px 20px",fontFamily:"var(--font-sans)",color:"var(--text-primary)"},children:[t.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:12},children:[t.jsx("h2",{id:"shortcut-modal-title",style:{margin:0,fontFamily:"var(--font-serif)",fontWeight:500,fontSize:18},children:s}),t.jsx("button",{ref:a,type:"button","aria-label":"Close",onClick:r,style:{background:"transparent",border:"1px solid var(--border-default)",borderRadius:4,padding:"2px 8px",color:"var(--text-secondary)",cursor:"pointer",fontSize:13},children:"Esc"})]}),n.map(i=>t.jsxs("section",{style:{marginBottom:12},children:[t.jsx("h3",{style:{fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.08em",color:"var(--text-secondary)",margin:"0 0 6px"},children:i.name}),t.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:i.items.map(c=>t.jsxs("li",{style:{display:"flex",justifyContent:"space-between",padding:"4px 0",borderTop:"1px solid var(--border-default)",fontSize:13},children:[t.jsx("span",{children:c.label}),t.jsx("kbd",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-secondary)",border:"1px solid var(--border-default)",borderRadius:3,padding:"1px 6px"},children:c.keys})]},`${i.name}:${c.keys}`))})]},i.name))]})}):null}function j1(e){const r=_.actions,n=[{action:"open",label:r.open},{action:"copy-path",label:r.copyPath},{action:"reveal",label:r.revealInEditor},{action:"run-benchmark",label:r.runBenchmark}];if(e.origin==="source")return[...n,{action:"edit",label:r.edit},{action:"duplicate",label:r.duplicate},{action:"delete",label:r.delete}];const s=[...n];return s.push({action:"clone",label:r.cloneToAuthoring}),e.updateAvailable&&s.push({action:"update",label:r.update}),s.push({action:"uninstall",label:r.uninstall}),s.push({action:"delete",label:r.delete,disabled:!0,title:r.deletePluginTooltip}),s}function w1({state:e,onClose:r,onAction:n,itemsOverride:s}){const o=l.useRef(null),a=l.useRef(null),[i,c]=l.useState(0),d=l.useMemo(()=>e.skill?s??j1(e.skill):[],[e.skill,s]),u=l.useMemo(()=>{if(typeof window>"u")return{left:e.x,top:e.y};const f=8,h=220,m=44+d.length*28;let g=e.x,x=e.y;return g+h+f>window.innerWidth&&(g=Math.max(f,e.x-h)),x+m+f>window.innerHeight&&(x=Math.max(f,e.y-m)),{left:g,top:x}},[e.x,e.y,d.length]);l.useEffect(()=>{if(e.open)return a.current=document.activeElement??null,c(0),requestAnimationFrame(()=>{var f;(f=o.current)==null||f.focus()}),()=>{var f,h;(h=(f=a.current)==null?void 0:f.focus)==null||h.call(f),a.current=null}},[e.open]);const p=l.useCallback(()=>{if(!e.skill)return;const f=d[i];!f||f.disabled||(n(f.action,e.skill),r())},[d,i,e.skill,n,r]);return l.useEffect(()=>{if(!e.open)return;function f(m){if(m.key==="Escape"){m.preventDefault(),r();return}if(m.key==="ArrowDown"){m.preventDefault(),c(g=>Math.min(g+1,Math.max(d.length-1,0)));return}if(m.key==="ArrowUp"){m.preventDefault(),c(g=>Math.max(g-1,0));return}if(m.key==="Enter"||m.key===" "){m.preventDefault(),p();return}}function h(m){o.current&&m.target instanceof Node&&(o.current.contains(m.target)||r())}return window.addEventListener("keydown",f,!0),window.addEventListener("mousedown",h,!0),()=>{window.removeEventListener("keydown",f,!0),window.removeEventListener("mousedown",h,!0)}},[e.open,r,d.length,p]),!e.open||!e.skill?null:t.jsx("div",{ref:o,role:"menu",tabIndex:-1,"data-testid":"context-menu",style:{position:"fixed",left:u.left,top:u.top,zIndex:70,minWidth:200,padding:4,background:"var(--bg-canvas)",border:"1px solid var(--border-default)",borderRadius:6,boxShadow:"0 12px 32px rgba(0,0,0,0.16)",fontFamily:"var(--font-sans)",fontSize:13,color:"var(--text-primary)",outline:"none"},children:d.map((f,h)=>t.jsx("div",{role:"menuitem","aria-disabled":f.disabled||void 0,title:f.title||void 0,"data-action":f.action,"data-selected":h===i||void 0,onMouseEnter:()=>c(h),onClick:()=>{f.disabled||(n(f.action,e.skill),r())},style:{padding:"5px 10px",borderRadius:4,cursor:f.disabled?"default":"pointer",opacity:f.disabled?.5:1,background:h===i?"color-mix(in srgb, var(--accent-surface) 10%, transparent)":"transparent"},children:f.label},f.action))})}const S1=/^[a-z][a-z0-9-]{0,62}[a-z0-9]$/;function C1(e){const{skill:r,onCloned:n,onCancel:s}=e,[o,a]=l.useState({target:"standalone",plugin:"",pluginName:""}),[i,c]=l.useState(!1),[d,u]=l.useState(null),p=l.useRef(null),f=l.useRef(null),h=l.useRef(null);l.useEffect(()=>(h.current=document.activeElement??null,requestAnimationFrame(()=>{var x;return(x=f.current)==null?void 0:x.focus()}),()=>{var x,v;(v=(x=h.current)==null?void 0:x.focus)==null||v.call(x),h.current=null}),[]),l.useEffect(()=>{function x(v){v.key==="Escape"&&(v.stopPropagation(),s())}return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[s]);const m=i||o.target==="plugin"&&!o.plugin.trim()||o.target==="new-plugin"&&!S1.test(o.pluginName.trim()),g=l.useCallback(async x=>{if(x.preventDefault(),!m){c(!0),u(null);try{const v={source:r.skill,sourcePlugin:r.plugin,target:o.target};o.target==="plugin"&&(v.plugin=o.plugin.trim()),o.target==="new-plugin"&&(v.pluginName=o.pluginName.trim());const b=await fetch("/api/skills/clone",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)}),y=await b.json().catch(()=>({}));if(!b.ok||!y.ok){u(y.message||y.error||`HTTP ${b.status}`);return}n({target:y.target??"",files:y.files??null})}catch(v){u(v.message??"Network error")}finally{c(!1)}}},[m,o,r,n]);return t.jsx("div",{role:"dialog","aria-modal":"true","aria-labelledby":"clone-dialog-title",ref:p,"data-testid":"clone-to-authoring-dialog",style:E1,onClick:x=>{x.target===x.currentTarget&&s()},children:t.jsxs("form",{onSubmit:g,style:N1,children:[t.jsx("h2",{id:"clone-dialog-title",style:R1,children:"Clone to authoring"}),t.jsxs("p",{style:T1,children:["Fork ",t.jsx("code",{style:Oi,children:r.skill})," into the authoring scope so you can edit it."]}),t.jsxs("fieldset",{style:I1,children:[t.jsx("legend",{style:L1,children:"Target"}),t.jsxs("label",{style:Us,children:[t.jsx("input",{type:"radio",name:"target",value:"standalone",checked:o.target==="standalone",onChange:()=>a(x=>({...x,target:"standalone"})),"data-testid":"clone-target-standalone"}),t.jsxs("span",{style:Vs,children:[t.jsx("strong",{children:"Standalone"}),t.jsxs("span",{style:Gs,children:["Lands at ",t.jsxs("code",{style:Oi,children:["skills/",r.skill,"-fork/"]})]})]})]}),t.jsxs("label",{style:Us,children:[t.jsx("input",{type:"radio",name:"target",value:"plugin",checked:o.target==="plugin",onChange:()=>a(x=>({...x,target:"plugin"})),"data-testid":"clone-target-plugin"}),t.jsxs("span",{style:Vs,children:[t.jsx("strong",{children:"Add to existing plugin"}),t.jsx("span",{style:Gs,children:"Lands inside a plugin you already author."})]})]}),o.target==="plugin"&&t.jsx("input",{type:"text",placeholder:"plugin name or path",value:o.plugin,onChange:x=>a(v=>({...v,plugin:x.target.value})),"data-testid":"clone-plugin-input",autoFocus:!0,style:_i}),t.jsxs("label",{style:Us,children:[t.jsx("input",{type:"radio",name:"target",value:"new-plugin",checked:o.target==="new-plugin",onChange:()=>a(x=>({...x,target:"new-plugin"})),"data-testid":"clone-target-new-plugin"}),t.jsxs("span",{style:Vs,children:[t.jsx("strong",{children:"Create new plugin"}),t.jsx("span",{style:Gs,children:"Scaffolds a fresh plugin folder with this skill inside."})]})]}),o.target==="new-plugin"&&t.jsx("input",{type:"text",placeholder:"plugin-name (kebab-case)",value:o.pluginName,onChange:x=>a(v=>({...v,pluginName:x.target.value})),"data-testid":"clone-new-plugin-name-input",autoFocus:!0,style:_i})]}),d&&t.jsx("div",{role:"alert",style:A1,"data-testid":"clone-error",children:d}),t.jsxs("div",{style:P1,children:[t.jsx("button",{type:"button",ref:f,onClick:s,disabled:i,style:$1,"data-testid":"clone-cancel",children:"Cancel"}),t.jsx("button",{type:"submit",disabled:m,style:M1,"data-testid":"clone-submit",children:i?"Cloning…":"Clone"})]})]})})}const E1={position:"fixed",inset:0,background:"rgba(0,0,0,0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3},N1={background:"var(--bg, #fff)",color:"var(--text, #111)",borderRadius:12,padding:"24px 28px",minWidth:460,maxWidth:560,boxShadow:"0 24px 60px rgba(0,0,0,0.5)",border:"1px solid var(--border, rgba(0,0,0,0.10))"},R1={fontSize:18,fontWeight:700,margin:0},T1={margin:"12px 0 18px",fontSize:14,color:"var(--text-muted, #555)"},I1={border:"none",padding:0,margin:"0 0 16px"},L1={fontSize:12,fontWeight:600,textTransform:"uppercase",letterSpacing:1.2,color:"var(--text-muted, #555)",padding:0,marginBottom:10},Us={display:"flex",alignItems:"flex-start",gap:10,padding:"10px 4px",cursor:"pointer",borderRadius:6},Vs={display:"flex",flexDirection:"column",gap:2,fontSize:14},Gs={fontSize:12,color:"var(--text-muted, #777)"},_i={display:"block",width:"100%",padding:"8px 12px",margin:"4px 0 8px 28px",maxWidth:380,fontSize:14,borderRadius:6,border:"1px solid var(--border, rgba(0,0,0,0.20))",background:"var(--bg, #fff)",color:"var(--text, #111)",fontFamily:"var(--font-geist-mono, monospace)"},Oi={fontFamily:"var(--font-geist-mono, monospace)",fontSize:13,padding:"1px 6px",borderRadius:4,background:"rgba(127,127,127,0.12)"},A1={fontSize:13,color:"#c62828",background:"rgba(198,40,40,0.10)",border:"1px solid rgba(198,40,40,0.40)",padding:"8px 12px",borderRadius:6,margin:"0 0 12px"},P1={display:"flex",justifyContent:"flex-end",gap:8,marginTop:8},$1={padding:"8px 16px",borderRadius:6,border:"1px solid var(--border, rgba(0,0,0,0.20))",background:"transparent",color:"var(--text, #111)",cursor:"pointer",fontSize:14},M1={padding:"8px 16px",borderRadius:6,border:"1px solid var(--accent, #06b6d4)",background:"var(--accent, #06b6d4)",color:"#fff",cursor:"pointer",fontSize:14,fontWeight:600},Wi=e=>`${e.plugin}/${e.skill}`;function Hi(e){const r=(e==null?void 0:e.delayMs)??1e4,n=e==null?void 0:e.onCommit,s=e==null?void 0:e.onFailure,o=(e==null?void 0:e.apiCall)??ie.deleteSkill.bind(ie),a=l.useRef(n),i=l.useRef(s),c=l.useRef(o);a.current=n,i.current=s,c.current=o;const d=l.useRef(new Map),[,u]=l.useState(0),p=l.useCallback(()=>u(y=>y+1),[]),f=l.useCallback(async y=>{var j,S;try{await c.current(y.skill.plugin,y.skill.skill),(j=a.current)==null||j.call(a,y.skill)}catch(w){(S=i.current)==null||S.call(i,y.skill,w)}finally{d.current.delete(Wi(y.skill)),p()}},[p]),h=l.useCallback(y=>{const j=Wi(y),S=d.current.get(j);S!=null&&S.timeoutId&&clearTimeout(S.timeoutId);const w={skill:y,timeoutId:null};w.timeoutId=setTimeout(()=>{w.timeoutId=null,f(w)},r),d.current.set(j,w),p()},[r,f,p]),m=l.useCallback(y=>{const j=d.current.get(y);j&&(j.timeoutId&&clearTimeout(j.timeoutId),d.current.delete(y),p())},[p]),g=l.useCallback(async()=>{const y=Array.from(d.current.values());for(const j of y)j.timeoutId&&(clearTimeout(j.timeoutId),j.timeoutId=null);await Promise.all(y.map(j=>f(j)))},[f]),x=l.useCallback(y=>d.current.has(y),[]),v=l.useCallback(async y=>{const j=d.current.get(y);j&&(j.timeoutId&&(clearTimeout(j.timeoutId),j.timeoutId=null),await f(j))},[f]),b=l.useCallback(async y=>{const j=Array.from(d.current.values()).filter(S=>S.skill.skill===y);for(const S of j)S.timeoutId&&(clearTimeout(S.timeoutId),S.timeoutId=null);await Promise.all(j.map(S=>f(S)))},[f]);return l.useEffect(()=>{const y=()=>{g()};return window.addEventListener("beforeunload",y),()=>{window.removeEventListener("beforeunload",y)}},[g]),l.useEffect(()=>{const y=d.current;return()=>{for(const j of y.values())j.timeoutId&&(clearTimeout(j.timeoutId),j.timeoutId=null,f(j));y.clear()}},[]),{enqueueDelete:h,cancelDelete:m,flushPending:g,isPending:x,flushKey:v,flushBySkillName:b}}const D1={"anthropic-api":{name:_.setupProviders.anthropic.name,description:_.setupProviders.anthropic.description,envVars:_.setupProviders.anthropic.envVars,keyUrl:_.setupProviders.anthropic.keyUrl,learnMoreUrl:_.setupProviders.anthropic.learnMoreUrl},openai:{name:_.setupProviders.openai.name,description:_.setupProviders.openai.description,envVars:_.setupProviders.openai.envVars,keyUrl:_.setupProviders.openai.keyUrl,learnMoreUrl:_.setupProviders.openai.learnMoreUrl},openrouter:{name:_.setupProviders.openrouter.name,description:_.setupProviders.openrouter.description,envVars:_.setupProviders.openrouter.envVars,keyUrl:_.setupProviders.openrouter.keyUrl,learnMoreUrl:_.setupProviders.openrouter.learnMoreUrl},gemini:{name:_.setupProviders.gemini.name,description:_.setupProviders.gemini.description,envVars:_.setupProviders.gemini.envVars,keyUrl:_.setupProviders.gemini.keyUrl,learnMoreUrl:_.setupProviders.gemini.learnMoreUrl},ollama:{name:_.setupProviders.ollama.name,description:_.setupProviders.ollama.description,envVars:_.setupProviders.ollama.envVars,install:[_.setupProviders.ollama.installCmd],start:[_.setupProviders.ollama.startCmd],pullExample:_.setupProviders.ollama.pullExample,learnMoreUrl:_.setupProviders.ollama.learnMoreUrl},"lm-studio":{name:_.setupProviders.lmStudio.name,description:_.setupProviders.lmStudio.description,envVars:_.setupProviders.lmStudio.envVars,install:[_.setupProviders.lmStudio.installCmd],start:[_.setupProviders.lmStudio.startCmd],pullExample:_.setupProviders.lmStudio.pullExample,learnMoreUrl:_.setupProviders.lmStudio.learnMoreUrl},"claude-code":{name:_.setupProviders.claudeCode.name,description:_.setupProviders.claudeCode.description,envVars:[],notes:[_.setupProviders.claudeCode.loginHint,_.claudeCodeLabel.compactLabel],learnMoreUrl:_.setupProviders.claudeCode.learnMoreUrl}};function F1(e){return e?D1[e]??null:null}function z1({open:e,providerKey:r,onClose:n}){const s=l.useRef(null);if(l.useEffect(()=>{if(!e)return;const i=c=>{c.key==="Escape"&&(c.preventDefault(),n())};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[e,n]),l.useEffect(()=>{if(!e)return;const i=s.current;if(!i)return;const c=i.querySelector("button, a[href], [tabindex]:not([tabindex='-1']), input, textarea, select");c==null||c.focus()},[e]),!e||typeof document>"u")return null;const o=F1(r),a=(o==null?void 0:o.name)??_.setupDrawer.fallbackTitle;return $r.createPortal(t.jsxs(t.Fragment,{children:[t.jsx("div",{"data-testid":"setup-drawer-backdrop","aria-hidden":"true",onClick:n,style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.4)",zIndex:99,animation:"vskillDrawerBackdropIn 120ms ease"}}),t.jsxs("div",{"data-testid":"setup-drawer",ref:s,role:"dialog","aria-modal":"true","aria-label":_.setupDrawer.title(a),style:{position:"fixed",top:0,right:0,bottom:0,width:"480px",maxWidth:"100vw",background:"var(--bg-surface, var(--surface-1))",borderLeft:"1px solid var(--border-default, var(--border-subtle))",boxShadow:"-8px 0 32px rgba(0,0,0,0.18)",display:"flex",flexDirection:"column",zIndex:100,fontFamily:"var(--font-sans)",animation:"vskillDrawerIn 200ms cubic-bezier(0.2, 0, 0, 1)"},children:[t.jsx(B1,{title:a,onClose:n}),t.jsx("div",{"data-testid":"setup-drawer-body",style:{flex:1,overflowY:"auto",padding:"16px 20px"},children:o?t.jsx(_1,{content:o}):t.jsx(O1,{})}),t.jsx("style",{children:`@keyframes vskillDrawerIn {
67
+ from { transform: translateX(100%); }
68
+ to { transform: translateX(0); }
69
+ }
70
+ @keyframes vskillDrawerBackdropIn {
71
+ from { opacity: 0; }
72
+ to { opacity: 1; }
73
+ }`})]})]}),document.body)}function B1({title:e,onClose:r}){return t.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"14px 20px",borderBottom:"1px solid var(--border-default, var(--border-subtle))"},children:[t.jsx("h2",{style:{fontFamily:"var(--font-serif)",fontSize:18,fontWeight:500,margin:0,color:"var(--text-primary)"},children:_.setupDrawer.title(e)}),t.jsx("button",{type:"button","data-testid":"setup-drawer-close",onClick:r,"aria-label":_.setupDrawer.close,style:{background:"transparent",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:18,padding:4,lineHeight:1},children:"×"})]})}function _1({content:e}){var r,n;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[t.jsx("p",{style:{fontSize:14,lineHeight:1.5,color:"var(--text-primary)",margin:0},children:e.description}),e.notes&&e.notes.length>0&&t.jsx("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:6},children:e.notes.map(s=>t.jsx("li",{style:{fontSize:13,color:"var(--text-secondary)",padding:"8px 10px",background:"color-mix(in srgb, var(--accent-surface) 8%, transparent)",borderRadius:4},children:s},s))}),e.envVars.length>0&&t.jsxs("section",{children:[t.jsx("h3",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-secondary)",margin:"0 0 8px"},children:_.setupDrawer.requiredEnv}),t.jsx("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:6},children:e.envVars.map(s=>t.jsx("li",{children:t.jsx(W1,{name:s})},s))})]}),e.keyUrl&&t.jsx(H1,{href:e.keyUrl,label:_.setupDrawer.getKey,testId:"setup-drawer-get-key"}),(e.install||e.start||e.pullExample)&&t.jsxs("section",{children:[t.jsx("h3",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-secondary)",margin:"0 0 8px"},children:_.setupDrawer.installRun}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(r=e.install)==null?void 0:r.map((s,o)=>t.jsx(Ks,{code:s},`install-${o}`)),(n=e.start)==null?void 0:n.map((s,o)=>t.jsx(Ks,{code:s},`start-${o}`)),e.pullExample&&t.jsx(Ks,{code:e.pullExample})]})]}),t.jsx("footer",{style:{marginTop:8},children:t.jsxs("a",{href:e.learnMoreUrl,target:"_blank",rel:"noopener noreferrer","data-testid":"setup-drawer-learn-more",style:{fontSize:12,color:"var(--color-accent, var(--accent-surface))",textDecoration:"none"},children:[_.setupDrawer.learnMore," →"]})})]})}function O1(){return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsx("h3",{style:{margin:0,fontFamily:"var(--font-serif)",fontSize:16,fontWeight:500,color:"var(--text-primary)"},children:_.setupDrawer.fallbackTitle}),t.jsx("p",{style:{margin:0,fontSize:13,color:"var(--text-secondary)",lineHeight:1.5},children:_.setupDrawer.fallbackBody})]})}function W1({name:e}){const r=async()=>{var n;try{await((n=navigator.clipboard)==null?void 0:n.writeText(e))}catch{}};return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"6px 8px",background:"color-mix(in srgb, var(--border-default) 30%, transparent)",borderRadius:4},children:[t.jsx("code",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-primary)",flex:1},children:e}),t.jsx("button",{type:"button",onClick:r,"aria-label":`Copy ${e} to clipboard`,style:{background:"transparent",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:3,padding:"2px 8px",color:"var(--text-secondary)",fontSize:11,fontFamily:"var(--font-sans)",cursor:"pointer"},children:_.setupDrawer.copy})]})}function Ks({code:e}){return t.jsx("pre",{style:{margin:0,padding:"8px 10px",background:"var(--bg-canvas, #111)",color:"var(--text-primary)",fontFamily:"var(--font-mono)",fontSize:11.5,lineHeight:1.5,borderRadius:4,border:"1px solid var(--border-default, var(--border-subtle))",overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:e})}function H1({href:e,label:r,testId:n}){return t.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer","data-testid":n,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,padding:"8px 14px",borderRadius:6,border:"1px solid var(--border-default, var(--border-subtle))",background:"color-mix(in srgb, var(--accent-surface) 12%, transparent)",color:"var(--text-primary)",textDecoration:"none",fontSize:13,fontWeight:500,fontFamily:"var(--font-sans)",width:"fit-content"},children:[r," →"]})}function U1(){const[e,r]=l.useState(!1),[n,s]=l.useState(null),o=l.useRef(null),a=l.useCallback((c,d)=>{var u;o.current=typeof document<"u"?document.activeElement:null,(u=d==null?void 0:d.beforeOpen)==null||u.call(d),s(c),r(!0)},[]),i=l.useCallback(()=>{r(!1);const c=o.current;c&&"focus"in c&&typeof c.focus=="function"&&queueMicrotask(()=>c.focus())},[]);return l.useMemo(()=>({open:a,close:i,isOpen:e,providerKey:n}),[a,i,e,n])}function V1(e){return(e instanceof DOMException||e instanceof Error)&&e.name==="AbortError"}function G1(e){let r="message";const n=[];for(const s of e.split(`
74
+ `)){if(!s||s.startsWith(":"))continue;const o=s.indexOf(":"),a=o===-1?s:s.slice(0,o),i=o===-1?"":s.slice(o+1),c=i.startsWith(" ")?i.slice(1):i;a==="event"?r=c||"message":a==="data"&&n.push(c)}return n.length===0?null:{event:r,data:n.join(`
75
+ `)}}function Ui(e,r){let n=e.replace(/\r\n/g,`
76
+ `).replace(/\r/g,`
77
+ `),s=n.indexOf(`
78
+
79
+ `);for(;s!==-1;){const o=n.slice(0,s);n=n.slice(s+2);const a=G1(o);a&&r(a),s=n.indexOf(`
80
+
81
+ `)}return n}function K1(e,r){const n=r.fetchImpl??fetch,s=new AbortController;let o=!1;const a=()=>{o||(o=!0,clearTimeout(i),s.abort())},i=setTimeout(()=>{var d;if(o)return;const c=new Error(r.timeoutMessage??"SSE stream timed out");a(),(d=r.onError)==null||d.call(r,c)},r.timeoutMs??2e5);return(async()=>{var c;try{const d=await n(e,{headers:{Accept:"text/event-stream"},signal:s.signal});if(!d.ok){const m=d.statusText?` ${d.statusText}`:"";throw new Error(`SSE stream failed: HTTP ${d.status}${m}`)}if(!d.body)throw new Error("SSE stream failed: response body is empty");const u=d.body.getReader(),p=new TextDecoder;let f="";for(;;){const{done:m,value:g}=await u.read();if(m)break;f=Ui(f+p.decode(g,{stream:!0}),r.onEvent)}const h=p.decode();(h||f)&&Ui(`${f}${h}
82
+
83
+ `,r.onEvent),clearTimeout(i),o=!0}catch(d){if(clearTimeout(i),o&&V1(d))return;o=!0,(c=r.onError)==null||c.call(r,d instanceof Error?d:new Error(String(d)))}})(),{close:a}}function oa(e){return(e==null?void 0:e.fetchImpl)??fetch}async function Ld(e){const n=await oa(e)("/api/studio/supported-agents",{headers:{Accept:"application/json"}});if(!n.ok)throw new Error(`fetchSupportedAgents failed: HTTP ${n.status}`);const s=await n.json();return Array.isArray(s==null?void 0:s.agents)?s.agents:[]}async function q1(e,r){const s=await oa(r)("/api/studio/install-skill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!s.ok){const a=await s.json().catch(()=>({}));throw new Error(a.error||`install-skill failed: HTTP ${s.status}`)}const o=await s.json();if(!o.jobId)throw new Error("install-skill: server did not return a jobId");return{jobId:o.jobId,...typeof o.streamPath=="string"&&o.streamPath.startsWith("/")?{streamPath:o.streamPath}:{},...typeof o.mode=="string"?{mode:o.mode}:{}}}function Y1(e,r,n){const s=oa(n),o=e.startsWith("/")?e:`/api/studio/install-skill/${encodeURIComponent(e)}/stream`;let a;return a=K1(o,{fetchImpl:s,timeoutMessage:"install-skill SSE stream timed out",onEvent:({event:i,data:c})=>{var d;if(i==="result"){try{const u=JSON.parse(c);r.onResult(u)}catch(u){(d=r.onError)==null||d.call(r,u instanceof Error?u:new Error(String(u)))}return}if(i==="done"){let u={results:[]};try{u=JSON.parse(c)}catch{}a.close(),r.onDone(u)}},onError:i=>{var c;return(c=r.onError)==null?void 0:c.call(r,i)}}),a}function J1(e){const r=[],n=[],s=[];for(const a of e)a.installMode==="clipboard"?s.push(a):a.detected?r.push(a):n.push(a);const o=(a,i)=>a.displayName.localeCompare(i.displayName);return{detected:r.sort(o),available:n.sort(o),cloud:s.sort(o)}}function X1(e){const r=[],n=[],s=[];for(const a of e)a.tier===1&&a.installMode==="filesystem"?r.push(a):a.tier===2&&a.installMode==="filesystem"?n.push(a):a.tier===3||a.installMode==="clipboard"?s.push(a):r.push(a);const o=(a,i)=>a.detected!==i.detected?a.detected?-1:1:a.displayName.localeCompare(i.displayName);return{dropIn:r.sort(o),formatConverted:n.sort(o),cloud:s.sort(o)}}function Q1(e){const r=[],n=[],s=new Set;for(const o of e){if(o.presence==="absent"||o.health==="missing"){n.push({kind:"individual",key:o.id,agent:o});continue}if(o.sharedFolderGroup&&o.sharedFolderGroup.length>1){const a=[...o.sharedFolderGroup].sort().join("+");if(s.has(a))continue;s.add(a);const i=e.filter(c=>o.sharedFolderGroup.includes(c.id));r.push({kind:"aggregate",key:`shared:${a}`,consumers:i,sharedFolderPath:o.sharedFolderPath??"~/.config/agents/skills",combinedCount:i.reduce((c,d)=>c+d.globalCount,0)});continue}r.push({kind:"individual",key:o.id,agent:o})}return{detected:r,notDetected:n}}function Z1({agents:e,activeAgentId:r,focusedAgentId:n,onFocusAgent:s,onSwitch:o,onOpenSetup:a,onClose:i,groupBy:c="presence",onRequestInstall:d,fetchSupportedAgentsImpl:u}){const p=l.useRef(null);l.useEffect(()=>{const b=y=>{y.key==="Escape"&&(y.preventDefault(),i())};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[i]),l.useEffect(()=>{const b=j=>{p.current&&!p.current.contains(j.target)&&i()},y=setTimeout(()=>{document.addEventListener("mousedown",b)},0);return()=>{clearTimeout(y),document.removeEventListener("mousedown",b)}},[i]);const f=l.useMemo(()=>Q1(e),[e]),[h,m]=l.useState(null),[g,x]=l.useState(null);l.useEffect(()=>{if(c!=="installMode")return;let b=!1;return(u??Ld)().then(j=>{b||m(j)}).catch(j=>{b||x(j instanceof Error?j.message:String(j))}),()=>{b=!0}},[c,u]);const v=e.find(b=>b.id===n)??e.find(b=>b.id===r)??e[0];return typeof document>"u"?null:$r.createPortal(t.jsxs("div",{ref:p,"data-testid":"agent-scope-picker-popover","data-group-by":c,role:"dialog","aria-label":_.scopePicker.popoverTitle,style:{position:"fixed",top:96,left:"50%",transform:"translateX(-50%)",width:600,maxWidth:"calc(100vw - 32px)",background:"var(--bg-surface, var(--surface-1))",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:8,boxShadow:"0 18px 40px rgba(0,0,0,0.25)",overflow:"hidden",zIndex:90,animation:"scopePickerFadeIn 120ms cubic-bezier(0.2, 0, 0, 1)"},children:[t.jsxs("div",{style:{display:"flex",height:360,maxHeight:"60vh"},children:[t.jsx("section",{"data-testid":"agent-scope-picker-agents",style:{width:260,borderRight:"1px solid var(--border-default, var(--border-subtle))",overflowY:"auto",padding:"6px 0"},children:c==="installMode"?t.jsx(t0,{supported:h,error:g,focusedAgentId:n,activeAgentId:r,onFocus:s,onRequestInstall:d}):t.jsx(e0,{rows:f,activeAgentId:r,focusedAgentId:n,onFocus:s})}),t.jsx("section",{"data-testid":"agent-scope-picker-stats",style:{flex:1,overflowY:"auto",padding:"14px 16px"},children:v?t.jsx(o0,{agent:v,activeAgentId:r,onSwitch:()=>o(v.id)}):t.jsx(Ad,{})})]}),t.jsx("style",{children:`@keyframes scopePickerFadeIn {
84
+ from { opacity: 0; transform: translateX(-50%) translateY(2px); }
85
+ to { opacity: 1; transform: translateX(-50%) translateY(0); }
86
+ }`})]}),document.body)}function e0({rows:e,activeAgentId:r,focusedAgentId:n,onFocus:s}){return e.detected.length===0&&e.notDetected.length===0?t.jsx(Ad,{}):t.jsxs(t.Fragment,{children:[e.detected.map(o=>o.kind==="aggregate"?t.jsx(n0,{row:o,onFocus:()=>{var a;return s(((a=o.consumers[0])==null?void 0:a.id)??r??"")}},o.key):t.jsx(r0,{agent:o.agent,focused:o.agent.id===n,active:o.agent.id===r,onClick:()=>s(o.agent.id)},o.key)),e.notDetected.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{"data-testid":"agent-scope-not-detected-subheading",title:"These agents were not found on this machine. Hover a row to see which folder detection looked for.",style:{padding:"10px 14px 4px",fontSize:10,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-tertiary)"},children:_.scopePicker.notDetectedSubheading}),e.notDetected.map(o=>t.jsx(s0,{agent:o.agent},o.key))]})]})}function t0({supported:e,error:r,focusedAgentId:n,activeAgentId:s,onFocus:o,onRequestInstall:a}){if(r)return t.jsxs("div",{"data-testid":"agent-scope-supported-error",style:{padding:"16px 18px",fontSize:12,color:"var(--color-error, #dc2626)"},children:["Failed to load supported agents: ",r]});if(e===null)return t.jsx("div",{"data-testid":"agent-scope-supported-loading",style:{padding:"16px 18px",fontSize:12,color:"var(--text-secondary)"},children:"Loading agents…"});const i=J1(e);return t.jsxs(t.Fragment,{children:[t.jsx(qs,{testId:"agent-scope-section-detected",title:"Detected on this machine",agents:i.detected,emptyHint:"No agents detected on this machine yet.",renderRow:c=>t.jsx(Ys,{agent:c,focused:c.id===n,active:c.id===s,onClick:()=>o(c.id),kind:"detected"},c.id)}),t.jsx(qs,{testId:"agent-scope-section-available",title:"Available to install",agents:i.available,emptyHint:"All supported agents are detected — nothing left to install here.",renderRow:c=>t.jsx(Ys,{agent:c,focused:c.id===n,active:!1,onClick:()=>o(c.id),kind:"available",onRequestInstall:a},c.id)}),t.jsx(qs,{testId:"agent-scope-section-cloud",title:"Cloud only (paste required)",agents:i.cloud,emptyHint:"No cloud-only tools available.",renderRow:c=>t.jsx(Ys,{agent:c,focused:c.id===n,active:!1,onClick:()=>o(c.id),kind:"cloud",onRequestInstall:a},c.id)})]})}function qs({testId:e,title:r,agents:n,emptyHint:s,renderRow:o}){return t.jsxs("div",{"data-testid":e,children:[t.jsx("div",{style:{padding:"10px 14px 4px",fontSize:10,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--text-tertiary)"},children:r}),n.length===0?t.jsx("div",{style:{padding:"4px 14px 8px",fontSize:11,color:"var(--text-tertiary)",fontStyle:"italic"},children:s}):n.map(o)]})}function Ys({agent:e,focused:r,active:n,onClick:s,kind:o,onRequestInstall:a}){const i=o==="detected"?"var(--color-ok, #22c55e)":o==="available"?"var(--color-own, #f59e0b)":"var(--text-tertiary)",c=o==="cloud"?"Copy to clipboard":e.resolvedGlobalDir;return t.jsxs("div",{"data-testid":`agent-scope-supported-row-${e.id}`,"data-kind":o,"data-detected":e.detected?"true":"false",style:{display:"flex",flexDirection:"column",gap:2,padding:"6px 14px",background:r?"color-mix(in srgb, var(--accent-surface) 10%, transparent)":"transparent"},children:[t.jsxs("button",{type:"button",onClick:s,"data-testid":`agent-scope-supported-row-button-${e.id}`,"data-active":n?"true":"false",style:{display:"flex",alignItems:"center",gap:10,width:"100%",background:"transparent",border:"none",cursor:"pointer",textAlign:"left",padding:0,fontFamily:"var(--font-sans)",color:"var(--text-primary)"},children:[t.jsx("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:i,flexShrink:0}}),t.jsx("span",{style:{flex:1,fontSize:13},children:e.displayName}),t.jsxs("span",{title:"Install tier",style:{fontFamily:"var(--font-mono)",fontSize:9,color:"var(--text-secondary)",letterSpacing:"0.04em",textTransform:"uppercase"},children:["T",e.tier]})]}),t.jsx("div",{title:c,style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-tertiary)",paddingLeft:16,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c}),o==="available"&&a&&t.jsx("button",{type:"button","data-testid":`agent-scope-install-cta-${e.id}`,onClick:d=>{d.stopPropagation(),a(e.id)},style:{alignSelf:"flex-start",marginLeft:16,marginTop:2,padding:"2px 8px",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:4,background:"transparent",color:"var(--accent-text, var(--text-primary))",cursor:"pointer",fontSize:11,fontFamily:"var(--font-sans)"},children:"+ Install here"})]})}function r0({agent:e,focused:r,active:n,onClick:s}){const o=e.health==="ok"?"var(--color-ok, #22c55e)":e.health==="stale"?"var(--color-own, #f59e0b)":"var(--text-tertiary)";return t.jsxs("button",{type:"button","data-testid":"agent-scope-row","data-agent-id":e.id,"data-active":n?"true":"false",onClick:s,style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"8px 14px",background:r?"color-mix(in srgb, var(--accent-surface) 10%, transparent)":"transparent",border:"none",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-sans)",color:"var(--text-primary)"},children:[t.jsx("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:o,flexShrink:0}}),t.jsx("span",{style:{flex:1,fontSize:13},children:e.displayName}),t.jsxs("span",{title:"project · personal · plugins",style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-secondary)",fontVariantNumeric:"tabular-nums"},children:[e.installedCount,"·",e.globalCount,"·",e.pluginCount??0]})]})}function n0({row:e,onFocus:r}){return t.jsxs("button",{type:"button","data-testid":"agent-scope-shared-folder-row",onClick:r,style:{display:"flex",flexDirection:"column",alignItems:"flex-start",gap:4,width:"100%",padding:"8px 14px",background:"transparent",border:"none",borderTop:"1px dashed var(--border-subtle)",borderBottom:"1px dashed var(--border-subtle)",cursor:"pointer",textAlign:"left",fontFamily:"var(--font-sans)",color:"var(--text-primary)"},children:[t.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-secondary)"},children:e.sharedFolderPath}),t.jsxs("span",{style:{display:"flex",gap:6,flexWrap:"wrap"},children:[e.consumers.map(n=>t.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:10,background:"color-mix(in srgb, var(--color-global) 20%, transparent)",color:"var(--text-primary)"},children:n.id},n.id)),t.jsxs("span",{style:{fontSize:10,color:"var(--text-secondary)",fontFamily:"var(--font-mono)"},children:["· ",e.combinedCount," skills"]})]})]})}function s0({agent:e}){const r=e.isRemoteOnly?`${e.displayName} is a web-only product — no local CLI or folder to detect.`:e.resolvedGlobalDir?`Looked for ${e.resolvedGlobalDir} — not found.`:`${e.displayName} was not found on this machine.`;return t.jsxs("div",{"data-testid":`agent-scope-not-detected-row-${e.id}`,title:r,style:{display:"flex",alignItems:"center",gap:10,padding:"6px 14px",color:"var(--text-secondary)",fontFamily:"var(--font-sans)",fontSize:12},children:[t.jsx("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:"var(--text-tertiary)",flexShrink:0}}),t.jsx("span",{style:{flex:1},children:e.displayName}),e.isRemoteOnly&&t.jsx("span",{"data-testid":`agent-scope-remote-badge-${e.id}`,"aria-label":"Remote-only agent",title:"Web-only agent — no local CLI to install skills into. Use the agent's web UI to load skills.",style:{background:"color-mix(in srgb, var(--text-tertiary) 18%, transparent)",border:"1px solid var(--border-default, var(--border-subtle))",borderRadius:10,padding:"1px 8px",color:"var(--text-secondary)",fontSize:10,letterSpacing:"0.04em",textTransform:"uppercase"},children:"Remote"})]})}function o0({agent:e,activeAgentId:r,onSwitch:n}){const s=e.id===r,o=e.isRemoteOnly===!0,a=s||o,i=s?"Active":o?"Remote-only":_.scopePicker.switchCta;return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontFamily:"var(--font-serif)",fontSize:16,fontWeight:500,color:"var(--text-primary)"},children:e.displayName}),t.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:2},children:o?"Remote service — no local install":i0(e.health)})]}),t.jsxs("dl",{style:{display:"grid",gridTemplateColumns:"auto 1fr",gap:"4px 12px",margin:0,fontSize:12},children:[t.jsx(Dn,{label:_.scopePicker.statsInstalled,value:String(e.installedCount)}),t.jsx(Dn,{label:_.scopePicker.statsGlobal,value:String(e.globalCount)}),t.jsx(Dn,{label:_.scopePicker.statsPlugins,value:String(e.pluginCount??0)}),t.jsx(Dn,{label:_.scopePicker.statsLastSync,value:e.lastSync?a0(e.lastSync):"—"})]}),t.jsx("button",{type:"button","data-testid":"agent-scope-switch",onClick:n,disabled:a,title:o?"This agent has no local CLI to switch to":void 0,style:{alignSelf:"flex-start",padding:"8px 14px",borderRadius:6,border:"1px solid var(--border-default, var(--border-subtle))",background:a?"transparent":"color-mix(in srgb, var(--accent-surface) 20%, transparent)",color:"var(--text-primary)",fontSize:12,fontWeight:500,fontFamily:"var(--font-sans)",cursor:a?"default":"pointer",opacity:a?.5:1},children:i})]})}function Dn({label:e,value:r}){return t.jsxs(t.Fragment,{children:[t.jsx("dt",{style:{color:"var(--text-secondary)",margin:0},children:e}),t.jsx("dd",{style:{color:"var(--text-primary)",margin:0,fontFamily:"var(--font-mono)",fontVariantNumeric:"tabular-nums"},children:r})]})}function Ad(){return t.jsx("div",{style:{padding:"16px 18px",fontSize:12,color:"var(--text-secondary)"},children:"No agents detected yet."})}function a0(e){try{const r=new Date(e).getTime(),n=Date.now()-r;if(Number.isNaN(r))return"—";const s=Math.round(n/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const o=Math.round(s/60);return o<24?`${o}h ago`:`${Math.round(o/24)}d ago`}catch{return"—"}}function i0(e){switch(e){case"ok":return _.scopePicker.statsHealthOk;case"stale":return _.scopePicker.statsHealthStale;case"missing":return _.scopePicker.statsHealthMissing}}function l0(e){const r=new Map;for(const n of e.sharedFolders??[])for(const s of n.consumers)r.set(s,n);return e.agents.map(n=>{const s=r.get(n.id);return{id:n.id,displayName:n.displayName,presence:n.detected?"detected":"absent",installedCount:n.localSkillCount,globalCount:n.globalSkillCount,pluginCount:n.pluginSkillCount??0,lastSync:n.lastSync,health:n.health,sharedFolderGroup:s?s.consumers:void 0,sharedFolderPath:s?s.path:void 0,isRemoteOnly:n.isRemoteOnly,resolvedGlobalDir:n.resolvedGlobalDir}})}function c0({agents:e,activeAgentId:r,onActiveAgentChange:n,onOpenSetup:s}){const[o,a]=l.useState(!1),[i,c]=l.useState(null),d=l.useRef(null),u=l.useMemo(()=>e.find(m=>m.id===r)??e[0]??null,[e,r]),p=l.useMemo(()=>u?u.health==="ok"?"var(--color-ok, #22c55e)":u.health==="stale"?"var(--color-own, #f59e0b)":"var(--text-tertiary)":"var(--text-tertiary)",[u]),f=l.useCallback(()=>{var m;a(!1),(m=d.current)==null||m.focus()},[]),h=l.useCallback(m=>{n(m),a(!1)},[n]);return t.jsxs(t.Fragment,{children:[t.jsxs("button",{ref:d,type:"button","data-testid":"agent-scope-picker-trigger","aria-haspopup":"dialog","aria-expanded":o,onClick:()=>a(m=>!m),onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),a(!0))},style:{display:"flex",alignItems:"center",gap:10,height:"40px",width:"100%",padding:"0 14px",background:"var(--bg-surface, var(--surface-1))",border:"none",borderBottom:"1px solid var(--border-default, var(--border-subtle))",cursor:"pointer",color:"var(--text-primary)",fontFamily:"var(--font-sans)",fontSize:13,fontWeight:500,textAlign:"left",position:"sticky",top:0,zIndex:2},children:[t.jsx("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:p,flexShrink:0}}),t.jsx("span",{style:{flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:(u==null?void 0:u.displayName)??"Select agent"}),t.jsxs("span",{title:"project · personal · plugins",style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-secondary)",fontVariantNumeric:"tabular-nums"},children:["(",(u==null?void 0:u.installedCount)??0," · ",(u==null?void 0:u.globalCount)??0," · ",(u==null?void 0:u.pluginCount)??0,")"]}),t.jsx("span",{"aria-hidden":"true",style:{fontSize:10,color:"var(--text-secondary)"},children:"▾"})]}),o&&t.jsx(Z1,{agents:e,activeAgentId:r,focusedAgentId:i??r,onFocusAgent:c,onSwitch:h,onOpenSetup:m=>{s(m),f()},onClose:f})]})}const Pd="vskill-ccode-banner-dismissed",d0=new Set(["claude-cli","claude-code"]);function u0(){try{return sessionStorage.getItem(Pd)==="true"}catch{return!1}}function p0(){try{sessionStorage.setItem(Pd,"true")}catch{}}function f0({activeAgentId:e}){const[r,n]=l.useState(()=>u0()),s=l.useCallback(()=>{typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:open-setup-drawer",{detail:{provider:"claude-code"}}))},[]),o=l.useCallback(()=>{p0(),n(!0)},[]);return!e||!d0.has(e)||r?null:t.jsxs("div",{"data-testid":"claude-code-first-use-banner",role:"note","aria-label":"Claude Code session info",style:{display:"flex",alignItems:"flex-start",gap:10,padding:"8px 12px",borderBottom:"1px solid var(--border-default, var(--border-subtle))",background:"color-mix(in srgb, var(--accent-surface) 8%, transparent)",fontFamily:"var(--font-sans)",fontSize:12,color:"var(--text-primary)",lineHeight:1.45},children:[t.jsx("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:"50%",background:"var(--color-ok, #22c55e)",marginTop:6,flexShrink:0}}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("span",{children:[_.claudeCodeLabel.firstUseBanner," "]}),t.jsx("button",{type:"button","data-testid":"claude-code-first-use-banner-learn-more",onClick:s,style:{background:"transparent",border:"none",padding:0,color:"var(--color-accent, var(--accent-surface))",cursor:"pointer",textDecoration:"underline",fontFamily:"inherit",fontSize:"inherit"},children:_.claudeCodeLabel.learnMore})]}),t.jsx("button",{type:"button","data-testid":"claude-code-first-use-banner-dismiss",onClick:o,"aria-label":"Dismiss Claude Code info banner",style:{background:"transparent",border:"none",color:"var(--text-secondary)",cursor:"pointer",fontSize:14,lineHeight:1,padding:2,flexShrink:0},children:"×"})]})}function h0(){const[e,r]=l.useState(null),[n,s]=l.useState("loading"),[o,a]=l.useState(null),i=l.useCallback(async()=>{try{const c=await ie.getAgents();r(c),s("ready"),a(null)}catch(c){s("error"),a(c.message)}},[]);return l.useEffect(()=>{i()},[i]),l.useEffect(()=>{const c=()=>void i();return window.addEventListener("studio:agent-changed",c),()=>window.removeEventListener("studio:agent-changed",c)},[i]),{status:n,response:e,error:o,refresh:()=>void i()}}const Fn="workspace",m0=["skills","agents"];async function x0(){const e=await fetch("/api/workspace");if(!e.ok)throw new Error(`GET /api/workspace failed: ${e.status}`);return await e.json()}async function g0(e){const r=await fetch("/api/workspace/active",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error??`POST /api/workspace/active failed: ${r.status}`)}return await r.json()}async function v0(e){const r=await fetch("/api/workspace/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error??`POST /api/workspace/projects failed: ${r.status}`)}return await r.json()}async function y0(e){const r=await fetch(`/api/workspace/projects/${encodeURIComponent(e)}`,{method:"DELETE"});if(!r.ok){const n=await r.json().catch(()=>({}));throw new Error(n.error??`DELETE /api/workspace/projects/${e} failed: ${r.status}`)}return await r.json()}function Js(){for(const e of m0)ze(e)}function b0(){const{data:e,loading:r,error:n,revalidate:s}=wt(Fn,x0),o=e,a=o==null?void 0:o.projects.find(u=>u.id===o.activeProjectId),i=l.useCallback(async u=>{await g0(u),ze(Fn),Js()},[]),c=l.useCallback(async u=>{await v0(u),ze(Fn),Js()},[]),d=l.useCallback(async u=>{await y0(u),ze(Fn),Js()},[]);return{workspace:o,activeProject:a,loading:r,error:n,switchProject:i,addProject:c,removeProject:d,revalidate:s}}function k0({workspace:e,onSwitch:r,onAdd:n,onRemove:s,isPathStale:o}){const[a,i]=l.useState(!1),[c,d]=l.useState(!1),[u,p]=l.useState(""),[f,h]=l.useState(null),[m,g]=l.useState(null),[x,v]=l.useState(null),[b,y]=l.useState(!1),j=l.useRef(null),S=(e==null?void 0:e.projects)??[],w=S.find(C=>C.id===(e==null?void 0:e.activeProjectId));l.useEffect(()=>{if(!a)return;function C(N){j.current&&!j.current.contains(N.target)&&(i(!1),d(!1),h(null))}return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[a]);async function R(){h(null);const C=u.trim();if(!C){h("Paste an absolute path (e.g. /Users/you/projects/my-skill)");return}if(!C.startsWith("/")&&!/^[A-Za-z]:[\\/]/.test(C)){h("Path must be absolute. In Terminal, cd to the folder and run: pwd — then paste the result here.");return}try{await n({path:C}),p(""),d(!1)}catch(N){const I=N instanceof Error?N.message:String(N);/does not exist/i.test(I)?h(`Path not found on disk: ${C}`):/Duplicate/i.test(I)?h("That project is already registered."):h(I)}}async function k(){if(h(null),typeof window<"u"&&"showDirectoryPicker"in window)try{const C=await window.showDirectoryPicker();p(C.name),d(!0)}catch{}else d(!0)}function E(C){if(C.length<=50)return C;const N=C.split("/");return N.length<=4?C:`${N.slice(0,3).join("/")}/…/${N.slice(-2).join("/")}`}return t.jsxs("div",{ref:j,"data-vskill-project-picker":!0,style:{position:"relative",display:"inline-block"},children:[t.jsxs("button",{type:"button",onClick:()=>i(C=>!C),"aria-expanded":a,"aria-haspopup":"menu",title:(w==null?void 0:w.path)??"No project selected",style:{display:"flex",alignItems:"center",gap:8,padding:"4px 10px",border:"1px solid transparent",borderRadius:6,background:a?"var(--surface-2, rgba(0,0,0,0.05))":"transparent",cursor:"pointer",fontFamily:"var(--font-mono)",fontSize:13,color:"var(--text-primary)",transition:"background-color 120ms ease"},children:[t.jsx("span",{"aria-hidden":!0,style:{width:8,height:8,borderRadius:"50%",flexShrink:0,backgroundColor:(w==null?void 0:w.colorDot)??"var(--text-tertiary, #999)"}}),t.jsx("span",{style:{maxWidth:180,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:w?w.name:"No project"}),t.jsx("span",{"aria-hidden":!0,style:{fontSize:10,color:"var(--text-tertiary, #999)",marginLeft:2},children:a?"▴":"▾"})]}),a&&t.jsxs("div",{role:"menu","aria-label":"Switch project",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:280,maxWidth:420,width:"max-content",background:"var(--color-paper, #fff)",border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:8,boxShadow:"0 4px 6px -1px rgba(0,0,0,0.08), 0 10px 20px -5px rgba(0,0,0,0.12)",overflow:"hidden",zIndex:50,fontFamily:"var(--font-sans)"},children:[S.length===0&&t.jsx("div",{style:{padding:"16px 16px 12px",fontSize:12,color:"var(--text-tertiary)",lineHeight:1.5},children:"No projects registered. Add one to get started."}),S.length>0&&t.jsx("ul",{role:"none",style:{listStyle:"none",margin:0,padding:4,maxHeight:320,overflowY:"auto"},children:S.map(C=>{const N=o?o(C.path):!1,I=C.id===(e==null?void 0:e.activeProjectId),P=m===C.id;return t.jsxs("li",{role:"menuitem","data-stale":N?"true":"false",onMouseEnter:()=>g(C.id),onMouseLeave:()=>g(L=>L===C.id?null:L),onClick:()=>{if(!N){if(I){i(!1);return}v(C)}},style:{display:"flex",alignItems:"center",gap:10,padding:"8px 10px",borderRadius:6,cursor:N?"not-allowed":"pointer",background:P&&!N?"var(--surface-2, rgba(0,0,0,0.04))":I?"var(--surface-1, rgba(0,0,0,0.02))":"transparent",opacity:N?.5:1,transition:"background-color 120ms ease"},children:[t.jsx("span",{"aria-hidden":!0,style:{width:10,height:10,borderRadius:"50%",flexShrink:0,backgroundColor:C.colorDot,boxShadow:I?"0 0 0 2px color-mix(in oklch, currentColor 20%, transparent)":"none"}}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,fontSize:13,fontWeight:I?600:500,color:"var(--text-primary)",lineHeight:1.3},children:[t.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:C.name}),I&&t.jsx("span",{"aria-label":"Active",style:{fontSize:10,color:"var(--color-action, #2F5B8E)",letterSpacing:"0.05em",textTransform:"uppercase",fontWeight:600},children:"Active"})]}),t.jsx("div",{title:C.path,style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-tertiary)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:E(C.path)}),N&&t.jsx("div",{style:{fontSize:10,color:"var(--color-own, #b45309)",marginTop:2},children:"Path no longer exists"})]}),t.jsx("button",{type:"button","aria-label":`Remove ${C.name}`,onClick:L=>{L.stopPropagation(),s(C.id)},style:{width:24,height:24,display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",borderRadius:4,cursor:"pointer",color:"var(--text-tertiary)",opacity:P?1:0,transition:"opacity 120ms ease, color 120ms ease, background-color 120ms ease",flexShrink:0},onMouseEnter:L=>{L.currentTarget.style.color="var(--color-error, #b91c1c)",L.currentTarget.style.backgroundColor="color-mix(in oklch, var(--color-error, #b91c1c) 10%, transparent)"},onMouseLeave:L=>{L.currentTarget.style.color="var(--text-tertiary)",L.currentTarget.style.backgroundColor="transparent"},children:t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("polyline",{points:"3 6 5 6 21 6"}),t.jsx("path",{d:"M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"}),t.jsx("path",{d:"M10 11v6"}),t.jsx("path",{d:"M14 11v6"}),t.jsx("path",{d:"M9 6V4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2"})]})})]},C.id)})}),t.jsxs("div",{style:{borderTop:"1px solid var(--border-subtle, rgba(0,0,0,0.08))",padding:c?8:6},children:[!c&&t.jsxs("button",{type:"button",onClick:()=>void k(),className:"vskill-project-add",style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"8px 10px",border:"none",borderRadius:6,background:"transparent",cursor:"pointer",fontFamily:"var(--font-sans)",fontSize:13,fontWeight:500,color:"var(--color-action, #2F5B8E)",transition:"background-color 120ms ease"},onMouseEnter:C=>{C.currentTarget.style.backgroundColor="color-mix(in oklch, var(--color-action, #2F5B8E) 10%, transparent)"},onMouseLeave:C=>{C.currentTarget.style.backgroundColor="transparent"},children:[t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Add project"]}),c&&t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("input",{type:"text",value:u,onChange:C=>p(C.target.value),onKeyDown:C=>{C.key==="Enter"&&R(),C.key==="Escape"&&(d(!1),h(null))},placeholder:"/absolute/path/to/project",autoFocus:!0,style:{width:"100%",padding:"6px 8px",fontFamily:"var(--font-mono)",fontSize:12,border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:4,background:"var(--surface-0, #fff)",color:"var(--text-primary)",outline:"none"}}),t.jsxs("div",{style:{display:"flex",gap:6,justifyContent:"flex-end"},children:[t.jsx("button",{type:"button",onClick:()=>{d(!1),h(null),p("")},style:{padding:"4px 10px",fontSize:12,border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:4,background:"transparent",color:"var(--text-primary)",cursor:"pointer"},children:"Cancel"}),t.jsx("button",{type:"button",onClick:()=>void R(),style:{padding:"4px 10px",fontSize:12,border:"none",borderRadius:4,background:"var(--color-action, #2F5B8E)",color:"var(--color-paper, #fff)",cursor:"pointer",fontWeight:500},children:"Add"})]}),f&&t.jsx("div",{style:{fontSize:11,color:"var(--color-error, #b91c1c)"},children:f})]})]})]}),x&&t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Switch project instructions",style:{position:"fixed",inset:0,zIndex:80,display:"flex",alignItems:"center",justifyContent:"center"},onClick:()=>v(null),children:[t.jsx("div",{style:{position:"absolute",inset:0,background:"rgba(0,0,0,0.40)"}}),t.jsxs("div",{onClick:C=>C.stopPropagation(),style:{position:"relative",width:"min(520px, 92vw)",background:"var(--color-paper, #fff)",border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:10,boxShadow:"0 10px 15px -3px rgba(0,0,0,0.12), 0 20px 40px -8px rgba(0,0,0,0.18)",padding:18,fontFamily:"var(--font-sans)",color:"var(--text-primary)"},children:[t.jsxs("h2",{style:{margin:0,fontSize:16,fontWeight:600,fontFamily:"var(--font-serif, ui-serif)",marginBottom:8},children:["Switch to ",x.name]}),t.jsx("p",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.5,margin:0,marginBottom:12},children:"Skill Studio's skill scanner reads from the folder it was launched in, so switching projects from the browser isn't possible. Quit this server and relaunch from the target folder:"}),t.jsx("div",{style:{background:"var(--surface-1, #0f0f10)",color:"var(--text-primary)",padding:"10px 12px",borderRadius:6,fontFamily:"var(--font-mono)",fontSize:12,lineHeight:1.55,whiteSpace:"pre-wrap",wordBreak:"break-all",border:"1px solid var(--border-subtle, rgba(255,255,255,0.08))"},children:`cd "${x.path}" && npx vskill@latest studio`}),t.jsxs("div",{style:{display:"flex",gap:8,marginTop:14,justifyContent:"flex-end"},children:[t.jsx("button",{type:"button",onClick:async()=>{try{await navigator.clipboard.writeText(`cd "${x.path}" && npx vskill@latest studio`),y(!0),setTimeout(()=>y(!1),1600)}catch{}},style:{padding:"7px 14px",fontSize:13,fontWeight:600,border:"1px solid var(--color-action, #2F5B8E)",borderRadius:6,background:"var(--color-action, #2F5B8E)",color:"#ffffff",cursor:"pointer",boxShadow:"0 1px 2px rgba(0,0,0,0.15), inset 0 1px 0 rgba(255,255,255,0.12)"},children:b?"Copied!":"Copy command"}),t.jsx("button",{type:"button",onClick:()=>v(null),style:{padding:"7px 12px",fontSize:13,fontWeight:500,border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:6,background:"transparent",color:"var(--text-primary)",cursor:"pointer"},children:"Close"})]})]})]})]})}function j0(e,r){const n=r.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?e:e.filter(s=>{const o=`${s.name} ${s.path}`.toLowerCase();return n.every(a=>o.includes(a))})}function w0({open:e,projects:r,onSwitch:n,onClose:s}){const[o,a]=l.useState(""),[i,c]=l.useState(0),d=l.useMemo(()=>j0(r,o),[r,o]);l.useEffect(()=>{e||(a(""),c(0))},[e]),l.useEffect(()=>{i>=d.length&&c(0)},[d.length,i]);const u=p=>{if(p.key==="Escape"){p.preventDefault(),s();return}if(p.key==="ArrowDown"){p.preventDefault(),c(f=>Math.min(f+1,Math.max(d.length-1,0)));return}if(p.key==="ArrowUp"){p.preventDefault(),c(f=>Math.max(f-1,0));return}if(p.key==="Enter"){p.preventDefault();const f=d[i];f&&(n(f.id),s())}};return e?t.jsxs("div",{role:"dialog","aria-modal":"true","data-vskill-project-palette":!0,className:"vskill-project-palette fixed inset-0 z-50 flex items-start justify-center pt-24",children:[t.jsx("div",{className:"absolute inset-0 bg-black/30",onClick:s}),t.jsxs("div",{className:"relative w-[520px] max-w-[92vw] bg-background border rounded shadow-lg",children:[t.jsx("input",{type:"text",autoFocus:!0,value:o,onChange:p=>a(p.target.value),onKeyDown:u,placeholder:"Switch project…",className:"w-full px-3 py-2 text-sm border-b outline-none"}),t.jsxs("ul",{role:"listbox",className:"max-h-80 overflow-auto",children:[d.length===0&&t.jsx("li",{className:"px-3 py-2 text-xs text-muted-foreground",children:"No matches."}),d.map((p,f)=>t.jsxs("li",{role:"option","aria-selected":f===i,"data-highlighted":f===i,className:["flex items-center gap-2 px-3 py-2 text-sm cursor-pointer",f===i?"bg-muted":""].join(" "),onMouseEnter:()=>c(f),onClick:()=>{n(p.id),s()},children:[t.jsx("span",{"aria-hidden":!0,className:"inline-block w-2 h-2 rounded-full",style:{backgroundColor:p.colorDot}}),t.jsxs("span",{className:"flex-1",children:[t.jsx("span",{className:"vskill-palette-name",children:p.name}),t.jsx("span",{className:"ml-2 vskill-palette-path text-xs font-mono text-muted-foreground",children:p.path})]})]},p.id))]})]})]}):null}const Vi=/^[a-z][a-z0-9-]{0,62}[a-z0-9]$/;function S0({open:e,onClose:r,initialMode:n="standalone",isClaudeCode:s,projectRoot:o,onCreated:a}){const[i,c]=l.useState("destination"),[d,u]=l.useState(n),[p,f]=l.useState(""),[h,m]=l.useState(""),[g,x]=l.useState(""),[v,b]=l.useState([]),[y,j]=l.useState(!1),[S,w]=l.useState(null);if(l.useEffect(()=>{e&&(c("destination"),u(n),f(""),m(""),x(""),w(null))},[e,n]),l.useEffect(()=>{if(!e)return;let T=!0;return fetch("/api/authoring/plugins").then($=>$.json()).then($=>{T&&b($.plugins??[])}).catch(()=>{}),()=>{T=!1}},[e]),l.useEffect(()=>{if(!e)return;function T($){$.key==="Escape"&&($.preventDefault(),r())}return document.addEventListener("keydown",T),()=>document.removeEventListener("keydown",T)},[e,r]),!e)return null;const R=v.length>0,k=s&&R,E=s,C=Vi.test(p),N=d==="existing-plugin"?h.length>0:Vi.test(h),I=!y&&C&&(d==="standalone"||N),P=C0(o,d,h,p);async function L(){w(null),j(!0);try{const M=new URLSearchParams;M.set("mode",d),M.set("skillName",p),h&&M.set("pluginName",h);const F=await fetch(`/api/authoring/skill-exists?${M.toString()}`),W=await F.json();if(!F.ok){w(W.error??`Check failed: ${F.status}`);return}if(W.exists){w(`Skill '${p}' already exists${W.path?` at ${W.path}`:""}`);return}}catch(M){w(M instanceof Error?M.message:String(M));return}finally{j(!1)}const T=new URLSearchParams;T.set("mode",d),T.set("skillName",p),g.trim()&&T.set("description",g.trim()),h&&T.set("pluginName",h);const $=`#/create?${T.toString()}`;typeof window<"u"&&(window.location.hash=$),r()}async function B(){w(null),j(!0);try{const T=await fetch("/api/authoring/create-skill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:d,skillName:p,description:g.trim()||void 0,pluginName:d==="standalone"?void 0:h})}),$=await T.json();if(!T.ok||!$.ok){w($.error??`Create failed: ${T.status}`);return}ze("skills"),a==null||a({mode:d,skillName:p,pluginName:$.pluginName??null,skillMdPath:$.skillMdPath}),r()}catch(T){w(T instanceof Error?T.message:String(T))}finally{j(!1)}}return t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Create skill","data-vskill-create-skill-modal":!0,style:{position:"fixed",inset:0,zIndex:100,display:"flex",alignItems:"center",justifyContent:"center"},children:[t.jsx("div",{onClick:r,style:{position:"absolute",inset:0,background:"rgba(0,0,0,0.45)"}}),t.jsxs("div",{style:{position:"relative",width:"min(560px, 92vw)",maxHeight:"86vh",overflow:"auto",background:"var(--color-paper, #fff)",border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:10,boxShadow:"0 10px 15px -3px rgba(0,0,0,0.12), 0 20px 40px -8px rgba(0,0,0,0.18)",fontFamily:"var(--font-sans)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 18px",borderBottom:"1px solid var(--border-subtle, rgba(0,0,0,0.08))"},children:[t.jsx("h2",{style:{margin:0,fontSize:16,fontWeight:600,color:"var(--text-primary)",fontFamily:"var(--font-serif, ui-serif)",letterSpacing:"0.01em"},children:i==="destination"?"Create a skill":"Name and describe"}),t.jsxs("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginLeft:"auto",fontVariantNumeric:"tabular-nums"},children:["Step ",i==="destination"?"1":"2"," of 2"]})]}),i==="destination"&&t.jsxs("div",{style:{padding:14,display:"flex",flexDirection:"column",gap:10},children:[t.jsx(Xs,{title:"Standalone skill",subtitle:"A single skill in this project",description:"Lives at <project>/skills/<name>/SKILL.md. Works with every agent.",icon:"📄",selected:d==="standalone",onClick:()=>u("standalone")}),t.jsx(Xs,{title:"Add to existing plugin",subtitle:k?`${v.length} plugin source${v.length===1?"":"s"} in this project`:s?"No plugin sources in this project yet":"Claude Code only",description:"Appends a skill to an existing <plugin>/.claude-plugin/plugin.json source.",icon:"🧩",disabled:!k,selected:d==="existing-plugin",onClick:()=>k&&u("existing-plugin")}),t.jsx(Xs,{title:"Plugin (multi-skill)",subtitle:E?"Bundle related skills under one Claude Code plugin":"Claude Code only",description:"Creates <folder>/.claude-plugin/plugin.json and <folder>/skills/<first>/SKILL.md.",icon:"📦",disabled:!E,selected:d==="new-plugin",onClick:()=>E&&u("new-plugin")})]}),i==="details"&&t.jsxs("div",{style:{padding:16,display:"flex",flexDirection:"column",gap:12},children:[d==="new-plugin"&&t.jsx(zn,{label:"Plugin name",hint:"kebab-case",children:t.jsx("input",{type:"text",value:h,onChange:T=>m(T.target.value.trim()),placeholder:"my-first-plugin",autoFocus:!0,style:Bn(!h||N)})}),d==="existing-plugin"&&t.jsx(zn,{label:"Plugin",children:t.jsxs("select",{value:h,onChange:T=>m(T.target.value),style:{...Bn(!0),fontFamily:"var(--font-mono)"},children:[t.jsx("option",{value:"",children:"Select a plugin…"}),v.map(T=>t.jsx("option",{value:T.name,children:T.name},T.path))]})}),t.jsx(zn,{label:"Skill name",hint:"kebab-case",children:t.jsx("input",{type:"text",value:p,onChange:T=>f(T.target.value.trim()),placeholder:"my-new-skill",autoFocus:d!=="new-plugin",style:Bn(!p||C)})}),t.jsx(zn,{label:"Description",hint:"One short sentence — shown in frontmatter",children:t.jsx("textarea",{value:g,onChange:T=>x(T.target.value),rows:2,placeholder:"Does a thing when Claude needs X",style:{...Bn(!0),resize:"vertical",minHeight:52,fontFamily:"var(--font-sans)"}})}),P&&t.jsxs("div",{style:{padding:"8px 10px",fontSize:11,fontFamily:"var(--font-mono)",color:"var(--text-secondary)",background:"var(--surface-1, rgba(0,0,0,0.03))",border:"1px solid var(--border-subtle, rgba(0,0,0,0.08))",borderRadius:4,wordBreak:"break-all"},children:[t.jsx("div",{style:{fontSize:10,color:"var(--text-tertiary)",marginBottom:2,fontFamily:"var(--font-sans)"},children:"Will create:"}),P.map((T,$)=>t.jsx("div",{children:T},$))]}),S&&t.jsx("div",{style:{fontSize:12,color:"var(--color-error, #b91c1c)",padding:"6px 10px",background:"color-mix(in oklch, var(--color-error, #b91c1c) 8%, transparent)",borderRadius:4},children:S})]}),t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,padding:"12px 16px",borderTop:"1px solid var(--border-subtle, rgba(0,0,0,0.08))",background:"var(--surface-1, rgba(0,0,0,0.02))"},children:[t.jsx("button",{type:"button",onClick:r,style:Qs,children:"Cancel"}),i==="destination"&&t.jsx("button",{type:"button",onClick:()=>c("details"),style:Gi,children:"Continue →"}),i==="details"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>c("destination"),style:Qs,children:"← Back"}),t.jsx("button",{type:"button",onClick:()=>void L(),disabled:!I,style:{...Qs,opacity:I?1:.5,cursor:I?"pointer":"not-allowed"},title:"Opens the AI generation flow with this destination pre-selected (choose Claude Code, Anthropic API, OpenRouter, or local models)",children:"Generate with AI"}),t.jsx("button",{type:"button",onClick:()=>void B(),disabled:!I,style:{...Gi,opacity:I?1:.5,cursor:I?"pointer":"not-allowed"},title:"Creates an empty SKILL.md scaffold you can fill in by hand",children:y?"Creating…":"Create empty scaffold"})]})]})]})]})}function Xs({title:e,subtitle:r,description:n,icon:s,selected:o,disabled:a,onClick:i}){return t.jsxs("button",{type:"button",onClick:i,disabled:a,"aria-pressed":o,style:{display:"flex",gap:12,padding:"12px 14px",textAlign:"left",borderRadius:8,border:o?"2px solid var(--color-accent, #2f6f8f)":"1px solid var(--border-default, rgba(0,0,0,0.12))",background:o?"color-mix(in oklch, var(--color-accent, #2f6f8f) 8%, var(--color-paper, #fff))":a?"var(--surface-1, rgba(0,0,0,0.02))":"var(--color-paper, #fff)",color:a?"var(--text-tertiary)":"var(--text-primary)",cursor:a?"not-allowed":"pointer",opacity:a?.6:1,fontFamily:"inherit",width:"100%",transition:"border-color 120ms ease, background-color 120ms ease"},children:[t.jsx("span",{"aria-hidden":!0,style:{fontSize:22,lineHeight:1,marginTop:2},children:s}),t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsx("div",{style:{fontSize:14,fontWeight:600,lineHeight:1.3},children:e}),t.jsx("div",{style:{fontSize:11,color:"var(--text-tertiary)",marginTop:2,textTransform:"uppercase",letterSpacing:"0.04em"},children:r}),t.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",marginTop:6,lineHeight:1.5},children:n})]})]})}function zn({label:e,hint:r,children:n}){return t.jsxs("label",{style:{display:"flex",flexDirection:"column",gap:4},children:[t.jsxs("span",{style:{display:"flex",alignItems:"baseline",gap:8},children:[t.jsx("span",{style:{fontSize:12,fontWeight:600,color:"var(--text-primary)"},children:e}),r&&t.jsx("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:r})]}),n]})}function Bn(e){return{width:"100%",padding:"7px 10px",fontSize:13,fontFamily:"var(--font-mono)",border:`1px solid ${e?"var(--border-default, rgba(0,0,0,0.12))":"var(--color-error, #b91c1c)"}`,borderRadius:4,background:"var(--surface-0, #fff)",color:"var(--text-primary)",outline:"none",boxSizing:"border-box"}}const Gi={padding:"8px 16px",fontSize:13,fontWeight:600,border:"1px solid var(--color-action, #2F5B8E)",borderRadius:6,background:"var(--color-action, #2F5B8E)",color:"var(--color-action-ink, #FFFFFF)",cursor:"pointer",fontFamily:"inherit",boxShadow:"0 1px 2px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.12)",letterSpacing:"0.01em"},Qs={padding:"7px 12px",fontSize:13,fontWeight:500,border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:6,background:"transparent",color:"var(--text-primary)",cursor:"pointer",fontFamily:"inherit"};function C0(e,r,n,s){const o=s||"<skill-name>",a=n||"<plugin-name>",i=e||"<project>";return r==="standalone"?[`${i}/skills/${o}/SKILL.md`]:r==="existing-plugin"?[`${i}/${a}/skills/${o}/SKILL.md`]:r==="new-plugin"?[`${i}/${a}/.claude-plugin/plugin.json`,`${i}/${a}/skills/${o}/SKILL.md`]:null}function $d(e){return e.trim().toLowerCase()}function E0(e,r){const n=$d(r);return n?e.filter(s=>s.name.toLowerCase().includes(n)||s.source.toLowerCase().includes(n)):e}function N0(e,r){const n=$d(r);return n?e.filter(s=>[s.name,s.description??"",s.category??"",s.author??""].join(" ").toLowerCase().includes(n)):e}function R0({open:e,onClose:r,onInstall:n,onUninstall:s,installedNames:o}){const[a,i]=l.useState(null),[c,d]=l.useState([]),[u,p]=l.useState(null),[f,h]=l.useState(null),[m,g]=l.useState(!1),[x,v]=l.useState(null),[b,y]=l.useState(""),[j,S]=l.useState("");l.useEffect(()=>{u?y(""):S("")},[u]);const w=l.useMemo(()=>E0(c,b),[c,b]),R=l.useMemo(()=>N0((f==null?void 0:f.plugins)??[],j),[f,j]);return l.useEffect(()=>{e&&(g(!0),v(null),fetch("/api/plugins/marketplaces").then(k=>k.json()).then(k=>{if(k.error)throw new Error(k.error);d(k.marketplaces??[])}).catch(k=>v(k instanceof Error?k.message:String(k))).finally(()=>g(!1)))},[e]),l.useEffect(()=>{if(!u){h(null);return}g(!0),v(null),fetch(`/api/plugins/marketplaces/${encodeURIComponent(u)}`).then(k=>k.json()).then(k=>{if(k.error)throw new Error(k.error);h(k)}).catch(k=>v(k instanceof Error?k.message:String(k))).finally(()=>g(!1))},[u]),l.useEffect(()=>{if(!e)return;function k(E){E.key==="Escape"&&r()}return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[e,r]),e?t.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":"Plugin marketplace","data-vskill-marketplace-drawer":!0,style:{position:"fixed",inset:0,zIndex:80},children:[t.jsx("div",{onClick:r,style:{position:"absolute",inset:0,background:"rgba(0,0,0,0.38)"}}),t.jsxs("aside",{style:{position:"absolute",top:0,right:0,bottom:0,width:"min(480px, 94vw)",background:"var(--color-paper, #fff)",borderLeft:"1px solid var(--border-default, rgba(0,0,0,0.12))",boxShadow:"-10px 0 30px -8px rgba(0,0,0,0.18)",display:"flex",flexDirection:"column",fontFamily:"var(--font-sans)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 18px",borderBottom:"1px solid var(--border-subtle, rgba(0,0,0,0.08))"},children:[u&&t.jsx("button",{type:"button",onClick:()=>p(null),"aria-label":"Back to marketplaces",style:{border:"none",background:"transparent",fontSize:14,color:"var(--text-secondary)",cursor:"pointer",padding:0},children:"← Back"}),t.jsx("h2",{style:{margin:0,fontSize:15,fontWeight:600,color:"var(--text-primary)",fontFamily:"var(--font-serif, ui-serif)",flex:1},children:u?(f==null?void 0:f.name)??u:"Browse plugins"}),t.jsx("button",{type:"button",onClick:r,"aria-label":"Close",style:{border:"none",background:"transparent",fontSize:16,color:"var(--text-secondary)",cursor:"pointer",padding:"4px 6px"},children:"✕"})]}),t.jsxs("div",{style:{flex:1,overflowY:"auto",padding:12},children:[m&&t.jsx("div",{style:{padding:12,fontSize:12,color:"var(--text-tertiary)"},children:"Loading…"}),x&&t.jsx("div",{style:{padding:10,fontSize:12,color:"var(--color-error, #b91c1c)",background:"color-mix(in oklch, var(--color-error, #b91c1c) 8%, transparent)",borderRadius:4},children:x}),!u&&!m&&c.length===0&&!x&&t.jsx(T0,{}),!u&&c.length>0&&t.jsx(Ki,{value:b,onChange:y,placeholder:"Search marketplaces…",ariaLabel:"Search marketplaces",testId:"marketplace-search"}),!u&&c.length>0&&w.length===0&&t.jsxs("div",{style:{padding:12,fontSize:12,color:"var(--text-tertiary)"},children:["No marketplaces match “",b,"”."]}),!u&&w.map(k=>t.jsxs("button",{type:"button",onClick:()=>p(k.name),style:L0,onMouseEnter:E=>{E.currentTarget.style.background="var(--surface-2, rgba(0,0,0,0.04))"},onMouseLeave:E=>{E.currentTarget.style.background="transparent"},children:[t.jsx("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:k.name}),t.jsx("div",{style:{fontSize:11,color:"var(--text-tertiary)",fontFamily:"var(--font-mono)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.source})]},k.name)),u&&f&&t.jsxs(t.Fragment,{children:[f.description&&t.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",padding:"0 6px 12px",lineHeight:1.5},children:f.description}),f.plugins.length===0&&t.jsx("div",{style:{padding:12,fontSize:12,color:"var(--text-tertiary)"},children:"This marketplace has no plugins catalogued yet."}),f.plugins.length>0&&t.jsx(Ki,{value:j,onChange:S,placeholder:"Search plugins…",ariaLabel:"Search plugins",testId:"plugin-search"}),f.plugins.length>0&&R.length===0&&t.jsxs("div",{style:{padding:12,fontSize:12,color:"var(--text-tertiary)"},children:["No plugins match “",j,"”."]}),R.map(k=>{const E=o.has(k.name);return t.jsx("div",{style:{padding:"10px 8px",borderBottom:"1px solid var(--border-subtle, rgba(0,0,0,0.05))"},children:t.jsxs("div",{style:{display:"flex",alignItems:"start",gap:8},children:[t.jsxs("div",{style:{flex:1,minWidth:0},children:[t.jsxs("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-primary)",display:"flex",alignItems:"baseline",gap:8},children:[k.name,k.version&&t.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-tertiary)"},children:k.version}),k.category&&t.jsx("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:10,background:"var(--surface-2, rgba(0,0,0,0.05))",color:"var(--text-secondary)"},children:k.category})]}),k.description&&t.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginTop:4,lineHeight:1.5},children:k.description})]}),E&&s?t.jsx("button",{type:"button",disabled:a===k.name,onClick:async()=>{i(k.name);try{await s(k.name)}finally{i(null)}},"aria-label":`Uninstall ${k.name}`,style:{flexShrink:0,padding:"5px 12px",fontSize:12,fontWeight:600,border:"1px solid var(--color-error, #b91c1c)",borderRadius:4,background:"transparent",color:"var(--color-error, #b91c1c)",cursor:a===k.name?"wait":"pointer",opacity:a===k.name?.6:1,fontFamily:"inherit"},children:a===k.name?"Uninstalling…":"Uninstall"}):t.jsx("button",{type:"button",disabled:E,onClick:()=>n(k.name,u),style:{flexShrink:0,padding:"5px 12px",fontSize:12,fontWeight:600,border:E?"none":"1px solid var(--color-action, #2F5B8E)",borderRadius:4,background:E?"var(--surface-2, rgba(0,0,0,0.05))":"var(--color-action, #2F5B8E)",color:E?"var(--text-tertiary)":"var(--color-action-ink, #FFFFFF)",cursor:E?"default":"pointer",fontFamily:"inherit",boxShadow:E?"none":"0 1px 2px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.12)"},children:E?"Installed":"Install"})]})},k.name)})]})]}),!u&&t.jsx("div",{style:{borderTop:"1px solid var(--border-subtle, rgba(0,0,0,0.08))",padding:12},children:t.jsx(I0,{onAdded:()=>{ze("marketplaces"),fetch("/api/plugins/marketplaces").then(k=>k.json()).then(k=>d(k.marketplaces??[]))}})})]})]}):null}function Ki({value:e,onChange:r,placeholder:n,ariaLabel:s,testId:o}){return t.jsx("div",{style:{padding:"0 4px 10px"},children:t.jsx("input",{type:"search",value:e,onChange:a=>r(a.target.value),placeholder:n,"aria-label":s,"data-testid":o,style:{width:"100%",padding:"6px 10px",fontSize:12,fontFamily:"var(--font-sans)",border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:4,background:"var(--surface-0, #fff)",color:"var(--text-primary)",outline:"none",boxSizing:"border-box"}})})}function T0(){return t.jsxs("div",{style:{padding:20,fontSize:12,color:"var(--text-tertiary)",lineHeight:1.6},children:["No marketplaces configured yet. Add one below — examples:",t.jsxs("ul",{style:{marginTop:8,paddingLeft:16},children:[t.jsx("li",{children:t.jsx("code",{children:"anthropics/claude-plugins-official"})}),t.jsx("li",{children:t.jsx("code",{children:"openai/codex-plugin-cc"})})]})]})}function I0({onAdded:e}){const[r,n]=l.useState(""),[s,o]=l.useState(!1),[a,i]=l.useState(null);async function c(){const d=r.trim();if(d){o(!0),i(null);try{const u=await fetch("/api/plugins/marketplaces",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:d})}),p=await u.json().catch(()=>({}));if(!u.ok||!p.ok){i(p.error??`Add failed (${u.status})`);return}n(""),e()}catch(u){i(u instanceof Error?u.message:String(u))}finally{o(!1)}}}return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{style:{fontSize:11,color:"var(--text-tertiary)",fontWeight:500},children:"Add marketplace (GitHub owner/repo, URL, or path)"}),t.jsxs("div",{style:{display:"flex",gap:6},children:[t.jsx("input",{type:"text",value:r,onChange:d=>n(d.target.value),onKeyDown:d=>{d.key==="Enter"&&c()},placeholder:"anthropics/claude-plugins-official",disabled:s,style:{flex:1,padding:"6px 8px",fontSize:12,fontFamily:"var(--font-mono)",border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderRadius:4,background:"var(--surface-0, #fff)",color:"var(--text-primary)",outline:"none"}}),t.jsx("button",{type:"button",onClick:()=>void c(),disabled:s||!r.trim(),style:{padding:"6px 14px",fontSize:12,fontWeight:600,border:"1px solid var(--color-action, #2F5B8E)",borderRadius:4,background:"var(--color-action, #2F5B8E)",color:"var(--color-action-ink, #FFFFFF)",cursor:s||!r.trim()?"not-allowed":"pointer",opacity:s||!r.trim()?.5:1,boxShadow:"0 1px 2px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.12)",fontFamily:"inherit"},children:s?"Adding…":"Add"})]}),a&&t.jsx("div",{style:{fontSize:11,color:"var(--color-error, #b91c1c)"},children:a})]})}const L0={display:"block",width:"100%",textAlign:"left",padding:"10px 12px",border:"none",borderRadius:6,background:"transparent",cursor:"pointer",fontFamily:"inherit",marginBottom:2},Zs=12;function A0({job:e,onDone:r}){const[n,s]=l.useState([]),[o,a]=l.useState("running"),[i,c]=l.useState(!1);if(l.useEffect(()=>{if(!e)return;s([]),a("running"),c(!1);const f=new AbortController;let h=[],m="running";return(async()=>{try{const g=await fetch("/api/plugins/install/stream",{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream"},body:JSON.stringify({plugin:e.ref}),signal:f.signal});if(!g.ok||!g.body){a("failed"),r({ok:!1,code:g.status,lines:[`HTTP ${g.status}`]});return}const x=g.body.getReader(),v=new TextDecoder;let b="";for(;;){const{value:y,done:j}=await x.read();if(j)break;b+=v.decode(y,{stream:!0});const S=b.split(/\n\n/);b=S.pop()??"";for(const w of S){const R=w.match(/^data:\s*(.*)$/m);if(R)try{const k=JSON.parse(R[1]);k.type==="stdout"&&k.line?(h=[...h,k.line].slice(-Zs),s(h)):k.type==="stderr"&&k.line?(h=[...h,`⚠ ${k.line}`].slice(-Zs),s(h)):k.type==="done"?(m=k.ok?"ok":"failed",a(m),Wl(),ze("skills"),r({ok:k.ok??!1,code:k.code??null,lines:h})):k.type==="error"&&k.error&&(h=[...h,`✘ ${k.error}`].slice(-Zs),s(h))}catch{}}}m==="running"&&r({ok:!0,code:0,lines:h})}catch(g){if(g.name==="AbortError")return;a("failed"),r({ok:!1,code:null,lines:[...h,g instanceof Error?g.message:String(g)]})}})(),()=>f.abort()},[e==null?void 0:e.ref]),!e)return null;const d=o==="ok"?"var(--color-installed, #2F6A4A)":o==="failed"?"var(--color-error, #b91c1c)":"var(--color-accent, #2f6f8f)",u=o==="ok"?"✔":o==="failed"?"✘":"…",p=o==="ok"?"Installed":o==="failed"?"Install failed":"Installing";return t.jsxs("div",{role:"status","aria-live":"polite","data-vskill-install-toast":!0,style:{position:"fixed",bottom:16,right:16,width:"min(420px, 92vw)",background:"var(--color-paper, #fff)",border:"1px solid var(--border-default, rgba(0,0,0,0.12))",borderLeft:`3px solid ${d}`,borderRadius:6,boxShadow:"0 10px 20px -6px rgba(0,0,0,0.18)",zIndex:90,fontFamily:"var(--font-sans)",overflow:"hidden"},children:[t.jsxs("button",{type:"button",onClick:()=>c(f=>!f),style:{display:"flex",alignItems:"center",gap:10,width:"100%",padding:"10px 12px",border:"none",background:"transparent",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},children:[t.jsx("span",{"aria-hidden":!0,style:{fontSize:16,color:d,width:16,textAlign:"center"},children:o==="running"?t.jsx(P0,{}):u}),t.jsxs("span",{style:{flex:1,minWidth:0},children:[t.jsxs("span",{style:{fontSize:12,fontWeight:600,color:"var(--text-primary)"},children:[p,": ",e.plugin,t.jsxs("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-primary)",marginLeft:4},children:["@",e.marketplace]})]}),!i&&n.length>0&&t.jsx("span",{style:{display:"block",fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-primary)",marginTop:2,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:n[n.length-1]})]}),t.jsx("span",{"aria-hidden":!0,style:{fontSize:10,color:"var(--text-primary)"},children:i?"▾":"▸"})]}),i&&t.jsx("pre",{style:{margin:0,padding:"0 12px 12px",maxHeight:180,overflowY:"auto",fontFamily:"var(--font-mono)",fontSize:10,lineHeight:1.5,color:"var(--text-secondary)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:n.length===0?"Waiting for output…":n.join(`
87
+ `)})]})}function P0(){return t.jsx("span",{"aria-hidden":!0,style:{display:"inline-block",width:10,height:10,borderRadius:"50%",border:"2px solid var(--color-accent, #2f6f8f)",borderTopColor:"transparent",animation:"vskill-spin 800ms linear infinite"},children:t.jsx("style",{children:"@keyframes vskill-spin { to { transform: rotate(360deg); } }"})})}async function $0(e,r){const s=await((r==null?void 0:r.fetchImpl)??fetch)("/api/studio/remove-skill",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!s.ok){const o=await s.json().catch(()=>({}));throw new Error(o.error||`remove-skill failed: HTTP ${s.status}`)}return await s.json()}async function M0(e){if(typeof navigator<"u"&&navigator.clipboard){await navigator.clipboard.writeText(e);return}throw new Error("Clipboard API unavailable in this environment")}function D0({agentId:e,agentDisplayName:r,blob:n,pasteInstructionsUrl:s,docsUrl:o,scopeDowngradeWarning:a,onClose:i,writeClipboardImpl:c}){const d=l.useRef(null),[u,p]=l.useState(!1),[f,h]=l.useState(null);l.useEffect(()=>{const g=x=>{x.key==="Escape"&&(x.preventDefault(),i())};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[i]);const m=l.useCallback(async()=>{const g=c??M0;try{await g(n),p(!0),h(null)}catch(x){h(x instanceof Error?x.message:String(x))}},[n,c]);return typeof document>"u"?null:$r.createPortal(t.jsx("div",{"data-testid":"clipboard-export-dialog-backdrop",role:"presentation",onClick:g=>{g.target===g.currentTarget&&i()},style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",backdropFilter:"blur(4px)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"min(10vh, 80px)",zIndex:10040},children:t.jsxs("div",{ref:d,"data-testid":"clipboard-export-dialog","data-agent-id":e,role:"dialog","aria-modal":"true","aria-label":`Copy skill to ${r}`,style:{position:"relative",width:"100%",maxWidth:640,margin:"0 1rem",background:"var(--bg-surface, #FFFFFF)",color:"var(--text-primary, #191919)",borderRadius:8,border:"1px solid var(--color-rule, #E8E1D6)",boxShadow:"0 20px 60px rgba(0,0,0,0.18)",overflow:"hidden",maxHeight:"80vh",display:"flex",flexDirection:"column"},children:[t.jsxs("div",{style:{padding:"0.875rem 1.125rem",borderBottom:"1px solid var(--color-rule, #E8E1D6)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{style:{fontFamily:"var(--font-serif, serif)",fontSize:16,fontWeight:500},children:["Copy to ",r]}),t.jsx("button",{type:"button","data-testid":"clipboard-export-dialog-close",onClick:i,"aria-label":"Close",style:{background:"transparent",border:"none",cursor:"pointer",fontSize:18,color:"var(--text-secondary, #5A5651)",padding:"0 4px",lineHeight:1},children:"×"})]}),t.jsxs("div",{style:{padding:"1rem 1.125rem",overflowY:"auto",display:"flex",flexDirection:"column",gap:"0.75rem"},children:[a&&t.jsx("div",{"data-testid":"clipboard-export-scope-warning",role:"status",style:{padding:"0.625rem 0.875rem",background:"color-mix(in srgb, var(--color-own, #f59e0b) 14%, transparent)",border:"1px solid color-mix(in srgb, var(--color-own, #f59e0b) 45%, transparent)",borderRadius:6,fontSize:12,color:"var(--text-primary, #191919)"},children:a}),t.jsxs("div",{style:{fontSize:12,color:"var(--text-secondary, #5A5651)",lineHeight:1.5},children:["Click ",t.jsx("strong",{children:"Copy"})," below, then paste the skill into"," ",r,".",s?t.jsxs(t.Fragment,{children:[" ",t.jsx("a",{"data-testid":"clipboard-export-paste-instructions-link",href:s,target:"_blank",rel:"noreferrer noopener",style:{color:"var(--accent-text, var(--text-primary))",textDecoration:"underline"},children:"Open paste instructions →"})]}):null]}),t.jsx("pre",{"data-testid":"clipboard-export-blob",style:{margin:0,padding:"0.75rem",background:"var(--surface-2, #F6F4EE)",border:"1px solid var(--color-rule, #E8E1D6)",borderRadius:6,fontFamily:"var(--font-mono, monospace)",fontSize:12,lineHeight:1.5,overflowX:"auto",maxHeight:"40vh",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:n}),f&&t.jsxs("div",{"data-testid":"clipboard-export-error",role:"alert",style:{fontSize:12,color:"var(--color-error, #dc2626)"},children:["Copy failed: ",f]})]}),t.jsxs("div",{style:{padding:"0.75rem 1.125rem",borderTop:"1px solid var(--color-rule, #E8E1D6)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"0.75rem"},children:[t.jsx("div",{style:{display:"flex",gap:"0.625rem"},children:o&&t.jsxs("a",{"data-testid":"clipboard-export-docs-link",href:o,target:"_blank",rel:"noreferrer noopener",style:{fontSize:12,color:"var(--text-secondary)",textDecoration:"underline"},children:[r," docs"]})}),t.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[t.jsx("button",{type:"button","data-testid":"clipboard-export-dialog-cancel",onClick:i,style:{padding:"0.5rem 0.875rem",borderRadius:6,border:"1px solid var(--color-rule, #E8E1D6)",background:"transparent",color:"var(--text-primary)",cursor:"pointer",fontSize:13,fontFamily:"var(--font-sans)"},children:"Close"}),t.jsx("button",{type:"button","data-testid":"clipboard-export-copy",onClick:m,style:{padding:"0.5rem 1rem",borderRadius:6,border:"1px solid var(--text-primary, #191919)",background:u?"var(--color-ok, #22c55e)":"var(--text-primary, #191919)",color:"var(--bg-surface, #FFFFFF)",cursor:"pointer",fontSize:13,fontWeight:600,fontFamily:"var(--font-sans)"},children:u?"Copied ✓":"Copy"})]})]})]})}),document.body)}function F0(e,r){const n=e.split(/[.-]/).map(o=>Number.parseInt(o,10)),s=r.split(/[.-]/).map(o=>Number.parseInt(o,10));for(let o=0;o<Math.max(n.length,s.length);o++){const a=Number.isFinite(n[o])?n[o]:0,i=Number.isFinite(s[o])?s[o]:0;if(a!==i)return a-i}return 0}function z0(e,r,n,s){if(!n)return{kind:"not-installed"};const o=n.scopes[r],a=r==="project"?"user":"project",i=n.scopes[a],c=o.installed&&o.installedAgentTools.includes(e),d=i.installed&&i.installedAgentTools.includes(e);if(!c)return d?{kind:"installed-other-scope",otherScope:a,version:i.version}:{kind:"not-installed"};const u=o.version;if(!u||!s)return{kind:"installed-current",version:u};const p=F0(u,s);return p===0?{kind:"installed-current",version:u}:p<0?{kind:"update-available",installed:u,target:s}:{kind:"newer-installed",installed:u,target:s}}const B0=Object.freeze({"claude-cli":"claude-code","codex-cli":"codex"});function qi(e){return e?B0[e]??e:null}function _0(e){var r,n;return((r=e.find(s=>s.detected&&s.installMode==="filesystem"))==null?void 0:r.id)??((n=e.find(s=>s.installMode==="filesystem"))==null?void 0:n.id)??null}function O0(e){switch(e){case"installed":return"Installed";case"exported":return"Exported";case"skipped":return"Skipped";case"error":return"Error"}}function $o(e){switch(e){case"installed":return"var(--color-ok, #22c55e)";case"exported":return"var(--accent-text, #3b82f6)";case"skipped":return"var(--text-tertiary)";case"error":return"var(--color-error, #dc2626)"}}function W0({skill:e,skillDisplayName:r,scope:n,targetVersion:s,activeAgentId:o,preCheckedAgentIds:a,onClose:i,onSuccess:c,fetchSupportedAgentsImpl:d,installToAgentsImpl:u,startInstallStreamImpl:p,fetchInstallStateImpl:f,removeSkillImpl:h,writeClipboardImpl:m}){var ge;const g=l.useRef(null),[x,v]=l.useState("loading"),[b,y]=l.useState([]),[j,S]=l.useState(null),[w,R]=l.useState(new Set),[k,E]=l.useState(null),[C,N]=l.useState({}),[I,P]=l.useState(null),[L,B]=l.useState(0),[T,$]=l.useState(new Set),[M,F]=l.useState([]),[W,le]=l.useState(null),U=l.useRef(null);l.useEffect(()=>{const se=fe=>{fe.key==="Escape"&&(W||(fe.preventDefault(),fe.stopPropagation(),x!=="installing"&&i()))};return document.addEventListener("keydown",se,!0),()=>document.removeEventListener("keydown",se,!0)},[W,x,i]),l.useEffect(()=>{let se=!1;return(d??Ld)().then(z=>{if(se)return;y(z);const q=new Set,Z=qi(o);Z&&z.some(J=>J.id===Z)&&q.add(Z);for(const J of a??[]){const ue=qi(J);ue&&z.some(de=>de.id===ue)&&q.add(ue)}if(q.size===0){const J=_0(z);J&&q.add(J)}R(q),v("select")}).catch(z=>{se||(S(z instanceof Error?z.message:String(z)),v("error"))}),()=>{se=!0}},[d,o,a]),l.useEffect(()=>()=>{var se;try{(se=U.current)==null||se.close()}catch{}},[]),l.useEffect(()=>{let se=!1;return(f??(z=>ie.getSkillInstallState(z)))(e).then(z=>{se||P(z)},()=>{se||P(null)}),()=>{se=!0}},[e,f,L]);const H=l.useMemo(()=>X1(b),[b]),ee=l.useCallback(se=>{R(fe=>{const z=new Set(fe);return z.has(se)?z.delete(se):z.add(se),z})},[]),K=l.useCallback(()=>{R(()=>{const se=new Set;for(const fe of b)fe.detected&&se.add(fe.id);return se})},[b]),X=l.useCallback(()=>{R(new Set)},[]),G=l.useCallback(()=>{var se;if(x!=="installing"){try{(se=U.current)==null||se.close()}catch{}i()}},[x,i]),he=l.useCallback(async()=>{if(w.size===0)return;E(null),N({}),v("installing");const se=Array.from(w),fe=u??q1,z=p??Y1;try{const{jobId:q,streamPath:Z}=await fe({skill:e,agentIds:se,scope:n});U.current=z(Z??q,{onResult:J=>{N(ue=>({...ue,[J.agentId]:J}))},onDone:J=>{const ue={},de=J.success===!1?typeof J.error=="string"&&J.error.trim()||"Install failed before any target reported a result.":null;for(const we of se)ue[we]=de?{agentId:we,status:"error",detail:de}:{agentId:we,status:"skipped"};if(de)E(de);else for(const we of J.results??[])ue[we.agentId]=we;N(we=>{var Re;const Ie={...ue};for(const[je,$e]of Object.entries(we))((Re=Ie[je])==null?void 0:Re.status)==="skipped"&&$e.status!=="skipped"&&(Ie[je]=$e);if(!Object.values(Ie).some(je=>je.status==="installed"||je.status==="exported"||je.status==="error")){const je="Install finished without writing any selected target.";for(const $e of se)Ie[$e]={agentId:$e,status:"error",detail:je};E(je)}const Ye=Object.values(Ie),Q=Ye.filter(je=>je.status==="exported"&&typeof je.blob=="string");return Q.length>0&&(F(Q),le(Q[0]??null)),globalThis.setTimeout(()=>{try{c==null||c(Ye)}catch{}},0),Ie}),B(we=>we+1),v("done")},onError:J=>{E(J.message),v("error")}})}catch(q){E(q instanceof Error?q.message:String(q)),v("error")}},[w,e,n,u,p,c]),A=l.useCallback(async se=>{const fe=h??$0;$(z=>{const q=new Set(z);return q.add(se),q});try{const z=await fe({skill:e,agentIds:[se],scope:n});if(typeof window<"u")try{window.dispatchEvent(new CustomEvent("studio:skill-installed",{detail:{skill:e,scope:n}}))}catch{}B(q=>q+1),z.errors.length>0&&E(`Remove failed for ${z.errors[0].agentId}: ${z.errors[0].message}`)}catch(z){E(z instanceof Error?z.message:String(z))}finally{$(z=>{const q=new Set(z);return q.delete(se),q})}},[h,e,n]),O=l.useCallback(()=>{F(se=>{const fe=se.slice(1);return le(fe[0]??null),fe})},[]),V=l.useMemo(()=>b.filter(se=>se.detected).length,[b]);if(typeof document>"u")return null;const re=w.size===0||x==="installing",ce=w.size===0?"Select at least one target":void 0,ne=`Install ${r??e} to:`,ve=n==="project"?"Project scope — writes under <project>/.claude/skills (or each tool's local dir)":"User scope — writes under ~/.claude/skills (or each tool's global dir)";return $r.createPortal(t.jsxs(t.Fragment,{children:[t.jsx("div",{"data-testid":"install-targets-modal-backdrop",role:"presentation",onClick:se=>{se.target===se.currentTarget&&G()},style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",backdropFilter:"blur(4px)",display:"flex",alignItems:"flex-start",justifyContent:"center",paddingTop:"min(8vh, 64px)",zIndex:10020},children:t.jsxs("div",{ref:g,"data-testid":"install-targets-modal",role:"dialog","aria-modal":"true","aria-label":ne,style:{position:"relative",width:"100%",maxWidth:640,margin:"0 1rem",background:"var(--bg-surface, #FFFFFF)",color:"var(--text-primary, #191919)",borderRadius:8,border:"1px solid var(--color-rule, #E8E1D6)",boxShadow:"0 20px 60px rgba(0,0,0,0.18)",overflow:"hidden",maxHeight:"84vh",display:"flex",flexDirection:"column"},children:[t.jsxs("div",{style:{padding:"0.875rem 1.125rem",borderBottom:"1px solid var(--color-rule, #E8E1D6)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"0.75rem"},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,minWidth:0},children:[t.jsx("div",{"data-testid":"install-targets-modal-title",style:{fontFamily:"var(--font-serif, serif)",fontSize:16,fontWeight:500},children:ne}),t.jsx("div",{"data-testid":"install-targets-modal-scope-line",style:{fontSize:11,color:"var(--text-secondary)",fontFamily:"var(--font-mono)"},children:ve})]}),t.jsx("button",{type:"button","data-testid":"install-targets-modal-close",onClick:G,"aria-label":"Close",disabled:x==="installing",style:{background:"transparent",border:"none",cursor:x==="installing"?"not-allowed":"pointer",fontSize:18,color:"var(--text-secondary, #5A5651)",padding:"0 4px",lineHeight:1,opacity:x==="installing"?.4:1},children:"×"})]}),t.jsxs("div",{style:{padding:"0.75rem 1.125rem",overflowY:"auto",flex:1},children:[x==="loading"&&t.jsx("div",{"data-testid":"install-targets-modal-loading",style:{fontSize:12,color:"var(--text-secondary)"},children:"Loading agents…"}),j&&x==="error"&&b.length===0&&t.jsxs("div",{"data-testid":"install-targets-modal-load-error",role:"alert",style:{fontSize:12,color:"var(--color-error, #dc2626)"},children:["Failed to load agents: ",j]}),(x==="select"||x==="installing"||x==="done"||x==="error"&&b.length>0)&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:"0.5rem",marginBottom:"0.625rem"},children:[t.jsxs("div",{style:{fontSize:11,color:"var(--text-secondary)",fontFamily:"var(--font-mono)"},children:[w.size," selected · ",V," detected"]}),t.jsxs("div",{style:{display:"flex",gap:"0.375rem"},children:[t.jsx("button",{type:"button","data-testid":"install-targets-select-all-detected",onClick:K,disabled:x==="installing"||V===0,style:Yi(),children:"Select all detected"}),t.jsx("button",{type:"button","data-testid":"install-targets-clear",onClick:X,disabled:x==="installing"||w.size===0,style:Yi(),children:"Clear"})]})]}),x==="installing"&&t.jsxs("div",{"data-testid":"install-targets-modal-installing-status",role:"status","aria-live":"polite",style:{margin:"0 0 0.75rem 0",padding:"0.625rem 0.875rem",borderRadius:6,border:"1px solid var(--color-rule, #E8E1D6)",background:"var(--surface-2, #F6F4EE)",color:"var(--text-primary)",fontSize:12},children:["Installing ",r??e," to ",w.size," target",w.size===1?"":"s","…"]}),t.jsx(eo,{testId:"install-targets-section-dropin",title:"Drop-in",description:"Filesystem install — Claude-style SKILL.md drops in unchanged.",agents:H.dropIn,selected:w,results:C,phase:x,onToggle:ee,scope:n,installState:I,targetVersion:s??null,removingAgents:T,onRemove:A}),t.jsx(eo,{testId:"install-targets-section-format-converted",title:"Format-converted",description:"Auto-converted to the tool's native format on install.",agents:H.formatConverted,selected:w,results:C,phase:x,onToggle:ee,scope:n,installState:I,targetVersion:s??null,removingAgents:T,onRemove:A}),t.jsx(eo,{testId:"install-targets-section-cloud",title:"Cloud only (paste required)",description:"No local filesystem — opens a paste-ready blob.",agents:H.cloud,selected:w,results:C,phase:x,onToggle:ee,tierBadge:"T3",pathOverride:"Copy to clipboard",scope:n,installState:I,targetVersion:s??null,removingAgents:T,onRemove:A})]}),x==="done"&&t.jsx(H0,{results:Object.values(C),agents:b}),(x==="error"||x==="done")&&k&&t.jsx("div",{"data-testid":"install-targets-modal-install-error",role:"alert",style:{marginTop:"0.75rem",padding:"0.625rem 0.875rem",borderRadius:6,background:"color-mix(in srgb, var(--color-error, #dc2626) 12%, transparent)",border:"1px solid color-mix(in srgb, var(--color-error, #dc2626) 45%, transparent)",color:"var(--text-primary)",fontSize:12},children:k})]}),t.jsxs("div",{style:{padding:"0.75rem 1.125rem",borderTop:"1px solid var(--color-rule, #E8E1D6)",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:"0.5rem"},children:[t.jsx("button",{type:"button","data-testid":"install-targets-modal-cancel",onClick:G,disabled:x==="installing",style:{padding:"0.5rem 0.875rem",borderRadius:6,border:"1px solid var(--color-rule, #E8E1D6)",background:"transparent",color:"var(--text-primary)",cursor:x==="installing"?"not-allowed":"pointer",fontSize:13,fontFamily:"var(--font-sans)",opacity:x==="installing"?.5:1},children:x==="done"?"Close":"Cancel"}),t.jsx("button",{type:"button","data-testid":"install-targets-modal-install",onClick:he,disabled:re||x==="done","aria-disabled":re||x==="done",title:ce,style:{padding:"0.5rem 1.125rem",borderRadius:6,border:"1px solid var(--text-primary, #191919)",background:re||x==="done"?"var(--bg-surface, #FFFFFF)":"var(--text-primary, #191919)",color:re||x==="done"?"var(--text-secondary, #5A5651)":"var(--bg-surface, #FFFFFF)",cursor:re||x==="done"?"not-allowed":"pointer",fontSize:13,fontWeight:600,fontFamily:"var(--font-sans)",opacity:re&&x!=="done"?.6:1},children:x==="installing"?"Installing…":x==="done"?"Done":`Install (${w.size})`})]})]})}),W&&t.jsx(D0,{agentId:W.agentId,agentDisplayName:((ge=b.find(se=>se.id===W.agentId))==null?void 0:ge.displayName)??W.agentId,blob:W.blob??"",pasteInstructionsUrl:W.pasteInstructionsUrl,docsUrl:W.docsUrl,scopeDowngradeWarning:W.detail&&W.detail.includes("project-scoped")?W.detail:void 0,onClose:O,writeClipboardImpl:m})]}),document.body)}function eo({testId:e,title:r,description:n,agents:s,selected:o,results:a,phase:i,onToggle:c,tierBadge:d,pathOverride:u,scope:p,installState:f,targetVersion:h,removingAgents:m,onRemove:g}){return s.length===0?null:t.jsxs("div",{"data-testid":e,style:{marginTop:"0.625rem"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:"0.5rem",padding:"0 0 0.25rem 0"},children:[t.jsx("div",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:"var(--text-tertiary)"},children:r}),t.jsx("div",{style:{fontSize:11,color:"var(--text-tertiary)"},children:n})]}),t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2},children:s.map(x=>{const v=o.has(x.id),b=a[x.id],y=i==="installing"||i==="done",j=u??(p==="project"?x.resolvedLocalDir:x.resolvedGlobalDir),S=z0(x.id,p,f,h),w=m.has(x.id);return t.jsxs("label",{"data-testid":`install-targets-row-${x.id}`,"data-checked":v?"true":"false","data-detected":x.detected?"true":"false",style:{display:"flex",alignItems:"center",gap:"0.625rem",padding:"0.375rem 0.5rem",borderRadius:4,cursor:y?"default":"pointer",background:v?"color-mix(in srgb, var(--accent-surface) 8%, transparent)":"transparent"},children:[t.jsx("input",{type:"checkbox","data-testid":`install-targets-checkbox-${x.id}`,checked:v,disabled:y,onChange:()=>c(x.id),style:{margin:0}}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[t.jsx("span",{style:{fontSize:13},children:x.displayName}),!x.detected&&t.jsx("span",{"data-testid":`install-targets-undetected-badge-${x.id}`,style:{fontSize:9,padding:"1px 6px",borderRadius:8,background:"color-mix(in srgb, var(--text-tertiary) 18%, transparent)",color:"var(--text-secondary)",letterSpacing:"0.04em",textTransform:"uppercase"},children:"Not detected"}),d&&t.jsx("span",{style:{fontSize:9,padding:"1px 6px",borderRadius:8,background:"color-mix(in srgb, var(--color-own, #f59e0b) 14%, transparent)",color:"var(--text-secondary)",letterSpacing:"0.04em",textTransform:"uppercase"},children:d}),t.jsx(U0,{agentId:x.id,badge:S,isRemoving:w,onRemove:g})]}),t.jsx("div",{title:j,"data-testid":`install-targets-path-${x.id}`,style:{fontFamily:"var(--font-mono)",fontSize:10,color:"var(--text-tertiary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:j})]}),b&&t.jsx("span",{"data-testid":`install-targets-status-${x.id}`,"data-status":b.status,style:{fontSize:11,padding:"1px 8px",borderRadius:10,background:`color-mix(in srgb, ${$o(b.status)} 16%, transparent)`,color:$o(b.status),fontFamily:"var(--font-mono)"},children:O0(b.status)})]},x.id)})})]})}function H0({results:e,agents:r}){return e.length===0?null:t.jsxs("div",{"data-testid":"install-targets-results-toast",role:"status","aria-live":"polite",style:{marginTop:"0.875rem",padding:"0.75rem 0.875rem",borderRadius:6,border:"1px solid var(--color-rule, #E8E1D6)",background:"var(--surface-2, #F6F4EE)",display:"flex",flexDirection:"column",gap:"0.375rem"},children:[t.jsx("div",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:"var(--text-tertiary)",marginBottom:"0.125rem"},children:"Install results"}),e.map(n=>{const s=r.find(i=>i.id===n.agentId),o=n.status==="installed"?n.path??n.detail:n.status==="exported"?n.detail&&n.detail.includes("project-scoped")?n.detail:"Copied to clipboard":n.status==="error"?n.detail??"Unknown error":n.detail??"",a=n.status==="installed"?"✓":n.status==="exported"?"⧉":n.status==="skipped"?"·":"✗";return t.jsxs("div",{"data-testid":`install-targets-result-row-${n.agentId}`,"data-status":n.status,style:{display:"flex",alignItems:"flex-start",gap:"0.5rem",fontSize:12},children:[t.jsx("span",{"aria-hidden":"true",style:{color:$o(n.status),fontWeight:600,fontFamily:"var(--font-mono)",width:"0.875rem",flexShrink:0},children:a}),t.jsxs("span",{style:{flex:1,minWidth:0},children:[t.jsx("span",{style:{fontWeight:500},children:(s==null?void 0:s.displayName)??n.agentId}),o&&t.jsx("span",{style:{marginLeft:"0.5rem",color:"var(--text-secondary)",fontFamily:"var(--font-mono)",fontSize:11,wordBreak:"break-all"},children:o}),n.status==="exported"&&n.pasteInstructionsUrl&&t.jsxs(t.Fragment,{children:[" ",t.jsx("a",{"data-testid":`install-targets-result-paste-link-${n.agentId}`,href:n.pasteInstructionsUrl,target:"_blank",rel:"noreferrer noopener",style:{fontSize:11,color:"var(--accent-text, var(--text-primary))",textDecoration:"underline"},children:"open paste instructions →"})]})]})]},n.agentId)})]})}function U0({agentId:e,badge:r,isRemoving:n,onRemove:s}){if(r.kind==="not-installed")return null;let o,a,i;switch(r.kind){case"installed-current":o=r.version?`Installed v${r.version}`:"Installed",a="color-mix(in srgb, var(--color-ok, #22c55e) 14%, transparent)",i="var(--color-ok, #22c55e)";break;case"update-available":o=`Update v${r.installed} → v${r.target}`,a="color-mix(in srgb, var(--color-own, #f59e0b) 18%, transparent)",i="var(--color-own, #f59e0b)";break;case"newer-installed":o=`Newer v${r.installed} (target v${r.target})`,a="color-mix(in srgb, var(--accent-text, #3b82f6) 14%, transparent)",i="var(--accent-text, #3b82f6)";break;case"installed-other-scope":o=r.version?`Installed v${r.version} (${r.otherScope} scope)`:`Installed (${r.otherScope} scope)`,a="color-mix(in srgb, var(--text-tertiary) 18%, transparent)",i="var(--text-secondary)";break}const c=r.kind!=="installed-other-scope";return t.jsxs(t.Fragment,{children:[t.jsx("span",{"data-testid":`install-targets-status-badge-${e}`,"data-badge-kind":r.kind,style:{fontSize:9,padding:"1px 6px",borderRadius:8,background:a,color:i,letterSpacing:"0.04em",textTransform:"uppercase",whiteSpace:"nowrap"},children:o}),c&&t.jsx("button",{type:"button","data-testid":`install-targets-remove-${e}`,disabled:n,onClick:d=>{d.preventDefault(),d.stopPropagation(),s(e)},style:{fontSize:10,padding:"1px 6px",borderRadius:8,background:"transparent",border:"1px solid var(--color-rule, #E8E1D6)",color:"var(--color-error, #dc2626)",cursor:n?"wait":"pointer",fontFamily:"var(--font-sans)"},children:n?"Removing…":"Remove"})]})}function Yi(){return{padding:"3px 8px",borderRadius:4,border:"1px solid var(--color-rule, #E8E1D6)",background:"transparent",color:"var(--text-secondary)",cursor:"pointer",fontSize:11,fontFamily:"var(--font-sans)"}}const V0=3e3,G0={anthropic:"Anthropic",openai:"OpenAI",openrouter:"OpenRouter"};function Ji(e){return e==="anthropic"||e==="openai"||e==="openrouter"}function K0(){const{toast:e}=ss(),r=l.useRef(new Map),n=l.useCallback(s=>{if(!Ji(s.provider))return;const o=Date.now(),a=r.current.get(s.provider)??0;if(o-a<V0)return;r.current.set(s.provider,o);const i=G0[s.provider];e({message:`${i} API key invalid or missing. Open Settings →`,severity:"error",action:{label:"Open Settings",onInvoke:()=>{typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:open-settings",{detail:{provider:s.provider}}))}}})},[e]);return l.useEffect(()=>{function s(o){const a=o.detail;!a||!Ji(a.provider)||n({provider:a.provider})}return window.addEventListener("studio:api-key-error",s),()=>window.removeEventListener("studio:api-key-error",s)},[n]),{report:n}}const Md="vskill.studio.prefs";function Dd(){try{return typeof window>"u"?null:window.localStorage??null}catch{return null}}function Fd(){const e=Dd();if(!e)return{};try{const r=e.getItem(Md);if(!r)return{};const n=JSON.parse(r);return n&&typeof n=="object"&&!Array.isArray(n)?n:{}}catch{return{}}}function q0(e,r){const n=Dd();if(n)try{const o={...Fd(),[e]:r};n.setItem(Md,JSON.stringify(o))}catch{}}function Y0(e,r){const s=Fd()[e];return s===void 0?r:s}const Xi={open:!1,x:0,y:0,skill:null};function J0(e,r){return{open:!0,x:e.clientX,y:e.clientY,skill:r}}function Bt(e,r="info"){typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:toast",{detail:{message:e,severity:r}}))}function X0(e){typeof window>"u"||window.dispatchEvent(new CustomEvent("studio:request-delete",{detail:{skill:e}}))}async function Qi(e,r){var n;try{await ie.revealInEditor(e.plugin,e.skill,r),Bt(_.toasts.openingInEditor,"info")}catch(s){if(s instanceof qt){const o=(n=s.details)==null?void 0:n.error;if(s.status===404){Bt(_.toasts.skillNotFound,"error");return}if(s.status===500&&o==="no_editor"){Bt(_.toasts.noEditor,"error");return}}Bt(_.toasts.openFailed,"error")}}async function Q0(e,r){var n;switch(e){case"copy-path":try{(n=navigator.clipboard)==null||n.writeText(r.dir)}catch{Bt(_.toasts.permissionDenied,"error");return}Bt(_.toasts.pathCopied,"info");return;case"reveal":case"edit":await Qi(r,"SKILL.md");return;case"open":await Qi(r);return;case"run-benchmark":Bt(_.toasts.benchmarkQueued,"info");return;case"duplicate":Bt(_.toasts.skillDuplicated,"info");return;case"clone":try{window.dispatchEvent(new CustomEvent("studio:request-clone",{detail:{skill:r}}))}catch{}return;case"update":Bt(_.toasts.skillUpdated,"info");return;case"uninstall":Bt(_.toasts.uninstallNotImplemented,"info");return;case"delete":X0(r);return;default:return}}function Z0(e){return e.startsWith("#/create")}function ek(e){return e.startsWith("#/updates")}function zd(e){const[r,n]=l.useState(()=>typeof window<"u"&&e(window.location.hash));return l.useEffect(()=>{function s(){n(e(window.location.hash))}return window.addEventListener("hashchange",s),s(),()=>window.removeEventListener("hashchange",s)},[]),r}function tk(){return zd(Z0)}function rk(){return zd(ek)}function nk(){var s,o;if(typeof navigator>"u")return"⌘⇧K";const e=((s=navigator.platform)==null?void 0:s.toUpperCase())??"",r=((o=navigator.userAgent)==null?void 0:o.toUpperCase())??"";return e.includes("MAC")||r.includes("MAC")?"⌘⇧K":"Ctrl+Shift+K"}function sk(){if(typeof window>"u"||typeof window.matchMedia!="function")return!1;try{return window.matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function ok(){const[e,r]=l.useState("⌘⇧K");l.useEffect(()=>{r(nk())},[]);const n=sk();function s(){window.dispatchEvent(new CustomEvent("openFindSkills"))}return t.jsxs("button",{type:"button",onClick:s,"aria-label":`Find verified skills — opens search (${e})`,title:`Find verified skills (${e})`,"data-testid":"find-skills-nav-button",style:{display:"inline-flex",alignItems:"center",gap:6,height:28,padding:"0 12px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-secondary)",fontSize:12,fontWeight:500,fontFamily:"var(--font-sans)",cursor:"pointer",letterSpacing:"0.01em"},children:[t.jsxs("svg",{"data-icon":"search","aria-hidden":"true",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("circle",{cx:"11",cy:"11",r:"8"}),t.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),t.jsx("span",{children:"Find skills"}),t.jsx("kbd",{"data-animated":n?"false":"true",style:{fontFamily:"var(--font-mono)",fontSize:11,color:"var(--text-faint)",border:"1px solid var(--border-default)",borderRadius:4,padding:"1px 5px",marginLeft:2,lineHeight:1},children:e})]})}function ak(){const e=pn(),[r,n]=l.useState(null),[s,o]=l.useState(!0),[a,i]=l.useState(!1),[c,d]=l.useState(null),[u,p]=l.useState(null),[f,h]=l.useState(!1),m=l.useRef(!1);l.useEffect(()=>{let j=!1;return(async()=>{try{const S=await e.getSignedInUser();j||n(S)}catch{}finally{j||o(!1)}})(),()=>{j=!0}},[e]);const g=l.useRef(null);l.useEffect(()=>{if(!a)return;function j(w){g.current&&(g.current.contains(w.target)||i(!1))}function S(w){w.key==="Escape"&&i(!1)}return document.addEventListener("pointerdown",j),document.addEventListener("keydown",S),()=>{document.removeEventListener("pointerdown",j),document.removeEventListener("keydown",S)}},[a]);const x=l.useCallback(async j=>{try{if(typeof e.openExternalUrl=="function"){await e.openExternalUrl(j);return}}catch(S){console.warn("open external URL:",S)}window.open(j,"_blank","noopener,noreferrer")},[e]),v=l.useCallback(async()=>{p(null),h(!0),m.current=!1;let j=null;const S=w=>{j=w,p(w)};try{const w=await e.startGithubDeviceFlow();window.__vskillOauthState=w.userCode,d(w),x(w.verificationUri);let R=Math.max(1,w.interval);const k=Date.now()+w.expiresIn*1e3;for(;!m.current&&Date.now()<k&&(await ck(R*1e3,()=>m.current),!m.current);){const E=await e.pollGithubDeviceFlow();if(E.status==="granted"){n(E.user),d(null),h(!1);return}if(E.status!=="pending"){if(E.status==="slow_down"){R=Math.max(R+1,E.newInterval);continue}if(E.status==="denied"){S("Sign-in was denied at GitHub. You can try again.");break}if(E.status==="expired"){S("Sign-in code expired. Try again to get a fresh code.");break}if(E.status==="no-flow"){S("Sign-in state lost. Please retry.");break}S(E.message);break}}!m.current&&!j&&S("Sign-in code expired. Try again to get a fresh code.")}catch(w){S(w instanceof Error?w.message:String(w))}finally{h(!1)}},[e,x]),b=l.useCallback(()=>{m.current=!0,d(null),p(null),h(!1)},[]),y=l.useCallback(async()=>{i(!1);try{await e.signOut()}catch(j){console.warn("sign-out:",j)}n(null)},[e]);return s?t.jsx("div",{"data-slot":"user-dropdown-placeholder",style:{width:28,height:28}}):r?t.jsxs("div",{"data-slot":"user-dropdown",style:{position:"relative"},ref:g,children:[t.jsxs("button",{type:"button","data-slot":"user-chip",onClick:()=>i(j=>!j),"aria-label":`Signed in as ${r.login}`,"aria-haspopup":"menu","aria-expanded":a,title:`Signed in as ${r.login}`,style:{display:"inline-flex",alignItems:"center",gap:6,height:28,padding:"0 6px 0 4px",borderRadius:14,border:"1px solid var(--border-default)",background:"var(--surface-1, transparent)",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font-sans)",cursor:"pointer"},children:[t.jsx("img",{src:r.avatar_url,alt:"",width:20,height:20,onError:j=>{const S=uk(r.login);j.currentTarget.src!==S&&(j.currentTarget.src=S)},style:{borderRadius:"50%",display:"block"}}),t.jsx("span",{style:{maxWidth:100,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.login})]}),a&&t.jsxs("div",{role:"menu","data-slot":"user-menu",style:{position:"absolute",top:"calc(100% + 4px)",right:0,minWidth:180,background:"var(--surface-2, #1a1d22)",border:"1px solid var(--border-default)",borderRadius:8,padding:4,boxShadow:"0 4px 16px rgba(0,0,0,0.32)",zIndex:50},children:[t.jsx(Zi,{label:"View on GitHub",onClick:()=>{x(`https://github.com/${r.login}`),i(!1)}}),t.jsx(Zi,{label:"Sign out",onClick:y})]})]}):t.jsxs("div",{"data-slot":"user-dropdown",style:{position:"relative"},ref:g,children:[t.jsxs("button",{type:"button","data-slot":"sign-in-button",onClick:v,disabled:f,"aria-label":"Sign in with GitHub",title:"Sign in with GitHub",style:{display:"inline-flex",alignItems:"center",gap:6,height:28,padding:"0 10px",borderRadius:6,border:"1px solid var(--border-default)",background:"var(--surface-1, transparent)",color:"var(--text-primary)",fontSize:12,fontFamily:"var(--font-sans)",cursor:f?"wait":"pointer"},children:[t.jsx(lk,{size:14}),f?"Signing in…":"Sign in"]}),c&&t.jsx(ik,{response:c,error:u,onCancel:b,onOpenGithub:()=>void x(c.verificationUri),onRetry:v})]})}function ik({response:e,error:r,onCancel:n,onOpenGithub:s,onRetry:o}){const[a,i]=l.useState("idle"),c=l.useRef(null);l.useEffect(()=>()=>{c.current!=null&&window.clearTimeout(c.current)},[]);let d=e.verificationUri;try{const p=new URL(e.verificationUri);d=`${p.host}${p.pathname}`}catch{}const u=l.useCallback(async()=>{c.current!=null&&window.clearTimeout(c.current);try{await dk(e.verificationUri),i("copied"),c.current=window.setTimeout(()=>i("idle"),1500)}catch{i("failed"),c.current=window.setTimeout(()=>i("idle"),1500)}},[e.verificationUri]);return t.jsxs("div",{role:"dialog","aria-label":"Sign in with GitHub","data-slot":"sign-in-dialog",style:{position:"absolute",top:"calc(100% + 8px)",right:0,width:320,background:"var(--surface-2, #1a1d22)",border:"1px solid var(--border-default)",borderRadius:10,padding:16,boxShadow:"0 6px 24px rgba(0,0,0,0.42)",zIndex:60,fontFamily:"var(--font-sans)",color:"var(--text-primary)"},children:[t.jsx("div",{style:{fontSize:13,marginBottom:8},children:"Authorize Skill Studio in GitHub. If the browser did not open, use the button or copy the link."}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:12},children:[t.jsx("code",{"aria-label":"Authorization URL",title:e.verificationUri,style:{flex:1,fontFamily:"var(--font-mono)",fontSize:12,padding:"6px 10px",background:"var(--surface-1, #0f1115)",border:"1px solid var(--border-default)",borderRadius:6,textAlign:"left",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:d}),t.jsx("button",{type:"button",onClick:u,"aria-label":"Copy sign-in link",title:a==="copied"?"Copied":"Copy sign-in link",style:{height:32,padding:"0 10px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-primary)",cursor:"pointer",fontSize:12},children:a==="copied"?"Copied":a==="failed"?"Copy failed":"Copy link"})]}),t.jsx("div",{"aria-live":"polite","data-slot":"copy-feedback",style:{minHeight:14,fontSize:11,color:"var(--text-secondary)",marginBottom:8},children:a==="copied"?"Link copied":a==="failed"?"Copy failed":""}),r?t.jsx("div",{role:"alert",style:{fontSize:12,color:"var(--color-danger, #d44)",marginBottom:10},children:r}):t.jsx("div",{style:{fontSize:11,color:"var(--text-secondary)",marginBottom:10},children:"Waiting for you to authorize on GitHub…"}),t.jsxs("div",{style:{display:"flex",gap:8},children:[t.jsx("button",{type:"button","data-slot":"open-github-button",onClick:s,style:{flex:1,height:32,borderRadius:6,border:"1px solid var(--color-action, #2F5B8E)",background:"var(--color-action, #2F5B8E)",color:"var(--color-action-ink, #FFFFFF)",cursor:"pointer",fontSize:12,fontWeight:600},children:"Authorize in GitHub"}),r?t.jsx("button",{type:"button",onClick:o,style:{height:32,padding:"0 12px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-primary)",cursor:"pointer",fontSize:12},children:"Try again"}):null,t.jsx("button",{type:"button",onClick:n,style:{height:32,padding:"0 12px",borderRadius:6,border:"1px solid var(--border-default)",background:"transparent",color:"var(--text-primary)",cursor:"pointer",fontSize:12},children:"Cancel"})]})]})}function Zi({label:e,onClick:r}){return t.jsx("button",{type:"button",role:"menuitem",onClick:r,style:{display:"block",width:"100%",textAlign:"left",padding:"8px 12px",background:"transparent",color:"var(--text-primary)",border:"none",cursor:"pointer",fontSize:13,fontFamily:"inherit",borderRadius:4},onMouseEnter:n=>{n.currentTarget.style.background="var(--surface-3, #25292f)"},onMouseLeave:n=>{n.currentTarget.style.background="transparent"},children:e})}function lk({size:e=16}){return t.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24","aria-hidden":"true",fill:"currentColor",children:t.jsx("path",{d:"M12 .5C5.65.5.5 5.65.5 12c0 5.08 3.29 9.39 7.86 10.91.58.1.79-.25.79-.56v-2.04c-3.2.7-3.87-1.37-3.87-1.37-.52-1.32-1.27-1.67-1.27-1.67-1.04-.71.08-.7.08-.7 1.15.08 1.76 1.18 1.76 1.18 1.02 1.75 2.69 1.24 3.34.95.1-.74.4-1.24.72-1.52-2.55-.29-5.24-1.27-5.24-5.66 0-1.25.45-2.27 1.18-3.07-.12-.29-.51-1.46.11-3.04 0 0 .96-.31 3.15 1.18a10.91 10.91 0 0 1 5.74 0c2.18-1.49 3.14-1.18 3.14-1.18.62 1.58.23 2.75.11 3.04.74.8 1.18 1.82 1.18 3.07 0 4.4-2.69 5.36-5.25 5.65.41.36.77 1.07.77 2.16v3.2c0 .31.21.67.8.55C20.21 21.39 23.5 17.08 23.5 12 23.5 5.65 18.35.5 12 .5z"})})}async function ck(e,r){const s=Date.now()+e;for(;Date.now()<s;){if(r())return;const o=s-Date.now();await new Promise(a=>setTimeout(a,Math.min(250,o)))}}async function dk(e){var s;try{await((s=navigator.clipboard)==null?void 0:s.writeText(e));return}catch{}const r=document.createElement("textarea");r.value=e,r.setAttribute("readonly","true"),r.style.position="fixed",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.focus(),r.select();const n=document.execCommand("copy");if(r.remove(),!n)throw new Error("copy failed")}function uk(e){return`https://github.com/${encodeURIComponent(e)}.png?size=40`}const Bd=l.createContext(null);function pk(e){if(typeof window>"u")return()=>{};if(!window.__TAURI_INTERNALS__)return()=>{};const n=()=>{document.visibilityState==="visible"&&e()};return document.addEventListener("visibilitychange",n),()=>{document.removeEventListener("visibilitychange",n)}}function fk({children:e,projectRoots:r=[]}){const n=pn(),[s,o]=l.useState(null),[a,i]=l.useState(!1),[c,d]=l.useState(null),u=l.useRef(r);u.current=r;const p=l.useRef(n);p.current=n;const f=l.useCallback(async()=>{i(!0),d(null);try{const x=await p.current.quotaGet(u.current);o(x)}catch(x){d(x instanceof Error?x.message:String(x))}finally{i(!1)}},[]),h=l.useCallback(async(x=!1)=>{i(!0),d(null);try{const v=await p.current.quotaForceSync(u.current,x);o(v)}catch(v){d(v instanceof Error?v.message:String(v));try{const b=await p.current.quotaGet(u.current);o(b)}catch{}}finally{i(!1)}},[]),m=l.useCallback(async()=>p.current.quotaCanCreateSkill(u.current),[]);l.useEffect(()=>{f();const x=pk(()=>{f()}),v=setInterval(()=>{f()},6e4);return()=>{x(),clearInterval(v)}},[f]);const g=l.useMemo(()=>({snapshot:s,refreshing:a,error:c,forceSync:h,canCreateSkill:m}),[s,a,c,h,m]);return t.jsx(Bd.Provider,{value:g,children:e})}function aa(){const e=l.useContext(Bd);if(!e)throw new Error("useQuota() called outside <QuotaProvider>");return e}function hk(){const{snapshot:e}=aa();if(!e)return{tier:"free",isPro:!1,isFree:!0,isEnterprise:!1,skillCount:0,skillLimit:null,isUnlimited:!0,gracePeriodDaysRemaining:0,isFresh:!1,loaded:!1,localSkillCount:0};const r=e.cache;if(!r)return{tier:"free",isPro:!1,isFree:!0,isEnterprise:!1,skillCount:0,skillLimit:null,isUnlimited:!0,gracePeriodDaysRemaining:e.daysRemaining,isFresh:e.isFresh,loaded:!0,localSkillCount:e.localSkillCount};const n=r.response.tier,s=n==="pro"||n==="enterprise",o=r.response.skillLimit;return{tier:n,isPro:s,isFree:n==="free",isEnterprise:n==="enterprise",skillCount:r.response.skillCount,skillLimit:o,isUnlimited:o===null,gracePeriodDaysRemaining:e.daysRemaining,isFresh:e.isFresh,loaded:!0,localSkillCount:e.localSkillCount}}const _d="https://verified-skill.com/pricing",el="paywall-modal-title",tl="paywall-modal-body";function mk({open:e,onClose:r,onProceed:n,skillName:s}){const o=pn(),{forceSync:a,snapshot:i}=aa(),c=l.useRef(null),d=l.useRef(null),u=l.useRef(null);l.useEffect(()=>{if(!e)return;let f=!1;return(async()=>{try{await a(!0)}catch{}})(),()=>{f=!0}},[e,a]),l.useEffect(()=>{var h;if(!e)return;const f=(h=i==null?void 0:i.cache)==null?void 0:h.response.tier;(f==="pro"||f==="enterprise")&&(n==null||n(),r())},[e,i,n,r]),l.useEffect(()=>{if(!e)return;u.current=typeof document<"u"?document.activeElement:null;const f=setTimeout(()=>{var m;return(m=d.current)==null?void 0:m.focus()},0),h=m=>{if(m.key==="Escape"){m.preventDefault(),r();return}if(m.key!=="Tab")return;const g=c.current;if(!g)return;const x=Array.from(g.querySelectorAll('button:not([disabled]),[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])'));if(x.length===0)return;const v=x[0],b=x[x.length-1],y=typeof document<"u"?document.activeElement:null;m.shiftKey&&y===v?(m.preventDefault(),b.focus()):!m.shiftKey&&y===b&&(m.preventDefault(),v.focus())};return document.addEventListener("keydown",h),()=>{clearTimeout(f),document.removeEventListener("keydown",h),u.current instanceof HTMLElement&&u.current.focus()}},[e,r]);const p=l.useCallback(()=>{o.openExternalUrl(_d)},[o]);return e?t.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":el,"aria-describedby":tl,"data-testid":"paywall-modal",style:xk,children:[t.jsx("div",{onClick:r,style:{position:"absolute",inset:0,background:"rgba(0,0,0,0.45)"}}),t.jsxs("div",{ref:c,style:gk,children:[t.jsx("h2",{id:el,style:vk,children:"Connect private repositories with Skill Studio Pro"}),t.jsxs("p",{id:tl,style:yk,children:["Pro adds private repo connections, priority support, and unlimited skills. Free users keep all current features for public repos.",s?t.jsxs(t.Fragment,{children:[" ",t.jsxs("span",{style:{color:"var(--color-muted, #888)"},children:["(",s," won’t connect until you upgrade.)"]})]}):null]}),t.jsxs("div",{style:bk,children:[t.jsx("button",{type:"button",onClick:r,"data-testid":"paywall-maybe-later",style:jk,children:"Maybe later"}),t.jsx("button",{ref:d,type:"button",onClick:p,"data-testid":"paywall-upgrade",style:kk,children:"Upgrade to Pro"})]})]})]}):null}const xk={position:"fixed",inset:0,zIndex:1e3,display:"flex",alignItems:"center",justifyContent:"center"},gk={position:"relative",width:"min(420px, 92vw)",background:"var(--color-bg, #ffffff)",color:"var(--color-text, #111111)",borderRadius:12,padding:"24px 24px 16px",boxShadow:"0 16px 48px rgba(0,0,0,0.25)",fontFamily:"var(--font-system, -apple-system, system-ui)"},vk={margin:0,fontSize:18,fontWeight:600},yk={marginTop:12,marginBottom:24,fontSize:14,lineHeight:1.5,color:"var(--color-text-soft, #444)"},bk={display:"flex",justifyContent:"flex-end",gap:12},Od={padding:"8px 16px",borderRadius:6,fontSize:13,fontWeight:500,cursor:"pointer",border:"1px solid transparent"},kk={...Od,background:"var(--color-accent, #cb4b16)",color:"#ffffff"},jk={...Od,background:"transparent",color:"var(--color-text, #111111)",borderColor:"var(--color-border, #cccccc)"};function wk({forcedTone:e}){const{snapshot:r,refreshing:n,forceSync:s}=aa(),o=(r==null?void 0:r.daysRemaining)??0,a=(r==null?void 0:r.isFresh)??!1;if(!((r==null?void 0:r.cache)??null))return null;const c=e??Sk(o,a);if(!c)return null;const d=l.useCallback(()=>{s(!0)},[s]),u=c==="danger"?"Sign in to refresh your subscription. Some features will be locked until you reconnect.":"Sync to verify your subscription — last synced 7 days ago.";return t.jsxs("div",{role:"status","aria-live":"polite","data-testid":"quota-grace-banner","data-tone":c,style:{...Ck,background:c==="danger"?"var(--color-danger-bg, rgba(220, 50, 47, 0.12))":"var(--color-warn-bg, rgba(203, 75, 22, 0.12))",color:c==="danger"?"var(--color-danger, #dc322f)":"var(--color-warn, #cb4b16)",borderColor:c==="danger"?"var(--color-danger, #dc322f)":"var(--color-warn, #cb4b16)"},children:[t.jsx("span",{style:{fontWeight:500},children:u}),t.jsx("button",{type:"button",onClick:d,disabled:n,"data-testid":"quota-grace-sync",style:Ek,children:n?"Syncing…":"Sync now"})]})}function Sk(e,r){return r?e<=1?"warn":null:"danger"}const Ck={display:"inline-flex",alignItems:"center",gap:12,padding:"6px 12px",borderRadius:6,fontSize:12,border:"1px solid currentColor",fontFamily:"var(--font-system, -apple-system, system-ui)"},Ek={padding:"2px 10px",borderRadius:4,border:"1px solid currentColor",background:"transparent",color:"inherit",cursor:"pointer",fontSize:12,fontWeight:500};function Nk({active:e,onClick:r,badgeCount:n}){return t.jsxs("button",{type:"button","data-testid":"account-sidebar-entry","data-active":e?"true":"false",onClick:r,style:{display:"flex",alignItems:"center",gap:8,width:"100%",textAlign:"left",padding:"8px 14px",fontSize:13,fontWeight:e?600:500,fontFamily:"var(--font-sans)",color:"var(--text-primary)",background:e?"var(--bg-canvas, #f3f4f6)":"transparent",border:"none",borderLeft:`3px solid ${e?"var(--color-accent, #2563eb)":"transparent"}`,cursor:"pointer"},children:[t.jsx("span",{"aria-hidden":!0,children:"👤"}),t.jsx("span",{style:{flex:1},children:"Account"}),n&&n>0?t.jsx("span",{style:{padding:"1px 6px",fontSize:10,fontWeight:600,background:"var(--color-accent, #2563eb)",color:"#fff",borderRadius:999},children:n}):null]})}const Rk={green:"#16a34a",amber:"#f59e0b",grey:"#9ca3af",red:"#dc2626"},Tk={green:"Synced",amber:"Reauth needed",grey:"Idle",red:"Error"};function Ik({repos:e,viewMode:r="table",pendingActions:n,onOpenOnGitHub:s,onResync:o,onDisconnect:a,onConnectNew:i,now:c=new Date}){const d=Ak(e),u=e.filter(f=>f.isPrivate).slice().sort((f,h)=>f.repoFullName.localeCompare(h.repoFullName)),p=e.filter(f=>!f.isPrivate).slice().sort((f,h)=>f.repoFullName.localeCompare(h.repoFullName));return t.jsxs("div",{"data-testid":"connected-repos-table",style:{width:"100%"},children:[t.jsx(Pk,{summary:d,onConnectNew:i,showConnectAction:!0}),e.length===0?t.jsx($k,{}):t.jsxs(t.Fragment,{children:[u.length>0?t.jsx(rl,{kind:"private",repos:u,viewMode:r,pendingActions:n,onOpenOnGitHub:s,onResync:o,onDisconnect:a,now:c}):null,p.length>0?t.jsx(rl,{kind:"public",repos:p,viewMode:r,pendingActions:n,onOpenOnGitHub:s,onResync:o,onDisconnect:a,now:c}):null]})]})}function rl({kind:e,repos:r,viewMode:n,pendingActions:s,onOpenOnGitHub:o,onResync:a,onDisconnect:i,now:c}){const d=e==="private";return t.jsxs("section",{"data-testid":`repos-section-${e}`,"data-visibility":e,style:{marginBottom:16,border:d?"1px solid rgba(245,158,11,0.45)":"1px solid var(--border-default, #e5e7eb)",borderRadius:8,overflow:"hidden"},children:[t.jsxs("header",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap",padding:"8px 12px",background:d?"rgba(245,158,11,0.10)":"var(--bg-canvas, #f9fafb)",borderBottom:d?"1px solid rgba(245,158,11,0.35)":"1px solid var(--border-default, #e5e7eb)",fontFamily:"var(--font-sans)",fontSize:12},children:[t.jsx(Lk,{kind:e}),t.jsx("strong",{style:{color:d?"#92400e":"var(--text-primary)",textTransform:"uppercase",letterSpacing:"0.05em",fontSize:11},children:d?"Private repositories":"Public repositories"}),t.jsx("span",{style:{color:"var(--text-tertiary)"},children:"·"}),t.jsx("span",{style:{color:"var(--text-secondary)",fontVariantNumeric:"tabular-nums"},children:r.length}),t.jsx("span",{style:{flex:1}}),t.jsx("span",{style:{color:"var(--text-secondary)",fontSize:11},children:d?"Skills here stay scoped to your account / org.":"Skills here are eligible for the public registry."})]}),n==="cards"?t.jsx(Dk,{repos:r,pendingActions:s,onOpenOnGitHub:o,onResync:a,onDisconnect:i,now:c}):t.jsx(Mk,{repos:r,pendingActions:s,onOpenOnGitHub:o,onResync:a,onDisconnect:i,now:c})]})}function Lk({kind:e}){return e==="private"?t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",style:{flexShrink:0,color:"#92400e"},children:[t.jsx("rect",{x:"2.75",y:"7",width:"10.5",height:"6.75",rx:"1.25",fill:"currentColor",fillOpacity:"0.15",stroke:"currentColor",strokeWidth:"1.25"}),t.jsx("path",{d:"M5 7V5.25C5 3.59 6.34 2.25 8 2.25C9.66 2.25 11 3.59 11 5.25V7",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",fill:"none"}),t.jsx("circle",{cx:"8",cy:"10.25",r:"0.9",fill:"currentColor"})]}):t.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",style:{flexShrink:0,color:"var(--text-secondary)"},children:[t.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.25",fill:"none"}),t.jsx("path",{d:"M2 8H14M8 2C9.5 4 10 6 10 8C10 10 9.5 12 8 14M8 2C6.5 4 6 6 6 8C6 10 6.5 12 8 14",stroke:"currentColor",strokeWidth:"1",fill:"none"})]})}function Ak(e){let r=0,n=0;for(const s of e)s.isPrivate?n++:r++;return{total:e.length,publicCount:r,privateCount:n}}function Pk({summary:e,onConnectNew:r,showConnectAction:n}){return t.jsxs("div",{"data-testid":"repos-summary-chip",style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",marginBottom:12,background:"var(--bg-canvas, #f9fafb)",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:8,fontFamily:"var(--font-sans)",fontSize:13},children:[t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:4,minWidth:0},children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap",color:"var(--text-primary)",fontWeight:500},children:[t.jsx("strong",{children:e.total}),t.jsxs("span",{children:[e.total===1?"repo":"repos"," connected"]}),t.jsx("span",{"aria-hidden":!0,style:{color:"var(--text-tertiary)"},children:"·"}),t.jsxs("span",{title:"Public repos","aria-label":"Public repos",children:[t.jsx(Mo,{isPrivate:!1})," ",e.publicCount]}),t.jsx("span",{"aria-hidden":!0,style:{color:"var(--text-tertiary)"},children:"·"}),t.jsxs("span",{title:"Private repos","aria-label":"Private repos",children:[t.jsx(Mo,{isPrivate:!0})," ",e.privateCount]})]}),t.jsx("div",{style:{fontSize:12,color:"var(--text-secondary)",lineHeight:1.4},children:"Public repositories work on Free. Private repository connections require Pro and GitHub App access."})]}),n?t.jsx("button",{type:"button",onClick:r,"data-testid":"connect-new-repo-button",style:{padding:"6px 14px",fontSize:13,fontWeight:500,fontFamily:"inherit",border:"1px solid var(--color-accent, #2563eb)",background:"var(--color-accent, #2563eb)",color:"#fff",borderRadius:6,cursor:"pointer",whiteSpace:"nowrap"},children:"Connect GitHub App"}):null]})}function Mo({isPrivate:e}){return t.jsx("span",{"aria-label":e?"Private repository":"Public repository",title:e?"Private repository":"Public repository",style:{display:"inline-flex",alignItems:"center",padding:"2px 6px",borderRadius:999,border:"1px solid var(--border-default, #e5e7eb)",color:e?"#92400e":"#166534",background:e?"rgba(245, 158, 11, 0.12)":"rgba(22, 163, 74, 0.10)",fontSize:11,fontWeight:600,lineHeight:1,whiteSpace:"nowrap"},children:e?"Private":"Public"})}function $k(){return t.jsxs("div",{"data-testid":"repos-empty-state",style:{textAlign:"center",padding:"32px 24px",background:"var(--bg-canvas, #f9fafb)",border:"1px dashed var(--border-default, #e5e7eb)",borderRadius:8,fontFamily:"var(--font-sans)"},children:[t.jsx("div",{style:{fontSize:15,fontWeight:600,color:"var(--text-primary)",marginBottom:6},children:"No repositories connected yet."}),t.jsxs("div",{style:{fontSize:13,color:"var(--text-secondary)",lineHeight:1.5},children:["Click the ",t.jsx("strong",{style:{color:"var(--text-primary)"},children:"Connect GitHub App"})," ","button above. Install the app, pick the repos to share, then Skill Studio syncs public repos on Free and private repos on Pro."]})]})}function Mk({repos:e,pendingActions:r,onOpenOnGitHub:n,onResync:s,onDisconnect:o,now:a}){return t.jsxs("table",{"data-testid":"repos-table",style:{width:"100%",borderCollapse:"collapse",fontFamily:"var(--font-sans)",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{borderBottom:"1px solid var(--border-default, #e5e7eb)"},children:[t.jsx(Gr,{children:"Repository"}),t.jsx(Gr,{align:"right",children:"Skills"}),t.jsx(Gr,{children:"Status"}),t.jsx(Gr,{children:"Last activity"}),t.jsx(Gr,{align:"right",style:{width:48},children:t.jsx("span",{style:{visibility:"hidden"},children:"Actions"})})]})}),t.jsx("tbody",{children:e.map(i=>t.jsx(Fk,{repo:i,pending:r==null?void 0:r[i.repoId],onOpenOnGitHub:n,onResync:s,onDisconnect:o,now:a},i.repoId))})]})}function Dk({repos:e,pendingActions:r,onOpenOnGitHub:n,onResync:s,onDisconnect:o,now:a}){return t.jsx("div",{"data-testid":"repos-card-list",style:{display:"flex",flexDirection:"column",gap:8},children:e.map(i=>t.jsx(zk,{repo:i,pending:r==null?void 0:r[i.repoId],onOpenOnGitHub:n,onResync:s,onDisconnect:o,now:a},i.repoId))})}function Fk({repo:e,pending:r,onOpenOnGitHub:n,onResync:s,onDisconnect:o,now:a}){const[i,c]=l.useState(!1);return t.jsxs("tr",{"data-testid":`repo-row-${e.repoId}`,style:{borderBottom:"1px solid var(--border-default, #e5e7eb)"},children:[t.jsx(Kr,{children:t.jsx(Wd,{repo:e})}),t.jsx(Kr,{align:"right",children:e.skillsCount===0?t.jsx("span",{style:{color:"var(--text-tertiary)"},children:"—"}):t.jsx("span",{style:{fontVariantNumeric:"tabular-nums"},children:e.skillsCount})}),t.jsx(Kr,{children:t.jsx(Hd,{status:e.syncStatus,errorMessage:e.lastErrorMessage})}),t.jsx(Kr,{children:t.jsx("span",{style:{color:"var(--text-secondary)"},children:Vd(e.lastActivityAt,a)})}),t.jsx(Kr,{align:"right",children:t.jsx(Ud,{repo:e,pending:r,isOpen:i,onToggle:()=>c(d=>!d),onClose:()=>c(!1),onOpenOnGitHub:n,onResync:s,onDisconnect:o})})]})}function zk({repo:e,pending:r,onOpenOnGitHub:n,onResync:s,onDisconnect:o,now:a}){const[i,c]=l.useState(!1);return t.jsxs("div",{"data-testid":`repo-card-${e.repoId}`,style:{padding:14,border:"1px solid var(--border-default, #e5e7eb)",borderRadius:8,background:"var(--bg-elevated, #fff)",display:"flex",flexDirection:"column",gap:10},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12},children:[t.jsx(Wd,{repo:e}),t.jsx(Ud,{repo:e,pending:r,isOpen:i,onToggle:()=>c(d=>!d),onClose:()=>c(!1),onOpenOnGitHub:n,onResync:s,onDisconnect:o})]}),t.jsx(to,{label:"Skills",children:e.skillsCount===0?"—":String(e.skillsCount)}),t.jsx(to,{label:"Status",children:t.jsx(Hd,{status:e.syncStatus,errorMessage:e.lastErrorMessage})}),t.jsx(to,{label:"Last activity",children:Vd(e.lastActivityAt,a)})]})}function Wd({repo:e}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[t.jsx(Mo,{isPrivate:e.isPrivate}),t.jsx("span",{style:{fontFamily:"var(--font-mono)",fontSize:13,color:"var(--text-primary)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.repoFullName})]})}function Hd({status:e,errorMessage:r}){const n=Rk[e],s=Tk[e],o=e==="red"&&r?r:s;return t.jsxs("span",{"data-testid":`status-${e}`,title:o,style:{display:"inline-flex",alignItems:"center",gap:6},children:[t.jsx("span",{"aria-hidden":!0,style:{width:8,height:8,borderRadius:"50%",background:n,display:"inline-block"}}),t.jsx("span",{style:{fontSize:12,color:"var(--text-secondary)"},children:s})]})}function to({label:e,children:r}){return t.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:12},children:[t.jsx("span",{style:{color:"var(--text-tertiary)"},children:e}),t.jsx("span",{style:{color:"var(--text-primary)"},children:r})]})}function Ud({repo:e,pending:r,isOpen:n,onToggle:s,onClose:o,onOpenOnGitHub:a,onResync:i,onDisconnect:c}){return t.jsxs("div",{style:{position:"relative",display:"inline-block"},children:[t.jsx("button",{type:"button","aria-label":`Actions for ${e.repoFullName}`,"aria-expanded":n,"aria-haspopup":"menu","data-testid":`kebab-${e.repoId}`,onClick:s,disabled:r==="disconnect",style:{width:28,height:28,padding:0,border:"1px solid transparent",background:"transparent",borderRadius:4,cursor:r==="disconnect"?"not-allowed":"pointer",color:"var(--text-secondary)",fontSize:16,lineHeight:1},children:"⋯"}),n&&t.jsxs("div",{role:"menu","data-testid":`kebab-menu-${e.repoId}`,style:{position:"absolute",top:"100%",right:0,marginTop:4,minWidth:180,background:"var(--bg-elevated, #fff)",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:6,boxShadow:"0 6px 18px rgba(0,0,0,0.12)",zIndex:10,padding:4},children:[t.jsx(ro,{onClick:()=>{a(e),o()},children:"Open on GitHub"}),t.jsx(ro,{disabled:r==="resync",onClick:async()=>{await i(e),o()},children:r==="resync"?"Resyncing…":"Resync now"}),t.jsx(ro,{danger:!0,onClick:async()=>{await c(e),o()},children:"Disconnect"})]})]})}function ro({children:e,onClick:r,disabled:n,danger:s}){return t.jsx("button",{type:"button",role:"menuitem",onClick:r,disabled:n,style:{display:"block",width:"100%",textAlign:"left",padding:"6px 10px",fontSize:13,fontFamily:"inherit",background:"transparent",border:"none",borderRadius:4,cursor:n?"not-allowed":"pointer",color:s?"#dc2626":"var(--text-primary)",opacity:n?.6:1},children:e})}function Gr({children:e,align:r="left",style:n}){return t.jsx("th",{style:{textAlign:r,padding:"10px 12px",fontWeight:600,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--text-secondary)",...n},children:e})}function Kr({children:e,align:r="left"}){return t.jsx("td",{style:{textAlign:r,padding:"12px 12px",verticalAlign:"middle"},children:e})}function Vd(e,r){if(!e)return"Never";const n=new Date(e).getTime();if(Number.isNaN(n))return"Never";const s=r.getTime()-n;if(s<0)return"Just now";const o=Math.floor(s/1e3);if(o<60)return"Just now";const a=Math.floor(o/60);if(a<60)return`${a}m ago`;const i=Math.floor(a/60);if(i<24)return`${i}h ago`;const c=Math.floor(i/24);if(c<30)return`${c}d ago`;const d=Math.floor(c/30);return d<12?`${d}mo ago`:`${Math.floor(c/365)}y ago`}const no=80,so=280;function Bk({profile:e,onSubmit:r,saving:n=!1,errorMessage:s=null}){const[o,a]=l.useState(e.displayName),[i,c]=l.useState(e.bio??""),[d,u]=l.useState(e.publicProfile);l.useEffect(()=>{a(e.displayName),c(e.bio??""),u(e.publicProfile)},[e.userId,e.displayName,e.bio,e.publicProfile]);const p=o!==e.displayName||i!==(e.bio??"")||d!==e.publicProfile,f=o.length>no,h=i.length>so,m=o.trim().length>0&&!f&&!h;async function g(x){if(x.preventDefault(),!p||!m||n)return;const v={};o!==e.displayName&&(v.displayName=o),i!==(e.bio??"")&&(v.bio=i||null),d!==e.publicProfile&&(v.publicProfile=d),await r(v)}return t.jsxs("form",{"data-testid":"profile-form",onSubmit:g,style:{display:"flex",flexDirection:"column",gap:18,maxWidth:560,fontFamily:"var(--font-sans)"},children:[t.jsx(_k,{profile:e}),t.jsxs(oo,{label:"Display name",htmlFor:"profile-display-name",children:[t.jsx("input",{id:"profile-display-name","data-testid":"profile-display-name",type:"text",value:o,maxLength:no+20,disabled:n,onChange:x=>a(x.target.value),style:ao}),t.jsx(nl,{current:o.length,max:no})]}),t.jsx(oo,{label:"GitHub handle",htmlFor:"profile-github-handle",caption:"Synced from GitHub",children:t.jsx("input",{id:"profile-github-handle",type:"text",value:e.githubHandle,readOnly:!0,"aria-readonly":"true",style:{...ao,background:"var(--bg-canvas, #f3f4f6)"}})}),t.jsxs(oo,{label:"Public bio",htmlFor:"profile-bio",children:[t.jsx("textarea",{id:"profile-bio","data-testid":"profile-bio",value:i,maxLength:so+40,rows:3,disabled:n,onChange:x=>c(x.target.value),style:{...ao,fontFamily:"inherit",resize:"vertical"}}),t.jsx(nl,{current:i.length,max:so})]}),t.jsx(Ok,{label:"Public profile page",helper:"Your bio + public skills appear on a verified-skill.com/u/{handle} page.",checked:d,disabled:n,onChange:u}),s&&t.jsx("div",{role:"alert","data-testid":"profile-form-error",style:{padding:"8px 12px",background:"rgba(220, 38, 38, 0.08)",border:"1px solid rgba(220, 38, 38, 0.4)",color:"#991b1b",borderRadius:6,fontSize:13},children:s}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{type:"submit","data-testid":"profile-save-button",disabled:!p||!m||n,style:{padding:"8px 20px",fontSize:13,fontWeight:500,fontFamily:"inherit",border:"1px solid var(--color-accent, #2563eb)",background:!p||!m||n?"var(--bg-canvas, #f3f4f6)":"var(--color-accent, #2563eb)",color:!p||!m||n?"var(--text-tertiary, #9ca3af)":"#fff",borderColor:!p||!m||n?"var(--border-default, #e5e7eb)":"var(--color-accent, #2563eb)",borderRadius:6,cursor:!p||!m||n?"not-allowed":"pointer"},children:n?"Saving…":"Save changes"})})]})}function _k({profile:e}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:14},children:[e.avatarUrl?t.jsx("img",{src:e.avatarUrl,alt:`Avatar for ${e.githubHandle}`,width:56,height:56,style:{width:56,height:56,borderRadius:"50%",objectFit:"cover",border:"1px solid var(--border-default, #e5e7eb)",background:"var(--bg-canvas, #f3f4f6)"}}):t.jsx("div",{"aria-hidden":!0,style:{width:56,height:56,borderRadius:"50%",background:"var(--bg-canvas, #f3f4f6)",border:"1px solid var(--border-default, #e5e7eb)"}}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:16,fontWeight:600,color:"var(--text-primary)"},children:e.displayName||e.githubHandle}),t.jsxs("div",{style:{fontSize:12,color:"var(--text-secondary)"},children:["@",e.githubHandle]})]})]})}function oo({label:e,htmlFor:r,caption:n,children:s}){return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{htmlFor:r,style:{fontSize:13,fontWeight:500,color:"var(--text-primary)"},children:e}),s,n&&t.jsx("span",{style:{fontSize:11,color:"var(--text-tertiary)"},children:n})]})}function nl({current:e,max:r}){const n=e>r;return t.jsxs("span",{style:{alignSelf:"flex-end",fontSize:11,color:n?"#dc2626":"var(--text-tertiary)",fontVariantNumeric:"tabular-nums"},children:[e,"/",r]})}function Ok({label:e,helper:r,checked:n,disabled:s,onChange:o}){return t.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:10,cursor:s?"not-allowed":"pointer"},children:[t.jsx("input",{type:"checkbox","data-testid":"profile-public-toggle",checked:n,disabled:s,onChange:a=>o(a.target.checked),style:{marginTop:2}}),t.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:2},children:[t.jsx("span",{style:{fontSize:13,fontWeight:500,color:"var(--text-primary)"},children:e}),r&&t.jsx("span",{style:{fontSize:12,color:"var(--text-secondary)"},children:r})]})]})}const ao={width:"100%",padding:"8px 10px",fontSize:13,fontFamily:"inherit",color:"var(--text-primary)",background:"var(--bg-elevated, #fff)",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:6,boxSizing:"border-box"},Wk={free:{label:"Free",badge:"Open Source · MIT",bullets:["Unlimited public skills","Public GitHub repo connections","Community support"],upgradeLabel:"Upgrade to Pro"},pro:{label:"Pro",badge:"Active",bullets:["Hosted private skill storage","Connect private GitHub repos","Sync skills automatically","Priority email support"],upgradeLabel:"Talk to sales about Enterprise"},enterprise:{label:"Enterprise",badge:"Active",bullets:["Everything in Pro","SSO + audit log","Dedicated support","Custom contract"],upgradeLabel:null}};function Hk({tier:e,onUpgradeClick:r,showUpgradeCta:n=!0}){const s=Wk[e];return t.jsxs("div",{"data-testid":`plan-card-${e}`,style:{padding:20,border:"1px solid var(--border-default, #e5e7eb)",borderRadius:10,background:"var(--bg-elevated, #fff)",fontFamily:"var(--font-sans)",display:"flex",flexDirection:"column",gap:14},children:[t.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12},children:t.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:12},children:[t.jsx("h3",{style:{margin:0,fontSize:20,fontWeight:600,color:"var(--text-primary)"},children:s.label}),t.jsx("span",{"data-testid":"plan-card-badge",style:{padding:"2px 10px",fontSize:11,fontWeight:500,background:e==="free"?"rgba(37, 99, 235, 0.1)":"rgba(22, 163, 74, 0.1)",color:e==="free"?"#1d4ed8":"#15803d",borderRadius:999},children:s.badge})]})}),t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:12,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--text-secondary)",marginBottom:6},children:"What's included"}),t.jsx("ul",{style:{margin:0,paddingLeft:18,display:"flex",flexDirection:"column",gap:4,fontSize:13,color:"var(--text-primary)"},children:s.bullets.map(o=>t.jsx("li",{children:o},o))})]}),n&&s.upgradeLabel&&t.jsx("div",{children:t.jsx("button",{type:"button","data-testid":"plan-card-upgrade",onClick:r,disabled:!r,style:{padding:"8px 16px",fontSize:13,fontWeight:500,fontFamily:"inherit",background:r?"var(--color-accent, #2563eb)":"var(--bg-canvas, #f3f4f6)",color:r?"#fff":"var(--text-tertiary, #9ca3af)",border:`1px solid ${r?"var(--color-accent, #2563eb)":"var(--border-default, #e5e7eb)"}`,borderRadius:6,cursor:r?"pointer":"not-allowed"},children:s.upgradeLabel})})]})}const Uk=[{value:30,label:"30 days"},{value:90,label:"90 days"},{value:365,label:"1 year"},{value:0,label:"Never"}];function Vk({tokens:e,recentlyCreated:r,onDismissRecentlyCreated:n,onCreate:s,onRevoke:o,pendingRevokeId:a,creating:i=!1,now:c=new Date}){const[d,u]=l.useState(!1),[p,f]=l.useState(null);return t.jsxs("div",{"data-testid":"tokens-table-root",children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:12},children:[t.jsxs("div",{children:[t.jsx("h2",{style:{margin:0,fontSize:16,fontWeight:600,color:"var(--text-primary)"},children:"API tokens"}),t.jsx("p",{style:{margin:"4px 0 0",fontSize:12,color:"var(--text-secondary)"},children:"For CLI and automation access; repository sync uses GitHub connections instead."})]}),t.jsx("button",{type:"button","data-testid":"tokens-generate-button",onClick:()=>u(!0),disabled:i,style:{padding:"8px 14px",fontSize:13,fontWeight:500,fontFamily:"inherit",background:"var(--color-accent, #2563eb)",color:"#fff",border:"1px solid var(--color-accent, #2563eb)",borderRadius:6,cursor:i?"not-allowed":"pointer",opacity:i?.6:1},children:"Generate new token"})]}),t.jsx("div",{"data-testid":"tokens-scope-note",style:{marginBottom:12,padding:"10px 12px",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:8,background:"var(--bg-elevated, #fff)",color:"var(--text-secondary)",fontSize:12,lineHeight:1.45},children:"Keep this page for scripts that call verified-skill APIs. To connect public or private repositories, use Connected repositories."}),e.length===0?t.jsx(Gk,{onGenerateClick:()=>u(!0)}):t.jsxs("table",{"data-testid":"tokens-table",style:{width:"100%",borderCollapse:"collapse",fontFamily:"var(--font-sans)",fontSize:13},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{borderBottom:"1px solid var(--border-default, #e5e7eb)"},children:[t.jsx(br,{children:"Name"}),t.jsx(br,{children:"Prefix"}),t.jsx(br,{children:"Scopes"}),t.jsx(br,{children:"Last used"}),t.jsx(br,{children:"Created"}),t.jsx(br,{align:"right",children:"Actions"})]})}),t.jsx("tbody",{children:e.map(h=>t.jsxs("tr",{"data-testid":`token-row-${h.id}`,style:{borderBottom:"1px solid var(--border-default, #e5e7eb)",opacity:h.revokedAt?.55:1},children:[t.jsx(kr,{children:h.name}),t.jsx(kr,{children:t.jsxs("code",{style:{fontFamily:"var(--font-mono)",fontSize:12,color:"var(--text-secondary)"},children:[h.prefix,"…"]})}),t.jsx(kr,{children:h.scopes.join(", ")}),t.jsx(kr,{children:ol(h.lastUsedAt,c)}),t.jsx(kr,{children:ol(h.createdAt,c)}),t.jsx(kr,{align:"right",children:h.revokedAt?t.jsx("span",{style:{color:"var(--text-tertiary)"},children:"Revoked"}):t.jsx("button",{type:"button","data-testid":`token-revoke-${h.id}`,disabled:a===h.id,onClick:()=>f(h),style:{padding:"4px 10px",fontSize:12,fontFamily:"inherit",background:"transparent",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:4,color:"#dc2626",cursor:a===h.id?"not-allowed":"pointer"},children:a===h.id?"Revoking…":"Revoke"})})]},h.id))})]}),d&&t.jsx(Kk,{creating:i,onCancel:()=>u(!1),onSubmit:async h=>{await s(h),u(!1)}}),r&&t.jsx(qk,{created:r,onDismiss:()=>n==null?void 0:n()}),p&&t.jsx(Yk,{token:p,pending:a===p.id,onCancel:()=>f(null),onConfirm:async()=>{await o(p),f(null)}})]})}function Gk({onGenerateClick:e}){return t.jsxs("div",{"data-testid":"tokens-empty-state",style:{textAlign:"center",padding:"40px 20px",background:"var(--bg-canvas, #f9fafb)",border:"1px dashed var(--border-default, #e5e7eb)",borderRadius:8,fontFamily:"var(--font-sans)"},children:[t.jsx("div",{style:{fontSize:14,color:"var(--text-primary)",marginBottom:6},children:"No API tokens yet"}),t.jsx("div",{style:{fontSize:13,color:"var(--text-secondary)",marginBottom:14},children:"Generate one only for local CLI auth, CI, or another scripted integration. GitHub repository access is managed separately."}),t.jsx("button",{type:"button",onClick:e,style:{padding:"6px 14px",fontSize:13,fontFamily:"inherit",background:"var(--color-accent, #2563eb)",color:"#fff",border:"none",borderRadius:6,cursor:"pointer"},children:"Generate new token"})]})}function Kk({creating:e,onCancel:r,onSubmit:n}){const[s,o]=l.useState(""),[a,i]=l.useState(!0),[c,d]=l.useState(!1),[u,p]=l.useState(90),f=s.trim().length>0&&(a||c);return t.jsxs(ia,{title:"Generate new token",onDismiss:r,testId:"tokens-generate-modal",children:[t.jsx(io,{label:"Name",htmlFor:"token-name",children:t.jsx("input",{id:"token-name","data-testid":"token-name-input",type:"text",value:s,maxLength:64,disabled:e,onChange:h=>o(h.target.value),placeholder:"e.g. Build CI",style:al})}),t.jsx(io,{label:"Scopes",children:t.jsxs("div",{style:{display:"flex",gap:16},children:[t.jsx(sl,{label:"read",checked:a,disabled:e,onChange:i,testId:"scope-read"}),t.jsx(sl,{label:"write",checked:c,disabled:e,onChange:d,testId:"scope-write"})]})}),t.jsx(io,{label:"Expiry",children:t.jsx("select",{"data-testid":"token-expiry-select",value:u,disabled:e,onChange:h=>p(Number(h.target.value)),style:al,children:Uk.map(h=>t.jsx("option",{value:h.value,children:h.label},h.value))})}),t.jsxs(la,{children:[t.jsx(ca,{onClick:r,disabled:e,children:"Cancel"}),t.jsx(Gd,{disabled:!f||e,onClick:()=>{const h=[];a&&h.push("read"),c&&h.push("write"),n({name:s.trim(),scopes:h,expiresInDays:u})},children:e?"Generating…":"Generate"})]})]})}function qk({created:e,onDismiss:r}){const[n,s]=l.useState(!1);async function o(){try{await navigator.clipboard.writeText(e.plaintext),s(!0)}catch{}}return t.jsxs(ia,{title:"Token created",onDismiss:r,testId:"tokens-created-modal",children:[t.jsxs("p",{style:{margin:0,fontSize:13,color:"var(--text-primary)",background:"rgba(245, 158, 11, 0.12)",border:"1px solid rgba(245, 158, 11, 0.4)",padding:12,borderRadius:6},children:[t.jsx("strong",{children:"This is the only time you'll see this token."})," Store it somewhere safe — verified-skill never stores the plaintext."]}),t.jsx("div",{"data-testid":"tokens-plaintext",style:{fontFamily:"var(--font-mono)",fontSize:13,padding:12,background:"var(--bg-canvas, #f3f4f6)",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:6,wordBreak:"break-all",userSelect:"all"},children:e.plaintext}),t.jsxs(la,{children:[t.jsx(ca,{onClick:o,children:n?"Copied!":"Copy to clipboard"}),t.jsx(Gd,{onClick:r,children:"Done"})]})]})}function Yk({token:e,pending:r,onCancel:n,onConfirm:s}){return t.jsxs(ia,{title:`Revoke ${e.prefix}…?`,onDismiss:n,testId:"tokens-revoke-modal",children:[t.jsx("p",{style:{margin:0,fontSize:13,color:"var(--text-primary)"},children:"Any process using this token will fail immediately. This cannot be undone."}),t.jsxs(la,{children:[t.jsx(ca,{onClick:n,disabled:r,children:"Cancel"}),t.jsx(Jk,{disabled:r,onClick:()=>void s(),children:r?"Revoking…":"Revoke"})]})]})}function ia({title:e,testId:r,onDismiss:n,children:s}){return t.jsx("div",{role:"dialog","aria-modal":"true","aria-label":e,"data-testid":r,style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,fontFamily:"var(--font-sans)"},onClick:o=>{o.target===o.currentTarget&&n()},children:t.jsxs("div",{style:{width:"min(440px, calc(100vw - 32px))",background:"var(--bg-elevated, #fff)",borderRadius:10,border:"1px solid var(--border-default, #e5e7eb)",boxShadow:"0 18px 40px rgba(0,0,0,0.18)",padding:20,display:"flex",flexDirection:"column",gap:14},children:[t.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600,color:"var(--text-primary)"},children:e}),s]})})}function la({children:e}){return t.jsx("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:4},children:e})}function Gd({children:e,onClick:r,disabled:n}){return t.jsx("button",{type:"button",onClick:r,disabled:n,style:{padding:"8px 16px",fontSize:13,fontFamily:"inherit",background:n?"var(--bg-canvas, #f3f4f6)":"var(--color-accent, #2563eb)",color:n?"var(--text-tertiary)":"#fff",border:`1px solid ${n?"var(--border-default, #e5e7eb)":"var(--color-accent, #2563eb)"}`,borderRadius:6,cursor:n?"not-allowed":"pointer"},children:e})}function ca({children:e,onClick:r,disabled:n}){return t.jsx("button",{type:"button",onClick:r,disabled:n,style:{padding:"8px 16px",fontSize:13,fontFamily:"inherit",background:"transparent",color:"var(--text-primary)",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:6,cursor:n?"not-allowed":"pointer",opacity:n?.6:1},children:e})}function Jk({children:e,onClick:r,disabled:n}){return t.jsx("button",{type:"button",onClick:r,disabled:n,style:{padding:"8px 16px",fontSize:13,fontFamily:"inherit",background:n?"var(--bg-canvas, #f3f4f6)":"#dc2626",color:n?"var(--text-tertiary)":"#fff",border:"1px solid #dc2626",borderRadius:6,cursor:n?"not-allowed":"pointer",opacity:n?.6:1},children:e})}function io({label:e,htmlFor:r,children:n}){return t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[t.jsx("label",{htmlFor:r,style:{fontSize:12,fontWeight:500,color:"var(--text-primary)"},children:e}),n]})}function sl({label:e,checked:r,onChange:n,disabled:s,testId:o}){return t.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:13,cursor:s?"not-allowed":"pointer",color:"var(--text-primary)"},children:[t.jsx("input",{type:"checkbox","data-testid":o,checked:r,disabled:s,onChange:a=>n(a.target.checked)}),e]})}function br({children:e,align:r="left"}){return t.jsx("th",{style:{textAlign:r,padding:"10px 12px",fontWeight:600,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--text-secondary)"},children:e})}function kr({children:e,align:r="left"}){return t.jsx("td",{style:{textAlign:r,padding:"12px 12px",verticalAlign:"middle"},children:e})}function ol(e,r){if(!e)return"—";const n=new Date(e).getTime();if(Number.isNaN(n))return"—";const s=r.getTime()-n;if(s<6e4)return"Just now";const o=Math.floor(s/6e4);if(o<60)return`${o}m ago`;const a=Math.floor(o/60);if(a<24)return`${a}h ago`;const i=Math.floor(a/24);if(i<30)return`${i}d ago`;const c=Math.floor(i/30);return c<12?`${c}mo ago`:`${Math.floor(i/365)}y ago`}const al={width:"100%",padding:"8px 10px",fontSize:13,fontFamily:"inherit",color:"var(--text-primary)",background:"var(--bg-elevated, #fff)",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:6,boxSizing:"border-box"},Xk=[{key:"weeklyDigest",label:"Weekly digest",helper:"Daily/weekly digest emails ship in a future update.",defaultOn:!1},{key:"securityAlerts",label:"Security alerts",helper:"We'll always notify you about suspicious account activity.",forcedOn:!0,defaultOn:!0},{key:"commentReplies",label:"Comment replies",defaultOn:!0},{key:"productUpdates",label:"Product updates",helper:"Marketing emails — opt out anytime.",defaultOn:!1}];function Qk({prefs:e,onSubmit:r,saving:n=!1,errorMessage:s=null}){const[o,a]=l.useState(()=>il(e));l.useEffect(()=>{a(il(e))},[e]);const i=o.weeklyDigest!==e.weeklyDigest||o.commentReplies!==e.commentReplies||o.productUpdates!==e.productUpdates;function c(u,p){a(f=>({...f,[u]:p}))}async function d(u){u.preventDefault(),!(!i||n)&&await r({...o,securityAlerts:!0})}return t.jsxs("form",{"data-testid":"notifications-form",onSubmit:d,style:{display:"flex",flexDirection:"column",gap:16,maxWidth:560,fontFamily:"var(--font-sans)"},children:[t.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:Xk.map(u=>t.jsx(Zk,{meta:u,checked:u.forcedOn?!0:!!o[u.key],disabled:n||!!u.forcedOn,onChange:p=>{u.key!=="securityAlerts"&&c(u.key,p)}},u.key))}),s&&t.jsx("div",{role:"alert","data-testid":"notifications-form-error",style:{padding:"8px 12px",background:"rgba(220, 38, 38, 0.08)",border:"1px solid rgba(220, 38, 38, 0.4)",color:"#991b1b",borderRadius:6,fontSize:13},children:s}),t.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:t.jsx("button",{type:"submit","data-testid":"notifications-save-button",disabled:!i||n,style:{padding:"8px 20px",fontSize:13,fontWeight:500,fontFamily:"inherit",border:`1px solid ${!i||n?"var(--border-default, #e5e7eb)":"var(--color-accent, #2563eb)"}`,background:!i||n?"var(--bg-canvas, #f3f4f6)":"var(--color-accent, #2563eb)",color:!i||n?"var(--text-tertiary, #9ca3af)":"#fff",borderRadius:6,cursor:!i||n?"not-allowed":"pointer"},children:n?"Saving…":"Save preferences"})})]})}function Zk({meta:e,checked:r,disabled:n,onChange:s}){return t.jsxs("label",{"data-testid":`notif-row-${e.key}`,style:{display:"flex",alignItems:"flex-start",gap:10,padding:12,border:"1px solid var(--border-default, #e5e7eb)",borderRadius:6,background:"var(--bg-elevated, #fff)",cursor:n&&!e.forcedOn?"not-allowed":"pointer",opacity:n&&!e.forcedOn?.7:1},children:[t.jsx("input",{type:"checkbox","data-testid":`notif-checkbox-${e.key}`,checked:r,disabled:n,onChange:o=>s(o.target.checked),style:{marginTop:2}}),t.jsxs("span",{style:{display:"flex",flexDirection:"column",gap:4,flex:1},children:[t.jsxs("span",{style:{fontSize:13,fontWeight:500,color:"var(--text-primary)",display:"flex",alignItems:"center",gap:8},children:[e.label,e.forcedOn&&t.jsx("span",{style:{fontSize:10,fontWeight:500,padding:"2px 8px",background:"rgba(37, 99, 235, 0.1)",color:"#1d4ed8",borderRadius:999},children:"Always on"})]}),e.helper&&t.jsx("span",{style:{fontSize:12,color:"var(--text-secondary)"},children:e.helper})]})]})}function il(e){return{weeklyDigest:!!e.weeklyDigest,securityAlerts:!0,commentReplies:e.commentReplies??!0,productUpdates:!!e.productUpdates}}function ej({githubHandle:e,exports:r=[],onSignOutAll:n,onExportRequest:s,onDeleteAccount:o,pending:a,errorMessage:i=null}){const[c,d]=l.useState(!1),[u,p]=l.useState(!1);return t.jsxs("div",{"data-testid":"danger-zone",style:{display:"flex",flexDirection:"column",gap:14,fontFamily:"var(--font-sans)"},children:[t.jsx(lo,{title:"Sign out of all devices",description:"Revoke every active session and API token. You'll need to sign back in everywhere.",actionLabel:a!=null&&a.signOutAll?"Signing out…":"Sign out everywhere",actionDisabled:a==null?void 0:a.signOutAll,onClick:()=>d(!0)}),t.jsx(lo,{title:"Export my data",description:"Queue an export of your skills, profile, and connected-repo metadata. Download link emailed within 24 hours.",actionLabel:a!=null&&a.exportRequest?"Queuing…":"Export my data",actionDisabled:a==null?void 0:a.exportRequest,onClick:()=>void s(),children:t.jsx(tj,{exports:r})}),t.jsx(lo,{title:"Delete account",description:"Soft-delete your account. We retain your data for 30 days, then purge permanently. Connected repos are disconnected; tokens revoked.",actionLabel:"Delete account…",actionDisabled:a==null?void 0:a.deleteAccount,destructive:!0,onClick:()=>p(!0)}),i&&t.jsx("div",{role:"alert","data-testid":"danger-zone-error",style:{padding:"8px 12px",background:"rgba(220, 38, 38, 0.08)",border:"1px solid rgba(220, 38, 38, 0.4)",color:"#991b1b",borderRadius:6,fontSize:13},children:i}),c&&t.jsx(rj,{pending:!!(a!=null&&a.signOutAll),onCancel:()=>d(!1),onConfirm:async()=>{await n(),d(!1)}}),u&&t.jsx(nj,{githubHandle:e,pending:!!(a!=null&&a.deleteAccount),onCancel:()=>p(!1),onConfirm:async f=>{await o(f),p(!1)}})]})}function lo({title:e,description:r,actionLabel:n,actionDisabled:s,destructive:o,onClick:a,children:i}){return t.jsxs("section",{"data-testid":`danger-card-${e.toLowerCase().replace(/\s+/g,"-")}`,style:{padding:16,border:"1px solid rgba(220, 38, 38, 0.4)",borderRadius:8,background:"rgba(220, 38, 38, 0.04)"},children:[t.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:16},children:[t.jsxs("div",{style:{flex:1},children:[t.jsx("h3",{style:{margin:0,fontSize:14,fontWeight:600,color:"var(--text-primary)"},children:e}),t.jsx("p",{style:{margin:"4px 0 0",fontSize:12,color:"var(--text-secondary)",lineHeight:1.5},children:r})]}),t.jsx("button",{type:"button",onClick:a,disabled:s,style:{padding:"6px 14px",fontSize:13,fontFamily:"inherit",background:o?"#dc2626":"transparent",color:o?"#fff":"#dc2626",border:"1px solid #dc2626",borderRadius:6,cursor:s?"not-allowed":"pointer",opacity:s?.6:1,whiteSpace:"nowrap"},children:n})]}),i]})}function tj({exports:e}){return e.length===0?t.jsx("div",{style:{marginTop:12,padding:10,fontSize:12,color:"var(--text-tertiary)",background:"var(--bg-elevated, #fff)",border:"1px dashed var(--border-default, #e5e7eb)",borderRadius:6},children:"No export jobs yet."}):t.jsxs("table",{"data-testid":"exports-table",style:{marginTop:12,width:"100%",borderCollapse:"collapse",fontSize:12},children:[t.jsx("thead",{children:t.jsxs("tr",{style:{borderBottom:"1px solid var(--border-default, #e5e7eb)"},children:[t.jsx("th",{style:co,children:"Requested"}),t.jsx("th",{style:co,children:"Status"}),t.jsx("th",{style:co,children:"Download"})]})}),t.jsx("tbody",{children:e.map(r=>t.jsxs("tr",{style:{borderBottom:"1px solid var(--border-default, #e5e7eb)"},children:[t.jsx("td",{style:uo,children:new Date(r.requestedAt).toLocaleString()}),t.jsx("td",{style:uo,children:r.status}),t.jsx("td",{style:uo,children:r.status==="ready"&&r.downloadUrl?t.jsx("a",{href:r.downloadUrl,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--color-accent, #2563eb)"},children:"Download"}):t.jsx("span",{style:{color:"var(--text-tertiary)"},children:"—"})})]},r.id))})]})}function rj({pending:e,onCancel:r,onConfirm:n}){return t.jsxs(Kd,{title:"Sign out of all devices?",onDismiss:r,testId:"sign-out-all-modal",children:[t.jsx("p",{style:{margin:0,fontSize:13,color:"var(--text-primary)"},children:"Every active session and API token will be revoked. You'll need to sign back in on every device. This cannot be undone."}),t.jsxs(qd,{children:[t.jsx(Yd,{onClick:r,disabled:e,children:"Cancel"}),t.jsx(Jd,{disabled:e,onClick:()=>void n(),children:e?"Signing out…":"Sign out everywhere"})]})]})}function nj({githubHandle:e,pending:r,onCancel:n,onConfirm:s}){const[o,a]=l.useState(""),i=o.trim()===e;return t.jsxs(Kd,{title:"Delete your account?",onDismiss:n,testId:"delete-account-modal",children:[t.jsx("p",{style:{margin:0,fontSize:13,color:"var(--text-primary)",lineHeight:1.5},children:"Your account will be soft-deleted for 30 days, then purged permanently. Connected repos are disconnected, API tokens revoked, and skills you've published become orphaned."}),t.jsxs("p",{style:{margin:0,fontSize:13,color:"var(--text-primary)"},children:["Type ",t.jsx("strong",{children:e})," to confirm:"]}),t.jsx("input",{type:"text","data-testid":"delete-account-confirm-input",value:o,onChange:c=>a(c.target.value),autoFocus:!0,placeholder:e,disabled:r,style:{width:"100%",padding:"8px 10px",fontSize:13,fontFamily:"var(--font-mono)",color:"var(--text-primary)",background:"var(--bg-elevated, #fff)",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:6,boxSizing:"border-box"}}),t.jsxs(qd,{children:[t.jsx(Yd,{onClick:n,disabled:r,children:"Cancel"}),t.jsx(Jd,{disabled:!i||r,onClick:()=>void s(o.trim()),children:r?"Deleting…":"Delete account"})]})]})}function Kd({title:e,testId:r,onDismiss:n,children:s}){return t.jsx("div",{role:"dialog","aria-modal":"true","aria-label":e,"data-testid":r,style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.45)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,fontFamily:"var(--font-sans)"},onClick:o=>{o.target===o.currentTarget&&n()},children:t.jsxs("div",{style:{width:"min(440px, calc(100vw - 32px))",background:"var(--bg-elevated, #fff)",borderRadius:10,border:"1px solid var(--border-default, #e5e7eb)",boxShadow:"0 18px 40px rgba(0,0,0,0.18)",padding:20,display:"flex",flexDirection:"column",gap:14},children:[t.jsx("h3",{style:{margin:0,fontSize:16,fontWeight:600,color:"var(--text-primary)"},children:e}),s]})})}function qd({children:e}){return t.jsx("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:4},children:e})}function Yd({children:e,onClick:r,disabled:n}){return t.jsx("button",{type:"button",onClick:r,disabled:n,style:{padding:"8px 16px",fontSize:13,fontFamily:"inherit",background:"transparent",color:"var(--text-primary)",border:"1px solid var(--border-default, #e5e7eb)",borderRadius:6,cursor:n?"not-allowed":"pointer",opacity:n?.6:1},children:e})}function Jd({children:e,onClick:r,disabled:n}){return t.jsx("button",{type:"button",onClick:r,disabled:n,style:{padding:"8px 16px",fontSize:13,fontFamily:"inherit",background:n?"var(--bg-canvas, #f3f4f6)":"#dc2626",color:n?"var(--text-tertiary)":"#fff",border:"1px solid #dc2626",borderRadius:6,cursor:n?"not-allowed":"pointer",opacity:n?.6:1},children:e})}const co={textAlign:"left",padding:"8px 10px",fontWeight:600,fontSize:11,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--text-secondary)"},uo={padding:"8px 10px",color:"var(--text-primary)"},sj=[{key:"profile",label:"Profile"},{key:"billing",label:"Plan & billing"},{key:"repos",label:"Connected repositories"},{key:"skills",label:"Skills"},{key:"tokens",label:"API tokens"},{key:"notifications",label:"Notifications"},{key:"danger",label:"Danger zone"}];function oj({initialTab:e="profile",online:r=!0,onConnectRepo:n,onOpenRepoOnGitHub:s,onUpgradeClick:o}){const[a,i]=l.useState(e);return t.jsxs("div",{"data-testid":"account-shell",style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0,fontFamily:"var(--font-sans)"},children:[t.jsx(aj,{}),!r&&t.jsx(ij,{}),t.jsxs("div",{style:{display:"flex",flex:1,minHeight:0},children:[t.jsx(lj,{activeTab:a,onSelectTab:i}),t.jsx("main",{"data-testid":"account-shell-pane",style:{flex:1,overflowY:"auto",padding:24,background:"var(--bg-canvas, #f9fafb)"},children:t.jsx(cj,{tab:a,online:r,onConnectRepo:n,onOpenRepoOnGitHub:s,onUpgradeClick:o})})]})]})}function aj(){const{data:e}=yn();return t.jsxs("header",{"data-testid":"account-shell-header",style:{display:"flex",alignItems:"center",gap:12,padding:"12px 16px",borderBottom:"1px solid var(--border-default, #e5e7eb)",background:"var(--bg-elevated, #fff)"},children:[e!=null&&e.avatarUrl?t.jsx("img",{src:e.avatarUrl,alt:"",width:28,height:28,style:{width:28,height:28,borderRadius:"50%",objectFit:"cover",border:"1px solid var(--border-default, #e5e7eb)"}}):t.jsx("div",{style:{width:28,height:28,borderRadius:"50%",background:"var(--bg-canvas, #f3f4f6)"}}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",lineHeight:1.2},children:[t.jsx("strong",{style:{fontSize:13,color:"var(--text-primary)"},children:(e==null?void 0:e.displayName)??"Loading…"}),t.jsx("span",{style:{fontSize:11,color:"var(--text-secondary)"},children:e?`@${e.githubHandle}`:""})]})]})}function ij(){return t.jsx("div",{role:"status","data-testid":"account-shell-offline-banner",style:{padding:"8px 16px",background:"rgba(245, 158, 11, 0.15)",color:"#92400e",fontSize:12,borderBottom:"1px solid rgba(245, 158, 11, 0.4)"},children:"Offline — showing the last synced data."})}function lj({activeTab:e,onSelectTab:r}){return t.jsx("nav",{"data-testid":"account-shell-sidenav","aria-label":"Account sections",style:{width:220,flexShrink:0,borderRight:"1px solid var(--border-default, #e5e7eb)",background:"var(--bg-elevated, #fff)",padding:"12px 8px",display:"flex",flexDirection:"column",gap:2},children:sj.map(n=>{const s=e===n.key;return t.jsx("button",{type:"button","data-testid":`account-tab-${n.key}`,"data-active":s?"true":"false",onClick:()=>r(n.key),style:{display:"block",textAlign:"left",padding:"8px 12px",fontSize:13,fontFamily:"inherit",fontWeight:s?600:400,color:"var(--text-primary)",background:s?"var(--bg-canvas, #f3f4f6)":"transparent",border:"none",borderLeft:`3px solid ${s?"var(--color-accent, #2563eb)":"transparent"}`,borderRadius:0,cursor:"pointer"},children:n.label},n.key)})})}function cj({tab:e,online:r,onConnectRepo:n,onOpenRepoOnGitHub:s,onUpgradeClick:o}){switch(e){case"profile":return t.jsx(dj,{});case"billing":return t.jsx(uj,{onUpgradeClick:o});case"repos":return t.jsx(pj,{online:r,onConnectRepo:n,onOpenRepoOnGitHub:s});case"skills":return t.jsx(fj,{});case"tokens":return t.jsx(hj,{});case"notifications":return t.jsx(xj,{});case"danger":return t.jsx(gj,{});default:return null}}function dj(){const{data:e,loading:r,error:n}=yn(),s=Cc(),[o,a]=l.useState(!1),[i,c]=l.useState(null);return r||!e?t.jsx(gr,{error:n}):t.jsx(Bk,{profile:e,saving:o,errorMessage:i,onSubmit:async d=>{a(!0),c(null);try{await s(d)}catch(u){c(u instanceof Error?u.message:String(u))}finally{a(!1)}}})}function uj({onUpgradeClick:e}){const{data:r,loading:n,error:s}=yn();return n||!r?t.jsx(gr,{error:s}):t.jsx(Hk,{tier:r.tier,onUpgradeClick:e})}function pj({online:e,onConnectRepo:r,onOpenRepoOnGitHub:n}){const{data:s,loading:o,error:a}=ra(),i=Nc(),c=Rc(),[d,u]=l.useState({});return o&&!s?t.jsx(gr,{error:a}):t.jsx(Ik,{repos:Ec(s),pendingActions:d,onConnectNew:()=>r==null?void 0:r(),onOpenOnGitHub:p=>{const f=`https://github.com/${p.repoFullName}`;n?n(f):typeof window<"u"&&window.open(f,"_blank")},onResync:async p=>{if(e){u(f=>({...f,[p.repoId]:"resync"}));try{await i(p.repoId)}finally{u(f=>{const h={...f};return delete h[p.repoId],h})}}},onDisconnect:async p=>{if(e){u(f=>({...f,[p.repoId]:"disconnect"}));try{await c(p.repoId)}finally{u(f=>{const h={...f};return delete h[p.repoId],h})}}}})}function fj(){const{skills:e}=zx();return e.data?t.jsxs("div",{"data-testid":"account-skills-tab",style:{display:"flex",flexDirection:"column",gap:12},children:[t.jsxs("div",{style:{display:"flex",gap:12},children:[t.jsx(ll,{label:"Public skills",value:e.data.publicCount}),t.jsx(ll,{label:"Private skills",value:e.data.privateCount})]}),t.jsxs("section",{style:{marginTop:8},children:[t.jsx("h3",{style:{margin:"0 0 8px",fontSize:13,fontWeight:600,color:"var(--text-primary)"},children:"Recent activity"}),e.data.recentActivity.length===0?t.jsx("p",{style:{margin:0,fontSize:12,color:"var(--text-secondary)"},children:"No recent activity."}):t.jsx("ul",{style:{margin:0,padding:0,listStyle:"none"},children:e.data.recentActivity.map((r,n)=>t.jsxs("li",{style:{padding:"6px 0",fontSize:12,borderBottom:"1px solid var(--border-default, #e5e7eb)",color:"var(--text-primary)"},children:[t.jsx("strong",{children:r.skillName})," ",t.jsx("span",{style:{color:"var(--text-secondary)"},children:r.action})]},`${r.skillName}-${n}`))})]})]}):t.jsx(gr,{error:e.error})}function ll({label:e,value:r}){return t.jsxs("div",{style:{flex:1,padding:16,border:"1px solid var(--border-default, #e5e7eb)",borderRadius:8,background:"var(--bg-elevated, #fff)"},children:[t.jsx("div",{style:{fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.04em",color:"var(--text-secondary)"},children:e}),t.jsx("div",{style:{fontSize:24,fontWeight:600,color:"var(--text-primary)",fontVariantNumeric:"tabular-nums"},children:r})]})}function hj(){const{data:e,loading:r,error:n}=Tc(),s=Ic(),o=Lc(),[a,i]=l.useState(!1),[c,d]=l.useState(null),[u,p]=l.useState(null);return r&&!e?t.jsx(gr,{error:n}):n&&!e?t.jsx(mj,{title:"API tokens are unavailable",message:"This page is for CLI and automation tokens, separate from GitHub repository access. Sign in again, then retry token management.",detail:n.message}):t.jsx(Vk,{tokens:e??[],creating:a,pendingRevokeId:c,recentlyCreated:u,onDismissRecentlyCreated:()=>p(null),onCreate:async f=>{i(!0);try{const h=await s(f);p(h)}finally{i(!1)}},onRevoke:async f=>{d(f.id);try{await o(f.id)}finally{d(null)}}})}function mj({title:e,message:r,detail:n}){return t.jsxs("div",{role:"alert","data-testid":"account-shell-section-error",style:{padding:16,border:"1px solid rgba(220, 38, 38, 0.35)",background:"rgba(220, 38, 38, 0.06)",borderRadius:8,color:"#7f1d1d",fontSize:13,display:"flex",flexDirection:"column",gap:6},children:[t.jsx("strong",{style:{color:"#991b1b"},children:e}),t.jsx("span",{children:r}),n?t.jsx("code",{style:{color:"#991b1b",fontSize:12,wordBreak:"break-word"},children:n}):null]})}function xj(){const{data:e,loading:r,error:n}=Ac(),s=Pc(),[o,a]=l.useState(!1),[i,c]=l.useState(null);return r||!e?t.jsx(gr,{error:n}):t.jsx(Qk,{prefs:e,saving:o,errorMessage:i,onSubmit:async d=>{a(!0),c(null);try{await s(d)}catch(u){c(u instanceof Error?u.message:String(u))}finally{a(!1)}}})}function gj(){const{data:e}=yn(),{data:r}=$c(),n=Mc(),s=Dc(),o=Fc(),[a,i]=l.useState({}),[c,d]=l.useState(null);return e?t.jsx(ej,{githubHandle:e.githubHandle,exports:r??[],pending:a,errorMessage:c,onSignOutAll:async()=>{i(u=>({...u,signOutAll:!0})),d(null);try{await n()}catch(u){d(u instanceof Error?u.message:String(u))}finally{i(u=>({...u,signOutAll:!1}))}},onExportRequest:async()=>{i(u=>({...u,exportRequest:!0})),d(null);try{await s()}catch(u){d(u instanceof Error?u.message:String(u))}finally{i(u=>({...u,exportRequest:!1}))}},onDeleteAccount:async u=>{i(p=>({...p,deleteAccount:!0})),d(null);try{await o(u)}catch(p){d(p instanceof Error?p.message:String(p))}finally{i(p=>({...p,deleteAccount:!1}))}}}):t.jsx(gr,{})}function gr({error:e}={}){return e?t.jsxs("div",{role:"alert","data-testid":"account-shell-tab-error",style:{padding:16,border:"1px solid rgba(220, 38, 38, 0.4)",background:"rgba(220, 38, 38, 0.06)",borderRadius:8,color:"#991b1b",fontSize:13},children:["Couldn't load this section: ",e.message]}):t.jsx("div",{"data-testid":"account-shell-tab-loading",style:{padding:16,color:"var(--text-secondary)",fontSize:13},children:"Loading…"})}const vj=l.lazy(()=>Lr(()=>import("./FindSkillsPalette-CyMmNPr-.js"),__vite__mapDeps([5,3,1,2])).then(e=>({default:e.FindSkillsPalette})));rf();const yj=l.lazy(()=>Lr(()=>import("./SkillDetailPanel-DTrRnyyJ.js"),__vite__mapDeps([6,1,2,7,3,4])).then(e=>({default:e.SkillDetailPanel}))),bj=l.lazy(()=>Lr(()=>import("./CreateSkillPage-DOBhKdgr.js"),__vite__mapDeps([8,1,2,3,4])).then(e=>({default:e.CreateSkillPage}))),kj=l.lazy(()=>Lr(()=>Promise.resolve().then(()=>yb),void 0).then(e=>({default:e.UpdatesPanel})));function jj(){return t.jsx(Sf,{children:t.jsx(fk,{children:t.jsx(kf,{children:t.jsx(jh,{children:t.jsx(wj,{children:t.jsxs(g1,{children:[t.jsx(Sj,{}),t.jsx(m1,{}),t.jsx(v1,{})]})})})})})})}function wj({children:e}){const[r,n]=l.useState(void 0);return l.useEffect(()=>{let s=!1;if(mg())return fg().then(o=>{s||n(o)}),()=>{s=!0}},[]),t.jsx(Px,{value:r,children:e})}function Sj(){var Gt,wn;const{state:e,selectSkill:r,clearSelection:n,refreshSkills:s,outdatedByOrigin:o,revealSkill:a,clearReveal:i}=Mt(),{config:c}=hr(),{resolvedTheme:d,setTheme:u}=Ol(),{toast:p}=ss(),[f,h]=l.useState(()=>$g()),[m]=l.useState(!0),[g,x]=l.useState(!1),[v,b]=l.useState(!1),[y,j]=l.useState(!1),[S,w]=l.useState(()=>typeof window>"u"?"overview":Po(window.location.search).tab),[R,k]=l.useState(()=>{if(typeof window>"u")return"";const D=Po(window.location.search);return D.mode?D.mode:D.view?D.view:Nd(D.tab,window.location.search)}),E=l.useCallback(D=>{w(oe=>(oe!==D&&k(rn(D)),D))},[]);l.useEffect(()=>{if(typeof window>"u")return;const D=()=>{const oe=new URLSearchParams(window.location.search),ae=oe.get("tab"),vt=oe.get("panel"),Ve=Zn(ae)??Zn(vt);if(!Ve)return;const Ft=new URLSearchParams(window.location.search);Ft.delete("panel"),Ft.delete("sub"),Ve.tab==="overview"?Ft.delete("tab"):Ft.set("tab",Ve.tab),Ft.delete("mode"),Ft.delete("view"),Ve.mode&&Ft.set("mode",Ve.mode),Ve.view&&Ft.set("view",Ve.view);const Lt=Ft.toString(),ua=`${window.location.pathname}${Lt?"?"+Lt:""}${window.location.hash}`,Xd=`${window.location.pathname}${window.location.search}${window.location.hash}`;ua!==Xd&&window.history.replaceState(null,"",ua),w(Ve.tab),Ve.mode?k(Ve.mode):Ve.view?k(Ve.view):k(rn(Ve.tab))};return D(),window.addEventListener("popstate",D),()=>window.removeEventListener("popstate",D)},[]),l.useEffect(()=>{if(typeof window>"u")return;const D=new URLSearchParams(window.location.search);D.delete("panel"),D.delete("sub"),S==="overview"?D.delete("tab"):D.set("tab",S),D.delete("mode"),D.delete("view"),!(R===rn(S))&&R&&(S==="run"?D.set("mode",R):S==="history"&&D.set("view",R));const ae=D.toString(),vt=`${window.location.pathname}${ae?"?"+ae:""}${window.location.hash}`,Ve=`${window.location.pathname}${window.location.search}${window.location.hash}`;vt!==Ve&&window.history.replaceState(null,"",vt)},[S,R]);const[C,N]=l.useState(Xi),I=l.useCallback((D,oe)=>{N(J0(D,oe))},[]),P=h0(),[L,B]=l.useState(()=>Y0("activeAgent",null)),T=l.useCallback(D=>{B(D),q0("activeAgent",D),typeof window<"u"&&window.dispatchEvent(new CustomEvent("studio:agent-changed",{detail:{agentId:D}}))},[]);l.useEffect(()=>{var D;!L&&((D=P.response)!=null&&D.suggested)&&T(P.response.suggested)},[L,(Gt=P.response)==null?void 0:Gt.suggested,T]);const $=l.useMemo(()=>P.response?l0(P.response):[],[P.response]),{workspace:M,switchProject:F,addProject:W,removeProject:le,activeProject:U}=b0(),[H,ee]=l.useState(!1);l.useEffect(()=>{ce.current=(U==null?void 0:U.path)??null},[U==null?void 0:U.path]);const[K,X]=l.useState(!1),[G,he]=l.useState("standalone"),[A,O]=l.useState(!1),[V,re]=l.useState(null),ce=l.useRef(null),ne=hk(),ve=pn(),ge=l.useCallback(D=>{ve.openExternalUrl(D).catch(()=>{typeof window<"u"&&window.open(D,"_blank","noopener,noreferrer")})},[ve]),se=l.useCallback(async(D="standalone")=>{he(D),X(!0)},[]);l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;se((ae==null?void 0:ae.mode)??"standalone")}return window.addEventListener("studio:request-create-skill",D),()=>window.removeEventListener("studio:request-create-skill",D)},[se]),l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;re(ae!=null&&ae.repoName?{repoName:ae.repoName}:null),O(!0)}return window.addEventListener("studio:request-paywall",D),()=>window.removeEventListener("studio:request-paywall",D)},[]);const[fe,z]=l.useState(!1),[q,Z]=l.useState(null),[J,ue]=l.useState(null);l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;!ae||typeof ae.skill!="string"||ae.skill.length===0||ue({skill:ae.skill,skillDisplayName:ae.skillDisplayName,scope:ae.scope==="project"?"project":"user",activeAgentId:ae.activeAgentId,preCheckedAgentIds:ae.preCheckedAgentIds})}return window.addEventListener("studio:open-install-targets-modal",D),()=>window.removeEventListener("studio:open-install-targets-modal",D)},[]);const[de,we]=l.useState(null);l.useEffect(()=>{function D(){z(!0)}return window.addEventListener("studio:open-marketplace",D),()=>window.removeEventListener("studio:open-marketplace",D)},[]);const Ie=l.useMemo(()=>{const D=new Set;for(const oe of e.skills)oe.source==="plugin"&&oe.pluginName&&D.add(oe.pluginName);return D},[e.skills]);wo([{key:"p",meta:!0,handler:D=>{var ae;const oe=typeof document<"u"?document.activeElement:null;oe&&oe.tagName==="INPUT"||((ae=D==null?void 0:D.preventDefault)==null||ae.call(D),ee(vt=>!vt))}}],{enabled:!0});const Fe=U1(),Ke=Fe.open;l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;ae!=null&&ae.provider&&Ke(ae.provider)}return window.addEventListener("studio:open-setup-drawer",D),()=>window.removeEventListener("studio:open-setup-drawer",D)},[Ke]);const Ye=l.useCallback(()=>{N(Xi)},[]);l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;ae!=null&&ae.message&&p({message:ae.message,severity:ae.severity??"info"})}return window.addEventListener("studio:toast",D),()=>window.removeEventListener("studio:toast",D)},[p]),K0();const[Q,Re]=l.useState(!1),[je,$e]=l.useState(void 0);l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;$e(ae==null?void 0:ae.provider),Re(!0)}return window.addEventListener("studio:open-settings",D),()=>window.removeEventListener("studio:open-settings",D)},[]),l.useEffect(()=>{document.documentElement.style.setProperty("--sidebar-width",`${f}px`)},[f]),l.useEffect(()=>{function D(){s()}return window.addEventListener("studio:content-saved",D),()=>window.removeEventListener("studio:content-saved",D)},[s]);const[He,nt]=l.useState(null),[St,vr]=l.useState(()=>new Set),Xt=l.useRef(!1),Ue=l.useMemo(()=>Vx(),[]),tt=l.useCallback(D=>`${D.plugin}/${D.skill}`,[]),mt=l.useCallback(D=>{vr(oe=>{const ae=new Set(oe);return ae.add(tt(D)),ae})},[tt]),Tt=l.useCallback(D=>{vr(oe=>{const ae=new Set(oe);return ae.delete(tt(D)),ae})},[tt]),xt=Hi({delayMs:1e4,onCommit:D=>{s(),Tt(D)},onFailure:(D,oe)=>{Tt(D),p({message:`Couldn't delete ${D.skill}: ${oe.message}`,severity:"error",durationMs:0,action:{label:_.actions.retry,onInvoke:()=>{mt(D),xt.enqueueDelete(D)}}})}});l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;ae!=null&&ae.skill&&nt(ae.skill)}return window.addEventListener("studio:request-delete",D),()=>window.removeEventListener("studio:request-delete",D)},[]);const[rt,ht]=l.useState(null);l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;ae!=null&&ae.skill&&ht(ae.skill)}return window.addEventListener("studio:request-clone",D),()=>window.removeEventListener("studio:request-clone",D)},[]);const[Ce,Ae]=l.useState(null),st=Hi({delayMs:250,apiCall:(D,oe)=>api.uninstallSkill(D,oe),onCommit:D=>{s(),Tt(D)},onFailure:(D,oe)=>{var ae;if(Tt(D),oe instanceof qt&&((ae=oe.details)==null?void 0:ae.code)==="not-installed"){p({message:`${D.skill} is a source-authored skill — use Delete instead`,severity:"info",durationMs:4e3});return}p({message:`Couldn't uninstall ${D.skill}: ${oe.message}`,severity:"error",durationMs:0,action:{label:_.actions.retry,onInvoke:()=>{mt(D),st.enqueueDelete(D)}}})}});l.useEffect(()=>{function D(oe){if(!(oe instanceof CustomEvent))return;const ae=oe.detail;ae!=null&&ae.skill&&Ae(ae.skill)}return window.addEventListener("studio:request-uninstall",D),()=>window.removeEventListener("studio:request-uninstall",D)},[]);const gt=l.useCallback(async D=>{await Promise.all([xt.flushBySkillName(D),st.flushBySkillName(D)])},[xt,st]),jn=l.useMemo(()=>({flushBySkillName:gt}),[gt]),Dt=l.useCallback(()=>{const D=Ce;if(Ae(null),!D)return;const oe={plugin:D.plugin,skill:D.skill};mt(oe),st.enqueueDelete(oe),p({message:`Uninstalled ${D.skill}. Sent to your ${Ue}.`,severity:"info",durationMs:4e3})},[Ce,mt,st,p,Ue]),ps=l.useCallback(()=>{Ae(null)},[]),fs=l.useCallback(()=>{const D=He;if(nt(null),!D)return;const oe={plugin:D.plugin,skill:D.skill};mt(oe),xt.enqueueDelete(oe);const ae=Xt.current?"":`Sent to your ${Ue}. Open Trash to restore. `;Xt.current=!0,p({message:`${ae}Deleted ${D.skill}`,severity:"info",durationMs:1e4,action:{label:_.actions.undo,onInvoke:()=>{xt.cancelDelete(tt(oe)),Tt(oe)}}})},[He,mt,Tt,xt,p,Ue,tt]),zr=l.useCallback(()=>{nt(null)},[]),It=l.useMemo(()=>e.skills.filter(D=>!St.has(tt(D))),[e.skills,St,tt]),yr=Wg(It,(U==null?void 0:U.path)??null),Je=l.useMemo(()=>e.selectedSkill?e.skills.find(D=>D.plugin===e.selectedSkill.plugin&&D.skill===e.selectedSkill.skill)??null:null,[e.skills,e.selectedSkill]),Br=l.useRef(null);l.useEffect(()=>{if(!Je||typeof window>"u"||new URLSearchParams(window.location.search).get("tab")||!(Je.origin==="installed"))return;const ae=`${Je.plugin}/${Je.skill}`;Br.current!==ae&&(Br.current=ae,S==="overview"&&w("source"))},[Je==null?void 0:Je.plugin,Je==null?void 0:Je.skill,Je==null?void 0:Je.origin]);const ir=l.useCallback(D=>{r({plugin:D.plugin,skill:D.skill,origin:D.origin,source:D.source})},[r]),De=l.useMemo(()=>{if(!e.selectedSkill)return"";const D=e.selectedSkill.origin==="installed"?"Installed":"Own";return`Viewing ${e.selectedSkill.skill} (${D})`},[e.selectedSkill]),[lr,Vt]=l.useState(null);wo([{key:"cmd+k",handler:()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("openFindSkills"))}},{key:"ctrl+k",handler:()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("openFindSkills"))}},{key:"cmd+shift+m",handler:()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("openAgentModelPicker"))}},{key:"ctrl+shift+m",handler:()=>{typeof window<"u"&&window.dispatchEvent(new CustomEvent("openAgentModelPicker"))}},{key:"?",handler:()=>x(D=>!D)},{key:"cmd+shift+d",handler:()=>u(d==="light"?"dark":"light")},{key:"ctrl+shift+d",handler:()=>u(d==="light"?"dark":"light")},{key:"cmd+b",handler:()=>b(D=>!D)},{key:"ctrl+b",handler:()=>b(D=>!D)}]);const hs=tk(),it=rk(),da=y?t.jsx(oj,{online:typeof navigator>"u"?!0:navigator.onLine!==!1,onConnectRepo:()=>{ge("https://verified-skill.com/account/repos/connect")},onOpenRepoOnGitHub:ge,onUpgradeClick:()=>{ge(_d)}}):it?t.jsx(l.Suspense,{fallback:t.jsx("div",{style:{padding:40},children:"Loading…"}),children:t.jsx(kj,{})}):hs?t.jsx(l.Suspense,{fallback:t.jsx("div",{style:{padding:40},children:"Loading…"}),children:t.jsx(bj,{})}):t.jsx(i1,{selectedSkillInfo:Je,activeDetailTab:S,onDetailTabChange:E,activeDetailSub:R,onDetailSubChange:k,allSkills:e.skills,onSelectSkill:ir});return t.jsxs(gd.Provider,{value:jn,children:[t.jsx(Cf,{sidebarWidth:f,sidebarHidden:v||e.isMobile&&e.mobileView==="detail",banner:t.jsx(Hg,{connected:m}),liveMessage:De,topRail:t.jsx(Ih,{projectName:(c==null?void 0:c.projectName)??null,selected:e.selectedSkill,onHome:n,onRequestCreateSkill:()=>se("standalone"),projectPickerSlot:M&&M.projects.length>0?t.jsx(k0,{workspace:M,onSwitch:F,onAdd:W,onRemove:le}):void 0,findSkillsSlot:t.jsx(ok,{}),appUpdateSlot:t.jsx(y1,{}),userDropdownSlot:t.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:8},children:[t.jsx(wk,{}),t.jsx(ak,{})]})}),sidebar:t.jsxs("div",{"data-testid":"desktop-sidebar",style:{display:"flex",flexDirection:"column",height:"100%",minHeight:0},children:[t.jsx("div",{style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:t.jsx(wg,{skills:It,selectedKey:e.selectedSkill?{plugin:e.selectedSkill.plugin,skill:e.selectedSkill.skill}:null,onSelect:D=>{j(!1),ir(D)},isLoading:e.skillsLoading,error:e.skillsError??null,onRetry:s,onContextMenu:I,outdatedByOrigin:o,activeAgentId:L,revealSkillId:e.revealSkillId,onRevealComplete:i,dirtySkillIds:yr,onSkillsChanged:s,topSlot:t.jsxs(t.Fragment,{children:[P.status==="ready"&&$.length>0?t.jsxs(t.Fragment,{children:[t.jsx(c0,{agents:$,activeAgentId:L,onActiveAgentChange:T,onOpenSetup:D=>Fe.open(D)}),t.jsx(f0,{activeAgentId:L})]}):null,U!=null&&U.path?t.jsx(_c,{folder:U.path,tier:ne.tier,onUpgradeClick:()=>{try{window.dispatchEvent(new CustomEvent("studio:request-paywall",{detail:{repoName:U.path}}))}catch{}}}):null]})})}),t.jsx("div",{style:{borderTop:"1px solid var(--border-default, rgba(128,128,128,0.25))",padding:"6px 0"},children:t.jsx(Nk,{active:y,onClick:()=>j(D=>!D)})})]}),resizeHandle:t.jsx(Dg,{initialWidth:f??tn,onChange:h}),main:da,statusBar:t.jsx(Oh,{projectPath:(c==null?void 0:c.root)??null,modelName:(c==null?void 0:c.model)??null,health:c!=null&&c.error?"degraded":"ok",providers:(wn=c==null?void 0:c.providers)==null?void 0:wn.map(D=>{const oe=D.id;return{id:oe,label:D.label,available:D.available,kind:oe==="ollama"||oe==="lm-studio"?"start-service":oe==="anthropic"||oe==="openrouter"?"api-key":"cli-install"}})})}),t.jsx(k1,{open:g,onClose:()=>x(!1)}),t.jsx(z1,{open:Fe.isOpen,providerKey:Fe.providerKey,onClose:Fe.close}),t.jsx(w1,{state:C,onClose:Ye,onAction:(D,oe)=>Q0(D,oe)}),t.jsx(l.Suspense,{fallback:null,children:t.jsx(vj,{onSelect:D=>{const oe=D.name.split("/");oe.length===3&&Vt({owner:oe[0],repo:oe[1],slug:oe[2],displayName:D.displayName??D.name})}})}),lr&&t.jsx(l.Suspense,{fallback:null,children:t.jsx(yj,{selectedSkill:lr,activeAgentId:L,onClose:()=>Vt(null)})}),t.jsx(w0,{open:H,projects:(M==null?void 0:M.projects)??[],onSwitch:D=>{F(D)},onClose:()=>ee(!1)}),t.jsx(S0,{open:K,onClose:()=>X(!1),initialMode:G,isClaudeCode:L==="claude-code",projectRoot:(U==null?void 0:U.path)??(c==null?void 0:c.projectName)??"",onCreated:D=>{s(),setTimeout(()=>{a(D.pluginName??"",D.skillName)},500),ve.quotaReportCount(It.length+1)}}),t.jsx(R0,{open:fe,onClose:()=>z(!1),installedNames:Ie,onInstall:(D,oe)=>{Z({plugin:D,marketplace:oe,ref:`${D}@${oe}`}),z(!1)},onUninstall:async D=>{if(await new Promise(ae=>{we({plugin:D,resolve:ae})}))try{const ae=await fetch(`/api/plugins/${encodeURIComponent(D)}/uninstall`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})}),vt=await ae.json().catch(()=>({}));if(!ae.ok||!vt.ok){p({message:vt.error??`Uninstall failed (${ae.status})`,severity:"error"});return}const Ve=vt.fallback==="orphan-cache-removed"?`Removed orphaned ${D}.`:`Uninstalled ${D}.`;p({message:Ve,severity:"success"}),s()}catch(ae){p({message:ae instanceof Error?ae.message:String(ae),severity:"error"})}}}),t.jsx(Fl,{open:Q,onClose:()=>Re(!1),initialProvider:je,onToast:D=>p({message:D,severity:"info"})}),t.jsx(A0,{job:q,onDone:D=>{D.ok&&(s(),setTimeout(()=>Z(null),3e3))}}),J&&t.jsx(W0,{skill:J.skill,skillDisplayName:J.skillDisplayName,scope:J.scope,activeAgentId:J.activeAgentId===void 0?L:J.activeAgentId,preCheckedAgentIds:J.preCheckedAgentIds,onClose:()=>ue(null),onSuccess:D=>{s();const oe=D.filter(Lt=>Lt.status==="installed").length,ae=D.filter(Lt=>Lt.status==="exported").length,vt=D.find(Lt=>Lt.status==="error"),Ve=J.skillDisplayName??J.skill;vt?p({message:vt.detail||`Could not install ${Ve}.`,severity:"error"}):ae>0?p({message:`Installed ${Ve}; ${ae} target${ae===1?"":"s"} need paste.`,severity:"info"}):oe>0&&p({message:`Installed ${Ve} to ${oe} target${oe===1?"":"s"}.`,severity:"success"}),D.some(Lt=>Lt.status==="error"||Lt.status==="exported")||ue(null)}}),t.jsx(Vn,{open:He!==null,title:He?`Delete "${He.skill}"?`:"",body:`It will be sent to your ${Ue}. You can recover it from there.`,confirmLabel:"Delete",cancelLabel:"Cancel",variant:"destructive",onConfirm:fs,onCancel:zr}),t.jsx(Vn,{open:Ce!==null,title:Ce?`Uninstall "${Ce.skill}"?`:"",body:`It will be sent to your ${Ue} and the lockfile entry will be removed. You can re-install with vskill install.`,confirmLabel:"Uninstall",cancelLabel:"Cancel",variant:"destructive",onConfirm:Dt,onCancel:ps}),t.jsx(Vn,{open:de!==null,title:de?`Uninstall ${de.plugin}?`:"",body:de?`This removes the ${de.plugin} plugin and all of its skills. You can reinstall it later from the marketplace.`:"",confirmLabel:"Uninstall",cancelLabel:"Cancel",variant:"destructive",onConfirm:()=>{de==null||de.resolve(!0),we(null)},onCancel:()=>{de==null||de.resolve(!1),we(null)}}),t.jsx(mk,{open:A,skillName:(V==null?void 0:V.repoName)??void 0,onClose:()=>{O(!1),re(null)},onProceed:()=>{re(null)}}),rt&&t.jsx(C1,{skill:rt,onCloned:D=>{p({message:_.toasts.cloneSucceeded,severity:"info"}),ht(null);try{window.dispatchEvent(new CustomEvent("studio:skills-changed",{detail:D}))}catch{}s()},onCancel:()=>ht(null)})]})}const cl="vskill.migrations.scope-rename.v1",Cj={own:"authoring-project",installed:"available-project",global:"available-personal"},Ej=/^vskill-sidebar-(.+)-(own|installed|global)-collapsed$/;function Nj(e){if(e.getItem(cl)==="done")return;const r=[];for(let n=0;n<e.length;n++){const s=e.key(n);if(!s)continue;const o=s.match(Ej);if(!o)continue;const[,a,i]=o,c=Cj[i];if(!c)continue;const d=e.getItem(s);d!==null&&r.push({oldKey:s,newKey:`vskill-sidebar-${a}-${c}-collapsed`,value:d})}for(const{oldKey:n,newKey:s,value:o}of r)e.getItem(s)===null&&e.setItem(s,o),e.removeItem(n);e.setItem(cl,"done")}if(typeof PerformanceObserver<"u")try{const e=new PerformanceObserver(r=>{for(const n of r.getEntries())if(n.name==="first-contentful-paint"){window.__vskillPaint=n.startTime,e.disconnect();return}});e.observe({type:"paint",buffered:!0})}catch{}if(typeof window<"u"&&window.localStorage)try{Nj(window.localStorage)}catch{}eu.createRoot(document.getElementById("root")).render(t.jsx(l.StrictMode,{children:t.jsx(kp,{children:t.jsx(Dh,{children:t.jsx(jj,{})})})}));export{us as E,W0 as I,El as L,kn as P,mb as S,Lj as T,ie as a,Mt as b,pb as c,db as d,bn as e,ss as f,Y0 as g,xd as h,K1 as o,Fd as r,Cr as t,hr as u,q0 as w};