@usechain/chain-hub 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +209 -2
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.js +32318 -0
  5. package/dist/web/apple-touch-icon.png +0 -0
  6. package/dist/web/assets/CatalogPage-DH4aZzR2.js +1 -0
  7. package/dist/web/assets/CatalogPage-M8VZyfIe.js +1 -0
  8. package/dist/web/assets/HealthPage-C2uKV9FU.js +1 -0
  9. package/dist/web/assets/HealthPage-DUbZiwpY.js +1 -0
  10. package/dist/web/assets/IntegrationsPage-BziKwfEq.js +1 -0
  11. package/dist/web/assets/IntegrationsPage-rJcPXOty.js +1 -0
  12. package/dist/web/assets/LearningsPage-DBJ9M7V5.js +2 -0
  13. package/dist/web/assets/LearningsPage-Da6i4TeB.js +2 -0
  14. package/dist/web/assets/LibraryPage-BP6IKKuN.js +4 -0
  15. package/dist/web/assets/LibraryPage-C9uf78JX.js +4 -0
  16. package/dist/web/assets/MarkdownSourceEditor-CV1ZTZzI.js +39 -0
  17. package/dist/web/assets/MarkdownSourceEditor-Xh-yr_Pu.js +39 -0
  18. package/dist/web/assets/OverviewPage-DeApcxoJ.js +1 -0
  19. package/dist/web/assets/OverviewPage-DhNIr7N8.js +1 -0
  20. package/dist/web/assets/SettingsPage-BCoxInUI.js +1 -0
  21. package/dist/web/assets/SettingsPage-BmRmIO3z.js +1 -0
  22. package/dist/web/assets/SetupPage-BUmmsWEo.js +1 -0
  23. package/dist/web/assets/SetupPage-CmXMvqM5.js +1 -0
  24. package/dist/web/assets/SkillRelinkDialog-C5PU7vKu.js +1 -0
  25. package/dist/web/assets/SkillRelinkDialog-DEY3IqVA.js +1 -0
  26. package/dist/web/assets/alert-Mr-ofzoN.js +1 -0
  27. package/dist/web/assets/alert-YumgHBdn.js +1 -0
  28. package/dist/web/assets/badge-C2BSIZMN.js +1 -0
  29. package/dist/web/assets/badge-CcASMiB4.js +1 -0
  30. package/dist/web/assets/format-time-D8VGlAcs.js +1 -0
  31. package/dist/web/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  32. package/dist/web/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  33. package/dist/web/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  34. package/dist/web/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  35. package/dist/web/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
  36. package/dist/web/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
  37. package/dist/web/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
  38. package/dist/web/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
  39. package/dist/web/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
  40. package/dist/web/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
  41. package/dist/web/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  42. package/dist/web/assets/index-D3L-4LuU.css +1 -0
  43. package/dist/web/assets/index-ltESF1KS.js +172 -0
  44. package/dist/web/assets/index-mFc_WQtU.css +1 -0
  45. package/dist/web/assets/index-ommOzjM4.js +172 -0
  46. package/dist/web/assets/libesm-CHGPMFhL.js +6 -0
  47. package/dist/web/assets/select-DJSrFTH0.js +1 -0
  48. package/dist/web/assets/tabs-B9fkoXIl.js +1 -0
  49. package/dist/web/assets/utils-BEATUXr4.js +1 -0
  50. package/dist/web/assets/vendor-react-BgntYnUn.js +12 -0
  51. package/dist/web/assets/vendor-ui-qVCZmmA-.js +41 -0
  52. package/dist/web/favicon-32.png +0 -0
  53. package/dist/web/favicon.svg +2 -0
  54. package/dist/web/icon-192.png +0 -0
  55. package/dist/web/icon-512.png +0 -0
  56. package/dist/web/icon-maskable-512.png +0 -0
  57. package/dist/web/index.html +37 -0
  58. package/dist/web/logo.svg +2 -0
  59. package/dist/web/site.webmanifest +25 -0
  60. package/package.json +42 -4
