MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / initReplBridge

Function initReplBridge

src/bridge/initReplBridge.ts:112–550  ·  view source on GitHub ↗
(
  options?: InitBridgeOptions,
)

Source from the content-addressed store, hash-verified

110}
111
112export async function initReplBridge(
113 options?: InitBridgeOptions,
114): Promise<ReplBridgeHandle | null> {
115 const {
116 onInboundMessage,
117 onPermissionResponse,
118 onInterrupt,
119 onSetModel,
120 onSetMaxThinkingTokens,
121 onSetPermissionMode,
122 onStateChange,
123 initialMessages,
124 getMessages,
125 previouslyFlushedUUIDs,
126 initialName,
127 perpetual,
128 outboundOnly,
129 tags,
130 } = options ?? {}
131
132 // Wire the cse_ shim kill switch so toCompatSessionId respects the
133 // GrowthBook gate. Daemon/SDK paths skip this — shim defaults to active.
134 setCseShimGate(isCseShimEnabled)
135
136 // 1. Runtime gate
137 if (!(await isBridgeEnabledBlocking())) {
138 logBridgeSkip('not_enabled', '[bridge:repl] Skipping: bridge not enabled')
139 return null
140 }
141
142 // 1b. Minimum version check — deferred to after the v1/v2 branch below,
143 // since each implementation has its own floor (tengu_bridge_min_version
144 // for v1, tengu_bridge_repl_v2_config.min_version for v2).
145
146 // 2. Check OAuth — must be signed in with claude.ai. Runs before the
147 // policy check so console-auth users get the actionable "/login" hint
148 // instead of a misleading policy error from a stale/wrong-org cache.
149 if (!getBridgeAccessToken()) {
150 logBridgeSkip('no_oauth', '[bridge:repl] Skipping: no OAuth tokens')
151 onStateChange?.('failed', '/login')
152 return null
153 }
154
155 // 3. Check organization policy — remote control may be disabled
156 await waitForPolicyLimitsToLoad()
157 if (!isPolicyAllowed('allow_remote_control')) {
158 logBridgeSkip(
159 'policy_denied',
160 '[bridge:repl] Skipping: allow_remote_control policy not allowed',
161 )
162 onStateChange?.('failed', "disabled by your organization's policy")
163 return null
164 }
165
166 // When CLAUDE_BRIDGE_OAUTH_TOKEN is set (ant-only local dev), the bridge
167 // uses that token directly via getBridgeAccessToken() — keychain state is
168 // irrelevant. Skip 2b/2c to preserve that decoupling: an expired keychain
169 // token shouldn't block a bridge connection that doesn't use it.

Callers 2

runHeadlessStreamingFunction · 0.85
useReplBridgeFunction · 0.85

Calls 15

setCseShimGateFunction · 0.85
isBridgeEnabledBlockingFunction · 0.85
logBridgeSkipFunction · 0.85
getBridgeAccessTokenFunction · 0.85
onStateChangeFunction · 0.85
isPolicyAllowedFunction · 0.85
getBridgeTokenOverrideFunction · 0.85
getGlobalConfigFunction · 0.85
saveGlobalConfigFunction · 0.85
generateShortWordSlugFunction · 0.85

Tested by

no test coverage detected