import{c4 as v,d4 as C}from"./cli-0.5.12-pycnjaeg.mjs";import{Eba as x,Fba as Y,gaa as Z,haa as V}from"./cli-0.5.12-g4wb8mj2.mjs";import{aea as R,eea as W,mea as O}from"./cli-0.5.12-hvtcdcev.mjs";import{bfa as Q,cfa as M}from"./cli-0.5.12-k1crwtdc.mjs";import{Kfa as P,Pfa as I,fga as f,iga as L}from"./cli-0.5.12-p5ps8gf0.mjs";import{Gga as H,zga as w}from"./cli-0.5.12-tfdwzg37.mjs";import{Qma as N,Rma as F}from"./cli-0.5.12-0qasc0ef.mjs";import{Dna as U,lna as X}from"./cli-0.5.12-495d826j.mjs";import{Zna as h,aoa as B}from"./cli-0.5.12-xzeb7mtb.mjs";import{hostname as E}from"os";function $(){return R(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 W(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(Z()){f("[trusted-device] Essential traffic only, skipping enrollment");return}let b=Q().BASE_API_URL,m;try{m=await X.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}: ${P(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(()=>{U();F();M();O();L();H();V();Y();I();y=N(()=>{let i=process.env.CLAUDE_TRUSTED_DEVICE_TOKEN;if(i)return i;return x().read()?.trustedDeviceToken})});
export{u as ER,n as FR,o as GR,t as HR,d as IR};
