| 16405 | `)),process.exit(1);let W=O?`pr-${O}`:Y??CQ(),D;if(P){let G=jH(Z8());if(!G)process.stderr.write($8.red(`Error: Could not determine the main git repository root. |
| 16406 | `)),process.exit(1);if(G!==(hY(Z8())??Z8()))c8("info","worktree_resolved_to_main_repo"),process.chdir(G),QO(G);D=$?bQ8(G,yJ6(W)):void 0}else D=$?bQ8(Z8(),yJ6(W)):void 0;let f;try{f=await b88(N8(),W,D,O?{prNumber:O}:void 0)}catch(G){process.stderr.write($8.red(`Error creating worktree: ${d6(G)} |
| 16407 | `)),process.exit(1)}if(d("tengu_worktree_created",{tmux_enabled:$}),$&&D){let G=await Z_7(D,f.worktreePath);if(G.created)console.log($8.green(`Created tmux session: ${$8.bold(D)} |
| 16408 | To attach: ${$8.bold(`tmux attach -t ${D}`)}`));else console.error($8.yellow(`Warning: Failed to create tmux session: ${G.error}`))}process.chdir(f.worktreePath),QO(f.worktreePath),aR(Z8()),bb6(Z8()),Oy(f),wN(),eE6()}if(c8("info","setup_background_jobs_starting"),!f9())P75();jn1(),c8("info","setup_background_jobs_launched"),U4("setup_before_prefetch"),c8("info","setup_prefetch_starting");let J=i7()&&i6(process.env.CLAUDE_CODE_SYNC_PLUGIN_INSTALL)||f9();if(!J)u0(Fz());if(Promise.resolve().then(() => (Nj6(),jo1)).then((X)=>{if(!J)X.loadPluginHooks(),X.setupPluginHookHotReload()}),!f9())Promise.resolve().then(() => (Q67(),HPK)).then((X)=>X.registerSessionFileAccessHooks()),Promise.resolve().then(() => (F67(),g67)).then((X)=>X.startTeamMemoryWatcher());if(m_7(),d("tengu_started",{}),bv1(i7()),U4("setup_after_prefetch"),!f9()){let{hasReleaseNotes:X}=await ARK(j8().lastReleaseNotesSeen);if(X)await mRK()}if(K==="bypassPermissions"||_){if(process.platform!=="win32"&&typeof process.getuid==="function"&&process.getuid()===0&&process.env.IS_SANDBOX!=="1"&&!i6(process.env.CLAUDE_CODE_BUBBLEWRAP))console.error("--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons"),process.exit(1)}let M=ww();if(M.lastCost!==void 0&&M.lastDuration!==void 0)d("tengu_exit",{last_session_cost:M.lastCost,last_session_api_duration:M.lastAPIDuration,last_session_tool_duration:M.lastToolDuration,last_session_duration:M.lastDuration,last_session_lines_added:M.lastLinesAdded,last_session_lines_removed:M.lastLinesRemoved,last_session_total_input_tokens:M.lastTotalInputTokens,last_session_total_output_tokens:M.lastTotalOutputTokens,last_session_total_cache_creation_input_tokens:M.lastTotalCacheCreationInputTokens,last_session_total_cache_read_input_tokens:M.lastTotalCacheReadInputTokens,last_session_fps_average:M.lastFpsAverage,last_session_fps_low_1_pct:M.lastFpsLow1Pct,last_session_id:M.lastSessionId,...M.lastSessionMetrics})}var Gl8=y(()=>{x3();k8();I7();XS6();tN();oq8();v8();yA();W75();M0();i$();x77();G7();wM();V1();oY();y_();J16();m8();y8();E5();M68();Vj6();y$();f75();E8();QF8();PQ();SJ();_K();Cx();d0()});import{URL as UoY}from"url";function Z75(q,K={},_,z){if(i6(process.env.CLAUDE_CODE_USE_CCR_V2)){let Y=new UoY(q.href);if(Y.protocol==="wss:")Y.protocol="https:";else if(Y.protocol==="ws:")Y.protocol="http:";return Y.pathname=Y.pathname.replace(/\/$/,"")+"/worker/events/stream",new bJ6(Y,K,_,z)}if(q.protocol==="ws:"||q.protocol==="wss:"){if(i6(process.env.CLAUDE_CODE_POST_FOR_SESSION_INGRESS_V2))return new A48(q,K,_,z);return new $48(q,K,_,z)}else throw Error(`Unsupported protocol: ${q.protocol}`)}var G75=y(()=>{m8();fz7();Ad8();Dz7()});import{PassThrough as QoY}from"stream";import{URL as doY}from"url";var Tl8;var T75=y(()=>{v8();gQ8();c9();_8();oY();m8();y8();RA();E8();nC();z48();_K();a$7();Qc8();Gz7();Ad8();G75();Tl8=class Tl8 extends zK8{url;transport;inputStream;isBridge=!1;isDebug=!1;ccrClient=null;keepAliveTimer=null;constructor(q,K,_){let z=new QoY({encoding:"utf8"});super(z,_);this.inputStream=z,this.url=new doY(q);let Y={},$=WD();if($)Y.Authorization=`Bearer ${$}`;else N("[remote-io] No session ingress token available",{level:"error"});let A=process.env.CLAUDE_CODE_ENVIRONMENT_RUNNER_VERSION;if(A)Y["x-environment-runner-version"]=A;let O=()=>{let j={},H=WD();if(H)j.Authorization=`Bearer ${H}`;let J=process.env.CLAUDE_CODE_ENVIRONMENT_RUNNER_VERSION;if(J)j["x-environment-runner-version"]=J;return j};if(this.transport=Z75(this.url,Y,N8(),O),this.isBridge=process.env.CLAUDE_CODE_ENVIRONMENT_KIND==="bridge",this.isDebug=ST(),this.transport.setOnData((j)=>{if(this.inputStream.write(j),this.isBridge&&this.isDebug)C4(j.endsWith(` |
| 16409 | `)?j:j+` |
| 16410 | `)}),this.transport.setOnClose(()=>{this.inputStream.end()}),i6(process.env.CLAUDE_CODE_USE_CCR_V2)){if(!(this.transport instanceof bJ6))throw Error("CCR v2 requires SSETransport; check getTransportForUrl");this.ccrClient=new O48(this.transport,this.url);let j=this.ccrClient.initialize();this.restoredWorkerState=j.catch(()=>null),j.catch((J)=>{c8("error","cli_worker_lifecycle_init_failed",{reason:J instanceof YC6?J.reason:"unknown"}),H6(Error(`CCRClient initialization failed: ${d6(J)}`)),xK(1,"other")}),pq(async()=>this.ccrClient?.close()),u97((J,M,X)=>this.ccrClient.writeInternalEvent(J,M,X)),m97(()=>this.ccrClient.readInternalEvents(),()=>this.ccrClient.readSubagentInternalEvents());let H={started:"processing",completed:"processed"};HP4((J,M)=>{this.ccrClient?.reportDelivery(J,H[M])}),bUK((J,M)=>{this.ccrClient?.reportState(J,M)}),xUK((J)=>{this.ccrClient?.reportMetadata(J)})}this.transport.connect();let w=bd().session_keepalive_interval_v2_ms;if(this.isBridge&&w>0)this.keepAliveTimer=setInterval(()=>{N("[remote-io] keep_alive sent"),this.write({type:"keep_alive"}).catch((j)=>{N(`[remote-io] keep_alive write failed: ${d6(j)}`)})},w),this.keepAliveTimer.unref?.();if(pq(async()=>this.close()),K){let j=this.inputStream;(async()=>{for await(let H of K)j.write(String(H).replace(/\n$/,"")+` |
| 16411 | `)})()}}flushInternalEvents(){return this.ccrClient?.flushInternalEvents()??Promise.resolve()}get internalEventsPending(){return this.ccrClient?.internalEventsPending??0}async write(q){if(this.ccrClient)await this.ccrClient.writeEvent(q);else await this.transport.write(q);if(this.isBridge){if(q.type==="control_request"||this.isDebug)C4(Uc8(q)+` |
| 16412 | `)}}close(){if(this.keepAliveTimer)clearInterval(this.keepAliveTimer),this.keepAliveTimer=null;this.transport.close(),this.inputStream.end()}}});var htj;var v75=y(()=>{IY();E2();qM();NO6();i1();Hr();htj=[...jr,"Tmux",zI]});function V75(q){if(q.length===0)return!0;try{return JSON.parse(q),!0}catch{return!1}}function N75(){if(dA7)return;dA7=!0,GM6=process.stdout.write.bind(process.stdout),process.stdout.write=function(q,K,_){let z=typeof q==="string"?q:Buffer.from(q).toString("utf-8");ad+=z;let Y,$=!0;while((Y=ad.indexOf(` |
| 16413 | `))!==-1){let O=ad.slice(0,Y);if(ad=ad.slice(Y+1),V75(O))$=GM6(O+` |