import{I as Nz}from"./cli-0.5.12-47dbnsz1.mjs";import"./cli-0.5.12-paj8nhxk.mjs";import{R as Kz}from"./cli-0.5.12-tnk4m7zs.mjs";import{ea as Qz}from"./cli-0.5.12-15jvdvek.mjs";import"./cli-0.5.12-gfm1s8a2.mjs";import"./cli-0.5.12-pwee4pmy.mjs";import"./cli-0.5.12-cwbm4b6n.mjs";import{ed as Jz,fd as tz}from"./cli-0.5.12-wqn70xss.mjs";import{hd as m,id as uz}from"./cli-0.5.12-k976aej3.mjs";import"./cli-0.5.12-dpm51wzp.mjs";import"./cli-0.5.12-7j2hryxc.mjs";import"./cli-0.5.12-pq058s0e.mjs";import"./cli-0.5.12-02yr8j71.mjs";import"./cli-0.5.12-xdrtyw81.mjs";import"./cli-0.5.12-d158qgn4.mjs";import{DK as iz,FJ as nz,NA as a,Nt as p,Op as d,Ot as lz,QA as cz,Qn as I,Qp as l,Rn as gz,ZB as r,Zp as mz,_B as pz,aJ as B,bJ as t,iH as n,pJ as rz,qH as i,uH as az,uJ as s,vJ as o,wK as e,zK as zz}from"./cli-0.5.12-zc0qwdy2.mjs";import"./cli-0.5.12-whfz3xsx.mjs";import"./cli-0.5.12-z100r543.mjs";import"./cli-0.5.12-bzab36pn.mjs";import"./cli-0.5.12-pp1549k7.mjs";import"./cli-0.5.12-9mq24qzr.mjs";import"./cli-0.5.12-7repzgzv.mjs";import"./cli-0.5.12-pdqnfqg3.mjs";import{RR as c,ZR as dz}from"./cli-0.5.12-c2yq69h9.mjs";import"./cli-0.5.12-kez9r81a.mjs";import"./cli-0.5.12-zbcr8cbk.mjs";import"./cli-0.5.12-2wf629mh.mjs";import"./cli-0.5.12-ghtxkxqx.mjs";import"./cli-0.5.12-xg7a0dy4.mjs";import"./cli-0.5.12-s0h788we.mjs";import"./cli-0.5.12-m22yxpb9.mjs";import"./cli-0.5.12-cw1qs4bg.mjs";import"./cli-0.5.12-yq8ds97a.mjs";import"./cli-0.5.12-qew4mzgp.mjs";import"./cli-0.5.12-gwg1e43k.mjs";import"./cli-0.5.12-36swspqa.mjs";import"./cli-0.5.12-4dn79vqp.mjs";import"./cli-0.5.12-f5pfjvdk.mjs";import"./cli-0.5.12-fqp5s15p.mjs";import"./cli-0.5.12-rc1p9wk6.mjs";import"./cli-0.5.12-x479axrj.mjs";import"./cli-0.5.12-ysy6e9rz.mjs";import"./cli-0.5.12-cqv7z22w.mjs";import"./cli-0.5.12-7cn41yy7.mjs";import"./cli-0.5.12-34cd39ve.mjs";import"./cli-0.5.12-m2gh4ewc.mjs";import"./cli-0.5.12-c6whkxmz.mjs";import"./cli-0.5.12-w3hy6c60.mjs";import"./cli-0.5.12-5d3qcvf5.mjs";import"./cli-0.5.12-f141d2qa.mjs";import"./cli-0.5.12-khvy67r3.mjs";import{H1 as Cz,O2 as u,Y2 as fz,b4 as g,d4 as vz,n1 as f,s1 as v}from"./cli-0.5.12-pycnjaeg.mjs";import"./cli-0.5.12-8v5w8znc.mjs";import"./cli-0.5.12-ctqkj6ve.mjs";import"./cli-0.5.12-cbevkwg4.mjs";import"./cli-0.5.12-w00qj83e.mjs";import"./cli-0.5.12-nbcjwzzn.mjs";import"./cli-0.5.12-3t06hwwh.mjs";import"./cli-0.5.12-057c2cp2.mjs";import"./cli-0.5.12-ecgx5n54.mjs";import{I6 as C,J6 as Sz}from"./cli-0.5.12-g4wb8mj2.mjs";import{jda as j,oda as hz}from"./cli-0.5.12-vp5smcs1.mjs";import"./cli-0.5.12-y2kq7fe8.mjs";import"./cli-0.5.12-7vxpqr5a.mjs";import"./cli-0.5.12-hvtcdcev.mjs";import"./cli-0.5.12-asbn3d19.mjs";import"./cli-0.5.12-k1crwtdc.mjs";import"./cli-0.5.12-2jxq8gnm.mjs";import{cga as S,fga as w,iga as Mz}from"./cli-0.5.12-p5ps8gf0.mjs";import"./cli-0.5.12-hp0508v9.mjs";import"./cli-0.5.12-tfdwzg37.mjs";import{Oga as h,Wga as Pz}from"./cli-0.5.12-60w1a0bs.mjs";import{Qja as P,mla as M,rma as xz}from"./cli-0.5.12-c8f4daey.mjs";import"./cli-0.5.12-0qasc0ef.mjs";import"./cli-0.5.12-f8850v2j.mjs";import"./cli-0.5.12-495d826j.mjs";import"./cli-0.5.12-rt0k97yj.mjs";import"./cli-0.5.12-1vyz0tt9.mjs";import{boa as x}from"./cli-0.5.12-xzeb7mtb.mjs";Sz();gz();xz();iz();rz();nz();pz();tz();lz();dz();vz();fz();Mz();mz();Pz();Cz();uz();az();cz();hz();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")S(!0);m(),Qz();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)M(!0);P(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=C(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"),!h())Nz(),import("./backgroundHousekeeping-0.5.12-1yfjbpvk.mjs").then((J)=>J.startBackgroundHousekeeping());Kz(),j("before_print_import");let{runHeadless:Tz}=await import("./print-0.5.12-9y9vvttb.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};