@@ -0,0 +1,4 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/MarkdownSourceEditor-CV1ZTZzI.js","assets/utils-BEATUXr4.js","assets/vendor-react-BgntYnUn.js","assets/index-ommOzjM4.js","assets/vendor-ui-qVCZmmA-.js","assets/index-D3L-4LuU.css"])))=>i.map(i=>d[i]);
2
+ import{i as e,t}from"./utils-BEATUXr4.js";import{H as n,J as r,L as i,M as a,U as o,V as s,W as c,Z as l,n as u,q as d,t as f}from"./vendor-react-BgntYnUn.js";import{B as p,C as m,E as h,F as g,G as _,H as v,J as y,K as b,M as x,N as S,S as C,T as w,V as T,W as E,_ as D,at as O,c as k,d as A,dt as ee,et as j,f as te,ft as M,g as N,it as ne,ot as re,q as ie,s as ae,st as oe,u as se,ut as ce,v as P,w as le,x as ue,y as de,z as fe}from"./vendor-ui-qVCZmmA-.js";import{$ as pe,A as F,B as me,C as I,F as he,G as ge,H as _e,I as L,J as ve,K as ye,L as be,M as xe,N as R,P as Se,R as Ce,T as we,U as Te,V as Ee,W as De,_ as Oe,a as ke,at as Ae,c as z,ct as B,d as V,dt as je,et as Me,f as H,g as U,gt as W,i as Ne,it as Pe,j as G,k as Fe,l as K,lt as Ie,n as Le,nt as Re,o as ze,ot as Be,p as q,pt as J,q as Ve,r as He,rt as Ue,s as Y,st as X,t as We,tt as Ge,u as Ke,ut as qe,w as Je,z as Ye}from"./index-ommOzjM4.js";import{n as Xe,r as Ze,t as Qe}from"./alert-YumgHBdn.js";import{t as Z}from"./badge-C2BSIZMN.js";import{t as $e}from"./select-DJSrFTH0.js";import{n as et,r as tt,t as nt}from"./tabs-B9fkoXIl.js";import{t as rt}from"./SkillRelinkDialog-C5PU7vKu.js";import{n as it,t as at}from"./libesm-CHGPMFhL.js";var Q=e(l(),1),$=r();function ot({className:e,...n}){return(0,$.jsx)(u,{className:t(`group relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-[5px] border border-input bg-background shadow-xs outline-none transition-[color,box-shadow,border-color,background-color] hover:border-foreground/30 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:cursor-not-allowed disabled:opacity-50 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground data-indeterminate:border-primary data-indeterminate:bg-primary data-indeterminate:text-primary-foreground sm:size-4`,e),"data-slot":`checkbox`,...n,children:(0,$.jsx)(f,{className:`flex items-center justify-center text-current data-unchecked:hidden`,"data-slot":`checkbox-indicator`,render:(e,t)=>(0,$.jsx)(`span`,{...e,children:t.indeterminate?(0,$.jsx)(x,{className:`size-3 stroke-[3]`}):(0,$.jsx)(oe,{className:`size-3 stroke-[3]`})})})})}var st={"kind-mismatch":`Kind mismatch`,"audit-findings":`Audit findings`,"compat-issue":`Compat issue`,"check-failed":`Check failed`};function ct(e){return e.type===`kind-mismatch`&&e.recommendedKind?`Reads like a ${Ce[e.recommendedKind].label.toLowerCase()}: ${e.reason??``}`:e.type===`audit-findings`?e.summary??null:e.type===`compat-issue`?e.compatIssues?.map(e=>e.message).join(` · `)??null:e.error??null}function lt(e){return e.type===`kind-mismatch`&&e.recommendedKind?`Convert to ${Ce[e.recommendedKind].label}`:e.type===`compat-issue`?`Fix description`:e.type===`audit-findings`?`Improve with AI`:null}function ut({item:e,editable:n,checked:r,isFixing:i,onToggleSelect:a,onOpenItem:o,onFixItem:s,onSetStatus:c}){let l=ct(e),u=lt(e),d=e.status===`open`;return(0,$.jsxs)(`li`,{className:t(`rounded-xl border border-border bg-muted/40 px-3 py-2.5 text-sm`,!d&&`opacity-60`),children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2.5`,children:[d?(0,$.jsx)(ot,{"aria-label":`Select ${e.name}`,checked:r,className:`mt-0.5`,onCheckedChange:()=>a(e.id)}):null,(0,$.jsxs)(`button`,{className:`min-w-0 flex-1 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-sm`,onClick:()=>o(e),type:`button`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium text-foreground`,children:e.name}),(0,$.jsx)(Z,{variant:`default`,children:Ce[e.kind].label}),(0,$.jsx)(Z,{variant:e.type===`kind-mismatch`?`accent`:e.type===`check-failed`?`destructive`:`default`,children:st[e.type]}),e.status===`done`?(0,$.jsx)(Z,{variant:`success`,children:`Done`}):null,e.status===`dismissed`?(0,$.jsx)(Z,{variant:`default`,children:`Dismissed`}):null,e.type===`audit-findings`&&e.findings?(0,$.jsxs)(Z,{variant:`default`,children:[e.findings.length,` findings`]}):null,!n&&d?(0,$.jsx)(Z,{variant:`default`,children:`Upstream`}):null]}),l?(0,$.jsx)(`p`,{className:`mt-1 leading-5 text-muted-foreground`,children:l}):null]})]}),d?(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2 pl-7`,children:[u?(0,$.jsxs)(J,{disabled:i||!n,onClick:()=>s(e),size:`sm`,type:`button`,variant:`secondary`,children:[(0,$.jsx)(k,{className:`size-3.5`}),i?`Working…`:u]}):null,(0,$.jsx)(J,{className:`h-7 px-2 text-xs`,onClick:()=>c(e,`dismissed`),size:`sm`,type:`button`,variant:`ghost`,children:`Dismiss`})]}):(0,$.jsx)(`div`,{className:`mt-2 pl-7`,children:(0,$.jsx)(J,{className:`h-7 px-2 text-xs`,onClick:()=>c(e,`open`),size:`sm`,type:`button`,variant:`ghost`,children:`Reopen`})})]})}function dt(e,t){return`${e}/${t}`}function ft(e){let{assetsByKey:t}=e,n=d(),[r,i]=(0,Q.useState)(new Set),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)([]);function f(){n.invalidateQueries({queryKey:[`library`]}),n.invalidateQueries({queryKey:[`library`,`detail`]}),n.invalidateQueries({queryKey:[`analysis`]}),n.invalidateQueries({queryKey:[`overview`]})}async function p(e,t){let r=await Oe.setItemStatus({id:e,status:t});n.setQueryData([`analysis`],r)}function m(e){let n=t.get(dt(e.kind,e.name));return n?Ge(n):!1}async function h(e){if(!m(e))return`skipped`;try{if(e.type===`kind-mismatch`&&e.recommendedKind)await I.convert(e.kind,e.name,{toKind:e.recommendedKind});else if(e.type===`compat-issue`){let t=await I.getByKindAndName(e.kind,e.name),n=pe(t.content,t.name);if(n===t.content)return`skipped`;await I.update(e.kind,e.name,{content:n})}else if(e.type===`audit-findings`&&e.findings&&e.findings.length>0){let t=await I.getByKindAndName(e.kind,e.name),n=await U.improveAsset({kind:e.kind,name:e.name,content:t.content,summary:e.summary??``,findings:e.findings});return u(r=>[...r,{id:e.id,kind:e.kind,name:e.name,before:t.content,after:n.content}]),`queued`}else return`skipped`;return await p(e.id,`done`),`done`}catch(t){return W.error(F(t,`Could not fix ${e.name}`)),`failed`}}async function g(e){o(e.id);let t=await h(e);o(null),f(),t===`done`?W.success(`Fixed ${e.name}`):t===`queued`?W.success(`Improvement ready for ${e.name} — review the diff`):t===`skipped`&&W.info(`${e.name}: fix it from the asset panel (upstream or not auto-fixable)`)}async function _(e){let t=e.filter(e=>e.status===`open`),n=0,r=0,a=0,o=0;c({current:0,total:t.length});for(let[e,i]of t.entries()){c({current:e+1,total:t.length});let s=await h(i);s===`done`?n+=1:s===`queued`?r+=1:s===`skipped`?a+=1:o+=1}c(null),i(new Set),f();let s=[n>0?`${n} fixed`:null,r>0?`${r} to review`:null,a>0?`${a} skipped`:null,o>0?`${o} failed`:null].filter(Boolean);W.success(s.length>0?s.join(` · `):`Nothing to apply`)}async function v(){let e=l[0];if(e)try{await I.update(e.kind,e.name,{content:e.after}),await p(e.id,`done`),u(e=>e.slice(1)),f();let t=l.length-1;W.success(`Applied to ${e.name}${t>0?` — ${t} left to review`:``}`)}catch(t){W.error(F(t,`Could not apply improvement to ${e.name}`))}}function y(){u(e=>e.slice(1))}function b(e){i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function x(e){i(new Set(e.filter(e=>e.status===`open`).map(e=>e.id)))}function S(){i(new Set)}return{selectedIds:r,fixingId:a,batch:s,diffQueue:l,fixItem:g,applyItems:_,approveQueuedDiff:v,discardQueuedDiff:y,toggleSelect:b,selectAllOpen:x,clearSelection:S,setItemStatus:p}}function pt({report:e,assetsByKey:n,selectedIds:r,fixingId:i,batch:a,isAnalyzing:o,onToggleSelect:s,onSelectAllOpen:c,onOpenItem:l,onFixItem:u,onSetStatus:d,onApplySelected:f,onRunAgain:p}){let h=e?.items??[],g=h.filter(e=>e.status===`open`),_=h.filter(e=>e.status===`done`),v=h.filter(e=>e.status===`dismissed`),y=a!==null;return(0,$.jsxs)(`div`,{className:`grid min-h-0 gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center justify-between gap-2 rounded-lg border border-border/80 bg-muted/40 px-2.5 py-1.5 text-xs`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,children:e?`Last run ${new Date(e.runAt).toLocaleString()} · ${g.length} open · ${e.totalAssets} checked`:`No analysis yet`}),(0,$.jsxs)(J,{className:`h-6 shrink-0 gap-1 px-2 text-xs font-medium`,disabled:o,onClick:p,size:`sm`,type:`button`,variant:`ghost`,children:[(0,$.jsx)(m,{className:t(`size-3`,o&&`animate-pulse`)}),o?`Analyzing…`:`Run analysis`]})]}),g.length>0?(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsxs)(J,{disabled:y||r.size===0,onClick:f,size:`sm`,type:`button`,children:[(0,$.jsx)(k,{className:`size-4`}),y?`Applying ${a.current}/${a.total}…`:`Apply selected (${r.size})`]}),(0,$.jsx)(J,{className:`h-8 px-2 text-xs`,onClick:c,size:`sm`,type:`button`,variant:`ghost`,children:`Select all open`})]}):null,h.length===0?(0,$.jsx)(`div`,{className:`rounded-xl border border-dashed border-border px-4 py-8 text-center text-sm text-muted-foreground`,children:e?`Everything looks right — no findings.`:`Run an analysis to build the worklist.`}):(0,$.jsx)($.Fragment,{children:[{title:`Open`,rows:g},{title:`Done`,rows:_},{title:`Dismissed`,rows:v}].filter(e=>e.rows.length>0).map(e=>(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsxs)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:[e.title,` (`,e.rows.length,`)`]}),(0,$.jsx)(`ul`,{className:`grid gap-2`,children:e.rows.map(e=>{let t=n.get(dt(e.kind,e.name));return(0,$.jsx)(ut,{checked:r.has(e.id),editable:t?Ge(t):!1,isFixing:i===e.id,item:e,onFixItem:u,onOpenItem:l,onSetStatus:d,onToggleSelect:s},e.id)})})]},e.title))})]})}function mt({kind:e,isPrompt:t,isSidecarActive:n,isUpstreamSkill:r,upstreamBrowseUrl:i,hasContent:a,copied:o,onCopy:s,isUpdating:c,onUpdateFromSource:l,updateAvailable:u,isReassessing:d,onReassessKind:f,isAuditing:p,onAuditAsset:h,isDeleting:_,onRequestDelete:v,onBackToMain:y,isForking:b,onFork:x,canSave:S,isSaving:C,onSave:w}){return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsxs)(J,{className:`w-fit`,disabled:!a&&!n,onClick:s,type:`button`,variant:`secondary`,children:[o?(0,$.jsx)(oe,{className:`size-4`}):(0,$.jsx)(j,{className:`size-4`}),o?`Copied`:n?`Copy file`:t?`Copy prompt`:`Copy`]}),r&&e===`skills`?(0,$.jsxs)(J,{className:`w-fit`,loading:c,onClick:l,variant:u?`default`:`secondary`,children:[(0,$.jsx)(le,{className:`size-4`}),c?`Updating…`:u?`Update to latest`:`Update from source`]}):null,i?(0,$.jsxs)(J,{className:`w-fit`,onClick:()=>window.open(i,`_blank`,`noopener,noreferrer`),type:`button`,variant:`secondary`,children:[(0,$.jsx)(ie,{className:`size-4`}),`Open source repo`]}):null,(0,$.jsxs)(J,{className:`w-fit`,disabled:!a,loading:d,onClick:f,type:`button`,variant:`secondary`,children:[(0,$.jsx)(m,{className:`size-4`}),d?`Checking…`:`Reassess kind`]}),(0,$.jsxs)(J,{className:`w-fit`,disabled:!a,loading:p,onClick:h,type:`button`,variant:`secondary`,children:[(0,$.jsx)(g,{className:`size-4`}),p?`Auditing…`:`Audit`]}),(0,$.jsxs)(J,{className:`w-fit`,loading:_,onClick:v,variant:`secondary`,children:[(0,$.jsx)(A,{className:`size-4`}),_?`Deleting…`:`Delete asset`]}),n?(0,$.jsxs)(J,{className:`ml-auto w-fit`,onClick:y,type:`button`,variant:`secondary`,children:[(0,$.jsx)(M,{className:`size-4`}),`Back to SKILL.md`]}):r?(0,$.jsxs)(J,{className:`ml-auto w-fit`,loading:b,onClick:x,children:[(0,$.jsx)(fe,{className:`size-4`}),b?`Forking…`:`Fork to customize`]}):(0,$.jsx)(J,{className:`ml-auto w-fit`,disabled:!S,loading:C,onClick:w,children:C?`Saving…`:`Save changes`})]})}function ht({className:e,size:n=`md`}){return(0,$.jsx)(`div`,{className:t(`ca-spinner text-primary`,{sm:`size-4`,md:`size-5`,lg:`size-6`}[n],e),children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Loading`})})}function gt({className:e,size:n=`md`}){let r={sm:`h-1 w-1`,md:`h-1.5 w-1.5`,lg:`h-2 w-2`};return(0,$.jsxs)(`div`,{className:t(`flex items-center space-x-1`,{sm:`h-4`,md:`h-5`,lg:`h-6`}[n],e),children:[[...[,,,]].map((e,i)=>(0,$.jsx)(`div`,{className:t(`bg-primary animate-[typing_1s_infinite] rounded-full`,r[n]),style:{animationDelay:`${i*250}ms`}},i)),(0,$.jsx)(`span`,{className:`sr-only`,children:`Loading`})]})}function _t({className:e,text:n=`Thinking`,size:r=`md`}){return(0,$.jsxs)(`div`,{className:t(`inline-flex items-center`,e),children:[(0,$.jsx)(`span`,{className:t(`text-primary-strong font-medium`,{sm:`text-xs`,md:`text-sm`,lg:`text-base`}[r]),children:n}),(0,$.jsxs)(`span`,{className:`inline-flex`,children:[(0,$.jsx)(`span`,{className:`text-primary-strong animate-[loading-dots_1.4s_infinite_0.2s]`,children:`.`}),(0,$.jsx)(`span`,{className:`text-primary-strong animate-[loading-dots_1.4s_infinite_0.4s]`,children:`.`}),(0,$.jsx)(`span`,{className:`text-primary-strong animate-[loading-dots_1.4s_infinite_0.6s]`,children:`.`})]})]})}function vt({variant:e=`circular`,size:t=`md`,text:n,className:r}){switch(e){case`circular`:return(0,$.jsx)(ht,{size:t,className:r});case`typing`:return(0,$.jsx)(gt,{size:t,className:r});case`loading-dots`:return(0,$.jsx)(_t,{text:n,size:t,className:r});default:return(0,$.jsx)(ht,{size:t,className:r})}}function yt(e){switch(e){case`high`:return`High`;case`medium`:return`Medium`;case`low`:return`Low`;default:return e}}function bt(e){return e===1?`1 field report`:`${e} field reports`}function xt({severity:e}){return(0,$.jsx)(Z,{variant:e===`high`?`accent`:`default`,children:yt(e)})}function St({audit:e,isLoading:t=!1,assetName:n,activeFindingIndex:r,open:i,onOpenChange:a,onSelectFindingIndex:o,isUpstreamSkill:s,isImproving:c,canImprove:l,onImprove:u}){let d=!!(e&&e.findings.length>0),f=!t&&e&&r!==null&&r>=0&&r<e.findings.length?e.findings[r]:null;return(0,$.jsx)(Y,{open:i,onOpenChange:a,children:(0,$.jsxs)(K,{className:`max-w-2xl`,children:[(0,$.jsxs)(H,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(q,{children:t?n?`Auditing ${n}`:`Auditing asset`:`Audit findings`}),t?(0,$.jsx)(Z,{variant:`accent`,children:`Auditing…`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{variant:`default`,children:d?`${e?.findings.length} findings`:`No findings`}),e?.learningsConsidered?(0,$.jsxs)(Z,{variant:`default`,children:[`Checked against `,bt(e.learningsConsidered)]}):null]})]}),(0,$.jsx)(Ke,{className:`text-foreground/80`,children:t?`Evaluating content against field reports from Learnings and quality standards…`:e?.summary})]}),(0,$.jsx)(z,{children:t?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center gap-3`,children:[(0,$.jsx)(ht,{size:`lg`}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:n?`Auditing ${n}…`:`Auditing asset…`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Checking content against field reports and best practice rules`})]})]}):f!==null&&r!==null&&e?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border pb-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(J,{onClick:()=>o(null),size:`sm`,type:`button`,variant:`ghost`,children:`View all findings`}),(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Finding `,r+1,` of `,e.findings.length]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(J,{"aria-label":`Previous finding`,disabled:r===0,onClick:()=>o(r-1),size:`sm`,type:`button`,variant:`outline`,children:[(0,$.jsx)(O,{className:`size-4`}),`Previous`]}),(0,$.jsxs)(J,{"aria-label":`Next finding`,disabled:r===e.findings.length-1,onClick:()=>o(r+1),size:`sm`,type:`button`,variant:`outline`,children:[`Next`,(0,$.jsx)(ne,{className:`size-4`})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(xt,{severity:f.severity}),f.source===`learning`?(0,$.jsx)(Z,{variant:`default`,children:`From learnings`}):(0,$.jsx)(Z,{variant:`default`,children:`Best practice`}),(0,$.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:f.title})]}),(0,$.jsx)(`p`,{className:`text-sm leading-6 text-foreground/90 whitespace-pre-wrap`,children:f.detail}),f.source===`learning`?(0,$.jsxs)(`div`,{className:`rounded-lg border border-border/60 bg-muted/30 p-2.5 text-xs text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:`Field report:`}),` This finding was detected from captured learning events in Learnings.`]}):null]})]}):d&&e?(0,$.jsx)(`div`,{className:`grid gap-2`,children:e.findings.map((e,t)=>(0,$.jsxs)(`button`,{className:`flex w-full flex-col gap-1.5 rounded-lg border border-border bg-card p-3.5 text-left hover:border-foreground/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>o(t),type:`button`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(xt,{severity:e.severity}),e.source===`learning`?(0,$.jsx)(Z,{variant:`default`,children:`From learnings`}):null,(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:e.title})]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-muted-foreground`,children:[`Details`,(0,$.jsx)(ne,{className:`size-3.5`})]})]}),(0,$.jsx)(`p`,{className:`text-xs text-foreground/80 leading-5`,children:e.detail})]},`${e.severity}-${e.title}`))}):(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-center gap-2`,children:[(0,$.jsx)(`div`,{className:`rounded-full bg-success/10 p-3 text-success`,children:(0,$.jsx)(oe,{className:`size-5`})}),(0,$.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`No material findings`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground max-w-sm`,children:`This asset meets quality standards and addresses checked field reports.`})]})}),(0,$.jsxs)(V,{children:[!t&&d?s?(0,$.jsx)(`p`,{className:`mr-auto text-xs text-muted-foreground leading-5`,children:`Fork this skill first if you want AI to apply improvements to a local copy.`}):(0,$.jsxs)(J,{className:`mr-auto`,disabled:!l,loading:c,onClick:u,size:`sm`,type:`button`,children:[(0,$.jsx)(N,{className:`size-4`}),c?`Improving…`:`Apply improvements`]}):null,(0,$.jsx)(J,{onClick:()=>a(!1),size:`sm`,type:`button`,variant:`outline`,children:`Close`})]})]})})}function Ct({audit:e,assetName:t,isAuditing:n=!1,isUpstreamSkill:r,isImproving:i,canImprove:a,onImprove:o,defaultOpenModal:s=!0}){let c=!!(e&&e.findings.length>0),l=!!e?.findings.some(e=>e.source===`learning`),[u,d]=(0,Q.useState)(s&&(e?.findings.length??0)>0||n),[f,p]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{n&&(d(!0),p(null))},[n]),(0,Q.useEffect)(()=>{s&&e&&e.findings.length>0&&(d(!0),p(null))},[e,s]),!e&&!n?null:(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/40 px-3 py-3 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:`Audit`}),n?(0,$.jsx)(Z,{variant:`accent`,children:`Auditing…`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Z,{variant:`default`,children:c?`${e?.findings.length} findings`:`No findings`}),c?(0,$.jsxs)(J,{className:`ml-auto h-6 px-2 text-xs`,onClick:()=>{p(null),d(!0)},size:`sm`,type:`button`,variant:`ghost`,children:[(0,$.jsx)(S,{className:`size-3.5`}),`View in modal`]}):null]})]}),(0,$.jsx)(`p`,{className:`mt-1 leading-5 text-foreground/80`,children:n?`Evaluating content against field reports and quality standards…`:e?.summary}),!n&&e?.learningsConsidered?(0,$.jsxs)(`p`,{className:`mt-1 leading-5`,children:[`Checked against `,bt(e.learningsConsidered),` from Learnings.`]}):null,!n&&c&&e?(0,$.jsx)(`ul`,{className:`mt-3 grid gap-2`,children:e.findings.map((e,t)=>(0,$.jsxs)(`li`,{className:`group relative cursor-pointer rounded-lg border border-border bg-card px-3 py-2 transition-colors hover:border-foreground/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>{p(t),d(!0)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p(t),d(!0))},role:`button`,tabIndex:0,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(Z,{variant:e.severity===`high`?`accent`:`default`,children:yt(e.severity)}),e.source===`learning`?(0,$.jsx)(Z,{variant:`default`,children:`From learnings`}):null,(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:e.title})]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-xs text-muted-foreground transition-colors group-hover:text-foreground`,children:[`Details`,(0,$.jsx)(ne,{className:`size-3`})]})]}),(0,$.jsx)(`p`,{className:`mt-1 leading-5 text-foreground/80`,children:e.detail})]},`${e.severity}-${e.title}`))}):null,!n&&c?r?(0,$.jsx)(`p`,{className:`mt-3 leading-5 text-foreground/80`,children:l?`Fork this skill to apply improvements locally, or contribute the field-report findings to the upstream repo.`:`Fork this skill first if you want AI to apply improvements to a local copy.`}):(0,$.jsxs)(J,{className:`mt-3 w-fit`,disabled:!a,loading:i,onClick:o,size:`sm`,type:`button`,children:[(0,$.jsx)(N,{className:`size-4`}),i?`Improving…`:`Apply improvements`]}):null]}),(0,$.jsx)(St,{activeFindingIndex:f,assetName:t,audit:e,canImprove:a,isImproving:i,isLoading:n,isUpstreamSkill:r,onImprove:o,onOpenChange:d,onSelectFindingIndex:p,open:u})]})}function wt({issue:e,isUpstreamSkill:t,isForkingAndFixingHeading:n,isForkingAndFixingWithAi:r,isFixingDescriptionWithAi:i,onForkAndFixHeading:a,onForkAndFixWithAi:o,onFixFromHeading:s,onFixDescriptionWithAi:c}){return(0,$.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/40 px-3 py-3 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:`Editor compatibility`}),(0,$.jsx)(Z,{variant:`warning`,children:`Missing description`})]}),(0,$.jsx)(`p`,{className:`mt-1 leading-5 text-foreground/80`,children:e.message}),t?(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsxs)(J,{loading:n,onClick:a,size:`sm`,type:`button`,variant:`secondary`,children:[(0,$.jsx)(fe,{className:`size-4`}),n?`Forking…`:`Fork & fix from heading`]}),(0,$.jsxs)(J,{loading:r,onClick:o,size:`sm`,type:`button`,children:[(0,$.jsx)(fe,{className:`size-4`}),r?`Forking…`:`Fork & fix with AI`]})]}):(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsxs)(J,{onClick:s,size:`sm`,type:`button`,variant:`secondary`,children:[(0,$.jsx)(k,{className:`size-4`}),`Fix from heading`]}),(0,$.jsxs)(J,{loading:i,onClick:c,size:`sm`,type:`button`,children:[(0,$.jsx)(N,{className:`size-4`}),i?`Drafting…`:`Fix with AI`]})]})]})}function Tt({assessment:e,recommendedLabel:t,canConvert:n,isConverting:r,isUpstreamSkill:i,onConvert:a}){return(0,$.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/40 px-3 py-3 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:`Kind check`}),(0,$.jsx)(Z,{variant:e.matchesCurrent?`default`:`accent`,children:e.matchesCurrent?`Matches`:`Suggests ${t}`})]}),(0,$.jsx)(`p`,{className:`mt-1 leading-5 text-foreground/80`,children:e.reason}),n?(0,$.jsx)(J,{className:`mt-3 w-fit`,loading:r,onClick:a,size:`sm`,type:`button`,children:r?`Converting…`:`Convert to ${e.recommendedKind}`}):null,i&&!e.matchesCurrent?(0,$.jsx)(`p`,{className:`mt-2 leading-5 text-foreground/80`,children:`Fork this skill first if you want to convert a customized copy.`}):null]})}function Et({fileCount:e,onOpenFileManager:t,onToggleFilesMenu:n}){return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-xl border border-border bg-muted/40 px-3 py-2 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(T,{className:`size-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:`Package files`}),(0,$.jsx)(Z,{variant:`default`,children:e}),(0,$.jsx)(`span`,{className:`hidden sm:inline text-muted-foreground`,children:`· Available as tabs in editor`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[t?(0,$.jsxs)(J,{className:`h-6 px-2 text-xs`,onClick:t,size:`sm`,type:`button`,variant:`secondary`,children:[(0,$.jsx)(T,{className:`mr-1 size-3`}),`Files in sidebar`]}):null,(0,$.jsxs)(J,{className:`h-6 px-2 text-xs`,onClick:n,size:`sm`,type:`button`,variant:`ghost`,children:[`Browse files `,(0,$.jsx)(re,{className:`ml-1 size-3`})]})]})]})}function Dt({kind:e,provenance:t,isUpstreamSkill:n,updateAvailable:r,upstreamBrowseUrl:i,onRetryCheck:a,isRetryingCheck:o=!1,onRelink:s,onUnlink:c,isUnlinking:l=!1}){return e!==`skills`&&!t?null:(0,$.jsxs)(`div`,{className:`rounded-xl border border-border bg-muted/40 px-3 py-3 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:`Source`}),(0,$.jsx)(Z,{variant:`default`,children:_e(t)}),n?(0,$.jsx)(Z,{variant:`default`,children:`Upstream-owned`}):null,r?(0,$.jsx)(Z,{variant:`accent`,children:`Update available`}):null,t?.unlinkedAt?(0,$.jsx)(Z,{variant:`warning`,children:t.unlinkedReason===`source-missing`?`Source gone`:`Unlinked`}):null]}),(0,$.jsx)(`p`,{className:`mt-1 break-all font-mono leading-5 text-foreground/80`,children:Ee(t)}),t?.sourceType===`path`?(0,$.jsx)(`p`,{className:`mt-1 leading-5`,children:`This source is a folder on disk, so there is no remote repository or owner to link to.`}):null,t?.subdir?(0,$.jsxs)(`p`,{className:`mt-1`,children:[`Subdir · `,(0,$.jsx)(`span`,{className:`font-mono`,children:t.subdir})]}):null,t?.updatedAt?(0,$.jsxs)(`p`,{className:`mt-1`,children:[`Locked · `,new Date(t.updatedAt).toLocaleString()]}):null,t?.lastCheckedAt?(0,$.jsxs)(`p`,{className:`mt-1`,children:[`Checked · `,new Date(t.lastCheckedAt).toLocaleString()]}):null,t?.unlinkedAt?(0,$.jsxs)(`p`,{className:`mt-2 leading-5 text-foreground/80`,children:[`Unlinked · `,new Date(t.unlinkedAt).toLocaleString(),t.unlinkedReason===`source-missing`?` — this source no longer exists. The copy below is now editable; reinstall from a new source to track it again.`:` — detached from source. The copy below is now editable; reinstall to track it again.`]}):null,t?.lastCheckError||t?.lastUpdateError?(0,$.jsxs)(`div`,{className:`mt-2 rounded-lg border border-destructive/20 bg-destructive/5 px-2.5 py-2`,children:[t.lastCheckError?(0,$.jsxs)(`p`,{className:`text-xs leading-5 text-destructive`,children:[`Check failed · `,t.lastCheckError]}):null,t.lastUpdateError?(0,$.jsxs)(`p`,{className:`text-xs leading-5 text-destructive`,children:[`Update failed · `,t.lastUpdateError]}):null,(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[a?(0,$.jsxs)(J,{loading:o,onClick:a,size:`sm`,type:`button`,variant:`secondary`,children:[(0,$.jsx)(le,{className:`size-3.5`}),`Retry check`]}):null,s&&e===`skills`&&t.sourceType===`git`?(0,$.jsx)(J,{onClick:s,size:`sm`,type:`button`,variant:`secondary`,children:`Relink…`}):null,c?(0,$.jsx)(J,{loading:l,onClick:c,size:`sm`,type:`button`,variant:`ghost`,children:`Unlink`}):null]})]}):null,n?(0,$.jsxs)(`p`,{className:`mt-2 leading-5 text-foreground/80`,children:[`Updates from source overwrite this copy. Fork to customize locally.`,i?` To propose changes upstream, open a PR in the source repo — Hub does not open PRs for you.`:null]}):null]})}function Ot(e){let t={high:0,medium:1,low:2},n=new Map;for(let t of e){let e=`${t.severity}:${t.ruleId}`,r=t.file?`${t.file}${t.line?`:${t.line}`:``}`:null,i=n.get(e);i?r&&!i.files.includes(r)&&i.files.push(r):n.set(e,{ruleId:t.ruleId,severity:t.severity,title:t.title,detail:t.detail,files:r?[r]:[]})}return[...n.values()].sort((e,n)=>t[e.severity]-t[n.severity])}var kt={"remote-code-exec":{title:`Runs code downloaded from the internet`,help:`Whatever the URL serves gets executed. Install only if you fully trust that URL.`},"exfil-endpoint":{title:`Mentions a service often used to collect stolen data`,help:`There are legitimate uses, but check why this service is referenced.`},"secret-file-exfil":{title:`Reads sensitive files and sends them elsewhere`,help:`This is the classic shape of data theft. Do not install unless you are sure it is a false alarm.`},"env-exfil":{title:`Sends environment variables to an outside address`,help:`Environment variables usually hold API keys and tokens. Do not install unless you are sure it is a false alarm.`},"trojan-source":{title:`Uses hidden characters that can disguise what code does`,help:`What you read may not be what runs. Do not install unless the file checks out.`},destructive:{title:`Can delete files or damage the system`,help:`Do not install unless you have verified these commands are safe.`},persistence:{title:`Installs something that keeps running later`,help:`Schedules or hooks execution outside the skill itself. Most skills do not need this.`},"prompt-injection":{title:`Tells the AI agent to ignore its own rules`,help:`Or to hide actions from you. Harmless when quoted as an example, dangerous as a real instruction.`},"system-write":{title:`Changes system or hub-internal files`,help:`Well outside what a skill should touch. Verify before installing.`},"credential-exfil-risk":{title:`Touches sensitive data and the network in the same file`,help:`A common data-theft shape. Review this file before installing.`},"binary-payload":{title:`Ships a ready-to-run program`,help:`Its contents cannot be reviewed as text. Check that it belongs in the skill.`},"bundled-secrets":{title:`Ships a file that looks like stored credentials`,help:`Check it is a template, not real secret material.`},"credential-access":{title:`Reaches for keys, passwords or other secrets`,help:`Check whether the skill actually needs that access.`},"config-tamper":{title:`Changes editor or agent configuration`,help:`Verify the skill is meant to manage those settings.`},"hidden-instruction":{title:`Hides instructions inside comments or markup`,help:`Invisible when you read the file, still read by the agent. Check what it says.`},obfuscation:{title:`Contains encoded or hidden content`,help:`Usually just bundled data, but it can hide a payload. Skim the file.`},"exec-primitive":{title:`Runs programs or dynamic code`,help:`Normal for skills that ship helper scripts. Check they do what the skill describes.`},"clipboard-capture":{title:`Reads the clipboard or screen`,help:`Clipboards often hold secrets. Check why the skill needs this.`},"network-outbound":{title:`Contacts the internet`,help:`Check the calls go where the skill says they go.`},"insecure-http":{title:`Uses an unencrypted HTTP address`,help:`Often just a link in documentation; worth a glance.`}},At={high:`high — likely malicious or dangerous if executed`,medium:`medium — suspicious shape, common in legitimate content too`,low:`low — informational, almost certainly benign`},jt={high:`destructive`,medium:`warning`,low:`default`},Mt=3;function Nt({findings:e}){return(0,$.jsx)(`ul`,{className:`grid gap-2.5`,children:Ot(e).map(e=>{let t=kt[e.ruleId];return(0,$.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,$.jsx)(Z,{title:At[e.severity],variant:jt[e.severity],children:e.severity}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t?.title??e.title}),(0,$.jsx)(`span`,{className:`block text-muted-foreground`,children:t?.help??e.detail}),(0,$.jsx)(Pt,{files:e.files})]})]},`${e.severity}-${e.ruleId}`)})})}function Pt({files:e}){let[t,n]=(0,Q.useState)(!1);if(e.length===0)return null;let r=t?e:e.slice(0,Mt);return(0,$.jsxs)(`span`,{className:`block font-mono text-[11px] text-muted-foreground`,children:[r.join(`, `),e.length>Mt?(0,$.jsx)(`button`,{className:`ml-1 cursor-pointer font-sans underline decoration-muted-foreground/50 underline-offset-2 hover:text-foreground`,onClick:()=>n(e=>!e),type:`button`,children:t?`show fewer`:`and ${e.length-Mt} more`}):null]})}var Ft={pass:{label:`Pass`,icon:P,variant:`success`,explanation:`The scanner found no suspicious patterns. This asset was checked before it was installed — no action needed.`},warn:{label:`Warn`,icon:D,variant:`warning`,explanation:`The scanner found patterns that appear in both legitimate and malicious content, so nothing was blocked — but the findings below are worth a look before you trust this asset.`},fail:{label:`Blocked`,icon:de,variant:`destructive`,explanation:`The scanner found strongly suspicious patterns and stopped this content from installing. Review the findings; install only if you trust the source and allow it explicitly.`}};function It({scan:e,isRescanning:t,onRescan:n}){if(!e)return null;let r=Ft[e.verdict]??Ft.warn,i=r.icon;return(0,$.jsx)(Le,{children:(0,$.jsxs)(He,{className:`grid gap-2 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(i,{className:`size-4`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:`Security scan`}),(0,$.jsx)(Z,{variant:r.variant,children:r.label}),e.overriddenAt?(0,$.jsxs)(Z,{variant:`warning`,children:[(0,$.jsx)(se,{className:`size-3`,"aria-hidden":!0}),` Allowed anyway`]}):null]}),(0,$.jsx)(J,{loading:t,onClick:n,size:`sm`,variant:`ghost`,children:`Rescan`})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r.explanation}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Scanned `,new Date(e.scannedAt).toLocaleString(),`,`,` `,e.engines.map(e=>e===`static`?`rules`:`AI review`).join(` + `),`, `,e.context]}),e.aiError?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`AI review was unavailable. The verdict below comes from the local rules engine only.`}):null,e.findings.length>0?(0,$.jsx)(Nt,{findings:e.findings}):(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No suspicious behavior found by the rules engine.`})]})})}function Lt(e){let{selected:t,nonDirectoryFiles:n}=e;return(0,$.jsxs)(`div`,{className:`grid min-h-0 max-h-72 gap-3 overflow-y-auto`,children:[e.blockingCompatIssue?(0,$.jsx)(wt,{isFixingDescriptionWithAi:e.isFixingDescriptionWithAi,isForkingAndFixingHeading:e.isForkingAndFixingHeading,isForkingAndFixingWithAi:e.isForkingAndFixingWithAi,isUpstreamSkill:e.isUpstreamSkill,issue:e.blockingCompatIssue,onFixDescriptionWithAi:e.onFixDescriptionWithAi,onFixFromHeading:e.onFixFromHeading,onForkAndFixHeading:e.onForkAndFixHeading,onForkAndFixWithAi:e.onForkAndFixWithAi}):null,(0,$.jsx)(Dt,{isRetryingCheck:e.isRetryingCheck,isUnlinking:e.isUnlinking,isUpstreamSkill:e.isUpstreamSkill,kind:t.kind,onRelink:e.onRelink,onRetryCheck:e.onRetryCheck,onUnlink:e.onUnlink,provenance:e.provenance,updateAvailable:e.updateAvailable,upstreamBrowseUrl:e.upstreamBrowseUrl}),t.kind===`skills`&&n.length>0?(0,$.jsx)(Et,{fileCount:n.length,onOpenFileManager:e.onOpenFileManager,onToggleFilesMenu:e.onToggleFilesMenu}):null,e.kindAssessment?(0,$.jsx)(Tt,{assessment:e.kindAssessment,canConvert:e.canConvert,isConverting:e.isConverting,isUpstreamSkill:e.isUpstreamSkill,onConvert:()=>e.onConvertKind(e.kindAssessment.recommendedKind),recommendedLabel:e.recommendedLabel}):null,(0,$.jsx)(It,{isRescanning:e.isRescanning,onRescan:e.onRescan,scan:e.securityScan}),e.assetAudit||e.isAuditing?(0,$.jsx)(Ct,{assetName:t.name,audit:e.assetAudit,canImprove:e.hasEditorContent,isAuditing:e.isAuditing,isImproving:e.isImproving,isUpstreamSkill:e.isUpstreamSkill,onImprove:e.onImproveAsset}):null]})}function Rt(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function zt({openTabs:e,activeTab:n,onSelectTab:r,onCloseTab:i,nonDirectoryFiles:a,filteredFiles:o,isFilesMenuOpen:s,onToggleFilesMenu:c,filesMenuRef:l,fileSearch:u,onFileSearchChange:d,onOpenFile:f}){return(0,$.jsxs)(`div`,{className:`relative mb-2 flex items-center justify-between border-b border-border pb-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto py-0.5 no-scrollbar`,children:[(0,$.jsxs)(`button`,{className:t(`flex shrink-0 items-center gap-1.5 rounded-lg px-2.5 py-1 text-xs transition-colors`,n===`SKILL.md`?`bg-muted font-medium text-foreground shadow-xs`:`text-muted-foreground hover:bg-muted/50 hover:text-foreground`),onClick:()=>r(`SKILL.md`),type:`button`,children:[(0,$.jsx)(_,{className:`size-3.5`}),(0,$.jsx)(`span`,{className:`font-mono`,children:`SKILL.md`}),(0,$.jsx)(`span`,{className:`rounded bg-background/80 px-1 py-0.2 text-2xs text-muted-foreground`,children:`Main`})]}),e.map(e=>{let a=e.split(`/`).pop()??e;return(0,$.jsxs)(`div`,{className:t(`group flex shrink-0 items-center gap-1.5 rounded-lg px-2.5 py-1 text-xs font-mono transition-colors`,n===e?`bg-muted font-medium text-foreground shadow-xs`:`text-muted-foreground hover:bg-muted/50 hover:text-foreground`),children:[(0,$.jsxs)(`button`,{className:`flex max-w-44 items-center gap-1.5 truncate text-left`,onClick:()=>r(e),title:e,type:`button`,children:[(0,$.jsx)(b,{className:`size-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:a})]}),(0,$.jsx)(`button`,{"aria-label":`Close ${a}`,className:`rounded p-0.5 text-muted-foreground opacity-70 hover:bg-background/80 hover:text-foreground hover:opacity-100`,onClick:t=>i(e,t),type:`button`,children:(0,$.jsx)(ae,{className:`size-3`})})]},e)})]}),(0,$.jsxs)(`div`,{className:`relative shrink-0 pl-2`,ref:l,children:[(0,$.jsxs)(J,{className:`h-7 gap-1 px-2 text-xs font-mono text-muted-foreground hover:text-foreground`,onClick:c,size:`sm`,type:`button`,variant:`ghost`,children:[(0,$.jsx)(`span`,{children:`+ Files`}),(0,$.jsxs)(`span`,{className:`text-2xs text-muted-foreground`,children:[`(`,a.length,`)`]}),(0,$.jsx)(re,{className:`size-3`})]}),s?(0,$.jsxs)(`div`,{className:`absolute right-0 top-full z-50 mt-1 w-80 rounded-xl border border-border bg-card p-2 shadow-lg`,children:[(0,$.jsxs)(`div`,{className:`relative mb-2`,children:[(0,$.jsx)(C,{className:`absolute left-2.5 top-2.5 size-3.5 text-muted-foreground`}),(0,$.jsx)(X,{autoFocus:!0,className:`h-8 pl-8 pr-2 text-xs font-mono`,onChange:e=>d(e.target.value),placeholder:`Search ${a.length} files...`,value:u})]}),(0,$.jsx)(`div`,{className:`max-h-64 overflow-y-auto`,children:o.length===0?(0,$.jsx)(`p`,{className:`py-4 text-center text-xs text-muted-foreground`,children:`No matching files`}):(0,$.jsx)(`ul`,{className:`grid gap-0.5`,children:o.map(r=>{let i=e.includes(r.path),a=n===r.path;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{className:t(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left font-mono text-xs transition-colors`,a?`bg-muted font-medium text-foreground`:`text-foreground/80 hover:bg-muted/50 hover:text-foreground`),onClick:()=>f(r.path),type:`button`,children:[(0,$.jsx)(b,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,title:r.path,children:r.path}),(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:Rt(r.size)}),i?(0,$.jsx)(`span`,{className:`size-1.5 shrink-0 rounded-full bg-primary`,title:`Open in tab`}):null]})},r.path)})})})]}):null]})]})}var Bt=(0,Q.lazy)(async()=>({default:(await n(()=>import(`./MarkdownSourceEditor-CV1ZTZzI.js`),__vite__mapDeps([0,1,2,3,4,5]))).MarkdownSourceEditor}));function Vt(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function Ht({activeTab:e,data:t,isLoading:n,isError:r,onBack:i}){return(0,$.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden rounded-xl border border-border`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-border bg-muted/40 px-3 py-1.5 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[(0,$.jsx)(Z,{variant:`default`,children:`Read-only`}),(0,$.jsx)(`span`,{className:`truncate font-mono font-medium text-foreground`,children:e}),t?(0,$.jsxs)(`span`,{children:[`(`,Vt(t.size),`)`]}):null,t?.truncated?(0,$.jsx)(`span`,{className:`font-medium text-warning-foreground`,children:`· Truncated (>1 MB)`}):null]}),(0,$.jsxs)(J,{className:`h-6 px-2 text-xs`,onClick:i,size:`sm`,type:`button`,variant:`ghost`,children:[(0,$.jsx)(M,{className:`mr-1 size-3`}),` Back to SKILL.md`]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:n?(0,$.jsx)(Be,{className:`h-full min-h-50 w-full`}):r?(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-sm text-destructive`,children:`Unable to load file content.`}):(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Be,{className:`h-full min-h-50 w-full`}),children:(0,$.jsx)(Bt,{"aria-label":`View sidecar ${e}`,onChange:()=>{},readOnly:!0,value:t?.content??``})})})]})}function Ut({name:e,isRenamingUi:t,renameValue:n,isRenaming:r,canRename:i,onRenameValueChange:a,onStartRename:o,onSubmitRename:s,onCancelRename:c}){return t?(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(X,{"aria-label":`Asset name`,autoFocus:!0,className:`max-w-md font-mono text-sm`,disabled:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),s()),e.key===`Escape`&&c()},value:n}),(0,$.jsxs)(J,{disabled:!n.trim(),loading:r,onClick:s,size:`icon-sm`,type:`button`,children:[(0,$.jsx)(oe,{className:`size-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Save name`})]}),(0,$.jsxs)(J,{disabled:r,onClick:c,size:`icon-sm`,type:`button`,variant:`ghost`,children:[(0,$.jsx)(ae,{className:`size-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Cancel rename`})]})]}):(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(ke,{className:`truncate`,children:e}),i?(0,$.jsxs)(J,{onClick:o,size:`icon-sm`,type:`button`,variant:`ghost`,children:[(0,$.jsx)(h,{className:`size-3.5`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Rename asset`})]}):null]})}var Wt=Q.lazy(async()=>({default:(await n(()=>import(`./MarkdownSourceEditor-CV1ZTZzI.js`),__vite__mapDeps([0,1,2,3,4,5]))).MarkdownSourceEditor}));function Gt({selected:e,securityScan:n,isRescanning:r,onRescan:i,author:a,provenance:o,isUpstreamSkill:s,upstreamBrowseUrl:l,editorContent:u,onEditorChange:d,onBack:f,onSave:p,isSaving:m,onRename:h,isRenaming:g,onFork:_,isForking:v,onUpdateFromSource:y,isUpdating:b,updateAvailable:x,onRequestDelete:S,isDeleting:C,onFixDescriptionWithAi:w,isFixingDescriptionWithAi:T,onForkAndFixHeading:E,isForkingAndFixingHeading:D,onForkAndFixWithAi:O,isForkingAndFixingWithAi:k,kindAssessment:A,onReassessKind:ee,isReassessing:j,onConvertKind:te,isConverting:N,assetAudit:ne,onAuditAsset:re,isAuditing:ie,onImproveAsset:ae,isImproving:oe,skillFiles:se,onPreviewFile:ce,activeFile:P,onSelectFile:le,onOpenFileManager:ue,onRetryCheck:de,isRetryingCheck:fe=!1,onRelink:F,onUnlink:me,isUnlinking:he=!1}){let[ge,_e]=(0,Q.useState)(!1),[L,ve]=(0,Q.useState)(!1),[ye,be]=(0,Q.useState)(e.name),[xe,R]=(0,Q.useState)(P??`SKILL.md`),[Se,we]=(0,Q.useState)([]),[Te,Ee]=(0,Q.useState)(!1),[De,Oe]=(0,Q.useState)(``),ke=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{P&&(R(P),P!==`SKILL.md`&&we(e=>e.includes(P)?e:[...e,P]))},[P]);let Ae=(0,Q.useMemo)(()=>se.filter(e=>!e.isDirectory),[se]),z=(0,Q.useMemo)(()=>{let e=De.trim().toLowerCase();return e?Ae.filter(t=>t.path.toLowerCase().includes(e)):Ae},[Ae,De]),B=e.kind===`skills`&&xe!==`SKILL.md`,V=c({queryKey:[`library`,`skill-file`,e.name,xe],queryFn:()=>I.getSkillFile(e.name,xe),enabled:B}),je=e.kind===`prompts`,Me=!s,H=(0,Q.useMemo)(()=>Ue(e.kind,u),[e.kind,u]).find(e=>e.severity===`error`)??null,U=!s&&!m&&!H;(0,Q.useEffect)(()=>{be(e.name),ve(!1),R(`SKILL.md`),we([]),Ee(!1),Oe(``)},[e.kind,e.name]),(0,Q.useEffect)(()=>{if(!Te)return;function e(e){ke.current&&!ke.current.contains(e.target)&&Ee(!1)}return document.addEventListener(`mousedown`,e),()=>{document.removeEventListener(`mousedown`,e)}},[Te]);function Pe(e){Se.includes(e)||we(t=>[...t,e]),R(e),le?.(e),Ee(!1),Oe(``)}function G(e,t){t.stopPropagation();let n=Se.filter(t=>t!==e);we(n),xe===e&&(R(`SKILL.md`),le?.(`SKILL.md`))}function Fe(){d(pe(u,e.name)),W.success(`Added description from heading — save to apply`)}function K(){H?W.error(H.message):p()}async function Ie(){let t=B?V.data?.content??``:Ye(u,e.kind).trim();if(!t)W.error(je?`Nothing to copy yet`:`Content is empty`);else try{await navigator.clipboard.writeText(t),_e(!0),W.success(B?`Copied ${xe}`:je?`Prompt copied`:`Content copied`),window.setTimeout(()=>_e(!1),1500)}catch{W.error(`Could not copy to clipboard`)}}function Re(){let t=ye.trim();!t||t===e.name?(ve(!1),be(e.name)):h(t)}let ze=A?Ce[A.recommendedKind]?.label??A.recommendedKind:null,q=!s&&A!==null&&!A.matchesCurrent;return(0,$.jsxs)(Le,{className:t(`fixed inset-0 z-40 flex min-w-0 flex-col overflow-hidden rounded-none border-0 bg-card`,`xl:static xl:z-auto xl:rounded-xl xl:border xl:border-border xl:bg-card`),children:[(0,$.jsxs)(Ne,{children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-3`,children:[(0,$.jsxs)(J,{className:`xl:hidden`,onClick:f,size:`icon-sm`,variant:`ghost`,children:[(0,$.jsx)(M,{className:`size-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`Back to index`})]}),(0,$.jsxs)(`div`,{className:`grid min-w-0 flex-1 gap-1`,children:[(0,$.jsx)(Ut,{canRename:Me,isRenaming:g,isRenamingUi:L,name:e.name,onCancelRename:()=>{ve(!1),be(e.name)},onRenameValueChange:be,onStartRename:()=>{be(e.name),ve(!0)},onSubmitRename:Re,renameValue:ye}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[s?`Viewing upstream ${e.kind}`:`Editing ${e.kind}`,g?` · Renaming…`:null]}),a?(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Author · `,a]}):null]})]}),(0,$.jsx)(Z,{variant:`accent`,children:e.kind})]}),(0,$.jsxs)(He,{className:`grid flex-1 grid-rows-[minmax(0,auto)_1fr_auto] gap-4 overflow-hidden`,children:[(0,$.jsx)(Lt,{assetAudit:ne,blockingCompatIssue:H,canConvert:q,hasEditorContent:!!u.trim(),isAuditing:ie,isConverting:N,isFixingDescriptionWithAi:T,isForkingAndFixingHeading:D,isForkingAndFixingWithAi:k,isImproving:oe,isRetryingCheck:fe,isUnlinking:he,isUpstreamSkill:s,kindAssessment:A,nonDirectoryFiles:Ae,onConvertKind:te,onFixDescriptionWithAi:w,onFixFromHeading:Fe,onForkAndFixHeading:E,onForkAndFixWithAi:O,onImproveAsset:ae,onOpenFileManager:ue,onRelink:F,onRetryCheck:de,isRescanning:r,onRescan:i,onToggleFilesMenu:()=>Ee(e=>!e),onUnlink:me,provenance:o,securityScan:n,recommendedLabel:ze,selected:e,updateAvailable:x,upstreamBrowseUrl:l}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[e.kind===`skills`&&Ae.length>0?(0,$.jsx)(zt,{activeTab:xe,fileSearch:De,filesMenuRef:ke,filteredFiles:z,isFilesMenuOpen:Te,nonDirectoryFiles:Ae,onCloseTab:G,onFileSearchChange:Oe,onOpenFile:Pe,onSelectTab:R,onToggleFilesMenu:()=>Ee(e=>!e),openTabs:Se}):null,(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:B?(0,$.jsx)(Ht,{activeTab:xe,data:V.data,isError:V.isError,isLoading:V.isLoading,onBack:()=>R(`SKILL.md`)}):(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Be,{className:`h-full min-h-50 w-full rounded-xl`}),children:(0,$.jsx)(Wt,{"aria-label":s?`View ${e.kind} ${e.name}`:`Edit ${e.kind} ${e.name}`,onChange:d,onSave:()=>{U&&K()},readOnly:s,value:u})})})]}),(0,$.jsx)(mt,{canSave:U,copied:ge,hasContent:!!u.trim(),isAuditing:ie,isDeleting:C,isForking:v,isPrompt:je,isReassessing:j,isSaving:m,isSidecarActive:B,isUpdating:b,isUpstreamSkill:s,kind:e.kind,onAuditAsset:re,onBackToMain:()=>R(`SKILL.md`),onCopy:()=>{Ie()},onFork:_,onReassessKind:ee,onRequestDelete:S,onSave:K,onUpdateFromSource:y,updateAvailable:x,upstreamBrowseUrl:l})]})]})}function Kt(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function qt(e){let t=e.toLowerCase();return t.endsWith(`.md`)||t.endsWith(`.txt`)?_:t.endsWith(`.csv`)||t.endsWith(`.tsv`)?te:t.endsWith(`.json`)||t.endsWith(`.yaml`)||t.endsWith(`.yml`)||t.endsWith(`.toml`)||t.endsWith(`.ts`)||t.endsWith(`.tsx`)||t.endsWith(`.js`)||t.endsWith(`.jsx`)||t.endsWith(`.sh`)?b:E}function Jt({file:e,label:n,isCurrent:r,onSelectFile:i,className:a}){let o=qt(e.path);return(0,$.jsxs)(`button`,{"aria-selected":r,className:t(`group flex w-full items-center justify-between gap-2 rounded-lg py-1.5 text-left text-xs transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,r?`border border-border/70 bg-muted font-medium text-foreground shadow-xs`:`text-muted-foreground hover:bg-muted/50 hover:text-foreground`,a),onClick:()=>i(e.path),title:e.path,type:`button`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(o,{className:t(`size-3.5 shrink-0`,r?`text-primary`:`text-muted-foreground`)}),(0,$.jsx)(`span`,{className:`truncate font-mono`,children:n})]}),(0,$.jsx)(`span`,{className:`font-mono text-2xs text-muted-foreground shrink-0`,children:Kt(e.size)})]})}function Yt({assetName:e,assetKind:n,files:r,activeFile:i,onSelectFile:a,onBackToAssets:o}){let[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)({}),d=(0,Q.useMemo)(()=>r.filter(e=>!e.isDirectory),[r]),f=(0,Q.useMemo)(()=>{let e=s.trim().toLowerCase();return e?d.filter(t=>t.path.toLowerCase().includes(e)):d},[d,s]),{rootFiles:m,folderGroups:h}=(0,Q.useMemo)(()=>{let e=[],t=new Map;for(let n of f){let r=n.path.split(`/`);if(r.length===1)e.push(n);else{let e=r.slice(0,-1).join(`/`),i=t.get(e);i?i.push(n):t.set(e,[n])}}return{rootFiles:e,folderGroups:Array.from(t.entries()).map(([e,t])=>({folder:e,files:t})).sort((e,t)=>e.folder.localeCompare(t.folder))}},[f]),g=e=>{u(t=>({...t,[e]:!t[e]}))},v=n===`skills`?`SKILL.md`:`${e}.md`,y=i===`SKILL.md`||i===v;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 border-b border-border pb-3`,children:[(0,$.jsxs)(J,{"aria-label":`Back to assets`,className:`-ml-2 h-8 gap-1.5 px-2 text-xs font-medium text-muted-foreground hover:text-foreground`,onClick:o,size:`sm`,type:`button`,variant:`ghost`,children:[(0,$.jsx)(M,{className:`size-3.5`}),(0,$.jsx)(`span`,{children:`Assets`}),(0,$.jsx)(`kbd`,{className:`ml-1 hidden rounded border border-border/80 bg-muted px-1 py-0.2 font-mono text-2xs text-muted-foreground sm:inline-block`,children:`Esc`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Z,{className:`text-2xs`,variant:`accent`,children:n}),(0,$.jsxs)(Z,{className:`text-2xs`,variant:`default`,children:[d.length+1,` files`]})]})]}),(0,$.jsxs)(`div`,{className:`shrink-0 space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(T,{className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`h2`,{className:`truncate text-sm font-semibold tracking-tight text-foreground`,title:e,children:e})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(C,{className:`pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(X,{"aria-label":`Filter files`,className:`h-8 rounded-lg pl-8 pr-7 text-xs`,onChange:e=>c(e.target.value),placeholder:`Filter files…`,value:s}),s?(0,$.jsx)(`button`,{"aria-label":`Clear filter`,className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,onClick:()=>c(``),type:`button`,children:(0,$.jsx)(ae,{className:`size-3.5`})}):null]})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-x-hidden overflow-y-auto space-y-3 pr-1`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`p`,{className:`px-2 text-2xs font-medium text-muted-foreground`,children:`Main file`}),(0,$.jsxs)(`button`,{"aria-selected":y,className:t(`group flex w-full items-center justify-between gap-2 rounded-lg px-2.5 py-2 text-left text-xs transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,y?`border border-border/70 bg-muted font-medium text-foreground shadow-xs`:`text-muted-foreground hover:bg-muted/50 hover:text-foreground`),onClick:()=>a(`SKILL.md`),type:`button`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(_,{className:t(`size-4 shrink-0`,y?`text-primary`:`text-muted-foreground`)}),(0,$.jsx)(`span`,{className:`truncate font-mono font-medium`,children:v})]}),(0,$.jsx)(`span`,{className:`rounded bg-background/80 px-1.5 py-0.5 text-2xs font-medium text-muted-foreground`,children:`Entry`})]})]}),d.length>0?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between px-2`,children:(0,$.jsxs)(`p`,{className:`text-2xs font-medium text-muted-foreground`,children:[`Package files (`,f.length,`)`]})}),f.length===0?(0,$.jsxs)(`p`,{className:`px-2 py-3 text-center text-xs text-muted-foreground`,children:[`No files match “`,s,`”`]}):null,m.length>0?(0,$.jsx)(`div`,{className:`space-y-0.5`,children:m.map(e=>(0,$.jsx)(Jt,{className:`px-2.5`,file:e,isCurrent:i===e.path,label:e.path,onSelectFile:a},e.path))}):null,h.map(({folder:e,files:n})=>{let r=!!l[e],o=n.some(e=>e.path===i);return(0,$.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,$.jsxs)(`button`,{className:`flex w-full items-center gap-1.5 rounded-md px-1.5 py-1 text-left text-xs text-muted-foreground hover:text-foreground transition-colors`,onClick:()=>g(e),type:`button`,children:[r?(0,$.jsx)(ne,{className:`size-3.5 shrink-0`}):(0,$.jsx)(re,{className:`size-3.5 shrink-0`}),(0,$.jsx)(p,{className:t(`size-3.5 shrink-0`,o?`text-primary`:`text-muted-foreground`)}),(0,$.jsxs)(`span`,{className:`truncate font-mono text-xs font-medium`,children:[e,`/`]}),(0,$.jsxs)(`span`,{className:`text-2xs text-muted-foreground`,children:[`(`,n.length,`)`]})]}),r?null:(0,$.jsx)(`div`,{className:`ml-3 border-l border-border/70 pl-2 space-y-0.5`,children:n.map(e=>(0,$.jsx)(Jt,{className:`px-2`,file:e,isCurrent:i===e.path,label:e.path.split(`/`).pop()??e.path,onSelectFile:a},e.path))})]},e)})]}):null]})]})}function Xt({asset:e,selected:n,compact:r=!1,onSelect:i,updateAvailable:a=!1}){let o=ve(e.kind),s=o.icon,c=e.kind===`skills`||!!e.provenance,l=c?Ee(e.provenance):null,u=Re(e.provenance??null),d=(e.compatIssues??[]).some(e=>e.severity===`error`),f=!!(e.provenance?.lastCheckError||e.provenance?.lastUpdateError),p=!!e.provenance?.unlinkedAt;return(0,$.jsx)(`button`,{className:t(`group relative grid w-full min-w-0 gap-3 rounded-xl border border-border bg-card text-left shadow-card transition-colors`,`hover:border-primary/25 hover:bg-muted/50`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background`,n&&`border-primary/40 bg-primary/5 ring-1 ring-primary/15`,r?`gap-2 p-3`:`p-4`),onClick:i,type:`button`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(s,{"aria-hidden":`true`,className:t(`mt-0.5 size-4 shrink-0 transition-colors`,n?`text-primary-strong`:`text-muted-foreground`)}),(0,$.jsxs)(`div`,{className:`grid min-w-0 flex-1 gap-1 overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium text-foreground`,children:e.name}),(0,$.jsx)(Z,{variant:`accent`,children:o.label}),c?(0,$.jsx)(Z,{variant:`default`,children:_e(e.provenance)}):null,u?(0,$.jsx)(Z,{variant:`default`,children:`Upstream-owned`}):null,a?(0,$.jsx)(Z,{variant:`accent`,children:`Update available`}):null,d?(0,$.jsx)(Z,{variant:`warning`,children:`Missing description`}):null,f?(0,$.jsx)(Z,{variant:`warning`,children:`Source issue`}):null,p?(0,$.jsx)(Z,{variant:`warning`,children:e.provenance?.unlinkedReason===`source-missing`?`Source gone`:`Unlinked`}):null]}),(0,$.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,title:e.relativePath,children:e.relativePath}),e.author?(0,$.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,title:e.author,children:[`Author · `,e.author]}):null,l?(0,$.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,title:l,children:[`Source · `,l]}):null,r?null:(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Updated `,new Date(e.updatedAt).toLocaleDateString()]})]}),r?(0,$.jsx)(`time`,{className:`shrink-0 font-mono text-2xs tabular-nums text-muted-foreground`,dateTime:e.updatedAt,children:new Date(e.updatedAt).toLocaleDateString()}):null]})})}function Zt({kindSections:e,filterKind:n,selected:r,onSelect:i,skillUpdates:a}){return e.length===0?(0,$.jsx)(`div`,{className:`rounded-xl border border-dashed border-border bg-card px-4 py-8 text-center text-sm text-muted-foreground`,children:`No assets match the current search and filter.`}):(0,$.jsxs)(`div`,{className:`grid min-w-0 gap-6 pb-2`,children:[e.length>1&&n===`__all__`?(0,$.jsx)(`div`,{className:`flex min-w-0 flex-wrap gap-2`,children:e.map(([e,t])=>(0,$.jsxs)(J,{className:`h-7 gap-1.5 px-2.5 capitalize`,onClick:()=>{document.getElementById(`library-kind-${e}`)?.scrollIntoView({behavior:`smooth`,block:`start`})},size:`sm`,type:`button`,variant:`secondary`,children:[e,(0,$.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:t.length})]},e))}):null,e.map(([e,n])=>(0,$.jsxs)(`section`,{className:`grid min-w-0 gap-3`,id:`library-kind-${e}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold capitalize text-foreground`,children:e}),(0,$.jsx)(Z,{variant:`default`,children:n.length})]}),(0,$.jsx)(`div`,{className:t(`grid min-w-0 gap-3`,r?`grid-cols-1`:`sm:grid-cols-2 xl:grid-cols-3`),children:n.map(e=>(0,$.jsx)(Xt,{asset:e,compact:!!r,onSelect:()=>i(e),selected:r?.kind===e.kind&&r?.name===e.name,updateAvailable:a?.get(e.name)??!1},`${e.kind}-${e.name}`))})]},e))]})}function Qt({open:e,onOpenChange:n,pendingEdit:r,onApprove:i,onDiscard:a}){let o=(0,Q.useMemo)(()=>r?at(r.before,r.after):[],[r]),s=o.some(e=>e.added||e.removed);return(0,$.jsx)(Y,{onOpenChange:n,open:e,children:(0,$.jsxs)(K,{className:`max-w-2xl`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{children:r?.label??`Review AI edit`}),(0,$.jsx)(Ke,{children:`Nothing is applied yet. Approve to load this into the editor, then save to persist it.`})]}),(0,$.jsx)(z,{children:s?(0,$.jsx)(`pre`,{className:`max-h-96 overflow-y-auto rounded-xl border border-border bg-muted/40 p-3 font-mono text-xs leading-5 whitespace-pre-wrap`,children:o.map((e,n)=>(0,$.jsx)(`span`,{className:t(`block`,e.added&&`bg-success/10 text-success-foreground`,e.removed&&`bg-destructive/10 text-destructive-foreground line-through`),children:e.value},n))}):(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No changes; the AI returned the same content.`})}),(0,$.jsxs)(V,{children:[(0,$.jsx)(J,{onClick:a,variant:`secondary`,children:`Discard`}),(0,$.jsx)(J,{disabled:!s,onClick:i,children:`Approve`})]})]})})}function $t(e){let t={high:0,medium:0,low:0};for(let n of e.findings)t[n.severity]+=1;return t}function en(e){return(e.asset.compatIssues?.length??0)>0}function tn(e){return e.classification!==null&&!e.classification.matchesCurrent||e.audit!==null&&e.audit.findings.length>0||en(e)}function nn({entry:e,onOpenAsset:t}){let{asset:n,classification:r,classifyError:i,audit:a,auditError:o}=e,s=Ce[n.kind]?.label??n.kind,c=r?Ce[r.recommendedKind]?.label??r.recommendedKind:null,l=a?$t(a):null;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{className:`block w-full rounded-xl border border-border bg-muted/40 px-3 py-2.5 text-left text-sm transition-colors hover:border-foreground/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,onClick:()=>t(e),type:`button`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium text-foreground`,children:n.name}),(0,$.jsx)(Z,{variant:`default`,children:s}),r&&!r.matchesCurrent?(0,$.jsxs)(Z,{variant:`accent`,children:[`Suggests `,c]}):null,r?.matchesCurrent?(0,$.jsx)(Z,{variant:`success`,children:`Kind OK`}):null,a&&a.findings.length>0?(0,$.jsxs)(Z,{variant:`default`,children:[a.findings.length,` findings`]}):null,a?.findings.length===0?(0,$.jsx)(Z,{variant:`success`,children:`Audit clean`}):null,en(e)?(0,$.jsx)(Z,{variant:`warning`,children:`Compat issue`}):null,i||o?(0,$.jsx)(Z,{variant:`destructive`,children:`Failed`}):null]}),r&&!r.matchesCurrent?(0,$.jsx)(`p`,{className:`mt-1 leading-5 text-muted-foreground`,children:r.reason}):null,l&&(l.high>0||l.medium>0||l.low>0)?(0,$.jsxs)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:[[l.high>0?`${l.high} high`:null,l.medium>0?`${l.medium} medium`:null,l.low>0?`${l.low} low`:null].filter(Boolean).join(`, `),a?.summary?`; ${a.summary}`:``]}):null,n.compatIssues?.map(e=>(0,$.jsxs)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:[e.severity===`error`?`Compat`:`Compat warning`,` · `,e.message]},e.code)),i?(0,$.jsxs)(`p`,{className:`mt-1 text-xs text-destructive`,children:[`Kind check failed · `,i]}):null,o?(0,$.jsxs)(`p`,{className:`mt-1 text-xs text-destructive`,children:[`Audit failed · `,o]}):null]})})}function rn({title:e,entries:t,onOpenAsset:n}){return t.length===0?null:(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsxs)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:[e,` (`,t.length,`)`]}),(0,$.jsx)(`ul`,{className:`grid gap-2`,children:t.map(e=>(0,$.jsx)(nn,{entry:e,onOpenAsset:n},`${e.asset.kind}/${e.asset.name}`))})]})}function an({open:e,onOpenChange:t,status:n,cancelled:r,progress:i,entries:a,totalAssets:o,onRunAgain:s,onCancel:c,onOpenAsset:l}){let u=n===`running`,d=a.filter(e=>!e.classifyError&&tn(e)),f=a.filter(e=>e.classifyError!==null),p=a.filter(e=>!e.classifyError&&!tn(e)),h=i?Math.round(i.current/Math.max(i.total,1)*100):0,g=u?i?.phase===`audit`?`Auditing flagged assets… ${i.current}/${i.total}`:`Checking kinds… ${i?.current??0}/${i?.total??o}`:[`${a.length} of ${o} checked`,d.length>0?`${d.length} need attention`:`all look right`,f.length>0?`${f.length} couldn't be checked`:null,r?`stopped early`:null].filter(Boolean).join(` · `);return(0,$.jsx)(Y,{onOpenChange:t,open:e,children:(0,$.jsxs)(K,{className:`max-w-2xl`,children:[(0,$.jsxs)(H,{children:[(0,$.jsxs)(q,{className:`flex items-center gap-2`,children:[(0,$.jsx)(m,{className:`size-5 text-muted-foreground`}),`Library analysis`]}),(0,$.jsx)(Ke,{children:g})]}),(0,$.jsxs)(z,{children:[u?(0,$.jsxs)(`div`,{"aria-label":`Analysis progress`,className:`grid gap-1.5`,role:`status`,children:[(0,$.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-muted`,children:(0,$.jsx)(`div`,{className:`h-full w-full origin-left rounded-full bg-primary transition-transform duration-300`,style:{transform:`scaleX(${h/100})`}})}),i?.label?(0,$.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:i.label}):null]}):null,(0,$.jsx)(rn,{entries:d,onOpenAsset:l,title:`Needs attention`}),(0,$.jsx)(rn,{entries:f,onOpenAsset:l,title:`Couldn't check`}),(0,$.jsx)(rn,{entries:p,onOpenAsset:l,title:`Looks right`}),!u&&a.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No assets to analyze yet.`}):null]}),(0,$.jsx)(V,{children:u?(0,$.jsx)(J,{onClick:c,variant:`secondary`,children:`Stop analysis`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(J,{onClick:s,variant:`secondary`,children:`Run again`}),(0,$.jsx)(J,{onClick:()=>t(!1),children:`Done`})]})})]})})}var on=new Set(`a.an.and.for.from.in.into.of.on.or.the.to.with.that.this.want.please.write.create.make.help.me.my.een.de.het.van.voor.met.ik.wil.maak.schrijf.dat.er.wordt.worden.uitgevoerd.uitvoeren.als.om.te.kan.kunnen.moet.moeten.zou.graag.nieuwe.nieuw.asset.skill.prompt.workflow.agent.rule`.split(`.`));function sn(e,t=48){return e.trim().toLowerCase().normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9\s-]+/g,` `).split(/[\s-]+/).filter(e=>e.length>1&&!on.has(e)).slice(0,6).join(`-`).replace(/[^a-z0-9-]+/g,`-`).replace(/-+/g,`-`).replace(/^-+|-+$/g,``).slice(0,t).replace(/-+$/g,``)}var cn={prompts:[`Review a PR for security issues and suggest concrete fixes`,`Turn messy meeting notes into clear action items`,`Write a concise commit message from a diff summary`,`Explain a codebase concept to a junior engineer`],mcp:[`Connect the GitHub MCP server with a GITHUB_TOKEN env var`,`Add a local database MCP server over stdio`,`Wire a remote HTTP MCP endpoint for our internal API`],hooks:[`Run eslint --fix after every file edit (PostToolUse)`,`Block git force-push commands before they run (PreToolUse)`,`Snapshot .env changes on session start`],skills:[`Audit React components for accessibility issues`,`Refactor messy TypeScript modules with safe steps`,`Plan and run a careful database migration`,`Review API design for consistency and error handling`],agents:[`A careful code reviewer focused on regressions`,`A senior frontend engineer for React + Tailwind`,`A debugging partner that asks clarifying questions first`,`A technical writer that turns diffs into clear changelogs`],workflows:[`Ship a feature from branch to PR with checklist steps`,`Triage a production bug from report to fix`,`Onboard a new package into this monorepo`,`Prepare a release: changelog, version, and tags`],rules:[`Always use named exports and avoid barrel files`,`Prefer Tailwind semantic tokens — no hex or arbitrary px`,`Keep tests colocated and cover new domain logic`,`Never commit secrets or modify schema without a plan`]},ln=[cn.skills[0],cn.prompts[0],cn.workflows[0],cn.agents[0],cn.rules[0]],un=(0,Q.createContext)({isLoading:!1,value:``,setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:Q.createRef()});function dn(){return(0,Q.useContext)(un)}function fn({className:e,isLoading:n=!1,maxHeight:r=240,value:i,onValueChange:a,onSubmit:o,children:s,disabled:c=!1,onClick:l,...u}){let[d,f]=(0,Q.useState)(i||``),p=(0,Q.useRef)(null);return(0,$.jsx)(qe,{children:(0,$.jsx)(un.Provider,{value:{isLoading:n,value:i??d,setValue:a??(e=>{f(e),a?.(e)}),maxHeight:r,onSubmit:o,disabled:c,textareaRef:p},children:(0,$.jsx)(`div`,{className:t(`cursor-text rounded-2xl border border-border bg-background p-2 shadow-card`,c&&`cursor-not-allowed opacity-60`,e),onClick:e=>{c||p.current?.focus(),l?.(e)},...u,children:s})})})}function pn({className:e,onKeyDown:n,disableAutosize:r=!1,...i}){let{value:a,setValue:o,maxHeight:s,onSubmit:c,disabled:l,isLoading:u,textareaRef:d}=dn(),f=e=>{e&&!r&&(e.style.height=`auto`,typeof s==`number`?e.style.height=`${Math.min(e.scrollHeight,s)}px`:e.style.height=`min(${e.scrollHeight}px, ${s})`)};return(0,Q.useLayoutEffect)(()=>{if(!d.current||r)return;let e=d.current;e.style.height=`auto`,typeof s==`number`?e.style.height=`${Math.min(e.scrollHeight,s)}px`:e.style.height=`min(${e.scrollHeight}px, ${s})`},[a,s,r,d]),(0,$.jsx)(it,{className:t(`min-h-11 w-full resize-none border-none bg-transparent px-2 py-2 text-sm text-foreground shadow-none outline-none focus-visible:border-transparent focus-visible:ring-0`,e),disabled:l||u,onChange:e=>{f(e.target),o(e.target.value)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),c?.()),n?.(e)},ref:e=>{d.current=e,f(e)},rows:1,value:a,...i})}function mn({children:e,className:n,...r}){return(0,$.jsx)(`div`,{className:t(`flex items-center gap-2`,n),...r,children:e})}function hn({tooltip:e,children:t,className:n,side:r=`top`,...i}){let{disabled:a}=dn(),o=Q.isValidElement(t)?t:(0,$.jsx)(`span`,{children:t});return(0,$.jsxs)(B,{...i,children:[(0,$.jsx)(je,{disabled:a,onClick:e=>e.stopPropagation(),render:o}),(0,$.jsx)(Ie,{className:n,side:r,children:e})]})}function gn({children:e,variant:n,size:r,className:i,highlight:a,...o}){let s=a!==void 0&&a.trim()!==``,c=typeof e==`string`?e:``;if(!s)return(0,$.jsx)(J,{className:t(`rounded-full`,i),size:r||`sm`,variant:n||`outline`,...o,children:e});if(!c)return(0,$.jsx)(J,{className:t(`w-full cursor-pointer justify-start rounded-xl py-2 hover:bg-accent`,i),size:r||`sm`,variant:n||`ghost`,...o,children:e});let l=a.trim(),u=c.toLowerCase(),d=l.toLowerCase(),f=u.includes(d);return(0,$.jsx)(J,{className:t(`w-full cursor-pointer justify-start gap-0 rounded-xl py-2 hover:bg-accent`,i),size:r||`sm`,variant:n||`ghost`,...o,children:f?(()=>{let e=u.indexOf(d);if(e===-1)return(0,$.jsx)(`span`,{className:`whitespace-pre-wrap text-muted-foreground`,children:c});let t=c.substring(e,e+d.length),n=c.substring(0,e),r=c.substring(e+t.length);return(0,$.jsxs)($.Fragment,{children:[n?(0,$.jsx)(`span`,{className:`whitespace-pre-wrap text-muted-foreground`,children:n}):null,(0,$.jsx)(`span`,{className:`whitespace-pre-wrap font-medium text-foreground`,children:t}),r?(0,$.jsx)(`span`,{className:`whitespace-pre-wrap text-muted-foreground`,children:r}):null]})})():(0,$.jsx)(`span`,{className:`whitespace-pre-wrap text-muted-foreground`,children:c})})}function _n({isAuto:e,kindLabel:t,suggestions:n,draftIntent:r,isDrafting:i,canDraft:o,thinkingText:s,onIntentChange:c,onDraftWithAi:l}){return(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e?`What should this asset do?`:`What should this ${t} do?`}),(0,$.jsxs)(a,{className:`inline-flex items-center gap-1 text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline`,to:`/settings`,children:[(0,$.jsx)(ue,{className:`size-3.5`}),`AI settings`]})]}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:n.map(e=>(0,$.jsx)(gn,{onClick:()=>c(e),type:`button`,children:e},e))}),(0,$.jsxs)(fn,{disabled:i,isLoading:i,maxHeight:160,onSubmit:()=>{o&&l()},onValueChange:c,value:r,children:[(0,$.jsx)(pn,{placeholder:e?`Describe what you need — AI chooses skill, prompt, workflow, agent, or rule…`:`Describe the ${t} you want to draft…`}),(0,$.jsxs)(mn,{className:`justify-between pt-1`,children:[i?(0,$.jsx)(vt,{size:`sm`,text:s,variant:`loading-dots`}):(0,$.jsx)(`span`,{className:`px-1 text-xs text-muted-foreground`,children:`Enter to draft · Shift+Enter for newline`}),(0,$.jsx)(hn,{tooltip:i?`AI is thinking…`:e?`Let AI choose form and draft`:`Draft ${t} with AI`,children:(0,$.jsx)(J,{"aria-busy":i||void 0,"aria-label":i?`AI is thinking`:e?`Let AI choose form and draft`:`Draft ${t} with AI`,className:`size-8 rounded-xl p-0`,disabled:!o,onClick:l,size:`icon-sm`,type:`button`,children:i?(0,$.jsx)(vt,{size:`sm`,variant:`circular`}):(0,$.jsx)(ce,{className:`size-4`})})})]})]}),i?(0,$.jsxs)(`div`,{"aria-live":`polite`,className:`flex items-center gap-3 rounded-xl border border-border bg-muted/50 px-3 py-2.5`,role:`status`,children:[(0,$.jsx)(vt,{size:`sm`,variant:`typing`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:s}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e?`This may take a moment — Hub classifies first, then writes the draft.`:`Hang tight while the draft is written.`})]})]}):null]})}function vn({open:e,onOpenChange:t,draftName:n,onDraftNameChange:r,draftNameLocked:i,onDraftNameLockedChange:a,draftKindChoice:o,onDraftKindChoiceChange:s,resolvedKind:c,kindReason:l,draftContent:u,onDraftContentChange:d,draftIntent:f,onDraftIntentChange:p,onDraftWithAi:m,isDrafting:h,onSubmit:g,isSubmitting:_}){let v=f.trim().length>0&&!h,[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(0),C=o===`auto`,w=C?`asset`:Ce[o].label.toLowerCase(),T=C?ln:cn[o],E=n.trim().length>0&&(!C||!!l)&&u.trim().length>0,D=c===`prompts`,O=C?[`Thinking about the best form…`,`Choosing skill, prompt, workflow, agent, or rule…`,`Drafting the asset…`]:[`Thinking…`,`Drafting your ${w}…`,`Almost ready…`],k=O[x%O.length];(0,Q.useEffect)(()=>{e||b(!1)},[e]),(0,Q.useEffect)(()=>{if(!h){S(0);return}let e=window.setInterval(()=>{S(e=>e+1)},2200);return()=>window.clearInterval(e)},[h]);async function A(){let e=Ye(u,c).trim();if(!e)W.error(D?`Nothing to copy yet`:`Content is empty`);else try{await navigator.clipboard.writeText(e),b(!0),W.success(D?`Prompt copied`:`Content copied`),window.setTimeout(()=>b(!1),1500)}catch{W.error(`Could not copy to clipboard`)}}let ee=e=>{i||r(sn(e))},te=e=>{p(e),ee(e)},M=e=>{s(e),!i&&f.trim()&&r(sn(f))};return(0,$.jsx)(Y,{onOpenChange:t,open:e,children:(0,$.jsxs)(K,{className:`max-w-2xl`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{children:`Create asset`}),(0,$.jsx)(Ke,{children:`Add a new portable asset to the local hub without leaving the library workspace.`})]}),(0,$.jsxs)(z,{children:[(0,$.jsxs)(`label`,{className:`grid gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Name`}),(0,$.jsx)(X,{onChange:e=>{let t=e.target.value;r(t),a(t.trim().length>0)},placeholder:`auto from intent…`,value:n}),i?(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Name locked. Clear the field to re-enable auto-naming.`}):(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Auto-filled from your intent; AI improves it after draft. Edit to lock the name.`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsxs)(`label`,{className:`grid gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Kind`}),(0,$.jsxs)($e,{value:o,onChange:e=>M(e.target.value),children:[(0,$.jsx)(`option`,{value:`auto`,children:`Auto (AI chooses)`}),(0,$.jsx)(`option`,{value:`skills`,children:`skills`}),(0,$.jsx)(`option`,{value:`agents`,children:`agents`}),(0,$.jsx)(`option`,{value:`workflows`,children:`workflows`}),(0,$.jsx)(`option`,{value:`rules`,children:`rules`}),(0,$.jsx)(`option`,{value:`prompts`,children:`prompts`})]})]}),C&&l?(0,$.jsxs)(`p`,{className:`rounded-xl border border-border bg-muted/40 px-3 py-2 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`span`,{className:`font-medium text-foreground`,children:[`→ `,Ce[c].label]}),` — `,l]}):null,C&&!l?(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Describe your intent and draft with AI. Hub picks the best form.`}):null]}),(0,$.jsx)(_n,{canDraft:v,draftIntent:f,isAuto:C,isDrafting:h,kindLabel:w,onDraftWithAi:m,onIntentChange:te,suggestions:T,thinkingText:k}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Content`}),(0,$.jsxs)(J,{disabled:h||!u.trim(),onClick:()=>{A()},size:`sm`,type:`button`,variant:`secondary`,children:[y?(0,$.jsx)(oe,{className:`size-3.5`}):(0,$.jsx)(j,{className:`size-3.5`}),y?`Copied`:D?`Copy prompt`:`Copy`]})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Be,{className:`h-64 w-full rounded-xl`}),children:(0,$.jsx)(Bt,{"aria-label":`Asset markdown content`,className:h?`h-64 opacity-50`:`h-64`,onChange:d,readOnly:h,value:u})}),h?(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 flex items-center justify-center rounded-xl bg-background/60`,children:(0,$.jsx)(vt,{size:`md`,text:`Writing draft`,variant:`loading-dots`})}):null]})]})]}),(0,$.jsxs)(V,{children:[(0,$.jsx)(J,{onClick:()=>t(!1),variant:`secondary`,children:`Cancel`}),(0,$.jsx)(J,{disabled:!E,loading:_,onClick:g,children:_?`Creating…`:C&&l?`Create ${c}`:`Create asset`})]})]})})}function yn({open:e,assetLabel:t,onKeepEditing:n,onDiscard:r}){return(0,$.jsx)(Y,{onOpenChange:e=>e?void 0:n(),open:e,children:(0,$.jsxs)(K,{className:`max-w-lg`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{children:`Discard unsaved changes?`}),(0,$.jsxs)(Ke,{children:[`You have edits in `,t,` that aren’t saved yet. If you leave now, they’re lost.`]})]}),(0,$.jsxs)(V,{children:[(0,$.jsx)(J,{onClick:n,variant:`secondary`,children:`Keep editing`}),(0,$.jsx)(J,{onClick:r,variant:`destructive`,children:`Discard changes`})]})]})})}function bn({open:e,onOpenChange:t,isLoading:n,groupedDiscovered:r,onImport:i,onImportAll:a,isCandidateImporting:o,isImportingAll:s=!1,importProgress:c=null}){let l=Object.entries(r),u=l.flatMap(([,e])=>e),d=s?c?`Importing (${c.current}/${c.total})…`:`Importing…`:`Import all (${u.length})`;return(0,$.jsx)(Y,{onOpenChange:t,open:e,children:(0,$.jsxs)(K,{className:`max-w-2xl`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{children:`Discover`}),(0,$.jsx)(Ke,{children:`Assets that exist in a linked editor but are not yet in the hub. Importing copies them in and keeps them in sync everywhere from now on.`})]}),(0,$.jsx)(z,{children:n?(0,$.jsxs)(`div`,{"aria-busy":`true`,"aria-label":`Scanning editors`,className:`grid gap-3`,children:[(0,$.jsx)(Be,{className:`h-4 w-32`}),(0,$.jsx)(Be,{className:`h-16 w-full`}),(0,$.jsx)(Be,{className:`h-16 w-full`}),(0,$.jsx)(Be,{className:`h-16 w-full`})]}):l.length>0?(0,$.jsxs)(`div`,{className:`grid gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl border border-border bg-card/60 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-medium text-foreground`,children:[u.length,` unmanaged asset`,u.length===1?``:`s`,` found`]}),l.length>1?(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`across `,l.length,` editors`]}):null]}),(0,$.jsx)(J,{className:`w-full shrink-0 sm:w-auto`,loading:s,onClick:()=>a(u),size:`sm`,children:d})]}),l.map(([e,t])=>(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:e}),(0,$.jsx)(Z,{children:t.length})]}),l.length>1&&t.length>1?(0,$.jsxs)(J,{loading:s,onClick:()=>a(t),size:`sm`,variant:`secondary`,children:[`Import from `,e]}):null]}),(0,$.jsx)(`ul`,{className:`overflow-hidden rounded-2xl border border-border`,children:t.map(e=>{let t=o(e);return(0,$.jsxs)(`li`,{className:`flex min-w-0 items-start justify-between gap-3 border-b border-border px-3 py-3 last:border-b-0`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`strong`,{className:`text-sm font-medium text-foreground`,children:e.name}),(0,$.jsx)(Z,{variant:`accent`,children:e.kind})]}),(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs text-muted-foreground`,children:e.preview})]}),(0,$.jsx)(J,{className:`w-fit shrink-0`,disabled:t,loading:t&&!s,onClick:()=>i(e),size:`sm`,children:t&&!s?`Importing…`:`Import`})]},`${e.editorId}-${e.kind}-${e.name}`)})})]},e))]}):(0,$.jsx)(`div`,{className:`rounded-2xl border border-dashed border-border px-4 py-6 text-sm text-muted-foreground`,children:`Nothing to import; every native asset in your linked editors is already tracked by the hub.`})}),(0,$.jsxs)(V,{children:[u.length>0?(0,$.jsx)(J,{loading:s,onClick:()=>a(u),children:d}):null,(0,$.jsx)(J,{onClick:()=>t(!1),variant:`secondary`,children:`Close`})]})]})})}function xn({open:e,onOpenChange:t,selected:n,takenNames:r,onSubmit:i,onOpenExisting:a,isForking:o}){let[s,c]=(0,Q.useState)(``);(0,Q.useEffect)(()=>{e&&n&&c(`${n.name}-local`)},[e,n]);let l=Pe(s),u=l!==``&&l===n?.name,d=l!==``&&!u&&r.has(l),f=!l||u||d;function p(){!f&&n&&i(l)}return(0,$.jsx)(Y,{onOpenChange:t,open:e,children:(0,$.jsxs)(K,{className:`max-w-lg`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{children:`Fork to customize`}),(0,$.jsxs)(Ke,{children:[`Copy `,n?`${n.kind}/${n.name}`:`this asset`,` into an editable local asset. The upstream original keeps tracking its source; the fork is yours to change.`]})]}),(0,$.jsxs)(z,{children:[(0,$.jsxs)(`label`,{className:`grid gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Fork name`}),(0,$.jsx)(X,{"aria-label":`Fork name`,autoFocus:!0,disabled:o,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p())},value:s})]}),u?(0,$.jsx)(`p`,{className:`text-xs text-destructive`,children:`The fork name must differ from the upstream name.`}):null,d&&n?(0,$.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/40 p-4 text-sm text-muted-foreground`,children:[(0,$.jsxs)(`p`,{children:[n.kind,`/`,l,` already exists in the hub. It may be a fork you made earlier.`]}),(0,$.jsxs)(J,{className:`mt-3`,onClick:()=>a(l),size:`sm`,type:`button`,variant:`secondary`,children:[`Open `,n.kind,`/`,l]})]}):null]}),(0,$.jsxs)(V,{children:[(0,$.jsx)(J,{onClick:()=>t(!1),variant:`secondary`,children:`Cancel`}),(0,$.jsxs)(J,{disabled:f,loading:o,onClick:p,children:[(0,$.jsx)(fe,{className:`size-4`}),o?`Forking…`:`Create fork`]})]})]})})}async function Sn(e){let t=await e.arrayBuffer(),n=new Uint8Array(t),r=``,i=32768;for(let e=0;e<n.length;e+=i)r+=String.fromCharCode(...n.subarray(e,e+i));return btoa(r)}async function Cn(e){let t=Array.from(e);if(t.length===0)throw Error(`No files selected`);let n=t.map(e=>e.webkitRelativePath||e.name)[0]?.split(`/`)[0]||`skill`,r=[];for(let e of t){let t=(e.webkitRelativePath||e.name).replace(/\\/g,`/`),i=t.startsWith(`${n}/`)?t.slice(n.length+1):t;i&&!i.endsWith(`/`)&&r.push({path:i,contentBase64:await Sn(e)})}if(!r.some(e=>e.path===`SKILL.md`||e.path.endsWith(`/SKILL.md`)))throw Error(`Selected folder must contain SKILL.md`);return{label:n,files:r}}function wn(e){return e.split(`/`).filter(Boolean).pop()??`repo root`}function Tn(e){let t=d(),n=(0,Q.useRef)(null),[r,i]=(0,Q.useState)(!1),[a,s]=(0,Q.useState)(`path`),[c,l]=(0,Q.useState)(``),[u,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)([]),[C,w]=(0,Q.useState)(null),[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)([]),[k,A]=(0,Q.useState)([]),ee=T?[...T.hasRootSkill?[``]:[],...T.dirs]:[],j=a===`repo`&&ee.length>1,te=()=>{E(null),O([])},M=()=>A([]),N=()=>{l(``),f(``),m(``),g(``),v(!1),w(null),te(),M(),n.current&&(n.current.value=``)},ne=o({mutationFn:e=>I.discoverSkillDirs({repo:e}),onSuccess:e=>{let t=[...e.hasRootSkill?[``]:[],...e.dirs];t.length===0?(te(),W.error(`No SKILL.md found in this repo`)):(E(e),O(t),!e.hasRootSkill&&e.dirs.length===1&&m(e.dirs[0]))},onError:e=>{te(),W.error(e.message||`Unable to scan repo`)}}),re=o({mutationFn:async()=>{let e=[];if(a===`path`&&C)e.push({label:C.label,payload:{files:C.files}});else if(a===`path`)e.push({label:c.trim(),payload:{path:c.trim()}});else{let t=j?D:[p.trim()];for(let n of t)e.push({label:n||u.trim(),payload:{repo:u.trim(),subdir:n||void 0,name:t.length===1&&h.trim()||void 0}})}return Promise.all(e.map(async({label:e,payload:t})=>{let n=await I.scanSkillSource(t);return{label:e,scan:n.scan,detectedSubdir:n.detectedSubdir}}))},onSuccess:e=>{A(e);let t=e.length===1?e[0].detectedSubdir:void 0;a===`repo`&&t&&!p.trim()&&m(t)},onError:e=>{A([]),W.error(`Unable to run the security scan`,{description:e.message||`Check that the hub API is running.`,action:{label:`Retry scan`,onClick:()=>re.mutate()}})}});return{installOpen:r,setInstallOpen:i,installMode:a,setInstallMode:s,installPath:c,setInstallPath:l,installRepo:u,setInstallRepo:f,handleInstallRepoChange:e=>{f(e),M(),T&&te()},installSubdir:p,setInstallSubdir:m,installName:h,setInstallName:g,installForce:_,setInstallForce:v,browsedFolder:C,setBrowsedFolder:w,folderInputRef:n,installSkill:o({mutationFn:async e=>{if(a===`path`&&C)try{return{installed:[await I.installSkillBundle({files:C.files,name:h.trim()||C.label||void 0,force:_,allowUnsafe:e})],failures:[]}}catch(e){return{installed:[],failures:[{subdir:``,error:e instanceof Error?e:Error(String(e))}]}}let t=j?D:[p.trim()],n=[],r=[];for(let i of t)try{n.push(await I.installSkill({path:a===`path`&&c.trim()||void 0,repo:a===`repo`&&u.trim()||void 0,subdir:a===`repo`&&i?i:void 0,name:t.length===1&&h.trim()||void 0,force:_,allowUnsafe:e}))}catch(e){r.push({subdir:i,error:e instanceof Error?e:Error(String(e))})}return{installed:n,failures:r}},onSuccess:({installed:n,failures:r})=>{n.length>0&&(t.invalidateQueries({queryKey:[`library`]}),t.invalidateQueries({queryKey:[`setup`]}),t.invalidateQueries({queryKey:[`overview`]}));let o=r.find(e=>e.error instanceof Fe);if(r.length>0){if(j&&O(r.map(e=>e.subdir)),o){b(o.error.scan);let e=r.filter(e=>e.error instanceof Fe).map(e=>a===`repo`?wn(e.subdir):C?.label??c.trim().split(`/`).filter(Boolean).pop()??`this skill`);S(e),W.error(`Security scan blocked ${e[0]} — review the findings`)}else{b(null),S([]);let[e]=r;W.error(r.length===1?e.error.message||`Unable to install skill`:`${e.error.message} — ${r.length-1} more failed`)}n.length>0&&W.success(n.length===1?`Installed skills/${n[0].asset.name}`:`Installed ${n.length} skills`);return}i(!1),b(null),S([]),N();let s=n[n.length-1];e.onInstalled({kind:`skills`,name:s.asset.name}),W.success(n.length===1?`Installed skills/${s.asset.name}`:`Installed ${n.length} skills`)},onError:e=>{b(null),S([]),W.error(e.message||`Unable to install skill`)}}),migrateAgentsSkills:o({mutationFn:async()=>I.migrateAgentsSkills({}),onSuccess:e=>{let n=e.results.filter(e=>e.status===`migrated`).length,r=e.results.filter(e=>e.status===`skipped`).length,i=e.results.filter(e=>e.status===`failed`).length;t.invalidateQueries({queryKey:[`library`]}),t.invalidateQueries({queryKey:[`overview`]}),W.success(`Agents migrate: ${n} migrated, ${r} skipped, ${i} failed`)},onError:()=>{W.error(`Unable to migrate from ~/.agents/.skill-lock.json`)}}),installSubmitDisabled:a===`path`?!C&&c.trim().length===0:u.trim().length===0||j&&D.length===0,handleBrowseFiles:e=>{Cn(e).then(e=>{w(e),l(``),M(),h.trim()||g(e.label),W.success(`Selected ${e.label} (${e.files.length} files)`)}).catch(e=>{w(null),W.error(e.message||`Unable to read folder`)})},blockedScan:y,blockedLabels:x,clearBlockedScan:()=>b(null),previewScans:k,scanSkillSecurity:re,handleInstallSubdirChange:e=>{m(e),M()},handleInstallPathChange:e=>{w(null),l(e),M()},handleInstallModeChange:e=>{s(e),w(null),M()},repoScan:T,scanOptions:ee,repoPickerActive:j,selectedDirs:D,toggleSelectedDir:e=>{M(),O(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},scanSkillDirs:ne,clearRepoScan:te}}function En({scans:e}){let t=[...new Set(e.map(e=>e.scan.aiError).filter(e=>!!e))];return t.length===0?null:(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`AI review did not run`,t.length===1?`: ${t[0]}`:``,`. The result comes from the local rules engine only.`]})}function Dn({scans:e}){let t=e.filter(e=>e.scan.verdict===`fail`),n=e.filter(e=>e.scan.verdict===`warn`),r=e.filter(e=>e.scan.verdict!==`pass`);if(t.length===0&&n.length===0)return(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-success/40 bg-success/5 p-3`,role:`status`,children:[(0,$.jsx)(P,{className:`size-4 text-success-foreground`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`text-sm`,children:[`Security scan found no risky patterns`,e.length>1?` in ${e.length} skills`:``]})]}),(0,$.jsx)(En,{scans:e})]});let i=t.length>0;return(0,$.jsxs)(`div`,{className:`grid gap-2 rounded-lg border p-3 ${i?`border-destructive/40 bg-destructive/5`:`border-warning/40 bg-warning/5`}`,role:i?`alert`:`status`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(de,{className:`size-4 ${i?`text-destructive`:`text-warning-foreground`}`,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:i?`Security scan will block ${t.map(e=>e.label).join(`, `)}`:`Security scan flagged ${n.map(e=>e.label).join(`, `)}`})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i?`Installing is stopped unless you explicitly allow it. Check the flagged files and install only if you trust the source.`:`Nothing is blocked. These patterns also appear in legitimate files, so check the flagged files in the source before installing.`}),r.map(({label:e,scan:t})=>(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[r.length>1?(0,$.jsx)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:e}):null,(0,$.jsx)(Nt,{findings:t.findings})]},e)),(0,$.jsx)(En,{scans:e})]})}function On({labels:e,scan:t}){return(0,$.jsxs)(`div`,{className:`grid gap-2 rounded-lg border border-destructive/40 bg-destructive/5 p-3`,role:`alert`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(de,{className:`size-4 text-destructive`,"aria-hidden":!0}),(0,$.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Security scan flagged `,e.length>0?e.join(`, `):`this skill`]})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`An automated check found patterns that are also used by harmful skills. Check the flagged files and install only if you trust the source; the override is recorded.`}),(0,$.jsx)(Nt,{findings:t.findings})]})}function kn({open:e,onOpenChange:t,installMode:n,onInstallModeChange:r,installPath:i,onInstallPathChange:a,installRepo:o,onInstallRepoChange:s,installSubdir:c,onInstallSubdirChange:l,installName:u,onInstallNameChange:d,installForce:f,onInstallForceChange:p,browsedFolder:m,folderInputRef:h,onBrowseFiles:g,onSubmit:_,isInstalling:y,submitDisabled:b,blockedScan:x,blockedLabels:S,onMigrate:w,isMigrating:T,scanOptions:E,repoPickerActive:D,selectedDirs:O,onToggleDir:k,onScanRepo:A,isScanning:ee,previewScans:j,onSecurityScan:te,isSecurityScanning:M}){let N=D?O.length:1,ne=n===`repo`&&E.length===1&&E[0]!==``,re=j.some(e=>e.scan.verdict===`fail`),ie=n===`path`?!m&&i.trim().length===0:o.trim().length===0||D&&O.length===0;return(0,$.jsx)(Y,{onOpenChange:t,open:e,children:(0,$.jsxs)(K,{className:`max-w-2xl`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{children:`Install skill`}),(0,$.jsx)(Ke,{children:`Install into the hub from a local folder or git repo, then project to Claude, Cursor, and other editors.`})]}),(0,$.jsxs)(z,{children:[(0,$.jsx)(nt,{onValueChange:e=>r(e),value:n,children:(0,$.jsxs)(et,{children:[(0,$.jsx)(tt,{value:`path`,children:`Local path`}),(0,$.jsx)(tt,{value:`repo`,children:`Git repo`})]})}),n===`path`?(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Skill directory`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(X,{onChange:e=>a(e.target.value),placeholder:`/Users/you/www/skills/my-skill`,value:m?`${m.label} (${m.files.length} files)`:i}),(0,$.jsxs)(J,{className:`shrink-0`,onClick:()=>h.current?.click(),type:`button`,variant:`secondary`,children:[(0,$.jsx)(v,{className:`size-4`}),`Browse`]}),(0,$.jsx)(`input`,{className:`hidden`,multiple:!0,onChange:e=>{let t=e.target.files;t&&t.length!==0&&g(t)},ref:e=>{h.current=e,e&&(e.setAttribute(`webkitdirectory`,``),e.setAttribute(`directory`,``))},type:`file`})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Browse selects a folder and uploads it to the hub. You can still paste an absolute server path instead.`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Repository URL`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(X,{onChange:e=>s(e.target.value),placeholder:`https://github.com/org/skills.git`,value:o}),(0,$.jsxs)(J,{className:`shrink-0`,disabled:o.trim().length===0,loading:ee,onClick:A,type:`button`,variant:`secondary`,children:[(0,$.jsx)(C,{className:`size-4`}),ee?`Scanning…`:`Scan`]})]})]}),D?(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[E.length,` skills found. Select which to install`]}),(0,$.jsx)(`ul`,{className:`grid max-h-52 gap-0.5 overflow-y-auto rounded-md border border-border p-1`,children:E.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`label`,{className:`flex cursor-pointer select-none items-center gap-2.5 rounded-sm px-2 py-1.5 text-sm transition-colors hover:bg-muted`,children:[(0,$.jsx)(ot,{checked:O.includes(e),onCheckedChange:()=>k(e)}),(0,$.jsx)(`span`,{className:`font-mono text-xs`,children:e||`(repo root)`})]})},e||`__root__`))}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[O.length,` of `,E.length,` selected`]})]}):(0,$.jsxs)(`label`,{className:`grid gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Subdir (optional)`}),(0,$.jsx)(X,{onChange:e=>l(e.target.value),placeholder:`e.g. plugin/skills/my-skill`,value:c}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave empty to auto-detect SKILL.md in the repo root or subfolders, or use Scan to pick from a list.`})]}),ne?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Found one skill in the repo; filled it in as Subdir.`}):null,E.length===1&&E[0]===``?(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Found SKILL.md at the repo root.`}):null]}),N===1?(0,$.jsxs)(`label`,{className:`grid gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Name override (optional)`}),(0,$.jsx)(X,{onChange:e=>d(e.target.value),value:u})]}):null,(0,$.jsxs)(`label`,{className:`flex cursor-pointer select-none items-center gap-2.5 text-sm text-muted-foreground transition-colors hover:text-foreground`,children:[(0,$.jsx)(ot,{checked:f,id:`install-force`,onCheckedChange:e=>p(!!e)}),(0,$.jsx)(`span`,{children:`Replace if the skill already exists in the hub`})]}),x?(0,$.jsx)(On,{labels:S,scan:x}):j.length>0?(0,$.jsx)(Dn,{scans:j}):null]}),(0,$.jsxs)(V,{children:[(0,$.jsx)(J,{loading:T,onClick:w,variant:`secondary`,children:T?`Migrating…`:`Migrate from agents lock`}),(0,$.jsxs)(J,{disabled:ie,loading:M,onClick:te,variant:`secondary`,children:[(0,$.jsx)(P,{className:`size-4`}),M?`Scanning…`:`Security scan`]}),(0,$.jsx)(J,{onClick:()=>t(!1),variant:`secondary`,children:`Cancel`}),x||re?(0,$.jsx)(J,{loading:y,onClick:()=>_(!0),variant:`destructive`,children:y?`Installing…`:`Install anyway`}):(0,$.jsx)(J,{disabled:b,loading:y,onClick:()=>_(),children:y?`Installing…`:N>1?`Install ${N} skills`:`Install`})]})]})})}function An({open:e,onOpenChange:t,selected:n,onConfirm:r,isDeleting:i}){return(0,$.jsx)(Y,{onOpenChange:t,open:e,children:(0,$.jsxs)(K,{className:`max-w-lg`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{children:`Delete asset`}),(0,$.jsx)(Ke,{children:`This permanently deletes the file from the local hub and pushes the removal to every connected editor that supports this asset kind. It will disappear there too.`})]}),(0,$.jsx)(z,{children:(0,$.jsx)(`div`,{className:`rounded-2xl border border-border bg-muted/40 p-4 text-sm text-muted-foreground`,children:n?`${n.kind}/${n.name} will be permanently deleted everywhere.`:`No asset is selected.`})}),(0,$.jsxs)(V,{children:[(0,$.jsx)(J,{onClick:()=>t(!1),variant:`secondary`,children:`Cancel`}),(0,$.jsx)(J,{disabled:!n,loading:i,onClick:r,variant:`destructive`,children:i?`Deleting…`:`Confirm delete`})]})]})})}function jn(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function Mn({skillName:e,path:t,onOpenChange:n}){let r=e!==null&&t!==null,i=c({queryKey:[`library`,`skill-file`,e,t],queryFn:()=>I.getSkillFile(e,t),enabled:r});return(0,$.jsx)(Y,{onOpenChange:n,open:r,children:(0,$.jsxs)(K,{className:`max-w-2xl`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{className:`font-mono`,children:t}),(0,$.jsxs)(Ke,{children:[`Read-only preview. This file isn’t editable from Chain Hub yet.`,i.data?` ${jn(i.data.size)}`:null]})]}),(0,$.jsxs)(z,{children:[i.isLoading?(0,$.jsx)(Be,{className:`h-64 w-full rounded-xl`}):null,i.isError?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:`Unable to load this file.`}):null,i.data?(0,$.jsxs)($.Fragment,{children:[i.data.truncated?(0,$.jsx)(`p`,{className:`mb-2 text-xs text-warning-foreground`,children:`File is larger than 1 MB. Showing the first part only.`}):null,(0,$.jsx)(`pre`,{className:`max-h-96 overflow-auto rounded-xl border border-border bg-muted/40 p-3 font-mono text-xs leading-5 whitespace-pre-wrap`,children:i.data.content})]}):null]})]})})}var Nn={updated:{label:`Updated`,variant:`success`},migrated:{label:`Migrated`,variant:`success`},skipped:{label:`Up to date`,variant:`default`},failed:{label:`Failed`,variant:`destructive`}};function Pn(e){return e?e.slice(0,7):`unknown`}function Fn({results:e,onOpenChange:t}){let n=e??[],r=n.filter(e=>e.status===`updated`||e.status===`migrated`).length,i=n.filter(e=>e.status===`failed`).length,a=n.filter(e=>e.status===`skipped`).length,o=[`${r} updated`,`${a} up to date`,i>0?`${i} failed`:null].filter(Boolean).join(`, `);return(0,$.jsx)(Y,{onOpenChange:t,open:e!==null,children:(0,$.jsxs)(K,{className:`max-w-lg`,children:[(0,$.jsxs)(H,{children:[(0,$.jsx)(q,{children:`Skill update summary`}),(0,$.jsxs)(Ke,{children:[n.length,` checked: `,o]})]}),(0,$.jsx)(z,{children:(0,$.jsx)(`ul`,{className:`grid gap-2`,children:n.map(e=>{let t=Nn[e.status],n=e.lockEntry?.commitSha,r=(e.status===`updated`||e.status===`migrated`)&&(e.previousCommitSha||n);return(0,$.jsxs)(`li`,{className:`rounded-xl border border-border bg-muted/40 px-3 py-2.5 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate font-medium text-foreground`,children:e.name}),(0,$.jsx)(Z,{variant:t.variant,children:t.label})]}),r?(0,$.jsxs)(`p`,{className:`mt-1 font-mono text-xs text-muted-foreground`,children:[Pn(e.previousCommitSha),` → `,Pn(n)]}):null,e.lockEntry?.source?(0,$.jsxs)(`p`,{className:`mt-1 truncate text-xs text-muted-foreground`,title:e.lockEntry.source,children:[`Source · `,e.lockEntry.source]}):null,e.error?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-destructive`,children:e.error}):null]},e.name)})})}),(0,$.jsx)(V,{children:(0,$.jsx)(J,{onClick:()=>t(!1),children:`Done`})})]})})}function In({createFlow:e,installFlow:t,analysis:n,review:r,selected:i,discardOpen:a,onDiscardChanges:o,onKeepEditing:s,removeOpen:c,isDeleting:l,onRemoveConfirm:u,onRemoveOpenChange:d,forkOpen:f,isForking:p,onForkOpenChange:m,onForkSubmit:h,onForkOpenExisting:g,forkTakenNames:_,pendingAiEdit:v,onApproveAiEdit:y,onDiscardAiEdit:b,discoverOpen:x,onDiscoverOpenChange:S,groupedDiscovered:C,importProgress:w,isCandidateImporting:T,isImportingAll:E,discoverLoading:D,onImportCandidate:O,onImportAll:k,analyzeOpen:A,onAnalyzeOpenChange:ee,onOpenAnalyzedAsset:j,onRunAnalysisAgain:te,totalAssets:M,updateResults:N,onUpdateResultsOpenChange:ne,relinkTarget:re,onRelinkOpenChange:ie,previewFilePath:ae,onPreviewOpenChange:oe}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(vn,{draftContent:e.draftContent,draftIntent:e.draftIntent,draftKindChoice:e.draftKindChoice,draftName:e.draftName,draftNameLocked:e.draftNameLocked,isDrafting:e.draftPromptWithAi.isPending,isSubmitting:e.createAsset.isPending,kindReason:e.kindReason,onDraftContentChange:e.setDraftContent,onDraftIntentChange:e.setDraftIntent,onDraftKindChoiceChange:e.handleDraftKindChoiceChange,onDraftNameChange:e.setDraftName,onDraftNameLockedChange:e.setDraftNameLocked,onDraftWithAi:()=>e.draftPromptWithAi.mutate(),onOpenChange:e.setCreateOpenSynced,onSubmit:()=>e.createAsset.mutate(),open:e.createOpen,resolvedKind:e.draftKind}),(0,$.jsx)(kn,{blockedLabels:t.blockedLabels,blockedScan:t.blockedScan,browsedFolder:t.browsedFolder,folderInputRef:t.folderInputRef,installForce:t.installForce,installMode:t.installMode,installName:t.installName,installPath:t.installPath,installRepo:t.installRepo,installSubdir:t.installSubdir,isInstalling:t.installSkill.isPending,isMigrating:t.migrateAgentsSkills.isPending,isScanning:t.scanSkillDirs.isPending,isSecurityScanning:t.scanSkillSecurity.isPending,onBrowseFiles:t.handleBrowseFiles,onInstallForceChange:t.setInstallForce,onInstallModeChange:t.handleInstallModeChange,onInstallNameChange:t.setInstallName,onInstallPathChange:t.handleInstallPathChange,onInstallRepoChange:t.handleInstallRepoChange,onInstallSubdirChange:t.handleInstallSubdirChange,onSecurityScan:()=>t.scanSkillSecurity.mutate(),onMigrate:()=>t.migrateAgentsSkills.mutate(),onOpenChange:t.setInstallOpen,onScanRepo:()=>t.scanSkillDirs.mutate(t.installRepo.trim()),onSubmit:e=>t.installSkill.mutate(e??!1),onToggleDir:t.toggleSelectedDir,open:t.installOpen,previewScans:t.previewScans,repoPickerActive:t.repoPickerActive,scanOptions:t.scanOptions,selectedDirs:t.selectedDirs,submitDisabled:t.installSubmitDisabled}),(0,$.jsx)(yn,{assetLabel:i?`${i.kind}/${i.name}`:`this asset`,onDiscard:o,onKeepEditing:s,open:a}),(0,$.jsx)(An,{isDeleting:l,onConfirm:u,onOpenChange:d,open:c,selected:i}),(0,$.jsx)(xn,{isForking:p,onOpenChange:m,onOpenExisting:g,onSubmit:h,open:f,selected:i,takenNames:_}),(0,$.jsx)(Qt,{onApprove:y,onDiscard:b,onOpenChange:e=>{e||b()},open:v!==null,pendingEdit:v}),(0,$.jsx)(bn,{groupedDiscovered:C,importProgress:w,isCandidateImporting:T,isImportingAll:E,isLoading:D,onImport:O,onImportAll:k,onOpenChange:S,open:x}),(0,$.jsx)(an,{cancelled:n.cancelled,entries:n.entries,onCancel:n.cancel,onOpenAsset:j,onOpenChange:ee,onRunAgain:te,open:A,progress:n.progress,status:n.status,totalAssets:M}),(0,$.jsx)(Fn,{onOpenChange:ne,results:N}),(0,$.jsx)(rt,{onOpenChange:ie,skillName:re}),(0,$.jsx)(Qt,{onApprove:()=>void r.approveQueuedDiff(),onDiscard:r.discardQueuedDiff,onOpenChange:e=>{e||r.discardQueuedDiff()},open:v===null&&r.diffQueue.length>0,pendingEdit:v===null&&r.diffQueue.length>0?{label:`Improve ${r.diffQueue[0].kind}/${r.diffQueue[0].name}`,before:r.diffQueue[0].before,after:r.diffQueue[0].after}:null}),(0,$.jsx)(Mn,{onOpenChange:oe,path:ae,skillName:i?.kind===`skills`?i.name:null})]})}function Ln(e){return e?e.slice(0,7):`…`}function Rn({items:e,isCompact:n,isUpdatingSkills:r,onUpdateSkill:i,onUpdateSkills:a}){let o=e.length;return o===0?(0,$.jsxs)(B,{children:[(0,$.jsx)(je,{render:(0,$.jsx)(J,{"aria-label":r?`Updating skills`:`Update skills`,disabled:r,onClick:a,size:`icon-sm`,variant:`secondary`,children:(0,$.jsx)(le,{className:t(`size-4`,r&&`animate-spin`)})})}),(0,$.jsx)(Ie,{children:r?`Updating…`:`Update skills`})]}):(0,$.jsxs)(G,{children:[(0,$.jsx)(be,{render:n?(0,$.jsxs)(J,{"aria-label":r?`Updating skills`:`Update ${o} skills`,disabled:r,size:`sm`,variant:`secondary`,children:[(0,$.jsx)(le,{className:t(`size-4`,r&&`animate-spin`)}),(0,$.jsx)(`span`,{className:`tabular-nums`,children:o})]}):(0,$.jsxs)(J,{disabled:r,size:`sm`,variant:`secondary`,children:[(0,$.jsx)(le,{className:t(`size-4`,r&&`animate-spin`)}),r?`Updating…`:`Update (${o})`]})}),(0,$.jsxs)(xe,{align:`end`,className:`w-80`,children:[(0,$.jsxs)(R,{children:[(0,$.jsxs)(he,{children:[o,` update`,o===1?``:`s`,` available`]}),e.map(e=>(0,$.jsxs)(Se,{onClick:()=>i(e.name),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name}),(0,$.jsxs)(`span`,{className:`ml-auto shrink-0 font-mono text-2xs tabular-nums text-muted-foreground`,children:[Ln(e.currentSha),` → `,Ln(e.latestSha)]})]},e.name))]}),(0,$.jsx)(L,{}),(0,$.jsxs)(Se,{onClick:a,children:[(0,$.jsx)(le,{}),`Update all (`,o,`)`]})]})]})}function zn({assetCount:e,filterKind:n,isCompact:r,view:i,reviewOpenCount:a,onViewChange:o,ownership:s,searchQuery:c,onOwnershipChange:l,onSearchQueryChange:u,onCreate:d,onInstall:f,onDiscover:p,onAnalyze:h,isAnalyzing:g,onUpdateSkills:_,onUpdateSkill:v,isUpdatingSkills:b,skillUpdateItems:x=[]}){return(0,$.jsxs)(`div`,{className:`grid min-w-0 shrink-0 gap-3 pb-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-foreground`,children:`Assets`}),(0,$.jsx)(Z,{variant:`default`,children:e})]}),(0,$.jsx)(qe,{children:(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[r?(0,$.jsxs)(B,{children:[(0,$.jsx)(je,{render:(0,$.jsx)(J,{"aria-label":`Create asset`,onClick:d,size:`icon-sm`,children:(0,$.jsx)(w,{className:`size-4`})})}),(0,$.jsx)(Ie,{children:`Create asset`})]}):(0,$.jsxs)(J,{className:`w-fit`,onClick:d,size:`sm`,children:[(0,$.jsx)(w,{className:`size-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Create`})]}),n===`skills`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(B,{children:[(0,$.jsx)(je,{render:(0,$.jsx)(J,{"aria-label":`Install skill`,onClick:f,size:`icon-sm`,variant:`secondary`,children:(0,$.jsx)(y,{className:`size-4`})})}),(0,$.jsx)(Ie,{children:`Install skill`})]}),(0,$.jsx)(Rn,{isCompact:r,isUpdatingSkills:b,items:x,onUpdateSkill:v,onUpdateSkills:_})]}):null,(0,$.jsxs)(B,{children:[(0,$.jsx)(je,{render:(0,$.jsx)(J,{"aria-label":g?`Analyzing assets`:`Analyze assets`,onClick:h,size:`icon-sm`,variant:`secondary`,children:(0,$.jsx)(m,{className:t(`size-4`,g&&`animate-pulse`)})})}),(0,$.jsx)(Ie,{children:g?`Analyzing…`:`Analyze`})]}),(0,$.jsxs)(B,{children:[(0,$.jsx)(je,{render:(0,$.jsx)(J,{"aria-label":`Discover`,onClick:p,size:`icon-sm`,variant:`secondary`,children:(0,$.jsx)(N,{className:`size-4`})})}),(0,$.jsx)(Ie,{children:`Discover`})]})]})})]}),(0,$.jsxs)(`div`,{className:t(`flex min-w-0 flex-col gap-3`,!r&&`lg:flex-row lg:items-center`),children:[(0,$.jsx)(nt,{className:`shrink-0 gap-0`,onValueChange:e=>{(e===`assets`||e===`review`)&&o(e)},value:i,children:(0,$.jsxs)(et,{"aria-label":`Library view`,children:[(0,$.jsx)(tt,{value:`assets`,children:`Assets`}),(0,$.jsxs)(tt,{value:`review`,children:[`Review`,a>0?(0,$.jsx)(Z,{className:`ml-1.5 px-1.5 py-0`,variant:`accent`,children:a}):null]})]})}),i===`assets`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,$.jsx)(C,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(X,{"aria-label":`Search assets`,className:`h-9 pl-9`,onChange:e=>u(e.target.value),placeholder:`Search name, path, or author`,value:c})]}),(0,$.jsx)(nt,{className:t(`shrink-0 gap-0`,r?`w-full`:`w-full lg:w-auto`),onValueChange:e=>{(e===`all`||e===`editable`||e===`upstream`)&&l(e)},value:s,children:(0,$.jsxs)(et,{"aria-label":`Filter by ownership`,className:t(r?`w-full`:`w-full lg:w-auto`),children:[(0,$.jsx)(tt,{value:`all`,children:`All`}),(0,$.jsx)(tt,{value:`editable`,children:`Editable`}),(0,$.jsx)(tt,{value:`upstream`,children:`Upstream`})]})})]}):null]})]})}function Bn({items:e,max:t=6}){if(e.length<=3)return(0,$.jsx)($.Fragment,{children:e.join(`, `)});let n=e.slice(0,t),r=e.length-n.length;return(0,$.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[n.map(e=>(0,$.jsx)(`span`,{children:e},e)),r>0?(0,$.jsxs)(`span`,{children:[`+`,r,` more`]}):null]})}async function Vn(e){try{return{forked:await I.forkSkill({kind:e.kind,name:e.name}),reused:!1}}catch(t){if(!(t instanceof Error?t.message:``).includes(`already exists`))throw t;let n=Pe(`${e.name}-local`);if(!n||n===e.name)throw t;let r=await I.getByKindAndName(e.kind,n).catch(()=>null);if(!r||Re(r.provenance))throw t;return{forked:r,reused:!0}}}function Hn(e){let{selected:t,editorContent:n,setEditorContent:r,setSelected:i}=e,a=d(),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),m=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=m.current;m.current=null;let n=e&&e.kind===t?.kind&&e.name===t.name?e:null;c(n?.kindAssessment??null),u(n?.assetAudit??null)},[t?.kind,t?.name]);function h(e){t&&e.kind===t.kind&&e.name===t.name?(c(e.kindAssessment),u(e.assetAudit)):m.current=e}function g(){c(null),u(null)}function _(){f&&(r(f.after),u(null),p(null),W.success(`Applied — review and save`))}function v(){p(null)}return{kindAssessment:s,assetAudit:l,pendingAiEdit:f,resetAiResults:g,seedAiResults:h,approveAiEdit:_,discardAiEdit:v,reassessKind:o({mutationFn:async()=>{if(!t)throw Error(`No asset selected`);return U.classifyAsset({kind:t.kind,name:t.name,content:n})},onSuccess:e=>{c(e),W.success(e.matchesCurrent?`Kind looks right (${e.recommendedKind})`:`Suggested kind: ${e.recommendedKind}`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to reassess kind`)}}),auditAsset:o({mutationFn:async e=>{if(!t)throw Error(`No asset selected`);return U.auditAsset({kind:t.kind,name:t.name,content:e??n})},onSuccess:e=>{u(e),W.success(e.findings.length===0?`Audit passed · no material findings`:`Audit ready · ${e.findings.length} findings`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to audit asset`)}}),improveAsset:o({mutationFn:async()=>{if(!t)throw Error(`No asset selected`);if(!l||l.findings.length===0)throw Error(`Run an audit before applying improvements`);return U.improveAsset({kind:t.kind,name:t.name,content:n,summary:l.summary,findings:l.findings})},onSuccess:e=>{p({label:`Apply improvements`,before:n,after:e.content}),W.success(`Improvements ready — review the diff`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to improve asset`)}}),fixDescriptionWithAi:o({mutationFn:async()=>{if(!t)throw Error(`No asset selected`);return U.improveAsset({kind:t.kind,name:t.name,content:n,summary:`Asset is missing a frontmatter description required by some editors.`,findings:[{severity:`high`,title:`Missing description`,detail:"Add a concise frontmatter `description` summarizing what this asset does and when to use it."}]})},onSuccess:e=>{p({label:`AI-drafted description`,before:n,after:e.content}),W.success(`Description ready — review the diff`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to generate description`)}}),forkAndFixDescription:o({mutationFn:async e=>{if(!t)throw Error(`No asset selected`);let{forked:n,reused:r}=await Vn(t);return{forked:n,content:e===`heading`?pe(n.content,n.name):await(async()=>(await U.improveAsset({kind:n.kind,name:n.name,content:n.content,summary:`Asset is missing a frontmatter description required by some editors.`,findings:[{severity:`high`,title:`Missing description`,detail:"Add a concise frontmatter `description` summarizing what this asset does and when to use it."}]})).content)(),reused:r}},onSuccess:({forked:e,content:t,reused:n})=>{a.setQueryData([`library`,`detail`,e.kind,e.name],{...e,content:t}),i({kind:e.kind,name:e.name}),a.invalidateQueries({queryKey:[`library`]}),a.invalidateQueries({queryKey:[`overview`]}),W.success(n?`Opened existing ${e.kind}/${e.name} · description drafted, review and save`:`Forked to ${e.kind}/${e.name} — description drafted, review and save`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to fork and fix description`)}})}}async function Un(e,t={}){let{onProgress:n,onEntry:r,isCancelled:i}=t,a=new Map,o=e=>{a.set(`${e.asset.kind}/${e.asset.name}`,{...e}),r?.({...e})};for(let t=0;t<e.length&&!i?.();t++){let r=e[t];n?.({phase:`classify`,current:t+1,total:e.length,label:r.name});let i={asset:r,classification:null,classifyError:null,audit:null,auditError:null};try{i.classification=await U.classifyAsset({kind:r.kind,name:r.name})}catch(e){i.classifyError=F(e,`Kind check failed`)}o(i)}let s=[...a.values()].filter(e=>e.classification!==null&&!e.classification.matchesCurrent);for(let e=0;e<s.length&&!i?.();e++){let t=s[e];n?.({phase:`audit`,current:e+1,total:s.length,label:t.asset.name});try{t.audit=await U.auditAsset({kind:t.asset.kind,name:t.asset.name})}catch(e){t.auditError=F(e,`Audit failed`)}o(t)}return[...a.values()]}function Wn(){let[e,t]=(0,Q.useState)(`idle`),[n,r]=(0,Q.useState)(!1),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)([]),c=(0,Q.useRef)(0);return{status:e,cancelled:n,progress:i,entries:o,run:(0,Q.useCallback)(e=>{let n=++c.current,i=()=>c.current===n;return t(`running`),r(!1),s([]),a(null),Un(e,{isCancelled:()=>!i(),onProgress:e=>{i()&&a(e)},onEntry:e=>{i()&&s(t=>{let n=`${e.asset.kind}/${e.asset.name}`,r=t.findIndex(e=>`${e.asset.kind}/${e.asset.name}`===n);if(r===-1)return[...t,e];let i=[...t];return i[r]=e,i})}}).then(e=>({entries:e,cancelled:!i()})).finally(()=>{i()&&(t(`done`),a(null))})},[]),cancel:(0,Q.useCallback)(()=>{c.current!==0&&(c.current++,t(`done`),r(!0),a(null))},[])}}function Gn({selected:e,setSelected:t,setForkOpen:n,setUpdateResults:r}){let i=d();return{updateSkills:o({mutationFn:async e=>I.updateSkills(e?{name:e}:{}),onSuccess:t=>{let n=t.results.some(e=>e.status===`updated`||e.status===`migrated`||e.status===`failed`);i.invalidateQueries({queryKey:[`library`]}),i.invalidateQueries({queryKey:[`library`,`skill-updates`]}),i.invalidateQueries({queryKey:[`issues`]}),e&&i.invalidateQueries({queryKey:[`library`,`detail`,e.kind,e.name]}),n?r(t.results):W.success(`All skills already up to date`)},onError:e=>{W.error(F(e,`Unable to update skills from upstream`))}}),retryCheck:o({mutationFn:async e=>I.checkSkillUpdates({name:e,force:!0}),onSuccess:(e,t)=>{i.invalidateQueries({queryKey:[`library`]}),i.invalidateQueries({queryKey:[`library`,`skill-updates`]}),i.invalidateQueries({queryKey:[`issues`]});let n=e.results.find(e=>e.name===t);n?.status===`failed`?W.warning(`Check still failing for ${t}: ${n.error??`unknown error`}`):W.success(n?.status===`update_available`?`Update available for ${t}`:`${t} is up to date`)},onError:e=>{W.error(F(e,`Unable to check skill`))}}),unlinkSkill:o({mutationFn:async e=>I.unlinkSkill(e),onSuccess:(t,n)=>{i.invalidateQueries({queryKey:[`library`]}),i.invalidateQueries({queryKey:[`library`,`skill-updates`]}),i.invalidateQueries({queryKey:[`issues`]}),e&&i.invalidateQueries({queryKey:[`library`,`detail`,e.kind,e.name]}),W.success(`${n} is now a local, editable skill`)},onError:e=>{W.error(F(e,`Unable to unlink skill`))}}),forkSkill:o({mutationFn:async e=>I.forkSkill(e),onSuccess:e=>{n(!1),t({kind:e.kind,name:e.name}),i.invalidateQueries({queryKey:[`library`]}),i.invalidateQueries({queryKey:[`library`,`detail`,e.kind,e.name]}),i.invalidateQueries({queryKey:[`overview`]}),W.success(`Forked to ${e.kind}/${e.name} — safe to edit`)},onError:e=>{W.error(e.message||`Unable to fork asset`)}}),rescanAsset:o({mutationFn:async e=>we.rescan({kind:e.kind,name:e.name}),onSuccess:(e,t)=>{i.invalidateQueries({queryKey:[`library`]}),i.invalidateQueries({queryKey:[`library`,`detail`,t.kind,t.name]});let n=e.results[0]?.scan;n?.verdict===`fail`?W.error(`Security scan flagged this asset — review the findings`):n?.verdict===`warn`?W.warning(`Security scan completed with warnings`):W.success(`Security scan passed`)},onError:e=>{W.error(F(e,`Unable to rescan asset`))}})}}function Kn({selected:e,editorContent:t,loadedContent:n,discoverOpen:r,setSelected:i,setEditorContent:a,setRemoveOpen:s,setForkOpen:l,setUpdateResults:u,setImportProgress:f,resetAiResults:p}){let m=d(),{updateSkills:h,retryCheck:g,unlinkSkill:_,forkSkill:v,rescanAsset:y}=Gn({selected:e,setSelected:i,setForkOpen:l,setUpdateResults:u});return{saveAsset:o({mutationFn:async()=>{if(!e)throw Error(`No asset selected`);return I.update(e.kind,e.name,{content:t})},onSuccess:e=>{m.invalidateQueries({queryKey:[`library`]}),m.invalidateQueries({queryKey:[`library`,`detail`,e.kind,e.name]}),W.success(`Saved ${e.kind}/${e.name}`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to save asset`)}}),renameAsset:o({mutationFn:async t=>{if(!e)throw Error(`No asset selected`);return I.rename(e.kind,e.name,{name:t})},onSuccess:e=>{i({kind:e.kind,name:e.name}),m.invalidateQueries({queryKey:[`library`]}),m.invalidateQueries({queryKey:[`library`,`detail`]}),m.invalidateQueries({queryKey:[`overview`]}),W.success(`Renamed to ${e.kind}/${e.name}`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to rename asset`)}}),discoverQuery:c({queryKey:[`library`,`discover`],queryFn:()=>I.discover(),enabled:r}),importAsset:o({mutationFn:async e=>I.import({editorId:e.editorId,kind:e.kind,name:e.name}),onSuccess:e=>{m.invalidateQueries({queryKey:[`library`]}),m.invalidateQueries({queryKey:[`library`,`discover`]}),m.invalidateQueries({queryKey:[`setup`]}),m.invalidateQueries({queryKey:[`overview`]}),W.success(`Imported ${e.kind}/${e.name}`)},onError:()=>{W.error(`Unable to import asset — it may already exist in the hub`)}}),importMultipleAssets:o({mutationFn:async e=>{let t=[],n=new Set;for(let r of e){let e=`${r.kind}/${r.name}`;n.has(e)||(n.add(e),t.push(r))}let r=0,i=0;f({current:0,total:t.length});for(let e=0;e<t.length;e++){let n=t[e];f({current:e+1,total:t.length});try{await I.import({editorId:n.editorId,kind:n.kind,name:n.name}),r++}catch{i++}}return{importedCount:r,skippedCount:i,total:t.length}},onSuccess:({importedCount:e,skippedCount:t})=>{f(null),m.invalidateQueries({queryKey:[`library`]}),m.invalidateQueries({queryKey:[`library`,`discover`]}),m.invalidateQueries({queryKey:[`setup`]}),m.invalidateQueries({queryKey:[`overview`]}),e>0?W.success(t>0?`Imported ${e} asset${e===1?``:`s`} (${t} skipped)`:`Imported ${e} asset${e===1?``:`s`}`):W.error(`No assets could be imported — they may already exist in the hub`)},onError:()=>{f(null),W.error(`Failed to import assets`)}}),removeAsset:o({mutationFn:async()=>{if(!e)throw Error(`No asset selected`);await I.delete(e.kind,e.name)},onSuccess:()=>{i(null),a(``),s(!1),m.invalidateQueries({queryKey:[`library`]}),m.invalidateQueries({queryKey:[`setup`]}),m.invalidateQueries({queryKey:[`overview`]}),W.success(`Asset deleted`)},onError:()=>{W.error(`Unable to delete asset`)}}),updateSkills:h,retryCheck:g,unlinkSkill:_,forkSkill:v,rescanAsset:y,convertKind:o({mutationFn:async r=>{if(!e)throw Error(`No asset selected`);return t!==n&&await I.update(e.kind,e.name,{content:t}),I.convert(e.kind,e.name,{toKind:r})},onSuccess:e=>{p(),i({kind:e.kind,name:e.name}),m.invalidateQueries({queryKey:[`library`]}),m.invalidateQueries({queryKey:[`library`,`detail`]}),m.invalidateQueries({queryKey:[`overview`]}),W.success(`Converted to ${e.kind}/${e.name}`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to convert asset`)}})}}function qn(e){let t=d(),[n,r]=(0,Q.useState)(e.searchParams.get(`create`)===`1`),[i,a]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(`auto`),[f,p]=(0,Q.useState)(`skills`),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(`# New Asset
3
+ `),[v,y]=(0,Q.useState)(``),b=e=>{u(e),h(null),e!==`auto`&&p(e)},x=(0,Q.useCallback)(e=>{e.name?.trim()&&(a(e.name.trim()),c(!0)),e.kind&&(u(e.kind),p(e.kind),h(null)),e.intent&&y(e.intent)},[]),S=()=>{a(``),c(!1),_(`# New Asset
4
+ `),y(``),u(`auto`),p(`skills`),h(null)},C=t=>{let n=new URLSearchParams(e.searchParams);t?n.set(`create`,`1`):n.delete(`create`),e.setSearchParams(n,{replace:!0})},w=e=>{r(e),C(e)};return{createOpen:n,setCreateOpenFromParams:r,setCreateOpenSynced:w,draftName:i,setDraftName:a,draftNameLocked:s,setDraftNameLocked:c,draftKindChoice:l,handleDraftKindChoiceChange:b,draftKind:f,kindReason:m,draftContent:g,setDraftContent:_,draftIntent:v,setDraftIntent:y,seedCreateDraft:x,createAsset:o({mutationFn:async()=>{let e=f===`skills`?pe(g,i.trim()||`new-skill`):g,t=Ue(f,e).find(e=>e.severity===`error`);if(t)throw Error(t.message);try{return await I.create({kind:f,name:i,content:e})}catch(e){throw e instanceof TypeError?Error("Hub server is unreachable. Run `bun run dev` or `chain hub` and try again."):e}},onSuccess:n=>{S(),e.onCreated({kind:n.kind,name:n.name}),w(!1),t.invalidateQueries({queryKey:[`library`]}),t.invalidateQueries({queryKey:[`overview`]}),t.invalidateQueries({queryKey:[`setup`]}),W.success(`Created ${n.kind}/${n.name}`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to create asset`)}}),draftPromptWithAi:o({mutationFn:async()=>U.draftPrompt({intent:v.trim(),kind:l,name:s&&i.trim()?i.trim():void 0}),onSuccess:e=>{_(e.content),p(e.recommendedKind),h(l===`auto`?e.reason??`Best fit as ${e.recommendedKind}`:null),!s&&e.suggestedName&&a(e.suggestedName),W.success(l===`auto`?`Draft ready as ${e.recommendedKind} — review and create`:`Draft ready — review and create`)},onError:e=>{W.error(e instanceof Error?e.message:`Unable to draft asset`)}})}}function Jn({isDirty:e,selected:t,onSameAsset:n,onSelect:r}){let[a,o]=(0,Q.useState)(void 0),s=i(({currentLocation:t,nextLocation:n})=>e&&t.pathname!==n.pathname);function c(i){i!==null&&t!==null&&i.kind===t.kind&&i.name===t.name?n():e?o(i):r(i)}return{pendingSelection:a,setPendingSelection:o,requestSelection:c,navigationBlocker:s}}function Yn(){let[e,t]=s(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(`assets`),[o,c]=(0,Q.useState)(`SKILL.md`),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(()=>ge(e.get(`kind`))),[x,S]=(0,Q.useState)(()=>ye(e.get(`ownership`))),[C,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(null),[ee,j]=(0,Q.useState)(null),[te,M]=(0,Q.useState)(!1),[N,ne]=(0,Q.useState)(`assets`),[re,ie]=(0,Q.useState)(!0),[ae,oe]=(0,Q.useState)(!0);return{searchParams:e,setSearchParams:t,selected:n,setSelected:r,masterView:i,setMasterView:a,activeFile:o,setActiveFile:c,removeOpen:l,setRemoveOpen:u,discoverOpen:d,setDiscoverOpen:f,forkOpen:p,setForkOpen:m,importProgress:h,setImportProgress:g,searchQuery:_,setSearchQuery:v,filterKind:y,setFilterKind:b,ownership:x,setOwnership:S,editorContent:C,setEditorContent:w,previewFilePath:T,setPreviewFilePath:E,autoAuditAsset:D,setAutoAuditAsset:O,updateResults:k,setUpdateResults:A,relinkTarget:ee,setRelinkTarget:j,analyzeOpen:te,setAnalyzeOpen:M,view:N,setView:ne,listAtTop:re,setListAtTop:ie,listAtBottom:ae,setListAtBottom:oe}}function Xn(){let e=d(),{searchParams:t,setSearchParams:n,selected:r,setSelected:i,masterView:a,setMasterView:o,activeFile:s,setActiveFile:l,removeOpen:u,setRemoveOpen:f,discoverOpen:p,setDiscoverOpen:m,forkOpen:h,setForkOpen:g,importProgress:_,setImportProgress:v,searchQuery:y,setSearchQuery:b,filterKind:x,setFilterKind:S,ownership:C,setOwnership:w,editorContent:T,setEditorContent:E,previewFilePath:D,setPreviewFilePath:O,autoAuditAsset:k,setAutoAuditAsset:A,updateResults:ee,setUpdateResults:j,relinkTarget:te,setRelinkTarget:M,analyzeOpen:N,setAnalyzeOpen:ne,view:re,setView:ie,listAtTop:ae,setListAtTop:oe,listAtBottom:se,setListAtBottom:ce}=Yn(),P=Wn(),le=qn({searchParams:t,setSearchParams:n,onCreated:i}),ue=Tn({onInstalled:i}),{setCreateOpenFromParams:de,seedCreateDraft:fe}=le;(0,Q.useEffect)(()=>{de(t.get(`create`)===`1`),S(ge(t.get(`kind`))),w(ye(t.get(`ownership`)));let e=t.get(`name`),r=t.get(`intent`);if(t.get(`create`)===`1`&&(e||r)){let i=ge(t.get(`kind`));fe({name:e??void 0,intent:r??void 0,kind:i===`__all__`?void 0:i});let a=new URLSearchParams(t);a.delete(`name`),a.delete(`intent`),n(a,{replace:!0});return}let a=Ve(t.get(`kind`),t.get(`asset`));if(a){i(a),t.get(`audit`)===`1`&&A(a.name);let e=new URLSearchParams(t);e.delete(`asset`),e.delete(`audit`),n(e,{replace:!0})}},[t,de,n,i,A,S,w,fe]);let pe=e=>{w(e);let r=new URLSearchParams(t);e===`all`?r.delete(`ownership`):r.set(`ownership`,e),n(r,{replace:!0})},F=c({queryKey:[`library`],queryFn:()=>I.getAll()}),he=c({queryKey:[`overview`],queryFn:()=>Je.get()}),_e=c({queryKey:[`library`,`skill-updates`],queryFn:()=>I.checkSkillUpdates(),enabled:x===`skills`,staleTime:3e5}),L=c({queryKey:[`library`,`detail`,r?.kind,r?.name],queryFn:()=>I.getByKindAndName(r?.kind||``,r?.name||``),enabled:r!==null}),ve=c({queryKey:[`library`,`skill-files`,r?.name],queryFn:()=>I.getSkillFiles(r?.name||``),enabled:r?.kind===`skills`}),{kindAssessment:be,assetAudit:xe,pendingAiEdit:R,resetAiResults:Se,seedAiResults:Ce,approveAiEdit:we,discardAiEdit:Ee,reassessKind:ke,auditAsset:z,improveAsset:B,fixDescriptionWithAi:V,forkAndFixDescription:je}=Hn({selected:r,editorContent:T,setEditorContent:E,setSelected:i}),H=(0,Q.useRef)(z.mutate);H.current=z.mutate,(0,Q.useEffect)(()=>{k&&r?.name!==k&&A(null)},[r?.name,k,A]),(0,Q.useEffect)(()=>{L.data&&(E(L.data.content),k&&k===L.data.name&&(A(null),H.current(L.data.content)))},[L.data,k,A,E]),(0,Q.useEffect)(()=>{O(null)},[r?.kind,r?.name,O]);let U=L.data!==void 0&&T!==L.data.content,{pendingSelection:Ne,setPendingSelection:Pe,requestSelection:G,navigationBlocker:Fe}=Jn({isDirty:U,selected:r,onSameAsset:()=>o(`files`),onSelect:e=>{i(e),o(`assets`),l(`SKILL.md`)}});(0,Q.useEffect)(()=>{if(!U)return;let e=e=>e.preventDefault();return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[U]);let{saveAsset:K,renameAsset:Ie,discoverQuery:Le,importAsset:ze,importMultipleAssets:Be,removeAsset:q,updateSkills:J,retryCheck:He,unlinkSkill:Ue,forkSkill:Y,rescanAsset:X,convertKind:We}=Kn({selected:r,editorContent:T,loadedContent:L.data?.content,discoverOpen:p,setSelected:i,setEditorContent:E,setRemoveOpen:f,setForkOpen:g,setUpdateResults:j,setImportProgress:v,resetAiResults:Se}),Ge=c({queryKey:[`analysis`],queryFn:()=>Oe.get()}),Ke=(0,Q.useMemo)(()=>{let e=new Map;for(let t of F.data??[])e.set(dt(t.kind,t.name),t);return e},[F.data]),qe=ft({assetsByKey:Ke});async function Ye(){let t=F.data??[],{entries:n,cancelled:r}=await P.run(t);if(!r)try{let r=await Oe.save({totalAssets:t.length,entries:n.map(e=>({kind:e.asset.kind,name:e.asset.name,classification:e.classification,classifyError:e.classifyError,audit:e.audit,auditError:e.auditError,compatIssues:e.asset.compatIssues??[]}))});e.setQueryData([`analysis`],r)}catch(e){W.error(e instanceof Error?e.message:`Could not save analysis report`)}}function Xe(){ne(!0),P.status===`idle`&&Ye()}function Ze(){Ye()}function Qe(e){Ce({kind:e.kind,name:e.name,kindAssessment:e.type===`kind-mismatch`&&e.recommendedKind?{currentKind:e.kind,recommendedKind:e.recommendedKind,matchesCurrent:!1,reason:e.reason??``}:null,assetAudit:e.type===`audit-findings`&&e.findings?{summary:e.summary??``,findings:e.findings}:null}),(r?.kind!==e.kind||r?.name!==e.name)&&G({kind:e.kind,name:e.name})}function Z(e){Ce({kind:e.asset.kind,name:e.asset.name,kindAssessment:e.classification,assetAudit:e.audit}),ne(!1),(r?.kind!==e.asset.kind||r?.name!==e.asset.name)&&G({kind:e.asset.kind,name:e.asset.name})}let $e=(0,Q.useRef)(P.status);(0,Q.useEffect)(()=>{let e=$e.current;if($e.current=P.status,e!==`running`||P.status!==`done`||N||P.cancelled)return;let t=P.entries.filter(e=>e.classification!==null&&!e.classification.matchesCurrent).length;W.success(t>0?`Analysis complete — ${t} asset${t===1?``:`s`} need attention`:`Analysis complete — all assets look right`)},[P.status,P.cancelled,P.entries,N]);let et=!!r&&Re(L.data?.provenance??null),tt=Ae(L.data?.provenance??null),nt=(0,Q.useMemo)(()=>{let e=new Map;for(let t of _e.data?.results??[])(t.status===`update_available`||t.status===`up_to_date`)&&e.set(t.name,t.status===`update_available`);for(let t of F.data??[])t.kind===`skills`&&!e.has(t.name)&&e.set(t.name,Me(t.provenance));return e},[_e.data,F.data]),rt=(0,Q.useMemo)(()=>{let e=new Map;for(let t of _e.data?.results??[])t.status===`update_available`&&e.set(t.name,{name:t.name,currentSha:t.currentSha??null,latestSha:t.latestSha??null});for(let t of F.data??[])t.kind===`skills`&&!e.has(t.name)&&Me(t.provenance)&&e.set(t.name,{name:t.name,currentSha:t.provenance?.commitSha??null,latestSha:t.provenance?.latestSha??null});return Array.from(e.values()).sort((e,t)=>e.name.localeCompare(t.name))},[_e.data,F.data]),it=(0,Q.useMemo)(()=>new Set((F.data??[]).filter(e=>e.kind===r?.kind).map(e=>e.name)),[F.data,r?.kind]),at=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=_e.data;if(!e)return;let t=e.results.map(e=>`${e.name}:${e.status}:${e.latestSha??``}`).join(`|`);if(at.current===t)return;at.current=t;let n=e.results.filter(e=>e.status===`update_available`),r=e.results.filter(e=>e.status===`failed`);n.length>0&&W.info(n.length===1?`1 skill update available`:`${n.length} skill updates available`,{description:(0,$.jsx)(Bn,{items:n.map(e=>e.name)}),duration:6e3}),r.length>0&&W.warning(r.length===1?`Could not check 1 skill`:`Could not check ${r.length} skills`,{description:(0,$.jsx)(Bn,{items:r.map(e=>`${e.name}${e.error?`: ${e.error}`:``}`),max:4}),duration:8e3})},[_e.data]);let ot=(0,Q.useMemo)(()=>me(F.data??[],x,y,C),[x,F.data,C,y]),st=(0,Q.useMemo)(()=>Te(ot),[ot]),ct=(0,Q.useMemo)(()=>De(Le.data??[]),[Le.data]),lt=Object.entries(st),ut=he.data?.agentsSkillsDrift,pt=(ut?.missingCount??0)>0,mt=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=mt.current;if(!e)return;let t=()=>{oe(e.scrollTop<4),ce(e.scrollHeight-e.scrollTop-e.clientHeight<4)};t(),e.addEventListener(`scroll`,t,{passive:!0});let n=new ResizeObserver(t);return n.observe(e),()=>{e.removeEventListener(`scroll`,t),n.disconnect()}},[lt,ce,oe]);let ht=e=>Be.isPending||ze.isPending&&ze.variables?.editorId===e.editorId&&ze.variables?.kind===e.kind&&ze.variables?.name===e.name;function gt(){Fe.state===`blocked`?Fe.proceed():(i(Ne??null),o(`assets`),l(`SKILL.md`),Pe(void 0))}function _t(){Fe.state===`blocked`&&Fe.reset(),Pe(void 0)}function vt(e){g(!1),r&&G({kind:r.kind,name:e})}function yt(e){r&&Y.mutate({kind:r.kind,name:r.name,as:e})}function bt(e){e||O(null)}function xt(e){e||M(null)}function St(e){e||j(null)}return{library:F,analysisReport:Ge,selectedAsset:L,skillFiles:ve,discoverQuery:Le,selected:r,masterView:a,setMasterView:o,activeFile:s,setActiveFile:l,requestSelection:G,pendingSelection:Ne,navigationBlocker:Fe,isDirty:U,filterKind:x,searchQuery:y,setSearchQuery:b,ownership:C,setOwnershipSynced:pe,filteredAssets:ot,kindSections:lt,skillUpdates:nt,skillUpdateItems:rt,listScrollRef:mt,listAtTop:ae,listAtBottom:se,view:re,setView:ie,editorContent:T,setEditorContent:E,autoAuditAsset:k,kindAssessment:be,assetAudit:xe,pendingAiEdit:R,approveAiEdit:we,discardAiEdit:Ee,reassessKind:ke,auditAsset:z,improveAsset:B,fixDescriptionWithAi:V,forkAndFixDescription:je,isUpstreamSkill:et,upstreamBrowseUrl:tt,saveAsset:K,renameAsset:Ie,removeAsset:q,updateSkills:J,retryCheck:He,unlinkSkill:Ue,forkSkill:Y,rescanAsset:X,convertKind:We,importAsset:ze,importMultipleAssets:Be,createFlow:le,installFlow:ue,analysis:P,review:qe,assetsByKey:Ke,removeOpen:u,setRemoveOpen:f,discoverOpen:p,setDiscoverOpen:m,forkOpen:h,setForkOpen:g,forkTakenNames:it,importProgress:_,updateResults:ee,relinkTarget:te,analyzeOpen:N,setAnalyzeOpen:ne,previewFilePath:D,setPreviewFilePath:O,setRelinkTarget:M,groupedDiscovered:ct,isCandidateImporting:ht,hasAgentsDrift:pt,agentsDrift:ut,handleAnalyze:Xe,handleRunAnalysisAgain:Ze,handleOpenAnalysisItem:Qe,handleOpenAnalyzedAsset:Z,handleDiscardChanges:gt,handleKeepEditing:_t,handleForkOpenExisting:vt,handleForkSubmit:yt,handlePreviewOpenChange:bt,handleRelinkOpenChange:xt,handleUpdateResultsOpenChange:St}}function Zn(){let{library:e,analysisReport:n,selectedAsset:r,skillFiles:i,discoverQuery:a,selected:o,masterView:s,setMasterView:c,activeFile:l,setActiveFile:u,requestSelection:d,pendingSelection:f,navigationBlocker:p,filterKind:m,searchQuery:h,setSearchQuery:g,ownership:_,setOwnershipSynced:v,filteredAssets:b,kindSections:x,skillUpdates:S,skillUpdateItems:C,listScrollRef:w,listAtTop:E,listAtBottom:D,view:O,setView:k,editorContent:A,setEditorContent:j,autoAuditAsset:te,kindAssessment:M,assetAudit:N,pendingAiEdit:ne,approveAiEdit:re,discardAiEdit:ie,reassessKind:ae,auditAsset:oe,improveAsset:se,fixDescriptionWithAi:ce,forkAndFixDescription:P,isUpstreamSkill:le,upstreamBrowseUrl:ue,saveAsset:de,renameAsset:fe,removeAsset:pe,updateSkills:F,retryCheck:me,unlinkSkill:I,forkSkill:he,rescanAsset:ge,convertKind:_e,importAsset:L,importMultipleAssets:ve,createFlow:ye,installFlow:be,analysis:xe,review:R,assetsByKey:Se,removeOpen:Ce,setRemoveOpen:we,discoverOpen:Te,setDiscoverOpen:Ee,forkOpen:De,setForkOpen:Oe,forkTakenNames:ke,importProgress:Ae,updateResults:z,relinkTarget:B,analyzeOpen:V,setAnalyzeOpen:je,previewFilePath:Me,setPreviewFilePath:H,setRelinkTarget:U,groupedDiscovered:W,isCandidateImporting:Ne,hasAgentsDrift:Pe,agentsDrift:G,handleAnalyze:Fe,handleRunAnalysisAgain:K,handleOpenAnalysisItem:Ie,handleOpenAnalyzedAsset:Le,handleDiscardChanges:Re,handleKeepEditing:Be,handleForkOpenExisting:q,handleForkSubmit:Ve,handlePreviewOpenChange:He,handleRelinkOpenChange:Ue,handleUpdateResultsOpenChange:Y}=Xn(),X=(0,$.jsx)(zn,{assetCount:b.length,filterKind:m,isAnalyzing:xe.status===`running`,isCompact:o!==null,isUpdatingSkills:F.isPending,onAnalyze:Fe,onCreate:()=>ye.setCreateOpenSynced(!0),onDiscover:()=>Ee(!0),onInstall:()=>be.setInstallOpen(!0),onOwnershipChange:v,onSearchQueryChange:g,onUpdateSkills:()=>F.mutate(void 0),onUpdateSkill:e=>F.mutate(e),onViewChange:k,ownership:_,reviewOpenCount:n.data?.items.filter(e=>e.status===`open`).length??0,searchQuery:h,skillUpdateItems:C,view:O});return e.isLoading?(0,$.jsxs)(`div`,{className:`flex h-[calc(100vh-2rem)] min-w-0 flex-col -mb-4 sm:-mb-6 sm:h-[calc(100vh-3rem)]`,children:[X,(0,$.jsx)(ze,{className:`min-h-0 flex-1`,variant:`workspace`})]}):e.isError?(0,$.jsxs)(`div`,{className:`flex h-[calc(100vh-2rem)] min-w-0 flex-col -mb-4 sm:-mb-6 sm:h-[calc(100vh-3rem)]`,children:[X,(0,$.jsx)(We,{description:`The library index is temporarily unavailable.`,title:`Unable to load library`})]}):(0,$.jsx)(`div`,{className:`flex h-[calc(100vh-2rem)] min-w-0 flex-col -mb-4 sm:-mb-6 sm:h-[calc(100vh-3rem)]`,children:(0,$.jsxs)(`section`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[Pe&&G?(0,$.jsx)(`div`,{className:`min-w-0 shrink-0 pb-3`,children:(0,$.jsxs)(Qe,{className:`items-center`,variant:`warning`,children:[(0,$.jsx)(Ze,{children:(0,$.jsx)(y,{})}),(0,$.jsxs)(Xe,{children:[G.missingCount,` skill`,G.missingCount===1?``:`s`,` in`,` `,(0,$.jsx)(`code`,{className:`font-mono text-xs text-foreground`,children:`~/.agents`}),` `,G.missingCount===1?`is`:`are`,` not in Hub yet`,G.missingNames.length>0?` (${G.missingNames.slice(0,3).join(`, `)}${G.missingNames.length>3?`, …`:``})`:``,`.`]}),(0,$.jsx)(J,{className:`shrink-0`,loading:be.migrateAgentsSkills.isPending,onClick:()=>be.migrateAgentsSkills.mutate(),size:`sm`,children:be.migrateAgentsSkills.isPending?`Importing…`:`Import into Hub`})]})}):null,(0,$.jsxs)(`div`,{className:t(`grid min-h-0 min-w-0 flex-1 gap-4`,o?`xl:grid-cols-[minmax(0,22rem)_minmax(0,1fr)]`:`grid-cols-1`),children:[(0,$.jsx)(`div`,{className:t(`flex min-h-0 min-w-0 flex-col`,o&&`hidden xl:flex`),children:o&&s===`files`?(0,$.jsx)(Yt,{activeFile:l,assetKind:o.kind,assetName:o.name,files:i.data?.files??[],onBackToAssets:()=>c(`assets`),onSelectFile:e=>u(e),provenanceSource:r.data?.provenance?.source}):(0,$.jsxs)($.Fragment,{children:[o?(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between rounded-lg border border-border/80 bg-muted/40 px-2.5 py-1.5 text-xs`,children:[(0,$.jsxs)(`span`,{className:`truncate text-muted-foreground`,children:[`Selected: `,(0,$.jsx)(`strong`,{className:`text-foreground`,children:o.name})]}),(0,$.jsxs)(J,{className:`group h-6 shrink-0 gap-1 px-2 text-xs font-medium`,onClick:()=>c(`files`),size:`sm`,type:`button`,variant:`ghost`,children:[(0,$.jsx)(T,{className:`size-3`}),`Files (`,i.data?.files?.filter(e=>!e.isDirectory).length??0,`)`,(0,$.jsx)(ee,{className:`size-3 transition-transform group-hover:translate-x-0.5`})]})]}):null,X,(0,$.jsx)(`div`,{className:t(`min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto`,!o&&`-mr-4 pr-4 sm:-mr-6 sm:pr-6`,!E&&`fade-top`,!D&&`fade-bottom`),ref:w,children:O===`review`?(0,$.jsx)(pt,{assetsByKey:Se,batch:R.batch,fixingId:R.fixingId,isAnalyzing:xe.status===`running`,onApplySelected:()=>R.applyItems((n.data?.items??[]).filter(e=>e.status===`open`&&R.selectedIds.has(e.id))),onFixItem:R.fixItem,onOpenItem:Ie,onRunAgain:Fe,onSelectAllOpen:()=>R.selectAllOpen(n.data?.items??[]),onSetStatus:(e,t)=>void R.setItemStatus(e.id,t),onToggleSelect:R.toggleSelect,report:n.data??null,selectedIds:R.selectedIds}):(0,$.jsx)(Zt,{filterKind:m,kindSections:x,onSelect:e=>d({kind:e.kind,name:e.name}),selected:o,skillUpdates:S})})]})}),o?(0,$.jsx)(Gt,{activeFile:l,assetAudit:N,author:r.data?.author,editorContent:A,isAuditing:oe.isPending||te===o.name,isConverting:_e.isPending,isDeleting:pe.isPending,isFixingDescriptionWithAi:ce.isPending,isForkingAndFixingHeading:P.isPending&&P.variables===`heading`,isForkingAndFixingWithAi:P.isPending&&P.variables===`ai`,isForking:he.isPending,isImproving:se.isPending,isReassessing:ae.isPending,isRenaming:fe.isPending,isRetryingCheck:me.isPending,isSaving:de.isPending,isUnlinking:I.isPending,isUpdating:F.isPending,isUpstreamSkill:le,kindAssessment:M,onAuditAsset:()=>oe.mutate(),onBack:()=>d(null),onConvertKind:e=>_e.mutate(e),onEditorChange:j,onFixDescriptionWithAi:()=>ce.mutate(),onFork:()=>Oe(!0),onForkAndFixHeading:()=>P.mutate(`heading`),onForkAndFixWithAi:()=>P.mutate(`ai`),onImproveAsset:()=>se.mutate(),onOpenFileManager:()=>c(`files`),onPreviewFile:H,onReassessKind:()=>ae.mutate(),onRelink:()=>U(o.name),onRename:e=>fe.mutate(e),onRequestDelete:()=>we(!0),onRetryCheck:()=>me.mutate(o.name),onSave:()=>de.mutate(),onSelectFile:e=>u(e),onUnlink:()=>I.mutate(o.name),isRescanning:ge.isPending,onRescan:()=>ge.mutate(o),onUpdateFromSource:()=>F.mutate(o.name),provenance:r.data?.provenance,securityScan:r.data?.securityScan??null,selected:o,skillFiles:i.data?.files??[],updateAvailable:S.get(o.name)??!1,upstreamBrowseUrl:ue}):null]}),(0,$.jsx)(In,{analysis:xe,analyzeOpen:V,createFlow:ye,discoverLoading:a.isLoading,discoverOpen:Te,discardOpen:f!==void 0||p.state===`blocked`,forkOpen:De,forkTakenNames:ke,groupedDiscovered:W,importProgress:Ae,installFlow:be,isCandidateImporting:Ne,isDeleting:pe.isPending,isForking:he.isPending,isImportingAll:ve.isPending,onAnalyzeOpenChange:je,onApproveAiEdit:re,onDiscardAiEdit:ie,onDiscardChanges:Re,onDiscoverOpenChange:Ee,onForkOpenChange:Oe,onForkOpenExisting:q,onForkSubmit:Ve,onImportAll:e=>ve.mutate(e),onImportCandidate:e=>L.mutate(e),onKeepEditing:Be,onOpenAnalyzedAsset:Le,onPreviewOpenChange:He,onRelinkOpenChange:Ue,onRemoveConfirm:()=>pe.mutate(),onRemoveOpenChange:we,onRunAnalysisAgain:K,onUpdateResultsOpenChange:Y,pendingAiEdit:ne,previewFilePath:Me,relinkTarget:B,removeOpen:Ce,review:R,selected:o,totalAssets:e.data?.length??0,updateResults:z})]})})}export{Zn as LibraryPage};