MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / flushHistory

Function flushHistory

source code/bridge/remoteBridgeCore.ts:626–658  ·  view source on GitHub ↗
(msgs: Message[])

Source from the content-addressed store, hash-verified

624 }
625
626 async function flushHistory(msgs: Message[]): Promise<void> {
627 // v2 always creates a fresh server session (unconditional createCodeSession
628 // above) — no session reuse, no double-post risk. Unlike v1, we do NOT
629 // filter by previouslyFlushedUUIDs: that set persists across REPL enable/
630 // disable cycles (useRef), so it would wrongly suppress history on re-enable.
631 const eligible = msgs.filter(isEligibleBridgeMessage)
632 const capped =
633 initialHistoryCap > 0 && eligible.length > initialHistoryCap
634 ? eligible.slice(-initialHistoryCap)
635 : eligible
636 if (capped.length < eligible.length) {
637 logForDebugging(
638 `[remote-bridge] Capped initial flush: ${eligible.length} -> ${capped.length} (cap=${initialHistoryCap})`,
639 )
640 }
641 const events = toSDKMessages(capped).map(m => ({
642 ...m,
643 session_id: sessionId,
644 }))
645 if (events.length === 0) return
646 // Mid-turn init: if Remote Control is enabled while a query is running,
647 // the last eligible message is a user prompt or tool_result (both 'user'
648 // type). Without this the init PUT's 'idle' sticks until the next user-
649 // type message forwards via writeMessages — which for a pure-text turn
650 // is never (only assistant chunks stream post-init). Check eligible (pre-
651 // cap), not capped: the cap may truncate to a user message even when the
652 // actual trailing message is assistant.
653 if (eligible.at(-1)?.type === 'user') {
654 transport.reportState('running')
655 }
656 logForDebugging(`[remote-bridge] Flushing ${events.length} history events`)
657 await transport.writeBatch(events)
658 }
659
660 // ── 9. Teardown ───────────────────────────────────────────────────────────
661 // On SIGINT/SIGTERM/⁠/exit, gracefulShutdown races runCleanupFunctions()

Callers 1

wireTransportCallbacksFunction · 0.85

Calls 4

logForDebuggingFunction · 0.85
toSDKMessagesFunction · 0.85
reportStateMethod · 0.80
writeBatchMethod · 0.80

Tested by

no test coverage detected