import{F as Kz,H as Nz,P as Qz}from"./cli-0.5.3-r14s18hg.mjs";import"./cli-0.5.3-t456sxjr.mjs";import"./cli-0.5.3-r4qf2552.mjs";import"./cli-0.5.3-x3245wpn.mjs";import{vd as Jz,wd as tz}from"./cli-0.5.3-y0dr2hdj.mjs";import"./cli-0.5.3-fq3092v1.mjs";import"./cli-0.5.3-v7c2x1hc.mjs";import"./cli-0.5.3-a5004mf6.mjs";import"./cli-0.5.3-hj2dsm82.mjs";import"./cli-0.5.3-gf93xez3.mjs";import"./cli-0.5.3-q7rc4gf8.mjs";import{qh as m,rh as uz}from"./cli-0.5.3-nahm9pp1.mjs";import{$I as rz,JA as a,Lp as d,MA as cz,MI as B,NI as t,Np as l,Os as c,Qt as p,Rt as lz,Ts as dz,UG as n,VB as r,WB as pz,Wp as mz,aH as i,eH as az,eJ as s,fJ as o,gK as e,jK as zz,nK as iz,pJ as nz,qn as I,rn as gz}from"./cli-0.5.3-jbzr8k4s.mjs";import"./cli-0.5.3-me9jkw92.mjs";import"./cli-0.5.3-bqmztzjc.mjs";import"./cli-0.5.3-ytqxzjff.mjs";import"./cli-0.5.3-h6n812td.mjs";import"./cli-0.5.3-hg8c6qbh.mjs";import"./cli-0.5.3-39jr2yrx.mjs";import"./cli-0.5.3-42e2paz8.mjs";import"./cli-0.5.3-mn45xfck.mjs";import"./cli-0.5.3-m884a3pk.mjs";import"./cli-0.5.3-4f9xxrem.mjs";import"./cli-0.5.3-gr8nsa2k.mjs";import"./cli-0.5.3-yj9nbd9d.mjs";import"./cli-0.5.3-55kd38ff.mjs";import"./cli-0.5.3-e6bjcfwg.mjs";import"./cli-0.5.3-4dbxtwh3.mjs";import"./cli-0.5.3-m0kfmb79.mjs";import"./cli-0.5.3-8zq9vdtg.mjs";import"./cli-0.5.3-vmx7agj7.mjs";import"./cli-0.5.3-h8xs2818.mjs";import"./cli-0.5.3-wcx7cnw5.mjs";import"./cli-0.5.3-9zbakvbf.mjs";import"./cli-0.5.3-hx550gz2.mjs";import"./cli-0.5.3-842pf3t4.mjs";import"./cli-0.5.3-wxead1ct.mjs";import"./cli-0.5.3-s1hz35ye.mjs";import"./cli-0.5.3-g0svn6bx.mjs";import"./cli-0.5.3-sfdh3pkx.mjs";import"./cli-0.5.3-d8tjnxcj.mjs";import"./cli-0.5.3-6zfw1732.mjs";import"./cli-0.5.3-ptjdgcsy.mjs";import"./cli-0.5.3-tp3jye12.mjs";import"./cli-0.5.3-vqmxwet2.mjs";import"./cli-0.5.3-rch86nhn.mjs";import"./cli-0.5.3-zg2apr51.mjs";import"./cli-0.5.3-ngnshpb7.mjs";import"./cli-0.5.3-e58xste9.mjs";import"./cli-0.5.3-6163zevg.mjs";import"./cli-0.5.3-jmkkd5ph.mjs";import{G0 as f,L0 as v,_0 as Cz,f2 as u,p2 as fz,x3 as g,z3 as vz}from"./cli-0.5.3-1vt6twff.mjs";import"./cli-0.5.3-7017ez65.mjs";import"./cli-0.5.3-ea94acj4.mjs";import"./cli-0.5.3-3k22nqvy.mjs";import"./cli-0.5.3-63q4g3zt.mjs";import"./cli-0.5.3-dyhbm5kp.mjs";import"./cli-0.5.3-vpcrbd8n.mjs";import"./cli-0.5.3-jdw3ajfv.mjs";import"./cli-0.5.3-qg4a557t.mjs";import{e6 as P,f6 as xz}from"./cli-0.5.3-t65dek0m.mjs";import"./cli-0.5.3-kavpx97n.mjs";import{ida as j,nda as Sz}from"./cli-0.5.3-9bdwhdys.mjs";import"./cli-0.5.3-ttc72eq3.mjs";import"./cli-0.5.3-g75gdzrp.mjs";import"./cli-0.5.3-1rg2r7n7.mjs";import"./cli-0.5.3-6j2jk6dt.mjs";import"./cli-0.5.3-66650sba.mjs";import"./cli-0.5.3-9vh3vpap.mjs";import{Kfa as C,Nfa as w,Qfa as hz}from"./cli-0.5.3-n3cxyxpg.mjs";import"./cli-0.5.3-kbvzmaax.mjs";import{cga as S,kga as Mz}from"./cli-0.5.3-7wdgps7z.mjs";import"./cli-0.5.3-c8bcrqa4.mjs";import{Fja as M,bla as h,gma as Pz}from"./cli-0.5.3-qrvd6cmy.mjs";import"./cli-0.5.3-2dk1sk8w.mjs";import{Yma as x}from"./cli-0.5.3-0df3r78b.mjs";xz();gz();Pz();iz();rz();nz();pz();tz();lz();dz();vz();fz();hz();mz();Mz();Cz();uz();az();cz();Sz();async function IJ(Wz){let{ctx:R,options:K,teleport:E,setupTrigger:_,outputFormat:L,inputPrompt:Xz,commands:Yz,tools:Zz,mcpClients:$z,mcpCommands:jz,mcpTools:Gz,sdkMcpConfigs:qz,agentDefinitions:wz,regularMcpConfigs:V,claudeaiConfigPromise:Rz,toolPermissionContext:q,effectiveModel:A,advisorModel:D,allowDangerouslySkipPermissions:Lz,betas:Vz,jsonSchema:Hz,allowedTools:Oz,thinkingConfig:Uz,systemPrompt:Iz,appendSystemPrompt:Bz,userSpecifiedFallbackModel:Ez,effectiveReplayUserMessages:_z,agentCli:Az,verbose:Dz}=Wz;if(L==="stream-json"||L==="json")C(!0);m(),Kz();let F=K.continue||K.resume||E||_?void 0:a("startup");F?.catch(()=>{}),j("before_validateForceLoginOrg");let b=await g();if(!b.valid)process.stderr.write(b.message+`
`),process.exit(1);let Fz=R.disableSlashCommands?[]:Yz.filter((J)=>J.type==="prompt"&&!J.disableNonInteractive||J.type==="local"&&J.supportsNonInteractive),y=r(),bz={...y,mcp:{...y.mcp,clients:$z,commands:jz,tools:Gz},toolPermissionContext:q,effortValue:d(K.effort)??l(),...f()&&{fastMode:v(A??null)},...c()&&D&&{advisorModel:D},...{}},Y=p(bz,Jz);if(q.mode==="bypassPermissions"||Lz)i(q);if(n(q,Y.getState().fastMode).then(({updateContext:J})=>{Y.setState((X)=>{let N=J(X.toolPermissionContext);if(N===X.toolPermissionContext)return X;return{...X,toolPermissionContext:N}})}),K.sessionPersistence===!1)h(!0);M(u(Vz));let k=(J,X)=>{if(Object.keys(J).length===0)return Promise.resolve();return Y.setState((N)=>({...N,mcp:{...N.mcp,clients:[...N.mcp.clients,...Object.entries(J).map(([Z,Q])=>({name:Z,type:"pending",config:Q}))]}})),e(({client:N,tools:Z,commands:Q})=>{Y.setState((z)=>({...z,mcp:{...z.mcp,clients:z.mcp.clients.some((W)=>W.name===N.name)?z.mcp.clients.map((W)=>W.name===N.name?N:W):[...z.mcp.clients,N],tools:I([...z.mcp.tools,...Z],"name"),commands:I([...z.mcp.commands,...Q],"name")}}))},J).catch((N)=>w(`[MCP] ${X} connect error: ${N}`))};j("before_connectMcp"),await k(V,"regular"),j("after_connectMcp");let T=5000,yz=Rz.then((J)=>{if(Object.keys(J).length>0){let Z=new Set;for(let z of Object.values(J)){let W=B(z);if(W)Z.add(W)}let Q=new Set;for(let[z,W]of Object.entries(V)){if(!z.startsWith("plugin:"))continue;let G=B(W);if(G&&Z.has(G))Q.add(z)}if(Q.size>0){w(`[MCP] Lazy dedup: suppressing ${Q.size} plugin server(s) that duplicate claude.ai connectors: ${[...Q].join(", ")}`);for(let z of Y.getState().mcp.clients){if(!Q.has(z.name)||z.type!=="connected")continue;z.client.onclose=void 0,zz(z.name,z.config).catch(()=>{})}Y.setState((z)=>{let{clients:W,tools:G,commands:O,resources:U}=z.mcp;W=W.filter(($)=>!Q.has($.name)),G=G.filter(($)=>!$.mcpInfo||!Q.has($.mcpInfo.serverName));for(let $ of Q)O=s(O,$),U=o(U,$);return{...z,mcp:{...z.mcp,clients:W,tools:G,commands:O,resources:U}}})}}let X=P(V,(Z,Q)=>!Q.startsWith("plugin:")),{servers:N}=t(J,X);return k(N,"claudeai")}),H,kz=await Promise.race([yz.then(()=>!1),new Promise((J)=>{H=setTimeout((X)=>X(!0),T,J)})]);if(H)clearTimeout(H);if(kz)w(`[MCP] claude.ai connectors not ready after ${T}ms — proceeding; background connection continues`);if(j("after_connectMcp_claudeai"),!S())Qz(),import("./backgroundHousekeeping-0.5.3-p0k5dqak.mjs").then((J)=>J.startBackgroundHousekeeping());Nz(),j("before_print_import");let{runHeadless:Tz}=await import("./print-0.5.3-v77bmcx5.mjs");j("after_print_import"),Tz(Xz,()=>Y.getState(),Y.setState,Fz,Zz,qz,wz.activeAgents,{continue:K.continue,resume:K.resume,verbose:Dz,outputFormat:L,jsonSchema:Hz,permissionPromptToolName:K.permissionPromptTool,allowedTools:Oz,thinkingConfig:Uz,maxTurns:K.maxTurns,maxBudgetUsd:K.maxBudgetUsd,taskBudget:K.taskBudget?{total:K.taskBudget}:void 0,systemPrompt:Iz,appendSystemPrompt:Bz,userSpecifiedModel:A,fallbackModel:Ez,teleport:E,sdkUrl:R.sdkUrl,replayUserMessages:_z,includePartialMessages:R.effectiveIncludePartialMessages,forkSession:K.forkSession||!1,resumeSessionAt:K.resumeSessionAt||void 0,rewindFiles:K.rewindFiles,enableAuthStatus:K.enableAuthStatus,agent:Az,setupTrigger:_??void 0,sessionStartHooksPromise:F})}export{IJ as runHeadlessBranch};
