import{A3 as v,B3 as C}from"./cli-0.5.4-jqt00ywx.mjs";import{F5 as Z,X5 as V}from"./cli-0.5.4-j7kkqxv6.mjs";import{Eba as x,Fba as Y,w6 as W,x6 as O}from"./cli-0.5.4-cbq01zg3.mjs";import{Kda as P,Oda as Q,Wda as H}from"./cli-0.5.4-2dw33ms6.mjs";import{Lea as X,Mea as U}from"./cli-0.5.4-e822fzaq.mjs";import{Pfa as f,Sfa as M,sfa as R,xfa as L}from"./cli-0.5.4-end8wj9r.mjs";import{Gga as w,Nga as I}from"./cli-0.5.4-sgcaw17t.mjs";import{Hma as N,Ima as F}from"./cli-0.5.4-959vxhhb.mjs";import{Wma as h,Zma as B}from"./cli-0.5.4-aacw1src.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 gQ,n as hQ,o as iQ,t as jQ,d as kQ};
