import{y3 as v,z3 as C}from"./cli-0.5.3-1vt6twff.mjs";import{D5 as Z,V5 as V}from"./cli-0.5.3-vpcrbd8n.mjs";import{Cba as x,Dba as Y,u6 as W,v6 as O}from"./cli-0.5.3-t65dek0m.mjs";import{Ida as P,Mda as Q,Uda as H}from"./cli-0.5.3-1rg2r7n7.mjs";import{Jea as X,Kea as U}from"./cli-0.5.3-66650sba.mjs";import{Nfa as f,Qfa as M,qfa as R,vfa as L}from"./cli-0.5.3-n3cxyxpg.mjs";import{Ega as w,Lga as I}from"./cli-0.5.3-c8bcrqa4.mjs";import{Fma as N,Gma as F}from"./cli-0.5.3-2dk1sk8w.mjs";import{Uma as h,Xma as B}from"./cli-0.5.3-0df3r78b.mjs";import{hostname as E}from"os";function $(){return P(G,!1)}function u(){if(!$())return;return y()}function n(){y.cache?.clear?.()}function o(){if(!$())return;let i=x();try{let q=i.read();if(q?.trustedDeviceToken)delete q.trustedDeviceToken,i.update(q)}catch{}y.cache?.clear?.()}async function t(){try{if(!await Q(G)){f(`[trusted-device] Gate ${G} is off, skipping enrollment`);return}if(process.env.CLAUDE_TRUSTED_DEVICE_TOKEN){f("[trusted-device] CLAUDE_TRUSTED_DEVICE_TOKEN env var is set, skipping enrollment (env var takes precedence)");return}let{getClaudeAIOAuthTokens:i}=(C(),h(v)),q=i()?.accessToken;if(!q){f("[trusted-device] No OAuth token, skipping enrollment");return}let J=x();if(W()){f("[trusted-device] Essential traffic only, skipping enrollment");return}let b=X().BASE_API_URL,m;try{m=await Z.post(`${b}/api/auth/trusted_devices`,{display_name:`Claude Code on ${E()} · ${process.platform}`},{headers:{Authorization:`Bearer ${q}`,"Content-Type":"application/json"},timeout:1e4,validateStatus:(j)=>j<500})}catch(j){f(`[trusted-device] Enrollment request failed: ${w(j)}`);return}if(m.status!==200&&m.status!==201){f(`[trusted-device] Enrollment failed ${m.status}: ${R(m.data).slice(0,200)}`);return}let z=m.data?.device_token;if(!z||typeof z!=="string"){f("[trusted-device] Enrollment response missing device_token field");return}try{let j=J.read();if(!j){f("[trusted-device] Cannot read storage, skipping token persist");return}j.trustedDeviceToken=z;let K=J.update(j);if(!K.success){f(`[trusted-device] Failed to persist token: ${K.warning??"unknown"}`);return}y.cache?.clear?.(),f(`[trusted-device] Enrolled device_id=${m.data.device_id??"unknown"}`)}catch(j){f(`[trusted-device] Storage write failed: ${w(j)}`)}}catch(i){f(`[trusted-device] Enrollment error: ${w(i)}`)}}var G="tengu_sessions_elevated_auth_enforcement",y;var d=B(()=>{V();F();U();H();M();I();O();Y();L();y=N(()=>{let i=process.env.CLAUDE_TRUSTED_DEVICE_TOKEN;if(i)return i;return x().read()?.trustedDeviceToken})});
export{u as eQ,n as fQ,o as gQ,t as hQ,d as iQ};
