import{n as e}from"./chunk-DR8-3Aex.js";import{l as t,n,s as r,u as i}from"./envUtils-BWeoiL4Y.js";import{i as a,t as o}from"./src-BJz1KAd_.js";import{H as ee,U as s,cn as te,yt as ne}from"./state-sIHsFpDu.js";import{Cc as c,S as l,_ as u,dc as d,yc as f}from"./paths-Ci1iwL5Y.js";import{E as p,K as m,O as re,U as h,l as g,p as _}from"./debug-otxXY3j-.js";import{n as v,t as ie}from"./bundledMode-kSQejuY4.js";import{i as y,o as ae}from"./platform-mh9ypxS8.js";import{n as oe,r as se}from"./execFileNoThrow-azCkYhmF.js";import{n as b,t as x}from"./distRoot-BNg_iO5-.js";import{a as S,c as C,d as w,n as T,r as E,t as D}from"./common-Da57Qwms.js";import{a as O,i as k}from"./prompt-IqfIbvg9.js";import{homedir as A}from"os";import{join as j}from"path";import{chmod as M,mkdir as N,readFile as P,readdir as F,writeFile as I}from"fs/promises";function L(){return process.env.USER_TYPE===`ant`?[B,V,H]:[B]}async function R(e,t){if(e.length===0)return t?.(`[Claude in Chrome] No browser paths to check`),{isInstalled:!1,browser:null};let n=L();for(let{browser:r,path:i}of e){let e=[];try{e=await F(i,{withFileTypes:!0})}catch(e){if(m(e))continue;throw e}let a=e.filter(e=>e.isDirectory()).filter(e=>e.name===`Default`||e.name.startsWith(`Profile `)).map(e=>e.name);a.length>0&&t?.(`[Claude in Chrome] Found ${r} profiles: ${a.join(`, `)}`);for(let e of a)for(let a of n){let n=j(i,e,`Extensions`,a);try{return await F(n),t?.(`[Claude in Chrome] Extension ${a} found in ${r} ${e}`),{isInstalled:!0,browser:r}}catch{}}}return t?.(`[Claude in Chrome] Extension not found in any browser`),{isInstalled:!1,browser:null}}async function z(e,t){return(await R(e,t)).isInstalled}var B,V,H,U=e((()=>{h(),B=`fcoeoabgfenejglbffodgkkbkcdhcgfn`,V=`dihbgbndebgnbjfmelmegjepbnkhlgni`,H=`dngcpimnedloihjnnfngkgjoidhnaolf`}));function W(e){if(s()&&e!==!0)return!1;if(e===!0)return!0;if(e===!1)return!1;if(i(process.env.CLAUDE_CODE_ENABLE_CFC))return!0;if(t(process.env.CLAUDE_CODE_ENABLE_CFC))return!1;let n=d();return n.claudeInChromeDefaultEnabled===void 0?!1:n.claudeInChromeDefaultEnabled}function G(){return $===void 0&&($=ee()&&ue()&&(process.env.USER_TYPE===`ant`||u(`tengu_chrome_auto_enable`,!1))),$}function K(){let e=v(),t=a.map(e=>`mcp__claude-in-chrome__${e.name}`),n={};ne()&&(n.CLAUDE_CHROME_PERMISSION_MODE=`skip_all_permission_checks`);let r=Object.keys(n).length>0;if(e)return J(`"${process.execPath}" --chrome-native-host`).then(e=>q(e)).catch(e=>_(`[Claude in Chrome] Failed to install native host: ${e}`,{level:`error`})),{mcpConfig:{[D]:{type:`stdio`,command:process.execPath,args:[`--claude-in-chrome-mcp`],scope:`dynamic`,...r&&{env:n}}},allowedTools:t,systemPrompt:k()};{let e=j(x,`cli.js`);return J(`"${process.execPath}" "${e}" --chrome-native-host`).then(e=>q(e)).catch(e=>_(`[Claude in Chrome] Failed to install native host: ${e}`,{level:`error`})),{mcpConfig:{[D]:{type:`stdio`,command:process.execPath,args:[`${e}`,`--claude-in-chrome-mcp`],scope:`dynamic`,...r&&{env:n}}},allowedTools:t,systemPrompt:k()}}}function ce(){if(y()===`windows`){let e=A();return[j(process.env.APPDATA||j(e,`AppData`,`Local`),`Claude Code`,`ChromeNativeHost`)]}return E().map(({path:e})=>e)}async function q(e){let t=ce();if(t.length===0)throw Error(`Claude in Chrome Native Host not supported on this platform`);let n=re({name:Z,description:`Claude Code Browser Extension Native Host`,path:e,type:`stdio`,allowed_origins:[`chrome-extension://fcoeoabgfenejglbffodgkkbkcdhcgfn/`,...process.env.USER_TYPE===`ant`?[`chrome-extension://dihbgbndebgnbjfmelmegjepbnkhlgni/`,`chrome-extension://dngcpimnedloihjnnfngkgjoidhnaolf/`]:[]]},null,2),r=!1;for(let e of t){let t=j(e,Q);if(await P(t,`utf-8`).catch(()=>null)!==n)try{await N(e,{recursive:!0}),await I(t,n),_(`[Claude in Chrome] Installed native host manifest at: ${t}`),r=!0}catch(e){_(`[Claude in Chrome] Failed to install manifest at ${t}: ${e}`)}}y()===`windows`&&le(j(t[0],Q)),r&&Y().then(e=>{e?(_(`[Claude in Chrome] First-time install detected, opening reconnect page in browser`),w(X)):_(`[Claude in Chrome] First-time install detected, but extension not installed, skipping reconnect`)})}function le(e){let t=S();for(let{browser:n,key:r}of t){let t=`${r}\\${Z}`;oe(`reg`,[`add`,t,`/ve`,`/t`,`REG_SZ`,`/d`,e,`/f`]).then(e=>{e.code===0?_(`[Claude in Chrome] Registered native host for ${n} in Windows registry: ${t}`):_(`[Claude in Chrome] Failed to register native host for ${n} in Windows registry: ${e.stderr}`)})}}async function J(e){let t=y(),r=j(n(),`chrome`),i=t===`windows`?j(r,`chrome-native-host.bat`):j(r,`chrome-native-host`),a=t===`windows`?`@echo off
REM Chrome native host wrapper script
REM Generated by Claude Code - do not edit manually
${e}
`:`#!/bin/sh
# Chrome native host wrapper script
# Generated by Claude Code - do not edit manually
exec ${e}
`;return await P(i,`utf-8`).catch(()=>null)===a?i:(await N(r,{recursive:!0}),await I(i,a),t!==`windows`&&await M(i,493),_(`[Claude in Chrome] Created Chrome native host wrapper script: ${i}`),i)}function ue(){return Y().then(e=>{e&&d().cachedChromeExtensionInstalled!==e&&c(t=>({...t,cachedChromeExtensionInstalled:e}))}),d().cachedChromeExtensionInstalled??!1}async function Y(){let e=T();return e.length===0?(_(`[Claude in Chrome] Unsupported platform for extension detection: ${y()}`),!1):z(e,_)}var X,Z,Q,$,de=e((()=>{o(),te(),l(),ie(),b(),f(),g(),r(),se(),ae(),p(),C(),O(),U(),X=`https://clau.de/chrome/reconnect`,Z=`com.anthropic.claude_code_browser_extension`,Q=`${Z}.json`}));export{W as a,G as i,Y as n,K as r,de as t};