makecoder 4.0.70 → 4.0.72

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.
package/dist/cc.mjs CHANGED
@@ -20,13 +20,13 @@ import{createRequire as vP5}from"node:module";var MP5=Object.create;var{getProto
20
20
  Object.assign(A, {
21
21
  post(...args) {
22
22
  const [url, payload, ...remainArgs] = args;
23
- const patchedUrl = url + (url.includes('?') ? '&' : '?') + 'app=codev-cli' + '&version=4.0.70' + '&session_id=' + I8() + (process.env.SPACE_ID ? '&space_id=' + process.env.SPACE_ID : '');
23
+ const patchedUrl = url + (url.includes('?') ? '&' : '?') + 'app=codev-cli' + '&version=4.0.72' + '&session_id=' + I8() + (process.env.SPACE_ID ? '&space_id=' + process.env.SPACE_ID : '');
24
24
  if (process.env.CODER_APIKEY) {
25
25
  const headerValues = payload.headers.values;
26
26
  headerValues.set('AUTHORIZATION', `Bearer ${process.env.CODER_APIKEY}`)
27
27
  }
28
28
 
29
- payload.headers.values.set('X-Coder-Version', '4.0.70');
29
+ payload.headers.values.set('X-Coder-Version', '4.0.72');
30
30
  payload.headers.values.set('X-Coder-Platform', process.platform);
31
31
  payload.headers.values.set('X-Coder-Arch', process.arch);
32
32
 
@@ -6419,7 +6419,7 @@ Need help? Common issues:
6419
6419
  For manual setup instructions, see: ${Vn}`:`GitHub App installation failed
6420
6420
  For manual setup instructions, see: ${Vn}`)}switch(_.step){case"check-gh":return K$.default.createElement(cBK,null);case"warnings":return K$.default.createElement(jpK,{warnings:_.warnings,onContinue:H});case"choose-repo":return K$.default.createElement(nBK,{currentRepo:_.currentRepo,useCurrentRepo:_.useCurrentRepo,repoUrl:_.selectedRepoName,onRepoUrlChange:J,onToggleUseCurrentRepo:G,onSubmit:H});case"install-app":return K$.default.createElement(qpK,{repoUrl:_.selectedRepoName,onSubmit:H});case"check-existing-workflow":return K$.default.createElement(tBK,{repoName:_.selectedRepoName,onSelectAction:V});case"check-existing-secret":return K$.default.createElement(UBK,{useExistingSecret:_.useExistingSecret,secretName:_.secretName,onToggleUseExistingSecret:v,onSecretNameChange:Z,onSubmit:H});case"api-key":return K$.default.createElement(FBK,{existingApiKey:K,useExistingKey:_.useExistingKey,apiKeyOrOAuthToken:_.apiKeyOrOAuthToken,onApiKeyChange:X,onToggleUseExistingKey:f,onSubmit:H,onCreateOAuthToken:jX()?P:void 0,selectedOption:_.selectedApiKeyOption,onSelectOption:M});case"creating":return K$.default.createElement(rBK,{currentWorkflowInstallStep:_.currentWorkflowInstallStep,secretExists:_.secretExists,useExistingSecret:_.useExistingSecret,secretName:_.secretName,skipWorkflow:_.workflowAction==="skip",selectedWorkflows:_.selectedWorkflows});case"success":return K$.default.createElement(u,{tabIndex:0,autoFocus:!0,onKeyDown:k},K$.default.createElement(ApK,{secretExists:_.secretExists,useExistingSecret:_.useExistingSecret,secretName:_.secretName,skipWorkflow:_.workflowAction==="skip"}));case"error":return K$.default.createElement(u,{tabIndex:0,autoFocus:!0,onKeyDown:k},K$.default.createElement(aBK,{error:_.error,errorReason:_.errorReason,errorInstructions:_.errorInstructions}));case"select-workflows":return K$.default.createElement(IBK,{defaultSelections:_.selectedWorkflows,onSubmit:(N)=>{if(d("tengu_install_github_app_step_completed",{step:"select-workflows"}),z((R)=>({...R,selectedWorkflows:N})),K)j();else z((R)=>({...R,step:"api-key"}))}});case"oauth-flow":return K$.default.createElement(zpK,{onSuccess:W,onCancel:D})}}async function OIY(q){return K$.default.createElement(AIY,{onDone:q})}var K$,YIY;var XpK=L(()=>{C8();xBK();C$();g6();T7();Nj();Q4();pK();NV();gBK();QBK();lBK();iBK();oBK();sBK();eBK();KpK();YpK();OpK();$pK();HpK();K$=K6(P6(),1),YIY={step:"check-gh",selectedRepoName:"",currentRepo:"",useCurrentRepo:!1,apiKeyOrOAuthToken:"",useExistingKey:!0,currentWorkflowInstallStep:0,warnings:[],secretExists:!1,secretName:"ANTHROPIC_API_KEY",useExistingSecret:!0,workflowExists:!1,selectedWorkflows:["claude","claude-review"],selectedApiKeyOption:"new",authType:"api_key"}});var wIY,MpK;var PpK=L(()=>{Q8();wIY={type:"local-jsx",name:"install-github-app",description:"Set up Claude GitHub Actions for a repository",availability:["claude-ai","console"],isEnabled:()=>!S6(process.env.DISABLE_INSTALL_GITHUB_APP_COMMAND),load:()=>Promise.resolve().then(() => (XpK(),JpK))},MpK=wIY});var DpK={};h8(DpK,{call:()=>$IY});async function $IY(){if(d("tengu_install_slack_app_clicked",{}),d8((K)=>({...K,slackAppInstallCount:(K.slackAppInstallCount??0)+1})),await J3(WpK))return{type:"text",value:"Opening Slack app installation page in browser…"};else return{type:"text",value:`Couldn't open browser. Visit: ${WpK}`}}var WpK="https://slack.com/marketplace/A08SF47R6P4-claude";var ZpK=L(()=>{C8();Nj();h1()});var jIY,fpK;var GpK=L(()=>{jIY={type:"local",name:"install-slack-app",description:"Install the Claude Slack app",availability:["claude-ai"],supportsNonInteractive:!1,load:()=>Promise.resolve().then(() => (ZpK(),DpK))},fpK=jIY});var vpK;var TpK=L(()=>{vpK={isEnabled:()=>!1,isHidden:!0,name:"stub"}});function cO7({agentServer:q,onCancel:K,onComplete:_}){let[z]=Zq(),[Y,A]=R5.useState(!1),[O,w]=R5.useState(null),[$,j]=R5.useState(null),H=R5.useRef(null);R5.useEffect(()=>()=>H.current?.abort(),[]);let J=R5.useCallback(()=>{if(Y)H.current?.abort(),H.current=null,A(!1),j(null)},[Y]);G1("confirm:no",J,{context:"Confirmation",isActive:Y});let X=R5.useCallback(async()=>{if(!q.needsAuth||!q.url)return;A(!0),w(null);let W=new AbortController;H.current=W;try{let D={type:q.transport,url:q.url};await T_6(q.name,D,j,W.signal),_?.(`Authentication successful for ${q.name}. The server will connect when the agent runs.`)}catch(D){if(D instanceof Error&&!(D instanceof Xu))w(D.message)}finally{A(!1),H.current=null}},[q,_]),M=zv(String(q.name));if(Y)return R5.default.createElement(u,{flexDirection:"column",gap:1,padding:1},R5.default.createElement(T,{color:"claude"},"Authenticating with ",q.name,"…"),R5.default.createElement(u,null,R5.default.createElement(Y5,null),R5.default.createElement(T,null," A browser window will open for authentication")),$&&R5.default.createElement(u,{flexDirection:"column"},R5.default.createElement(T,{dimColor:!0},"If your browser doesn't open automatically, copy this URL manually:"),R5.default.createElement(yq,{url:$})),R5.default.createElement(u,{marginLeft:3},R5.default.createElement(T,{dimColor:!0},"Return here after authenticating in your browser."," ",R5.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))));let P=[];if(q.needsAuth)P.push({label:q.isAuthenticated?"Re-authenticate":"Authenticate",value:"auth"});return P.push({label:"Back",value:"back"}),R5.default.createElement(R1,{title:`${M} MCP Server`,subtitle:"agent-only",onCancel:K,inputGuide:(W)=>W.pending?R5.default.createElement(T,null,"Press ",W.keyName," again to exit"):R5.default.createElement(z1,null,R5.default.createElement(A8,{chord:["up","down"],format:{arrowSep:""},action:"navigate"}),R5.default.createElement(A8,{chord:"enter",action:"confirm"}),R5.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))},R5.default.createElement(u,{flexDirection:"column",gap:0},R5.default.createElement(u,null,R5.default.createElement(T,{bold:!0},"Type: "),R5.default.createElement(T,{dimColor:!0},q.transport)),q.url&&R5.default.createElement(u,null,R5.default.createElement(T,{bold:!0},"URL: "),R5.default.createElement(T,{dimColor:!0},q.url)),q.command&&R5.default.createElement(u,null,R5.default.createElement(T,{bold:!0},"Command: "),R5.default.createElement(T,{dimColor:!0},q.command)),R5.default.createElement(u,null,R5.default.createElement(T,{bold:!0},"Used by: "),R5.default.createElement(T,{dimColor:!0},q.sourceAgents.join(", "))),R5.default.createElement(u,{marginTop:1},R5.default.createElement(T,{bold:!0},"Status: "),R5.default.createElement(T,null,d7("inactive",z)(e6.radioOff)," not connected (agent-only)")),q.needsAuth&&R5.default.createElement(u,null,R5.default.createElement(T,{bold:!0},"Auth: "),q.isAuthenticated?R5.default.createElement(T,null,d7("success",z)(e6.tick)," authenticated"):R5.default.createElement(T,null,d7("warning",z)(e6.triangleUpOutline)," may need authentication"))),R5.default.createElement(u,null,R5.default.createElement(T,{dimColor:!0},"This server connects only when running the agent.")),O&&R5.default.createElement(u,null,R5.default.createElement(T,{color:"error"},"Error: ",O)),R5.default.createElement(u,null,R5.default.createElement(A1,{options:P,onChange:async(W)=>{switch(W){case"auth":await X();break;case"back":K();break}},onCancel:K})))}var R5;var lO7=L(()=>{Qq();g6();C7();me();bK();g_();Nq();S4();u7();Ej();R5=K6(P6(),1)});function kpK(q){switch(q){case"project":return{label:"Project MCPs",path:rk(q)};case"user":return{label:"User MCPs",path:rk(q)};case"local":return{label:"Local MCPs",path:rk(q)};case"enterprise":return{label:"Enterprise MCPs"};case"dynamic":return{label:"Built-in MCPs",path:"always available"};default:return{label:q}}}function HIY(q){let K=new Map;for(let _ of q){let z=_.scope;if(!K.has(z))K.set(z,[]);K.get(z).push(_)}for(let[,_]of K)_.sort((z,Y)=>z.name.localeCompare(Y.name));return K}function nO7(q){let K=s(78),{servers:_,agentServers:z,onSelectServer:Y,onSelectAgentServer:A,onComplete:O}=q,w;if(K[0]!==z)w=z===void 0?[]:z,K[0]=z,K[1]=w;else w=K[1];let $=w,[j]=Zq(),[H,J]=B9.useState(0),X;if(K[2]!==_){let k6=_.filter(DIY);X=HIY(k6),K[2]=_,K[3]=X}else X=K[3];let M=X,P;if(K[4]!==_)P=_.filter(WIY).sort(PIY),K[4]=_,K[5]=P;else P=K[5];let W=P,D;if(K[6]!==M)D=(M.get("dynamic")??[]).sort(MIY),K[6]=M,K[7]=D;else D=K[7];let Z=D,G;if(K[8]===Symbol.for("react.memo_cache_sentinel"))G=kpK("dynamic"),K[8]=G;else G=K[8];let f=G,v;if(K[9]!==$||K[10]!==W||K[11]!==Z||K[12]!==M){v=[];for(let k6 of VpK){let T6=M.get(k6)??[];for(let v6 of T6)v.push({type:"server",server:v6})}for(let k6 of W)v.push({type:"server",server:k6});for(let k6 of $)v.push({type:"agent-server",agentServer:k6});for(let k6 of Z)v.push({type:"server",server:k6});K[9]=$,K[10]=W,K[11]=Z,K[12]=M,K[13]=v}else v=K[13];let V=v,k;if(K[14]!==O)k=()=>{O("MCP dialog dismissed",{display:"system"})},K[14]=O,K[15]=k;else k=K[15];let N=k,R;if(K[16]!==A||K[17]!==Y||K[18]!==V||K[19]!==H)R=()=>{let k6=V[H];if(!k6)return;if(k6.type==="server")Y(k6.server);else if(k6.type==="agent-server"&&A)A(k6.agentServer)},K[16]=A,K[17]=Y,K[18]=V,K[19]=H,K[20]=R;else R=K[20];let h=R,C,x;if(K[21]!==V)x=()=>J((k6)=>k6===0?V.length-1:k6-1),C=()=>J((k6)=>k6===V.length-1?0:k6+1),K[21]=V,K[22]=C,K[23]=x;else C=K[22],x=K[23];let B;if(K[24]!==N||K[25]!==h||K[26]!==C||K[27]!==x)B={"confirm:previous":x,"confirm:next":C,"confirm:yes":h,"confirm:no":N},K[24]=N,K[25]=h,K[26]=C,K[27]=x,K[28]=B;else B=K[28];let m;if(K[29]===Symbol.for("react.memo_cache_sentinel"))m={context:"Confirmation"},K[29]=m;else m=K[29];L7(B,m);let S;if(K[30]!==V)S=(k6)=>V.findIndex((T6)=>T6.type==="server"&&T6.server===k6),K[30]=V,K[31]=S;else S=K[31];let F=S,U;if(K[32]!==V)U=(k6)=>V.findIndex((T6)=>T6.type==="agent-server"&&T6.agentServer===k6),K[32]=V,K[33]=U;else U=K[33];let g=U,c;if(K[34]===Symbol.for("react.memo_cache_sentinel"))c=MV(),K[34]=c;else c=K[34];let n=c,l;if(K[35]!==_)l=_.some(XIY),K[35]=_,K[36]=l;else l=K[36];let z6=l;if(_.length===0&&$.length===0)return null;let A6;if(K[37]!==F||K[38]!==H||K[39]!==j)A6=(k6)=>{let T6=F(k6),v6=H===T6,L6,y6;if(k6.client.type==="disabled")L6=d7("inactive",j)(e6.radioOff),y6="disabled";else if(k6.client.type==="connected")L6=d7("success",j)(e6.tick),y6="connected";else if(k6.client.type==="pending"){L6=d7("inactive",j)(e6.radioOff);let{reconnectAttempt:c6,maxReconnectAttempts:Z8}=k6.client;if(c6&&Z8)y6=`reconnecting (${c6}/${Z8})…`;else y6="connecting…"}else if(k6.client.type==="needs-auth")L6=d7("warning",j)(e6.triangleUpOutline),y6="needs authentication";else L6=d7("error",j)(e6.cross),y6="failed";return B9.default.createElement(u,{key:`${k6.name}-${T6}`},B9.default.createElement(T,{color:v6?"suggestion":void 0},v6?`${e6.pointer} `:" "),B9.default.createElement(T,{color:v6?"suggestion":void 0},k6.name),B9.default.createElement(T,{dimColor:!v6}," · ",L6," "),B9.default.createElement(T,{dimColor:!v6},y6))},K[37]=F,K[38]=H,K[39]=j,K[40]=A6;else A6=K[40];let e=A6,i;if(K[41]!==g||K[42]!==H||K[43]!==j)i=(k6)=>{let T6=g(k6),v6=H===T6,L6=k6.needsAuth?d7("warning",j)(e6.triangleUpOutline):d7("inactive",j)(e6.radioOff),y6=k6.needsAuth?"may need auth":"agent-only";return B9.default.createElement(u,{key:`agent-${k6.name}-${T6}`},B9.default.createElement(T,{color:v6?"suggestion":void 0},v6?`${e6.pointer} `:" "),B9.default.createElement(T,{color:v6?"suggestion":void 0},k6.name),B9.default.createElement(T,{dimColor:!v6}," · ",L6," "),B9.default.createElement(T,{dimColor:!v6},y6))},K[41]=g,K[42]=H,K[43]=j,K[44]=i;else i=K[44];let O6=i,J6=_.length+$.length,$6;if(K[45]===Symbol.for("react.memo_cache_sentinel"))$6=B9.default.createElement(Pi8,null),K[45]=$6;else $6=K[45];let H6;if(K[46]!==J6)H6=O7(J6,"server"),K[46]=J6,K[47]=H6;else H6=K[47];let q6=`${J6} ${H6}`,o;if(K[48]!==e||K[49]!==M)o=VpK.map((k6)=>{let T6=M.get(k6);if(!T6||T6.length===0)return null;let v6=kpK(k6);return B9.default.createElement(u,{key:k6,flexDirection:"column",marginBottom:1},B9.default.createElement(u,{paddingLeft:2},B9.default.createElement(T,{bold:!0},v6.label),v6.path&&B9.default.createElement(T,{dimColor:!0}," (",v6.path,")")),T6.map((L6)=>e(L6)))}),K[48]=e,K[49]=M,K[50]=o;else o=K[50];let _6;if(K[51]!==W||K[52]!==e)_6=W.length>0&&B9.default.createElement(u,{flexDirection:"column",marginBottom:1},B9.default.createElement(u,{paddingLeft:2},B9.default.createElement(T,{bold:!0},"claude.ai")),W.map((k6)=>e(k6))),K[51]=W,K[52]=e,K[53]=_6;else _6=K[53];let r;if(K[54]!==$||K[55]!==O6)r=$.length>0&&B9.default.createElement(u,{flexDirection:"column",marginBottom:1},B9.default.createElement(u,{paddingLeft:2},B9.default.createElement(T,{bold:!0},"Agent MCPs")),F4($.flatMap(JIY)).map((k6)=>B9.default.createElement(u,{key:k6,flexDirection:"column",marginTop:1},B9.default.createElement(u,{paddingLeft:2},B9.default.createElement(T,{dimColor:!0},"@",k6)),$.filter((T6)=>T6.sourceAgents.includes(k6)).map((T6)=>O6(T6))))),K[54]=$,K[55]=O6,K[56]=r;else r=K[56];let t;if(K[57]!==Z||K[58]!==e)t=Z.length>0&&B9.default.createElement(u,{flexDirection:"column",marginBottom:1},B9.default.createElement(u,{paddingLeft:2},B9.default.createElement(T,{bold:!0},f.label),f.path&&B9.default.createElement(T,{dimColor:!0}," (",f.path,")")),Z.map((k6)=>e(k6))),K[57]=Z,K[58]=e,K[59]=t;else t=K[59];let Y6;if(K[60]!==z6)Y6=z6&&B9.default.createElement(T,{dimColor:!0},n?"※ Error logs shown inline with --debug":"※ Run claude --debug to see error logs"),K[60]=z6,K[61]=Y6;else Y6=K[61];let X6;if(K[62]===Symbol.for("react.memo_cache_sentinel"))X6=B9.default.createElement(T,{dimColor:!0},B9.default.createElement(yq,{url:"https://code.claude.com/docs/en/mcp"},"https://code.claude.com/docs/en/mcp")," ","for help"),K[62]=X6;else X6=K[62];let M6;if(K[63]!==Y6)M6=B9.default.createElement(u,{flexDirection:"column"},Y6,X6),K[63]=Y6,K[64]=M6;else M6=K[64];let W6;if(K[65]!==o||K[66]!==_6||K[67]!==r||K[68]!==t||K[69]!==M6)W6=B9.default.createElement(u,{flexDirection:"column"},o,_6,r,t,M6),K[65]=o,K[66]=_6,K[67]=r,K[68]=t,K[69]=M6,K[70]=W6;else W6=K[70];let V6;if(K[71]!==N||K[72]!==q6||K[73]!==W6)V6=B9.default.createElement(R1,{title:"Manage MCP servers",subtitle:q6,onCancel:N,hideInputGuide:!0},W6),K[71]=N,K[72]=q6,K[73]=W6,K[74]=V6;else V6=K[74];let f6;if(K[75]===Symbol.for("react.memo_cache_sentinel"))f6=B9.default.createElement(u,{paddingX:1},B9.default.createElement(T,{dimColor:!0,italic:!0},B9.default.createElement(z1,null,B9.default.createElement(A8,{chord:["up","down"],format:{arrowSep:""},action:"navigate"}),B9.default.createElement(A8,{chord:"enter",action:"confirm"}),B9.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"cancel"})))),K[75]=f6;else f6=K[75];let G6;if(K[76]!==V6)G6=B9.default.createElement(u,{flexDirection:"column"},$6,V6,f6),K[76]=V6,K[77]=G6;else G6=K[77];return G6}function JIY(q){return q.sourceAgents}function XIY(q){return q.client.type==="failed"}function MIY(q,K){return q.name.localeCompare(K.name)}function PIY(q,K){return q.name.localeCompare(K.name)}function WIY(q){return q.client.config.type==="claudeai-proxy"}function DIY(q){return q.client.config.type!=="claudeai-proxy"}var B9,VpK;var iO7=L(()=>{o6();Qq();g6();C7();iD();K8();bK();Nq();S4();u7();hO7();B9=K6(P6(),1),VpK=["project","local","user","enterprise"]});function ZIY(q,K){return QC(q,Pl8(xN(K)))}var rO7;var NpK=L(()=>{N86();Gz7();Xf6();rO7=ZIY});var EpK={};h8(EpK,{isChannelsEnabled:()=>mP6,isChannelAllowlisted:()=>oO7,getChannelAllowlist:()=>ki8});function ki8(){let q=u8("tengu_harbor_ledger",[]),K=fIY().safeParse(q);return K.success?K.data:[]}function mP6(){return u8("tengu_harbor",!1)}function oO7(q){if(!q)return!1;let{name:K,marketplace:_}=Z4(q);if(!_)return!1;return ki8().some((z)=>z.plugin===K&&z.marketplace===_)}var fIY;var __8=L(()=>{p7();aW();B1();fIY=C6(()=>y.array(y.object({marketplace:y.string(),plugin:y.string()})))});function Y_8(q,K,_){let z=Object.entries(_??{}).filter(([Y])=>GIY.test(Y)).map(([Y,A])=>` ${Y}="${O_(A)}"`).join("");return`<${Tf6} source="${O_(q)}"${z}>
6421
6421
  ${K}
6422
- </${Tf6}>`}function sO7(q,K){if((q==="team"||q==="enterprise")&&K)return{entries:K,source:"org"};return{entries:ki8(),source:"ledger"}}function BP6(q,K){let _=q.split(":");return K.find((z)=>z.kind==="server"?q===z.name:_[0]==="plugin"&&_[1]===z.name)}function A_8(q,K,_){if(false)return{action:"skip",kind:"capability",reason:"server did not declare claude/channel capability"};if(false)return{action:"skip",kind:"disabled",reason:"channels feature is not currently available"};if(false)return{action:"skip",kind:"auth",reason:"channels requires claude.ai authentication (run /login)"};let z=MK(),Y=z==="team"||z==="enterprise",A=Y?E1("policySettings"):void 0;if(Y&&A?.channelsEnabled!==!0)return{action:"skip",kind:"policy",reason:"channels not enabled by org policy (set channelsEnabled: true in managed settings)"};let O=BP6(q,qj());if(!O)return{action:"skip",kind:"session",reason:`server ${q} not in --channels list for this session`};if(O.kind==="plugin"){let w=_?Z4(_).marketplace:void 0;if(false)return{action:"skip",kind:"marketplace",reason:`you asked for plugin:${O.name}@${O.marketplace} but the installed ${O.name} plugin is from ${w??"an unknown source"}`};if(!O.dev){let{entries:$,source:j}=sO7(z,A?.allowedChannelPlugins);if(!$.some((H)=>H.plugin===O.name&&H.marketplace===O.marketplace))return{action:"skip",kind:"allowlist",reason:j==="org"?`plugin ${O.name}@${O.marketplace} is not on your org's approved channels list (set allowedChannelPlugins in managed settings)`:`plugin ${O.name}@${O.marketplace} is not on the approved channels allowlist (use --dangerously-load-development-channels for local dev)`}}}else if(!O.dev)return{action:"skip",kind:"allowlist",reason:`server ${O.name} is not on the approved channels allowlist (use --dangerously-load-development-channels for local dev)`};return{action:"register"}}var z_8,aO7="notifications/claude/channel/permission",ypK,LpK="notifications/claude/channel/permission_request",GIY;var O_8=L(()=>{p7();y8();rA();T7();aW();a1();__8();z_8=C6(()=>y.object({method:y.literal("notifications/claude/channel"),params:y.object({content:y.string(),meta:y.record(y.string(),y.string()).optional()})})),ypK=C6(()=>y.object({method:y.literal(aO7),params:y.object({request_id:y.string(),behavior:y.enum(["allow","deny"])})})),GIY=/^[a-zA-Z_][a-zA-Z0-9_]*$/});function RpK(){return true}function hpK(q){let K=2166136261;for(let z=0;z<q.length;z++)K^=q.charCodeAt(z),K=Math.imul(K,16777619);K=K>>>0;let _="";for(let z=0;z<5;z++)_+=vIY[K%25],K=Math.floor(K/25);return _}function SpK(q){let K=hpK(q);for(let _=0;_<10;_++){if(!TIY.some((z)=>K.includes(z)))return K;K=hpK(`${q}:${_}`)}return K}function CpK(q){try{let K=I6(q);return K.length>200?K.slice(0,200)+"…":K}catch{return"(unserializable)"}}function bpK(q,K){return q.filter((_)=>_.type==="connected"&&K(_.name)&&_.capabilities?.experimental?.["claude/channel"]!==void 0&&_.capabilities?.experimental?.["claude/channel/permission"]!==void 0)}function IpK(){let q=new Map;return{onResponse(K,_){let z=K.toLowerCase();return q.set(z,_),()=>{q.delete(z)}},resolve(K,_,z){let Y=K.toLowerCase(),A=q.get(Y);if(!A)return!1;return q.delete(Y),A({behavior:_,fromServer:z}),!0}}}var vIY="abcdefghijkmnopqrstuvwxyz",TIY;var tO7=L(()=>{e8();B1();TIY=["fuck","shit","cunt","cock","dick","twat","piss","crap","bitch","whore","ass","tit","cum","fag","dyke","nig","kike","rape","nazi","damn","poo","pee","wank","anus"]});function xpK(q){let K="plugin"in q?q.plugin:"no-plugin";return`${q.type}:${q.source}:${K}`}function upK(q,K){if(K.length===0)return;q((_)=>{let z=new Set(_.plugins.errors.map((A)=>xpK(A))),Y=K.filter((A)=>!z.has(xpK(A)));if(Y.length===0)return _;return{..._,plugins:{..._.plugins,errors:[..._.plugins.errors,...Y]}}})}function mpK(q,K=!1){let _=H9(),z=M8((v)=>v.authVersion),Y=M8((v)=>v.mcp.pluginReconnectKey),A=R7(),O=wZ.useRef(new Map),w=wZ.useRef(new Set),$=wZ.useRef(new Set),j=wZ.useRef(null);if(j.current===null)j.current=IpK();wZ.useEffect(()=>{{let v=j.current;if(!v)return;if(!RpK())return;return A((V)=>{if(V.channelPermissionCallbacks===v)return V;return{...V,channelPermissionCallbacks:v}}),()=>{A((V)=>{if(V.channelPermissionCallbacks===void 0)return V;return{...V,channelPermissionCallbacks:void 0}})}}},[A]);let{addNotification:H}=EK(),J=16,X=wZ.useRef([]),M=wZ.useRef(null),P=wZ.useCallback(()=>{M.current=null;let v=X.current;if(v.length===0)return;X.current=[],A((V)=>{let k=V.mcp;for(let N of v){let{tools:R,commands:h,resources:C,resourceTemplates:x,...B}=N,m=B.type==="disabled"||B.type==="failed"?R??[]:R,S=B.type==="disabled"||B.type==="failed"?h??[]:h,F=B.type==="disabled"||B.type==="failed"?C??[]:C,U=B.type==="disabled"||B.type==="failed"?x??[]:x,g=Zh(B.name),n=k.clients.findIndex((i)=>i.name===B.name)===-1?[...k.clients,B]:k.clients.map((i)=>i.name===B.name?B:i),l=m===void 0?k.tools:[...PG(k.tools,(i)=>i.name?.startsWith(g)),...m],z6=S===void 0?k.commands:[...PG(k.commands,(i)=>hl(i,B.name)),...S],A6=F===void 0?k.resources:{...k.resources,...F.length>0?{[B.name]:F}:gF(k.resources,B.name)},e=U===void 0?k.resourceTemplates:U.length>0?{...k.resourceTemplates,[B.name]:U}:gF(k.resourceTemplates,B.name);k={...k,clients:n,tools:l,commands:z6,resources:A6,resourceTemplates:e}}return{...V,mcp:k}})},[A]),W=wZ.useCallback((v)=>{if(X.current.push(v),M.current===null)M.current=setTimeout(P,J)},[P]),D=wZ.useCallback(({client:v,tools:V,commands:k,resources:N,resourceTemplates:R})=>{switch(W({...v,tools:V,commands:k,resources:N,resourceTemplates:R}),v.type){case"connected":{BhK(v.client,v.name,A),v.client.onclose=()=>{let h=v.config.type??"stdio";if(WG(v.name,v.config).catch(()=>{E(`Failed to invalidate the server cache: ${v.name}`)}),ZT(v.name)){i8(v.name,"Server is disabled, skipping automatic reconnection");return}if(h!=="stdio"&&h!=="sdk"){let C=EIY(h);i8(v.name,`${C} transport closed/disconnected, attempting automatic reconnection`);let x=O.current.get(v.name);if(x)clearTimeout(x),O.current.delete(v.name);(async()=>{for(let m=1;m<=kx6;m++){if(ZT(v.name)){i8(v.name,"Server disabled during reconnection, stopping retry"),O.current.delete(v.name);return}W({...v,type:"pending",reconnectAttempt:m,maxReconnectAttempts:kx6});let S=Date.now();try{let U=await _g(v.name,v.config),g=Date.now()-S;if(U.client.type==="connected"){i8(v.name,`${C} reconnection successful after ${g}ms (attempt ${m})`),O.current.delete(v.name),D(U);return}if(i8(v.name,`${C} reconnection attempt ${m} completed with status: ${U.client.type}`),m===kx6){i8(v.name,`Max reconnection attempts (${kx6}) reached, giving up`),O.current.delete(v.name),D(U);return}}catch(U){let g=Date.now()-S;if(yz(v.name,`${C} reconnection attempt ${m} failed after ${g}ms: ${U}`),m===kx6){i8(v.name,`Max reconnection attempts (${kx6}) reached, giving up`),O.current.delete(v.name),W({...v,type:"failed"});return}}let F=Math.min(kIY*Math.pow(2,m-1),NIY);i8(v.name,`Scheduling reconnection attempt ${m+1} in ${F}ms`),await new Promise((U)=>{let g=setTimeout(U,F);O.current.set(v.name,g)})}})()}else $.current.delete(v.name),W({...v,type:"failed"})};{let h=A_8(v.name,v.capabilities,v.config.pluginSource),C=BP6(v.name,qj()),x=C?.kind==="plugin"?`${C.name}@${C.marketplace}`:void 0,B=!1,m=()=>{if($.current.add(v.name),v.client.setNotificationHandler(z_8(),async(S)=>{let{content:F,meta:U}=S.params;i8(v.name,`notifications/claude/channel: ${F.slice(0,80)}`),d("tengu_mcp_channel_message",{content_length:F.length,meta_key_count:Object.keys(U??{}).length,entry_kind:C?.kind,is_dev:C?.dev??!1,plugin:x}),Dj({mode:"prompt",value:Y_8(v.name,F,U),priority:"next",isMeta:!0,origin:{kind:"channel",server:v.name},skipSlashCommands:!0})}),v.capabilities?.experimental?.["claude/channel/permission"]!==void 0)v.client.setNotificationHandler(ypK(),async(S)=>{let{request_id:F,behavior:U}=S.params,g=j.current?.resolve(F,U,v.name)??!1;i8(v.name,`notifications/claude/channel/permission: ${F} → ${U} (${g?"matched pending":"no pending entry — stale or unknown ID"})`)})};switch(h.action){case"register":i8(v.name,"Channel notifications registered"),m(),B=!0;break;case"skip":{let S=h.kind==="auth"||h.kind==="disabled"||h.kind==="capability",F=$.current.has(v.name);if(S)$.current.delete(v.name),v.client.removeNotificationHandler("notifications/claude/channel"),v.client.removeNotificationHandler(aO7);else if(F){i8(v.name,`Channel gate says skip:${h.kind} but was previously registered — preserving handler`),m(),B=!0;break}if(i8(v.name,`Channel notifications skipped: ${h.reason}`),h.kind!=="capability"&&h.kind!=="session"&&!w.current.has(h.kind)&&(h.kind==="marketplace"||h.kind==="allowlist"||C!==void 0)){w.current.add(h.kind);let U=h.kind==="disabled"?"Channels are not currently available":h.kind==="auth"?"Channels require claude.ai authentication · run /login":h.kind==="policy"?"Channels are not enabled for your org · have an administrator set channelsEnabled: true in managed settings":h.reason;H({key:`channels-blocked-${h.kind}`,priority:"high",text:U,color:"warning",timeoutMs:12000})}break}}if(B||h.action==="skip"&&h.kind!=="capability")d("tengu_mcp_channel_gate",{registered:B,skip_kind:h.action==="skip"?h.kind:void 0,entry_kind:C?.kind,is_dev:C?.dev??!1,plugin:x})}if(v.capabilities?.tools?.listChanged)v.client.setNotificationHandler(Ig6,async()=>{i8(v.name,"Received tools/list_changed notification, refreshing tools");try{let h=NS.cache.get(v.name);NS.cache.delete(v.name);let C=await NS(v),x=C.length;if(h)h.then((B)=>{d("tengu_mcp_list_changed",{type:"tools",previousCount:B.length,newCount:x})},()=>{d("tengu_mcp_list_changed",{type:"tools",newCount:x})});else d("tengu_mcp_list_changed",{type:"tools",newCount:x});W({...v,tools:C})}catch(h){yz(v.name,`Failed to refresh tools after list_changed notification: ${b6(h)}`)}});if(v.capabilities?.prompts?.listChanged)v.client.setNotificationHandler(Cg6,async()=>{i8(v.name,"Received prompts/list_changed notification, refreshing prompts"),d("tengu_mcp_list_changed",{type:"prompts"});try{JP6.cache.delete(v.name);let[h,C]=await Promise.all([JP6(v),Promise.resolve([])]);W({...v,commands:[...h,...C]}),VIY?.()}catch(h){yz(v.name,`Failed to refresh prompts after list_changed notification: ${b6(h)}`)}});if(v.capabilities?.resources?.listChanged)v.client.setNotificationHandler(Rg6,async()=>{i8(v.name,"Received resources/list_changed notification, refreshing resources"),d("tengu_mcp_list_changed",{type:"resources"});try{Es.cache.delete(v.name),HP6.cache.delete(v.name);{let[h,C]=await Promise.all([Es(v),HP6(v)]);W({...v,resources:h,resourceTemplates:C})}}catch(h){yz(v.name,`Failed to refresh resources after list_changed notification: ${b6(h)}`)}});break}case"needs-auth":case"failed":case"pending":case"disabled":break}},[W]),Z=I8();wZ.useEffect(()=>{async function v(){let{servers:V,errors:k}=K?{servers:{},errors:[]}:await ZX6(q),N={...V,...q};upK(A,k),A((R)=>{let{stale:h,...C}=P_K(R.mcp,N);for(let m of h){let S=O.current.get(m.name);if(S)clearTimeout(S),O.current.delete(m.name);if($.current.delete(m.name),m.type==="connected")m.client.onclose=void 0,WG(m.name,m.config).catch(()=>{})}let x=new Set(C.clients.map((m)=>m.name)),B=Object.entries(N).filter(([m])=>!x.has(m)).map(([m,S])=>({name:m,type:ZT(m)?"disabled":"pending",config:S}));if(B.length===0&&h.length===0)return R;return{...R,mcp:{...R.mcp,...C,clients:[...C.clients,...B]}}})}v().catch((V)=>{yz("useManageMCPConnections",`Failed to initialize servers as pending: ${b6(V)}`)})},[K,q,A,Z,Y]),wZ.useEffect(()=>{let v=!1;async function V(){let k;if(K||e36())k=Promise.resolve({});else X_K(),k=DX6();let{servers:N,errors:R}=K?{servers:{},errors:[]}:await ZX6(q);if(v)return;upK(A,R);let h={...N,...q},C=rO7(h,(F,U)=>ZT(U));XP6(D,C).catch((F)=>{yz("useManageMcpConnections",`Failed to get MCP resources: ${b6(F)}`)});let x={};if(!K){if(x=s36(await k).allowed,v)return;if(Object.keys(x).length>0){let{servers:F}=Y48(x,h);x=F}if(Object.keys(x).length>0){A((U)=>{let g=new Set(U.mcp.clients.map((n)=>n.name)),c=Object.entries(x).filter(([n])=>!g.has(n)).map(([n,l])=>({name:n,type:ZT(n)?"disabled":"pending",config:l}));if(c.length===0)return U;return{...U,mcp:{...U.mcp,clients:[...U.mcp.clients,...c]}}});let F=rO7(x,(U,g)=>ZT(g));XP6(D,F).catch((U)=>{yz("useManageMcpConnections",`Failed to get claude.ai MCP resources: ${b6(U)}`)})}}let B={...h,...x},m={enterprise:0,global:0,project:0,user:0,plugin:0,claudeai:0},S=[];for(let[F,U]of Object.entries(B))if(U.scope==="enterprise")m.enterprise++;else if(U.scope==="user")m.global++;else if(U.scope==="project")m.project++;else if(U.scope==="local")m.user++;else if(U.scope==="dynamic")m.plugin++;else if(U.scope==="claudeai")m.claudeai++;d("tengu_mcp_servers",{...m,...!1})}return V(),()=>{v=!0}},[K,q,D,A,z,Z,Y]),wZ.useEffect(()=>{let v=O.current;return()=>{for(let V of v.values())clearTimeout(V);if(v.clear(),M.current!==null)clearTimeout(M.current),M.current=null,P()}},[P]);let G=wZ.useCallback(async(v)=>{let V=_.getState().mcp.clients.find((R)=>R.name===v);if(!V)throw Error(`MCP server ${v} not found`);let k=O.current.get(v);if(k)clearTimeout(k),O.current.delete(v);let N=await _g(v,V.config);return D(N),N},[_,D]),f=wZ.useCallback(async(v)=>{let V=_.getState().mcp.clients.find((N)=>N.name===v);if(!V)throw Error(`MCP server ${v} not found`);if(V.type!=="disabled"){let N=O.current.get(v);if(N)clearTimeout(N),O.current.delete(v);if(YC6(v,!1),$.current.delete(v),V.type==="connected")await WG(v,V.config);W({name:v,type:"disabled",config:V.config})}else{YC6(v,!0),W({name:v,type:"pending",config:V.config});let N=await _g(v,V.config);D(N)}},[_,W,D]);return{reconnectMcpServer:G,toggleMcpServer:f}}function EIY(q){switch(q){case"http":return"HTTP";case"ws":case"ws-ide":return"WebSocket";default:return"SSE"}}var wZ,VIY=null,kx6=5,kIY=1000,NIY=30000;var BpK=L(()=>{y8();oW();_P();jU8();NpK();Wl8();C8();rD();K8();y8();kY();N7();m8();U8();b$();O_8();tO7();tS6();dl8();fh();iD();wZ=K6(P6(),1)});function Nx6(){let q=pP6.useContext(eO7);if(!q)throw Error("useMcpReconnect must be used within MCPConnectionManager");return q.reconnectMcpServer}function m_6(){let q=pP6.useContext(eO7);if(!q)throw Error("useMcpToggleEnabled must be used within MCPConnectionManager");return q.toggleMcpServer}function Ni8(q){let K=s(6),{children:_,dynamicMcpConfig:z,isStrictMcpConfig:Y}=q,{reconnectMcpServer:A,toggleMcpServer:O}=mpK(z,Y),w;if(K[0]!==A||K[1]!==O)w={reconnectMcpServer:A,toggleMcpServer:O},K[0]=A,K[1]=O,K[2]=w;else w=K[2];let $=w,j;if(K[3]!==_||K[4]!==$)j=pP6.default.createElement(eO7.Provider,{value:$},_),K[3]=_,K[4]=$,K[5]=j;else j=K[5];return j}var pP6,eO7;var B_6=L(()=>{o6();BpK();pP6=K6(P6(),1),eO7=pP6.createContext(null)});function qw7(q){let K=s(25),{serverName:_,onComplete:z}=q,[Y]=Zq(),A=H9(),O=Nx6(),[w,$]=GG.useState(!0),[j,H]=GG.useState(null),J,X;if(K[0]!==z||K[1]!==O||K[2]!==_||K[3]!==A)J=()=>{(async function(){try{if(!A.getState().mcp.clients.find((Z)=>Z.name===_)){H(`MCP server "${_}" not found`),$(!1),z(`MCP server "${_}" not found`);return}let D=await O(_);q:switch(D.client.type){case"connected":{$(!1),z(`Successfully reconnected to ${_}`);break q}case"needs-auth":{H(`${_} requires authentication`),$(!1),z(`${_} requires authentication. Use /mcp to authenticate.`);break q}case"pending":case"failed":case"disabled":H(`Failed to reconnect to ${_}`),$(!1),z(`Failed to reconnect to ${_}`)}}catch(W){let D=W,Z=D instanceof Error?D.message:String(D);H(Z),$(!1),z(`Error: ${Z}`)}})()},X=[_,O,A,z],K[0]=z,K[1]=O,K[2]=_,K[3]=A,K[4]=J,K[5]=X;else J=K[4],X=K[5];if(GG.useEffect(J,X),w){let M;if(K[6]!==_)M=GG.default.createElement(T,{color:"text"},"Reconnecting to ",GG.default.createElement(T,{bold:!0},_)),K[6]=_,K[7]=M;else M=K[7];let P;if(K[8]===Symbol.for("react.memo_cache_sentinel"))P=GG.default.createElement(u,null,GG.default.createElement(Y5,null),GG.default.createElement(T,null," Establishing connection to MCP server")),K[8]=P;else P=K[8];let W;if(K[9]!==M)W=GG.default.createElement(u,{flexDirection:"column",gap:1,padding:1},M,P),K[9]=M,K[10]=W;else W=K[10];return W}if(j){let M;if(K[11]!==Y)M=d7("error",Y)(e6.cross),K[11]=Y,K[12]=M;else M=K[12];let P;if(K[13]!==M)P=GG.default.createElement(T,null,M," "),K[13]=M,K[14]=P;else P=K[14];let W;if(K[15]!==_)W=GG.default.createElement(T,{color:"error"},"Failed to reconnect to ",_),K[15]=_,K[16]=W;else W=K[16];let D;if(K[17]!==P||K[18]!==W)D=GG.default.createElement(u,null,P,W),K[17]=P,K[18]=W,K[19]=D;else D=K[19];let Z;if(K[20]!==j)Z=GG.default.createElement(T,{dimColor:!0},"Error: ",j),K[20]=j,K[21]=Z;else Z=K[21];let G;if(K[22]!==D||K[23]!==Z)G=GG.default.createElement(u,{flexDirection:"column",gap:1,padding:1},D,Z),K[22]=D,K[23]=Z,K[24]=G;else G=K[24];return G}return null}var GG;var Kw7=L(()=>{o6();Qq();g6();B_6();N7();Ej();GG=K6(P6(),1)});function Ei8(q){let K=s(9),{serverToolsCount:_,serverPromptsCount:z,serverResourcesCount:Y}=q,A;if(K[0]!==z||K[1]!==Y||K[2]!==_){if(A=[],_>0)A.push("tools");if(Y>0)A.push("resources");if(z>0)A.push("prompts");K[0]=z,K[1]=Y,K[2]=_,K[3]=A}else A=K[3];let O;if(K[4]===Symbol.for("react.memo_cache_sentinel"))O=w_8.default.createElement(T,{bold:!0},"Capabilities: "),K[4]=O;else O=K[4];let w;if(K[5]!==A)w=A.length>0?w_8.default.createElement(z1,null,A):"none",K[5]=A,K[6]=w;else w=K[6];let $;if(K[7]!==w)$=w_8.default.createElement(u,null,O,w_8.default.createElement(T,{color:"text"},w)),K[7]=w,K[8]=$;else $=K[8];return $}var w_8;var _w7=L(()=>{o6();g6();Nq();w_8=K6(P6(),1)});function yi8(q,K,_){switch(q.client.type){case"connected":return{message:`Reconnected to ${K}.`,success:!0};case"needs-auth":return{message:_?.hasHeadersHelper?`${K} requires authentication. Check that the headersHelper script returns valid credentials, then use the 'Reconnect' option.`:`${K} requires authentication. Use the 'Authenticate' option.`,success:!1};case"failed":return{message:`Failed to reconnect to ${K}.`,success:!1};default:return{message:`Unknown result when reconnecting to ${K}.`,success:!1}}}function $_8(q,K){let _=q instanceof Error?q.message:String(q);return`Error reconnecting to ${K}: ${_}`}function FP6({server:q,serverToolsCount:K,onViewTools:_,onCancel:z,onComplete:Y,borderless:A=!1}){let[O]=Zq(),w=$3(),{columns:$}=s1(),[j,H]=H7.default.useState(!1),[J,X]=H7.default.useState(null),M=M8((f6)=>f6.mcp),P=R7(),[W,D]=H7.default.useState(null),[Z,G]=H7.useState(!1),f=H7.useRef(null),[v,V]=H7.useState(!1),[k,N]=H7.useState(null),[R,h]=H7.useState(!1),[C,x]=H7.useState(null),[B,m]=H7.useState(!1),[S,F]=H7.useState(!1),U=H7.useRef(void 0),g=H7.useRef(!1),[c,n]=H7.useState(""),[l,z6]=H7.useState(0),[A6,e]=H7.useState(null);H7.useEffect(()=>()=>{if(g.current=!0,f.current?.abort(),U.current!==void 0)clearTimeout(U.current)},[]);let i=q.isAuthenticated||q.client.type==="connected"&&K>0,O6=Nx6(),J6=H7.default.useCallback(async()=>{V(!1),N(null),G(!0);try{let f6=await O6(q.name),G6=f6.client.type==="connected";if(d("tengu_claudeai_mcp_auth_completed",{success:G6}),G6)Y?.(`Authentication successful. Connected to ${q.name}.`);else if(f6.client.type==="needs-auth")Y?.("Authentication successful, but server still requires authentication. You may need to manually restart Claude Code.");else Y?.("Authentication successful, but server reconnection failed. You may need to manually restart Claude Code for the changes to take effect.")}catch(f6){d("tengu_claudeai_mcp_auth_completed",{success:!1}),Y?.($_8(f6,q.name))}finally{G(!1)}},[O6,q.name,Y]),$6=H7.default.useCallback(async()=>{await WG(q.name,{...q.config,scope:q.scope}),P((f6)=>{let G6=f6.mcp.clients.map((L6)=>L6.name===q.name?{...L6,type:"needs-auth"}:L6),k6=bp8(f6.mcp.tools,q.name),T6=eS6(f6.mcp.commands,q.name),v6=qC6(f6.mcp.resources,q.name);return{...f6,mcp:{...f6.mcp,clients:G6,tools:k6,commands:T6,resources:v6}}}),d("tengu_claudeai_mcp_clear_auth_completed",{}),Y?.(`Disconnected from ${q.name}.`),h(!1),x(null),m(!1)},[q.name,q.config,q.scope,P,Y]);G1("confirm:no",()=>{f.current?.abort(),f.current=null,H(!1),D(null)},{context:"Confirmation",isActive:j}),G1("confirm:no",()=>{V(!1),N(null)},{context:"Confirmation",isActive:v}),G1("confirm:no",()=>{h(!1),x(null),m(!1)},{context:"Confirmation",isActive:R});function H6(f6){if(f6.key==="return"&&v)f6.preventDefault(),J6();if(f6.key==="return"&&R)if(f6.preventDefault(),B)$6();else{let G6=`${r7().CLAUDE_AI_ORIGIN}/settings/connectors`;x(G6),m(!0),J3(G6)}if(f6.key==="c"&&!f6.ctrl&&!f6.meta&&!S){let G6=W||k||C;if(G6)f6.preventDefault(),hP(G6).then((k6)=>{if(g.current)return;if(k6)process.stdout.write(k6);if(F(!0),U.current!==void 0)clearTimeout(U.current);U.current=setTimeout(F,2000,!1)})}}let q6=zv(String(q.name)),o=Cp8(M.commands,q.name).length,_6=m_6(),r=H7.default.useCallback(async()=>{let f6=r7().CLAUDE_AI_ORIGIN,k6=k_()?.organizationUuid,T6;if(k6&&q.config.type==="claudeai-proxy"&&q.config.id){let v6=q.config.id.startsWith("mcprs")?"mcpsrv"+q.config.id.slice(5):q.config.id,L6=encodeURIComponent(process.env.CLAUDE_CODE_ENTRYPOINT||"cli");T6=`${f6}/api/organizations/${k6}/mcp/start-auth/${v6}?product_surface=${L6}`}else T6=`${f6}/settings/connectors`;N(T6),V(!0),d("tengu_claudeai_mcp_auth_started",{}),await J3(T6)},[q.config]),t=H7.default.useCallback(()=>{h(!0),d("tengu_claudeai_mcp_clear_auth_started",{})},[]),Y6=H7.default.useCallback(async()=>{let f6=q.client.type!=="disabled";try{if(await _6(q.name),q.config.type==="claudeai-proxy")d("tengu_claudeai_mcp_toggle",{new_state:f6?"disabled":"enabled"});z()}catch(G6){Y?.(`Failed to ${f6?"disable":"enable"} MCP server '${q.name}': ${b6(G6)}`)}},[q.client.type,q.config.type,q.name,_6,z,Y]),X6=H7.default.useCallback(async()=>{if(q.config.type==="claudeai-proxy")return;H(!0),X(null);let f6=new AbortController;f.current=f6;try{if(q.isAuthenticated&&q.config)await q98(q.name,q.config,{preserveStepUpState:!0});if(q.config){await T_6(q.name,q.config,D,f6.signal,{onWaitingForCallback:(k6)=>{e(()=>k6)}}),d("tengu_mcp_auth_config_authenticate",{wasAuthenticated:q.isAuthenticated});let G6=await O6(q.name);if(G6.client.type==="connected"){let k6=i?`Authentication successful. Reconnected to ${q.name}.`:`Authentication successful. Connected to ${q.name}.`;Y?.(k6)}else if(G6.client.type==="needs-auth")Y?.("Authentication successful, but server still requires authentication. You may need to manually restart Claude Code.");else i8(q.name,"Reconnection failed after authentication"),Y?.("Authentication successful, but server reconnection failed. You may need to manually restart Claude Code for the changes to take effect.")}}catch(G6){if(G6 instanceof Error&&!(G6 instanceof Xu))X(G6.message)}finally{H(!1),f.current=null,e(null),n("")}},[q.isAuthenticated,q.config,q.name,Y,O6,i]),M6=async()=>{if(q.config.type==="claudeai-proxy")return;if(q.config)await q98(q.name,q.config),d("tengu_mcp_auth_config_clear",{}),await WG(q.name,{...q.config,scope:q.scope}),P((f6)=>{let G6=f6.mcp.clients.map((L6)=>L6.name===q.name?{...L6,type:"failed"}:L6),k6=bp8(f6.mcp.tools,q.name),T6=eS6(f6.mcp.commands,q.name),v6=qC6(f6.mcp.resources,q.name);return{...f6,mcp:{...f6.mcp,clients:G6,tools:k6,commands:T6,resources:v6}}}),Y?.(`Authentication cleared for ${q.name}.`)};if(j){let f6=q.config.type!=="claudeai-proxy"&&q.config.oauth?.xaa?" Authenticating via your identity provider":" A browser window will open for authentication";return H7.default.createElement(u,{flexDirection:"column",gap:1,padding:1,tabIndex:0,autoFocus:!0,onKeyDown:H6},H7.default.createElement(T,{color:"claude"},"Authenticating with ",q.name,"…"),H7.default.createElement(u,null,H7.default.createElement(Y5,null),H7.default.createElement(T,null,f6)),W&&H7.default.createElement(u,{flexDirection:"column"},H7.default.createElement(u,null,H7.default.createElement(T,{dimColor:!0},"If your browser doesn't open automatically, copy this URL manually"," "),S?H7.default.createElement(T,{color:"success"},"(Copied!)"):H7.default.createElement(T,{dimColor:!0},H7.default.createElement(A8,{chord:"c",action:"copy",parens:!0}))),H7.default.createElement(yq,{url:W})),j&&W&&A6&&H7.default.createElement(u,{flexDirection:"column",marginTop:1},H7.default.createElement(T,{dimColor:!0},"If the redirect page shows a connection error, paste the URL from your browser's address bar:"),H7.default.createElement(u,null,H7.default.createElement(T,{dimColor:!0},"URL ",">"," "),H7.default.createElement(l4,{value:c,onChange:n,onSubmit:(G6)=>{A6(G6.trim()),n("")},cursorOffset:l,onChangeCursorOffset:z6,columns:$-8}))),H7.default.createElement(u,{marginLeft:3},H7.default.createElement(T,{dimColor:!0},"Return here after authenticating in your browser. Press"," ",H7.default.createElement(A8,{chord:"escape",action:"go back"}),".")))}if(v)return H7.default.createElement(u,{flexDirection:"column",gap:1,padding:1,tabIndex:0,autoFocus:!0,onKeyDown:H6},H7.default.createElement(T,{color:"claude"},"Authenticating with ",q.name,"…"),H7.default.createElement(u,null,H7.default.createElement(Y5,null),H7.default.createElement(T,null," A browser window will open for authentication")),k&&H7.default.createElement(u,{flexDirection:"column"},H7.default.createElement(u,null,H7.default.createElement(T,{dimColor:!0},"If your browser doesn't open automatically, copy this URL manually"," "),S?H7.default.createElement(T,{color:"success"},"(Copied!)"):H7.default.createElement(T,{dimColor:!0},H7.default.createElement(A8,{chord:"c",action:"copy",parens:!0}))),H7.default.createElement(yq,{url:k})),H7.default.createElement(u,{marginLeft:3,flexDirection:"column"},H7.default.createElement(T,{color:"permission"},"Press ",H7.default.createElement(T,{bold:!0},"Enter")," after authenticating in your browser."),H7.default.createElement(T,{dimColor:!0,italic:!0},H7.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"}))));if(R)return H7.default.createElement(u,{flexDirection:"column",gap:1,padding:1,tabIndex:0,autoFocus:!0,onKeyDown:H6},H7.default.createElement(T,{color:"claude"},"Clear authentication for ",q.name),B?H7.default.createElement(H7.default.Fragment,null,H7.default.createElement(T,null,'Find the MCP server in the browser and click "Disconnect".'),C&&H7.default.createElement(u,{flexDirection:"column"},H7.default.createElement(u,null,H7.default.createElement(T,{dimColor:!0},"If your browser didn't open automatically, copy this URL manually"," "),S?H7.default.createElement(T,{color:"success"},"(Copied!)"):H7.default.createElement(T,{dimColor:!0},H7.default.createElement(A8,{chord:"c",action:"copy",parens:!0}))),H7.default.createElement(yq,{url:C})),H7.default.createElement(u,{marginLeft:3,flexDirection:"column"},H7.default.createElement(T,{color:"permission"},"Press ",H7.default.createElement(T,{bold:!0},"Enter")," when done."),H7.default.createElement(T,{dimColor:!0,italic:!0},H7.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))):H7.default.createElement(H7.default.Fragment,null,H7.default.createElement(T,null,'This will open claude.ai in the browser. Find the MCP server in the list and click "Disconnect".'),H7.default.createElement(u,{marginLeft:3,flexDirection:"column"},H7.default.createElement(T,{color:"permission"},"Press"," ",H7.default.createElement(A8,{chord:"enter",action:"open the browser",bold:!0}),"."),H7.default.createElement(T,{dimColor:!0,italic:!0},H7.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))));if(Z)return H7.default.createElement(u,{flexDirection:"column",gap:1,padding:1},H7.default.createElement(T,{color:"text"},"Connecting to ",H7.default.createElement(T,{bold:!0},q.name),"…"),H7.default.createElement(u,null,H7.default.createElement(Y5,null),H7.default.createElement(T,null," Establishing connection to MCP server")),H7.default.createElement(T,{dimColor:!0},"This may take a few moments."));let W6=[];if(q.client.type==="disabled")W6.push({label:"Enable",value:"toggle-enabled"});if(q.client.type==="connected"&&K>0)W6.push({label:"View tools",value:"tools"});if(q.config.type==="claudeai-proxy"){if(q.client.type==="connected")W6.push({label:"Clear authentication",value:"claudeai-clear-auth"});else if(q.client.type!=="disabled")W6.push({label:"Authenticate",value:"claudeai-auth"})}else if(!q.config.headersHelper){if(i)W6.push({label:"Re-authenticate",value:"reauth"}),W6.push({label:"Clear authentication",value:"clear-auth"});if(!i)W6.push({label:"Authenticate",value:"auth"})}let V6=q.config.type!=="claudeai-proxy"&&!!q.config.headersHelper;if(q.client.type!=="disabled"){if(q.client.type!=="needs-auth"||V6)W6.push({label:"Reconnect",value:"reconnectMcpServer"});W6.push({label:"Disable",value:"toggle-enabled"})}if(W6.length===0)W6.push({label:"Back",value:"back"});return H7.default.createElement(u,{flexDirection:"column"},H7.default.createElement(u,{flexDirection:"column",paddingX:1,borderStyle:A?void 0:"round"},H7.default.createElement(u,{marginBottom:1},H7.default.createElement(T,{bold:!0},q6," MCP Server")),H7.default.createElement(u,{flexDirection:"column",gap:0},H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"Status: "),q.client.type==="disabled"?H7.default.createElement(T,null,d7("inactive",O)(e6.radioOff)," disabled"):q.client.type==="connected"?H7.default.createElement(T,null,d7("success",O)(e6.tick)," connected"):q.client.type==="pending"?H7.default.createElement(H7.default.Fragment,null,H7.default.createElement(T,{dimColor:!0},e6.radioOff),H7.default.createElement(T,null," connecting…")):q.client.type==="needs-auth"?H7.default.createElement(T,null,d7("warning",O)(e6.triangleUpOutline)," needs authentication"):H7.default.createElement(T,null,d7("error",O)(e6.cross)," failed")),q.transport!=="claudeai-proxy"&&H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"Auth: "),i?H7.default.createElement(T,null,d7("success",O)(e6.tick)," authenticated"):H7.default.createElement(T,null,d7("error",O)(e6.cross)," not authenticated")),H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"URL: "),H7.default.createElement(T,{dimColor:!0},q.config.url)),H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"Config location: "),H7.default.createElement(T,{dimColor:!0},rk(q.scope))),q.client.type==="connected"&&H7.default.createElement(Ei8,{serverToolsCount:K,serverPromptsCount:o,serverResourcesCount:M.resources[q.name]?.length||0}),q.client.type==="connected"&&K>0&&H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"Tools: "),H7.default.createElement(T,{dimColor:!0},K," tools"))),J&&H7.default.createElement(u,{marginTop:1},H7.default.createElement(T,{color:"error"},"Error: ",J)),W6.length>0&&H7.default.createElement(u,{marginTop:1},H7.default.createElement(A1,{options:W6,onChange:async(f6)=>{switch(f6){case"tools":_();break;case"auth":case"reauth":await X6();break;case"clear-auth":await M6();break;case"claudeai-auth":await r();break;case"claudeai-clear-auth":t();break;case"reconnectMcpServer":G(!0);try{let G6=await O6(q.name);if(q.config.type==="claudeai-proxy")d("tengu_claudeai_mcp_reconnect",{success:G6.client.type==="connected"});let{message:k6}=yi8(G6,q.name,{hasHeadersHelper:V6});Y?.(k6)}catch(G6){if(q.config.type==="claudeai-proxy")d("tengu_claudeai_mcp_reconnect",{success:!1});Y?.($_8(G6,q.name))}finally{G(!1)}break;case"toggle-enabled":await Y6();break;case"back":z();break}},onCancel:z}))),H7.default.createElement(u,{marginTop:1},H7.default.createElement(T,{dimColor:!0,italic:!0},w.pending?H7.default.createElement(H7.default.Fragment,null,"Press ",w.keyName," again to exit"):H7.default.createElement(z1,null,H7.default.createElement(A8,{chord:["up","down"],format:{arrowSep:""},action:"navigate"}),H7.default.createElement(A8,{chord:"enter",action:"select"}),H7.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}var H7;var Li8=L(()=>{Qq();C8();z3();C$();I4();HX();g6();C7();me();oW();B_6();iD();N7();T7();Nj();m8();U8();bK();g_();Nq();u7();Ej();NY();_w7();H7=K6(P6(),1)});function j_8({server:q,serverToolsCount:K,onViewTools:_,onCancel:z,onComplete:Y,borderless:A=!1}){let[O]=Zq(),w=$3(),$=M8((Z)=>Z.mcp),j=Nx6(),H=m_6(),[J,X]=M3.useState(!1),M=M3.default.useCallback(async()=>{let Z=q.client.type!=="disabled";try{await H(q.name),z()}catch(G){Y(`Failed to ${Z?"disable":"enable"} MCP server '${q.name}': ${b6(G)}`)}},[q.client.type,q.name,H,z,Y]),P=zv(String(q.name)),W=Cp8($.commands,q.name).length,D=[];if(q.client.type!=="disabled"&&K>0)D.push({label:"View tools",value:"tools"});if(q.client.type!=="disabled")D.push({label:"Reconnect",value:"reconnectMcpServer"});if(D.push({label:q.client.type!=="disabled"?"Disable":"Enable",value:"toggle-enabled"}),D.length===0)D.push({label:"Back",value:"back"});if(J)return M3.default.createElement(u,{flexDirection:"column",gap:1,padding:1},M3.default.createElement(T,{color:"text"},"Reconnecting to ",M3.default.createElement(T,{bold:!0},q.name)),M3.default.createElement(u,null,M3.default.createElement(Y5,null),M3.default.createElement(T,null," Restarting MCP server process")),M3.default.createElement(T,{dimColor:!0},"This may take a few moments."));return M3.default.createElement(u,{flexDirection:"column"},M3.default.createElement(u,{flexDirection:"column",paddingX:1,borderStyle:A?void 0:"round"},M3.default.createElement(u,{marginBottom:1},M3.default.createElement(T,{bold:!0},P," MCP Server")),M3.default.createElement(u,{flexDirection:"column",gap:0},M3.default.createElement(Wn,{box:"plain",columns:[{bold:!0},{}]},M3.default.createElement(Wn.Row,null,M3.default.createElement(M3.default.Fragment,null,"Status:"),q.client.type==="disabled"?M3.default.createElement(T,null,d7("inactive",O)(e6.radioOff)," disabled"):q.client.type==="connected"?M3.default.createElement(T,null,d7("success",O)(e6.tick)," connected"):q.client.type==="pending"?M3.default.createElement(T,null,M3.default.createElement(T,{dimColor:!0},e6.radioOff)," connecting…"):M3.default.createElement(T,null,d7("error",O)(e6.cross)," failed")),M3.default.createElement(Wn.Row,null,M3.default.createElement(M3.default.Fragment,null,"Command:"),M3.default.createElement(T,{dimColor:!0},q.config.command)),q.config.args&&q.config.args.length>0&&M3.default.createElement(Wn.Row,null,M3.default.createElement(M3.default.Fragment,null,"Args:"),M3.default.createElement(T,{dimColor:!0},q.config.args.join(" "))),M3.default.createElement(Wn.Row,null,M3.default.createElement(M3.default.Fragment,null,"Config location:"),M3.default.createElement(T,{dimColor:!0},rk(my(q.name)?.scope??"dynamic")))),q.client.type==="connected"&&M3.default.createElement(Ei8,{serverToolsCount:K,serverPromptsCount:W,serverResourcesCount:$.resources[q.name]?.length||0}),q.client.type==="connected"&&K>0&&M3.default.createElement(u,null,M3.default.createElement(T,{bold:!0},"Tools: "),M3.default.createElement(T,{dimColor:!0},K," tools"))),D.length>0&&M3.default.createElement(u,{marginTop:1},M3.default.createElement(A1,{options:D,onChange:async(Z)=>{if(Z==="tools")_();else if(Z==="reconnectMcpServer"){X(!0);try{let G=await j(q.name),{message:f}=yi8(G,q.name);Y?.(f)}catch(G){Y?.($_8(G,q.name))}finally{X(!1)}}else if(Z==="toggle-enabled")await M();else if(Z==="back")z()},onCancel:z}))),M3.default.createElement(u,{marginTop:1},M3.default.createElement(T,{dimColor:!0,italic:!0},w.pending?M3.default.createElement(M3.default.Fragment,null,"Press ",w.keyName," again to exit"):M3.default.createElement(z1,null,M3.default.createElement(A8,{chord:["up","down"],format:{arrowSep:""},action:"navigate"}),M3.default.createElement(A8,{chord:"enter",action:"select"}),M3.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}var M3;var hi8=L(()=>{Qq();C$();g6();rD();B_6();iD();N7();m8();bK();g_();Nq();u7();aA7();Ej();_w7();M3=K6(P6(),1)});function H_8(q){let K=s(44),{tool:_,server:z,onBack:Y}=q,[A,O]=f2.default.useState(""),w,$;if(K[0]!==z.name||K[1]!==_){$=fX8(_.name,z.name);let F=_.userFacingName?_.userFacingName({}):$;w=GX8(F),K[0]=z.name,K[1]=_,K[2]=w,K[3]=$}else w=K[2],$=K[3];let j=w,H;if(K[4]!==_)H=_.isReadOnly?.({})??!1,K[4]=_,K[5]=H;else H=K[5];let J=H,X;if(K[6]!==_)X=_.isDestructive?.({})??!1,K[6]=_,K[7]=X;else X=K[7];let M=X,P;if(K[8]!==_)P=_.isOpenWorld?.({})??!1,K[8]=_,K[9]=P;else P=K[9];let W=P,D,Z;if(K[10]!==_)D=()=>{(async function(){try{let g=await _.description({},{isNonInteractiveSession:!1,toolPermissionContext:{mode:"default",additionalWorkingDirectories:new Map,alwaysAllowRules:{},alwaysDenyRules:{},alwaysAskRules:{},isBypassPermissionsModeAvailable:!1},tools:[]});O(g)}catch{O("Failed to load description")}})()},Z=[_],K[10]=_,K[11]=D,K[12]=Z;else D=K[11],Z=K[12];f2.default.useEffect(D,Z);let G;if(K[13]!==J)G=J&&f2.default.createElement(T,{color:"success"}," [read-only]"),K[13]=J,K[14]=G;else G=K[14];let f;if(K[15]!==M)f=M&&f2.default.createElement(T,{color:"error"}," [destructive]"),K[15]=M,K[16]=f;else f=K[16];let v;if(K[17]!==W)v=W&&f2.default.createElement(T,{dimColor:!0}," [open-world]"),K[17]=W,K[18]=v;else v=K[18];let V;if(K[19]!==j||K[20]!==G||K[21]!==f||K[22]!==v)V=f2.default.createElement(f2.default.Fragment,null,j,G,f,v),K[19]=j,K[20]=G,K[21]=f,K[22]=v,K[23]=V;else V=K[23];let k=V,N;if(K[24]===Symbol.for("react.memo_cache_sentinel"))N=f2.default.createElement(T,{bold:!0},"Tool name: "),K[24]=N;else N=K[24];let R;if(K[25]!==$)R=f2.default.createElement(u,null,N,f2.default.createElement(T,{dimColor:!0},$)),K[25]=$,K[26]=R;else R=K[26];let h;if(K[27]===Symbol.for("react.memo_cache_sentinel"))h=f2.default.createElement(T,{bold:!0},"Full name: "),K[27]=h;else h=K[27];let C;if(K[28]!==_.name)C=f2.default.createElement(u,null,h,f2.default.createElement(T,{dimColor:!0},_.name)),K[28]=_.name,K[29]=C;else C=K[29];let x;if(K[30]!==A)x=A&&f2.default.createElement(u,{flexDirection:"column",marginTop:1},f2.default.createElement(T,{bold:!0},"Description:"),f2.default.createElement(T,{wrap:"wrap"},A)),K[30]=A,K[31]=x;else x=K[31];let B;if(K[32]!==_.inputJSONSchema)B=_.inputJSONSchema&&_.inputJSONSchema.properties&&Object.keys(_.inputJSONSchema.properties).length>0&&f2.default.createElement(u,{flexDirection:"column",marginTop:1},f2.default.createElement(T,{bold:!0},"Parameters:"),f2.default.createElement(u,{marginLeft:2,flexDirection:"column"},Object.entries(_.inputJSONSchema.properties).map((F)=>{let[U,g]=F,n=_.inputJSONSchema?.required?.includes(U);return f2.default.createElement(T,{key:U},"• ",U,f2.default.createElement(CP6,{when:n??!1},"required"),":"," ",f2.default.createElement(T,{dimColor:!0},typeof g==="object"&&g&&"type"in g?String(g.type):"unknown"),typeof g==="object"&&g&&"description"in g&&f2.default.createElement(T,{dimColor:!0}," - ",String(g.description)))}))),K[32]=_.inputJSONSchema,K[33]=B;else B=K[33];let m;if(K[34]!==R||K[35]!==C||K[36]!==x||K[37]!==B)m=f2.default.createElement(u,{flexDirection:"column"},R,C,x,B),K[34]=R,K[35]=C,K[36]=x,K[37]=B,K[38]=m;else m=K[38];let S;if(K[39]!==Y||K[40]!==z.name||K[41]!==m||K[42]!==k)S=f2.default.createElement(R1,{title:k,subtitle:z.name,onCancel:Y,inputGuide:yIY},m),K[39]=Y,K[40]=z.name,K[41]=m,K[42]=k,K[43]=S;else S=K[43];return S}function yIY(q){return q.pending?f2.default.createElement(T,null,"Press ",q.keyName," again to exit"):f2.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"})}var f2;var Ri8=L(()=>{o6();g6();fh();bK();Xi8();S4();f2=K6(P6(),1)});function J_8(q){let K=s(21),{server:_,onSelectTool:z,onBack:Y}=q,A=M8(hIY),O;q:{if(_.client.type!=="connected"){let Z;if(K[0]===Symbol.for("react.memo_cache_sentinel"))Z=[],K[0]=Z;else Z=K[0];O=Z;break q}let D;if(K[1]!==A||K[2]!==_.name)D=Ll(A,_.name),K[1]=A,K[2]=_.name,K[3]=D;else D=K[3];O=D}let w=O,$;if(K[4]!==_.name||K[5]!==w){let D;if(K[7]!==_.name)D=(Z,G)=>{let f=fX8(Z.name,_.name),v=Z.userFacingName?Z.userFacingName({}):f,V=GX8(v),k=Z.isReadOnly?.({})??!1,N=Z.isDestructive?.({})??!1,R=Z.isOpenWorld?.({})??!1,h=[];if(k)h.push("read-only");if(N)h.push("destructive");if(R)h.push("open-world");return{label:V,value:G.toString(),description:h.length>0?h.join(", "):void 0,descriptionColor:N?"error":k?"success":void 0}},K[7]=_.name,K[8]=D;else D=K[8];$=w.map(D),K[4]=_.name,K[5]=w,K[6]=$}else $=K[6];let j=$,H=`Tools for ${_.name}`,J=w.length,X;if(K[9]!==w.length)X=O7(w.length,"tool"),K[9]=w.length,K[10]=X;else X=K[10];let M=`${J} ${X}`,P;if(K[11]!==Y||K[12]!==z||K[13]!==w||K[14]!==j)P=w.length===0?ne.default.createElement(T,{dimColor:!0},"No tools available"):ne.default.createElement(A1,{options:j,onChange:(D)=>{let Z=parseInt(D),G=w[Z];if(G)z(G,Z)},onCancel:Y}),K[11]=Y,K[12]=z,K[13]=w,K[14]=j,K[15]=P;else P=K[15];let W;if(K[16]!==Y||K[17]!==H||K[18]!==M||K[19]!==P)W=ne.default.createElement(R1,{title:H,subtitle:M,onCancel:Y,inputGuide:LIY},P),K[16]=Y,K[17]=H,K[18]=M,K[19]=P,K[20]=W;else W=K[20];return W}function LIY(q){return q.pending?ne.default.createElement(T,null,"Press ",q.keyName," again to exit"):ne.default.createElement(z1,null,ne.default.createElement(A8,{chord:["up","down"],format:{arrowSep:""},action:"navigate"}),ne.default.createElement(A8,{chord:"enter",action:"select"}),ne.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"}))}function hIY(q){return q.mcp.tools}var ne;var Si8=L(()=>{o6();g6();fh();iD();N7();bK();g_();Nq();S4();u7();ne=K6(P6(),1)});function Ci8(q){let K=s(66),{onComplete:_}=q,z=M8(bIY),Y=M8(CIY),A=z.clients,O;if(K[0]===Symbol.for("react.memo_cache_sentinel"))O={type:"list"},K[0]=O;else O=K[0];let[w,$]=Nu.default.useState(O),j;if(K[1]===Symbol.for("react.memo_cache_sentinel"))j=[],K[1]=j;else j=K[1];let[H,J]=Nu.default.useState(j),X;if(K[2]!==Y.allAgents)X=D_K(Y.allAgents),K[2]=Y.allAgents,K[3]=X;else X=K[3];let M=X,P;if(K[4]!==A)P=A.filter(SIY).sort(RIY),K[4]=A,K[5]=P;else P=K[5];let W=P,D,Z;if(K[6]!==W||K[7]!==z.tools)D=()=>{let v=!1;return async function(){let N=await Promise.all(W.map(async(R)=>{let h=R.config.scope,C=R.config.type==="sse",x=R.config.type==="http",B=R.config.type==="claudeai-proxy",m=void 0;if(C||x){let U=await new jP6(R.name,R.config).tokens(),g=qW()!==null&&R.type==="connected",c=R.type==="connected"&&Ll(z.tools,R.name).length>0;m=Boolean(U)||g||c}let S={name:R.name,client:R,scope:h};if(B)return{...S,transport:"claudeai-proxy",isAuthenticated:!1,config:R.config};else if(C)return{...S,transport:"sse",isAuthenticated:m,config:R.config};else if(x)return{...S,transport:"http",isAuthenticated:m,config:R.config};else return{...S,transport:"stdio",config:R.config}}));if(v)return;J(N)}(),()=>{v=!0}},Z=[W,z.tools],K[6]=W,K[7]=z.tools,K[8]=D,K[9]=Z;else D=K[8],Z=K[9];Nu.default.useEffect(D,Z);let G,f;if(K[10]!==M.length||K[11]!==W.length||K[12]!==_||K[13]!==H.length)G=()=>{if(H.length===0&&W.length>0)return;if(H.length===0&&M.length===0)_("No MCP servers configured. Please run /doctor if this is unexpected. Otherwise, run `claude mcp --help` or visit https://code.claude.com/docs/en/mcp to learn more.")},f=[H.length,W.length,M.length,_],K[10]=M.length,K[11]=W.length,K[12]=_,K[13]=H.length,K[14]=G,K[15]=f;else G=K[14],f=K[15];switch(Nu.useEffect(G,f),w.type){case"list":{let v,V;if(K[16]===Symbol.for("react.memo_cache_sentinel"))V=(N)=>$({type:"server-menu",server:N}),v=(N)=>$({type:"agent-server-menu",agentServer:N}),K[16]=v,K[17]=V;else v=K[16],V=K[17];let k;if(K[18]!==M||K[19]!==_||K[20]!==H||K[21]!==w.defaultTab)k=Nu.default.createElement(nO7,{servers:H,agentServers:M,onSelectServer:V,onSelectAgentServer:v,onComplete:_,defaultTab:w.defaultTab}),K[18]=M,K[19]=_,K[20]=H,K[21]=w.defaultTab,K[22]=k;else k=K[22];return k}case"server-menu":{let v;if(K[23]!==z.tools||K[24]!==w.server.name)v=Ll(z.tools,w.server.name),K[23]=z.tools,K[24]=w.server.name,K[25]=v;else v=K[25];let V=v,k=w.server.transport==="claudeai-proxy"?"claude.ai":"Claude Code";if(w.server.transport==="stdio"){let N;if(K[26]!==w.server)N=()=>$({type:"server-tools",server:w.server}),K[26]=w.server,K[27]=N;else N=K[27];let R;if(K[28]!==k)R=()=>$({type:"list",defaultTab:k}),K[28]=k,K[29]=R;else R=K[29];let h;if(K[30]!==_||K[31]!==V.length||K[32]!==N||K[33]!==R||K[34]!==w.server)h=Nu.default.createElement(j_8,{server:w.server,serverToolsCount:V.length,onViewTools:N,onCancel:R,onComplete:_}),K[30]=_,K[31]=V.length,K[32]=N,K[33]=R,K[34]=w.server,K[35]=h;else h=K[35];return h}else{let N;if(K[36]!==w.server)N=()=>$({type:"server-tools",server:w.server}),K[36]=w.server,K[37]=N;else N=K[37];let R;if(K[38]!==k)R=()=>$({type:"list",defaultTab:k}),K[38]=k,K[39]=R;else R=K[39];let h;if(K[40]!==_||K[41]!==V.length||K[42]!==N||K[43]!==R||K[44]!==w.server)h=Nu.default.createElement(FP6,{server:w.server,serverToolsCount:V.length,onViewTools:N,onCancel:R,onComplete:_}),K[40]=_,K[41]=V.length,K[42]=N,K[43]=R,K[44]=w.server,K[45]=h;else h=K[45];return h}}case"server-tools":{let v,V;if(K[46]!==w.server)V=(N,R)=>$({type:"server-tool-detail",server:w.server,toolIndex:R}),v=()=>$({type:"server-menu",server:w.server}),K[46]=w.server,K[47]=v,K[48]=V;else v=K[47],V=K[48];let k;if(K[49]!==v||K[50]!==V||K[51]!==w.server)k=Nu.default.createElement(J_8,{server:w.server,onSelectTool:V,onBack:v}),K[49]=v,K[50]=V,K[51]=w.server,K[52]=k;else k=K[52];return k}case"server-tool-detail":{let v;if(K[53]!==z.tools||K[54]!==w.server.name)v=Ll(z.tools,w.server.name),K[53]=z.tools,K[54]=w.server.name,K[55]=v;else v=K[55];let k=v[w.toolIndex];if(!k)return $({type:"server-tools",server:w.server}),null;let N;if(K[56]!==w.server)N=()=>$({type:"server-tools",server:w.server}),K[56]=w.server,K[57]=N;else N=K[57];let R;if(K[58]!==N||K[59]!==k||K[60]!==w.server)R=Nu.default.createElement(H_8,{tool:k,server:w.server,onBack:N}),K[58]=N,K[59]=k,K[60]=w.server,K[61]=R;else R=K[61];return R}case"agent-server-menu":{let v;if(K[62]===Symbol.for("react.memo_cache_sentinel"))v=()=>$({type:"list",defaultTab:"Agents"}),K[62]=v;else v=K[62];let V;if(K[63]!==_||K[64]!==w.agentServer)V=Nu.default.createElement(cO7,{agentServer:w.agentServer,onCancel:v,onComplete:_}),K[63]=_,K[64]=w.agentServer,K[65]=V;else V=K[65];return V}}}function RIY(q,K){return q.name.localeCompare(K.name)}function SIY(q){return q.name!=="ide"}function CIY(q){return q.agentDefinitions}function bIY(q){return q.mcp}var Nu;var ppK=L(()=>{o6();me();iD();N7();ox();lO7();iO7();Li8();hi8();Ri8();Si8();Nu=K6(P6(),1)});var FpK=L(()=>{lO7();iO7();Kw7();Li8();ppK();hi8();Ri8();Si8()});var UpK={};h8(UpK,{settingSourceToScope:()=>mIY,isPersistableScope:()=>uIY,installSelectedPlugins:()=>pIY,getPluginEditableScopes:()=>p_6,getInstalledPlugins:()=>gpK,findMissingPlugins:()=>BIY,checkEnabledPlugins:()=>xIY});import{join as IIY}from"path";async function xIY(){let q=v7(),K=[],_=ej6();for(let[z,Y]of Object.entries(_))if(z.includes("@")&&Y)K.push(z);if(q.enabledPlugins)for(let[z,Y]of Object.entries(q.enabledPlugins)){if(!z.includes("@"))continue;let A=K.indexOf(z);if(Y){if(A===-1)K.push(z)}else if(A!==-1)K.splice(A,1)}return K}function p_6(){let q=new Map,K=ej6();for(let[z,Y]of Object.entries(K)){if(!z.includes("@"))continue;if(Y===!0)q.set(z,"flag");else if(Y===!1)q.delete(z)}let _=[{scope:"managed",source:"policySettings"},{scope:"user",source:"userSettings"},{scope:"project",source:"projectSettings"},{scope:"local",source:"localSettings"},{scope:"flag",source:"flagSettings"}];for(let{scope:z,source:Y}of _){let A=E1(Y);if(!A?.enabledPlugins)continue;for(let[O,w]of Object.entries(A.enabledPlugins)){if(!O.includes("@"))continue;if(O in K&&K[O]!==w)E(`Plugin ${O} from --add-dir (${K[O]}) overridden by ${Y} (${w})`);if(w===!0)q.set(O,z);else if(w===!1)q.delete(O)}}return E(`Found ${q.size} enabled plugins with scopes: ${Array.from(q.entries()).map(([z,Y])=>`${z}(${Y})`).join(", ")}`),q}function uIY(q){return q!=="flag"}function mIY(q){return ZQ1[q]}async function gpK(){w_7().catch((_)=>{j6(_)});let q=N68(),K=Object.keys(q.plugins);return E(`Found ${K.length} installed plugins`),K}async function BIY(q){try{let K=await gpK(),_=q.filter((A)=>!K.includes(A));return(await Promise.all(_.map(async(A)=>{try{let O=await mf(A);return{pluginId:A,found:O!==null&&O!==void 0}}catch(O){return E(`Failed to check plugin ${A} in marketplace: ${O}`),{pluginId:A,found:!1}}}))).filter(({found:A})=>A).map(({pluginId:A})=>A)}catch(K){return j6(K),[]}}async function pIY(q,K,_="user"){let z=_!=="user"?b8():void 0,Y=jc(_),A=E1(Y),O={...A?.enabledPlugins},w=[],$=[];for(let j=0;j<q.length;j++){let H=q[j];if(!H)continue;if(K)K(H,j+1,q.length);try{let J=await mf(H);if(!J){$.push({name:H,error:"Plugin not found in any marketplace"});continue}let{entry:X,marketplaceInstallLocation:M}=J;if(!uQ6(X.source))await Z68(H,X,_,z);else WG4({pluginId:H,installPath:IIY(M,X.source),version:X.version},_,z);O[H]=!0,w.push(H)}catch(J){let X=J instanceof Error?J.message:String(J);$.push({name:H,error:X}),j6(J)}}return P7(Y,{...A,enabledPlugins:O}),{installed:w,failed:$}}var X_8=L(()=>{n7();K8();U8();a1();WS8();yD();m$();aW();Y56();Hv()});import{homedir as FIY}from"os";import{resolve as gIY}from"path";async function bi8(q){let K=q.trim(),_=V8(),z=K.match(/^([a-zA-Z0-9._-]+@[^:]+:.+?(?:\.git)?)(#(.+))?$/);if(z?.[1]){let O=z[1],w=z[3];return w?{source:"git",url:O,ref:w}:{source:"git",url:O}}if(K.startsWith("http://")||K.startsWith("https://")){let O=K.match(/^([^#]+)(#(.+))?$/),w=O?.[1]||K,$=O?.[3];if(w.endsWith(".git")||w.includes("/_git/"))return $?{source:"git",url:w,ref:$}:{source:"git",url:w};let j;try{j=new URL(w)}catch(H){return{source:"url",url:w}}if(j.hostname==="github.com"||j.hostname==="www.github.com"){if(j.pathname.match(/^\/([^/]+\/[^/]+?)(\/|\.git|$)/)?.[1]){let J=w.endsWith(".git")?w:`${w}.git`;return $?{source:"git",url:J,ref:$}:{source:"git",url:J}}}return{source:"url",url:w}}let A=process.platform==="win32"&&(K.startsWith(".\\")||K.startsWith("..\\")||/^[a-zA-Z]:[/\\]/.test(K));if(K.startsWith("./")||K.startsWith("../")||K.startsWith("/")||K.startsWith("~")||A){let O=gIY(K.startsWith("~")?K.replace(/^~/,FIY()):K),w;try{w=await _.stat(O)}catch($){let j=Q1($);return{error:j==="ENOENT"?`Path does not exist: ${O}`:`Cannot access path: ${O} (${j??$})`}}if(w.isFile())if(O.endsWith(".json"))return{source:"file",path:O};else return{error:`File path must point to a .json file (marketplace.json), but got: ${O}`};else if(w.isDirectory())return{source:"directory",path:O};else return{error:`Path is neither a file nor a directory: ${O}`}}if(K.includes("/")&&!K.startsWith("@")){if(K.includes(":"))return null;let O=K.match(/^([^#@]+)(?:[#@](.+))?$/),w=O?.[1]||K,$=O?.[2];return $?{source:"github",repo:w,ref:$}:{source:"github",repo:w}}return null}var zw7=L(()=>{m8();Yq()});function QpK({inputValue:q,setInputValue:K,cursorOffset:_,setCursorOffset:z,error:Y,setError:A,result:O,setResult:w,setViewState:$,onAddComplete:j,cliMode:H=!1}){let J=gP6.useRef(!1),[X,M]=gP6.useState(!1),[P,W]=gP6.useState(""),D=async()=>{let Z=q.trim();if(!Z){A("Please enter a marketplace source");return}let G=await bi8(Z);if(!G){A("Invalid marketplace source format. Try: owner/repo, https://..., or ./path");return}if("error"in G){A(G.error);return}A(null);try{M(!0),W("");let{name:f,resolvedSource:v}=await M_6(G,(k)=>{W(k)});h38(f,{source:v}),YO();let V=G.source;if(G.source==="github")V=G.repo;if(d("tengu_marketplace_added",{source_type:V}),j)await j();if(W(""),M(!1),H)w(`Successfully added marketplace: ${f}`);else $({type:"browse-marketplace",targetMarketplace:f})}catch(f){let v=r1(f);if(j6(v),A(v.message),W(""),M(!1),H)w(`Error: ${v.message}`);else w(null)}};return gP6.useEffect(()=>{if(q&&!J.current&&!Y&&!O)J.current=!0,D()},[]),P3.createElement(u,{flexDirection:"column"},P3.createElement(u,{flexDirection:"column",paddingX:1,borderStyle:"round"},P3.createElement(u,{marginBottom:1},P3.createElement(T,{bold:!0},"Add Marketplace")),P3.createElement(u,{flexDirection:"column"},P3.createElement(T,null,"Enter marketplace source:"),P3.createElement(T,{dimColor:!0},"Examples:"),P3.createElement(T,{dimColor:!0}," · owner/repo (GitHub)"),P3.createElement(T,{dimColor:!0}," · git@github.com:owner/repo.git (SSH)"),P3.createElement(T,{dimColor:!0}," · https://example.com/marketplace.json"),P3.createElement(T,{dimColor:!0}," · ./path/to/marketplace"),P3.createElement(u,{marginTop:1},P3.createElement(l4,{value:q,onChange:K,onSubmit:D,columns:80,cursorOffset:_,onChangeCursorOffset:z,focus:!0,showCursor:!0}))),X&&P3.createElement(u,{marginTop:1},P3.createElement(Y5,null),P3.createElement(T,null,P||"Adding marketplace to configuration…")),Y&&P3.createElement(u,{marginTop:1},P3.createElement(T,{color:"error"},Y)),O&&P3.createElement(u,{marginTop:1},P3.createElement(T,null,O))),P3.createElement(u,{marginLeft:3},P3.createElement(T,{dimColor:!0,italic:!0},P3.createElement(z1,null,P3.createElement(A8,{chord:"enter",action:"add"}),P3.createElement(v1,{action:"confirm:no",context:"Settings",fallback:"Esc",description:"cancel"})))))}var P3,gP6;var dpK=L(()=>{C8();bK();Nq();u7();Ej();NY();g6();m8();U8();uR();m$();zw7();P3=K6(P6(),1),gP6=K6(P6(),1)});import{randomBytes as UIY}from"crypto";import{readFile as QIY,rename as dIY,unlink as cIY,writeFile as lIY}from"fs/promises";import{join as nIY}from"path";function cpK(){return nIY(gP(),iIY)}async function oIY(){let q=cpK();try{let K=await QIY(q,{encoding:"utf-8"}),_=n8(K);if(typeof _!=="object"||_===null||!("version"in _)||!("fetchedAt"in _)||!("counts"in _))return E("Install counts cache has invalid structure"),null;let z=_;if(z.version!==Yw7)return E(`Install counts cache version mismatch (got ${z.version}, expected ${Yw7})`),null;if(typeof z.fetchedAt!=="string"||!Array.isArray(z.counts))return E("Install counts cache has invalid structure"),null;let Y=new Date(z.fetchedAt).getTime();if(Number.isNaN(Y))return E("Install counts cache has invalid fetchedAt timestamp"),null;if(!z.counts.every((w)=>typeof w==="object"&&w!==null&&typeof w.plugin==="string"&&typeof w.unique_installs==="number"))return E("Install counts cache has malformed entries"),null;if(Date.now()-Y>rIY)return E("Install counts cache is stale (>24h old)"),null;return{version:z.version,fetchedAt:z.fetchedAt,counts:z.counts}}catch(K){if(Q1(K)!=="ENOENT")E(`Failed to load install counts cache: ${b6(K)}`);return null}}async function aIY(q){let K=cpK(),_=`${K}.${UIY(8).toString("hex")}.tmp`;try{let z=gP();await V8().mkdir(z);let Y=I6(q,null,2);await lIY(_,Y,{encoding:"utf-8",mode:384}),await dIY(_,K),E("Install counts cache saved successfully")}catch(z){j6(z);try{await cIY(_)}catch{}}}async function sIY(){E(`Fetching install counts from ${M_8}`);let q=performance.now();try{let K=await Z1.get(M_8,{timeout:1e4});if(!K.data?.plugins||!Array.isArray(K.data.plugins))throw Error("Invalid response format from install counts API");return ED("install_counts",M_8,"success",performance.now()-q),K.data.plugins}catch(K){throw ED("install_counts",M_8,"failure",performance.now()-q,Kx(K)),K}}async function Ex6(){let q=await oIY();if(q){E("Using cached install counts"),ED("install_counts",M_8,"cache_hit",0);let K=new Map;for(let _ of q.counts)K.set(_.plugin,_.unique_installs);return K}try{let K=await sIY(),_={version:Yw7,fetchedAt:new Date().toISOString(),counts:K};await aIY(_);let z=new Map;for(let Y of K)z.set(Y.plugin,Y.unique_installs);return z}catch(K){return j6(K),E(`Failed to fetch install counts: ${b6(K)}`),null}}function Ii8(q){if(q<1000)return String(q);if(q<1e6){let Y=(q/1000).toFixed(1);return Y.endsWith(".0")?`${Y.slice(0,-2)}K`:`${Y}K`}let _=(q/1e6).toFixed(1);return _.endsWith(".0")?`${_.slice(0,-2)}M`:`${_}M`}var Yw7=1,iIY="install-counts-cache.json",M_8="https://raw.githubusercontent.com/anthropics/claude-plugins-official/refs/heads/stats/stats/plugin-installs.json",rIY=86400000;var xi8=L(()=>{CK();K8();m8();Yq();U8();e8();Y68();Jy()});function tIY(q,K,_,z){let Y={};for(let A of q){let O=_[A],w=K[A]??"";if(O?.sensitive===!0&&w===""&&z?.[A]!==void 0)continue;if(O?.type==="number"){if(w.trim()==="")continue;let $=Number(w);Y[A]=Number.isNaN($)?w:$}else if(O?.type==="boolean")Y[A]=S6(w);else Y[A]=w}return Y}function P_8(q){let K=s(70),{title:_,subtitle:z,configSchema:Y,initialValues:A,onSave:O,onCancel:w}=q,$;if(K[0]!==Y)$=Object.keys(Y),K[0]=Y,K[1]=$;else $=K[1];let j=$,H;if(K[2]!==Y||K[3]!==A)H=(Y6)=>{if(Y[Y6]?.sensitive===!0)return"";let X6=A?.[Y6];return X6===void 0?"":String(X6)},K[2]=Y,K[3]=A,K[4]=H;else H=K[4];let J=H,[X,M]=$Z.useState(0),P;if(K[5]===Symbol.for("react.memo_cache_sentinel"))P={},K[5]=P;else P=K[5];let[W,D]=$Z.useState(P),Z;if(K[6]!==j[0]||K[7]!==J)Z=()=>j[0]?J(j[0]):"",K[6]=j[0],K[7]=J,K[8]=Z;else Z=K[8];let[G,f]=$Z.useState(Z),v=j[X],V=v?Y[v]:null,k;if(K[9]===Symbol.for("react.memo_cache_sentinel"))k={context:"Settings"},K[9]=k;else k=K[9];G1("confirm:no",w,k);let N;if(K[10]!==v||K[11]!==X||K[12]!==G||K[13]!==j||K[14]!==J)N=()=>{if(X<j.length-1&&v){D((X6)=>({...X6,[v]:G})),M(KxY);let Y6=j[X+1];f(Y6?J(Y6):"")}},K[10]=v,K[11]=X,K[12]=G,K[13]=j,K[14]=J,K[15]=N;else N=K[15];let R=N,h;if(K[16]!==Y||K[17]!==v||K[18]!==X||K[19]!==G||K[20]!==j||K[21]!==J||K[22]!==A||K[23]!==O||K[24]!==W)h=()=>{if(!v)return;let Y6={...W,[v]:G};if(X===j.length-1)O(tIY(j,Y6,Y,A));else{D(Y6),M(qxY);let X6=j[X+1];f(X6?J(X6):"")}},K[16]=Y,K[17]=v,K[18]=X,K[19]=G,K[20]=j,K[21]=J,K[22]=A,K[23]=O,K[24]=W,K[25]=h;else h=K[25];let C=h,x;if(K[26]!==C||K[27]!==R)x=function(X6){if(X6.key==="return"){X6.preventDefault(),C();return}if(X6.key==="tab"){X6.preventDefault(),R();return}if(X6.key==="backspace"||X6.key==="delete"){X6.preventDefault(),f(eIY);return}if(X6.ctrl||X6.meta)return;if(X6.key.length===1)X6.preventDefault(),f((M6)=>M6+X6.key)},K[26]=C,K[27]=R,K[28]=x;else x=K[28];let B=x,m;if(K[29]===Symbol.for("react.memo_cache_sentinel"))m=function(X6){X6.preventDefault(),f((M6)=>M6+(X6.text.split(/\r\n|\r|\n/,2)[0]??"").trim())},K[29]=m;else m=K[29];let S=m;if(!V||!v)return null;let F=V.sensitive===!0,U=V.required===!0,g;if(K[30]!==G||K[31]!==F)g=F?"*".repeat(N1(G)):G,K[30]=G,K[31]=F,K[32]=g;else g=K[32];let c=g,n=V.title||v,l;if(K[33]!==U)l=U&&$Z.default.createElement(T,{color:"error"}," *"),K[33]=U,K[34]=l;else l=K[34];let z6;if(K[35]!==n||K[36]!==l)z6=$Z.default.createElement(T,{bold:!0},n,l),K[35]=n,K[36]=l,K[37]=z6;else z6=K[37];let A6;if(K[38]!==V.description)A6=V.description&&$Z.default.createElement(T,{dimColor:!0},V.description),K[38]=V.description,K[39]=A6;else A6=K[39];let e;if(K[40]===Symbol.for("react.memo_cache_sentinel"))e=$Z.default.createElement(T,null,e6.pointerSmall," "),K[40]=e;else e=K[40];let i;if(K[41]!==c)i=$Z.default.createElement(T,null,c),K[41]=c,K[42]=i;else i=K[42];let O6;if(K[43]===Symbol.for("react.memo_cache_sentinel"))O6=$Z.default.createElement(T,null,"█"),K[43]=O6;else O6=K[43];let J6;if(K[44]!==i)J6=$Z.default.createElement(u,{marginTop:1},e,i,O6),K[44]=i,K[45]=J6;else J6=K[45];let $6;if(K[46]!==B||K[47]!==z6||K[48]!==A6||K[49]!==J6)$6=$Z.default.createElement(u,{flexDirection:"column",tabIndex:0,autoFocus:!0,onKeyDown:B,onPaste:S},z6,A6,J6),K[46]=B,K[47]=z6,K[48]=A6,K[49]=J6,K[50]=$6;else $6=K[50];let H6=X+1,q6;if(K[51]!==j.length||K[52]!==H6)q6=$Z.default.createElement(T,{dimColor:!0},"Field ",H6," of ",j.length),K[51]=j.length,K[52]=H6,K[53]=q6;else q6=K[53];let o;if(K[54]!==X||K[55]!==j.length)o=X<j.length-1&&$Z.default.createElement(T,{dimColor:!0},"Tab: Next field · Enter: Save and continue"),K[54]=X,K[55]=j.length,K[56]=o;else o=K[56];let _6;if(K[57]!==X||K[58]!==j.length)_6=X===j.length-1&&$Z.default.createElement(T,{dimColor:!0},"Enter: Save configuration"),K[57]=X,K[58]=j.length,K[59]=_6;else _6=K[59];let r;if(K[60]!==q6||K[61]!==o||K[62]!==_6)r=$Z.default.createElement(u,{flexDirection:"column"},q6,o,_6),K[60]=q6,K[61]=o,K[62]=_6,K[63]=r;else r=K[63];let t;if(K[64]!==w||K[65]!==z||K[66]!==$6||K[67]!==r||K[68]!==_)t=$Z.default.createElement(R1,{title:_,subtitle:z,onCancel:w,isCancelActive:!1},$6,r),K[64]=w,K[65]=z,K[66]=$6,K[67]=r,K[68]=_,K[69]=t;else t=K[69];return t}function eIY(q){return q.slice(0,-1)}function qxY(q){return q+1}function KxY(q){return q+1}var $Z;var Aw7=L(()=>{o6();Qq();S4();n5();g6();C7();Q8();$Z=K6(P6(),1)});async function ui8(q){let{enabled:K,disabled:_}=await sW();return[...K,..._].find((z)=>z.repository===q||z.source===q)}function yx6({plugin:q,pluginId:K,onDone:_}){let[z]=kn.useState(()=>{let j=[],H=Ch4(q);if(Object.keys(H).length>0)j.push({key:"top-level",title:`Configure ${q.name}`,subtitle:"Plugin options",schema:H,load:()=>ID(K),save:(X)=>Tb8(K,X,q.manifest.userConfig)});let J=H_K(q);for(let X of J)j.push({key:`channel:${X.server}`,title:`Configure ${X.displayName}`,subtitle:`Plugin: ${q.name}`,schema:X.configSchema,load:()=>IH6(K,X.server)??void 0,save:(M)=>Gb8(K,X.server,M,X.configSchema)});return j}),[Y,A]=kn.useState(0),O=kn.useRef(_);if(O.current=_,kn.useEffect(()=>{if(z.length===0)O.current("skipped")},[z.length]),z.length===0)return null;let w=z[Y];function $(j){try{w.save(j)}catch(J){_("error",b6(J));return}let H=Y+1;if(H<z.length)A(H);else _("configured")}return kn.createElement(P_8,{key:w.key,title:w.title,subtitle:w.subtitle,configSchema:w.schema,initialValues:w.load(),onSave:$,onCancel:()=>_("skipped")})}var kn;var mi8=L(()=>{m8();W88();WX6();vH();Gx();Aw7();kn=K6(P6(),1)});function Bi8(){let q=s(3),K;if(q[0]===Symbol.for("react.memo_cache_sentinel"))K=Wf4(),q[0]=K;else K=q[0];let _=K,z;if(q[1]===Symbol.for("react.memo_cache_sentinel"))z=UP6.createElement(T,{color:"claude"},e6.warning," "),q[1]=z;else z=q[1];let Y;if(q[2]===Symbol.for("react.memo_cache_sentinel"))Y=UP6.createElement(u,{marginBottom:1},z,UP6.createElement(T,{dimColor:!0,italic:!0},"Make sure you trust a plugin before installing, updating, or using it. Anthropic does not control what MCP servers, files, or other software are included in plugins and cannot verify that they will work as intended or that they won't change. See each plugin's homepage for more information.",_?` ${_}`:"")),q[2]=Y;else Y=q[2];return Y}var UP6;var Ow7=L(()=>{o6();Qq();g6();Xc();UP6=K6(P6(),1)});function F_6(q){if(q.entry.source&&typeof q.entry.source==="object"&&"source"in q.entry.source&&q.entry.source.source==="github"&&typeof q.entry.source==="object"&&"repo"in q.entry.source)return q.entry.source.repo;return null}function Lx6(q,K){let _=[{label:"Install for you (user scope)",action:"install-user"},{label:"Install for all collaborators on this repository (project scope)",action:"install-project"},{label:"Install for you, in this repo only (local scope)",action:"install-local"}];if(q)_.push({label:"Open homepage",action:"homepage"});if(K)_.push({label:"View on GitHub",action:"github"});return _.push({label:"Back to plugin list",action:"back"}),_}function lpK(q){let K=s(7),{hasSelection:_}=q,z;if(K[0]!==_)z=_&&ON.createElement(v1,{action:"plugin:install",context:"Plugin",fallback:"i",description:"install",bold:!0}),K[0]=_,K[1]=z;else z=K[1];let Y,A,O;if(K[2]===Symbol.for("react.memo_cache_sentinel"))Y=ON.createElement(v1,{action:"plugin:toggle",context:"Plugin",fallback:"Space",description:"toggle"}),A=ON.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"details"}),O=ON.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"}),K[2]=Y,K[3]=A,K[4]=O;else Y=K[2],A=K[3],O=K[4];let w;if(K[5]!==z)w=ON.createElement(u,{marginTop:1},ON.createElement(T,{dimColor:!0,italic:!0},ON.createElement(z1,null,z,Y,A,O))),K[5]=z,K[6]=w;else w=K[6];return w}var ON;var ww7=L(()=>{o6();bK();Nq();g6();ON=K6(P6(),1)});function QP6({totalItems:q,maxVisible:K=_xY,selectedIndex:_=0}){let z=q>K,Y=mS.useRef(0),A=mS.useMemo(()=>{if(!z)return 0;let G=Y.current;if(_<G)return Y.current=_,_;if(_>=G+K){let V=_-K+1;return Y.current=V,V}let f=Math.max(0,q-K),v=Math.min(G,f);return Y.current=v,v},[_,K,z,q]),O=A,w=Math.min(A+K,q),$=mS.useCallback((G)=>{if(!z)return G;return G.slice(O,w)},[z,O,w]),j=mS.useCallback((G)=>{return O+G},[O]),H=mS.useCallback((G)=>{return G>=O&&G<w},[O,w]),J=mS.useCallback((G)=>{},[]),X=mS.useCallback(()=>{},[]),M=mS.useCallback(()=>{},[]),P=mS.useCallback((G,f)=>{let v=Math.max(0,Math.min(G,q-1));f(v)},[q]),W=mS.useCallback((G,f)=>{return!1},[]),D=Math.max(1,Math.ceil(q/K));return{currentPage:Math.floor(A/K),totalPages:D,startIndex:O,endIndex:w,needsPagination:z,pageSize:K,getVisibleItems:$,toActualIndex:j,isOnCurrentPage:H,goToPage:J,nextPage:X,prevPage:M,handleSelectionChange:P,handlePageNavigation:W,scrollPosition:{current:_+1,total:q,canScrollUp:A>0,canScrollDown:A+K<q}}}var mS,_xY=5;var W_8=L(()=>{mS=K6(P6(),1)});function npK({error:q,setError:K,result:_,setResult:z,setViewState:Y,onInstallComplete:A,targetMarketplace:O,targetPlugin:w}){let[$,j]=G0.useState("marketplace-list"),[H,J]=G0.useState(null),[X,M]=G0.useState(null),[P,W]=G0.useState([]),[D,Z]=G0.useState([]),[G,f]=G0.useState(!0),[v,V]=G0.useState(null),[k,N]=G0.useState(0),[R,h]=G0.useState(new Set),[C,x]=G0.useState(new Set),B=QP6({totalItems:D.length,selectedIndex:k}),[m,S]=G0.useState(0),[F,U]=G0.useState(!1),[g,c]=G0.useState(null),[n,l]=G0.useState(null),z6=V1.useCallback(()=>{if($==="plugin-list")if(O)Y({type:"manage-marketplaces",targetMarketplace:O});else if(P.length===1)Y({type:"menu"});else j("marketplace-list"),J(null),h(new Set);else if($==="plugin-details")j("plugin-list"),M(null);else Y({type:"menu"})},[$,O,Y,P.length]);G1("confirm:no",z6,{context:"Confirmation"}),G0.useEffect(()=>{async function J6(){try{let $6=await Dz(),{marketplaces:H6,failures:q6}=await Rp($6),o=[];for(let{name:t,config:Y6,data:X6}of H6)if(X6){let M6=w7(X6.plugins,(W6)=>Hu(Jc(W6.name,t)));o.push({name:t,totalPlugins:X6.plugins.length,installedCount:M6,source:O68(Y6.source)})}o.sort((t,Y6)=>{if(t.name==="claude-plugin-directory")return-1;if(Y6.name==="claude-plugin-directory")return 1;return 0}),W(o);let _6=w7(H6,(t)=>t.data!==null),r=$L6(q6,_6);if(r)if(r.type==="warning")l(r.message+". Showing available marketplaces.");else throw Error(r.message);if(o.length===1&&!O&&!w){let t=o[0];if(t)J(t.name),j("plugin-list")}if(w){let t=null,Y6=null;for(let[X6]of Object.entries($6)){let M6=await xf(X6);if(M6){let W6=M6.plugins.find((V6)=>V6.name===w);if(W6){let V6=Jc(W6.name,X6);t={entry:W6,marketplaceName:X6,pluginId:V6,isInstalled:aM6(V6)},Y6=X6;break}}}if(t&&Y6){let X6=t.pluginId;if(aM6(X6))K(`Plugin '${X6}' is already installed globally. Use '/plugin' to manage existing plugins.`);else J(Y6),M(t),j("plugin-details")}else K(`Plugin "${w}" not found in any marketplace`)}else if(O)if(o.some((Y6)=>Y6.name===O))J(O),j("plugin-list");else K(`Marketplace "${O}" not found`)}catch($6){K($6 instanceof Error?$6.message:"Failed to load marketplaces")}finally{f(!1)}}J6()},[K,O,w]),G0.useEffect(()=>{if(!H)return;let J6=!1;async function $6(H6){f(!0);try{let q6=await xf(H6);if(J6)return;if(!q6)throw Error(`Failed to load marketplace: ${H6}`);let o=[];for(let _6 of q6.plugins){let r=Jc(_6.name,H6);if(Rk(r))continue;o.push({entry:_6,marketplaceName:H6,pluginId:r,isInstalled:aM6(r)})}try{let _6=await Ex6();if(J6)return;if(V(_6),_6)o.sort((r,t)=>{let Y6=_6.get(r.pluginId)??0,X6=_6.get(t.pluginId)??0;if(Y6!==X6)return X6-Y6;return r.entry.name.localeCompare(t.entry.name)});else o.sort((r,t)=>r.entry.name.localeCompare(t.entry.name))}catch(_6){if(J6)return;E(`Failed to fetch install counts: ${b6(_6)}`),o.sort((r,t)=>r.entry.name.localeCompare(t.entry.name))}Z(o),N(0),h(new Set)}catch(q6){if(J6)return;K(q6 instanceof Error?q6.message:"Failed to load plugins")}finally{f(!1)}}return $6(H),()=>{J6=!0}},[H,K]);let A6=async()=>{if(R.size===0)return;let J6=D.filter((o)=>R.has(o.pluginId));x(new Set(J6.map((o)=>o.pluginId)));let $6=0,H6=0,q6=[];for(let o of J6){let _6=await z56({pluginId:o.pluginId,entry:o.entry,marketplaceName:o.marketplaceName,scope:"user"});if(_6.success)$6++;else H6++,q6.push({name:o.entry.name,reason:_6.error})}if(x(new Set),h(new Set),YO(),H6===0){let o=`✓ Installed ${$6} ${O7($6,"plugin")}. Run /reload-plugins to activate.`;z(o)}else if($6===0)K(`Failed to install: ${wL6(q6,!0)}`);else{let o=`✓ Installed ${$6} of ${$6+H6} plugins. Failed: ${wL6(q6,!1)}. Run /reload-plugins to activate successfully installed plugins.`;z(o)}if($6>0){if(A)await A()}Y({type:"menu"})},e=async(J6,$6="user")=>{U(!0),c(null);let H6=await z56({pluginId:J6.pluginId,entry:J6.entry,marketplaceName:J6.marketplaceName,scope:$6});if(H6.success){let q6=await ui8(J6.pluginId);if(q6){U(!1),j({type:"plugin-options",plugin:q6,pluginId:J6.pluginId,depNote:H6.depNote});return}if(z(H6.message),A)await A();Y({type:"menu"})}else U(!1),c(H6.error)};G0.useEffect(()=>{if(q)z(q)},[q,z]),L7({"select:previous":()=>{if(k>0)N(k-1)},"select:next":()=>{if(k<P.length-1)N(k+1)},"select:accept":()=>{let J6=P[k];if(J6)J(J6.name),j("plugin-list")}},{context:"Select",isActive:$==="marketplace-list"}),L7({"select:previous":()=>{if(k>0)B.handleSelectionChange(k-1,N)},"select:next":()=>{if(k<D.length-1)B.handleSelectionChange(k+1,N)},"select:accept":()=>{if(k===D.length&&R.size>0)A6();else if(k<D.length){let J6=D[k];if(J6)if(J6.isInstalled)Y({type:"manage-plugins",targetPlugin:J6.entry.name,targetMarketplace:J6.marketplaceName});else M(J6),j("plugin-details"),S(0),c(null)}}},{context:"Select",isActive:$==="plugin-list"}),L7({"plugin:toggle":()=>{if(k<D.length){let J6=D[k];if(J6&&!J6.isInstalled){let $6=new Set(R);if($6.has(J6.pluginId))$6.delete(J6.pluginId);else $6.add(J6.pluginId);h($6)}}},"plugin:install":()=>{if(R.size>0)A6()}},{context:"Plugin",isActive:$==="plugin-list"});let i=V1.useMemo(()=>{if(!X)return[];let J6=X.entry.homepage,$6=F_6(X);return Lx6(J6,$6)},[X]);if(L7({"select:previous":()=>{if(m>0)S(m-1)},"select:next":()=>{if(m<i.length-1)S(m+1)},"select:accept":()=>{if(!X)return;let J6=i[m]?.action,$6=X.entry.homepage,H6=F_6(X);if(J6==="install-user")e(X,"user");else if(J6==="install-project")e(X,"project");else if(J6==="install-local")e(X,"local");else if(J6==="homepage"&&$6)J3($6);else if(J6==="github"&&H6)J3(`https://github.com/${H6}`);else if(J6==="back")j("plugin-list"),M(null)}},{context:"Select",isActive:$==="plugin-details"&&!!X}),typeof $==="object"&&$.type==="plugin-options"){let q6=function(o){if(z(o),A)A();Y({type:"menu"})},{plugin:J6,pluginId:$6,depNote:H6}=$;return V1.createElement(yx6,{plugin:J6,pluginId:$6,onDone:(o,_6)=>{switch(o){case"configured":q6(`✓ Installed and configured ${J6.name}${H6}. Run /reload-plugins to apply.`);break;case"skipped":q6(`✓ Installed ${J6.name}${H6}. Run /reload-plugins to apply.`);break;case"error":q6(`Installed but failed to save config: ${_6}`);break}}})}if(G)return V1.createElement(T,null,"Loading…");if(q)return V1.createElement(T,{color:"error"},q);if($==="marketplace-list"){if(P.length===0)return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Select marketplace")),V1.createElement(T,null,"No marketplaces configured."),V1.createElement(T,{dimColor:!0},"Add a marketplace first using ","'Add marketplace'","."),V1.createElement(u,{marginTop:1,paddingLeft:1},V1.createElement(T,{dimColor:!0},V1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))));return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Select marketplace")),n&&V1.createElement(u,{marginBottom:1,flexDirection:"column"},V1.createElement(T,{color:"warning"},V1.createElement(D4,{status:"warning",withSpace:!0}),n)),P.map((J6,$6)=>V1.createElement(u,{key:J6.name,flexDirection:"column",marginBottom:$6<P.length-1?1:0},V1.createElement(u,null,V1.createElement(T,{color:k===$6?"suggestion":void 0},k===$6?e6.pointer:" "," ",J6.name)),V1.createElement(u,{marginLeft:2},V1.createElement(T,{dimColor:!0},V1.createElement(z1,null,V1.createElement(V1.Fragment,null,J6.totalPlugins," ",O7(J6.totalPlugins,"plugin")," available"),J6.installedCount>0&&`${J6.installedCount} already installed`,J6.source))))),V1.createElement(u,{marginTop:1},V1.createElement(T,{dimColor:!0,italic:!0},V1.createElement(z1,null,V1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),V1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"})))))}if($==="plugin-details"&&X){let J6=X.entry.homepage,$6=F_6(X),H6=Lx6(J6,$6);return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Plugin Details")),V1.createElement(u,{flexDirection:"column",marginBottom:1},V1.createElement(T,{bold:!0},X.entry.name),X.entry.version&&V1.createElement(T,{dimColor:!0},"Version: ",X.entry.version),X.entry.description&&V1.createElement(u,{marginTop:1},V1.createElement(T,null,X.entry.description)),X.entry.author&&V1.createElement(u,{marginTop:1},V1.createElement(T,{dimColor:!0},"By:"," ",typeof X.entry.author==="string"?X.entry.author:X.entry.author.name))),V1.createElement(u,{flexDirection:"column",marginBottom:1},V1.createElement(T,{bold:!0},"Will install:"),X.entry.commands&&V1.createElement(T,{dimColor:!0},"· Commands:"," ",Array.isArray(X.entry.commands)?X.entry.commands.join(", "):Object.keys(X.entry.commands).join(", ")),X.entry.agents&&V1.createElement(T,{dimColor:!0},"· Agents:"," ",Array.isArray(X.entry.agents)?X.entry.agents.join(", "):Object.keys(X.entry.agents).join(", ")),X.entry.hooks&&V1.createElement(T,{dimColor:!0},"· Hooks: ",Object.keys(X.entry.hooks).join(", ")),X.entry.mcpServers&&V1.createElement(T,{dimColor:!0},"· MCP Servers:"," ",Array.isArray(X.entry.mcpServers)?X.entry.mcpServers.join(", "):typeof X.entry.mcpServers==="object"?Object.keys(X.entry.mcpServers).join(", "):"configured"),!X.entry.commands&&!X.entry.agents&&!X.entry.hooks&&!X.entry.mcpServers&&V1.createElement(V1.Fragment,null,typeof X.entry.source==="object"&&"source"in X.entry.source&&(X.entry.source.source==="github"||X.entry.source.source==="url"||X.entry.source.source==="npm"||X.entry.source.source==="pip")?V1.createElement(T,{dimColor:!0},"· Component summary not available for remote plugin"):V1.createElement(T,{dimColor:!0},"· Components will be discovered at installation"))),V1.createElement(Bi8,null),g&&V1.createElement(u,{marginBottom:1},V1.createElement(T,{color:"error"},"Error: ",g)),V1.createElement(u,{flexDirection:"column"},H6.map((q6,o)=>V1.createElement(u,{key:q6.action},m===o&&V1.createElement(T,null,"> "),m!==o&&V1.createElement(T,null," "),V1.createElement(T,{bold:m===o},F&&q6.action==="install"?"Installing…":q6.label)))),V1.createElement(u,{marginTop:1,paddingLeft:1},V1.createElement(T,{dimColor:!0},V1.createElement(z1,null,V1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),V1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}if(D.length===0)return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Install plugins")),V1.createElement(T,{dimColor:!0},"No new plugins available to install."),V1.createElement(T,{dimColor:!0},"All plugins from this marketplace are already installed."),V1.createElement(u,{marginLeft:3},V1.createElement(T,{dimColor:!0,italic:!0},V1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))));let O6=B.getVisibleItems(D);return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Install Plugins")),B.scrollPosition.canScrollUp&&V1.createElement(u,null,V1.createElement(T,{dimColor:!0}," ",e6.arrowUp," more above")),O6.map((J6,$6)=>{let H6=B.toActualIndex($6),q6=k===H6,o=R.has(J6.pluginId),_6=C.has(J6.pluginId),r=$6===O6.length-1;return V1.createElement(u,{key:J6.pluginId,flexDirection:"column",marginBottom:r&&!q?0:1},V1.createElement(u,null,V1.createElement(T,{color:q6?"suggestion":void 0},q6?e6.pointer:" "," "),V1.createElement(T,{color:J6.isInstalled?"success":void 0},J6.isInstalled?e6.tick:_6?e6.ellipsis:o?e6.radioOn:e6.radioOff," ",J6.entry.name,J6.entry.category&&V1.createElement(T,{dimColor:!0}," [",J6.entry.category,"]"),J6.entry.tags?.includes("community-managed")&&V1.createElement(T,{dimColor:!0}," [Community Managed]"),J6.isInstalled&&V1.createElement(T,{dimColor:!0}," (installed)"),v&&H===WM&&V1.createElement(T,{dimColor:!0}," · ",Ii8(v.get(J6.pluginId)??0)," ","installs"))),J6.entry.description&&V1.createElement(u,{marginLeft:4},V1.createElement(T,{dimColor:!0},j4(J6.entry.description,60)),J6.entry.version&&V1.createElement(T,{dimColor:!0}," · v",J6.entry.version)))}),B.scrollPosition.canScrollDown&&V1.createElement(u,null,V1.createElement(T,{dimColor:!0}," ",e6.arrowDown," more below")),q&&V1.createElement(u,{marginTop:1},V1.createElement(T,{color:"error"},V1.createElement(D4,{status:"error",withSpace:!0}),q)),V1.createElement(lpK,{hasSelection:R.size>0}))}var V1,G0;var ipK=L(()=>{Qq();bK();Nq();Y2();g6();C7();Nj();K8();m8();uR();xi8();yD();Xc();m$();qH6();Y56();AH6();U86();mi8();Ow7();ww7();W_8();V1=K6(P6(),1),G0=K6(P6(),1)});function rpK({error:q,setError:K,result:_,setResult:z,setViewState:Y,onInstallComplete:A,onSearchModeChange:O,targetPlugin:w}){let[$,j]=FJ.useState("plugin-list"),[H,J]=FJ.useState(null),[X,M]=FJ.useState([]),[P,W]=FJ.useState(!0),[D,Z]=FJ.useState(null),[G,f]=FJ.useState(!1),v=FJ.useCallback((M6)=>{f(M6),O?.(M6)},[O]),{query:V,setQuery:k,cursorOffset:N,handleKeyDown:R,handlePaste:h}=bS({isActive:$==="plugin-list"&&G&&!P,onExit:()=>{v(!1)}}),C=K2(),{columns:x}=s1(),B=FJ.useMemo(()=>{if(!V)return X;let M6=V.toLowerCase();return X.filter((W6)=>W6.entry.name.toLowerCase().includes(M6)||W6.entry.description?.toLowerCase().includes(M6)||W6.marketplaceName.toLowerCase().includes(M6))},[X,V]),[m,S]=FJ.useState(0),[F,U]=FJ.useState(new Set),[g,c]=FJ.useState(new Set),n=QP6({totalItems:B.length,selectedIndex:m});FJ.useEffect(()=>{S(0)},[V]);let[l,z6]=FJ.useState(0),[A6,e]=FJ.useState(!1),[i,O6]=FJ.useState(null),[J6,$6]=FJ.useState(null),[H6,q6]=FJ.useState(null);FJ.useEffect(()=>{async function M6(){try{let W6=await Dz(),{marketplaces:V6,failures:f6}=await Rp(W6),G6=[];for(let{name:y6,data:c6}of V6)if(c6)for(let Z8 of c6.plugins){let N8=Jc(Z8.name,y6);G6.push({entry:Z8,marketplaceName:y6,pluginId:N8,isInstalled:Hu(N8)})}let k6=G6.filter((y6)=>!y6.isInstalled&&!Rk(y6.pluginId));try{let y6=await Ex6();if(Z(y6),y6)k6.sort((c6,Z8)=>{let N8=y6.get(c6.pluginId)??0,R6=y6.get(Z8.pluginId)??0;if(N8!==R6)return R6-N8;return c6.entry.name.localeCompare(Z8.entry.name)});else k6.sort((c6,Z8)=>c6.entry.name.localeCompare(Z8.entry.name))}catch(y6){E(`Failed to fetch install counts: ${b6(y6)}`),k6.sort((c6,Z8)=>c6.entry.name.localeCompare(Z8.entry.name))}M(k6);let T6=Object.keys(W6).length;if(k6.length===0){let y6=await Zf4({configuredMarketplaceCount:T6,failedMarketplaceCount:f6.length});if(y6==="all-plugins-installed"&&G6.length>0&&G6.every((c6)=>c6.isInstalled&&!aM6(c6.pluginId))&&!G6.some((c6)=>Rk(c6.pluginId)))y6="all-plugins-project-installed";q6(y6)}let v6=w7(V6,(y6)=>y6.data!==null),L6=$L6(f6,v6);if(L6)if(L6.type==="warning")$6(L6.message+(k6.length>0?". Showing available plugins.":"."));else throw Error(L6.message);if(w){let y6=G6.find((c6)=>c6.entry.name===w);if(y6)if(aM6(y6.pluginId))K(`Plugin '${y6.pluginId}' is already installed. Use '/plugin' to manage existing plugins.`);else J(y6),j("plugin-details");else K(`Plugin "${w}" not found in any marketplace`)}}catch(W6){K(W6 instanceof Error?W6.message:"Failed to load plugins")}finally{W(!1)}}M6()},[K,w]);let o=async()=>{if(F.size===0)return;let M6=X.filter((G6)=>F.has(G6.pluginId));c(new Set(M6.map((G6)=>G6.pluginId)));let W6=0,V6=0,f6=[];for(let G6 of M6){let k6=await z56({pluginId:G6.pluginId,entry:G6.entry,marketplaceName:G6.marketplaceName,scope:"user"});if(k6.success)W6++;else V6++,f6.push({name:G6.entry.name,reason:k6.error})}if(c(new Set),U(new Set),YO(),V6===0){let G6=`✓ Installed ${W6} ${O7(W6,"plugin")}. Run /reload-plugins to activate.`;z(G6)}else if(W6===0)K(`Failed to install: ${wL6(f6,!0)}`);else{let G6=`✓ Installed ${W6} of ${W6+V6} plugins. Failed: ${wL6(f6,!1)}. Run /reload-plugins to activate successfully installed plugins.`;z(G6)}if(W6>0){if(A)await A()}Y({type:"menu"})},_6=async(M6,W6="user")=>{e(!0),O6(null);let V6=await z56({pluginId:M6.pluginId,entry:M6.entry,marketplaceName:M6.marketplaceName,scope:W6});if(V6.success){let f6=await ui8(M6.pluginId);if(f6){e(!1),j({type:"plugin-options",plugin:f6,pluginId:M6.pluginId,depNote:V6.depNote});return}if(z(V6.message),A)await A();Y({type:"menu"})}else e(!1),O6(V6.error)};FJ.useEffect(()=>{if(q)z(q)},[q,z]),G1("confirm:no",()=>{j("plugin-list"),J(null)},{context:"Confirmation",isActive:$==="plugin-details"}),G1("confirm:no",()=>{Y({type:"menu"})},{context:"Confirmation",isActive:$==="plugin-list"&&!G});function r(M6){if(G){R(M6);return}if(M6.ctrl||M6.meta||P)return;if(M6.key==="/")M6.preventDefault(),v(!0),k("");else if(M6.key.length===1&&M6.key!==" ")M6.preventDefault(),v(!0),k(M6.key)}function t(M6){if(G){h(M6);return}if(P)return;let W6=(M6.text.split(/\r\n|\r|\n/,2)[0]??"").trim();if(!W6)return;M6.preventDefault(),v(!0),k(W6)}L7({"select:previous":()=>{if(m===0)v(!0);else n.handleSelectionChange(m-1,S)},"select:next":()=>{if(m<B.length-1)n.handleSelectionChange(m+1,S)},"select:accept":()=>{if(m===B.length&&F.size>0)o();else if(m<B.length){let M6=B[m];if(M6)if(M6.isInstalled)Y({type:"manage-plugins",targetPlugin:M6.entry.name,targetMarketplace:M6.marketplaceName});else J(M6),j("plugin-details"),z6(0),O6(null)}}},{context:"Select",isActive:$==="plugin-list"&&!G}),L7({"plugin:toggle":()=>{if(m<B.length){let M6=B[m];if(M6&&!M6.isInstalled){let W6=new Set(F);if(W6.has(M6.pluginId))W6.delete(M6.pluginId);else W6.add(M6.pluginId);U(W6)}}},"plugin:install":()=>{if(F.size>0)o()}},{context:"Plugin",isActive:$==="plugin-list"&&!G});let Y6=J1.useMemo(()=>{if(!H)return[];let M6=H.entry.homepage,W6=F_6(H);return Lx6(M6,W6)},[H]);if(L7({"select:previous":()=>{if(l>0)z6(l-1)},"select:next":()=>{if(l<Y6.length-1)z6(l+1)},"select:accept":()=>{if(!H)return;let M6=Y6[l]?.action,W6=H.entry.homepage,V6=F_6(H);if(M6==="install-user")_6(H,"user");else if(M6==="install-project")_6(H,"project");else if(M6==="install-local")_6(H,"local");else if(M6==="homepage"&&W6)J3(W6);else if(M6==="github"&&V6)J3(`https://github.com/${V6}`);else if(M6==="back")j("plugin-list"),J(null)}},{context:"Select",isActive:$==="plugin-details"&&!!H}),typeof $==="object"&&$.type==="plugin-options"){let f6=function(G6){if(z(G6),A)A();Y({type:"menu"})},{plugin:M6,pluginId:W6,depNote:V6}=$;return J1.createElement(yx6,{plugin:M6,pluginId:W6,onDone:(G6,k6)=>{switch(G6){case"configured":f6(`✓ Installed and configured ${M6.name}${V6}. Run /reload-plugins to apply.`);break;case"skipped":f6(`✓ Installed ${M6.name}${V6}. Run /reload-plugins to apply.`);break;case"error":f6(`Installed but failed to save config: ${k6}`);break}}})}if(P)return J1.createElement(T,null,"Loading…");if(q)return J1.createElement(T,{color:"error"},q);if($==="plugin-details"&&H){let M6=H.entry.homepage,W6=F_6(H),V6=Lx6(M6,W6);return J1.createElement(u,{flexDirection:"column"},J1.createElement(u,{marginBottom:1},J1.createElement(T,{bold:!0},"Plugin details")),J1.createElement(u,{flexDirection:"column",marginBottom:1},J1.createElement(T,{bold:!0},H.entry.name),J1.createElement(T,{dimColor:!0},"from ",H.marketplaceName),H.entry.version&&J1.createElement(T,{dimColor:!0},"Version: ",H.entry.version),H.entry.description&&J1.createElement(u,{marginTop:1},J1.createElement(T,null,H.entry.description)),H.entry.author&&J1.createElement(u,{marginTop:1},J1.createElement(T,{dimColor:!0},"By:"," ",typeof H.entry.author==="string"?H.entry.author:H.entry.author.name))),J1.createElement(Bi8,null),i&&J1.createElement(u,{marginBottom:1},J1.createElement(T,{color:"error"},"Error: ",i)),J1.createElement(u,{flexDirection:"column"},V6.map((f6,G6)=>J1.createElement(u,{key:f6.action},l===G6&&J1.createElement(T,null,"> "),l!==G6&&J1.createElement(T,null," "),J1.createElement(T,{bold:l===G6},A6&&f6.action.startsWith("install-")?"Installing…":f6.label)))),J1.createElement(u,{marginTop:1},J1.createElement(T,{dimColor:!0},J1.createElement(z1,null,J1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),J1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}if(X.length===0)return J1.createElement(u,{flexDirection:"column"},J1.createElement(u,{marginBottom:1},J1.createElement(T,{bold:!0},"Discover plugins")),J6&&J1.createElement(u,{marginBottom:1},J1.createElement(T,{color:"warning"},J1.createElement(D4,{status:"warning",withSpace:!0}),J6)),J1.createElement(YxY,{reason:H6}),J1.createElement(u,{marginTop:1},J1.createElement(T,{dimColor:!0,italic:!0},J1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))));let X6=n.getVisibleItems(B);return J1.createElement(u,{flexDirection:"column",tabIndex:0,autoFocus:!0,onKeyDown:r,onPaste:t},J1.createElement(u,null,J1.createElement(T,{bold:!0},"Discover plugins"),n.needsPagination&&J1.createElement(T,{dimColor:!0}," ","(",n.scrollPosition.current,"/",n.scrollPosition.total,")")),J1.createElement(u,{marginBottom:1},J1.createElement(wg,{query:V,isFocused:G,isTerminalFocused:C,width:x-4,cursorOffset:N})),J6&&J1.createElement(u,{marginBottom:1},J1.createElement(T,{color:"warning"},J1.createElement(D4,{status:"warning",withSpace:!0}),J6)),B.length===0&&V&&J1.createElement(u,{marginBottom:1},J1.createElement(T,{dimColor:!0},'No plugins match "',V,'"')),n.scrollPosition.canScrollUp&&J1.createElement(u,null,J1.createElement(T,{dimColor:!0}," ",e6.arrowUp," more above")),X6.map((M6,W6)=>{let V6=n.toActualIndex(W6),f6=m===V6,G6=F.has(M6.pluginId),k6=g.has(M6.pluginId),T6=W6===X6.length-1;return J1.createElement(u,{key:`${n.startIndex}-${M6.pluginId}`,flexDirection:"column",marginBottom:T6&&!q?0:1},J1.createElement(u,null,J1.createElement(T,{color:f6&&!G?"suggestion":void 0},f6&&!G?e6.pointer:" "," "),J1.createElement(T,null,k6?e6.ellipsis:G6?e6.radioOn:e6.radioOff," ",M6.entry.name,J1.createElement(T,{dimColor:!0}," · ",M6.marketplaceName),M6.entry.tags?.includes("community-managed")&&J1.createElement(T,{dimColor:!0}," [Community Managed]"),D&&M6.marketplaceName===WM&&J1.createElement(T,{dimColor:!0}," · ",Ii8(D.get(M6.pluginId)??0)," ","installs"))),M6.entry.description&&J1.createElement(u,{marginLeft:4},J1.createElement(T,{dimColor:!0},j4(M6.entry.description,60))))}),n.scrollPosition.canScrollDown&&J1.createElement(u,null,J1.createElement(T,{dimColor:!0}," ",e6.arrowDown," more below")),q&&J1.createElement(u,{marginTop:1},J1.createElement(T,{color:"error"},J1.createElement(D4,{status:"error",withSpace:!0}),q)),J1.createElement(zxY,{hasSelection:F.size>0,canToggle:m<B.length&&!B[m]?.isInstalled}))}function zxY(q){let K=s(10),{hasSelection:_,canToggle:z}=q,Y;if(K[0]!==_)Y=_&&J1.createElement(v1,{action:"plugin:install",context:"Plugin",fallback:"i",description:"install",bold:!0}),K[0]=_,K[1]=Y;else Y=K[1];let A;if(K[2]===Symbol.for("react.memo_cache_sentinel"))A=J1.createElement(T,null,"type to search"),K[2]=A;else A=K[2];let O;if(K[3]!==z)O=z&&J1.createElement(v1,{action:"plugin:toggle",context:"Plugin",fallback:"Space",description:"toggle"}),K[3]=z,K[4]=O;else O=K[4];let w,$;if(K[5]===Symbol.for("react.memo_cache_sentinel"))w=J1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"details"}),$=J1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"}),K[5]=w,K[6]=$;else w=K[5],$=K[6];let j;if(K[7]!==Y||K[8]!==O)j=J1.createElement(u,{marginTop:1},J1.createElement(T,{dimColor:!0,italic:!0},J1.createElement(z1,null,Y,A,O,w,$))),K[7]=Y,K[8]=O,K[9]=j;else j=K[9];return j}function YxY(q){let K=s(7),{reason:_}=q;switch(_){case"git-not-installed":{let z;if(K[0]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"Git is required to install marketplaces."),J1.createElement(T,{dimColor:!0},"Please install git and restart Claude Code.")),K[0]=z;else z=K[0];return z}case"all-blocked-by-policy":{let z;if(K[1]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"Your organization policy does not allow any external marketplaces."),J1.createElement(T,{dimColor:!0},"Contact your administrator.")),K[1]=z;else z=K[1];return z}case"policy-restricts-sources":{let z;if(K[2]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"Your organization restricts which marketplaces can be added."),J1.createElement(T,{dimColor:!0},"Switch to the Marketplaces tab to view allowed sources.")),K[2]=z;else z=K[2];return z}case"all-marketplaces-failed":{let z;if(K[3]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"Failed to load marketplace data."),J1.createElement(T,{dimColor:!0},"Check your network connection.")),K[3]=z;else z=K[3];return z}case"all-plugins-installed":{let z;if(K[4]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"All available plugins are already installed."),J1.createElement(T,{dimColor:!0},"Check for new plugins later or add more marketplaces.")),K[4]=z;else z=K[4];return z}case"all-plugins-project-installed":{let z;if(K[5]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"All available plugins are installed for this project."),J1.createElement(T,{dimColor:!0},"Use the Browse tab to install at user scope.")),K[5]=z;else z=K[5];return z}case"no-marketplaces-configured":default:{let z;if(K[6]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"No plugins available."),J1.createElement(T,{dimColor:!0},"Add a marketplace first using the Marketplaces tab.")),K[6]=z;else z=K[6];return z}}}var J1,FJ;var opK=L(()=>{o6();Qq();bK();Nq();Y2();EP6();R_6();I4();g6();C7();Nj();K8();m8();uR();xi8();yD();Xc();m$();qH6();Y56();AH6();U86();mi8();Ow7();ww7();W_8();J1=K6(P6(),1),FJ=K6(P6(),1)});import{dirname as AxY,join as OxY}from"path";function $w7(q){if(!vG.includes(q))throw Error(`Invalid scope "${q}". Must be one of: ${vG.join(", ")}`)}function Rx6(q){return vG.includes(q)}function apK(q){return q==="project"||q==="local"?Y7():void 0}function spK(q){return E1("projectSettings")?.enabledPlugins?.[q]===!0}function wxY(q){let K=q.includes("@"),_=["local","project","user"];for(let z of _){let Y=E1(jc(z))?.enabledPlugins;if(!Y)continue;for(let A of Object.keys(Y))if(K?A===q:A.startsWith(`${q}@`))return{pluginId:A,scope:z}}return null}function $xY(q,K){let{name:_,marketplace:z}=Z4(q);return K.find((Y)=>{if(Y.name===q||Y.name===_)return!0;if(z&&Y.source)return Y.name===_&&Y.source.includes(`@${z}`);return!1})}function jxY(q){let{name:K}=Z4(q),_=OZ();if(_.plugins[q]?.length)return{pluginId:q,pluginName:K};let z=Object.keys(_.plugins).find((Y)=>{let{name:A}=Z4(Y);return A===K&&(_.plugins[Y]?.length??0)>0});if(z)return{pluginId:z,pluginName:K};return null}function pi8(q){let _=OZ().plugins[q];if(!_||_.length===0)return{scope:"user"};let z=Y7(),Y=_.find((w)=>w.scope==="local"&&w.projectPath===z);if(Y)return{scope:Y.scope,projectPath:Y.projectPath};let A=_.find((w)=>w.scope==="project"&&w.projectPath===z);if(A)return{scope:A.scope,projectPath:A.projectPath};let O=_.find((w)=>w.scope==="user");if(O)return{scope:O.scope};return{scope:_[0].scope,projectPath:_[0].projectPath}}async function tpK(q,K="user"){$w7(K);let{name:_,marketplace:z}=Z4(q),Y,A,O;if(z){let H=await mf(q);if(H)Y=H.entry,A=z,O=H.marketplaceInstallLocation}else{let H=await Dz();for(let[J,X]of Object.entries(H))try{let P=(await xf(J)).plugins.find((W)=>W.name===_);if(P){Y=P,A=J,O=X.installLocation;break}}catch(M){j6(r1(M));continue}}if(!Y||!A){let H=z?`marketplace "${z}"`:"any configured marketplace";return{success:!1,message:`Plugin "${_}" not found in ${H}`}}let w=Y,$=`${w.name}@${A}`,j=await $d1({pluginId:$,entry:w,scope:K,marketplaceInstallLocation:O,trigger:"cli"});if(!j.ok)switch(j.reason){case"local-source-no-location":return{success:!1,message:`Cannot install local plugin "${j.pluginName}" without marketplace install location`};case"settings-write-failed":return{success:!1,message:`Failed to update settings: ${j.message}`};case"resolution-failed":return{success:!1,message:wd1(j.resolution)};case"blocked-by-policy":return{success:!1,message:`Plugin "${j.pluginName}" is blocked by your organization's policy and cannot be installed`};case"dependency-blocked-by-policy":return{success:!1,message:`Plugin "${j.pluginName}" depends on "${j.blockedDependency}", which is blocked by your organization's policy`};case"range-conflict":{let H=j.dep===$?"Plugin":"Dependency";return{success:!1,message:fS8(H,j.dep,j.ranges,j.why)}}case"no-matching-tag":{let H=j.dep===$?"Plugin":"Dependency";return{success:!1,message:GS8(H,j.dep,j.range)}}}return{success:!0,message:`Successfully installed plugin: ${$} (scope: ${K})${j.depNote}`,pluginId:$,pluginName:w.name,scope:K}}async function ie(q,K="user",_=!0){$w7(K);let{enabled:z,disabled:Y}=await sW(),A=[...z,...Y],O=$xY(q,A),w=jc(K),$=E1(w),j,H;if(O)j=Object.keys($?.enabledPlugins??{}).find((k)=>k===q||k===O.name||k.startsWith(`${O.name}@`))??(q.includes("@")?q:O.name),H=O.name;else{let k=jxY(q);if(!k)return{success:!1,message:`Plugin "${q}" not found in installed plugins`};j=k.pluginId,H=k.pluginName}let J=apK(K),M=OZ().plugins[j],P=M?.find((k)=>k.scope===K&&k.projectPath===J);if(!P){let{scope:k}=pi8(j);if(k!==K&&M&&M.length>0){if(k==="project")return{success:!1,message:`Plugin "${q}" is enabled at project scope (.claude/settings.json, shared with your team). To disable just for you: claude plugin disable ${q} --scope local`};return{success:!1,message:`Plugin "${q}" is installed in ${k} scope, not ${K}. Use --scope ${k} to uninstall.`}}return{success:!1,message:`Plugin "${q}" is not installed in ${K} scope. Use --scope to specify the correct scope.`}}let W=P.installPath,D={...$?.enabledPlugins};D[j]=void 0,P7(w,{enabledPlugins:D}),YO(),DEK(j,K,J);let G=OZ().plugins[j],f=!G||G.length===0;if(f&&W)await hI6(W);if(f){if(Vb8(j),_)await PS8(j)}let v=vQ1(j,A),V=TQ1(v);return{success:!0,message:`Successfully uninstalled plugin: ${H} (scope: ${K})${V}`,pluginId:j,pluginName:H,scope:K,reverseDependents:v.length>0?v:void 0}}async function jw7(q,K,_){let z=K?"enable":"disable";if(qf4(q)){let{error:D}=P7("userSettings",{enabledPlugins:{...E1("userSettings")?.enabledPlugins,[q]:K}});if(D)return{success:!1,message:`Failed to ${z} built-in plugin: ${D.message}`};YO();let{name:Z}=Z4(q);return{success:!0,message:`Successfully ${z}d built-in plugin: ${Z}`,pluginId:q,pluginName:Z,scope:"user"}}if(_)$w7(_);let Y,A,O=wxY(q);if(_)if(A=_,O)Y=O.pluginId;else if(q.includes("@"))Y=q;else return{success:!1,message:`Plugin "${q}" not found in settings. Use plugin@marketplace format.`};else if(O)Y=O.pluginId,A=O.scope;else if(q.includes("@"))Y=q,A="user";else return{success:!1,message:`Plugin "${q}" not found in any editable settings scope. Use plugin@marketplace format.`};if(K&&Rk(Y))return{success:!1,message:`Plugin "${Y}" is blocked by your organization's policy and cannot be enabled`};let w=jc(A),$=E1(w)?.enabledPlugins?.[Y],j={user:0,project:1,local:2},H=_&&O&&j[_]>j[O.scope];if(_&&$===void 0&&O&&O.scope!==_&&!H)return{success:!1,message:`Plugin "${q}" is installed at ${O.scope} scope, not ${_}. Use --scope ${O.scope} or omit --scope to auto-detect.`};let J=_&&!H?$===!0:p_6().has(Y);if(K===J)return{success:!1,message:`Plugin "${q}" is already ${K?"enabled":"disabled"}${_?` at ${_} scope`:""}`};let X;if(!K){let{enabled:D,disabled:Z}=await sW(),G=vQ1(Y,[...D,...Z]);if(G.length>0)X=G}let{error:M}=P7(w,{enabledPlugins:{...E1(w)?.enabledPlugins,[Y]:K}});if(M)return{success:!1,message:`Failed to ${z} plugin: ${M.message}`};YO();let{name:P}=Z4(Y),W=TQ1(X);return{success:!0,message:`Successfully ${z}d plugin: ${P} (scope: ${A})${W}`,pluginId:Y,pluginName:P,scope:A,reverseDependents:X}}async function Sx6(q,K){return jw7(q,!0,K)}async function Cx6(q,K){return jw7(q,!1,K)}async function epK(){let q=p_6();if(q.size===0)return{success:!0,message:"No enabled plugins to disable"};let K=[],_=[];for(let[z]of q){let Y=await jw7(z,!1);if(Y.success)K.push(z);else _.push(`${z}: ${Y.message}`)}if(_.length>0)return{success:!1,message:`Disabled ${K.length} ${O7(K.length,"plugin")}, ${_.length} failed:
6422
+ </${Tf6}>`}function sO7(q,K){if((q==="team"||q==="enterprise")&&K)return{entries:K,source:"org"};return{entries:ki8(),source:"ledger"}}function BP6(q,K){let _=q.split(":");return K.find((z)=>z.kind==="server"?q===z.name:_[0]==="plugin"&&_[1]===z.name)}function A_8(q,K,_){if(!K?.experimental?.["claude/channel"])return{action:"skip",kind:"capability",reason:"server did not declare claude/channel capability"};if(!mP6())return{action:"skip",kind:"disabled",reason:"channels feature is not currently available"};if(!o7()?.accessToken)return{action:"skip",kind:"auth",reason:"channels requires claude.ai authentication (run /login)"};let z=MK(),Y=z==="team"||z==="enterprise",A=Y?E1("policySettings"):void 0;if(Y&&A?.channelsEnabled!==!0)return{action:"skip",kind:"policy",reason:"channels not enabled by org policy (set channelsEnabled: true in managed settings)"};let O=BP6(q,qj());if(!O)return{action:"skip",kind:"session",reason:`server ${q} not in --channels list for this session`};if(O.kind==="plugin"){let w=_?Z4(_).marketplace:void 0;if(w!==O.marketplace)return{action:"skip",kind:"marketplace",reason:`you asked for plugin:${O.name}@${O.marketplace} but the installed ${O.name} plugin is from ${w??"an unknown source"}`};if(!O.dev){let{entries:$,source:j}=sO7(z,A?.allowedChannelPlugins);if(!$.some((H)=>H.plugin===O.name&&H.marketplace===O.marketplace))return{action:"skip",kind:"allowlist",reason:j==="org"?`plugin ${O.name}@${O.marketplace} is not on your org's approved channels list (set allowedChannelPlugins in managed settings)`:`plugin ${O.name}@${O.marketplace} is not on the approved channels allowlist (use --dangerously-load-development-channels for local dev)`}}}else if(!O.dev)return{action:"skip",kind:"allowlist",reason:`server ${O.name} is not on the approved channels allowlist (use --dangerously-load-development-channels for local dev)`};return{action:"register"}}var z_8,aO7="notifications/claude/channel/permission",ypK,LpK="notifications/claude/channel/permission_request",GIY;var O_8=L(()=>{p7();y8();rA();T7();aW();a1();__8();z_8=C6(()=>y.object({method:y.literal("notifications/claude/channel"),params:y.object({content:y.string(),meta:y.record(y.string(),y.string()).optional()})})),ypK=C6(()=>y.object({method:y.literal(aO7),params:y.object({request_id:y.string(),behavior:y.enum(["allow","deny"])})})),GIY=/^[a-zA-Z_][a-zA-Z0-9_]*$/});function RpK(){return u8("tengu_harbor_permissions",!1)}function hpK(q){let K=2166136261;for(let z=0;z<q.length;z++)K^=q.charCodeAt(z),K=Math.imul(K,16777619);K=K>>>0;let _="";for(let z=0;z<5;z++)_+=vIY[K%25],K=Math.floor(K/25);return _}function SpK(q){let K=hpK(q);for(let _=0;_<10;_++){if(!TIY.some((z)=>K.includes(z)))return K;K=hpK(`${q}:${_}`)}return K}function CpK(q){try{let K=I6(q);return K.length>200?K.slice(0,200)+"…":K}catch{return"(unserializable)"}}function bpK(q,K){return q.filter((_)=>_.type==="connected"&&K(_.name)&&_.capabilities?.experimental?.["claude/channel"]!==void 0&&_.capabilities?.experimental?.["claude/channel/permission"]!==void 0)}function IpK(){let q=new Map;return{onResponse(K,_){let z=K.toLowerCase();return q.set(z,_),()=>{q.delete(z)}},resolve(K,_,z){let Y=K.toLowerCase(),A=q.get(Y);if(!A)return!1;return q.delete(Y),A({behavior:_,fromServer:z}),!0}}}var vIY="abcdefghijkmnopqrstuvwxyz",TIY;var tO7=L(()=>{e8();B1();TIY=["fuck","shit","cunt","cock","dick","twat","piss","crap","bitch","whore","ass","tit","cum","fag","dyke","nig","kike","rape","nazi","damn","poo","pee","wank","anus"]});function xpK(q){let K="plugin"in q?q.plugin:"no-plugin";return`${q.type}:${q.source}:${K}`}function upK(q,K){if(K.length===0)return;q((_)=>{let z=new Set(_.plugins.errors.map((A)=>xpK(A))),Y=K.filter((A)=>!z.has(xpK(A)));if(Y.length===0)return _;return{..._,plugins:{..._.plugins,errors:[..._.plugins.errors,...Y]}}})}function mpK(q,K=!1){let _=H9(),z=M8((v)=>v.authVersion),Y=M8((v)=>v.mcp.pluginReconnectKey),A=R7(),O=wZ.useRef(new Map),w=wZ.useRef(new Set),$=wZ.useRef(new Set),j=wZ.useRef(null);if(j.current===null)j.current=IpK();wZ.useEffect(()=>{{let v=j.current;if(!v)return;if(!RpK())return;return A((V)=>{if(V.channelPermissionCallbacks===v)return V;return{...V,channelPermissionCallbacks:v}}),()=>{A((V)=>{if(V.channelPermissionCallbacks===void 0)return V;return{...V,channelPermissionCallbacks:void 0}})}}},[A]);let{addNotification:H}=EK(),J=16,X=wZ.useRef([]),M=wZ.useRef(null),P=wZ.useCallback(()=>{M.current=null;let v=X.current;if(v.length===0)return;X.current=[],A((V)=>{let k=V.mcp;for(let N of v){let{tools:R,commands:h,resources:C,resourceTemplates:x,...B}=N,m=B.type==="disabled"||B.type==="failed"?R??[]:R,S=B.type==="disabled"||B.type==="failed"?h??[]:h,F=B.type==="disabled"||B.type==="failed"?C??[]:C,U=B.type==="disabled"||B.type==="failed"?x??[]:x,g=Zh(B.name),n=k.clients.findIndex((i)=>i.name===B.name)===-1?[...k.clients,B]:k.clients.map((i)=>i.name===B.name?B:i),l=m===void 0?k.tools:[...PG(k.tools,(i)=>i.name?.startsWith(g)),...m],z6=S===void 0?k.commands:[...PG(k.commands,(i)=>hl(i,B.name)),...S],A6=F===void 0?k.resources:{...k.resources,...F.length>0?{[B.name]:F}:gF(k.resources,B.name)},e=U===void 0?k.resourceTemplates:U.length>0?{...k.resourceTemplates,[B.name]:U}:gF(k.resourceTemplates,B.name);k={...k,clients:n,tools:l,commands:z6,resources:A6,resourceTemplates:e}}return{...V,mcp:k}})},[A]),W=wZ.useCallback((v)=>{if(X.current.push(v),M.current===null)M.current=setTimeout(P,J)},[P]),D=wZ.useCallback(({client:v,tools:V,commands:k,resources:N,resourceTemplates:R})=>{switch(W({...v,tools:V,commands:k,resources:N,resourceTemplates:R}),v.type){case"connected":{BhK(v.client,v.name,A),v.client.onclose=()=>{let h=v.config.type??"stdio";if(WG(v.name,v.config).catch(()=>{E(`Failed to invalidate the server cache: ${v.name}`)}),ZT(v.name)){i8(v.name,"Server is disabled, skipping automatic reconnection");return}if(h!=="stdio"&&h!=="sdk"){let C=EIY(h);i8(v.name,`${C} transport closed/disconnected, attempting automatic reconnection`);let x=O.current.get(v.name);if(x)clearTimeout(x),O.current.delete(v.name);(async()=>{for(let m=1;m<=kx6;m++){if(ZT(v.name)){i8(v.name,"Server disabled during reconnection, stopping retry"),O.current.delete(v.name);return}W({...v,type:"pending",reconnectAttempt:m,maxReconnectAttempts:kx6});let S=Date.now();try{let U=await _g(v.name,v.config),g=Date.now()-S;if(U.client.type==="connected"){i8(v.name,`${C} reconnection successful after ${g}ms (attempt ${m})`),O.current.delete(v.name),D(U);return}if(i8(v.name,`${C} reconnection attempt ${m} completed with status: ${U.client.type}`),m===kx6){i8(v.name,`Max reconnection attempts (${kx6}) reached, giving up`),O.current.delete(v.name),D(U);return}}catch(U){let g=Date.now()-S;if(yz(v.name,`${C} reconnection attempt ${m} failed after ${g}ms: ${U}`),m===kx6){i8(v.name,`Max reconnection attempts (${kx6}) reached, giving up`),O.current.delete(v.name),W({...v,type:"failed"});return}}let F=Math.min(kIY*Math.pow(2,m-1),NIY);i8(v.name,`Scheduling reconnection attempt ${m+1} in ${F}ms`),await new Promise((U)=>{let g=setTimeout(U,F);O.current.set(v.name,g)})}})()}else $.current.delete(v.name),W({...v,type:"failed"})};{let h=A_8(v.name,v.capabilities,v.config.pluginSource),C=BP6(v.name,qj()),x=C?.kind==="plugin"?`${C.name}@${C.marketplace}`:void 0,B=!1,m=()=>{if($.current.add(v.name),v.client.setNotificationHandler(z_8(),async(S)=>{let{content:F,meta:U}=S.params;i8(v.name,`notifications/claude/channel: ${F.slice(0,80)}`),d("tengu_mcp_channel_message",{content_length:F.length,meta_key_count:Object.keys(U??{}).length,entry_kind:C?.kind,is_dev:C?.dev??!1,plugin:x}),Dj({mode:"prompt",value:Y_8(v.name,F,U),priority:"next",isMeta:!0,origin:{kind:"channel",server:v.name},skipSlashCommands:!0})}),v.capabilities?.experimental?.["claude/channel/permission"]!==void 0)v.client.setNotificationHandler(ypK(),async(S)=>{let{request_id:F,behavior:U}=S.params,g=j.current?.resolve(F,U,v.name)??!1;i8(v.name,`notifications/claude/channel/permission: ${F} → ${U} (${g?"matched pending":"no pending entry — stale or unknown ID"})`)})};switch(h.action){case"register":i8(v.name,"Channel notifications registered"),m(),B=!0;break;case"skip":{let S=h.kind==="auth"||h.kind==="disabled"||h.kind==="capability",F=$.current.has(v.name);if(S)$.current.delete(v.name),v.client.removeNotificationHandler("notifications/claude/channel"),v.client.removeNotificationHandler(aO7);else if(F){i8(v.name,`Channel gate says skip:${h.kind} but was previously registered — preserving handler`),m(),B=!0;break}if(i8(v.name,`Channel notifications skipped: ${h.reason}`),h.kind!=="capability"&&h.kind!=="session"&&!w.current.has(h.kind)&&(h.kind==="marketplace"||h.kind==="allowlist"||C!==void 0)){w.current.add(h.kind);let U=h.kind==="disabled"?"Channels are not currently available":h.kind==="auth"?"Channels require claude.ai authentication · run /login":h.kind==="policy"?"Channels are not enabled for your org · have an administrator set channelsEnabled: true in managed settings":h.reason;H({key:`channels-blocked-${h.kind}`,priority:"high",text:U,color:"warning",timeoutMs:12000})}break}}if(B||h.action==="skip"&&h.kind!=="capability")d("tengu_mcp_channel_gate",{registered:B,skip_kind:h.action==="skip"?h.kind:void 0,entry_kind:C?.kind,is_dev:C?.dev??!1,plugin:x})}if(v.capabilities?.tools?.listChanged)v.client.setNotificationHandler(Ig6,async()=>{i8(v.name,"Received tools/list_changed notification, refreshing tools");try{let h=NS.cache.get(v.name);NS.cache.delete(v.name);let C=await NS(v),x=C.length;if(h)h.then((B)=>{d("tengu_mcp_list_changed",{type:"tools",previousCount:B.length,newCount:x})},()=>{d("tengu_mcp_list_changed",{type:"tools",newCount:x})});else d("tengu_mcp_list_changed",{type:"tools",newCount:x});W({...v,tools:C})}catch(h){yz(v.name,`Failed to refresh tools after list_changed notification: ${b6(h)}`)}});if(v.capabilities?.prompts?.listChanged)v.client.setNotificationHandler(Cg6,async()=>{i8(v.name,"Received prompts/list_changed notification, refreshing prompts"),d("tengu_mcp_list_changed",{type:"prompts"});try{JP6.cache.delete(v.name);let[h,C]=await Promise.all([JP6(v),Promise.resolve([])]);W({...v,commands:[...h,...C]}),VIY?.()}catch(h){yz(v.name,`Failed to refresh prompts after list_changed notification: ${b6(h)}`)}});if(v.capabilities?.resources?.listChanged)v.client.setNotificationHandler(Rg6,async()=>{i8(v.name,"Received resources/list_changed notification, refreshing resources"),d("tengu_mcp_list_changed",{type:"resources"});try{Es.cache.delete(v.name),HP6.cache.delete(v.name);{let[h,C]=await Promise.all([Es(v),HP6(v)]);W({...v,resources:h,resourceTemplates:C})}}catch(h){yz(v.name,`Failed to refresh resources after list_changed notification: ${b6(h)}`)}});break}case"needs-auth":case"failed":case"pending":case"disabled":break}},[W]),Z=I8();wZ.useEffect(()=>{async function v(){let{servers:V,errors:k}=K?{servers:{},errors:[]}:await ZX6(q),N={...V,...q};upK(A,k),A((R)=>{let{stale:h,...C}=P_K(R.mcp,N);for(let m of h){let S=O.current.get(m.name);if(S)clearTimeout(S),O.current.delete(m.name);if($.current.delete(m.name),m.type==="connected")m.client.onclose=void 0,WG(m.name,m.config).catch(()=>{})}let x=new Set(C.clients.map((m)=>m.name)),B=Object.entries(N).filter(([m])=>!x.has(m)).map(([m,S])=>({name:m,type:ZT(m)?"disabled":"pending",config:S}));if(B.length===0&&h.length===0)return R;return{...R,mcp:{...R.mcp,...C,clients:[...C.clients,...B]}}})}v().catch((V)=>{yz("useManageMCPConnections",`Failed to initialize servers as pending: ${b6(V)}`)})},[K,q,A,Z,Y]),wZ.useEffect(()=>{let v=!1;async function V(){let k;if(K||e36())k=Promise.resolve({});else X_K(),k=DX6();let{servers:N,errors:R}=K?{servers:{},errors:[]}:await ZX6(q);if(v)return;upK(A,R);let h={...N,...q},C=rO7(h,(F,U)=>ZT(U));XP6(D,C).catch((F)=>{yz("useManageMcpConnections",`Failed to get MCP resources: ${b6(F)}`)});let x={};if(!K){if(x=s36(await k).allowed,v)return;if(Object.keys(x).length>0){let{servers:F}=Y48(x,h);x=F}if(Object.keys(x).length>0){A((U)=>{let g=new Set(U.mcp.clients.map((n)=>n.name)),c=Object.entries(x).filter(([n])=>!g.has(n)).map(([n,l])=>({name:n,type:ZT(n)?"disabled":"pending",config:l}));if(c.length===0)return U;return{...U,mcp:{...U.mcp,clients:[...U.mcp.clients,...c]}}});let F=rO7(x,(U,g)=>ZT(g));XP6(D,F).catch((U)=>{yz("useManageMcpConnections",`Failed to get claude.ai MCP resources: ${b6(U)}`)})}}let B={...h,...x},m={enterprise:0,global:0,project:0,user:0,plugin:0,claudeai:0},S=[];for(let[F,U]of Object.entries(B))if(U.scope==="enterprise")m.enterprise++;else if(U.scope==="user")m.global++;else if(U.scope==="project")m.project++;else if(U.scope==="local")m.user++;else if(U.scope==="dynamic")m.plugin++;else if(U.scope==="claudeai")m.claudeai++;d("tengu_mcp_servers",{...m,...!1})}return V(),()=>{v=!0}},[K,q,D,A,z,Z,Y]),wZ.useEffect(()=>{let v=O.current;return()=>{for(let V of v.values())clearTimeout(V);if(v.clear(),M.current!==null)clearTimeout(M.current),M.current=null,P()}},[P]);let G=wZ.useCallback(async(v)=>{let V=_.getState().mcp.clients.find((R)=>R.name===v);if(!V)throw Error(`MCP server ${v} not found`);let k=O.current.get(v);if(k)clearTimeout(k),O.current.delete(v);let N=await _g(v,V.config);return D(N),N},[_,D]),f=wZ.useCallback(async(v)=>{let V=_.getState().mcp.clients.find((N)=>N.name===v);if(!V)throw Error(`MCP server ${v} not found`);if(V.type!=="disabled"){let N=O.current.get(v);if(N)clearTimeout(N),O.current.delete(v);if(YC6(v,!1),$.current.delete(v),V.type==="connected")await WG(v,V.config);W({name:v,type:"disabled",config:V.config})}else{YC6(v,!0),W({name:v,type:"pending",config:V.config});let N=await _g(v,V.config);D(N)}},[_,W,D]);return{reconnectMcpServer:G,toggleMcpServer:f}}function EIY(q){switch(q){case"http":return"HTTP";case"ws":case"ws-ide":return"WebSocket";default:return"SSE"}}var wZ,VIY=null,kx6=5,kIY=1000,NIY=30000;var BpK=L(()=>{y8();oW();_P();jU8();NpK();Wl8();C8();rD();K8();y8();kY();N7();m8();U8();b$();O_8();tO7();tS6();dl8();fh();iD();wZ=K6(P6(),1)});function Nx6(){let q=pP6.useContext(eO7);if(!q)throw Error("useMcpReconnect must be used within MCPConnectionManager");return q.reconnectMcpServer}function m_6(){let q=pP6.useContext(eO7);if(!q)throw Error("useMcpToggleEnabled must be used within MCPConnectionManager");return q.toggleMcpServer}function Ni8(q){let K=s(6),{children:_,dynamicMcpConfig:z,isStrictMcpConfig:Y}=q,{reconnectMcpServer:A,toggleMcpServer:O}=mpK(z,Y),w;if(K[0]!==A||K[1]!==O)w={reconnectMcpServer:A,toggleMcpServer:O},K[0]=A,K[1]=O,K[2]=w;else w=K[2];let $=w,j;if(K[3]!==_||K[4]!==$)j=pP6.default.createElement(eO7.Provider,{value:$},_),K[3]=_,K[4]=$,K[5]=j;else j=K[5];return j}var pP6,eO7;var B_6=L(()=>{o6();BpK();pP6=K6(P6(),1),eO7=pP6.createContext(null)});function qw7(q){let K=s(25),{serverName:_,onComplete:z}=q,[Y]=Zq(),A=H9(),O=Nx6(),[w,$]=GG.useState(!0),[j,H]=GG.useState(null),J,X;if(K[0]!==z||K[1]!==O||K[2]!==_||K[3]!==A)J=()=>{(async function(){try{if(!A.getState().mcp.clients.find((Z)=>Z.name===_)){H(`MCP server "${_}" not found`),$(!1),z(`MCP server "${_}" not found`);return}let D=await O(_);q:switch(D.client.type){case"connected":{$(!1),z(`Successfully reconnected to ${_}`);break q}case"needs-auth":{H(`${_} requires authentication`),$(!1),z(`${_} requires authentication. Use /mcp to authenticate.`);break q}case"pending":case"failed":case"disabled":H(`Failed to reconnect to ${_}`),$(!1),z(`Failed to reconnect to ${_}`)}}catch(W){let D=W,Z=D instanceof Error?D.message:String(D);H(Z),$(!1),z(`Error: ${Z}`)}})()},X=[_,O,A,z],K[0]=z,K[1]=O,K[2]=_,K[3]=A,K[4]=J,K[5]=X;else J=K[4],X=K[5];if(GG.useEffect(J,X),w){let M;if(K[6]!==_)M=GG.default.createElement(T,{color:"text"},"Reconnecting to ",GG.default.createElement(T,{bold:!0},_)),K[6]=_,K[7]=M;else M=K[7];let P;if(K[8]===Symbol.for("react.memo_cache_sentinel"))P=GG.default.createElement(u,null,GG.default.createElement(Y5,null),GG.default.createElement(T,null," Establishing connection to MCP server")),K[8]=P;else P=K[8];let W;if(K[9]!==M)W=GG.default.createElement(u,{flexDirection:"column",gap:1,padding:1},M,P),K[9]=M,K[10]=W;else W=K[10];return W}if(j){let M;if(K[11]!==Y)M=d7("error",Y)(e6.cross),K[11]=Y,K[12]=M;else M=K[12];let P;if(K[13]!==M)P=GG.default.createElement(T,null,M," "),K[13]=M,K[14]=P;else P=K[14];let W;if(K[15]!==_)W=GG.default.createElement(T,{color:"error"},"Failed to reconnect to ",_),K[15]=_,K[16]=W;else W=K[16];let D;if(K[17]!==P||K[18]!==W)D=GG.default.createElement(u,null,P,W),K[17]=P,K[18]=W,K[19]=D;else D=K[19];let Z;if(K[20]!==j)Z=GG.default.createElement(T,{dimColor:!0},"Error: ",j),K[20]=j,K[21]=Z;else Z=K[21];let G;if(K[22]!==D||K[23]!==Z)G=GG.default.createElement(u,{flexDirection:"column",gap:1,padding:1},D,Z),K[22]=D,K[23]=Z,K[24]=G;else G=K[24];return G}return null}var GG;var Kw7=L(()=>{o6();Qq();g6();B_6();N7();Ej();GG=K6(P6(),1)});function Ei8(q){let K=s(9),{serverToolsCount:_,serverPromptsCount:z,serverResourcesCount:Y}=q,A;if(K[0]!==z||K[1]!==Y||K[2]!==_){if(A=[],_>0)A.push("tools");if(Y>0)A.push("resources");if(z>0)A.push("prompts");K[0]=z,K[1]=Y,K[2]=_,K[3]=A}else A=K[3];let O;if(K[4]===Symbol.for("react.memo_cache_sentinel"))O=w_8.default.createElement(T,{bold:!0},"Capabilities: "),K[4]=O;else O=K[4];let w;if(K[5]!==A)w=A.length>0?w_8.default.createElement(z1,null,A):"none",K[5]=A,K[6]=w;else w=K[6];let $;if(K[7]!==w)$=w_8.default.createElement(u,null,O,w_8.default.createElement(T,{color:"text"},w)),K[7]=w,K[8]=$;else $=K[8];return $}var w_8;var _w7=L(()=>{o6();g6();Nq();w_8=K6(P6(),1)});function yi8(q,K,_){switch(q.client.type){case"connected":return{message:`Reconnected to ${K}.`,success:!0};case"needs-auth":return{message:_?.hasHeadersHelper?`${K} requires authentication. Check that the headersHelper script returns valid credentials, then use the 'Reconnect' option.`:`${K} requires authentication. Use the 'Authenticate' option.`,success:!1};case"failed":return{message:`Failed to reconnect to ${K}.`,success:!1};default:return{message:`Unknown result when reconnecting to ${K}.`,success:!1}}}function $_8(q,K){let _=q instanceof Error?q.message:String(q);return`Error reconnecting to ${K}: ${_}`}function FP6({server:q,serverToolsCount:K,onViewTools:_,onCancel:z,onComplete:Y,borderless:A=!1}){let[O]=Zq(),w=$3(),{columns:$}=s1(),[j,H]=H7.default.useState(!1),[J,X]=H7.default.useState(null),M=M8((f6)=>f6.mcp),P=R7(),[W,D]=H7.default.useState(null),[Z,G]=H7.useState(!1),f=H7.useRef(null),[v,V]=H7.useState(!1),[k,N]=H7.useState(null),[R,h]=H7.useState(!1),[C,x]=H7.useState(null),[B,m]=H7.useState(!1),[S,F]=H7.useState(!1),U=H7.useRef(void 0),g=H7.useRef(!1),[c,n]=H7.useState(""),[l,z6]=H7.useState(0),[A6,e]=H7.useState(null);H7.useEffect(()=>()=>{if(g.current=!0,f.current?.abort(),U.current!==void 0)clearTimeout(U.current)},[]);let i=q.isAuthenticated||q.client.type==="connected"&&K>0,O6=Nx6(),J6=H7.default.useCallback(async()=>{V(!1),N(null),G(!0);try{let f6=await O6(q.name),G6=f6.client.type==="connected";if(d("tengu_claudeai_mcp_auth_completed",{success:G6}),G6)Y?.(`Authentication successful. Connected to ${q.name}.`);else if(f6.client.type==="needs-auth")Y?.("Authentication successful, but server still requires authentication. You may need to manually restart Claude Code.");else Y?.("Authentication successful, but server reconnection failed. You may need to manually restart Claude Code for the changes to take effect.")}catch(f6){d("tengu_claudeai_mcp_auth_completed",{success:!1}),Y?.($_8(f6,q.name))}finally{G(!1)}},[O6,q.name,Y]),$6=H7.default.useCallback(async()=>{await WG(q.name,{...q.config,scope:q.scope}),P((f6)=>{let G6=f6.mcp.clients.map((L6)=>L6.name===q.name?{...L6,type:"needs-auth"}:L6),k6=bp8(f6.mcp.tools,q.name),T6=eS6(f6.mcp.commands,q.name),v6=qC6(f6.mcp.resources,q.name);return{...f6,mcp:{...f6.mcp,clients:G6,tools:k6,commands:T6,resources:v6}}}),d("tengu_claudeai_mcp_clear_auth_completed",{}),Y?.(`Disconnected from ${q.name}.`),h(!1),x(null),m(!1)},[q.name,q.config,q.scope,P,Y]);G1("confirm:no",()=>{f.current?.abort(),f.current=null,H(!1),D(null)},{context:"Confirmation",isActive:j}),G1("confirm:no",()=>{V(!1),N(null)},{context:"Confirmation",isActive:v}),G1("confirm:no",()=>{h(!1),x(null),m(!1)},{context:"Confirmation",isActive:R});function H6(f6){if(f6.key==="return"&&v)f6.preventDefault(),J6();if(f6.key==="return"&&R)if(f6.preventDefault(),B)$6();else{let G6=`${r7().CLAUDE_AI_ORIGIN}/settings/connectors`;x(G6),m(!0),J3(G6)}if(f6.key==="c"&&!f6.ctrl&&!f6.meta&&!S){let G6=W||k||C;if(G6)f6.preventDefault(),hP(G6).then((k6)=>{if(g.current)return;if(k6)process.stdout.write(k6);if(F(!0),U.current!==void 0)clearTimeout(U.current);U.current=setTimeout(F,2000,!1)})}}let q6=zv(String(q.name)),o=Cp8(M.commands,q.name).length,_6=m_6(),r=H7.default.useCallback(async()=>{let f6=r7().CLAUDE_AI_ORIGIN,k6=k_()?.organizationUuid,T6;if(k6&&q.config.type==="claudeai-proxy"&&q.config.id){let v6=q.config.id.startsWith("mcprs")?"mcpsrv"+q.config.id.slice(5):q.config.id,L6=encodeURIComponent(process.env.CLAUDE_CODE_ENTRYPOINT||"cli");T6=`${f6}/api/organizations/${k6}/mcp/start-auth/${v6}?product_surface=${L6}`}else T6=`${f6}/settings/connectors`;N(T6),V(!0),d("tengu_claudeai_mcp_auth_started",{}),await J3(T6)},[q.config]),t=H7.default.useCallback(()=>{h(!0),d("tengu_claudeai_mcp_clear_auth_started",{})},[]),Y6=H7.default.useCallback(async()=>{let f6=q.client.type!=="disabled";try{if(await _6(q.name),q.config.type==="claudeai-proxy")d("tengu_claudeai_mcp_toggle",{new_state:f6?"disabled":"enabled"});z()}catch(G6){Y?.(`Failed to ${f6?"disable":"enable"} MCP server '${q.name}': ${b6(G6)}`)}},[q.client.type,q.config.type,q.name,_6,z,Y]),X6=H7.default.useCallback(async()=>{if(q.config.type==="claudeai-proxy")return;H(!0),X(null);let f6=new AbortController;f.current=f6;try{if(q.isAuthenticated&&q.config)await q98(q.name,q.config,{preserveStepUpState:!0});if(q.config){await T_6(q.name,q.config,D,f6.signal,{onWaitingForCallback:(k6)=>{e(()=>k6)}}),d("tengu_mcp_auth_config_authenticate",{wasAuthenticated:q.isAuthenticated});let G6=await O6(q.name);if(G6.client.type==="connected"){let k6=i?`Authentication successful. Reconnected to ${q.name}.`:`Authentication successful. Connected to ${q.name}.`;Y?.(k6)}else if(G6.client.type==="needs-auth")Y?.("Authentication successful, but server still requires authentication. You may need to manually restart Claude Code.");else i8(q.name,"Reconnection failed after authentication"),Y?.("Authentication successful, but server reconnection failed. You may need to manually restart Claude Code for the changes to take effect.")}}catch(G6){if(G6 instanceof Error&&!(G6 instanceof Xu))X(G6.message)}finally{H(!1),f.current=null,e(null),n("")}},[q.isAuthenticated,q.config,q.name,Y,O6,i]),M6=async()=>{if(q.config.type==="claudeai-proxy")return;if(q.config)await q98(q.name,q.config),d("tengu_mcp_auth_config_clear",{}),await WG(q.name,{...q.config,scope:q.scope}),P((f6)=>{let G6=f6.mcp.clients.map((L6)=>L6.name===q.name?{...L6,type:"failed"}:L6),k6=bp8(f6.mcp.tools,q.name),T6=eS6(f6.mcp.commands,q.name),v6=qC6(f6.mcp.resources,q.name);return{...f6,mcp:{...f6.mcp,clients:G6,tools:k6,commands:T6,resources:v6}}}),Y?.(`Authentication cleared for ${q.name}.`)};if(j){let f6=q.config.type!=="claudeai-proxy"&&q.config.oauth?.xaa?" Authenticating via your identity provider":" A browser window will open for authentication";return H7.default.createElement(u,{flexDirection:"column",gap:1,padding:1,tabIndex:0,autoFocus:!0,onKeyDown:H6},H7.default.createElement(T,{color:"claude"},"Authenticating with ",q.name,"…"),H7.default.createElement(u,null,H7.default.createElement(Y5,null),H7.default.createElement(T,null,f6)),W&&H7.default.createElement(u,{flexDirection:"column"},H7.default.createElement(u,null,H7.default.createElement(T,{dimColor:!0},"If your browser doesn't open automatically, copy this URL manually"," "),S?H7.default.createElement(T,{color:"success"},"(Copied!)"):H7.default.createElement(T,{dimColor:!0},H7.default.createElement(A8,{chord:"c",action:"copy",parens:!0}))),H7.default.createElement(yq,{url:W})),j&&W&&A6&&H7.default.createElement(u,{flexDirection:"column",marginTop:1},H7.default.createElement(T,{dimColor:!0},"If the redirect page shows a connection error, paste the URL from your browser's address bar:"),H7.default.createElement(u,null,H7.default.createElement(T,{dimColor:!0},"URL ",">"," "),H7.default.createElement(l4,{value:c,onChange:n,onSubmit:(G6)=>{A6(G6.trim()),n("")},cursorOffset:l,onChangeCursorOffset:z6,columns:$-8}))),H7.default.createElement(u,{marginLeft:3},H7.default.createElement(T,{dimColor:!0},"Return here after authenticating in your browser. Press"," ",H7.default.createElement(A8,{chord:"escape",action:"go back"}),".")))}if(v)return H7.default.createElement(u,{flexDirection:"column",gap:1,padding:1,tabIndex:0,autoFocus:!0,onKeyDown:H6},H7.default.createElement(T,{color:"claude"},"Authenticating with ",q.name,"…"),H7.default.createElement(u,null,H7.default.createElement(Y5,null),H7.default.createElement(T,null," A browser window will open for authentication")),k&&H7.default.createElement(u,{flexDirection:"column"},H7.default.createElement(u,null,H7.default.createElement(T,{dimColor:!0},"If your browser doesn't open automatically, copy this URL manually"," "),S?H7.default.createElement(T,{color:"success"},"(Copied!)"):H7.default.createElement(T,{dimColor:!0},H7.default.createElement(A8,{chord:"c",action:"copy",parens:!0}))),H7.default.createElement(yq,{url:k})),H7.default.createElement(u,{marginLeft:3,flexDirection:"column"},H7.default.createElement(T,{color:"permission"},"Press ",H7.default.createElement(T,{bold:!0},"Enter")," after authenticating in your browser."),H7.default.createElement(T,{dimColor:!0,italic:!0},H7.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"}))));if(R)return H7.default.createElement(u,{flexDirection:"column",gap:1,padding:1,tabIndex:0,autoFocus:!0,onKeyDown:H6},H7.default.createElement(T,{color:"claude"},"Clear authentication for ",q.name),B?H7.default.createElement(H7.default.Fragment,null,H7.default.createElement(T,null,'Find the MCP server in the browser and click "Disconnect".'),C&&H7.default.createElement(u,{flexDirection:"column"},H7.default.createElement(u,null,H7.default.createElement(T,{dimColor:!0},"If your browser didn't open automatically, copy this URL manually"," "),S?H7.default.createElement(T,{color:"success"},"(Copied!)"):H7.default.createElement(T,{dimColor:!0},H7.default.createElement(A8,{chord:"c",action:"copy",parens:!0}))),H7.default.createElement(yq,{url:C})),H7.default.createElement(u,{marginLeft:3,flexDirection:"column"},H7.default.createElement(T,{color:"permission"},"Press ",H7.default.createElement(T,{bold:!0},"Enter")," when done."),H7.default.createElement(T,{dimColor:!0,italic:!0},H7.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))):H7.default.createElement(H7.default.Fragment,null,H7.default.createElement(T,null,'This will open claude.ai in the browser. Find the MCP server in the list and click "Disconnect".'),H7.default.createElement(u,{marginLeft:3,flexDirection:"column"},H7.default.createElement(T,{color:"permission"},"Press"," ",H7.default.createElement(A8,{chord:"enter",action:"open the browser",bold:!0}),"."),H7.default.createElement(T,{dimColor:!0,italic:!0},H7.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))));if(Z)return H7.default.createElement(u,{flexDirection:"column",gap:1,padding:1},H7.default.createElement(T,{color:"text"},"Connecting to ",H7.default.createElement(T,{bold:!0},q.name),"…"),H7.default.createElement(u,null,H7.default.createElement(Y5,null),H7.default.createElement(T,null," Establishing connection to MCP server")),H7.default.createElement(T,{dimColor:!0},"This may take a few moments."));let W6=[];if(q.client.type==="disabled")W6.push({label:"Enable",value:"toggle-enabled"});if(q.client.type==="connected"&&K>0)W6.push({label:"View tools",value:"tools"});if(q.config.type==="claudeai-proxy"){if(q.client.type==="connected")W6.push({label:"Clear authentication",value:"claudeai-clear-auth"});else if(q.client.type!=="disabled")W6.push({label:"Authenticate",value:"claudeai-auth"})}else if(!q.config.headersHelper){if(i)W6.push({label:"Re-authenticate",value:"reauth"}),W6.push({label:"Clear authentication",value:"clear-auth"});if(!i)W6.push({label:"Authenticate",value:"auth"})}let V6=q.config.type!=="claudeai-proxy"&&!!q.config.headersHelper;if(q.client.type!=="disabled"){if(q.client.type!=="needs-auth"||V6)W6.push({label:"Reconnect",value:"reconnectMcpServer"});W6.push({label:"Disable",value:"toggle-enabled"})}if(W6.length===0)W6.push({label:"Back",value:"back"});return H7.default.createElement(u,{flexDirection:"column"},H7.default.createElement(u,{flexDirection:"column",paddingX:1,borderStyle:A?void 0:"round"},H7.default.createElement(u,{marginBottom:1},H7.default.createElement(T,{bold:!0},q6," MCP Server")),H7.default.createElement(u,{flexDirection:"column",gap:0},H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"Status: "),q.client.type==="disabled"?H7.default.createElement(T,null,d7("inactive",O)(e6.radioOff)," disabled"):q.client.type==="connected"?H7.default.createElement(T,null,d7("success",O)(e6.tick)," connected"):q.client.type==="pending"?H7.default.createElement(H7.default.Fragment,null,H7.default.createElement(T,{dimColor:!0},e6.radioOff),H7.default.createElement(T,null," connecting…")):q.client.type==="needs-auth"?H7.default.createElement(T,null,d7("warning",O)(e6.triangleUpOutline)," needs authentication"):H7.default.createElement(T,null,d7("error",O)(e6.cross)," failed")),q.transport!=="claudeai-proxy"&&H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"Auth: "),i?H7.default.createElement(T,null,d7("success",O)(e6.tick)," authenticated"):H7.default.createElement(T,null,d7("error",O)(e6.cross)," not authenticated")),H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"URL: "),H7.default.createElement(T,{dimColor:!0},q.config.url)),H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"Config location: "),H7.default.createElement(T,{dimColor:!0},rk(q.scope))),q.client.type==="connected"&&H7.default.createElement(Ei8,{serverToolsCount:K,serverPromptsCount:o,serverResourcesCount:M.resources[q.name]?.length||0}),q.client.type==="connected"&&K>0&&H7.default.createElement(u,null,H7.default.createElement(T,{bold:!0},"Tools: "),H7.default.createElement(T,{dimColor:!0},K," tools"))),J&&H7.default.createElement(u,{marginTop:1},H7.default.createElement(T,{color:"error"},"Error: ",J)),W6.length>0&&H7.default.createElement(u,{marginTop:1},H7.default.createElement(A1,{options:W6,onChange:async(f6)=>{switch(f6){case"tools":_();break;case"auth":case"reauth":await X6();break;case"clear-auth":await M6();break;case"claudeai-auth":await r();break;case"claudeai-clear-auth":t();break;case"reconnectMcpServer":G(!0);try{let G6=await O6(q.name);if(q.config.type==="claudeai-proxy")d("tengu_claudeai_mcp_reconnect",{success:G6.client.type==="connected"});let{message:k6}=yi8(G6,q.name,{hasHeadersHelper:V6});Y?.(k6)}catch(G6){if(q.config.type==="claudeai-proxy")d("tengu_claudeai_mcp_reconnect",{success:!1});Y?.($_8(G6,q.name))}finally{G(!1)}break;case"toggle-enabled":await Y6();break;case"back":z();break}},onCancel:z}))),H7.default.createElement(u,{marginTop:1},H7.default.createElement(T,{dimColor:!0,italic:!0},w.pending?H7.default.createElement(H7.default.Fragment,null,"Press ",w.keyName," again to exit"):H7.default.createElement(z1,null,H7.default.createElement(A8,{chord:["up","down"],format:{arrowSep:""},action:"navigate"}),H7.default.createElement(A8,{chord:"enter",action:"select"}),H7.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}var H7;var Li8=L(()=>{Qq();C8();z3();C$();I4();HX();g6();C7();me();oW();B_6();iD();N7();T7();Nj();m8();U8();bK();g_();Nq();u7();Ej();NY();_w7();H7=K6(P6(),1)});function j_8({server:q,serverToolsCount:K,onViewTools:_,onCancel:z,onComplete:Y,borderless:A=!1}){let[O]=Zq(),w=$3(),$=M8((Z)=>Z.mcp),j=Nx6(),H=m_6(),[J,X]=M3.useState(!1),M=M3.default.useCallback(async()=>{let Z=q.client.type!=="disabled";try{await H(q.name),z()}catch(G){Y(`Failed to ${Z?"disable":"enable"} MCP server '${q.name}': ${b6(G)}`)}},[q.client.type,q.name,H,z,Y]),P=zv(String(q.name)),W=Cp8($.commands,q.name).length,D=[];if(q.client.type!=="disabled"&&K>0)D.push({label:"View tools",value:"tools"});if(q.client.type!=="disabled")D.push({label:"Reconnect",value:"reconnectMcpServer"});if(D.push({label:q.client.type!=="disabled"?"Disable":"Enable",value:"toggle-enabled"}),D.length===0)D.push({label:"Back",value:"back"});if(J)return M3.default.createElement(u,{flexDirection:"column",gap:1,padding:1},M3.default.createElement(T,{color:"text"},"Reconnecting to ",M3.default.createElement(T,{bold:!0},q.name)),M3.default.createElement(u,null,M3.default.createElement(Y5,null),M3.default.createElement(T,null," Restarting MCP server process")),M3.default.createElement(T,{dimColor:!0},"This may take a few moments."));return M3.default.createElement(u,{flexDirection:"column"},M3.default.createElement(u,{flexDirection:"column",paddingX:1,borderStyle:A?void 0:"round"},M3.default.createElement(u,{marginBottom:1},M3.default.createElement(T,{bold:!0},P," MCP Server")),M3.default.createElement(u,{flexDirection:"column",gap:0},M3.default.createElement(Wn,{box:"plain",columns:[{bold:!0},{}]},M3.default.createElement(Wn.Row,null,M3.default.createElement(M3.default.Fragment,null,"Status:"),q.client.type==="disabled"?M3.default.createElement(T,null,d7("inactive",O)(e6.radioOff)," disabled"):q.client.type==="connected"?M3.default.createElement(T,null,d7("success",O)(e6.tick)," connected"):q.client.type==="pending"?M3.default.createElement(T,null,M3.default.createElement(T,{dimColor:!0},e6.radioOff)," connecting…"):M3.default.createElement(T,null,d7("error",O)(e6.cross)," failed")),M3.default.createElement(Wn.Row,null,M3.default.createElement(M3.default.Fragment,null,"Command:"),M3.default.createElement(T,{dimColor:!0},q.config.command)),q.config.args&&q.config.args.length>0&&M3.default.createElement(Wn.Row,null,M3.default.createElement(M3.default.Fragment,null,"Args:"),M3.default.createElement(T,{dimColor:!0},q.config.args.join(" "))),M3.default.createElement(Wn.Row,null,M3.default.createElement(M3.default.Fragment,null,"Config location:"),M3.default.createElement(T,{dimColor:!0},rk(my(q.name)?.scope??"dynamic")))),q.client.type==="connected"&&M3.default.createElement(Ei8,{serverToolsCount:K,serverPromptsCount:W,serverResourcesCount:$.resources[q.name]?.length||0}),q.client.type==="connected"&&K>0&&M3.default.createElement(u,null,M3.default.createElement(T,{bold:!0},"Tools: "),M3.default.createElement(T,{dimColor:!0},K," tools"))),D.length>0&&M3.default.createElement(u,{marginTop:1},M3.default.createElement(A1,{options:D,onChange:async(Z)=>{if(Z==="tools")_();else if(Z==="reconnectMcpServer"){X(!0);try{let G=await j(q.name),{message:f}=yi8(G,q.name);Y?.(f)}catch(G){Y?.($_8(G,q.name))}finally{X(!1)}}else if(Z==="toggle-enabled")await M();else if(Z==="back")z()},onCancel:z}))),M3.default.createElement(u,{marginTop:1},M3.default.createElement(T,{dimColor:!0,italic:!0},w.pending?M3.default.createElement(M3.default.Fragment,null,"Press ",w.keyName," again to exit"):M3.default.createElement(z1,null,M3.default.createElement(A8,{chord:["up","down"],format:{arrowSep:""},action:"navigate"}),M3.default.createElement(A8,{chord:"enter",action:"select"}),M3.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}var M3;var hi8=L(()=>{Qq();C$();g6();rD();B_6();iD();N7();m8();bK();g_();Nq();u7();aA7();Ej();_w7();M3=K6(P6(),1)});function H_8(q){let K=s(44),{tool:_,server:z,onBack:Y}=q,[A,O]=f2.default.useState(""),w,$;if(K[0]!==z.name||K[1]!==_){$=fX8(_.name,z.name);let F=_.userFacingName?_.userFacingName({}):$;w=GX8(F),K[0]=z.name,K[1]=_,K[2]=w,K[3]=$}else w=K[2],$=K[3];let j=w,H;if(K[4]!==_)H=_.isReadOnly?.({})??!1,K[4]=_,K[5]=H;else H=K[5];let J=H,X;if(K[6]!==_)X=_.isDestructive?.({})??!1,K[6]=_,K[7]=X;else X=K[7];let M=X,P;if(K[8]!==_)P=_.isOpenWorld?.({})??!1,K[8]=_,K[9]=P;else P=K[9];let W=P,D,Z;if(K[10]!==_)D=()=>{(async function(){try{let g=await _.description({},{isNonInteractiveSession:!1,toolPermissionContext:{mode:"default",additionalWorkingDirectories:new Map,alwaysAllowRules:{},alwaysDenyRules:{},alwaysAskRules:{},isBypassPermissionsModeAvailable:!1},tools:[]});O(g)}catch{O("Failed to load description")}})()},Z=[_],K[10]=_,K[11]=D,K[12]=Z;else D=K[11],Z=K[12];f2.default.useEffect(D,Z);let G;if(K[13]!==J)G=J&&f2.default.createElement(T,{color:"success"}," [read-only]"),K[13]=J,K[14]=G;else G=K[14];let f;if(K[15]!==M)f=M&&f2.default.createElement(T,{color:"error"}," [destructive]"),K[15]=M,K[16]=f;else f=K[16];let v;if(K[17]!==W)v=W&&f2.default.createElement(T,{dimColor:!0}," [open-world]"),K[17]=W,K[18]=v;else v=K[18];let V;if(K[19]!==j||K[20]!==G||K[21]!==f||K[22]!==v)V=f2.default.createElement(f2.default.Fragment,null,j,G,f,v),K[19]=j,K[20]=G,K[21]=f,K[22]=v,K[23]=V;else V=K[23];let k=V,N;if(K[24]===Symbol.for("react.memo_cache_sentinel"))N=f2.default.createElement(T,{bold:!0},"Tool name: "),K[24]=N;else N=K[24];let R;if(K[25]!==$)R=f2.default.createElement(u,null,N,f2.default.createElement(T,{dimColor:!0},$)),K[25]=$,K[26]=R;else R=K[26];let h;if(K[27]===Symbol.for("react.memo_cache_sentinel"))h=f2.default.createElement(T,{bold:!0},"Full name: "),K[27]=h;else h=K[27];let C;if(K[28]!==_.name)C=f2.default.createElement(u,null,h,f2.default.createElement(T,{dimColor:!0},_.name)),K[28]=_.name,K[29]=C;else C=K[29];let x;if(K[30]!==A)x=A&&f2.default.createElement(u,{flexDirection:"column",marginTop:1},f2.default.createElement(T,{bold:!0},"Description:"),f2.default.createElement(T,{wrap:"wrap"},A)),K[30]=A,K[31]=x;else x=K[31];let B;if(K[32]!==_.inputJSONSchema)B=_.inputJSONSchema&&_.inputJSONSchema.properties&&Object.keys(_.inputJSONSchema.properties).length>0&&f2.default.createElement(u,{flexDirection:"column",marginTop:1},f2.default.createElement(T,{bold:!0},"Parameters:"),f2.default.createElement(u,{marginLeft:2,flexDirection:"column"},Object.entries(_.inputJSONSchema.properties).map((F)=>{let[U,g]=F,n=_.inputJSONSchema?.required?.includes(U);return f2.default.createElement(T,{key:U},"• ",U,f2.default.createElement(CP6,{when:n??!1},"required"),":"," ",f2.default.createElement(T,{dimColor:!0},typeof g==="object"&&g&&"type"in g?String(g.type):"unknown"),typeof g==="object"&&g&&"description"in g&&f2.default.createElement(T,{dimColor:!0}," - ",String(g.description)))}))),K[32]=_.inputJSONSchema,K[33]=B;else B=K[33];let m;if(K[34]!==R||K[35]!==C||K[36]!==x||K[37]!==B)m=f2.default.createElement(u,{flexDirection:"column"},R,C,x,B),K[34]=R,K[35]=C,K[36]=x,K[37]=B,K[38]=m;else m=K[38];let S;if(K[39]!==Y||K[40]!==z.name||K[41]!==m||K[42]!==k)S=f2.default.createElement(R1,{title:k,subtitle:z.name,onCancel:Y,inputGuide:yIY},m),K[39]=Y,K[40]=z.name,K[41]=m,K[42]=k,K[43]=S;else S=K[43];return S}function yIY(q){return q.pending?f2.default.createElement(T,null,"Press ",q.keyName," again to exit"):f2.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"})}var f2;var Ri8=L(()=>{o6();g6();fh();bK();Xi8();S4();f2=K6(P6(),1)});function J_8(q){let K=s(21),{server:_,onSelectTool:z,onBack:Y}=q,A=M8(hIY),O;q:{if(_.client.type!=="connected"){let Z;if(K[0]===Symbol.for("react.memo_cache_sentinel"))Z=[],K[0]=Z;else Z=K[0];O=Z;break q}let D;if(K[1]!==A||K[2]!==_.name)D=Ll(A,_.name),K[1]=A,K[2]=_.name,K[3]=D;else D=K[3];O=D}let w=O,$;if(K[4]!==_.name||K[5]!==w){let D;if(K[7]!==_.name)D=(Z,G)=>{let f=fX8(Z.name,_.name),v=Z.userFacingName?Z.userFacingName({}):f,V=GX8(v),k=Z.isReadOnly?.({})??!1,N=Z.isDestructive?.({})??!1,R=Z.isOpenWorld?.({})??!1,h=[];if(k)h.push("read-only");if(N)h.push("destructive");if(R)h.push("open-world");return{label:V,value:G.toString(),description:h.length>0?h.join(", "):void 0,descriptionColor:N?"error":k?"success":void 0}},K[7]=_.name,K[8]=D;else D=K[8];$=w.map(D),K[4]=_.name,K[5]=w,K[6]=$}else $=K[6];let j=$,H=`Tools for ${_.name}`,J=w.length,X;if(K[9]!==w.length)X=O7(w.length,"tool"),K[9]=w.length,K[10]=X;else X=K[10];let M=`${J} ${X}`,P;if(K[11]!==Y||K[12]!==z||K[13]!==w||K[14]!==j)P=w.length===0?ne.default.createElement(T,{dimColor:!0},"No tools available"):ne.default.createElement(A1,{options:j,onChange:(D)=>{let Z=parseInt(D),G=w[Z];if(G)z(G,Z)},onCancel:Y}),K[11]=Y,K[12]=z,K[13]=w,K[14]=j,K[15]=P;else P=K[15];let W;if(K[16]!==Y||K[17]!==H||K[18]!==M||K[19]!==P)W=ne.default.createElement(R1,{title:H,subtitle:M,onCancel:Y,inputGuide:LIY},P),K[16]=Y,K[17]=H,K[18]=M,K[19]=P,K[20]=W;else W=K[20];return W}function LIY(q){return q.pending?ne.default.createElement(T,null,"Press ",q.keyName," again to exit"):ne.default.createElement(z1,null,ne.default.createElement(A8,{chord:["up","down"],format:{arrowSep:""},action:"navigate"}),ne.default.createElement(A8,{chord:"enter",action:"select"}),ne.default.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"}))}function hIY(q){return q.mcp.tools}var ne;var Si8=L(()=>{o6();g6();fh();iD();N7();bK();g_();Nq();S4();u7();ne=K6(P6(),1)});function Ci8(q){let K=s(66),{onComplete:_}=q,z=M8(bIY),Y=M8(CIY),A=z.clients,O;if(K[0]===Symbol.for("react.memo_cache_sentinel"))O={type:"list"},K[0]=O;else O=K[0];let[w,$]=Nu.default.useState(O),j;if(K[1]===Symbol.for("react.memo_cache_sentinel"))j=[],K[1]=j;else j=K[1];let[H,J]=Nu.default.useState(j),X;if(K[2]!==Y.allAgents)X=D_K(Y.allAgents),K[2]=Y.allAgents,K[3]=X;else X=K[3];let M=X,P;if(K[4]!==A)P=A.filter(SIY).sort(RIY),K[4]=A,K[5]=P;else P=K[5];let W=P,D,Z;if(K[6]!==W||K[7]!==z.tools)D=()=>{let v=!1;return async function(){let N=await Promise.all(W.map(async(R)=>{let h=R.config.scope,C=R.config.type==="sse",x=R.config.type==="http",B=R.config.type==="claudeai-proxy",m=void 0;if(C||x){let U=await new jP6(R.name,R.config).tokens(),g=qW()!==null&&R.type==="connected",c=R.type==="connected"&&Ll(z.tools,R.name).length>0;m=Boolean(U)||g||c}let S={name:R.name,client:R,scope:h};if(B)return{...S,transport:"claudeai-proxy",isAuthenticated:!1,config:R.config};else if(C)return{...S,transport:"sse",isAuthenticated:m,config:R.config};else if(x)return{...S,transport:"http",isAuthenticated:m,config:R.config};else return{...S,transport:"stdio",config:R.config}}));if(v)return;J(N)}(),()=>{v=!0}},Z=[W,z.tools],K[6]=W,K[7]=z.tools,K[8]=D,K[9]=Z;else D=K[8],Z=K[9];Nu.default.useEffect(D,Z);let G,f;if(K[10]!==M.length||K[11]!==W.length||K[12]!==_||K[13]!==H.length)G=()=>{if(H.length===0&&W.length>0)return;if(H.length===0&&M.length===0)_("No MCP servers configured. Please run /doctor if this is unexpected. Otherwise, run `claude mcp --help` or visit https://code.claude.com/docs/en/mcp to learn more.")},f=[H.length,W.length,M.length,_],K[10]=M.length,K[11]=W.length,K[12]=_,K[13]=H.length,K[14]=G,K[15]=f;else G=K[14],f=K[15];switch(Nu.useEffect(G,f),w.type){case"list":{let v,V;if(K[16]===Symbol.for("react.memo_cache_sentinel"))V=(N)=>$({type:"server-menu",server:N}),v=(N)=>$({type:"agent-server-menu",agentServer:N}),K[16]=v,K[17]=V;else v=K[16],V=K[17];let k;if(K[18]!==M||K[19]!==_||K[20]!==H||K[21]!==w.defaultTab)k=Nu.default.createElement(nO7,{servers:H,agentServers:M,onSelectServer:V,onSelectAgentServer:v,onComplete:_,defaultTab:w.defaultTab}),K[18]=M,K[19]=_,K[20]=H,K[21]=w.defaultTab,K[22]=k;else k=K[22];return k}case"server-menu":{let v;if(K[23]!==z.tools||K[24]!==w.server.name)v=Ll(z.tools,w.server.name),K[23]=z.tools,K[24]=w.server.name,K[25]=v;else v=K[25];let V=v,k=w.server.transport==="claudeai-proxy"?"claude.ai":"Claude Code";if(w.server.transport==="stdio"){let N;if(K[26]!==w.server)N=()=>$({type:"server-tools",server:w.server}),K[26]=w.server,K[27]=N;else N=K[27];let R;if(K[28]!==k)R=()=>$({type:"list",defaultTab:k}),K[28]=k,K[29]=R;else R=K[29];let h;if(K[30]!==_||K[31]!==V.length||K[32]!==N||K[33]!==R||K[34]!==w.server)h=Nu.default.createElement(j_8,{server:w.server,serverToolsCount:V.length,onViewTools:N,onCancel:R,onComplete:_}),K[30]=_,K[31]=V.length,K[32]=N,K[33]=R,K[34]=w.server,K[35]=h;else h=K[35];return h}else{let N;if(K[36]!==w.server)N=()=>$({type:"server-tools",server:w.server}),K[36]=w.server,K[37]=N;else N=K[37];let R;if(K[38]!==k)R=()=>$({type:"list",defaultTab:k}),K[38]=k,K[39]=R;else R=K[39];let h;if(K[40]!==_||K[41]!==V.length||K[42]!==N||K[43]!==R||K[44]!==w.server)h=Nu.default.createElement(FP6,{server:w.server,serverToolsCount:V.length,onViewTools:N,onCancel:R,onComplete:_}),K[40]=_,K[41]=V.length,K[42]=N,K[43]=R,K[44]=w.server,K[45]=h;else h=K[45];return h}}case"server-tools":{let v,V;if(K[46]!==w.server)V=(N,R)=>$({type:"server-tool-detail",server:w.server,toolIndex:R}),v=()=>$({type:"server-menu",server:w.server}),K[46]=w.server,K[47]=v,K[48]=V;else v=K[47],V=K[48];let k;if(K[49]!==v||K[50]!==V||K[51]!==w.server)k=Nu.default.createElement(J_8,{server:w.server,onSelectTool:V,onBack:v}),K[49]=v,K[50]=V,K[51]=w.server,K[52]=k;else k=K[52];return k}case"server-tool-detail":{let v;if(K[53]!==z.tools||K[54]!==w.server.name)v=Ll(z.tools,w.server.name),K[53]=z.tools,K[54]=w.server.name,K[55]=v;else v=K[55];let k=v[w.toolIndex];if(!k)return $({type:"server-tools",server:w.server}),null;let N;if(K[56]!==w.server)N=()=>$({type:"server-tools",server:w.server}),K[56]=w.server,K[57]=N;else N=K[57];let R;if(K[58]!==N||K[59]!==k||K[60]!==w.server)R=Nu.default.createElement(H_8,{tool:k,server:w.server,onBack:N}),K[58]=N,K[59]=k,K[60]=w.server,K[61]=R;else R=K[61];return R}case"agent-server-menu":{let v;if(K[62]===Symbol.for("react.memo_cache_sentinel"))v=()=>$({type:"list",defaultTab:"Agents"}),K[62]=v;else v=K[62];let V;if(K[63]!==_||K[64]!==w.agentServer)V=Nu.default.createElement(cO7,{agentServer:w.agentServer,onCancel:v,onComplete:_}),K[63]=_,K[64]=w.agentServer,K[65]=V;else V=K[65];return V}}}function RIY(q,K){return q.name.localeCompare(K.name)}function SIY(q){return q.name!=="ide"}function CIY(q){return q.agentDefinitions}function bIY(q){return q.mcp}var Nu;var ppK=L(()=>{o6();me();iD();N7();ox();lO7();iO7();Li8();hi8();Ri8();Si8();Nu=K6(P6(),1)});var FpK=L(()=>{lO7();iO7();Kw7();Li8();ppK();hi8();Ri8();Si8()});var UpK={};h8(UpK,{settingSourceToScope:()=>mIY,isPersistableScope:()=>uIY,installSelectedPlugins:()=>pIY,getPluginEditableScopes:()=>p_6,getInstalledPlugins:()=>gpK,findMissingPlugins:()=>BIY,checkEnabledPlugins:()=>xIY});import{join as IIY}from"path";async function xIY(){let q=v7(),K=[],_=ej6();for(let[z,Y]of Object.entries(_))if(z.includes("@")&&Y)K.push(z);if(q.enabledPlugins)for(let[z,Y]of Object.entries(q.enabledPlugins)){if(!z.includes("@"))continue;let A=K.indexOf(z);if(Y){if(A===-1)K.push(z)}else if(A!==-1)K.splice(A,1)}return K}function p_6(){let q=new Map,K=ej6();for(let[z,Y]of Object.entries(K)){if(!z.includes("@"))continue;if(Y===!0)q.set(z,"flag");else if(Y===!1)q.delete(z)}let _=[{scope:"managed",source:"policySettings"},{scope:"user",source:"userSettings"},{scope:"project",source:"projectSettings"},{scope:"local",source:"localSettings"},{scope:"flag",source:"flagSettings"}];for(let{scope:z,source:Y}of _){let A=E1(Y);if(!A?.enabledPlugins)continue;for(let[O,w]of Object.entries(A.enabledPlugins)){if(!O.includes("@"))continue;if(O in K&&K[O]!==w)E(`Plugin ${O} from --add-dir (${K[O]}) overridden by ${Y} (${w})`);if(w===!0)q.set(O,z);else if(w===!1)q.delete(O)}}return E(`Found ${q.size} enabled plugins with scopes: ${Array.from(q.entries()).map(([z,Y])=>`${z}(${Y})`).join(", ")}`),q}function uIY(q){return q!=="flag"}function mIY(q){return ZQ1[q]}async function gpK(){w_7().catch((_)=>{j6(_)});let q=N68(),K=Object.keys(q.plugins);return E(`Found ${K.length} installed plugins`),K}async function BIY(q){try{let K=await gpK(),_=q.filter((A)=>!K.includes(A));return(await Promise.all(_.map(async(A)=>{try{let O=await mf(A);return{pluginId:A,found:O!==null&&O!==void 0}}catch(O){return E(`Failed to check plugin ${A} in marketplace: ${O}`),{pluginId:A,found:!1}}}))).filter(({found:A})=>A).map(({pluginId:A})=>A)}catch(K){return j6(K),[]}}async function pIY(q,K,_="user"){let z=_!=="user"?b8():void 0,Y=jc(_),A=E1(Y),O={...A?.enabledPlugins},w=[],$=[];for(let j=0;j<q.length;j++){let H=q[j];if(!H)continue;if(K)K(H,j+1,q.length);try{let J=await mf(H);if(!J){$.push({name:H,error:"Plugin not found in any marketplace"});continue}let{entry:X,marketplaceInstallLocation:M}=J;if(!uQ6(X.source))await Z68(H,X,_,z);else WG4({pluginId:H,installPath:IIY(M,X.source),version:X.version},_,z);O[H]=!0,w.push(H)}catch(J){let X=J instanceof Error?J.message:String(J);$.push({name:H,error:X}),j6(J)}}return P7(Y,{...A,enabledPlugins:O}),{installed:w,failed:$}}var X_8=L(()=>{n7();K8();U8();a1();WS8();yD();m$();aW();Y56();Hv()});import{homedir as FIY}from"os";import{resolve as gIY}from"path";async function bi8(q){let K=q.trim(),_=V8(),z=K.match(/^([a-zA-Z0-9._-]+@[^:]+:.+?(?:\.git)?)(#(.+))?$/);if(z?.[1]){let O=z[1],w=z[3];return w?{source:"git",url:O,ref:w}:{source:"git",url:O}}if(K.startsWith("http://")||K.startsWith("https://")){let O=K.match(/^([^#]+)(#(.+))?$/),w=O?.[1]||K,$=O?.[3];if(w.endsWith(".git")||w.includes("/_git/"))return $?{source:"git",url:w,ref:$}:{source:"git",url:w};let j;try{j=new URL(w)}catch(H){return{source:"url",url:w}}if(j.hostname==="github.com"||j.hostname==="www.github.com"){if(j.pathname.match(/^\/([^/]+\/[^/]+?)(\/|\.git|$)/)?.[1]){let J=w.endsWith(".git")?w:`${w}.git`;return $?{source:"git",url:J,ref:$}:{source:"git",url:J}}}return{source:"url",url:w}}let A=process.platform==="win32"&&(K.startsWith(".\\")||K.startsWith("..\\")||/^[a-zA-Z]:[/\\]/.test(K));if(K.startsWith("./")||K.startsWith("../")||K.startsWith("/")||K.startsWith("~")||A){let O=gIY(K.startsWith("~")?K.replace(/^~/,FIY()):K),w;try{w=await _.stat(O)}catch($){let j=Q1($);return{error:j==="ENOENT"?`Path does not exist: ${O}`:`Cannot access path: ${O} (${j??$})`}}if(w.isFile())if(O.endsWith(".json"))return{source:"file",path:O};else return{error:`File path must point to a .json file (marketplace.json), but got: ${O}`};else if(w.isDirectory())return{source:"directory",path:O};else return{error:`Path is neither a file nor a directory: ${O}`}}if(K.includes("/")&&!K.startsWith("@")){if(K.includes(":"))return null;let O=K.match(/^([^#@]+)(?:[#@](.+))?$/),w=O?.[1]||K,$=O?.[2];return $?{source:"github",repo:w,ref:$}:{source:"github",repo:w}}return null}var zw7=L(()=>{m8();Yq()});function QpK({inputValue:q,setInputValue:K,cursorOffset:_,setCursorOffset:z,error:Y,setError:A,result:O,setResult:w,setViewState:$,onAddComplete:j,cliMode:H=!1}){let J=gP6.useRef(!1),[X,M]=gP6.useState(!1),[P,W]=gP6.useState(""),D=async()=>{let Z=q.trim();if(!Z){A("Please enter a marketplace source");return}let G=await bi8(Z);if(!G){A("Invalid marketplace source format. Try: owner/repo, https://..., or ./path");return}if("error"in G){A(G.error);return}A(null);try{M(!0),W("");let{name:f,resolvedSource:v}=await M_6(G,(k)=>{W(k)});h38(f,{source:v}),YO();let V=G.source;if(G.source==="github")V=G.repo;if(d("tengu_marketplace_added",{source_type:V}),j)await j();if(W(""),M(!1),H)w(`Successfully added marketplace: ${f}`);else $({type:"browse-marketplace",targetMarketplace:f})}catch(f){let v=r1(f);if(j6(v),A(v.message),W(""),M(!1),H)w(`Error: ${v.message}`);else w(null)}};return gP6.useEffect(()=>{if(q&&!J.current&&!Y&&!O)J.current=!0,D()},[]),P3.createElement(u,{flexDirection:"column"},P3.createElement(u,{flexDirection:"column",paddingX:1,borderStyle:"round"},P3.createElement(u,{marginBottom:1},P3.createElement(T,{bold:!0},"Add Marketplace")),P3.createElement(u,{flexDirection:"column"},P3.createElement(T,null,"Enter marketplace source:"),P3.createElement(T,{dimColor:!0},"Examples:"),P3.createElement(T,{dimColor:!0}," · owner/repo (GitHub)"),P3.createElement(T,{dimColor:!0}," · git@github.com:owner/repo.git (SSH)"),P3.createElement(T,{dimColor:!0}," · https://example.com/marketplace.json"),P3.createElement(T,{dimColor:!0}," · ./path/to/marketplace"),P3.createElement(u,{marginTop:1},P3.createElement(l4,{value:q,onChange:K,onSubmit:D,columns:80,cursorOffset:_,onChangeCursorOffset:z,focus:!0,showCursor:!0}))),X&&P3.createElement(u,{marginTop:1},P3.createElement(Y5,null),P3.createElement(T,null,P||"Adding marketplace to configuration…")),Y&&P3.createElement(u,{marginTop:1},P3.createElement(T,{color:"error"},Y)),O&&P3.createElement(u,{marginTop:1},P3.createElement(T,null,O))),P3.createElement(u,{marginLeft:3},P3.createElement(T,{dimColor:!0,italic:!0},P3.createElement(z1,null,P3.createElement(A8,{chord:"enter",action:"add"}),P3.createElement(v1,{action:"confirm:no",context:"Settings",fallback:"Esc",description:"cancel"})))))}var P3,gP6;var dpK=L(()=>{C8();bK();Nq();u7();Ej();NY();g6();m8();U8();uR();m$();zw7();P3=K6(P6(),1),gP6=K6(P6(),1)});import{randomBytes as UIY}from"crypto";import{readFile as QIY,rename as dIY,unlink as cIY,writeFile as lIY}from"fs/promises";import{join as nIY}from"path";function cpK(){return nIY(gP(),iIY)}async function oIY(){let q=cpK();try{let K=await QIY(q,{encoding:"utf-8"}),_=n8(K);if(typeof _!=="object"||_===null||!("version"in _)||!("fetchedAt"in _)||!("counts"in _))return E("Install counts cache has invalid structure"),null;let z=_;if(z.version!==Yw7)return E(`Install counts cache version mismatch (got ${z.version}, expected ${Yw7})`),null;if(typeof z.fetchedAt!=="string"||!Array.isArray(z.counts))return E("Install counts cache has invalid structure"),null;let Y=new Date(z.fetchedAt).getTime();if(Number.isNaN(Y))return E("Install counts cache has invalid fetchedAt timestamp"),null;if(!z.counts.every((w)=>typeof w==="object"&&w!==null&&typeof w.plugin==="string"&&typeof w.unique_installs==="number"))return E("Install counts cache has malformed entries"),null;if(Date.now()-Y>rIY)return E("Install counts cache is stale (>24h old)"),null;return{version:z.version,fetchedAt:z.fetchedAt,counts:z.counts}}catch(K){if(Q1(K)!=="ENOENT")E(`Failed to load install counts cache: ${b6(K)}`);return null}}async function aIY(q){let K=cpK(),_=`${K}.${UIY(8).toString("hex")}.tmp`;try{let z=gP();await V8().mkdir(z);let Y=I6(q,null,2);await lIY(_,Y,{encoding:"utf-8",mode:384}),await dIY(_,K),E("Install counts cache saved successfully")}catch(z){j6(z);try{await cIY(_)}catch{}}}async function sIY(){E(`Fetching install counts from ${M_8}`);let q=performance.now();try{let K=await Z1.get(M_8,{timeout:1e4});if(!K.data?.plugins||!Array.isArray(K.data.plugins))throw Error("Invalid response format from install counts API");return ED("install_counts",M_8,"success",performance.now()-q),K.data.plugins}catch(K){throw ED("install_counts",M_8,"failure",performance.now()-q,Kx(K)),K}}async function Ex6(){let q=await oIY();if(q){E("Using cached install counts"),ED("install_counts",M_8,"cache_hit",0);let K=new Map;for(let _ of q.counts)K.set(_.plugin,_.unique_installs);return K}try{let K=await sIY(),_={version:Yw7,fetchedAt:new Date().toISOString(),counts:K};await aIY(_);let z=new Map;for(let Y of K)z.set(Y.plugin,Y.unique_installs);return z}catch(K){return j6(K),E(`Failed to fetch install counts: ${b6(K)}`),null}}function Ii8(q){if(q<1000)return String(q);if(q<1e6){let Y=(q/1000).toFixed(1);return Y.endsWith(".0")?`${Y.slice(0,-2)}K`:`${Y}K`}let _=(q/1e6).toFixed(1);return _.endsWith(".0")?`${_.slice(0,-2)}M`:`${_}M`}var Yw7=1,iIY="install-counts-cache.json",M_8="https://raw.githubusercontent.com/anthropics/claude-plugins-official/refs/heads/stats/stats/plugin-installs.json",rIY=86400000;var xi8=L(()=>{CK();K8();m8();Yq();U8();e8();Y68();Jy()});function tIY(q,K,_,z){let Y={};for(let A of q){let O=_[A],w=K[A]??"";if(O?.sensitive===!0&&w===""&&z?.[A]!==void 0)continue;if(O?.type==="number"){if(w.trim()==="")continue;let $=Number(w);Y[A]=Number.isNaN($)?w:$}else if(O?.type==="boolean")Y[A]=S6(w);else Y[A]=w}return Y}function P_8(q){let K=s(70),{title:_,subtitle:z,configSchema:Y,initialValues:A,onSave:O,onCancel:w}=q,$;if(K[0]!==Y)$=Object.keys(Y),K[0]=Y,K[1]=$;else $=K[1];let j=$,H;if(K[2]!==Y||K[3]!==A)H=(Y6)=>{if(Y[Y6]?.sensitive===!0)return"";let X6=A?.[Y6];return X6===void 0?"":String(X6)},K[2]=Y,K[3]=A,K[4]=H;else H=K[4];let J=H,[X,M]=$Z.useState(0),P;if(K[5]===Symbol.for("react.memo_cache_sentinel"))P={},K[5]=P;else P=K[5];let[W,D]=$Z.useState(P),Z;if(K[6]!==j[0]||K[7]!==J)Z=()=>j[0]?J(j[0]):"",K[6]=j[0],K[7]=J,K[8]=Z;else Z=K[8];let[G,f]=$Z.useState(Z),v=j[X],V=v?Y[v]:null,k;if(K[9]===Symbol.for("react.memo_cache_sentinel"))k={context:"Settings"},K[9]=k;else k=K[9];G1("confirm:no",w,k);let N;if(K[10]!==v||K[11]!==X||K[12]!==G||K[13]!==j||K[14]!==J)N=()=>{if(X<j.length-1&&v){D((X6)=>({...X6,[v]:G})),M(KxY);let Y6=j[X+1];f(Y6?J(Y6):"")}},K[10]=v,K[11]=X,K[12]=G,K[13]=j,K[14]=J,K[15]=N;else N=K[15];let R=N,h;if(K[16]!==Y||K[17]!==v||K[18]!==X||K[19]!==G||K[20]!==j||K[21]!==J||K[22]!==A||K[23]!==O||K[24]!==W)h=()=>{if(!v)return;let Y6={...W,[v]:G};if(X===j.length-1)O(tIY(j,Y6,Y,A));else{D(Y6),M(qxY);let X6=j[X+1];f(X6?J(X6):"")}},K[16]=Y,K[17]=v,K[18]=X,K[19]=G,K[20]=j,K[21]=J,K[22]=A,K[23]=O,K[24]=W,K[25]=h;else h=K[25];let C=h,x;if(K[26]!==C||K[27]!==R)x=function(X6){if(X6.key==="return"){X6.preventDefault(),C();return}if(X6.key==="tab"){X6.preventDefault(),R();return}if(X6.key==="backspace"||X6.key==="delete"){X6.preventDefault(),f(eIY);return}if(X6.ctrl||X6.meta)return;if(X6.key.length===1)X6.preventDefault(),f((M6)=>M6+X6.key)},K[26]=C,K[27]=R,K[28]=x;else x=K[28];let B=x,m;if(K[29]===Symbol.for("react.memo_cache_sentinel"))m=function(X6){X6.preventDefault(),f((M6)=>M6+(X6.text.split(/\r\n|\r|\n/,2)[0]??"").trim())},K[29]=m;else m=K[29];let S=m;if(!V||!v)return null;let F=V.sensitive===!0,U=V.required===!0,g;if(K[30]!==G||K[31]!==F)g=F?"*".repeat(N1(G)):G,K[30]=G,K[31]=F,K[32]=g;else g=K[32];let c=g,n=V.title||v,l;if(K[33]!==U)l=U&&$Z.default.createElement(T,{color:"error"}," *"),K[33]=U,K[34]=l;else l=K[34];let z6;if(K[35]!==n||K[36]!==l)z6=$Z.default.createElement(T,{bold:!0},n,l),K[35]=n,K[36]=l,K[37]=z6;else z6=K[37];let A6;if(K[38]!==V.description)A6=V.description&&$Z.default.createElement(T,{dimColor:!0},V.description),K[38]=V.description,K[39]=A6;else A6=K[39];let e;if(K[40]===Symbol.for("react.memo_cache_sentinel"))e=$Z.default.createElement(T,null,e6.pointerSmall," "),K[40]=e;else e=K[40];let i;if(K[41]!==c)i=$Z.default.createElement(T,null,c),K[41]=c,K[42]=i;else i=K[42];let O6;if(K[43]===Symbol.for("react.memo_cache_sentinel"))O6=$Z.default.createElement(T,null,"█"),K[43]=O6;else O6=K[43];let J6;if(K[44]!==i)J6=$Z.default.createElement(u,{marginTop:1},e,i,O6),K[44]=i,K[45]=J6;else J6=K[45];let $6;if(K[46]!==B||K[47]!==z6||K[48]!==A6||K[49]!==J6)$6=$Z.default.createElement(u,{flexDirection:"column",tabIndex:0,autoFocus:!0,onKeyDown:B,onPaste:S},z6,A6,J6),K[46]=B,K[47]=z6,K[48]=A6,K[49]=J6,K[50]=$6;else $6=K[50];let H6=X+1,q6;if(K[51]!==j.length||K[52]!==H6)q6=$Z.default.createElement(T,{dimColor:!0},"Field ",H6," of ",j.length),K[51]=j.length,K[52]=H6,K[53]=q6;else q6=K[53];let o;if(K[54]!==X||K[55]!==j.length)o=X<j.length-1&&$Z.default.createElement(T,{dimColor:!0},"Tab: Next field · Enter: Save and continue"),K[54]=X,K[55]=j.length,K[56]=o;else o=K[56];let _6;if(K[57]!==X||K[58]!==j.length)_6=X===j.length-1&&$Z.default.createElement(T,{dimColor:!0},"Enter: Save configuration"),K[57]=X,K[58]=j.length,K[59]=_6;else _6=K[59];let r;if(K[60]!==q6||K[61]!==o||K[62]!==_6)r=$Z.default.createElement(u,{flexDirection:"column"},q6,o,_6),K[60]=q6,K[61]=o,K[62]=_6,K[63]=r;else r=K[63];let t;if(K[64]!==w||K[65]!==z||K[66]!==$6||K[67]!==r||K[68]!==_)t=$Z.default.createElement(R1,{title:_,subtitle:z,onCancel:w,isCancelActive:!1},$6,r),K[64]=w,K[65]=z,K[66]=$6,K[67]=r,K[68]=_,K[69]=t;else t=K[69];return t}function eIY(q){return q.slice(0,-1)}function qxY(q){return q+1}function KxY(q){return q+1}var $Z;var Aw7=L(()=>{o6();Qq();S4();n5();g6();C7();Q8();$Z=K6(P6(),1)});async function ui8(q){let{enabled:K,disabled:_}=await sW();return[...K,..._].find((z)=>z.repository===q||z.source===q)}function yx6({plugin:q,pluginId:K,onDone:_}){let[z]=kn.useState(()=>{let j=[],H=Ch4(q);if(Object.keys(H).length>0)j.push({key:"top-level",title:`Configure ${q.name}`,subtitle:"Plugin options",schema:H,load:()=>ID(K),save:(X)=>Tb8(K,X,q.manifest.userConfig)});let J=H_K(q);for(let X of J)j.push({key:`channel:${X.server}`,title:`Configure ${X.displayName}`,subtitle:`Plugin: ${q.name}`,schema:X.configSchema,load:()=>IH6(K,X.server)??void 0,save:(M)=>Gb8(K,X.server,M,X.configSchema)});return j}),[Y,A]=kn.useState(0),O=kn.useRef(_);if(O.current=_,kn.useEffect(()=>{if(z.length===0)O.current("skipped")},[z.length]),z.length===0)return null;let w=z[Y];function $(j){try{w.save(j)}catch(J){_("error",b6(J));return}let H=Y+1;if(H<z.length)A(H);else _("configured")}return kn.createElement(P_8,{key:w.key,title:w.title,subtitle:w.subtitle,configSchema:w.schema,initialValues:w.load(),onSave:$,onCancel:()=>_("skipped")})}var kn;var mi8=L(()=>{m8();W88();WX6();vH();Gx();Aw7();kn=K6(P6(),1)});function Bi8(){let q=s(3),K;if(q[0]===Symbol.for("react.memo_cache_sentinel"))K=Wf4(),q[0]=K;else K=q[0];let _=K,z;if(q[1]===Symbol.for("react.memo_cache_sentinel"))z=UP6.createElement(T,{color:"claude"},e6.warning," "),q[1]=z;else z=q[1];let Y;if(q[2]===Symbol.for("react.memo_cache_sentinel"))Y=UP6.createElement(u,{marginBottom:1},z,UP6.createElement(T,{dimColor:!0,italic:!0},"Make sure you trust a plugin before installing, updating, or using it. Anthropic does not control what MCP servers, files, or other software are included in plugins and cannot verify that they will work as intended or that they won't change. See each plugin's homepage for more information.",_?` ${_}`:"")),q[2]=Y;else Y=q[2];return Y}var UP6;var Ow7=L(()=>{o6();Qq();g6();Xc();UP6=K6(P6(),1)});function F_6(q){if(q.entry.source&&typeof q.entry.source==="object"&&"source"in q.entry.source&&q.entry.source.source==="github"&&typeof q.entry.source==="object"&&"repo"in q.entry.source)return q.entry.source.repo;return null}function Lx6(q,K){let _=[{label:"Install for you (user scope)",action:"install-user"},{label:"Install for all collaborators on this repository (project scope)",action:"install-project"},{label:"Install for you, in this repo only (local scope)",action:"install-local"}];if(q)_.push({label:"Open homepage",action:"homepage"});if(K)_.push({label:"View on GitHub",action:"github"});return _.push({label:"Back to plugin list",action:"back"}),_}function lpK(q){let K=s(7),{hasSelection:_}=q,z;if(K[0]!==_)z=_&&ON.createElement(v1,{action:"plugin:install",context:"Plugin",fallback:"i",description:"install",bold:!0}),K[0]=_,K[1]=z;else z=K[1];let Y,A,O;if(K[2]===Symbol.for("react.memo_cache_sentinel"))Y=ON.createElement(v1,{action:"plugin:toggle",context:"Plugin",fallback:"Space",description:"toggle"}),A=ON.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"details"}),O=ON.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"}),K[2]=Y,K[3]=A,K[4]=O;else Y=K[2],A=K[3],O=K[4];let w;if(K[5]!==z)w=ON.createElement(u,{marginTop:1},ON.createElement(T,{dimColor:!0,italic:!0},ON.createElement(z1,null,z,Y,A,O))),K[5]=z,K[6]=w;else w=K[6];return w}var ON;var ww7=L(()=>{o6();bK();Nq();g6();ON=K6(P6(),1)});function QP6({totalItems:q,maxVisible:K=_xY,selectedIndex:_=0}){let z=q>K,Y=mS.useRef(0),A=mS.useMemo(()=>{if(!z)return 0;let G=Y.current;if(_<G)return Y.current=_,_;if(_>=G+K){let V=_-K+1;return Y.current=V,V}let f=Math.max(0,q-K),v=Math.min(G,f);return Y.current=v,v},[_,K,z,q]),O=A,w=Math.min(A+K,q),$=mS.useCallback((G)=>{if(!z)return G;return G.slice(O,w)},[z,O,w]),j=mS.useCallback((G)=>{return O+G},[O]),H=mS.useCallback((G)=>{return G>=O&&G<w},[O,w]),J=mS.useCallback((G)=>{},[]),X=mS.useCallback(()=>{},[]),M=mS.useCallback(()=>{},[]),P=mS.useCallback((G,f)=>{let v=Math.max(0,Math.min(G,q-1));f(v)},[q]),W=mS.useCallback((G,f)=>{return!1},[]),D=Math.max(1,Math.ceil(q/K));return{currentPage:Math.floor(A/K),totalPages:D,startIndex:O,endIndex:w,needsPagination:z,pageSize:K,getVisibleItems:$,toActualIndex:j,isOnCurrentPage:H,goToPage:J,nextPage:X,prevPage:M,handleSelectionChange:P,handlePageNavigation:W,scrollPosition:{current:_+1,total:q,canScrollUp:A>0,canScrollDown:A+K<q}}}var mS,_xY=5;var W_8=L(()=>{mS=K6(P6(),1)});function npK({error:q,setError:K,result:_,setResult:z,setViewState:Y,onInstallComplete:A,targetMarketplace:O,targetPlugin:w}){let[$,j]=G0.useState("marketplace-list"),[H,J]=G0.useState(null),[X,M]=G0.useState(null),[P,W]=G0.useState([]),[D,Z]=G0.useState([]),[G,f]=G0.useState(!0),[v,V]=G0.useState(null),[k,N]=G0.useState(0),[R,h]=G0.useState(new Set),[C,x]=G0.useState(new Set),B=QP6({totalItems:D.length,selectedIndex:k}),[m,S]=G0.useState(0),[F,U]=G0.useState(!1),[g,c]=G0.useState(null),[n,l]=G0.useState(null),z6=V1.useCallback(()=>{if($==="plugin-list")if(O)Y({type:"manage-marketplaces",targetMarketplace:O});else if(P.length===1)Y({type:"menu"});else j("marketplace-list"),J(null),h(new Set);else if($==="plugin-details")j("plugin-list"),M(null);else Y({type:"menu"})},[$,O,Y,P.length]);G1("confirm:no",z6,{context:"Confirmation"}),G0.useEffect(()=>{async function J6(){try{let $6=await Dz(),{marketplaces:H6,failures:q6}=await Rp($6),o=[];for(let{name:t,config:Y6,data:X6}of H6)if(X6){let M6=w7(X6.plugins,(W6)=>Hu(Jc(W6.name,t)));o.push({name:t,totalPlugins:X6.plugins.length,installedCount:M6,source:O68(Y6.source)})}o.sort((t,Y6)=>{if(t.name==="claude-plugin-directory")return-1;if(Y6.name==="claude-plugin-directory")return 1;return 0}),W(o);let _6=w7(H6,(t)=>t.data!==null),r=$L6(q6,_6);if(r)if(r.type==="warning")l(r.message+". Showing available marketplaces.");else throw Error(r.message);if(o.length===1&&!O&&!w){let t=o[0];if(t)J(t.name),j("plugin-list")}if(w){let t=null,Y6=null;for(let[X6]of Object.entries($6)){let M6=await xf(X6);if(M6){let W6=M6.plugins.find((V6)=>V6.name===w);if(W6){let V6=Jc(W6.name,X6);t={entry:W6,marketplaceName:X6,pluginId:V6,isInstalled:aM6(V6)},Y6=X6;break}}}if(t&&Y6){let X6=t.pluginId;if(aM6(X6))K(`Plugin '${X6}' is already installed globally. Use '/plugin' to manage existing plugins.`);else J(Y6),M(t),j("plugin-details")}else K(`Plugin "${w}" not found in any marketplace`)}else if(O)if(o.some((Y6)=>Y6.name===O))J(O),j("plugin-list");else K(`Marketplace "${O}" not found`)}catch($6){K($6 instanceof Error?$6.message:"Failed to load marketplaces")}finally{f(!1)}}J6()},[K,O,w]),G0.useEffect(()=>{if(!H)return;let J6=!1;async function $6(H6){f(!0);try{let q6=await xf(H6);if(J6)return;if(!q6)throw Error(`Failed to load marketplace: ${H6}`);let o=[];for(let _6 of q6.plugins){let r=Jc(_6.name,H6);if(Rk(r))continue;o.push({entry:_6,marketplaceName:H6,pluginId:r,isInstalled:aM6(r)})}try{let _6=await Ex6();if(J6)return;if(V(_6),_6)o.sort((r,t)=>{let Y6=_6.get(r.pluginId)??0,X6=_6.get(t.pluginId)??0;if(Y6!==X6)return X6-Y6;return r.entry.name.localeCompare(t.entry.name)});else o.sort((r,t)=>r.entry.name.localeCompare(t.entry.name))}catch(_6){if(J6)return;E(`Failed to fetch install counts: ${b6(_6)}`),o.sort((r,t)=>r.entry.name.localeCompare(t.entry.name))}Z(o),N(0),h(new Set)}catch(q6){if(J6)return;K(q6 instanceof Error?q6.message:"Failed to load plugins")}finally{f(!1)}}return $6(H),()=>{J6=!0}},[H,K]);let A6=async()=>{if(R.size===0)return;let J6=D.filter((o)=>R.has(o.pluginId));x(new Set(J6.map((o)=>o.pluginId)));let $6=0,H6=0,q6=[];for(let o of J6){let _6=await z56({pluginId:o.pluginId,entry:o.entry,marketplaceName:o.marketplaceName,scope:"user"});if(_6.success)$6++;else H6++,q6.push({name:o.entry.name,reason:_6.error})}if(x(new Set),h(new Set),YO(),H6===0){let o=`✓ Installed ${$6} ${O7($6,"plugin")}. Run /reload-plugins to activate.`;z(o)}else if($6===0)K(`Failed to install: ${wL6(q6,!0)}`);else{let o=`✓ Installed ${$6} of ${$6+H6} plugins. Failed: ${wL6(q6,!1)}. Run /reload-plugins to activate successfully installed plugins.`;z(o)}if($6>0){if(A)await A()}Y({type:"menu"})},e=async(J6,$6="user")=>{U(!0),c(null);let H6=await z56({pluginId:J6.pluginId,entry:J6.entry,marketplaceName:J6.marketplaceName,scope:$6});if(H6.success){let q6=await ui8(J6.pluginId);if(q6){U(!1),j({type:"plugin-options",plugin:q6,pluginId:J6.pluginId,depNote:H6.depNote});return}if(z(H6.message),A)await A();Y({type:"menu"})}else U(!1),c(H6.error)};G0.useEffect(()=>{if(q)z(q)},[q,z]),L7({"select:previous":()=>{if(k>0)N(k-1)},"select:next":()=>{if(k<P.length-1)N(k+1)},"select:accept":()=>{let J6=P[k];if(J6)J(J6.name),j("plugin-list")}},{context:"Select",isActive:$==="marketplace-list"}),L7({"select:previous":()=>{if(k>0)B.handleSelectionChange(k-1,N)},"select:next":()=>{if(k<D.length-1)B.handleSelectionChange(k+1,N)},"select:accept":()=>{if(k===D.length&&R.size>0)A6();else if(k<D.length){let J6=D[k];if(J6)if(J6.isInstalled)Y({type:"manage-plugins",targetPlugin:J6.entry.name,targetMarketplace:J6.marketplaceName});else M(J6),j("plugin-details"),S(0),c(null)}}},{context:"Select",isActive:$==="plugin-list"}),L7({"plugin:toggle":()=>{if(k<D.length){let J6=D[k];if(J6&&!J6.isInstalled){let $6=new Set(R);if($6.has(J6.pluginId))$6.delete(J6.pluginId);else $6.add(J6.pluginId);h($6)}}},"plugin:install":()=>{if(R.size>0)A6()}},{context:"Plugin",isActive:$==="plugin-list"});let i=V1.useMemo(()=>{if(!X)return[];let J6=X.entry.homepage,$6=F_6(X);return Lx6(J6,$6)},[X]);if(L7({"select:previous":()=>{if(m>0)S(m-1)},"select:next":()=>{if(m<i.length-1)S(m+1)},"select:accept":()=>{if(!X)return;let J6=i[m]?.action,$6=X.entry.homepage,H6=F_6(X);if(J6==="install-user")e(X,"user");else if(J6==="install-project")e(X,"project");else if(J6==="install-local")e(X,"local");else if(J6==="homepage"&&$6)J3($6);else if(J6==="github"&&H6)J3(`https://github.com/${H6}`);else if(J6==="back")j("plugin-list"),M(null)}},{context:"Select",isActive:$==="plugin-details"&&!!X}),typeof $==="object"&&$.type==="plugin-options"){let q6=function(o){if(z(o),A)A();Y({type:"menu"})},{plugin:J6,pluginId:$6,depNote:H6}=$;return V1.createElement(yx6,{plugin:J6,pluginId:$6,onDone:(o,_6)=>{switch(o){case"configured":q6(`✓ Installed and configured ${J6.name}${H6}. Run /reload-plugins to apply.`);break;case"skipped":q6(`✓ Installed ${J6.name}${H6}. Run /reload-plugins to apply.`);break;case"error":q6(`Installed but failed to save config: ${_6}`);break}}})}if(G)return V1.createElement(T,null,"Loading…");if(q)return V1.createElement(T,{color:"error"},q);if($==="marketplace-list"){if(P.length===0)return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Select marketplace")),V1.createElement(T,null,"No marketplaces configured."),V1.createElement(T,{dimColor:!0},"Add a marketplace first using ","'Add marketplace'","."),V1.createElement(u,{marginTop:1,paddingLeft:1},V1.createElement(T,{dimColor:!0},V1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))));return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Select marketplace")),n&&V1.createElement(u,{marginBottom:1,flexDirection:"column"},V1.createElement(T,{color:"warning"},V1.createElement(D4,{status:"warning",withSpace:!0}),n)),P.map((J6,$6)=>V1.createElement(u,{key:J6.name,flexDirection:"column",marginBottom:$6<P.length-1?1:0},V1.createElement(u,null,V1.createElement(T,{color:k===$6?"suggestion":void 0},k===$6?e6.pointer:" "," ",J6.name)),V1.createElement(u,{marginLeft:2},V1.createElement(T,{dimColor:!0},V1.createElement(z1,null,V1.createElement(V1.Fragment,null,J6.totalPlugins," ",O7(J6.totalPlugins,"plugin")," available"),J6.installedCount>0&&`${J6.installedCount} already installed`,J6.source))))),V1.createElement(u,{marginTop:1},V1.createElement(T,{dimColor:!0,italic:!0},V1.createElement(z1,null,V1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),V1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"})))))}if($==="plugin-details"&&X){let J6=X.entry.homepage,$6=F_6(X),H6=Lx6(J6,$6);return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Plugin Details")),V1.createElement(u,{flexDirection:"column",marginBottom:1},V1.createElement(T,{bold:!0},X.entry.name),X.entry.version&&V1.createElement(T,{dimColor:!0},"Version: ",X.entry.version),X.entry.description&&V1.createElement(u,{marginTop:1},V1.createElement(T,null,X.entry.description)),X.entry.author&&V1.createElement(u,{marginTop:1},V1.createElement(T,{dimColor:!0},"By:"," ",typeof X.entry.author==="string"?X.entry.author:X.entry.author.name))),V1.createElement(u,{flexDirection:"column",marginBottom:1},V1.createElement(T,{bold:!0},"Will install:"),X.entry.commands&&V1.createElement(T,{dimColor:!0},"· Commands:"," ",Array.isArray(X.entry.commands)?X.entry.commands.join(", "):Object.keys(X.entry.commands).join(", ")),X.entry.agents&&V1.createElement(T,{dimColor:!0},"· Agents:"," ",Array.isArray(X.entry.agents)?X.entry.agents.join(", "):Object.keys(X.entry.agents).join(", ")),X.entry.hooks&&V1.createElement(T,{dimColor:!0},"· Hooks: ",Object.keys(X.entry.hooks).join(", ")),X.entry.mcpServers&&V1.createElement(T,{dimColor:!0},"· MCP Servers:"," ",Array.isArray(X.entry.mcpServers)?X.entry.mcpServers.join(", "):typeof X.entry.mcpServers==="object"?Object.keys(X.entry.mcpServers).join(", "):"configured"),!X.entry.commands&&!X.entry.agents&&!X.entry.hooks&&!X.entry.mcpServers&&V1.createElement(V1.Fragment,null,typeof X.entry.source==="object"&&"source"in X.entry.source&&(X.entry.source.source==="github"||X.entry.source.source==="url"||X.entry.source.source==="npm"||X.entry.source.source==="pip")?V1.createElement(T,{dimColor:!0},"· Component summary not available for remote plugin"):V1.createElement(T,{dimColor:!0},"· Components will be discovered at installation"))),V1.createElement(Bi8,null),g&&V1.createElement(u,{marginBottom:1},V1.createElement(T,{color:"error"},"Error: ",g)),V1.createElement(u,{flexDirection:"column"},H6.map((q6,o)=>V1.createElement(u,{key:q6.action},m===o&&V1.createElement(T,null,"> "),m!==o&&V1.createElement(T,null," "),V1.createElement(T,{bold:m===o},F&&q6.action==="install"?"Installing…":q6.label)))),V1.createElement(u,{marginTop:1,paddingLeft:1},V1.createElement(T,{dimColor:!0},V1.createElement(z1,null,V1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),V1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}if(D.length===0)return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Install plugins")),V1.createElement(T,{dimColor:!0},"No new plugins available to install."),V1.createElement(T,{dimColor:!0},"All plugins from this marketplace are already installed."),V1.createElement(u,{marginLeft:3},V1.createElement(T,{dimColor:!0,italic:!0},V1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))));let O6=B.getVisibleItems(D);return V1.createElement(u,{flexDirection:"column"},V1.createElement(u,{marginBottom:1},V1.createElement(T,{bold:!0},"Install Plugins")),B.scrollPosition.canScrollUp&&V1.createElement(u,null,V1.createElement(T,{dimColor:!0}," ",e6.arrowUp," more above")),O6.map((J6,$6)=>{let H6=B.toActualIndex($6),q6=k===H6,o=R.has(J6.pluginId),_6=C.has(J6.pluginId),r=$6===O6.length-1;return V1.createElement(u,{key:J6.pluginId,flexDirection:"column",marginBottom:r&&!q?0:1},V1.createElement(u,null,V1.createElement(T,{color:q6?"suggestion":void 0},q6?e6.pointer:" "," "),V1.createElement(T,{color:J6.isInstalled?"success":void 0},J6.isInstalled?e6.tick:_6?e6.ellipsis:o?e6.radioOn:e6.radioOff," ",J6.entry.name,J6.entry.category&&V1.createElement(T,{dimColor:!0}," [",J6.entry.category,"]"),J6.entry.tags?.includes("community-managed")&&V1.createElement(T,{dimColor:!0}," [Community Managed]"),J6.isInstalled&&V1.createElement(T,{dimColor:!0}," (installed)"),v&&H===WM&&V1.createElement(T,{dimColor:!0}," · ",Ii8(v.get(J6.pluginId)??0)," ","installs"))),J6.entry.description&&V1.createElement(u,{marginLeft:4},V1.createElement(T,{dimColor:!0},j4(J6.entry.description,60)),J6.entry.version&&V1.createElement(T,{dimColor:!0}," · v",J6.entry.version)))}),B.scrollPosition.canScrollDown&&V1.createElement(u,null,V1.createElement(T,{dimColor:!0}," ",e6.arrowDown," more below")),q&&V1.createElement(u,{marginTop:1},V1.createElement(T,{color:"error"},V1.createElement(D4,{status:"error",withSpace:!0}),q)),V1.createElement(lpK,{hasSelection:R.size>0}))}var V1,G0;var ipK=L(()=>{Qq();bK();Nq();Y2();g6();C7();Nj();K8();m8();uR();xi8();yD();Xc();m$();qH6();Y56();AH6();U86();mi8();Ow7();ww7();W_8();V1=K6(P6(),1),G0=K6(P6(),1)});function rpK({error:q,setError:K,result:_,setResult:z,setViewState:Y,onInstallComplete:A,onSearchModeChange:O,targetPlugin:w}){let[$,j]=FJ.useState("plugin-list"),[H,J]=FJ.useState(null),[X,M]=FJ.useState([]),[P,W]=FJ.useState(!0),[D,Z]=FJ.useState(null),[G,f]=FJ.useState(!1),v=FJ.useCallback((M6)=>{f(M6),O?.(M6)},[O]),{query:V,setQuery:k,cursorOffset:N,handleKeyDown:R,handlePaste:h}=bS({isActive:$==="plugin-list"&&G&&!P,onExit:()=>{v(!1)}}),C=K2(),{columns:x}=s1(),B=FJ.useMemo(()=>{if(!V)return X;let M6=V.toLowerCase();return X.filter((W6)=>W6.entry.name.toLowerCase().includes(M6)||W6.entry.description?.toLowerCase().includes(M6)||W6.marketplaceName.toLowerCase().includes(M6))},[X,V]),[m,S]=FJ.useState(0),[F,U]=FJ.useState(new Set),[g,c]=FJ.useState(new Set),n=QP6({totalItems:B.length,selectedIndex:m});FJ.useEffect(()=>{S(0)},[V]);let[l,z6]=FJ.useState(0),[A6,e]=FJ.useState(!1),[i,O6]=FJ.useState(null),[J6,$6]=FJ.useState(null),[H6,q6]=FJ.useState(null);FJ.useEffect(()=>{async function M6(){try{let W6=await Dz(),{marketplaces:V6,failures:f6}=await Rp(W6),G6=[];for(let{name:y6,data:c6}of V6)if(c6)for(let Z8 of c6.plugins){let N8=Jc(Z8.name,y6);G6.push({entry:Z8,marketplaceName:y6,pluginId:N8,isInstalled:Hu(N8)})}let k6=G6.filter((y6)=>!y6.isInstalled&&!Rk(y6.pluginId));try{let y6=await Ex6();if(Z(y6),y6)k6.sort((c6,Z8)=>{let N8=y6.get(c6.pluginId)??0,R6=y6.get(Z8.pluginId)??0;if(N8!==R6)return R6-N8;return c6.entry.name.localeCompare(Z8.entry.name)});else k6.sort((c6,Z8)=>c6.entry.name.localeCompare(Z8.entry.name))}catch(y6){E(`Failed to fetch install counts: ${b6(y6)}`),k6.sort((c6,Z8)=>c6.entry.name.localeCompare(Z8.entry.name))}M(k6);let T6=Object.keys(W6).length;if(k6.length===0){let y6=await Zf4({configuredMarketplaceCount:T6,failedMarketplaceCount:f6.length});if(y6==="all-plugins-installed"&&G6.length>0&&G6.every((c6)=>c6.isInstalled&&!aM6(c6.pluginId))&&!G6.some((c6)=>Rk(c6.pluginId)))y6="all-plugins-project-installed";q6(y6)}let v6=w7(V6,(y6)=>y6.data!==null),L6=$L6(f6,v6);if(L6)if(L6.type==="warning")$6(L6.message+(k6.length>0?". Showing available plugins.":"."));else throw Error(L6.message);if(w){let y6=G6.find((c6)=>c6.entry.name===w);if(y6)if(aM6(y6.pluginId))K(`Plugin '${y6.pluginId}' is already installed. Use '/plugin' to manage existing plugins.`);else J(y6),j("plugin-details");else K(`Plugin "${w}" not found in any marketplace`)}}catch(W6){K(W6 instanceof Error?W6.message:"Failed to load plugins")}finally{W(!1)}}M6()},[K,w]);let o=async()=>{if(F.size===0)return;let M6=X.filter((G6)=>F.has(G6.pluginId));c(new Set(M6.map((G6)=>G6.pluginId)));let W6=0,V6=0,f6=[];for(let G6 of M6){let k6=await z56({pluginId:G6.pluginId,entry:G6.entry,marketplaceName:G6.marketplaceName,scope:"user"});if(k6.success)W6++;else V6++,f6.push({name:G6.entry.name,reason:k6.error})}if(c(new Set),U(new Set),YO(),V6===0){let G6=`✓ Installed ${W6} ${O7(W6,"plugin")}. Run /reload-plugins to activate.`;z(G6)}else if(W6===0)K(`Failed to install: ${wL6(f6,!0)}`);else{let G6=`✓ Installed ${W6} of ${W6+V6} plugins. Failed: ${wL6(f6,!1)}. Run /reload-plugins to activate successfully installed plugins.`;z(G6)}if(W6>0){if(A)await A()}Y({type:"menu"})},_6=async(M6,W6="user")=>{e(!0),O6(null);let V6=await z56({pluginId:M6.pluginId,entry:M6.entry,marketplaceName:M6.marketplaceName,scope:W6});if(V6.success){let f6=await ui8(M6.pluginId);if(f6){e(!1),j({type:"plugin-options",plugin:f6,pluginId:M6.pluginId,depNote:V6.depNote});return}if(z(V6.message),A)await A();Y({type:"menu"})}else e(!1),O6(V6.error)};FJ.useEffect(()=>{if(q)z(q)},[q,z]),G1("confirm:no",()=>{j("plugin-list"),J(null)},{context:"Confirmation",isActive:$==="plugin-details"}),G1("confirm:no",()=>{Y({type:"menu"})},{context:"Confirmation",isActive:$==="plugin-list"&&!G});function r(M6){if(G){R(M6);return}if(M6.ctrl||M6.meta||P)return;if(M6.key==="/")M6.preventDefault(),v(!0),k("");else if(M6.key.length===1&&M6.key!==" ")M6.preventDefault(),v(!0),k(M6.key)}function t(M6){if(G){h(M6);return}if(P)return;let W6=(M6.text.split(/\r\n|\r|\n/,2)[0]??"").trim();if(!W6)return;M6.preventDefault(),v(!0),k(W6)}L7({"select:previous":()=>{if(m===0)v(!0);else n.handleSelectionChange(m-1,S)},"select:next":()=>{if(m<B.length-1)n.handleSelectionChange(m+1,S)},"select:accept":()=>{if(m===B.length&&F.size>0)o();else if(m<B.length){let M6=B[m];if(M6)if(M6.isInstalled)Y({type:"manage-plugins",targetPlugin:M6.entry.name,targetMarketplace:M6.marketplaceName});else J(M6),j("plugin-details"),z6(0),O6(null)}}},{context:"Select",isActive:$==="plugin-list"&&!G}),L7({"plugin:toggle":()=>{if(m<B.length){let M6=B[m];if(M6&&!M6.isInstalled){let W6=new Set(F);if(W6.has(M6.pluginId))W6.delete(M6.pluginId);else W6.add(M6.pluginId);U(W6)}}},"plugin:install":()=>{if(F.size>0)o()}},{context:"Plugin",isActive:$==="plugin-list"&&!G});let Y6=J1.useMemo(()=>{if(!H)return[];let M6=H.entry.homepage,W6=F_6(H);return Lx6(M6,W6)},[H]);if(L7({"select:previous":()=>{if(l>0)z6(l-1)},"select:next":()=>{if(l<Y6.length-1)z6(l+1)},"select:accept":()=>{if(!H)return;let M6=Y6[l]?.action,W6=H.entry.homepage,V6=F_6(H);if(M6==="install-user")_6(H,"user");else if(M6==="install-project")_6(H,"project");else if(M6==="install-local")_6(H,"local");else if(M6==="homepage"&&W6)J3(W6);else if(M6==="github"&&V6)J3(`https://github.com/${V6}`);else if(M6==="back")j("plugin-list"),J(null)}},{context:"Select",isActive:$==="plugin-details"&&!!H}),typeof $==="object"&&$.type==="plugin-options"){let f6=function(G6){if(z(G6),A)A();Y({type:"menu"})},{plugin:M6,pluginId:W6,depNote:V6}=$;return J1.createElement(yx6,{plugin:M6,pluginId:W6,onDone:(G6,k6)=>{switch(G6){case"configured":f6(`✓ Installed and configured ${M6.name}${V6}. Run /reload-plugins to apply.`);break;case"skipped":f6(`✓ Installed ${M6.name}${V6}. Run /reload-plugins to apply.`);break;case"error":f6(`Installed but failed to save config: ${k6}`);break}}})}if(P)return J1.createElement(T,null,"Loading…");if(q)return J1.createElement(T,{color:"error"},q);if($==="plugin-details"&&H){let M6=H.entry.homepage,W6=F_6(H),V6=Lx6(M6,W6);return J1.createElement(u,{flexDirection:"column"},J1.createElement(u,{marginBottom:1},J1.createElement(T,{bold:!0},"Plugin details")),J1.createElement(u,{flexDirection:"column",marginBottom:1},J1.createElement(T,{bold:!0},H.entry.name),J1.createElement(T,{dimColor:!0},"from ",H.marketplaceName),H.entry.version&&J1.createElement(T,{dimColor:!0},"Version: ",H.entry.version),H.entry.description&&J1.createElement(u,{marginTop:1},J1.createElement(T,null,H.entry.description)),H.entry.author&&J1.createElement(u,{marginTop:1},J1.createElement(T,{dimColor:!0},"By:"," ",typeof H.entry.author==="string"?H.entry.author:H.entry.author.name))),J1.createElement(Bi8,null),i&&J1.createElement(u,{marginBottom:1},J1.createElement(T,{color:"error"},"Error: ",i)),J1.createElement(u,{flexDirection:"column"},V6.map((f6,G6)=>J1.createElement(u,{key:f6.action},l===G6&&J1.createElement(T,null,"> "),l!==G6&&J1.createElement(T,null," "),J1.createElement(T,{bold:l===G6},A6&&f6.action.startsWith("install-")?"Installing…":f6.label)))),J1.createElement(u,{marginTop:1},J1.createElement(T,{dimColor:!0},J1.createElement(z1,null,J1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),J1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}if(X.length===0)return J1.createElement(u,{flexDirection:"column"},J1.createElement(u,{marginBottom:1},J1.createElement(T,{bold:!0},"Discover plugins")),J6&&J1.createElement(u,{marginBottom:1},J1.createElement(T,{color:"warning"},J1.createElement(D4,{status:"warning",withSpace:!0}),J6)),J1.createElement(YxY,{reason:H6}),J1.createElement(u,{marginTop:1},J1.createElement(T,{dimColor:!0,italic:!0},J1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))));let X6=n.getVisibleItems(B);return J1.createElement(u,{flexDirection:"column",tabIndex:0,autoFocus:!0,onKeyDown:r,onPaste:t},J1.createElement(u,null,J1.createElement(T,{bold:!0},"Discover plugins"),n.needsPagination&&J1.createElement(T,{dimColor:!0}," ","(",n.scrollPosition.current,"/",n.scrollPosition.total,")")),J1.createElement(u,{marginBottom:1},J1.createElement(wg,{query:V,isFocused:G,isTerminalFocused:C,width:x-4,cursorOffset:N})),J6&&J1.createElement(u,{marginBottom:1},J1.createElement(T,{color:"warning"},J1.createElement(D4,{status:"warning",withSpace:!0}),J6)),B.length===0&&V&&J1.createElement(u,{marginBottom:1},J1.createElement(T,{dimColor:!0},'No plugins match "',V,'"')),n.scrollPosition.canScrollUp&&J1.createElement(u,null,J1.createElement(T,{dimColor:!0}," ",e6.arrowUp," more above")),X6.map((M6,W6)=>{let V6=n.toActualIndex(W6),f6=m===V6,G6=F.has(M6.pluginId),k6=g.has(M6.pluginId),T6=W6===X6.length-1;return J1.createElement(u,{key:`${n.startIndex}-${M6.pluginId}`,flexDirection:"column",marginBottom:T6&&!q?0:1},J1.createElement(u,null,J1.createElement(T,{color:f6&&!G?"suggestion":void 0},f6&&!G?e6.pointer:" "," "),J1.createElement(T,null,k6?e6.ellipsis:G6?e6.radioOn:e6.radioOff," ",M6.entry.name,J1.createElement(T,{dimColor:!0}," · ",M6.marketplaceName),M6.entry.tags?.includes("community-managed")&&J1.createElement(T,{dimColor:!0}," [Community Managed]"),D&&M6.marketplaceName===WM&&J1.createElement(T,{dimColor:!0}," · ",Ii8(D.get(M6.pluginId)??0)," ","installs"))),M6.entry.description&&J1.createElement(u,{marginLeft:4},J1.createElement(T,{dimColor:!0},j4(M6.entry.description,60))))}),n.scrollPosition.canScrollDown&&J1.createElement(u,null,J1.createElement(T,{dimColor:!0}," ",e6.arrowDown," more below")),q&&J1.createElement(u,{marginTop:1},J1.createElement(T,{color:"error"},J1.createElement(D4,{status:"error",withSpace:!0}),q)),J1.createElement(zxY,{hasSelection:F.size>0,canToggle:m<B.length&&!B[m]?.isInstalled}))}function zxY(q){let K=s(10),{hasSelection:_,canToggle:z}=q,Y;if(K[0]!==_)Y=_&&J1.createElement(v1,{action:"plugin:install",context:"Plugin",fallback:"i",description:"install",bold:!0}),K[0]=_,K[1]=Y;else Y=K[1];let A;if(K[2]===Symbol.for("react.memo_cache_sentinel"))A=J1.createElement(T,null,"type to search"),K[2]=A;else A=K[2];let O;if(K[3]!==z)O=z&&J1.createElement(v1,{action:"plugin:toggle",context:"Plugin",fallback:"Space",description:"toggle"}),K[3]=z,K[4]=O;else O=K[4];let w,$;if(K[5]===Symbol.for("react.memo_cache_sentinel"))w=J1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"details"}),$=J1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"}),K[5]=w,K[6]=$;else w=K[5],$=K[6];let j;if(K[7]!==Y||K[8]!==O)j=J1.createElement(u,{marginTop:1},J1.createElement(T,{dimColor:!0,italic:!0},J1.createElement(z1,null,Y,A,O,w,$))),K[7]=Y,K[8]=O,K[9]=j;else j=K[9];return j}function YxY(q){let K=s(7),{reason:_}=q;switch(_){case"git-not-installed":{let z;if(K[0]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"Git is required to install marketplaces."),J1.createElement(T,{dimColor:!0},"Please install git and restart Claude Code.")),K[0]=z;else z=K[0];return z}case"all-blocked-by-policy":{let z;if(K[1]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"Your organization policy does not allow any external marketplaces."),J1.createElement(T,{dimColor:!0},"Contact your administrator.")),K[1]=z;else z=K[1];return z}case"policy-restricts-sources":{let z;if(K[2]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"Your organization restricts which marketplaces can be added."),J1.createElement(T,{dimColor:!0},"Switch to the Marketplaces tab to view allowed sources.")),K[2]=z;else z=K[2];return z}case"all-marketplaces-failed":{let z;if(K[3]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"Failed to load marketplace data."),J1.createElement(T,{dimColor:!0},"Check your network connection.")),K[3]=z;else z=K[3];return z}case"all-plugins-installed":{let z;if(K[4]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"All available plugins are already installed."),J1.createElement(T,{dimColor:!0},"Check for new plugins later or add more marketplaces.")),K[4]=z;else z=K[4];return z}case"all-plugins-project-installed":{let z;if(K[5]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"All available plugins are installed for this project."),J1.createElement(T,{dimColor:!0},"Use the Browse tab to install at user scope.")),K[5]=z;else z=K[5];return z}case"no-marketplaces-configured":default:{let z;if(K[6]===Symbol.for("react.memo_cache_sentinel"))z=J1.createElement(J1.Fragment,null,J1.createElement(T,{dimColor:!0},"No plugins available."),J1.createElement(T,{dimColor:!0},"Add a marketplace first using the Marketplaces tab.")),K[6]=z;else z=K[6];return z}}}var J1,FJ;var opK=L(()=>{o6();Qq();bK();Nq();Y2();EP6();R_6();I4();g6();C7();Nj();K8();m8();uR();xi8();yD();Xc();m$();qH6();Y56();AH6();U86();mi8();Ow7();ww7();W_8();J1=K6(P6(),1),FJ=K6(P6(),1)});import{dirname as AxY,join as OxY}from"path";function $w7(q){if(!vG.includes(q))throw Error(`Invalid scope "${q}". Must be one of: ${vG.join(", ")}`)}function Rx6(q){return vG.includes(q)}function apK(q){return q==="project"||q==="local"?Y7():void 0}function spK(q){return E1("projectSettings")?.enabledPlugins?.[q]===!0}function wxY(q){let K=q.includes("@"),_=["local","project","user"];for(let z of _){let Y=E1(jc(z))?.enabledPlugins;if(!Y)continue;for(let A of Object.keys(Y))if(K?A===q:A.startsWith(`${q}@`))return{pluginId:A,scope:z}}return null}function $xY(q,K){let{name:_,marketplace:z}=Z4(q);return K.find((Y)=>{if(Y.name===q||Y.name===_)return!0;if(z&&Y.source)return Y.name===_&&Y.source.includes(`@${z}`);return!1})}function jxY(q){let{name:K}=Z4(q),_=OZ();if(_.plugins[q]?.length)return{pluginId:q,pluginName:K};let z=Object.keys(_.plugins).find((Y)=>{let{name:A}=Z4(Y);return A===K&&(_.plugins[Y]?.length??0)>0});if(z)return{pluginId:z,pluginName:K};return null}function pi8(q){let _=OZ().plugins[q];if(!_||_.length===0)return{scope:"user"};let z=Y7(),Y=_.find((w)=>w.scope==="local"&&w.projectPath===z);if(Y)return{scope:Y.scope,projectPath:Y.projectPath};let A=_.find((w)=>w.scope==="project"&&w.projectPath===z);if(A)return{scope:A.scope,projectPath:A.projectPath};let O=_.find((w)=>w.scope==="user");if(O)return{scope:O.scope};return{scope:_[0].scope,projectPath:_[0].projectPath}}async function tpK(q,K="user"){$w7(K);let{name:_,marketplace:z}=Z4(q),Y,A,O;if(z){let H=await mf(q);if(H)Y=H.entry,A=z,O=H.marketplaceInstallLocation}else{let H=await Dz();for(let[J,X]of Object.entries(H))try{let P=(await xf(J)).plugins.find((W)=>W.name===_);if(P){Y=P,A=J,O=X.installLocation;break}}catch(M){j6(r1(M));continue}}if(!Y||!A){let H=z?`marketplace "${z}"`:"any configured marketplace";return{success:!1,message:`Plugin "${_}" not found in ${H}`}}let w=Y,$=`${w.name}@${A}`,j=await $d1({pluginId:$,entry:w,scope:K,marketplaceInstallLocation:O,trigger:"cli"});if(!j.ok)switch(j.reason){case"local-source-no-location":return{success:!1,message:`Cannot install local plugin "${j.pluginName}" without marketplace install location`};case"settings-write-failed":return{success:!1,message:`Failed to update settings: ${j.message}`};case"resolution-failed":return{success:!1,message:wd1(j.resolution)};case"blocked-by-policy":return{success:!1,message:`Plugin "${j.pluginName}" is blocked by your organization's policy and cannot be installed`};case"dependency-blocked-by-policy":return{success:!1,message:`Plugin "${j.pluginName}" depends on "${j.blockedDependency}", which is blocked by your organization's policy`};case"range-conflict":{let H=j.dep===$?"Plugin":"Dependency";return{success:!1,message:fS8(H,j.dep,j.ranges,j.why)}}case"no-matching-tag":{let H=j.dep===$?"Plugin":"Dependency";return{success:!1,message:GS8(H,j.dep,j.range)}}}return{success:!0,message:`Successfully installed plugin: ${$} (scope: ${K})${j.depNote}`,pluginId:$,pluginName:w.name,scope:K}}async function ie(q,K="user",_=!0){$w7(K);let{enabled:z,disabled:Y}=await sW(),A=[...z,...Y],O=$xY(q,A),w=jc(K),$=E1(w),j,H;if(O)j=Object.keys($?.enabledPlugins??{}).find((k)=>k===q||k===O.name||k.startsWith(`${O.name}@`))??(q.includes("@")?q:O.name),H=O.name;else{let k=jxY(q);if(!k)return{success:!1,message:`Plugin "${q}" not found in installed plugins`};j=k.pluginId,H=k.pluginName}let J=apK(K),M=OZ().plugins[j],P=M?.find((k)=>k.scope===K&&k.projectPath===J);if(!P){let{scope:k}=pi8(j);if(k!==K&&M&&M.length>0){if(k==="project")return{success:!1,message:`Plugin "${q}" is enabled at project scope (.claude/settings.json, shared with your team). To disable just for you: claude plugin disable ${q} --scope local`};return{success:!1,message:`Plugin "${q}" is installed in ${k} scope, not ${K}. Use --scope ${k} to uninstall.`}}return{success:!1,message:`Plugin "${q}" is not installed in ${K} scope. Use --scope to specify the correct scope.`}}let W=P.installPath,D={...$?.enabledPlugins};D[j]=void 0,P7(w,{enabledPlugins:D}),YO(),DEK(j,K,J);let G=OZ().plugins[j],f=!G||G.length===0;if(f&&W)await hI6(W);if(f){if(Vb8(j),_)await PS8(j)}let v=vQ1(j,A),V=TQ1(v);return{success:!0,message:`Successfully uninstalled plugin: ${H} (scope: ${K})${V}`,pluginId:j,pluginName:H,scope:K,reverseDependents:v.length>0?v:void 0}}async function jw7(q,K,_){let z=K?"enable":"disable";if(qf4(q)){let{error:D}=P7("userSettings",{enabledPlugins:{...E1("userSettings")?.enabledPlugins,[q]:K}});if(D)return{success:!1,message:`Failed to ${z} built-in plugin: ${D.message}`};YO();let{name:Z}=Z4(q);return{success:!0,message:`Successfully ${z}d built-in plugin: ${Z}`,pluginId:q,pluginName:Z,scope:"user"}}if(_)$w7(_);let Y,A,O=wxY(q);if(_)if(A=_,O)Y=O.pluginId;else if(q.includes("@"))Y=q;else return{success:!1,message:`Plugin "${q}" not found in settings. Use plugin@marketplace format.`};else if(O)Y=O.pluginId,A=O.scope;else if(q.includes("@"))Y=q,A="user";else return{success:!1,message:`Plugin "${q}" not found in any editable settings scope. Use plugin@marketplace format.`};if(K&&Rk(Y))return{success:!1,message:`Plugin "${Y}" is blocked by your organization's policy and cannot be enabled`};let w=jc(A),$=E1(w)?.enabledPlugins?.[Y],j={user:0,project:1,local:2},H=_&&O&&j[_]>j[O.scope];if(_&&$===void 0&&O&&O.scope!==_&&!H)return{success:!1,message:`Plugin "${q}" is installed at ${O.scope} scope, not ${_}. Use --scope ${O.scope} or omit --scope to auto-detect.`};let J=_&&!H?$===!0:p_6().has(Y);if(K===J)return{success:!1,message:`Plugin "${q}" is already ${K?"enabled":"disabled"}${_?` at ${_} scope`:""}`};let X;if(!K){let{enabled:D,disabled:Z}=await sW(),G=vQ1(Y,[...D,...Z]);if(G.length>0)X=G}let{error:M}=P7(w,{enabledPlugins:{...E1(w)?.enabledPlugins,[Y]:K}});if(M)return{success:!1,message:`Failed to ${z} plugin: ${M.message}`};YO();let{name:P}=Z4(Y),W=TQ1(X);return{success:!0,message:`Successfully ${z}d plugin: ${P} (scope: ${A})${W}`,pluginId:Y,pluginName:P,scope:A,reverseDependents:X}}async function Sx6(q,K){return jw7(q,!0,K)}async function Cx6(q,K){return jw7(q,!1,K)}async function epK(){let q=p_6();if(q.size===0)return{success:!0,message:"No enabled plugins to disable"};let K=[],_=[];for(let[z]of q){let Y=await jw7(z,!1);if(Y.success)K.push(z);else _.push(`${z}: ${Y.message}`)}if(_.length>0)return{success:!1,message:`Disabled ${K.length} ${O7(K.length,"plugin")}, ${_.length} failed:
6423
6423
  ${_.join(`
6424
6424
  `)}`};return{success:!0,message:`Disabled ${K.length} ${O7(K.length,"plugin")}`}}async function bx6(q,K){let{name:_,marketplace:z}=Z4(q),Y=z?`${_}@${z}`:q,A;if(z){let D=(await Dz())[z]?.source;if(D&&(D.source==="github"||D.source==="git"||D.source==="url"))try{await P_6(z,void 0,{skipIfRecent:!0})}catch(Z){A=`marketplace not refreshed (${b6(Z)})`,E(`Failed to refresh marketplace '${z}' before update; using cached data: ${b6(Z)}`,{level:"warn"})}}let O=await mf(q);if(!O)return{success:!1,message:`Plugin "${_}" not found`,pluginId:Y,scope:K};let{entry:w,marketplaceInstallLocation:$}=O,H=mR().plugins[Y];if(!H||H.length===0)return{success:!1,message:`Plugin "${_}" is not installed`,pluginId:Y,scope:K};let J=apK(K),X=H.filter((W)=>W.scope===K),M=X.find((W)=>W.projectPath===J);if(!M&&X.length>1)E(`updatePluginOp: ${X.length} ${K}-scope installs, none match CWD '${J}'; updating '${X[0]?.projectPath}' only`,{level:"warn"});let P=M??X[0];if(!P){let W=J?`${K} (${J})`:K;return{success:!1,message:`Plugin "${_}" is not installed at scope ${W}`,pluginId:Y,scope:K}}return HxY({pluginId:Y,pluginName:_,entry:w,marketplaceInstallLocation:$,installation:P,scope:K,projectPath:P.projectPath,refreshWarning:A})}async function HxY({pluginId:q,pluginName:K,entry:_,marketplaceInstallLocation:z,installation:Y,scope:A,projectPath:O,refreshWarning:w}){let $=V8(),j=Y.version,H,J,X,M=!1,P;if(typeof _.source!=="string"){let W=await f68(_.source,{manifest:{name:_.name}});H=W.path,M=!0,P=W.gitCommitSha,X=W.manifest?.version,J=await us(q,_.source,W.manifest,W.path,_.version,W.gitCommitSha)}else{let W;try{W=await $.stat(z)}catch(G){if(t1(G))return{success:!1,message:`Marketplace directory not found at ${z}`,pluginId:q,scope:A};throw G}let D=W.isDirectory()?z:AxY(z);H=OxY(D,_.source);try{await $.stat(H)}catch(G){if(t1(G))return{success:!1,message:`Plugin source not found at ${H}`,pluginId:q,scope:A};throw G}let Z;try{Z=(await k68(H,_.name,_.source)).manifest}catch{}X=Z?.version,J=await us(q,_.source,Z,H,_.version)}try{let{enabled:W,disabled:D}=await sW(),Z=$f4(q,[...W,...D]);if(Z.length>0){let R=hx6.valid(X)??hx6.coerce(X)?.version,h=Z.filter(({constraint:C})=>C.version!==void 0&&R!==void 0&&!hx6.satisfies(R,C.version)).map(({plugin:C})=>C.source);if(h.length>0)return{success:!0,skipped:!0,message:`Skipped — ${h.join(", ")} requires ${K} at a version range that ${X??J} does not satisfy`,pluginId:q,scope:A,blockedBy:h,oldVersion:j}}let G=Sp(q,J),f=yL6(q,J);if(Y.version===J||Y.installPath===G||Y.installPath===f){let R=`${K} is already at the latest version (${J}).`;return{success:!0,message:w?`${R} Warning: ${w} — version shown may be stale.`:R,pluginId:q,newVersion:J,oldVersion:j,alreadyUpToDate:!0,scope:A}}G=await rS8(H,q,J,_);let V=Y.installPath;if(ZEK(q,A,O,G,J,P),V&&V!==G){let R=mR();if(!Object.values(R.plugins).some((C)=>C.some((x)=>x.installPath===V)))await hI6(V)}let k=O?`${A} (${O})`:A,N=`Plugin "${K}" updated from ${j||"unknown"} to ${J} for scope ${k}. Restart to apply changes.`;return{success:!0,message:w?`${N} Warning: ${w}.`:N,pluginId:q,newVersion:J,oldVersion:j,scope:A}}finally{if(M&&H!==Sp(q,J))await $.rm(H,{recursive:!0,force:!0})}}var hx6,vG,dP6;var Ix6=L(()=>{y8();z68();K8();m8();Yq();U8();uR();vS8();yD();m$();Jy();aW();Y56();vH();Gx();AH6();X_8();yS8();a1();hx6=K6(Pd(),1),vG=["user","project","local"],dP6=["user","project","local","managed"]});function qFK(q){if(Fi8=q,D_8!==null&&D_8.length>0)q(D_8),D_8=null;return()=>{Fi8=null}}async function JxY(){let q=await Dz(),K=X_6(),_=new Set;for(let[z,Y]of Object.entries(q)){let A=K[z]?.autoUpdate;if(A!==void 0?A:bQ6(z,Y))_.add(z.toLowerCase())}return _}async function XxY(q,K){let _=!1;for(let{scope:z}of K)try{let Y=await bx6(q,z);if(Y.success&&!Y.alreadyUpToDate&&!Y.skipped)_=!0,E(`Plugin autoupdate: updated ${q} from ${Y.oldVersion} to ${Y.newVersion}`);else if(Y.skipped)E(`Plugin autoupdate: ${q} ${Y.message}`);else if(!Y.alreadyUpToDate)E(`Plugin autoupdate: failed to update ${q}: ${Y.message}`,{level:"warn"})}catch(Y){E(`Plugin autoupdate: error updating ${q}: ${b6(Y)}`,{level:"warn"})}return _?q:null}async function Hw7(q){let K=mR(),_=Object.keys(K.plugins);if(_.length===0)return[];return(await Promise.allSettled(_.map(async(Y)=>{let{marketplace:A}=Z4(Y);if(!A||!q.has(A.toLowerCase()))return null;let O=K.plugins[Y];if(!O||O.length===0)return null;let w=O.filter(O_7);if(w.length===0)return null;return XxY(Y,w)}))).filter((Y)=>Y.status==="fulfilled"&&Y.value!==null).map((Y)=>Y.value)}async function MxY(q){return Hw7(q)}function KFK(){return(async()=>{if(ok6()){E("Plugin autoupdate: skipped (auto-updater disabled)");return}try{let q=await JxY();if(q.size===0)return;let _=(await Promise.allSettled(Array.from(q).map(async(Y)=>{try{await P_6(Y,void 0,{disableCredentialHelper:!0})}catch(A){E(`Plugin autoupdate: failed to refresh marketplace ${Y}: ${b6(A)}`,{level:"warn"})}}))).filter((Y)=>Y.status==="rejected");if(_.length>0)E(`Plugin autoupdate: ${_.length} marketplace refresh(es) failed`,{level:"warn"});E("Plugin autoupdate: checking installed plugins");let z=await MxY(q);if(z.length>0)if(Fi8)Fi8(z);else D_8=z}catch(q){j6(q)}})()}var Fi8=null,D_8=null;var gi8=L(()=>{Ix6();h1();K8();m8();U8();yD();m$();aW();Hv()});function _FK({setViewState:q,error:K,setError:_,setResult:z,exitState:Y,onManageComplete:A,targetMarketplace:O,action:w}){let[$,j]=jZ.useState([]),[H,J]=jZ.useState(!0),[X,M]=jZ.useState(0),[P,W]=jZ.useState(!1),[D,Z]=jZ.useState(null),[G,f]=jZ.useState(null),[v,V]=jZ.useState(null),[k,N]=jZ.useState("list"),[R,h]=jZ.useState(null),[C,x]=jZ.useState(0),B=jZ.useRef(!1),m=jZ.useRef(void 0),S=jZ.useRef(!0);jZ.useEffect(()=>()=>{S.current=!1,clearTimeout(m.current)},[]),jZ.useEffect(()=>{async function O6(){try{let J6=await Dz(),{enabled:$6,disabled:H6}=await sW(),q6=[...$6,...H6],{marketplaces:o,failures:_6}=await Rp(J6),r=[];for(let{name:X6,config:M6,data:W6}of o){let V6=q6.filter((f6)=>f6.source.endsWith(`@${X6}`));r.push({name:X6,source:O68(M6.source),lastUpdated:M6.lastUpdated,pluginCount:W6?.plugins.length,installedPlugins:V6,pendingUpdate:!1,pendingRemove:!1,autoUpdate:bQ6(X6,M6)})}r.sort((X6,M6)=>{if(X6.name==="claude-plugin-directory")return-1;if(M6.name==="claude-plugin-directory")return 1;return X6.name.localeCompare(M6.name)}),j(r);let t=w7(o,(X6)=>X6.data!==null),Y6=$L6(_6,t);if(Y6)if(Y6.type==="warning")Z(Y6.message);else throw Error(Y6.message);if(O&&!B.current&&!K){B.current=!0;let X6=r.findIndex((M6)=>M6.name===O);if(X6>=0){let M6=r[X6];if(w){M(X6+1);let W6=r.map((V6,f6)=>f6===X6?{...V6,pendingUpdate:w==="update",pendingRemove:w==="remove"}:V6);j(W6),g(W6)}else if(M6)M(X6+1),h(M6),clearTimeout(m.current),N("details")}else if(_)_(`Marketplace not found: ${O}`)}}catch(J6){if(_)_(J6 instanceof Error?J6.message:"Failed to load marketplaces");Z(J6 instanceof Error?J6.message:"Failed to load marketplaces")}finally{J(!1)}}O6()},[O,w,K]);let F=()=>{return $.some((O6)=>O6.pendingUpdate||O6.pendingRemove)},U=()=>{let O6=w7($,($6)=>$6.pendingUpdate),J6=w7($,($6)=>$6.pendingRemove);return{updateCount:O6,removeCount:J6}},g=async(O6)=>{let J6=O6||$,$6=k==="details";W(!0),Z(null),f(null),V(null);try{let H6=E1("userSettings"),q6=0,o=0,_6=new Set;for(let G6 of J6){if(G6.pendingRemove){if(G6.installedPlugins&&G6.installedPlugins.length>0){let k6={...H6?.enabledPlugins};for(let T6 of G6.installedPlugins){let v6=Jc(T6.name,G6.name);k6[v6]=!1}P7("userSettings",{enabledPlugins:k6})}await RI6(G6.name),o++,d("tengu_marketplace_removed",{marketplace_name:G6.name,plugins_uninstalled:G6.installedPlugins?.length||0});continue}if(G6.pendingUpdate)await P_6(G6.name,(k6)=>{V(k6)}),q6++,_6.add(G6.name.toLowerCase()),d("tengu_marketplace_updated",{marketplace_name:G6.name})}let r=0;if(_6.size>0)r=(await Hw7(_6)).length;if(YO(),A)await A();if(!S.current)return;let t=await Dz(),{enabled:Y6,disabled:X6}=await sW();if(!S.current)return;let M6=[...Y6,...X6],{marketplaces:W6}=await Rp(t);if(!S.current)return;let V6=[];for(let{name:G6,config:k6,data:T6}of W6){let v6=M6.filter((L6)=>L6.source.endsWith(`@${G6}`));V6.push({name:G6,source:O68(k6.source),lastUpdated:k6.lastUpdated,pluginCount:T6?.plugins.length,installedPlugins:v6,pendingUpdate:!1,pendingRemove:!1,autoUpdate:bQ6(G6,k6)})}if(V6.sort((G6,k6)=>{if(G6.name==="claude-plugin-directory")return-1;if(k6.name==="claude-plugin-directory")return 1;return G6.name.localeCompare(k6.name)}),j(V6),$6&&R){let G6=V6.find((k6)=>k6.name===R.name);if(G6)h(G6)}let f6=[];if(q6>0){let G6=r>0?` (${r} ${O7(r,"plugin")} bumped)`:"";f6.push(`Updated ${q6} ${O7(q6,"marketplace")}${G6}`)}if(o>0)f6.push(`Removed ${o} ${O7(o,"marketplace")}`);if(f6.length>0){let G6=`${e6.tick} ${f6.join(", ")}`;if($6)f(G6);else{if(!S.current)return;z(G6),clearTimeout(m.current),m.current=setTimeout(q,2000,{type:"menu"})}}else if(!$6){if(!S.current)return;q({type:"menu"})}}catch(H6){let q6=b6(H6);if(!S.current)return;if(Z(q6),_)_(q6)}finally{if(S.current)W(!1),V(null)}},c=async()=>{if(!R)return;let O6=$.map((J6)=>J6.name===R.name?{...J6,pendingRemove:!0}:J6);j(O6),await g(O6)},n=(O6)=>{if(!O6)return[];let J6=[{label:`Browse plugins (${O6.pluginCount??0})`,value:"browse"},{label:"Update marketplace",secondaryLabel:O6.lastUpdated?`(last updated ${new Date(O6.lastUpdated).toLocaleDateString()})`:void 0,value:"update"}];if(!ok6())J6.push({label:O6.autoUpdate?"Disable auto-update":"Enable auto-update",value:"toggle-auto-update"});return J6.push({label:"Remove marketplace",value:"remove"}),J6},l=async(O6)=>{let J6=!O6.autoUpdate;try{await XEK(O6.name,J6),j(($6)=>$6.map((H6)=>H6.name===O6.name?{...H6,autoUpdate:J6}:H6)),h(($6)=>$6?{...$6,autoUpdate:J6}:$6)}catch($6){Z($6 instanceof Error?$6.message:"Failed to update setting")}};G1("confirm:no",()=>{clearTimeout(m.current),N("list"),x(0)},{context:"Confirmation",isActive:!P&&(k==="details"||k==="confirm-remove")}),G1("confirm:no",()=>{clearTimeout(m.current),j((O6)=>O6.map((J6)=>({...J6,pendingUpdate:!1,pendingRemove:!1}))),M(0)},{context:"Confirmation",isActive:!P&&k==="list"&&F()}),G1("confirm:no",()=>{q({type:"menu"})},{context:"Confirmation",isActive:!P&&k==="list"&&!F()}),L7({"select:previous":()=>M((O6)=>Math.max(0,O6-1)),"select:next":()=>{let O6=$.length+1;M((J6)=>Math.min(O6-1,J6+1))},"select:accept":()=>{clearTimeout(m.current);let O6=X-1;if(X===0)q({type:"add-marketplace"});else if(F())g();else{let J6=$[O6];if(J6)h(J6),N("details"),x(0)}}},{context:"Select",isActive:!P&&k==="list"});function z6(O6){if(O6.ctrl||O6.meta||P)return;let J6=X-1;if((O6.key==="u"||O6.key==="U")&&J6>=0)O6.preventDefault(),clearTimeout(m.current),j(($6)=>$6.map((H6,q6)=>q6===J6?{...H6,pendingUpdate:!H6.pendingUpdate,pendingRemove:H6.pendingUpdate?H6.pendingRemove:!1}:H6));else if((O6.key==="r"||O6.key==="R")&&J6>=0){let $6=$[J6];if($6)O6.preventDefault(),h($6),clearTimeout(m.current),N("confirm-remove")}}L7({"select:previous":()=>x((O6)=>Math.max(0,O6-1)),"select:next":()=>{let O6=n(R);x((J6)=>Math.min(O6.length-1,J6+1))},"select:accept":()=>{if(clearTimeout(m.current),!R)return;let J6=n(R)[C];if(J6?.value==="browse")q({type:"browse-marketplace",targetMarketplace:R.name});else if(J6?.value==="update"){let $6=$.map((H6)=>H6.name===R.name?{...H6,pendingUpdate:!0}:H6);j($6),g($6)}else if(J6?.value==="toggle-auto-update")l(R);else if(J6?.value==="remove")N("confirm-remove")}},{context:"Select",isActive:!P&&k==="details"});function A6(O6){if(O6.ctrl||O6.meta||P)return;if(O6.key==="y"||O6.key==="Y")O6.preventDefault(),clearTimeout(m.current),c();else if(O6.key==="n"||O6.key==="N")O6.preventDefault(),clearTimeout(m.current),N("list"),h(null)}if(H)return $1.createElement(T,null,"Loading marketplaces…");if($.length===0)return $1.createElement(u,{flexDirection:"column"},$1.createElement(u,{marginBottom:1},$1.createElement(T,{bold:!0},"Manage marketplaces")),$1.createElement(u,{flexDirection:"row",gap:1},$1.createElement(T,{color:"suggestion"},e6.pointer," +"),$1.createElement(T,{bold:!0,color:"suggestion"},"Add Marketplace")),$1.createElement(u,{marginLeft:3},$1.createElement(T,{dimColor:!0,italic:!0},Y.pending?$1.createElement($1.Fragment,null,"Press ",Y.keyName," again to go back"):$1.createElement(z1,null,$1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),$1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"})))));if(k==="confirm-remove"&&R){let O6=R.installedPlugins?.length||0;return $1.createElement(u,{flexDirection:"column",tabIndex:0,autoFocus:!0,onKeyDown:A6},$1.createElement(T,{bold:!0,color:"warning"},"Remove marketplace ",$1.createElement(T,{italic:!0},R.name),"?"),$1.createElement(u,{flexDirection:"column"},O6>0&&$1.createElement(u,{marginTop:1},$1.createElement(T,{color:"warning"},"This will also uninstall ",O6," ",O7(O6,"plugin")," from this marketplace:")),R.installedPlugins&&R.installedPlugins.length>0&&$1.createElement(u,{flexDirection:"column",marginTop:1,marginLeft:2},R.installedPlugins.map((J6)=>$1.createElement(T,{key:J6.name,dimColor:!0},"• ",J6.name))),$1.createElement(u,{marginTop:1},$1.createElement(T,null,"Press ",$1.createElement(T,{bold:!0},"y")," to confirm or ",$1.createElement(T,{bold:!0},"n")," to cancel"))))}if(k==="details"&&R){let O6=R.pendingUpdate||P,J6=n(R);return $1.createElement(u,{flexDirection:"column"},$1.createElement(T,{bold:!0},R.name),$1.createElement(T,{dimColor:!0},R.source),$1.createElement(u,{marginTop:1},$1.createElement(T,null,R.pluginCount||0," available"," ",O7(R.pluginCount||0,"plugin"))),R.installedPlugins&&R.installedPlugins.length>0&&$1.createElement(u,{flexDirection:"column",marginTop:1},$1.createElement(T,{bold:!0},"Installed plugins (",R.installedPlugins.length,"):"),$1.createElement(u,{flexDirection:"column",marginLeft:1},R.installedPlugins.map(($6)=>$1.createElement(u,{key:$6.name,flexDirection:"row",gap:1},$1.createElement(T,null,e6.bullet),$1.createElement(u,{flexDirection:"column"},$1.createElement(T,null,$6.name),$1.createElement(T,{dimColor:!0},$6.manifest.description)))))),O6&&$1.createElement(u,{marginTop:1,flexDirection:"column"},$1.createElement(T,{color:"claude"},"Updating marketplace…"),v&&$1.createElement(T,{dimColor:!0},v)),!O6&&G&&$1.createElement(u,{marginTop:1},$1.createElement(T,{color:"claude"},G)),!O6&&D&&$1.createElement(u,{marginTop:1},$1.createElement(T,{color:"error"},D)),!O6&&$1.createElement(u,{flexDirection:"column",marginTop:1},J6.map(($6,H6)=>{if(!$6)return null;let q6=H6===C;return $1.createElement(u,{key:$6.value},$1.createElement(T,{color:q6?"suggestion":void 0},q6?e6.pointer:" "," ",$6.label),$6.secondaryLabel&&$1.createElement(T,{dimColor:!0}," ",$6.secondaryLabel))})),!O6&&!ok6()&&R.autoUpdate&&$1.createElement(u,{marginTop:1},$1.createElement(T,{dimColor:!0},"Auto-update enabled. Claude Code will automatically update this marketplace and its installed plugins.")),$1.createElement(u,{marginLeft:3},$1.createElement(T,{dimColor:!0,italic:!0},O6?$1.createElement($1.Fragment,null,"Please wait…"):$1.createElement(z1,null,$1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),$1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"})))))}let{updateCount:e,removeCount:i}=U();return $1.createElement(u,{flexDirection:"column",tabIndex:0,autoFocus:!0,onKeyDown:z6},$1.createElement(u,{marginBottom:1},$1.createElement(T,{bold:!0},"Manage marketplaces")),$1.createElement(u,{flexDirection:"row",gap:1,marginBottom:1},$1.createElement(T,{color:X===0?"suggestion":void 0},X===0?e6.pointer:" "," +"),$1.createElement(T,{bold:!0,color:X===0?"suggestion":void 0},"Add Marketplace")),$1.createElement(u,{flexDirection:"column"},$.map((O6,J6)=>{let $6=J6+1===X,H6=[];if(O6.pendingUpdate)H6.push("UPDATE");if(O6.pendingRemove)H6.push("REMOVE");return $1.createElement(u,{key:O6.name,flexDirection:"row",gap:1,marginBottom:1},$1.createElement(T,{color:$6?"suggestion":void 0},$6?e6.pointer:" "," ",O6.pendingRemove?e6.cross:e6.bullet),$1.createElement(u,{flexDirection:"column",flexGrow:1},$1.createElement(u,{flexDirection:"row",gap:1},$1.createElement(T,{bold:!0,strikethrough:O6.pendingRemove,dimColor:O6.pendingRemove},O6.name==="claude-plugins-official"&&$1.createElement(T,{color:"claude"},"✻ "),O6.name,O6.name==="claude-plugins-official"&&$1.createElement(T,{color:"claude"}," ✻")),H6.length>0&&$1.createElement(T,{color:"warning"},"[",H6.join(", "),"]")),$1.createElement(T,{dimColor:!0},O6.source),$1.createElement(T,{dimColor:!0},O6.pluginCount!==void 0&&$1.createElement($1.Fragment,null,O6.pluginCount," available"),O6.installedPlugins&&O6.installedPlugins.length>0&&$1.createElement($1.Fragment,null," • ",O6.installedPlugins.length," installed"),O6.lastUpdated&&$1.createElement($1.Fragment,null," ","• Updated"," ",new Date(O6.lastUpdated).toLocaleDateString()))))})),F()&&$1.createElement(u,{marginTop:1,flexDirection:"column"},$1.createElement(T,null,$1.createElement(T,{bold:!0},"Pending changes:")," ",$1.createElement(T,{dimColor:!0},$1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"apply"}))),e>0&&$1.createElement(T,null,"• Update ",e," ",O7(e,"marketplace")),i>0&&$1.createElement(T,{color:"warning"},"• Remove ",i," ",O7(i,"marketplace"))),P&&$1.createElement(u,{marginTop:1},$1.createElement(T,{color:"claude"},"Processing changes…")),D&&$1.createElement(u,{marginTop:1},$1.createElement(T,{color:"error"},D)),$1.createElement(PxY,{exitState:Y,hasPendingActions:F()}))}function PxY(q){let K=s(18),{exitState:_,hasPendingActions:z}=q;if(_.pending){let J;if(K[0]!==_.keyName)J=$1.createElement(u,{marginTop:1},$1.createElement(T,{dimColor:!0,italic:!0},"Press ",_.keyName," again to go back")),K[0]=_.keyName,K[1]=J;else J=K[1];return J}let Y;if(K[2]!==z)Y=z&&$1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"apply changes"}),K[2]=z,K[3]=Y;else Y=K[3];let A;if(K[4]!==z)A=!z&&$1.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),K[4]=z,K[5]=A;else A=K[5];let O;if(K[6]!==z)O=!z&&$1.createElement(A8,{chord:"u",action:"update"}),K[6]=z,K[7]=O;else O=K[7];let w;if(K[8]!==z)w=!z&&$1.createElement(A8,{chord:"r",action:"remove"}),K[8]=z,K[9]=w;else w=K[9];let $=z?"cancel":"go back",j;if(K[10]!==$)j=$1.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:$}),K[10]=$,K[11]=j;else j=K[11];let H;if(K[12]!==Y||K[13]!==A||K[14]!==O||K[15]!==w||K[16]!==j)H=$1.createElement(u,{marginTop:1},$1.createElement(T,{dimColor:!0,italic:!0},$1.createElement(z1,null,Y,A,O,w,j))),K[12]=Y,K[13]=A,K[14]=O,K[15]=w,K[16]=j,K[17]=H;else H=K[17];return H}var $1,jZ;var zFK=L(()=>{o6();Qq();C8();bK();Nq();u7();g6();C7();h1();m8();uR();Xc();m$();gi8();vH();Hv();a1();$1=K6(P6(),1),jZ=K6(P6(),1)});import{randomBytes as WxY}from"crypto";import{readFile as DxY,rename as ZxY,unlink as fxY,writeFile as GxY}from"fs/promises";import{join as vxY}from"path";function YFK(){return vxY(gP(),TxY)}function kxY(q){let K=n8(q);if(typeof K!=="object"||K===null||!("plugins"in K)||typeof K.plugins!=="object"||K.plugins===null)return{};let _=K.plugins,z={};for(let[Y,A]of Object.entries(_))if(A&&typeof A==="object"&&"flaggedAt"in A&&typeof A.flaggedAt==="string"){let O={flaggedAt:A.flaggedAt};if("seenAt"in A&&typeof A.seenAt==="string")O.seenAt=A.seenAt;z[Y]=O}return z}async function Ui8(){try{let q=await DxY(YFK(),{encoding:"utf-8"});return kxY(q)}catch{return{}}}async function Qi8(q){let K=YFK(),_=`${K}.${WxY(8).toString("hex")}.tmp`;try{await V8().mkdir(gP());let z=I6({plugins:q},null,2);await GxY(_,z,{encoding:"utf-8",mode:384}),await ZxY(_,K),WL=q}catch(z){j6(z);try{await fxY(_)}catch{}}}async function AFK(){let q=await Ui8(),K=Date.now(),_=!1;for(let[z,Y]of Object.entries(q))if(Y.seenAt&&K-new Date(Y.seenAt).getTime()>=VxY)delete q[z],_=!0;if(WL=q,_)await Qi8(q)}function xx6(){return WL??{}}async function OFK(q){if(WL===null)WL=await Ui8();let K={...WL,[q]:{flaggedAt:new Date().toISOString()}};await Qi8(K),E(`Flagged plugin: ${q}`)}async function wFK(q){if(WL===null)WL=await Ui8();let K=new Date().toISOString(),_=!1,z={...WL};for(let Y of q){let A=z[Y];if(A&&!A.seenAt)z[Y]={...A,seenAt:K},_=!0}if(_)await Qi8(z)}async function $FK(q){if(WL===null)WL=await Ui8();if(!(q in WL))return;let{[q]:K,..._}=WL;WL=_,await Qi8(_)}var TxY="flagged-plugins.json",VxY=172800000,WL=null;var di8=L(()=>{K8();Yq();U8();e8();Jy()});function g_6(q){switch(q.type){case"path-not-found":return`${q.component} path not found: ${q.path}`;case"path-traversal":return`${q.component} path escapes plugin directory: ${q.path}`;case"git-auth-failed":return`Git ${q.authType.toUpperCase()} authentication failed for ${q.gitUrl}`;case"git-timeout":return`Git ${q.operation} timed out for ${q.gitUrl}`;case"network-error":return`Network error accessing ${q.url}${q.details?`: ${q.details}`:""}`;case"manifest-parse-error":return`Failed to parse manifest at ${q.manifestPath}: ${q.parseError}`;case"manifest-validation-error":return`Invalid manifest at ${q.manifestPath}: ${q.validationErrors.join(", ")}`;case"plugin-not-found":return`Plugin "${q.pluginId}" not found in marketplace "${q.marketplace}"`;case"marketplace-not-found":return`Marketplace "${q.marketplace}" not found`;case"marketplace-load-failed":return`Failed to load marketplace "${q.marketplace}": ${q.reason}`;case"mcp-config-invalid":return`Invalid MCP server config for "${q.serverName}": ${q.validationError}`;case"mcp-server-suppressed-duplicate":{let _=q.duplicateOf.startsWith("plugin:")?`server provided by plugin "${q.duplicateOf.split(":")[1]??"?"}"`:`already-configured "${q.duplicateOf}"`;return`MCP server "${q.serverName}" skipped — same command/URL as ${_}`}case"hook-load-failed":return`Failed to load hooks from ${q.hookPath}: ${q.reason}`;case"component-load-failed":return`Failed to load ${q.component} from ${q.path}: ${q.reason}`;case"mcpb-download-failed":return`Failed to download MCPB from ${q.url}: ${q.reason}`;case"mcpb-extract-failed":return`Failed to extract MCPB ${q.mcpbPath}: ${q.reason}`;case"mcpb-invalid-manifest":return`MCPB manifest invalid at ${q.mcpbPath}: ${q.validationError}`;case"marketplace-blocked-by-policy":return q.blockedByBlocklist?`Marketplace "${q.marketplace}" is blocked by enterprise policy`:`Marketplace "${q.marketplace}" is not in the allowed marketplace list`;case"dependency-unsatisfied":return q.reason==="not-enabled"?`Dependency "${q.dependency}" is disabled`:`Dependency "${q.dependency}" is not installed`;case"dependency-version-unsatisfied":return`Requires "${q.dependency}" ${q.required}, installed ${q.installed??"version unknown"}`;case"lsp-config-invalid":return`Invalid LSP server config for "${q.serverName}": ${q.validationError}`;case"lsp-server-start-failed":return`LSP server "${q.serverName}" failed to start: ${q.reason}`;case"lsp-server-crashed":return q.signal?`LSP server "${q.serverName}" crashed with signal ${q.signal}`:`LSP server "${q.serverName}" crashed with exit code ${q.exitCode??"unknown"}`;case"lsp-request-timeout":return`LSP server "${q.serverName}" timed out on ${q.method} after ${q.timeoutMs}ms`;case"lsp-request-failed":return`LSP server "${q.serverName}" ${q.method} failed: ${q.error}`;case"plugin-cache-miss":return`Plugin "${q.plugin}" not cached at ${q.installPath}`;case"generic-error":return q.error}return GH(q)}function ux6(q){switch(q.type){case"path-not-found":return"Check that the path in your manifest or marketplace config is correct";case"path-traversal":return'Paths in plugin.json must not use ".." to reference files outside the plugin directory';case"git-auth-failed":return q.authType==="ssh"?"Configure SSH keys or use HTTPS URL instead":"Configure credentials or use SSH URL instead";case"git-timeout":case"network-error":return"Check your internet connection and try again";case"manifest-parse-error":return"Check manifest file syntax in the plugin directory";case"manifest-validation-error":return"Check manifest file follows the required schema";case"plugin-not-found":return`Plugin may not exist in marketplace "${q.marketplace}"`;case"marketplace-not-found":return q.availableMarketplaces.length>0?`Available marketplaces: ${q.availableMarketplaces.join(", ")}`:"Add the marketplace first using /plugin marketplace add";case"mcp-config-invalid":return"Check MCP server configuration in .mcp.json or manifest";case"mcp-server-suppressed-duplicate":{if(q.duplicateOf.startsWith("plugin:"))return`Disable plugin "${q.duplicateOf.split(":")[1]??"the other plugin"}" if you want this plugin's version instead`;return`Remove "${q.duplicateOf}" from your MCP config if you want the plugin's version instead`}case"hook-load-failed":return"Check hooks.json file syntax and structure";case"component-load-failed":return`Check ${q.component} directory structure and file permissions`;case"mcpb-download-failed":return"Check your internet connection and URL accessibility";case"mcpb-extract-failed":return"Verify the MCPB file is valid and not corrupted";case"mcpb-invalid-manifest":return"Contact the plugin author about the invalid manifest";case"marketplace-blocked-by-policy":if(q.blockedByBlocklist)return"This marketplace source is explicitly blocked by your administrator";return q.allowedSources.length>0?`Allowed sources: ${q.allowedSources.join(", ")}`:"Contact your administrator to configure allowed marketplace sources";case"dependency-unsatisfied":return q.reason==="not-enabled"?`Enable "${q.dependency}" or uninstall "${q.plugin}"`:`Install "${q.dependency}" or uninstall "${q.plugin}"`;case"dependency-version-unsatisfied":return`Update "${q.dependency}" to satisfy ${q.required}, or uninstall "${q.plugin}"`;case"lsp-config-invalid":return"Check LSP server configuration in the plugin manifest";case"lsp-server-start-failed":case"lsp-server-crashed":case"lsp-request-timeout":case"lsp-request-failed":return"Check LSP server logs with --debug for details";case"plugin-cache-miss":return"Run /plugins to refresh the plugin cache";case"marketplace-load-failed":case"generic-error":return null}let K=q;return null}var Jw7=()=>{};function jFK(q){let K=s(143),{item:_,isSelected:z}=q,[Y]=Zq();if(_.type==="plugin"){let v,V;if(_.pendingToggle){let l;if(K[0]!==Y)l=d7("suggestion",Y)(e6.arrowRight),K[0]=Y,K[1]=l;else l=K[1];v=l,V=_.pendingToggle==="will-enable"?"will enable":"will disable"}else if(_.errorCount>0){let l;if(K[2]!==Y)l=d7("error",Y)(e6.cross),K[2]=Y,K[3]=l;else l=K[3];v=l;let z6=_.errorCount,A6;if(K[4]!==_.errorCount)A6=O7(_.errorCount,"error"),K[4]=_.errorCount,K[5]=A6;else A6=K[5];V=`${z6} ${A6}`}else if(!_.isEnabled){let l;if(K[6]!==Y)l=d7("inactive",Y)(e6.radioOff),K[6]=Y,K[7]=l;else l=K[7];v=l,V="disabled"}else{let l;if(K[8]!==Y)l=d7("success",Y)(e6.tick),K[8]=Y,K[9]=l;else l=K[9];v=l,V="enabled"}let k=z?"suggestion":void 0,N=z?`${e6.pointer} `:" ",R;if(K[10]!==k||K[11]!==N)R=O4.createElement(T,{color:k},N),K[10]=k,K[11]=N,K[12]=R;else R=K[12];let h=z?"suggestion":void 0,C;if(K[13]!==_.name||K[14]!==h)C=O4.createElement(T,{color:h},_.name),K[13]=_.name,K[14]=h,K[15]=C;else C=K[15];let x=!z,B;if(K[16]===Symbol.for("react.memo_cache_sentinel"))B=O4.createElement(T,{backgroundColor:"userMessageBackground"},"Plugin"),K[16]=B;else B=K[16];let m;if(K[17]!==x)m=O4.createElement(T,{dimColor:x}," ",B),K[17]=x,K[18]=m;else m=K[18];let S;if(K[19]!==_.marketplace)S=O4.createElement(T,{dimColor:!0}," · ",_.marketplace),K[19]=_.marketplace,K[20]=S;else S=K[20];let F=!z,U;if(K[21]!==v||K[22]!==F)U=O4.createElement(T,{dimColor:F}," · ",v," "),K[21]=v,K[22]=F,K[23]=U;else U=K[23];let g=!z,c;if(K[24]!==V||K[25]!==g)c=O4.createElement(T,{dimColor:g},V),K[24]=V,K[25]=g,K[26]=c;else c=K[26];let n;if(K[27]!==U||K[28]!==c||K[29]!==R||K[30]!==C||K[31]!==m||K[32]!==S)n=O4.createElement(u,null,R,C,m,S,U,c),K[27]=U,K[28]=c,K[29]=R,K[30]=C,K[31]=m,K[32]=S,K[33]=n;else n=K[33];return n}if(_.type==="flagged-plugin"){let v;if(K[34]!==Y)v=d7("warning",Y)(e6.warning),K[34]=Y,K[35]=v;else v=K[35];let V=v,k=z?"suggestion":void 0,N=z?`${e6.pointer} `:" ",R;if(K[36]!==k||K[37]!==N)R=O4.createElement(T,{color:k},N),K[36]=k,K[37]=N,K[38]=R;else R=K[38];let h=z?"suggestion":void 0,C;if(K[39]!==_.name||K[40]!==h)C=O4.createElement(T,{color:h},_.name),K[39]=_.name,K[40]=h,K[41]=C;else C=K[41];let x=!z,B;if(K[42]===Symbol.for("react.memo_cache_sentinel"))B=O4.createElement(T,{backgroundColor:"userMessageBackground"},"Plugin"),K[42]=B;else B=K[42];let m;if(K[43]!==x)m=O4.createElement(T,{dimColor:x}," ",B),K[43]=x,K[44]=m;else m=K[44];let S;if(K[45]!==_.marketplace)S=O4.createElement(T,{dimColor:!0}," · ",_.marketplace),K[45]=_.marketplace,K[46]=S;else S=K[46];let F=!z,U;if(K[47]!==V||K[48]!==F)U=O4.createElement(T,{dimColor:F}," · ",V," "),K[47]=V,K[48]=F,K[49]=U;else U=K[49];let g=!z,c;if(K[50]!==g)c=O4.createElement(T,{dimColor:g},"removed"),K[50]=g,K[51]=c;else c=K[51];let n;if(K[52]!==S||K[53]!==U||K[54]!==c||K[55]!==R||K[56]!==C||K[57]!==m)n=O4.createElement(u,null,R,C,m,S,U,c),K[52]=S,K[53]=U,K[54]=c,K[55]=R,K[56]=C,K[57]=m,K[58]=n;else n=K[58];return n}if(_.type==="failed-plugin"){let v;if(K[59]!==Y)v=d7("error",Y)(e6.cross),K[59]=Y,K[60]=v;else v=K[60];let V=v,k=_.errorCount,N;if(K[61]!==_.errorCount)N=O7(_.errorCount,"error"),K[61]=_.errorCount,K[62]=N;else N=K[62];let R=`failed to load · ${k} ${N}`,h=z?"suggestion":void 0,C=z?`${e6.pointer} `:" ",x;if(K[63]!==h||K[64]!==C)x=O4.createElement(T,{color:h},C),K[63]=h,K[64]=C,K[65]=x;else x=K[65];let B=z?"suggestion":void 0,m;if(K[66]!==_.name||K[67]!==B)m=O4.createElement(T,{color:B},_.name),K[66]=_.name,K[67]=B,K[68]=m;else m=K[68];let S=!z,F;if(K[69]===Symbol.for("react.memo_cache_sentinel"))F=O4.createElement(T,{backgroundColor:"userMessageBackground"},"Plugin"),K[69]=F;else F=K[69];let U;if(K[70]!==S)U=O4.createElement(T,{dimColor:S}," ",F),K[70]=S,K[71]=U;else U=K[71];let g;if(K[72]!==_.marketplace)g=O4.createElement(T,{dimColor:!0}," · ",_.marketplace),K[72]=_.marketplace,K[73]=g;else g=K[73];let c=!z,n;if(K[74]!==V||K[75]!==c)n=O4.createElement(T,{dimColor:c}," · ",V," "),K[74]=V,K[75]=c,K[76]=n;else n=K[76];let l=!z,z6;if(K[77]!==R||K[78]!==l)z6=O4.createElement(T,{dimColor:l},R),K[77]=R,K[78]=l,K[79]=z6;else z6=K[79];let A6;if(K[80]!==U||K[81]!==g||K[82]!==n||K[83]!==z6||K[84]!==x||K[85]!==m)A6=O4.createElement(u,null,x,m,U,g,n,z6),K[80]=U,K[81]=g,K[82]=n,K[83]=z6,K[84]=x,K[85]=m,K[86]=A6;else A6=K[86];return A6}let A,O;if(_.status==="connected"){let v;if(K[87]!==Y)v=d7("success",Y)(e6.tick),K[87]=Y,K[88]=v;else v=K[88];A=v,O="connected"}else if(_.status==="disabled"){let v;if(K[89]!==Y)v=d7("inactive",Y)(e6.radioOff),K[89]=Y,K[90]=v;else v=K[90];A=v,O="disabled"}else if(_.status==="pending"){let v;if(K[91]!==Y)v=d7("inactive",Y)(e6.radioOff),K[91]=Y,K[92]=v;else v=K[92];A=v,O="connecting…"}else if(_.status==="needs-auth"){let v;if(K[93]!==Y)v=d7("warning",Y)(e6.triangleUpOutline),K[93]=Y,K[94]=v;else v=K[94];A=v;let V;if(K[95]===Symbol.for("react.memo_cache_sentinel"))V=O4.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"auth"}),K[95]=V;else V=K[95];O=V}else{let v;if(K[96]!==Y)v=d7("error",Y)(e6.cross),K[96]=Y,K[97]=v;else v=K[97];A=v,O="failed"}if(_.indented){let v=z?"suggestion":void 0,V=z?`${e6.pointer} `:" ",k;if(K[98]!==v||K[99]!==V)k=O4.createElement(T,{color:v},V),K[98]=v,K[99]=V,K[100]=k;else k=K[100];let N=!z,R;if(K[101]!==N)R=O4.createElement(T,{dimColor:N},"└ "),K[101]=N,K[102]=R;else R=K[102];let h=z?"suggestion":void 0,C;if(K[103]!==_.name||K[104]!==h)C=O4.createElement(T,{color:h},_.name),K[103]=_.name,K[104]=h,K[105]=C;else C=K[105];let x=!z,B;if(K[106]===Symbol.for("react.memo_cache_sentinel"))B=O4.createElement(T,{backgroundColor:"userMessageBackground"},"MCP"),K[106]=B;else B=K[106];let m;if(K[107]!==x)m=O4.createElement(T,{dimColor:x}," ",B),K[107]=x,K[108]=m;else m=K[108];let S=!z,F;if(K[109]!==A||K[110]!==S)F=O4.createElement(T,{dimColor:S}," · ",A," "),K[109]=A,K[110]=S,K[111]=F;else F=K[111];let U=!z,g;if(K[112]!==O||K[113]!==U)g=O4.createElement(T,{dimColor:U},O),K[112]=O,K[113]=U,K[114]=g;else g=K[114];let c;if(K[115]!==m||K[116]!==F||K[117]!==g||K[118]!==k||K[119]!==R||K[120]!==C)c=O4.createElement(u,null,k,R,C,m,F,g),K[115]=m,K[116]=F,K[117]=g,K[118]=k,K[119]=R,K[120]=C,K[121]=c;else c=K[121];return c}let w=z?"suggestion":void 0,$=z?`${e6.pointer} `:" ",j;if(K[122]!==w||K[123]!==$)j=O4.createElement(T,{color:w},$),K[122]=w,K[123]=$,K[124]=j;else j=K[124];let H=z?"suggestion":void 0,J;if(K[125]!==_.name||K[126]!==H)J=O4.createElement(T,{color:H},_.name),K[125]=_.name,K[126]=H,K[127]=J;else J=K[127];let X=!z,M;if(K[128]===Symbol.for("react.memo_cache_sentinel"))M=O4.createElement(T,{backgroundColor:"userMessageBackground"},"MCP"),K[128]=M;else M=K[128];let P;if(K[129]!==X)P=O4.createElement(T,{dimColor:X}," ",M),K[129]=X,K[130]=P;else P=K[130];let W=!z,D;if(K[131]!==A||K[132]!==W)D=O4.createElement(T,{dimColor:W}," · ",A," "),K[131]=A,K[132]=W,K[133]=D;else D=K[133];let Z=!z,G;if(K[134]!==O||K[135]!==Z)G=O4.createElement(T,{dimColor:Z},O),K[134]=O,K[135]=Z,K[136]=G;else G=K[136];let f;if(K[137]!==D||K[138]!==G||K[139]!==j||K[140]!==J||K[141]!==P)f=O4.createElement(u,null,j,J,P,D,G),K[137]=D,K[138]=G,K[139]=j,K[140]=J,K[141]=P,K[142]=f;else f=K[142];return f}var O4;var HFK=L(()=>{o6();Qq();bK();g6();O4=K6(P6(),1)});function Z_8(q){return q?.kind==="item"||q?.kind==="disabled-header"}function JFK(q){switch(q.type){case"plugin":return q.isEnabled&&q.errorCount>0;case"failed-plugin":case"flagged-plugin":return!0;case"mcp":return q.status==="needs-auth"||q.status==="failed"}}function Xw7(q){return q.type==="plugin"&&!q.isEnabled||q.type==="mcp"&&q.status==="disabled"}import*as cP6 from"fs/promises";import*as mx6 from"path";function NxY(q){switch(q){case"flagged":return"Flagged";case"project":return"Project";case"local":return"Local";case"user":return"User";case"enterprise":return"Enterprise";case"managed":return"Managed";case"builtin":case"dynamic":return"Built-in";default:return q}}async function XFK(q){try{return(await cP6.readdir(q,{withFileTypes:!0})).filter((_)=>_.isFile()&&_.name.endsWith(".md")).map((_)=>{return mx6.basename(_.name,".md")})}catch(K){let _=b6(K);return E(`Failed to read plugin components from ${q}: ${_}`,{level:"error"}),j6(r1(K)),[]}}async function ExY(q){try{let K=await cP6.readdir(q,{withFileTypes:!0}),_=[];for(let z of K)if(z.isDirectory()||z.isSymbolicLink()){let Y=mx6.join(q,z.name,"SKILL.md");try{if((await cP6.stat(Y)).isFile())_.push(z.name)}catch{}}return _}catch(K){let _=b6(K);return E(`Failed to read skill directories from ${q}: ${_}`,{level:"error"}),j6(r1(K)),[]}}function yxY({plugin:q,marketplace:K}){let[_,z]=C_.useState(null),[Y,A]=C_.useState(!0),[O,w]=C_.useState(null);if(C_.useEffect(()=>{async function j(){try{if(K==="builtin"){let X=Kf4(q.name);if(X){let M=X.skills?.map((D)=>D.name)??[],P=X.hooks?Object.keys(X.hooks):[],W=X.mcpServers?Object.keys(X.mcpServers):[];z({commands:null,agents:null,skills:M.length>0?M:null,hooks:P.length>0?P:null,mcpServers:W.length>0?W:null})}else w(`Built-in plugin ${q.name} not found`);A(!1);return}let J=(await xf(K)).plugins.find((X)=>X.name===q.name);if(J){let X=[];if(q.commandsPath)X.push(q.commandsPath);if(q.commandsPaths)X.push(...q.commandsPaths);let M=[];for(let v of X)if(typeof v==="string"){let V=await XFK(v);M.push(...V)}let P=[];if(q.agentsPath)P.push(q.agentsPath);if(q.agentsPaths)P.push(...q.agentsPaths);let W=[];for(let v of P)if(typeof v==="string"){let V=await XFK(v);W.push(...V)}let D=[];if(q.skillsPath)D.push(q.skillsPath);if(q.skillsPaths)D.push(...q.skillsPaths);let Z=[];for(let v of D)if(typeof v==="string"){let V=await ExY(v);Z.push(...V)}let G=[];if(q.hooksConfig)G.push(Object.keys(q.hooksConfig));if(J.hooks)G.push(J.hooks);let f=[];if(q.mcpServers)f.push(Object.keys(q.mcpServers));if(J.mcpServers)f.push(J.mcpServers);z({commands:M.length>0?M:null,agents:W.length>0?W:null,skills:Z.length>0?Z:null,hooks:G.length>0?G:null,mcpServers:f.length>0?f:null})}else w(`Plugin ${q.name} not found in marketplace`)}catch(H){w(H instanceof Error?H.message:"Failed to load components")}finally{A(!1)}}j()},[q.name,q.commandsPath,q.commandsPaths,q.agentsPath,q.agentsPaths,q.skillsPath,q.skillsPaths,q.hooksConfig,q.mcpServers,K]),Y)return null;if(O)return E8.createElement(u,{flexDirection:"column",marginBottom:1},E8.createElement(T,{bold:!0},"Components:"),E8.createElement(T,{dimColor:!0},"Error: ",O));if(!_)return null;if(!(_.commands||_.agents||_.skills||_.hooks||_.mcpServers))return null;return E8.createElement(u,{flexDirection:"column",marginBottom:1},E8.createElement(T,{bold:!0},"Installed components:"),_.commands?E8.createElement(T,{dimColor:!0},"• Commands:"," ",typeof _.commands==="string"?_.commands:Array.isArray(_.commands)?_.commands.join(", "):Object.keys(_.commands).join(", ")):null,_.agents?E8.createElement(T,{dimColor:!0},"• Agents:"," ",typeof _.agents==="string"?_.agents:Array.isArray(_.agents)?_.agents.join(", "):Object.keys(_.agents).join(", ")):null,_.skills?E8.createElement(T,{dimColor:!0},"• Skills:"," ",typeof _.skills==="string"?_.skills:Array.isArray(_.skills)?_.skills.join(", "):Object.keys(_.skills).join(", ")):null,_.hooks?E8.createElement(T,{dimColor:!0},"• Hooks:"," ",typeof _.hooks==="string"?_.hooks:Array.isArray(_.hooks)?_.hooks.map(String).join(", "):typeof _.hooks==="object"&&_.hooks!==null?Object.keys(_.hooks).join(", "):String(_.hooks)):null,_.mcpServers?E8.createElement(T,{dimColor:!0},"• MCP Servers:"," ",typeof _.mcpServers==="string"?_.mcpServers:Array.isArray(_.mcpServers)?_.mcpServers.map(String).join(", "):typeof _.mcpServers==="object"&&_.mcpServers!==null?Object.keys(_.mcpServers).join(", "):String(_.mcpServers)):null)}async function LxY(q,K){let z=(await xf(K))?.plugins.find((Y)=>Y.name===q);if(z&&typeof z.source==="string")return`Local plugins cannot be updated remotely. To update, modify the source at: ${z.source}`;return null}function hxY(q){return q.filter((K)=>{let _=K.source.split("@")[1]||"local";return!Rk(`${K.name}@${_}`)})}function MFK({setViewState:q,setResult:K,onManageComplete:_,onSearchModeChange:z,targetPlugin:Y,targetMarketplace:A,action:O}){let w=M8((h6)=>h6.mcp.clients),$=M8((h6)=>h6.mcp.tools),j=M8((h6)=>h6.plugins.errors),H=xx6(),[J,X]=C_.useState(!1),M=C_.useCallback((h6)=>{X(h6),z?.(h6)},[z]),P=K2(),W=bP(),D=s1(),{columns:Z}=D,{rows:G}=Fd(D),[f,v]=C_.useState("plugin-list"),{query:V,setQuery:k,cursorOffset:N,handleKeyDown:R,handlePaste:h}=bS({isActive:f==="plugin-list"&&J,onExit:()=>{M(!1)}}),[C,x]=C_.useState(null),[B,m]=C_.useState([]),[S,F]=C_.useState([]),[U,g]=C_.useState(!0),[c,n]=C_.useState(new Map),l=C_.useRef(!1),z6=C_.useRef(void 0),A6=m_6(),e=E8.useCallback(()=>{if(f==="plugin-details")v("plugin-list"),x(null),L6(null);else if(typeof f==="object"&&f.type==="failed-plugin-details")v("plugin-list"),L6(null);else if(f==="configuring")v("plugin-details"),c6(null);else if(typeof f==="object"&&(f.type==="plugin-options"||f.type==="configuring-options")){if(v("plugin-list"),x(null),K("Plugin enabled. Configuration skipped — run /reload-plugins to apply."),_)_()}else if(typeof f==="object"&&f.type==="flagged-detail")v("plugin-list"),L6(null);else if(typeof f==="object"&&f.type==="mcp-detail")v("plugin-list"),L6(null);else if(typeof f==="object"&&f.type==="mcp-tools")v({type:"mcp-detail",client:f.client});else if(typeof f==="object"&&f.type==="mcp-tool-detail")v({type:"mcp-tools",client:f.client});else{if(c.size>0){K("Run /reload-plugins to apply plugin changes.");return}q({type:"menu"})}},[f,q,c,K]);G1("confirm:no",e,{context:"Confirmation",isActive:(f!=="plugin-list"||!J)&&f!=="confirm-project-uninstall"&&!(typeof f==="object"&&f.type==="confirm-data-cleanup")});let i=(h6)=>{if(h6.type==="connected")return"connected";if(h6.type==="disabled")return"disabled";if(h6.type==="pending")return"pending";if(h6.type==="needs-auth")return"needs-auth";return"failed"},O6=C_.useMemo(()=>{let h6=y7(),_8=new Map;for(let l6 of w)if(l6.name.startsWith("plugin:")){let j8=l6.name.split(":");if(j8.length>=3){let f8=j8[1],p8=j8.slice(2).join(":"),o8=_8.get(f8)||[];o8.push({displayName:p8,client:l6}),_8.set(f8,o8)}}let R8=[];for(let l6 of S){let j8=`${l6.plugin.name}@${l6.marketplace}`,f8=h6?.enabledPlugins?.[j8]!==!1,p8=j.filter((n1)=>("plugin"in n1)&&n1.plugin===l6.plugin.name||n1.source===j8||n1.source.startsWith(`${l6.plugin.name}@`)),o8=l6.plugin.isBuiltin?"builtin":l6.scope||"user";R8.push({item:{type:"plugin",id:j8,name:l6.plugin.name,description:l6.plugin.manifest.description,marketplace:l6.marketplace,scope:o8,isEnabled:f8,errorCount:p8.length,errors:p8,plugin:l6.plugin,pendingEnable:l6.pendingEnable,pendingUpdate:l6.pendingUpdate,pendingToggle:c.get(j8)},originalScope:o8,childMcps:_8.get(l6.plugin.name)||[]})}let x6=new Set(R8.map(({item:l6})=>l6.id)),i6=new Set(R8.map(({item:l6})=>l6.name)),v8=new Map;for(let l6 of j){if(x6.has(l6.source)||"plugin"in l6&&typeof l6.plugin==="string"&&i6.has(l6.plugin))continue;let j8=v8.get(l6.source)||[];j8.push(l6),v8.set(l6.source,j8)}let f1=p_6(),g8=[];for(let[l6,j8]of v8){if(l6 in H)continue;let f8=Z4(l6),p8=f8.name||l6,o8=f8.marketplace||"unknown",n1=f1.get(l6),c1=n1==="flag"||n1===void 0?"user":n1;g8.push({type:"failed-plugin",id:l6,name:p8,marketplace:o8,scope:c1,errorCount:j8.length,errors:j8})}let w6=[];for(let l6 of w){if(l6.name==="ide")continue;if(l6.name.startsWith("plugin:"))continue;w6.push({type:"mcp",id:`mcp:${l6.name}`,name:l6.name,description:void 0,scope:l6.config.scope,status:i(l6),client:l6})}let D6={flagged:-1,project:0,local:1,user:2,enterprise:3,managed:4,dynamic:5,builtin:6},U6=[],F6=new Map;for(let{item:l6,originalScope:j8,childMcps:f8}of R8){let p8=l6.scope;if(!F6.has(p8))F6.set(p8,[]);F6.get(p8).push(l6);for(let{displayName:o8,client:n1}of f8){let c1=j8==="builtin"?"user":j8;if(!F6.has(c1))F6.set(c1,[]);F6.get(c1).push({type:"mcp",id:`mcp:${n1.name}`,name:o8,description:void 0,scope:c1,status:i(n1),client:n1,indented:!0})}}for(let l6 of w6){let j8=l6.scope;if(!F6.has(j8))F6.set(j8,[]);F6.get(j8).push(l6)}for(let l6 of g8){let j8=l6.scope;if(!F6.has(j8))F6.set(j8,[]);F6.get(j8).push(l6)}for(let[l6,j8]of Object.entries(H)){let f8=Z4(l6),p8=f8.name||l6,o8=f8.marketplace||"unknown";if(!F6.has("flagged"))F6.set("flagged",[]);F6.get("flagged").push({type:"flagged-plugin",id:l6,name:p8,marketplace:o8,scope:"flagged",reason:"delisted",text:"Removed from marketplace",flaggedAt:j8.flaggedAt})}let z8=[...F6.keys()].sort((l6,j8)=>(D6[l6]??99)-(D6[j8]??99));for(let l6 of z8){let j8=F6.get(l6),f8=[],p8=[],o8=0;while(o8<j8.length){let n1=j8[o8];if(n1.type==="plugin"||n1.type==="failed-plugin"||n1.type==="flagged-plugin"){let c1=[n1];o8++;let dq=j8[o8];while(dq?.type==="mcp"&&dq.indented)c1.push(dq),o8++,dq=j8[o8];f8.push(c1)}else if(n1.type==="mcp"&&!n1.indented)p8.push(n1),o8++;else o8++}f8.sort((n1,c1)=>n1[0].name.localeCompare(c1[0].name)),p8.sort((n1,c1)=>n1.name.localeCompare(c1.name));for(let n1 of f8)U6.push(...n1);U6.push(...p8)}return U6},[S,w,j,c,H]),J6=C_.useMemo(()=>O6.filter((h6)=>h6.type==="flagged-plugin").map((h6)=>h6.id),[O6]);C_.useEffect(()=>{if(J6.length>0)wFK(J6)},[J6]);let[$6,H6]=C_.useState(()=>new Set(H8().favoritePlugins??[])),q6=C_.useCallback((h6)=>{H6((_8)=>{let R8=new Set(_8);if(R8.has(h6))R8.delete(h6);else R8.add(h6);return d8((x6)=>({...x6,favoritePlugins:[...R8]})),R8})},[]),[o,_6]=C_.useState(!1),r=C_.useMemo(()=>{if(V){let i6=V.toLowerCase();return O6.filter((v8)=>v8.name.toLowerCase().includes(i6)||("description"in v8)&&v8.description?.toLowerCase().includes(i6)).map((v8)=>({kind:"item",section:"main",item:v8}))}let h6=[],_8=null,R8=(i6,v8)=>{let f1=_8?.section!==i6;if(f1){if(h6.length>0&&h6.at(-1)?.kind!=="disabled-header")h6.push({kind:"spacer"});if(i6==="attention"||i6==="favorites")h6.push({kind:"section-header",section:i6})}if((i6==="main"||i6==="disabled")&&(f1||_8?.item.scope!==v8.scope)){if(!f1)h6.push({kind:"spacer"});h6.push({kind:"scope-header",scope:v8.scope})}let g8=!f1&&_8?.item.type==="plugin",w6=v8.type==="mcp"&&v8.indented&&!g8?{...v8,indented:!1}:v8;h6.push({kind:"item",section:i6,item:w6}),_8={section:i6,item:w6}};for(let i6 of O6)if(JFK(i6))R8("attention",i6);for(let i6 of O6)if($6.has(i6.id))R8("favorites",i6);for(let i6 of O6)if(!Xw7(i6))R8("main",i6);let x6=O6.filter(Xw7);if(x6.length>0){if(h6.length>0)h6.push({kind:"spacer"});if(h6.push({kind:"disabled-header",count:x6.length}),o)for(let i6 of x6)R8("disabled",i6)}return h6},[O6,V,$6,o]),t=C_.useCallback((h6,_8)=>{let R8=_8===-1?Math.min(h6,r.length-1):h6;for(let x6=R8;x6>=0&&x6<r.length;x6+=_8)if(Z_8(r[x6]))return x6;return-1},[r]),[Y6,X6]=C_.useState(0),M6=C_.useRef(null);C_.useEffect(()=>{if(r.length===0)return;let h6=M6.current;if(h6){M6.current=null;let _8=r.findIndex((R8)=>R8.kind==="item"&&R8.section===h6.section&&R8.item.id===h6.id);if(_8!==-1){X6(_8);return}}if(!Z_8(r[Y6])){let _8=t(Y6,1),R8=t(Y6,-1);X6(_8!==-1?_8:R8!==-1?R8:0)}},[r,Y6,t]);let W6=W?Math.max(8,G-10):8,V6=QP6({totalItems:r.length,selectedIndex:Y6,maxVisible:W6}),[f6,G6]=C_.useState(0),[k6,T6]=C_.useState(!1),[v6,L6]=C_.useState(null),[y6,c6]=C_.useState(null),[Z8,N8]=C_.useState(!1),[R6,p6]=C_.useState(!1);C_.useEffect(()=>{if(!C){p6(!1);return}async function h6(){let _8=C.plugin.manifest.mcpServers,R8=!1;if(_8)R8=typeof _8==="string"&&Zx(_8)||Array.isArray(_8)&&_8.some((x6)=>typeof x6==="string"&&Zx(x6));if(!R8)try{let x6=mx6.join(C.plugin.path,".."),i6=mx6.join(x6,".claude-plugin","marketplace.json"),v8=await cP6.readFile(i6,"utf-8"),g8=n8(v8).plugins?.find((w6)=>w6.name===C.plugin.name);if(g8?.mcpServers){let w6=g8.mcpServers;R8=typeof w6==="string"&&Zx(w6)||Array.isArray(w6)&&w6.some((D6)=>typeof D6==="string"&&Zx(D6))}}catch(x6){E(`Failed to read raw marketplace.json: ${x6}`)}p6(R8)}h6()},[C]),C_.useEffect(()=>{async function h6(){g(!0);try{let{enabled:_8,disabled:R8}=await sW(),x6=y7(),i6=hxY([..._8,...R8]),v8={};for(let w6 of i6){let D6=w6.source.split("@")[1]||"local";if(!v8[D6])v8[D6]=[];v8[D6].push(w6)}let f1=[];for(let[w6,D6]of Object.entries(v8)){let U6=w7(D6,(z8)=>{let l6=`${z8.name}@${w6}`;return x6?.enabledPlugins?.[l6]!==!1}),F6=D6.length-U6;f1.push({name:w6,installedPlugins:D6,enabledCount:U6,disabledCount:F6})}f1.sort((w6,D6)=>{if(w6.name==="claude-plugin-directory")return-1;if(D6.name==="claude-plugin-directory")return 1;return w6.name.localeCompare(D6.name)}),m(f1);let g8=[];for(let w6 of f1)for(let D6 of w6.installedPlugins){let U6=`${D6.name}@${w6.name}`,F6=D6.isBuiltin?"builtin":pi8(U6).scope;g8.push({plugin:D6,marketplace:w6.name,scope:F6,pendingEnable:void 0,pendingUpdate:!1})}F(g8),X6(0)}finally{g(!1)}}h6()},[]),C_.useEffect(()=>{if(l.current)return;if(Y&&B.length>0&&!U){let{name:h6,marketplace:_8}=Z4(Y),R8=A??_8,x6=R8?B.filter((v8)=>v8.name===R8):B;for(let v8 of x6){let f1=v8.installedPlugins.find((g8)=>g8.name===h6);if(f1){let g8=`${f1.name}@${v8.name}`,{scope:w6}=pi8(g8),D6={plugin:f1,marketplace:v8.name,scope:w6,pendingEnable:void 0,pendingUpdate:!1};x(D6),v("plugin-details"),z6.current=O,l.current=!0;return}}let i6=O6.find((v8)=>v8.type==="failed-plugin"&&v8.name===h6);if(i6&&i6.type==="failed-plugin")v({type:"failed-plugin-details",plugin:{id:i6.id,name:i6.name,marketplace:i6.marketplace,errors:i6.errors,scope:i6.scope}}),l.current=!0;if(!l.current&&O)l.current=!0,K(`Plugin "${Y}" is not installed in this project`)}},[Y,A,B,U,O6,O,K]);let q8=async(h6)=>{if(!C)return;let _8=C.scope||"user",R8=_8==="builtin";if(R8&&(h6==="update"||h6==="uninstall")){L6("Built-in plugins cannot be updated or uninstalled.");return}if(!R8&&!Rx6(_8)&&h6!=="update"){L6("This plugin is managed by your organization. Contact your admin to disable it.");return}T6(!0),L6(null);try{let x6=`${C.plugin.name}@${C.marketplace}`,i6;switch(h6){case"enable":{let F6=await Sx6(x6);if(!F6.success)throw Error(F6.message);break}case"disable":{let F6=await Cx6(x6);if(!F6.success)throw Error(F6.message);i6=F6.reverseDependents;break}case"uninstall":{if(R8)break;if(!Rx6(_8))break;if(spK(x6)){T6(!1),v("confirm-project-uninstall");return}let F6=OZ().plugins[x6],l6=!F6||F6.length<=1?await oZ4(x6):null;if(l6){T6(!1),v({type:"confirm-data-cleanup",size:l6});return}let j8=await ie(x6,_8);if(!j8.success)throw Error(j8.message);i6=j8.reverseDependents;break}case"update":{if(R8)break;let F6=await bx6(x6,_8);if(!F6.success)throw Error(F6.message);if(F6.alreadyUpToDate||F6.skipped){if(K(F6.message),_)await _();q({type:"menu"});return}break}}YO();let v8=`${C.plugin.name}@${C.marketplace}`;if(y7()?.enabledPlugins?.[v8]!==!1){T6(!1),v({type:"plugin-options"});return}let w6=h6==="enable"?"Enabled":h6==="disable"?"Disabled":h6==="update"?"Updated":"Uninstalled",D6=i6&&i6.length>0?` · required by ${i6.join(", ")}`:"",U6=`✓ ${w6} ${C.plugin.name}${D6}. Run /reload-plugins to apply.`;if(K(U6),_)await _();q({type:"menu"})}catch(x6){T6(!1);let i6=x6 instanceof Error?x6.message:String(x6);L6(`Failed to ${h6}: ${i6}`),j6(r1(x6))}},L8=C_.useRef(q8);L8.current=q8,C_.useEffect(()=>{if(f==="plugin-details"&&C&&z6.current){let h6=z6.current;z6.current=void 0,L8.current(h6)}},[f,C]);let w8=E8.useCallback(()=>{let h6=r[Y6];if(!Z_8(h6))return;if(h6.kind==="disabled-header"){_6((R8)=>!R8);return}let _8=h6.item;if(_8.type==="flagged-plugin")return;if(_8.type==="plugin"){let R8=`${_8.plugin.name}@${_8.marketplace}`,x6=y7(),i6=c.get(R8),v8=x6?.enabledPlugins?.[R8]!==!1,f1=_8.scope;if(f1==="builtin"||Rx6(f1)){let w6=new Map(c);if(i6)w6.delete(R8),(async()=>{try{if(i6==="will-disable")await Sx6(R8);else await Cx6(R8);YO()}catch(D6){j6(D6)}})();else w6.set(R8,v8?"will-disable":"will-enable"),(async()=>{try{if(v8)await Cx6(R8);else await Sx6(R8);YO()}catch(D6){j6(D6)}})();n(w6)}}else if(_8.type==="mcp")A6(_8.client.name)},[Y6,r,c,S,A6]),x8=E8.useCallback(()=>{let h6=r[Y6];if(!Z_8(h6))return;if(h6.kind==="disabled-header"){_6((R8)=>!R8);return}let _8=h6.item;if(_8.type==="plugin"){let R8=S.find((x6)=>x6.plugin.name===_8.plugin.name&&x6.marketplace===_8.marketplace);if(R8)x(R8),v("plugin-details"),G6(0),L6(null)}else if(_8.type==="flagged-plugin")v({type:"flagged-detail",plugin:{id:_8.id,name:_8.name,marketplace:_8.marketplace,reason:_8.reason,text:_8.text,flaggedAt:_8.flaggedAt}}),L6(null);else if(_8.type==="failed-plugin")v({type:"failed-plugin-details",plugin:{id:_8.id,name:_8.name,marketplace:_8.marketplace,errors:_8.errors,scope:_8.scope}}),G6(0),L6(null);else if(_8.type==="mcp")v({type:"mcp-detail",client:_8.client}),L6(null)},[Y6,r,S]);L7({"select:previous":()=>{let h6=t(Y6-1,-1);if(h6===-1)M(!0);else V6.handleSelectionChange(h6,X6)},"select:next":()=>{let h6=t(Y6+1,1);if(h6!==-1)V6.handleSelectionChange(h6,X6)},"select:accept":x8},{context:"Select",isActive:f==="plugin-list"&&!J});let a6=E8.useCallback(()=>{let h6=r[Y6];if(h6?.kind!=="item")return;M6.current={section:h6.section,id:h6.item.id},q6(h6.item.id)},[r,Y6,q6]);L7({"plugin:toggle":w8,"plugin:favorite":a6},{context:"Plugin",isActive:f==="plugin-list"&&!J});let D8=E8.useCallback(()=>{if(typeof f!=="object"||f.type!=="flagged-detail")return;$FK(f.plugin.id),v("plugin-list")},[f]);L7({"select:accept":D8},{context:"Select",isActive:typeof f==="object"&&f.type==="flagged-detail"});let Q6=E8.useMemo(()=>{if(f!=="plugin-details"||!C)return[];let h6=y7(),_8=`${C.plugin.name}@${C.marketplace}`,R8=h6?.enabledPlugins?.[_8]!==!1,x6=C.marketplace==="builtin",i6=[];if(i6.push({label:R8?"Disable plugin":"Enable plugin",action:()=>void q8(R8?"disable":"enable")}),i6.push({label:$6.has(_8)?"Remove from favorites":"Add to favorites",action:()=>q6(_8)}),!x6){if(i6.push({label:C.pendingUpdate?"Unmark for update":"Mark for update",action:async()=>{try{let v8=await LxY(C.plugin.name,C.marketplace);if(v8){L6(v8);return}let f1=[...S],g8=f1.findIndex((w6)=>w6.plugin.name===C.plugin.name&&w6.marketplace===C.marketplace);if(g8!==-1)f1[g8].pendingUpdate=!C.pendingUpdate,F(f1),x({...C,pendingUpdate:!C.pendingUpdate})}catch(v8){L6(v8 instanceof Error?v8.message:"Failed to check plugin update availability")}}}),R6)i6.push({label:"Configure",action:async()=>{N8(!0);try{let v8=C.plugin.manifest.mcpServers,f1=null;if(typeof v8==="string"&&Zx(v8))f1=v8;else if(Array.isArray(v8)){for(let D6 of v8)if(typeof D6==="string"&&Zx(D6)){f1=D6;break}}if(!f1){L6("No MCPB file found in plugin"),N8(!1);return}let g8=`${C.plugin.name}@${C.marketplace}`,w6=await P88(f1,C.plugin.path,g8,void 0,void 0,!0);if("status"in w6&&w6.status==="needs-config")c6(w6),v("configuring");else L6("Failed to load MCPB for configuration")}catch(v8){let f1=b6(v8);L6(`Failed to load configuration: ${f1}`)}finally{N8(!1)}}});if(C.plugin.manifest.userConfig&&Object.keys(C.plugin.manifest.userConfig).length>0)i6.push({label:"Configure options",action:()=>{v({type:"configuring-options",schema:C.plugin.manifest.userConfig})}});i6.push({label:"Update now",action:()=>void q8("update")}),i6.push({label:"Uninstall",action:()=>void q8("uninstall")})}if(C.plugin.manifest.homepage)i6.push({label:"Open homepage",action:()=>void J3(C.plugin.manifest.homepage)});if(C.plugin.manifest.repository)i6.push({label:"View repository",action:()=>void J3(C.plugin.manifest.repository)});return i6.push({label:"Back to plugin list",action:()=>{v("plugin-list"),x(null),L6(null)}}),i6},[f,C,R6,S,$6,q6]);L7({"select:previous":()=>{if(f6>0)G6(f6-1)},"select:next":()=>{if(f6<Q6.length-1)G6(f6+1)},"select:accept":()=>{if(Q6[f6])Q6[f6].action()}},{context:"Select",isActive:f==="plugin-details"&&!!C}),L7({"select:accept":()=>{if(typeof f==="object"&&f.type==="failed-plugin-details")(async()=>{T6(!0),L6(null);let h6=f.plugin.id,_8=f.plugin.scope,R8=Rx6(_8)?await ie(h6,_8,!1):await ie(h6,"user",!1),x6=R8.success;if(!x6){for(let i6 of $v){let v8=E1(i6);if(v8?.enabledPlugins?.[h6]!==void 0)P7(i6,{enabledPlugins:{...v8.enabledPlugins,[h6]:void 0}}),x6=!0}YO()}if(x6){if(_)await _();T6(!1),v("plugin-list")}else T6(!1),L6(R8.message)})()}},{context:"Select",isActive:typeof f==="object"&&f.type==="failed-plugin-details"&&f.plugin.scope!=="managed"}),L7({"confirm:yes":()=>{if(!C)return;T6(!0),L6(null);let h6=`${C.plugin.name}@${C.marketplace}`,{error:_8}=P7("localSettings",{enabledPlugins:{...E1("localSettings")?.enabledPlugins,[h6]:!1}});if(_8){T6(!1),L6(`Failed to write settings: ${_8.message}`);return}if(YO(),K(`✓ Disabled ${C.plugin.name} in .claude/settings.local.json. Run /reload-plugins to apply.`),_)_();q({type:"menu"})},"confirm:no":()=>{v("plugin-details"),L6(null)}},{context:"Confirmation",isActive:f==="confirm-project-uninstall"&&!!C&&!k6});function W8(h6){if(h6.ctrl||h6.meta||k6)return;if(!C)return;let _8=`${C.plugin.name}@${C.marketplace}`,R8=C.scope;if(!R8||R8==="builtin"||!Rx6(R8))return;let x6=async(i6)=>{T6(!0),L6(null);try{let v8=await ie(_8,R8,i6);if(!v8.success)throw Error(v8.message);YO();let f1=i6?"":" · data preserved";if(K(`${e6.tick} ${v8.message}${f1}`),_)_();q({type:"menu"})}catch(v8){T6(!1),L6(v8 instanceof Error?v8.message:String(v8))}};if(h6.key==="y"||h6.key==="Y")h6.preventDefault(),x6(!0);else if(h6.key==="n"||h6.key==="N")h6.preventDefault(),x6(!1);else if(h6.key==="escape")h6.preventDefault(),v("plugin-details"),L6(null)}E8.useEffect(()=>{X6(0)},[V]);function G8(h6){if(J){R(h6);return}if(h6.ctrl||h6.meta)return;if(h6.key==="/")h6.preventDefault(),M(!0),k(""),X6(0);else if(h6.key.length===1&&h6.key!==" ")h6.preventDefault(),M(!0),k(h6.key),X6(0)}function s6(h6){if(J){h(h6);return}let _8=(h6.text.split(/\r\n|\r|\n/,2)[0]??"").trim();if(!_8)return;h6.preventDefault(),M(!0),k(_8),X6(0)}if(U)return E8.createElement(T,null,"Loading installed plugins…");if(O6.length===0)return E8.createElement(u,{flexDirection:"column"},E8.createElement(u,{marginBottom:1},E8.createElement(T,{bold:!0},"Manage plugins")),E8.createElement(T,null,"No plugins or MCP servers installed."),E8.createElement(u,{marginTop:1},E8.createElement(T,{dimColor:!0},E8.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"go back"}))));if(typeof f==="object"&&f.type==="plugin-options"&&C){let _8=function(R8){if(K(R8),_)_();q({type:"menu"})},h6=`${C.plugin.name}@${C.marketplace}`;return E8.createElement(yx6,{plugin:C.plugin,pluginId:h6,onDone:(R8,x6)=>{switch(R8){case"configured":_8(`✓ Enabled and configured ${C.plugin.name}. Run /reload-plugins to apply.`);break;case"skipped":_8(`✓ Enabled ${C.plugin.name}. Run /reload-plugins to apply.`);break;case"error":_8(`Failed to save configuration: ${x6}`);break}}})}if(typeof f==="object"&&f.type==="configuring-options"&&C){let h6=`${C.plugin.name}@${C.marketplace}`;return E8.createElement(P_8,{title:`Configure ${C.plugin.name}`,subtitle:"Plugin options",configSchema:f.schema,initialValues:ID(h6),onSave:(_8)=>{try{Tb8(h6,_8,f.schema),YO(),K("Configuration saved. Run /reload-plugins for changes to take effect.")}catch(R8){L6(`Failed to save configuration: ${b6(R8)}`)}v("plugin-details")},onCancel:()=>v("plugin-details")})}if(f==="configuring"&&y6&&C){let R8=function(){c6(null),v("plugin-details")},h6=`${C.plugin.name}@${C.marketplace}`;async function _8(x6){if(!y6||!C)return;try{let i6=C.plugin.manifest.mcpServers,v8=null;if(typeof i6==="string"&&Zx(i6))v8=i6;else if(Array.isArray(i6)){for(let f1 of i6)if(typeof f1==="string"&&Zx(f1)){v8=f1;break}}if(!v8){L6("No MCPB file found"),v("plugin-details");return}await P88(v8,C.plugin.path,h6,void 0,x6),L6(null),c6(null),v("plugin-details"),K("Configuration saved. Run /reload-plugins for changes to take effect.")}catch(i6){let v8=b6(i6);L6(`Failed to save configuration: ${v8}`),v("plugin-details")}}return E8.createElement(P_8,{title:`Configure ${y6.manifest.name}`,subtitle:`Plugin: ${C.plugin.name}`,configSchema:y6.configSchema,initialValues:y6.existingConfig,onSave:_8,onCancel:R8})}if(typeof f==="object"&&f.type==="flagged-detail"){let h6=f.plugin;return E8.createElement(u,{flexDirection:"column"},E8.createElement(u,null,E8.createElement(T,{bold:!0},h6.name," @ ",h6.marketplace)),E8.createElement(u,{marginBottom:1},E8.createElement(T,{dimColor:!0},"Status: "),E8.createElement(T,{color:"error"},"Removed")),E8.createElement(u,{marginBottom:1,flexDirection:"column"},E8.createElement(T,{color:"error"},"Removed from marketplace · reason: ",h6.reason),E8.createElement(T,null,h6.text),E8.createElement(T,{dimColor:!0},"Flagged on ",new Date(h6.flaggedAt).toLocaleDateString())),E8.createElement(u,{marginTop:1,flexDirection:"column"},E8.createElement(u,null,E8.createElement(T,null,e6.pointer," "),E8.createElement(T,{color:"suggestion"},"Dismiss"))),E8.createElement(z1,null,E8.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"dismiss"}),E8.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))}if(f==="confirm-project-uninstall"&&C)return E8.createElement(u,{flexDirection:"column"},E8.createElement(T,{bold:!0,color:"warning"},C.plugin.name," is enabled in .claude/settings.json (shared with your team)"),E8.createElement(u,{marginTop:1,flexDirection:"column"},E8.createElement(T,null,"Disable it just for you in .claude/settings.local.json?"),E8.createElement(T,{dimColor:!0},"This has the same effect as uninstalling, without affecting other contributors.")),v6&&E8.createElement(u,{marginTop:1},E8.createElement(T,{color:"error"},v6)),E8.createElement(u,{marginTop:1},k6?E8.createElement(T,{dimColor:!0},"Disabling…"):E8.createElement(z1,null,E8.createElement(v1,{action:"confirm:yes",context:"Confirmation",fallback:"y",description:"disable"}),E8.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"cancel"}))));if(typeof f==="object"&&f.type==="confirm-data-cleanup"&&C)return E8.createElement(u,{flexDirection:"column",tabIndex:0,autoFocus:!0,onKeyDown:W8},E8.createElement(T,{bold:!0},C.plugin.name," has ",f.size.human," of persistent data"),E8.createElement(u,{marginTop:1,flexDirection:"column"},E8.createElement(T,null,"Delete it along with the plugin?"),E8.createElement(T,{dimColor:!0},K68(`${C.plugin.name}@${C.marketplace}`))),v6&&E8.createElement(u,{marginTop:1},E8.createElement(T,{color:"error"},v6)),E8.createElement(u,{marginTop:1},k6?E8.createElement(T,{dimColor:!0},"Uninstalling…"):E8.createElement(T,null,E8.createElement(T,{bold:!0},"y")," to delete · ",E8.createElement(T,{bold:!0},"n")," to keep ·"," ",E8.createElement(T,{bold:!0},"esc")," to cancel")));if(f==="plugin-details"&&C){let h6=y7(),_8=`${C.plugin.name}@${C.marketplace}`,R8=h6?.enabledPlugins?.[_8]!==!1,x6=j.filter((v8)=>("plugin"in v8)&&v8.plugin===C.plugin.name||v8.source===_8||v8.source.startsWith(`${C.plugin.name}@`)),i6=x6.length===0?null:E8.createElement(u,{flexDirection:"column",marginBottom:1},E8.createElement(T,{bold:!0,color:"error"},x6.length," ",O7(x6.length,"error"),":"),x6.map((v8,f1)=>{let g8=ux6(v8);return E8.createElement(u,{key:f1,flexDirection:"column",marginLeft:2},E8.createElement(T,{color:"error"},g_6(v8)),g8&&E8.createElement(T,{dimColor:!0,italic:!0},e6.arrowRight," ",g8))}));return E8.createElement(u,{flexDirection:"column"},E8.createElement(u,null,E8.createElement(T,{bold:!0},C.plugin.name," @ ",C.marketplace)),E8.createElement(u,null,E8.createElement(T,{dimColor:!0},"Scope: "),E8.createElement(T,null,C.scope||"user")),C.plugin.manifest.version&&E8.createElement(u,null,E8.createElement(T,{dimColor:!0},"Version: "),E8.createElement(T,null,C.plugin.manifest.version)),C.plugin.manifest.description&&E8.createElement(u,{marginBottom:1},E8.createElement(T,null,C.plugin.manifest.description)),C.plugin.manifest.author&&E8.createElement(u,null,E8.createElement(T,{dimColor:!0},"Author: "),E8.createElement(T,null,C.plugin.manifest.author.name)),E8.createElement(u,{marginBottom:1},E8.createElement(T,{dimColor:!0},"Status: "),E8.createElement(T,{color:R8?"success":"warning"},R8?"Enabled":"Disabled"),C.pendingUpdate&&E8.createElement(T,{color:"suggestion"}," · Marked for update")),E8.createElement(yxY,{plugin:C.plugin,marketplace:C.marketplace}),i6,E8.createElement(u,{marginTop:1,flexDirection:"column"},Q6.map((v8,f1)=>{let g8=f1===f6;return E8.createElement(u,{key:f1},g8&&E8.createElement(T,null,e6.pointer," "),!g8&&E8.createElement(T,null," "),E8.createElement(T,{bold:g8,color:v8.label.includes("Uninstall")?"error":v8.label.includes("Update")?"suggestion":void 0},v8.label))})),k6&&E8.createElement(u,{marginTop:1},E8.createElement(T,null,"Processing…")),v6&&E8.createElement(u,{marginTop:1},E8.createElement(T,{color:"error"},v6)),E8.createElement(u,{marginTop:1},E8.createElement(T,{dimColor:!0,italic:!0},E8.createElement(z1,null,E8.createElement(v1,{action:"select:previous",context:"Select",fallback:"↑",description:"navigate"}),E8.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"select"}),E8.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}if(typeof f==="object"&&f.type==="failed-plugin-details"){let h6=f.plugin,_8=h6.errors[0],R8=_8?g_6(_8):"Failed to load";return E8.createElement(u,{flexDirection:"column"},E8.createElement(T,null,E8.createElement(T,{bold:!0},h6.name),E8.createElement(T,{dimColor:!0}," @ ",h6.marketplace),E8.createElement(T,{dimColor:!0}," (",h6.scope,")")),E8.createElement(T,{color:"error"},R8),h6.scope==="managed"?E8.createElement(u,{marginTop:1},E8.createElement(T,{dimColor:!0},"Managed by your organization — contact your admin")):E8.createElement(u,{marginTop:1},E8.createElement(T,{color:"suggestion"},e6.pointer," "),E8.createElement(T,{bold:!0},"Remove")),k6&&E8.createElement(T,null,"Processing…"),v6&&E8.createElement(T,{color:"error"},v6),E8.createElement(u,{marginTop:1},E8.createElement(T,{dimColor:!0,italic:!0},E8.createElement(z1,null,h6.scope!=="managed"&&E8.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"remove"}),E8.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))))}if(typeof f==="object"&&f.type==="mcp-detail"){let h6=f.client,_8=Ll($,h6.name).length,R8=()=>{v({type:"mcp-tools",client:h6})},x6=()=>{v("plugin-list")},i6=(g8)=>{if(g8)K(g8);v("plugin-list")},v8=h6.config.scope,f1=h6.config.type;if(f1==="stdio"){let g8={name:h6.name,client:h6,scope:v8,transport:"stdio",config:h6.config};return E8.createElement(j_8,{server:g8,serverToolsCount:_8,onViewTools:R8,onCancel:x6,onComplete:i6,borderless:!0})}else if(f1==="sse"){let g8={name:h6.name,client:h6,scope:v8,transport:"sse",isAuthenticated:void 0,config:h6.config};return E8.createElement(FP6,{server:g8,serverToolsCount:_8,onViewTools:R8,onCancel:x6,onComplete:i6,borderless:!0})}else if(f1==="http"){let g8={name:h6.name,client:h6,scope:v8,transport:"http",isAuthenticated:void 0,config:h6.config};return E8.createElement(FP6,{server:g8,serverToolsCount:_8,onViewTools:R8,onCancel:x6,onComplete:i6,borderless:!0})}else if(f1==="claudeai-proxy"){let g8={name:h6.name,client:h6,scope:v8,transport:"claudeai-proxy",isAuthenticated:void 0,config:h6.config};return E8.createElement(FP6,{server:g8,serverToolsCount:_8,onViewTools:R8,onCancel:x6,onComplete:i6,borderless:!0})}return v("plugin-list"),null}if(typeof f==="object"&&f.type==="mcp-tools"){let h6=f.client,_8=h6.config.scope,R8=h6.config.type,x6;if(R8==="stdio")x6={name:h6.name,client:h6,scope:_8,transport:"stdio",config:h6.config};else if(R8==="sse")x6={name:h6.name,client:h6,scope:_8,transport:"sse",isAuthenticated:void 0,config:h6.config};else if(R8==="http")x6={name:h6.name,client:h6,scope:_8,transport:"http",isAuthenticated:void 0,config:h6.config};else x6={name:h6.name,client:h6,scope:_8,transport:"claudeai-proxy",isAuthenticated:void 0,config:h6.config};return E8.createElement(J_8,{server:x6,onSelectTool:(i6)=>{v({type:"mcp-tool-detail",client:h6,tool:i6})},onBack:()=>v({type:"mcp-detail",client:h6})})}if(typeof f==="object"&&f.type==="mcp-tool-detail"){let{client:h6,tool:_8}=f,R8=h6.config.scope,x6=h6.config.type,i6;if(x6==="stdio")i6={name:h6.name,client:h6,scope:R8,transport:"stdio",config:h6.config};else if(x6==="sse")i6={name:h6.name,client:h6,scope:R8,transport:"sse",isAuthenticated:void 0,config:h6.config};else if(x6==="http")i6={name:h6.name,client:h6,scope:R8,transport:"http",isAuthenticated:void 0,config:h6.config};else i6={name:h6.name,client:h6,scope:R8,transport:"claudeai-proxy",isAuthenticated:void 0,config:h6.config};return E8.createElement(H_8,{tool:_8,server:i6,onBack:()=>v({type:"mcp-tools",client:h6})})}let u6=V6.getVisibleItems(r);return E8.createElement(u,{flexDirection:"column",tabIndex:0,autoFocus:!0,onKeyDown:G8,onPaste:s6},E8.createElement(u,{marginBottom:1},E8.createElement(wg,{query:V,isFocused:J,isTerminalFocused:P,width:Z-4,cursorOffset:N})),r.length===0&&V&&E8.createElement(u,{marginBottom:1},E8.createElement(T,{dimColor:!0},'No items match "',V,'"')),V6.scrollPosition.canScrollUp&&E8.createElement(u,null,E8.createElement(T,{dimColor:!0}," ",e6.arrowUp," more above")),u6.map((h6,_8)=>{let R8=V6.toActualIndex(_8),x6=R8===Y6&&!J;switch(h6.kind){case"spacer":return E8.createElement(u,{key:`spacer:${R8}`,height:1});case"section-header":return E8.createElement(u,{key:`section:${h6.section}`,paddingLeft:2},E8.createElement(T,{dimColor:h6.section!=="attention",color:h6.section==="attention"?"warning":void 0,bold:!0},h6.section==="attention"?"Needs attention":"Favorites"));case"scope-header":return E8.createElement(u,{key:`scope:${R8}`,paddingLeft:4},E8.createElement(T,{dimColor:!0},NxY(h6.scope)));case"disabled-header":return E8.createElement(u,{key:"section:disabled",paddingLeft:2},E8.createElement(T,{color:x6?"suggestion":void 0},x6?`${e6.pointer} `:" ",o?e6.arrowDown:e6.arrowRight," Show disabled ",E8.createElement(T,{dimColor:!0},"(",h6.count,")")));case"item":return E8.createElement(jFK,{key:`${h6.section}:${h6.item.id}`,item:h6.item,isSelected:x6})}}),V6.scrollPosition.canScrollDown&&E8.createElement(u,null,E8.createElement(T,{dimColor:!0}," ",e6.arrowDown," more below")),E8.createElement(u,{marginTop:1,marginLeft:1},E8.createElement(T,{dimColor:!0,italic:!0},E8.createElement(z1,null,E8.createElement(T,null,"type to search"),E8.createElement(v1,{action:"plugin:toggle",context:"Plugin",fallback:"Space",description:"toggle"}),E8.createElement(v1,{action:"plugin:favorite",context:"Plugin",fallback:"f",description:"favorite"}),E8.createElement(v1,{action:"select:accept",context:"Select",fallback:"Enter",description:"details"}),E8.createElement(v1,{action:"confirm:no",context:"Confirmation",fallback:"Esc",description:"back"})))),c.size>0&&E8.createElement(u,{marginLeft:1},E8.createElement(T,{dimColor:!0,italic:!0},"Run /reload-plugins to apply changes")))}var E8,C_;var PFK=L(()=>{Qq();bK();Nq();Li8();hi8();Ri8();Si8();EP6();Mk();R_6();I4();g6();C7();z68();B_6();iD();Ix6();N7();Nj();h1();K8();m8();U8();uR();yD();m$();W88();Jy();di8();aW();vH();Gx();AH6();X_8();aY();a1();e8();Jw7();Aw7();mi8();HFK();W_8();E8=K6(P6(),1),C_=K6(P6(),1)});function WFK(q){if(!q)return{type:"menu"};let K=q.trim().split(/\s+/);switch(K[0]?.toLowerCase()){case"help":case"--help":case"-h":return{type:"help"};case"install":case"i":{let z=K[1];if(!z)return{type:"install"};let Y=z.lastIndexOf("@");if(Y>0){let O=z.slice(0,Y),w=z.slice(Y+1);return{type:"install",plugin:O,marketplace:w}}if(!z.startsWith("@")&&(z.startsWith("http://")||z.startsWith("https://")||z.startsWith("file://")||z.includes("/")||z.includes("\\")))return{type:"install",marketplace:z};return{type:"install",plugin:z}}case"manage":return{type:"manage"};case"uninstall":return{type:"uninstall",plugin:K[1]};case"enable":return{type:"enable",plugin:K[1]};case"disable":return{type:"disable",plugin:K[1]};case"validate":return{type:"validate",path:K.slice(1).join(" ").trim()||void 0};case"marketplace":case"market":{let z=K[1]?.toLowerCase(),Y=K.slice(2).join(" ");switch(z){case"add":return{type:"marketplace",action:"add",target:Y};case"remove":case"rm":return{type:"marketplace",action:"remove",target:Y};case"update":return{type:"marketplace",action:"update",target:Y};case"list":return{type:"marketplace",action:"list"};default:return{type:"marketplace"}}}default:return{type:"menu"}}}import{readdir as RxY,readFile as Bx6,stat as SxY}from"fs/promises";import*as _$ from"path";function bxY(q){let K=_$.basename(q),_=_$.basename(_$.dirname(q));if(K==="plugin.json")return"plugin";if(K==="marketplace.json")return"marketplace";if(_===".claude-plugin")return"plugin";return"unknown"}function Ww7(q){return q.issues.map((K)=>({path:K.path.join(".")||"root",message:K.message,code:K.code}))}function f_8(q,K,_,z){if(q.includes(".."))_.push({path:K,message:z?`Path contains "..": ${q}. ${z}`:`Path contains ".." which could be a path traversal attempt: ${q}`})}function IxY(q){let K=q.replace(/^(\.\.\/)+/,"");return`Plugin source paths are resolved relative to the marketplace root (the directory containing .claude-plugin/), not relative to marketplace.json. Use "${K!==q?`./${K}`:"./plugins/my-plugin"}" instead of "${q}".`}async function Mw7(q){let K=[],_=[],z=_$.resolve(q),Y;try{Y=await Bx6(z,{encoding:"utf-8"})}catch($){let j=Q1($),H;if(j==="ENOENT")H=`File not found: ${z}`;else if(j==="EISDIR")H=`Path is not a file: ${z}`;else H=`Failed to read file: ${b6($)}`;return{success:!1,errors:[{path:"file",message:H,code:j}],warnings:[],filePath:z,fileType:"plugin"}}let A;try{A=n8(Y)}catch($){return{success:!1,errors:[{path:"json",message:`Invalid JSON syntax: ${b6($)}`}],warnings:[],filePath:z,fileType:"plugin"}}if(A&&typeof A==="object"){let $=A;if($.commands)(Array.isArray($.commands)?$.commands:[$.commands]).forEach((H,J)=>{if(typeof H==="string")f_8(H,`commands[${J}]`,K)});if($.agents)(Array.isArray($.agents)?$.agents:[$.agents]).forEach((H,J)=>{if(typeof H==="string")f_8(H,`agents[${J}]`,K)});if($.skills)(Array.isArray($.skills)?$.skills:[$.skills]).forEach((H,J)=>{if(typeof H==="string")f_8(H,`skills[${J}]`,K)})}let O=A;if(typeof A==="object"&&A!==null){let $=A,j=Object.keys($).filter((H)=>CxY.has(H));if(j.length>0){let H={...$};for(let J of j)delete H[J],_.push({path:J,message:`Field '${J}' belongs in the marketplace entry (marketplace.json), `+"not plugin.json. It's harmless here but unused — Claude Code "+"ignores it at load time."});O=H}}let w=IQ6().strict().safeParse(O);if(!w.success)K.push(...Ww7(w.error));if(w.success){let $=w.data;if(!/^[a-z0-9]+(-[a-z0-9]+)*$/.test($.name))_.push({path:"name",message:`Plugin name "${$.name}" is not kebab-case. Claude Code accepts it, but the Claude.ai marketplace sync requires kebab-case (lowercase letters, digits, and hyphens only, e.g., "my-plugin").`});if(!$.version)_.push({path:"version",message:'No version specified. Consider adding a version following semver (e.g., "1.0.0")'});if(!$.description)_.push({path:"description",message:"No description provided. Adding a description helps users understand what your plugin does"});if(!$.author)_.push({path:"author",message:"No author information provided. Consider adding author details for plugin attribution"})}return{success:K.length===0,errors:K,warnings:_,filePath:z,fileType:"plugin"}}async function Pw7(q){let K=[],_=[],z=_$.resolve(q),Y;try{Y=await Bx6(z,{encoding:"utf-8"})}catch($){let j=Q1($),H;if(j==="ENOENT")H=`File not found: ${z}`;else if(j==="EISDIR")H=`Path is not a file: ${z}`;else H=`Failed to read file: ${b6($)}`;return{success:!1,errors:[{path:"file",message:H,code:j}],warnings:[],filePath:z,fileType:"marketplace"}}let A;try{A=n8(Y)}catch($){return{success:!1,errors:[{path:"json",message:`Invalid JSON syntax: ${b6($)}`}],warnings:[],filePath:z,fileType:"marketplace"}}if(A&&typeof A==="object"){let $=A;if(Array.isArray($.plugins))$.plugins.forEach((j,H)=>{if(j&&typeof j==="object"&&"source"in j){let J=j.source;if(typeof J==="string")f_8(J,`plugins[${H}].source`,K,IxY(J));if(J&&typeof J==="object"&&"path"in J&&typeof J.path==="string")f_8(J.path,`plugins[${H}].source.path`,K)}})}let w=g16().extend({plugins:y.array(MO1().strict())}).strict().safeParse(A);if(!w.success)K.push(...Ww7(w.error));if(w.success){let $=w.data;if(!$.plugins||$.plugins.length===0)_.push({path:"plugins",message:"Marketplace has no plugins defined"});if($.plugins){$.plugins.forEach((J,X)=>{if($.plugins.filter((P)=>P.name===J.name).length>1)K.push({path:`plugins[${X}].name`,message:`Duplicate plugin name "${J.name}" found in marketplace`})});let j=_$.dirname(z),H=_$.basename(j)===".claude-plugin"?_$.dirname(j):j;for(let[J,X]of $.plugins.entries()){if(!X.version||typeof X.source!=="string"||!X.source.startsWith("./"))continue;let M=_$.join(H,X.source),P=_$.join(M,".claude-plugin","plugin.json"),W;try{let D=await Bx6(P,{encoding:"utf-8"});try{let Z=n8(D);if(typeof Z.version==="string")W=Z.version}catch(Z){_.push({path:`plugins[${J}].source`,message:`Could not parse ${_$.relative(H,P)} for version cross-check: ${b6(Z)}`})}}catch(D){if(!t1(D)&&Q1(D)!=="ENOTDIR")_.push({path:`plugins[${J}].source`,message:`Could not read ${_$.relative(H,P)} for version cross-check: ${b6(D)}`})}if(W&&W!==X.version){let D=_$.relative(H,P);_.push({path:`plugins[${J}].version`,message:`Entry declares version "${X.version}" but ${D} says "${W}". `+"At install time, plugin.json wins (calculatePluginVersion precedence) — the entry version is silently ignored. "+`Update this entry to "${W}" to match.`})}}}if(!$.metadata?.description)_.push({path:"metadata.description",message:"No marketplace description provided. Adding a description helps users understand what this marketplace offers"})}return{success:K.length===0,errors:K,warnings:_,filePath:z,fileType:"marketplace"}}function xxY(q,K,_){let z=[],Y=[],A=K.match(zy6);if(!A)return Y.push({path:"frontmatter",message:"No frontmatter block found. Add YAML frontmatter between --- delimiters at the top of the file to set description and other metadata."}),{success:!0,errors:z,warnings:Y,filePath:q,fileType:_};let O=A[1]||"",w;try{w=yt6(O)}catch(J){return z.push({path:"frontmatter",message:`YAML frontmatter failed to parse: ${b6(J)}. At runtime this ${_} loads with empty metadata (all frontmatter fields silently dropped).`}),{success:!1,errors:z,warnings:Y,filePath:q,fileType:_}}if(w===null||typeof w!=="object"||Array.isArray(w))return z.push({path:"frontmatter",message:`Frontmatter must be a YAML mapping (key: value pairs), got ${Array.isArray(w)?"an array":w===null?"null":typeof w}.`}),{success:!1,errors:z,warnings:Y,filePath:q,fileType:_};let $=w;if($.description!==void 0){let J=$.description;if(typeof J!=="string"&&typeof J!=="number"&&typeof J!=="boolean"&&J!==null)z.push({path:"description",message:`description must be a string, got ${Array.isArray(J)?"array":typeof J}. At runtime this value is dropped.`})}else Y.push({path:"description",message:`No description in frontmatter. A description helps users and Claude understand when to use this ${_}.`});if($.name!==void 0&&$.name!==null&&typeof $.name!=="string")z.push({path:"name",message:`name must be a string, got ${typeof $.name}.`});let j=$["allowed-tools"];if(j!==void 0&&j!==null){if(typeof j!=="string"&&!Array.isArray(j))z.push({path:"allowed-tools",message:`allowed-tools must be a string or array of strings, got ${typeof j}.`});else if(Array.isArray(j)&&j.some((J)=>typeof J!=="string"))z.push({path:"allowed-tools",message:"allowed-tools array must contain only strings."})}let H=$.shell;if(H!==void 0&&H!==null)if(typeof H!=="string")z.push({path:"shell",message:`shell must be a string, got ${typeof H}.`});else{let J=H.trim().toLowerCase();if(J!=="bash"&&J!=="powershell")z.push({path:"shell",message:`shell must be 'bash' or 'powershell', got '${H}'.`})}return{success:z.length===0,errors:z,warnings:Y,filePath:q,fileType:_}}async function uxY(q){let K;try{K=await Bx6(q,{encoding:"utf-8"})}catch(Y){if(Q1(Y)==="ENOENT")return{success:!0,errors:[],warnings:[],filePath:q,fileType:"hooks"};return{success:!1,errors:[{path:"file",message:`Failed to read file: ${b6(Y)}`}],warnings:[],filePath:q,fileType:"hooks"}}let _;try{_=n8(K)}catch(Y){return{success:!1,errors:[{path:"json",message:`Invalid JSON syntax: ${b6(Y)}. At runtime this breaks the entire plugin load.`}],warnings:[],filePath:q,fileType:"hooks"}}let z=WX8().safeParse(_);if(!z.success)return{success:!1,errors:Ww7(z.error),warnings:[],filePath:q,fileType:"hooks"};return{success:!0,errors:[],warnings:[],filePath:q,fileType:"hooks"}}async function DFK(q,K){let _;try{_=await RxY(q,{withFileTypes:!0})}catch(Y){let A=Q1(Y);if(A==="ENOENT"||A==="ENOTDIR")return[];throw Y}if(K)return _.filter((Y)=>Y.isDirectory()).map((Y)=>_$.join(q,Y.name,"SKILL.md"));let z=[];for(let Y of _){let A=_$.join(q,Y.name);if(Y.isDirectory())z.push(...await DFK(A,!1));else if(Y.isFile()&&Y.name.toLowerCase().endsWith(".md"))z.push(A)}return z}async function ZFK(q){let K=[],_=[["skill",_$.join(q,"skills")],["agent",_$.join(q,"agents")],["command",_$.join(q,"commands")]];for(let[Y,A]of _){let O=await DFK(A,Y==="skill");for(let w of O){let $;try{$=await Bx6(w,{encoding:"utf-8"})}catch(H){if(t1(H))continue;K.push({success:!1,errors:[{path:"file",message:`Failed to read: ${b6(H)}`}],warnings:[],filePath:w,fileType:Y});continue}let j=xxY(w,$,Y);if(j.errors.length>0||j.warnings.length>0)K.push(j)}}let z=await uxY(_$.join(q,"hooks","hooks.json"));if(z.errors.length>0||z.warnings.length>0)K.push(z);return K}async function ci8(q){let K=_$.resolve(q),_=null;try{_=await SxY(K)}catch(Y){if(!t1(Y))throw Y}if(_?.isDirectory()){let Y=_$.join(K,".claude-plugin","marketplace.json"),A=await Pw7(Y),O=A.errors[0]?.code;if(O!=="ENOENT"&&O!=="ENOTDIR")return A;let w=_$.join(K,".claude-plugin","plugin.json"),$=await Mw7(w),j=$.errors[0]?.code;if(j!=="ENOENT"&&j!=="ENOTDIR")return $;return{success:!1,errors:[{path:"directory",message:"No manifest found in directory. Expected .claude-plugin/marketplace.json or .claude-plugin/plugin.json"}],warnings:[],filePath:K,fileType:"plugin"}}switch(bxY(q)){case"plugin":return Mw7(q);case"marketplace":return Pw7(q);case"unknown":{try{let Y=await Bx6(K,{encoding:"utf-8"}),A=n8(Y);if(Array.isArray(A.plugins))return Pw7(q)}catch(Y){if(Q1(Y)==="ENOENT")return{success:!1,errors:[{path:"file",message:`File not found: ${K}`}],warnings:[],filePath:K,fileType:"plugin"}}return Mw7(q)}}}var CxY;var Dw7=L(()=>{p7();m8();Lf();e8();Hv();CxY=new Set(["category","source","tags","strict","id"])});function GFK(q){let K=s(5),{onComplete:_,path:z}=q,Y,A;if(K[0]!==_||K[1]!==z)Y=()=>{(async function(){if(!z){_(`Usage: /plugin validate <path>
6425
6425
 
@@ -18263,7 +18263,7 @@ Error: sandbox required but unavailable: ${j}
18263
18263
  `);break}f4(I6(h)+`
18264
18264
  `);break;case"stream-json":break;default:if(!h||h.type!=="result")throw Error("No messages returned");switch(h.subtype){case"success":f4(h.result.endsWith(`
18265
18265
  `)?h.result:h.result+`
18266
- `);break;case"error_during_execution":f4("Execution error");break;case"error_max_turns":f4(`Error: Reached max turns (${w.maxTurns})`);break;case"error_max_budget_usd":f4(`Error: Exceeded USD budget (${w.maxBudgetUsd})`);break;case"error_max_structured_output_retries":f4("Error: Failed to provide valid structured output after maximum retries")}}if(rr1(),Lk8())await EXA.drainPendingExtraction();j5(h?.type==="result"&&h?.is_error?1:0)}function CXA(q,K,_,z,Y,A,O,w,$,j,H,J,X){let M=!1,P=X,W,D=!1,Z=!1,G=(a6)=>a6.agentId===void 0,f=null,v,V=q.outbound;if(H.outputFormat==="stream-json"&&H.sessionMirror)EH7((a6,D8)=>{q.write({type:"transcript_mirror",filePath:a6,entries:D8})});let k=()=>{if(j1("info","shutdown_signal",{signal:"SIGINT"}),v&&!v.signal.aborted)v.abort();WK(0)};process.on("SIGINT",k),eq(async()=>{let a6={};for(let D8 of XI8(w()))if(yH(D8))a6[D8.type]=(a6[D8.type]??0)+1;j1("info","run_state_at_shutdown",{run_active:M,run_phase:W,worker_status:q.sessionState.getState(),internal_events_pending:q.internalEventsPending,bg_tasks:a6})}),q.sessionState.onPermissionModeChanged=(a6)=>{if(a6==="default"||a6==="acceptEdits"||a6==="bypassPermissions"||a6==="plan"||a6==="auto"||a6==="dontAsk")V.enqueue({type:"system",subtype:"status",status:null,permissionMode:a6,uuid:gX(),session_id:I8()})};let N={abortController:null,inflightPromise:null,lastEmitted:null,pendingSuggestion:null,pendingLastEmittedEntry:null},R;if(H.enableAuthStatus)R=wD.getInstance().subscribe((D8)=>{V.enqueue({type:"auth_status",isAuthenticating:D8.isAuthenticating,output:D8.output,error:D8.error,uuid:gX(),session_id:I8()})});let h=(a6)=>{let D8=PnK(a6);if(D8)V.enqueue({type:"rate_limit_event",rate_limit_info:D8,uuid:gX(),session_id:I8()})};ZK6.add(h);let C=Y,x=nR6(Y,AA8(),oI),B=new Map,m=void 0,S=CR(oI),F=process.env.CLAUDE_CODE_RESUME_INTERRUPTED_TURN;if(J&&J.kind!=="none"&&F)E(`[print.ts] Auto-resuming interrupted turn (kind: ${J.kind})`),WX5(C,J.message),Dj({mode:"prompt",value:J.message.message.content,uuid:gX()});let g=q_6().map((a6)=>{let D8=a6.value===null?"default":a6.value,Q6=D8==="default"?ZP():K5(D8),W8=QI(Q6),G8=kh8(Q6),s6=zX(a6.value),u6=Dk6(Q6);return{value:D8,displayName:a6.label,description:a6.description,...W8&&{supportsEffort:!0,supportedEffortLevels:UI.filter((h6)=>{if(h6==="max"&&!Ct6(Q6))return!1;if(h6==="xhigh"&&!bt6(Q6))return!1;return!0})},...G8&&{supportsAdaptiveThinking:!0},...s6&&{supportsFastMode:!0},...u6&&{supportsAutoMode:!0}}}),c=H.userSpecifiedModel,n=H.thinkingConfig&&H.thinkingConfig.type!=="disabled"?H.thinkingConfig.display:void 0,l=H.thinkingConfig;function z6(a6,D8){let Q6=BCK(a6,hE(D8));C.push(...Q6);for(let W8 of Q6)if(typeof W8.message.content==="string"&&W8.message.content.includes(`<${l0}>`))V.enqueue({type:"user",message:W8.message,session_id:I8(),parent_tool_use_id:null,uuid:W8.uuid,timestamp:W8.timestamp,isReplay:!0})}let A6=[],e=[],i=new Set;function O6(a6){for(let D8 of a6){if(D8.type!=="connected"||i.has(D8.name))continue;if(D8.config.type==="sdk")continue;let Q6=D8.name;try{D8.client.setRequestHandler($r,async(W8,G8)=>{i8(Q6,`Elicitation request received in print mode: ${I6(W8)}`);let s6=W8.params.mode==="url"?"url":"form";d("tengu_mcp_elicitation_shown",{mode:s6});let u6=await Y98(Q6,W8.params,G8.signal);if(u6)return i8(Q6,`Elicitation resolved by hook: ${I6(u6)}`),d("tengu_mcp_elicitation_response",{mode:s6,action:u6.action}),u6;let h6="url"in W8.params?W8.params.url:void 0,_8="requestedSchema"in W8.params?W8.params.requestedSchema:void 0,R8="elicitationId"in W8.params?W8.params.elicitationId:void 0,x6=OX5(W8.params._meta),i6=await q.handleElicitation(Q6,W8.params.message,_8,G8.signal,s6,h6,R8,x6),v8=await A98(Q6,i6,G8.signal,s6,R8);return d("tengu_mcp_elicitation_response",{mode:s6,action:v8.action}),v8}),D8.client.setNotificationHandler(mg6,(W8)=>{let{elicitationId:G8}=W8.params;i8(Q6,`Elicitation completion notification: ${G8}`),lx({message:`MCP server "${Q6}" confirmed elicitation ${G8} complete`,notificationType:"elicitation_complete"}),V.enqueue({type:"system",subtype:"elicitation_complete",mcp_server_name:Q6,elicitation_id:G8,uuid:gX(),session_id:I8()})}),i.add(Q6)}catch{}}}async function J6(){let a6=new Set(Object.keys(O)),D8=new Set(A6.map((h6)=>h6.name)),Q6=Array.from(a6).some((h6)=>!D8.has(h6)),W8=Array.from(D8).some((h6)=>!a6.has(h6)),G8=A6.some((h6)=>h6.type==="pending"),s6=A6.some((h6)=>h6.type==="failed");if(Q6||W8||G8||s6){for(let R8 of A6)if(!a6.has(R8.name)){if(R8.type==="connected")await R8.cleanup()}let h6=await ERK(O,(R8,x6)=>q.sendMcpMessage(R8,x6));A6=h6.clients,e=h6.tools;let _8=F4([...D8,...a6]);$((R8)=>({...R8,mcp:{...R8.mcp,tools:[...R8.mcp.tools.filter((x6)=>!_8.some((i6)=>x6.name.startsWith(Zh(i6)))),...e]}})),gP4(A6)}}J6();let $6={clients:[],tools:[],configs:{},policyRules:new Set},H6=(a6)=>{let D8=cl(a6.toolPermissionContext,a6.mcp.tools),Q6=j2(Du6([...z,...e,...$6.tools],D8,a6.toolPermissionContext.mode),"name");if(H.permissionPromptToolName)Q6=Q6.filter((G8)=>!e3(G8,H.permissionPromptToolName));let W8=rO8();if(W8&&!H.jsonSchema){let G8=OR8(W8);if("tool"in G8)Q6=[...Q6,G8.tool]}return Q6},q6=S6(process.env.CLAUDE_CODE_REMOTE)?process.env.CLAUDE_CODE_SYSTEM_PROMPT_GB_FEATURE:void 0,o=()=>{if(!q6)return H.systemPrompt;let a6=u8(q6,"");return typeof a6==="string"&&a6.length>0?a6:H.systemPrompt},_6=null,r=0;function t(){if(!_6)return;let a6=Math.min(r,C.length),D8=C.slice(a6).filter((Q6)=>Q6.type==="user"||Q6.type==="assistant");if(r=C.length,D8.length>0)_6.writeMessages(D8)}let Y6=Promise.resolve({response:{added:[],removed:[],errors:{}},sdkServersChanged:!1});function X6(a6){let D8=async()=>{let Q6=new Set(A6.map((G8)=>G8.name)),W8=await fX5(a6,{configs:O,clients:A6,tools:e},$6,$);for(let G8 of Object.keys(O))delete O[G8];if(Object.assign(O,W8.newSdkState.configs),A6=W8.newSdkState.clients,e=W8.newSdkState.tools,$6=W8.newDynamicState,W8.sdkServersChanged){let G8=new Set(A6.map((u6)=>u6.name)),s6=F4([...Q6,...G8]);$((u6)=>({...u6,mcp:{...u6.mcp,tools:[...u6.mcp.tools.filter((h6)=>!s6.some((_8)=>h6.name.startsWith(Zh(_8)))),...e]}}))}return{response:W8.response,sdkServersChanged:W8.sdkServersChanged}};return Y6=Y6.then(D8,D8),Y6}function M6(){let a6=w(),D8=a6.mcp.clients,Q6=j2([...a6.mcp.tools,...$6.tools],"name"),W8=new Set([...D8.map((G8)=>G8.name),...A6.map((G8)=>G8.name)]);return[...D8,...A6,...$6.clients.filter((G8)=>!W8.has(G8.name))].map((G8)=>{let s6;if(G8.config.type==="sse"||G8.config.type==="http")s6={type:G8.config.type,url:G8.config.url,headers:G8.config.headers,oauth:G8.config.oauth};else if(G8.config.type==="claudeai-proxy")s6={type:"claudeai-proxy",url:G8.config.url,id:G8.config.id};else if(G8.config.type==="stdio"||G8.config.type===void 0)s6={type:"stdio",command:G8.config.command,args:G8.config.args};let u6=G8.type==="connected"?Ll(Q6,G8.name).map((_8)=>({name:_8.mcpInfo?.toolName??_8.name,annotations:{readOnly:_8.isReadOnly({})||void 0,destructive:_8.isDestructive?.({})||void 0,openWorld:_8.isOpenWorld?.({})||void 0}})):void 0,h6;if(G8.type==="connected"&&G8.capabilities.experimental){let _8={...G8.capabilities.experimental};if(_8["claude/channel"]&&(false))delete _8["claude/channel"];if(Object.keys(_8).length>0)h6={experimental:_8}}return{name:G8.name,status:G8.type,serverInfo:G8.type==="connected"?G8.serverInfo:void 0,error:G8.type==="failed"?G8.error:void 0,config:s6,scope:G8.config.scope,tools:u6,capabilities:h6}})}async function W6(a6){try{await Promise.all([Promise.resolve(),Rf6("headless_managed_settings_wait",()=>Qu8())])}catch(Q6){j6(Q6)}let D8=!1;try{if(D8=await eJ5(a6),D8)await y6()}catch(Q6){j6(Q6)}return D8}let V6=null,f6=null,G6;if(!S9())if(S6(process.env.CLAUDE_CODE_SYNC_PLUGIN_INSTALL))G6=H.outputFormat==="stream-json"?(a6)=>void q.write({type:"system",subtype:"plugin_install",status:a6.status,name:"name"in a6?a6.name:void 0,error:"error"in a6?a6.error:void 0,uuid:gX(),session_id:I8()}):void 0,G6?.({status:"started"}),V6=W6((a6)=>G6?.(a6));else f6=$X5(W6);let k6=nJ5(()=>!M),T6=_,v6=j;async function L6(){let{agentDefinitions:a6}=await PW6($);T6=yu6(await eD(AA8()));let D8=v6.filter((Q6)=>Q6.source==="flagSettings");v6=[...a6.allAgents,...D8]}async function y6(){let{servers:a6}=await Ct(),D8={};for(let[G8,s6]of Object.entries(a6)){let u6=s6.type;if(u6===void 0||u6==="stdio"||u6==="sse"||u6==="http"||u6==="sdk")D8[G8]=s6}for(let[G8,s6]of Object.entries(O))if(s6.type==="sdk"&&!(G8 in D8))D8[G8]=s6;let{response:Q6,sdkServersChanged:W8}=await X6(D8);if(W8)J6();E(`Headless MCP refresh: added=${Q6.added.length}, removed=${Q6.removed.length}`)}let c6=Em6.subscribe(()=>{On(),eD(AA8()).then((a6)=>{T6=yu6(a6)})});yj6(()=>{if(v&&AR8("now").length>0)v.abort("interrupt")});let Z8=async()=>{if(M)return;M=!0,W=void 0,q.sessionState.notifyStateChanged("running"),k6.stop(),GM("run_entry");try{if(await J6(),GM("after_updateSdkMcp"),V6){let D8=parseInt(process.env.CLAUDE_CODE_SYNC_PLUGIN_INSTALL_TIMEOUT_MS||"",10);if(D8>0){let W8=l7(D8).then(()=>"timeout");if(await Promise.race([V6,W8])==="timeout")j6(Error(`CLAUDE_CODE_SYNC_PLUGIN_INSTALL: plugin installation timed out after ${D8}ms`)),d("tengu_sync_plugin_install_timeout",{timeout_ms:D8})}else await V6;V6=null;try{await L6()}catch(W8){j6(W8)}let{setupPluginHookHotReload:Q6}=await Promise.resolve().then(() => (HJ6(),di1));Q6()}}finally{G6?.({status:"completed"}),G6=void 0}if(S6(process.env.CLAUDE_CODE_ENABLE_BACKGROUND_PLUGIN_REFRESH)&&f6?.needsRefresh){f6.needsRefresh=!1;try{await L6()}catch(D8){j6(D8)}}try{let D8,Q6=!1,W8=!0,G8=async()=>{while(D8=Ke6(G)){if(D8.mode!=="prompt"&&D8.mode!=="orphaned-permission"&&D8.mode!=="task-notification")throw Error("only prompt commands are supported in streaming mode");let s6=[D8];if(D8.mode==="prompt"){while(HX5(D8,Lj6(G)))s6.push(Ke6(G));if(s6.length>1)D8={...D8,value:jX5(s6.map((g8)=>g8.value)),uuid:s6.findLast((g8)=>g8.uuid)?.uuid??D8.uuid,fileAttachments:s6.flatMap((g8)=>g8.fileAttachments??[])}}let u6=s6.map((g8)=>g8.uuid).filter((g8)=>g8!==void 0);if(H.replayUserMessages&&s6.length>1){for(let g8 of s6)if(g8.uuid&&g8.uuid!==D8.uuid)V.enqueue({type:"user",message:{role:"user",content:g8.value},session_id:I8(),parent_tool_use_id:null,uuid:g8.uuid,isReplay:!0,...g8.fileAttachments?.length&&{file_attachments:g8.fileAttachments},...g8.origin&&{origin:g8.origin}})}if(W8)W8=!1,await JX5(w);let h6=w(),_8=[...h6.mcp.clients,...A6,...$6.clients];O6(_8);for(let g8 of _8)P07(g8);let R8=H6(h6);for(let g8 of u6)q.onCommandLifecycle?.(g8,"started");if(D8.mode==="task-notification"){let g8=typeof D8.value==="string"?D8.value:"",w6=g8.match(/<task-id>([^<]+)<\/task-id>/),D6=g8.match(/<tool-use-id>([^<]+)<\/tool-use-id>/),U6=g8.match(/<output-file>([^<]+)<\/output-file>/),F6=g8.match(/<status>([^<]+)<\/status>/),z8=g8.match(/<summary>([^<]+)<\/summary>/),l6=(uq)=>uq==="completed"||uq==="failed"||uq==="stopped"||uq==="killed",j8=F6?.[1],f8=l6(j8)?j8==="killed"?"stopped":j8:"completed",o8=g8.match(/<usage>([\s\S]*?)<\/usage>/)?.[1]??"",n1=o8.match(/<total_tokens>(\d+)<\/total_tokens>/),c1=o8.match(/<tool_uses>(\d+)<\/tool_uses>/),dq=o8.match(/<duration_ms>(\d+)<\/duration_ms>/);if(F6)V.enqueue({type:"system",subtype:"task_notification",task_id:w6?.[1]??"",tool_use_id:D6?.[1],status:f8,output_file:U6?.[1]??"",summary:z8?.[1]??"",usage:n1&&c1?{total_tokens:parseInt(n1[1],10),tool_uses:parseInt(c1[1],10),duration_ms:dq?parseInt(dq[1],10):0}:void 0,session_id:I8(),uuid:gX()})}let x6=D8.value;if(q instanceof $e8&&D8.mode==="prompt")d("tengu_bridge_message_received",{is_repl:!1});if(D8.shouldQuery!==!1){if(N.abortController?.abort(),N.abortController=null,N.pendingSuggestion=null,N.pendingLastEmittedEntry=null,N.lastEmitted&&D8.mode==="prompt"){let g8=typeof x6==="string"?x6:x6.find((w6)=>w6.type==="text")?.text;if(typeof g8==="string")hc4(N.lastEmitted.text,g8,N.lastEmitted.emittedAt,N.lastEmitted.promptId,N.lastEmitted.generationRequestId);N.lastEmitted=null}}v=F5();let i6=void 0;GM("before_ask"),J38();let v8=D8;if(v8.uuid!==void 0&&aP4(v8.uuid)){q.onCommandLifecycle?.(v8.uuid,"completed");continue}let f1=typeof x6==="string"?x6:s5(x6,`
18266
+ `);break;case"error_during_execution":f4("Execution error");break;case"error_max_turns":f4(`Error: Reached max turns (${w.maxTurns})`);break;case"error_max_budget_usd":f4(`Error: Exceeded USD budget (${w.maxBudgetUsd})`);break;case"error_max_structured_output_retries":f4("Error: Failed to provide valid structured output after maximum retries")}}if(rr1(),Lk8())await EXA.drainPendingExtraction();j5(h?.type==="result"&&h?.is_error?1:0)}function CXA(q,K,_,z,Y,A,O,w,$,j,H,J,X){let M=!1,P=X,W,D=!1,Z=!1,G=(a6)=>a6.agentId===void 0,f=null,v,V=q.outbound;if(H.outputFormat==="stream-json"&&H.sessionMirror)EH7((a6,D8)=>{q.write({type:"transcript_mirror",filePath:a6,entries:D8})});let k=()=>{if(j1("info","shutdown_signal",{signal:"SIGINT"}),v&&!v.signal.aborted)v.abort();WK(0)};process.on("SIGINT",k),eq(async()=>{let a6={};for(let D8 of XI8(w()))if(yH(D8))a6[D8.type]=(a6[D8.type]??0)+1;j1("info","run_state_at_shutdown",{run_active:M,run_phase:W,worker_status:q.sessionState.getState(),internal_events_pending:q.internalEventsPending,bg_tasks:a6})}),q.sessionState.onPermissionModeChanged=(a6)=>{if(a6==="default"||a6==="acceptEdits"||a6==="bypassPermissions"||a6==="plan"||a6==="auto"||a6==="dontAsk")V.enqueue({type:"system",subtype:"status",status:null,permissionMode:a6,uuid:gX(),session_id:I8()})};let N={abortController:null,inflightPromise:null,lastEmitted:null,pendingSuggestion:null,pendingLastEmittedEntry:null},R;if(H.enableAuthStatus)R=wD.getInstance().subscribe((D8)=>{V.enqueue({type:"auth_status",isAuthenticating:D8.isAuthenticating,output:D8.output,error:D8.error,uuid:gX(),session_id:I8()})});let h=(a6)=>{let D8=PnK(a6);if(D8)V.enqueue({type:"rate_limit_event",rate_limit_info:D8,uuid:gX(),session_id:I8()})};ZK6.add(h);let C=Y,x=nR6(Y,AA8(),oI),B=new Map,m=void 0,S=CR(oI),F=process.env.CLAUDE_CODE_RESUME_INTERRUPTED_TURN;if(J&&J.kind!=="none"&&F)E(`[print.ts] Auto-resuming interrupted turn (kind: ${J.kind})`),WX5(C,J.message),Dj({mode:"prompt",value:J.message.message.content,uuid:gX()});let g=q_6().map((a6)=>{let D8=a6.value===null?"default":a6.value,Q6=D8==="default"?ZP():K5(D8),W8=QI(Q6),G8=kh8(Q6),s6=zX(a6.value),u6=Dk6(Q6);return{value:D8,displayName:a6.label,description:a6.description,...W8&&{supportsEffort:!0,supportedEffortLevels:UI.filter((h6)=>{if(h6==="max"&&!Ct6(Q6))return!1;if(h6==="xhigh"&&!bt6(Q6))return!1;return!0})},...G8&&{supportsAdaptiveThinking:!0},...s6&&{supportsFastMode:!0},...u6&&{supportsAutoMode:!0}}}),c=H.userSpecifiedModel,n=H.thinkingConfig&&H.thinkingConfig.type!=="disabled"?H.thinkingConfig.display:void 0,l=H.thinkingConfig;function z6(a6,D8){let Q6=BCK(a6,hE(D8));C.push(...Q6);for(let W8 of Q6)if(typeof W8.message.content==="string"&&W8.message.content.includes(`<${l0}>`))V.enqueue({type:"user",message:W8.message,session_id:I8(),parent_tool_use_id:null,uuid:W8.uuid,timestamp:W8.timestamp,isReplay:!0})}let A6=[],e=[],i=new Set;function O6(a6){for(let D8 of a6){if(D8.type!=="connected"||i.has(D8.name))continue;if(D8.config.type==="sdk")continue;let Q6=D8.name;try{D8.client.setRequestHandler($r,async(W8,G8)=>{i8(Q6,`Elicitation request received in print mode: ${I6(W8)}`);let s6=W8.params.mode==="url"?"url":"form";d("tengu_mcp_elicitation_shown",{mode:s6});let u6=await Y98(Q6,W8.params,G8.signal);if(u6)return i8(Q6,`Elicitation resolved by hook: ${I6(u6)}`),d("tengu_mcp_elicitation_response",{mode:s6,action:u6.action}),u6;let h6="url"in W8.params?W8.params.url:void 0,_8="requestedSchema"in W8.params?W8.params.requestedSchema:void 0,R8="elicitationId"in W8.params?W8.params.elicitationId:void 0,x6=OX5(W8.params._meta),i6=await q.handleElicitation(Q6,W8.params.message,_8,G8.signal,s6,h6,R8,x6),v8=await A98(Q6,i6,G8.signal,s6,R8);return d("tengu_mcp_elicitation_response",{mode:s6,action:v8.action}),v8}),D8.client.setNotificationHandler(mg6,(W8)=>{let{elicitationId:G8}=W8.params;i8(Q6,`Elicitation completion notification: ${G8}`),lx({message:`MCP server "${Q6}" confirmed elicitation ${G8} complete`,notificationType:"elicitation_complete"}),V.enqueue({type:"system",subtype:"elicitation_complete",mcp_server_name:Q6,elicitation_id:G8,uuid:gX(),session_id:I8()})}),i.add(Q6)}catch{}}}async function J6(){let a6=new Set(Object.keys(O)),D8=new Set(A6.map((h6)=>h6.name)),Q6=Array.from(a6).some((h6)=>!D8.has(h6)),W8=Array.from(D8).some((h6)=>!a6.has(h6)),G8=A6.some((h6)=>h6.type==="pending"),s6=A6.some((h6)=>h6.type==="failed");if(Q6||W8||G8||s6){for(let R8 of A6)if(!a6.has(R8.name)){if(R8.type==="connected")await R8.cleanup()}let h6=await ERK(O,(R8,x6)=>q.sendMcpMessage(R8,x6));A6=h6.clients,e=h6.tools;let _8=F4([...D8,...a6]);$((R8)=>({...R8,mcp:{...R8.mcp,tools:[...R8.mcp.tools.filter((x6)=>!_8.some((i6)=>x6.name.startsWith(Zh(i6)))),...e]}})),gP4(A6)}}J6();let $6={clients:[],tools:[],configs:{},policyRules:new Set},H6=(a6)=>{let D8=cl(a6.toolPermissionContext,a6.mcp.tools),Q6=j2(Du6([...z,...e,...$6.tools],D8,a6.toolPermissionContext.mode),"name");if(H.permissionPromptToolName)Q6=Q6.filter((G8)=>!e3(G8,H.permissionPromptToolName));let W8=rO8();if(W8&&!H.jsonSchema){let G8=OR8(W8);if("tool"in G8)Q6=[...Q6,G8.tool]}return Q6},q6=S6(process.env.CLAUDE_CODE_REMOTE)?process.env.CLAUDE_CODE_SYSTEM_PROMPT_GB_FEATURE:void 0,o=()=>{if(!q6)return H.systemPrompt;let a6=u8(q6,"");return typeof a6==="string"&&a6.length>0?a6:H.systemPrompt},_6=null,r=0;function t(){if(!_6)return;let a6=Math.min(r,C.length),D8=C.slice(a6).filter((Q6)=>Q6.type==="user"||Q6.type==="assistant");if(r=C.length,D8.length>0)_6.writeMessages(D8)}let Y6=Promise.resolve({response:{added:[],removed:[],errors:{}},sdkServersChanged:!1});function X6(a6){let D8=async()=>{let Q6=new Set(A6.map((G8)=>G8.name)),W8=await fX5(a6,{configs:O,clients:A6,tools:e},$6,$);for(let G8 of Object.keys(O))delete O[G8];if(Object.assign(O,W8.newSdkState.configs),A6=W8.newSdkState.clients,e=W8.newSdkState.tools,$6=W8.newDynamicState,W8.sdkServersChanged){let G8=new Set(A6.map((u6)=>u6.name)),s6=F4([...Q6,...G8]);$((u6)=>({...u6,mcp:{...u6.mcp,tools:[...u6.mcp.tools.filter((h6)=>!s6.some((_8)=>h6.name.startsWith(Zh(_8)))),...e]}}))}return{response:W8.response,sdkServersChanged:W8.sdkServersChanged}};return Y6=Y6.then(D8,D8),Y6}function M6(){let a6=w(),D8=a6.mcp.clients,Q6=j2([...a6.mcp.tools,...$6.tools],"name"),W8=new Set([...D8.map((G8)=>G8.name),...A6.map((G8)=>G8.name)]);return[...D8,...A6,...$6.clients.filter((G8)=>!W8.has(G8.name))].map((G8)=>{let s6;if(G8.config.type==="sse"||G8.config.type==="http")s6={type:G8.config.type,url:G8.config.url,headers:G8.config.headers,oauth:G8.config.oauth};else if(G8.config.type==="claudeai-proxy")s6={type:"claudeai-proxy",url:G8.config.url,id:G8.config.id};else if(G8.config.type==="stdio"||G8.config.type===void 0)s6={type:"stdio",command:G8.config.command,args:G8.config.args};let u6=G8.type==="connected"?Ll(Q6,G8.name).map((_8)=>({name:_8.mcpInfo?.toolName??_8.name,annotations:{readOnly:_8.isReadOnly({})||void 0,destructive:_8.isDestructive?.({})||void 0,openWorld:_8.isOpenWorld?.({})||void 0}})):void 0,h6;if(G8.type==="connected"&&G8.capabilities.experimental){let _8={...G8.capabilities.experimental};if(_8["claude/channel"]&&(!mP6()||!oO7(G8.config.pluginSource)))delete _8["claude/channel"];if(Object.keys(_8).length>0)h6={experimental:_8}}return{name:G8.name,status:G8.type,serverInfo:G8.type==="connected"?G8.serverInfo:void 0,error:G8.type==="failed"?G8.error:void 0,config:s6,scope:G8.config.scope,tools:u6,capabilities:h6}})}async function W6(a6){try{await Promise.all([Promise.resolve(),Rf6("headless_managed_settings_wait",()=>Qu8())])}catch(Q6){j6(Q6)}let D8=!1;try{if(D8=await eJ5(a6),D8)await y6()}catch(Q6){j6(Q6)}return D8}let V6=null,f6=null,G6;if(!S9())if(S6(process.env.CLAUDE_CODE_SYNC_PLUGIN_INSTALL))G6=H.outputFormat==="stream-json"?(a6)=>void q.write({type:"system",subtype:"plugin_install",status:a6.status,name:"name"in a6?a6.name:void 0,error:"error"in a6?a6.error:void 0,uuid:gX(),session_id:I8()}):void 0,G6?.({status:"started"}),V6=W6((a6)=>G6?.(a6));else f6=$X5(W6);let k6=nJ5(()=>!M),T6=_,v6=j;async function L6(){let{agentDefinitions:a6}=await PW6($);T6=yu6(await eD(AA8()));let D8=v6.filter((Q6)=>Q6.source==="flagSettings");v6=[...a6.allAgents,...D8]}async function y6(){let{servers:a6}=await Ct(),D8={};for(let[G8,s6]of Object.entries(a6)){let u6=s6.type;if(u6===void 0||u6==="stdio"||u6==="sse"||u6==="http"||u6==="sdk")D8[G8]=s6}for(let[G8,s6]of Object.entries(O))if(s6.type==="sdk"&&!(G8 in D8))D8[G8]=s6;let{response:Q6,sdkServersChanged:W8}=await X6(D8);if(W8)J6();E(`Headless MCP refresh: added=${Q6.added.length}, removed=${Q6.removed.length}`)}let c6=Em6.subscribe(()=>{On(),eD(AA8()).then((a6)=>{T6=yu6(a6)})});yj6(()=>{if(v&&AR8("now").length>0)v.abort("interrupt")});let Z8=async()=>{if(M)return;M=!0,W=void 0,q.sessionState.notifyStateChanged("running"),k6.stop(),GM("run_entry");try{if(await J6(),GM("after_updateSdkMcp"),V6){let D8=parseInt(process.env.CLAUDE_CODE_SYNC_PLUGIN_INSTALL_TIMEOUT_MS||"",10);if(D8>0){let W8=l7(D8).then(()=>"timeout");if(await Promise.race([V6,W8])==="timeout")j6(Error(`CLAUDE_CODE_SYNC_PLUGIN_INSTALL: plugin installation timed out after ${D8}ms`)),d("tengu_sync_plugin_install_timeout",{timeout_ms:D8})}else await V6;V6=null;try{await L6()}catch(W8){j6(W8)}let{setupPluginHookHotReload:Q6}=await Promise.resolve().then(() => (HJ6(),di1));Q6()}}finally{G6?.({status:"completed"}),G6=void 0}if(S6(process.env.CLAUDE_CODE_ENABLE_BACKGROUND_PLUGIN_REFRESH)&&f6?.needsRefresh){f6.needsRefresh=!1;try{await L6()}catch(D8){j6(D8)}}try{let D8,Q6=!1,W8=!0,G8=async()=>{while(D8=Ke6(G)){if(D8.mode!=="prompt"&&D8.mode!=="orphaned-permission"&&D8.mode!=="task-notification")throw Error("only prompt commands are supported in streaming mode");let s6=[D8];if(D8.mode==="prompt"){while(HX5(D8,Lj6(G)))s6.push(Ke6(G));if(s6.length>1)D8={...D8,value:jX5(s6.map((g8)=>g8.value)),uuid:s6.findLast((g8)=>g8.uuid)?.uuid??D8.uuid,fileAttachments:s6.flatMap((g8)=>g8.fileAttachments??[])}}let u6=s6.map((g8)=>g8.uuid).filter((g8)=>g8!==void 0);if(H.replayUserMessages&&s6.length>1){for(let g8 of s6)if(g8.uuid&&g8.uuid!==D8.uuid)V.enqueue({type:"user",message:{role:"user",content:g8.value},session_id:I8(),parent_tool_use_id:null,uuid:g8.uuid,isReplay:!0,...g8.fileAttachments?.length&&{file_attachments:g8.fileAttachments},...g8.origin&&{origin:g8.origin}})}if(W8)W8=!1,await JX5(w);let h6=w(),_8=[...h6.mcp.clients,...A6,...$6.clients];O6(_8);for(let g8 of _8)P07(g8);let R8=H6(h6);for(let g8 of u6)q.onCommandLifecycle?.(g8,"started");if(D8.mode==="task-notification"){let g8=typeof D8.value==="string"?D8.value:"",w6=g8.match(/<task-id>([^<]+)<\/task-id>/),D6=g8.match(/<tool-use-id>([^<]+)<\/tool-use-id>/),U6=g8.match(/<output-file>([^<]+)<\/output-file>/),F6=g8.match(/<status>([^<]+)<\/status>/),z8=g8.match(/<summary>([^<]+)<\/summary>/),l6=(uq)=>uq==="completed"||uq==="failed"||uq==="stopped"||uq==="killed",j8=F6?.[1],f8=l6(j8)?j8==="killed"?"stopped":j8:"completed",o8=g8.match(/<usage>([\s\S]*?)<\/usage>/)?.[1]??"",n1=o8.match(/<total_tokens>(\d+)<\/total_tokens>/),c1=o8.match(/<tool_uses>(\d+)<\/tool_uses>/),dq=o8.match(/<duration_ms>(\d+)<\/duration_ms>/);if(F6)V.enqueue({type:"system",subtype:"task_notification",task_id:w6?.[1]??"",tool_use_id:D6?.[1],status:f8,output_file:U6?.[1]??"",summary:z8?.[1]??"",usage:n1&&c1?{total_tokens:parseInt(n1[1],10),tool_uses:parseInt(c1[1],10),duration_ms:dq?parseInt(dq[1],10):0}:void 0,session_id:I8(),uuid:gX()})}let x6=D8.value;if(q instanceof $e8&&D8.mode==="prompt")d("tengu_bridge_message_received",{is_repl:!1});if(D8.shouldQuery!==!1){if(N.abortController?.abort(),N.abortController=null,N.pendingSuggestion=null,N.pendingLastEmittedEntry=null,N.lastEmitted&&D8.mode==="prompt"){let g8=typeof x6==="string"?x6:x6.find((w6)=>w6.type==="text")?.text;if(typeof g8==="string")hc4(N.lastEmitted.text,g8,N.lastEmitted.emittedAt,N.lastEmitted.promptId,N.lastEmitted.generationRequestId);N.lastEmitted=null}}v=F5();let i6=void 0;GM("before_ask"),J38();let v8=D8;if(v8.uuid!==void 0&&aP4(v8.uuid)){q.onCommandLifecycle?.(v8.uuid,"completed");continue}let f1=typeof x6==="string"?x6:s5(x6,`
18267
18267
  `);await gV8(v8.workload??H.workload,()=>jx8(f1,async()=>{let g8=!1,w6=!1,D6=0,U6=VW();try{for await(let F6 of dJ5({commands:j2([...T6,...h6.mcp.commands],"name"),prompt:x6,promptUuid:v8.uuid,isMeta:v8.isMeta,shouldQuery:v8.shouldQuery,stopHookActive:v8.stopHookActive,fileAttachments:v8.fileAttachments,origin:v8.origin??(v8.mode==="task-notification"?{kind:"task-notification"}:void 0),cwd:AA8(),tools:R8,refreshTools:()=>H6(w()),verbose:H.verbose,mcpClients:_8,thinkingConfig:l,maxTurns:H.maxTurns,maxBudgetUsd:H.maxBudgetUsd,taskBudget:H.taskBudget,canUseTool:A,userSpecifiedModel:c,fallbackModel:H.fallbackModel,jsonSchema:rO8()??H.jsonSchema,mutableMessages:C,sessionEnvVars:B,tmuxSocket:m,getReadFileCache:()=>S.size===0?x:oy6(x,S),setReadFileCache:(z8)=>{x=z8;for(let[l6,j8]of S.entries()){let f8=x.get(l6);if(!f8||j8.timestamp>f8.timestamp)x.set(l6,j8)}S.clear()},customSystemPrompt:o(),appendSystemPrompt:H.appendSystemPrompt,appendSubagentSystemPrompt:H.appendSubagentSystemPrompt,excludeDynamicSections:H.excludeDynamicSections,getAppState:w,setAppState:$,abortController:v,replayUserMessages:H.replayUserMessages,includePartialMessages:H.includePartialMessages,onCommandLifecycle:q.onCommandLifecycle,sessionState:q.sessionState,handleElicitation:(z8,l6,j8)=>q.handleElicitation(z8,l6.message,void 0,j8,l6.mode,l6.url,"elicitationId"in l6?l6.elicitationId:void 0,OX5(l6._meta)),agents:v6,orphanedPermission:v8.orphanedPermission,deferredToolUse:P,setSDKStatus:(z8,l6)=>{V.enqueue({type:"system",subtype:"status",status:z8,...l6?.compactResult!==void 0&&{compact_result:l6.compactResult},...l6?.compactError!==void 0&&{compact_error:l6.compactError},session_id:I8(),uuid:gX()})}})){if(P=void 0,t(),F6.type==="system"){if(F6.subtype==="api_retry")g8=!0,D6=Math.max(D6,F6.error_status??0);if(F6.subtype==="compact_boundary")w6=!0}if(F6.type==="result"){d("tengu_sdk_result",{subtype:F6.subtype,is_error:F6.is_error,num_turns:F6.num_turns,duration_ms:F6.duration_ms,duration_api_ms:VW()-U6,saw_retry:g8,saw_compact:w6,retry_status:g8?D6:void 0,api_error_status:F6.subtype==="success"?F6.api_error_status??void 0:void 0});for(let l6 of ze6())V.enqueue(l6);let z8=w();if(v8.shouldQuery===!1){if(H.sessionMirror)await mT();V.enqueue(F6)}else if(XI8(z8).some((l6)=>(l6.type==="local_agent"||l6.type==="local_workflow")&&yH(l6)))f=F6;else{if(f=null,H.sessionMirror)await mT();V.enqueue(F6)}}else{for(let z8 of ze6())V.enqueue(z8);V.enqueue(F6)}}}finally{Uc()}}));for(let g8 of u6)q.onCommandLifecycle?.(g8,"completed");if(t(),_6?.sendResult(),H.promptSuggestions&&v8.shouldQuery!==!1&&!c5(process.env.CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION)){N.abortController?.abort();let w6=new AbortController;N.abortController=w6;let D6=XJ6();if(!D6)af("sdk_no_params",void 0,void 0,"sdk");else{let U6={promise:null};U6.promise=(async()=>{try{let F6=await ka1(w6,C,w,D6,"sdk");if(!F6||w6.signal.aborted)return;let z8={type:"prompt_suggestion",suggestion:F6.suggestion,uuid:gX(),session_id:I8()},l6={text:F6.suggestion,emittedAt:Date.now(),promptId:F6.promptId,generationRequestId:F6.generationRequestId};if(f)N.pendingSuggestion=z8,N.pendingLastEmittedEntry={text:l6.text,promptId:l6.promptId,generationRequestId:l6.generationRequestId};else N.lastEmitted=l6,V.enqueue(z8)}catch(F6){if(F6 instanceof Error&&(F6.name==="AbortError"||F6.name==="APIUserAbortError")){af("aborted",void 0,void 0,"sdk");return}j6(r1(F6))}finally{if(N.inflightPromise===U6.promise)N.inflightPromise=null}})(),N.inflightPromise=U6.promise}}rr1(),ad8(),ir1()}};do{for(let s6 of ze6())V.enqueue(s6);W="draining_commands",await G8(),Q6=!1;{let s6=w(),u6=XI8(s6).some((_8)=>yH(_8)&&_8.type!=="in_process_teammate"),h6=Lj6(G)!==void 0;if(u6||h6){if(Q6=!0,!h6)W="waiting_for_agents",await l7(100)}}}while(Q6);if(f){if(H.sessionMirror)await mT();if(V.enqueue(f),f=null,N.pendingSuggestion){if(V.enqueue(N.pendingSuggestion),N.pendingLastEmittedEntry)N.lastEmitted={...N.pendingLastEmittedEntry,emittedAt:Date.now()},N.pendingLastEmittedEntry=null;N.pendingSuggestion=null}}}catch(D8){d("tengu_sdk_session_crash",BXA(D8)),d("tengu_sdk_result",{subtype:"error_during_execution",is_error:!0,num_turns:0,duration_ms:0,duration_api_ms:0,saw_retry:!1,saw_compact:!1});try{if(H.sessionMirror)await mT();await q.write({type:"result",subtype:"error_during_execution",duration_ms:0,duration_api_ms:0,is_error:!0,num_turns:0,stop_reason:null,session_id:I8(),total_cost_usd:0,usage:iP,modelUsage:{},permission_denials:[],uuid:gX(),errors:[b6(D8),...NA6().map((Q6)=>Q6.error)]})}catch{}N.abortController?.abort(),j5(1);return}finally{if(W="finally_flush",await q.flushInternalEvents(),W="finally_post_flush",!rs())await Promise.race([q.flushDeliveryAcks(),l7(5000,void 0,{unref:!0})]);if(!rs()){q.sessionState.notifyStateChanged("idle");for(let D8 of ze6())V.enqueue(D8)}M=!1,k6.start()}if(Lj6(G)!==void 0){Z8();return}{let Q6=w().teamContext;if(Q6&&Sv(Q6))while(!0){let s6=w();if(!(iZ8(s6)||s6.teamContext&&Object.keys(s6.teamContext.teammates).length>0)){E("[print.ts] No more active teammates, stopping poll");break}let h6=await qJ6("team-lead",s6.teamContext?.teamName);if(h6.length>0){E(`[print.ts] Team-lead found ${h6.length} unread messages`),await A18("team-lead",s6.teamContext?.teamName);let _8=s6.teamContext?.teamName;for(let x6 of h6){let i6=Qk(x6.text);if(i6&&_8){let v8=i6.from;E(`[print.ts] Processing shutdown_approved from ${v8}`);let f1=s6.teamContext?.teammates?Object.entries(s6.teamContext.teammates).find(([,g8])=>g8.name===v8)?.[0]:void 0;if(f1)nM6(_8,{agentId:f1,name:v8}),E(`[print.ts] Removed ${v8} from team file`),await p56(_8,f1,v8,"shutdown"),$((g8)=>{if(!g8.teamContext?.teammates)return g8;if(!(f1 in g8.teamContext.teammates))return g8;let{[f1]:w6,...D6}=g8.teamContext.teammates;return{...g8,teamContext:{...g8.teamContext,teammates:D6}}})}}let R8=h6.map((x6)=>`<${oX} teammate_id="${x6.from}"${x6.color?` color="${x6.color}"`:""}>
18268
18268
  ${x6.text}
18269
18269
  </${oX}>`).join(`