MCPcopy
hub / github.com/claude-code-best/claude-code / initBridgeCore

Function initBridgeCore

src/bridge/replBridge.ts:275–1910  ·  view source on GitHub ↗
(
  params: BridgeCoreParams,
)

Source from the content-addressed store, hash-verified

273 * Returns null on registration or session-creation failure.
274 */
275export async function initBridgeCore(
276 params: BridgeCoreParams,
277): Promise<BridgeCoreHandle | null> {
278 const {
279 dir,
280 machineName,
281 branch,
282 gitRepoUrl,
283 title,
284 baseUrl,
285 sessionIngressUrl,
286 workerType,
287 getAccessToken,
288 createSession,
289 archiveSession,
290 getCurrentTitle = () => title,
291 toSDKMessages = () => {
292 throw new Error(
293 'BridgeCoreParams.toSDKMessages not provided. Pass it if you use writeMessages() or initialMessages — daemon callers that only use writeSdkMessages() never hit this path.',
294 )
295 },
296 onAuth401,
297 getPollIntervalConfig = () => DEFAULT_POLL_CONFIG,
298 initialHistoryCap = 200,
299 initialMessages,
300 previouslyFlushedUUIDs,
301 onInboundMessage,
302 onPermissionResponse,
303 onInterrupt,
304 onSetModel,
305 onSetMaxThinkingTokens,
306 onSetPermissionMode,
307 onStateChange,
308 onUserMessage,
309 perpetual,
310 initialSSESequenceNum = 0,
311 } = params
312
313 const seq = ++initSequence
314
315 // bridgePointer import hoisted: perpetual mode reads it before register;
316 // non-perpetual writes it after session create; both use clear at teardown.
317 const { writeBridgePointer, clearBridgePointer, readBridgePointer } =
318 await import('./bridgePointer.js')
319
320 // Perpetual mode: read the crash-recovery pointer and treat it as prior
321 // state. The pointer is written unconditionally after session create
322 // (crash-recovery for all sessions); perpetual mode just skips the
323 // teardown clear so it survives clean exits too. Only reuse 'repl'
324 // pointers — a crashed standalone bridge (`claude remote-control`)
325 // writes source:'standalone' with a different workerType.
326 const rawPrior = perpetual ? await readBridgePointer(dir) : null
327 const prior = rawPrior?.source === 'repl' ? rawPrior : null
328
329 logForDebugging(
330 `[bridge:repl] initBridgeCore #${seq} starting (initialMessages=${initialMessages?.length ?? 0}${prior ? ` perpetual prior=env:${prior.environmentId}` : ''})`,
331 )
332

Callers 1

initReplBridgeFunction · 0.85

Calls 15

addMethod · 0.95
dropMethod · 0.95
deactivateMethod · 0.95
readBridgePointerFunction · 0.85
createBridgeApiClientFunction · 0.85
wrapApiForFaultInjectionFunction · 0.85
logBridgeSkipFunction · 0.85
clearBridgePointerFunction · 0.85
onStateChangeFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
logEventFunction · 0.85
tryReconnectInPlaceFunction · 0.85

Tested by

no test coverage detected