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

Function writeMessages

source code/bridge/replBridge.ts:1696–1758  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

1694 },
1695 sessionIngressUrl,
1696 writeMessages(messages) {
1697 // Filter to user/assistant messages that haven't already been sent.
1698 // Two layers of dedup:
1699 // - initialMessageUUIDs: messages sent as session creation events
1700 // - recentPostedUUIDs: messages recently sent via POST
1701 const filtered = messages.filter(
1702 m =>
1703 isEligibleBridgeMessage(m) &&
1704 !initialMessageUUIDs.has(m.uuid) &&
1705 !recentPostedUUIDs.has(m.uuid),
1706 )
1707 if (filtered.length === 0) return
1708
1709 // Fire onUserMessage for title derivation. Scan before the flushGate
1710 // check — prompts are title-worthy even if they queue behind the
1711 // initial history flush. Keeps calling on every title-worthy message
1712 // until the callback returns true; the caller owns the policy.
1713 if (!userMessageCallbackDone) {
1714 for (const m of filtered) {
1715 const text = extractTitleText(m)
1716 if (text !== undefined && onUserMessage?.(text, currentSessionId)) {
1717 userMessageCallbackDone = true
1718 break
1719 }
1720 }
1721 }
1722
1723 // Queue messages while the initial flush is in progress to prevent
1724 // them from arriving at the server interleaved with history.
1725 if (flushGate.enqueue(...filtered)) {
1726 logForDebugging(
1727 `[bridge:repl] Queued ${filtered.length} message(s) during initial flush`,
1728 )
1729 return
1730 }
1731
1732 if (!transport) {
1733 const types = filtered.map(m => m.type).join(',')
1734 logForDebugging(
1735 `[bridge:repl] Transport not configured, dropping ${filtered.length} message(s) [${types}] for session=${currentSessionId}`,
1736 { level: 'warn' },
1737 )
1738 return
1739 }
1740
1741 // Track in the bounded ring buffer for echo filtering and dedup.
1742 for (const msg of filtered) {
1743 recentPostedUUIDs.add(msg.uuid)
1744 }
1745
1746 logForDebugging(
1747 `[bridge:repl] Sending ${filtered.length} message(s) via transport`,
1748 )
1749
1750 // Convert to SDK format and send via HTTP POST (HybridTransport).
1751 // The web UI receives them via the subscribe WebSocket.
1752 const sdkMessages = toSDKMessages(filtered)
1753 const events = sdkMessages.map(sdkMsg => ({

Callers

nothing calls this directly

Calls 9

isEligibleBridgeMessageFunction · 0.85
extractTitleTextFunction · 0.85
onUserMessageFunction · 0.85
logForDebuggingFunction · 0.85
toSDKMessagesFunction · 0.85
writeBatchMethod · 0.80
hasMethod · 0.45
enqueueMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected