MCPcopy
hub / github.com/codeaashu/claude-code / runBridgeHeadless

Function runBridgeHeadless

src/bridge/bridgeMain.ts:2810–2965  ·  view source on GitHub ↗
(
  opts: HeadlessBridgeOpts,
  signal: AbortSignal,
)

Source from the content-addressed store, hash-verified

2808 * Resolves cleanly when `signal` aborts and the poll loop tears down.
2809 */
2810export async function runBridgeHeadless(
2811 opts: HeadlessBridgeOpts,
2812 signal: AbortSignal,
2813): Promise<void> {
2814 const { dir, log } = opts
2815
2816 // Worker inherits the supervisor's CWD. chdir first so git utilities
2817 // (getBranch/getRemoteUrl) — which read from bootstrap CWD state set
2818 // below — resolve against the right repo.
2819 process.chdir(dir)
2820 const { setOriginalCwd, setCwdState } = await import('../bootstrap/state.js')
2821 setOriginalCwd(dir)
2822 setCwdState(dir)
2823
2824 const { enableConfigs, checkHasTrustDialogAccepted } = await import(
2825 '../utils/config.js'
2826 )
2827 enableConfigs()
2828 const { initSinks } = await import('../utils/sinks.js')
2829 initSinks()
2830
2831 if (!checkHasTrustDialogAccepted()) {
2832 throw new BridgeHeadlessPermanentError(
2833 `Workspace not trusted: ${dir}. Run \`claude\` in that directory first to accept the trust dialog.`,
2834 )
2835 }
2836
2837 if (!opts.getAccessToken()) {
2838 // Transient — supervisor's AuthManager may pick up a token on next cycle.
2839 throw new Error(BRIDGE_LOGIN_ERROR)
2840 }
2841
2842 const { getBridgeBaseUrl } = await import('./bridgeConfig.js')
2843 const baseUrl = getBridgeBaseUrl()
2844 if (
2845 baseUrl.startsWith('http://') &&
2846 !baseUrl.includes('localhost') &&
2847 !baseUrl.includes('127.0.0.1')
2848 ) {
2849 throw new BridgeHeadlessPermanentError(
2850 'Remote Control base URL uses HTTP. Only HTTPS or localhost HTTP is allowed.',
2851 )
2852 }
2853 const sessionIngressUrl =
2854 process.env.USER_TYPE === 'ant' &&
2855 process.env.CLAUDE_BRIDGE_SESSION_INGRESS_URL
2856 ? process.env.CLAUDE_BRIDGE_SESSION_INGRESS_URL
2857 : baseUrl
2858
2859 const { getBranch, getRemoteUrl, findGitRoot } = await import(
2860 '../utils/git.js'
2861 )
2862 const { hasWorktreeCreateHook } = await import('../utils/hooks.js')
2863
2864 if (opts.spawnMode === 'worktree') {
2865 const worktreeAvailable =
2866 hasWorktreeCreateHook() || findGitRoot(dir) !== null
2867 if (!worktreeAvailable) {

Callers

nothing calls this directly

Calls 15

setOriginalCwdFunction · 0.85
setCwdStateFunction · 0.85
enableConfigsFunction · 0.85
initSinksFunction · 0.85
hasWorktreeCreateHookFunction · 0.85
getBranchFunction · 0.85
getRemoteUrlFunction · 0.85
createBridgeApiClientFunction · 0.85
createSessionSpawnerFunction · 0.85
spawnScriptArgsFunction · 0.85

Tested by

no test coverage detected