import{F as Kz,H as Nz,P as Qz}from"./cli-0.5.4-rk55tarh.mjs";import"./cli-0.5.4-xzfkbd3v.mjs";import"./cli-0.5.4-ns88wgqc.mjs";import"./cli-0.5.4-w7xyhk3x.mjs";import{vd as Jz,wd as tz}from"./cli-0.5.4-jrd2w9wa.mjs";import"./cli-0.5.4-3ne6665p.mjs";import"./cli-0.5.4-x2j8jcae.mjs";import"./cli-0.5.4-tzkhjsa7.mjs";import"./cli-0.5.4-bey1wxde.mjs";import"./cli-0.5.4-vs9qj6eq.mjs";import"./cli-0.5.4-5fpyxq2n.mjs";import{qh as m,rh as uz}from"./cli-0.5.4-7c6wpbhq.mjs";import{LA as a,Np as d,OA as cz,OI as B,PI as t,Pp as l,Qs as c,St as p,Tt as lz,Vs as dz,WG as n,XB as r,YB as pz,Yp as mz,bJ as rz,cH as i,gH as az,gJ as s,hJ as o,iK as e,lK as zz,pK as iz,rJ as nz,sn as I,tn as gz}from"./cli-0.5.4-k5fz4zd3.mjs";import"./cli-0.5.4-wbqf44ym.mjs";import"./cli-0.5.4-9ewg9gfs.mjs";import"./cli-0.5.4-we3mspgg.mjs";import"./cli-0.5.4-jzhazry0.mjs";import"./cli-0.5.4-82sw3hrw.mjs";import"./cli-0.5.4-31v143kt.mjs";import"./cli-0.5.4-1cy7wd6s.mjs";import"./cli-0.5.4-5e0pk96f.mjs";import"./cli-0.5.4-z154a7bp.mjs";import"./cli-0.5.4-ng5p0zjs.mjs";import"./cli-0.5.4-5hp7ks3t.mjs";import"./cli-0.5.4-8hdwp78f.mjs";import"./cli-0.5.4-mr9aznxx.mjs";import"./cli-0.5.4-jevfk5q7.mjs";import"./cli-0.5.4-27dzbzdy.mjs";import"./cli-0.5.4-a5bkdqqb.mjs";import"./cli-0.5.4-j2hnw539.mjs";import"./cli-0.5.4-9w59nnw4.mjs";import"./cli-0.5.4-z5d3q8kh.mjs";import"./cli-0.5.4-c0r12dqp.mjs";import"./cli-0.5.4-kqh172jk.mjs";import"./cli-0.5.4-vv4jbgkc.mjs";import"./cli-0.5.4-s7k1f0wc.mjs";import"./cli-0.5.4-0h0yz2k5.mjs";import"./cli-0.5.4-942dm5q1.mjs";import"./cli-0.5.4-rcmp5h4y.mjs";import"./cli-0.5.4-xdcww3x8.mjs";import"./cli-0.5.4-fq32ny1h.mjs";import"./cli-0.5.4-h1m67ngp.mjs";import"./cli-0.5.4-49erze3e.mjs";import"./cli-0.5.4-jytjks37.mjs";import"./cli-0.5.4-mn22gk7g.mjs";import"./cli-0.5.4-5t3jj85n.mjs";import"./cli-0.5.4-5shjmmkz.mjs";import"./cli-0.5.4-zb412kkm.mjs";import"./cli-0.5.4-prfn3sxd.mjs";import"./cli-0.5.4-6xmgebmk.mjs";import"./cli-0.5.4-vjgejcrz.mjs";import{B3 as vz,I0 as f,N0 as v,a1 as Cz,h2 as u,r2 as fz,z3 as g}from"./cli-0.5.4-jqt00ywx.mjs";import"./cli-0.5.4-9e7rkd8e.mjs";import"./cli-0.5.4-jp4wtw87.mjs";import"./cli-0.5.4-hambpq58.mjs";import"./cli-0.5.4-syvgmg9g.mjs";import"./cli-0.5.4-w8ttefr5.mjs";import"./cli-0.5.4-j7kkqxv6.mjs";import"./cli-0.5.4-qrwczx7j.mjs";import"./cli-0.5.4-v2z6p9td.mjs";import{g6 as P,h6 as xz}from"./cli-0.5.4-cbq01zg3.mjs";import"./cli-0.5.4-37v5fhf1.mjs";import{kda as j,pda as Sz}from"./cli-0.5.4-7grzwf6q.mjs";import"./cli-0.5.4-9qmek5dq.mjs";import"./cli-0.5.4-9c6r1fjg.mjs";import"./cli-0.5.4-2dw33ms6.mjs";import"./cli-0.5.4-x1fzfxmm.mjs";import"./cli-0.5.4-e822fzaq.mjs";import"./cli-0.5.4-09dvrzcr.mjs";import{Mfa as C,Pfa as w,Sfa as hz}from"./cli-0.5.4-end8wj9r.mjs";import"./cli-0.5.4-4x206j04.mjs";import{ega as S,mga as Mz}from"./cli-0.5.4-yd3rd9qt.mjs";import"./cli-0.5.4-sgcaw17t.mjs";import{Hja as M,dla as h,ima as Pz}from"./cli-0.5.4-jmc3bzbn.mjs";import"./cli-0.5.4-959vxhhb.mjs";import{_ma as x}from"./cli-0.5.4-aacw1src.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.4-eyy3dav6.mjs").then((J)=>J.startBackgroundHousekeeping());Nz(),j("before_print_import");let{runHeadless:Tz}=await import("./print-0.5.4-1p9gjatr.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};
