MCPcopy Index your code
hub / github.com/codeaashu/claude-code / writeMessages

Function writeMessages

src/bridge/remoteBridgeCore.ts:767–812  ·  view source on GitHub ↗
(messages)

Source from the content-addressed store, hash-verified

765 environmentId: '',
766 sessionIngressUrl: credentials.api_base_url,
767 writeMessages(messages) {
768 const filtered = messages.filter(
769 m =>
770 isEligibleBridgeMessage(m) &&
771 !initialMessageUUIDs.has(m.uuid) &&
772 !recentPostedUUIDs.has(m.uuid),
773 )
774 if (filtered.length === 0) return
775
776 // Fire onUserMessage for title derivation. Scan before the flushGate
777 // check — prompts are title-worthy even if they queue. Keeps calling
778 // on every title-worthy message until the callback returns true; the
779 // caller owns the policy (derive at 1st and 3rd, skip if explicit).
780 if (!userMessageCallbackDone) {
781 for (const m of filtered) {
782 const text = extractTitleText(m)
783 if (text !== undefined && onUserMessage?.(text, sessionId)) {
784 userMessageCallbackDone = true
785 break
786 }
787 }
788 }
789
790 if (flushGate.enqueue(...filtered)) {
791 logForDebugging(
792 `[remote-bridge] Queued ${filtered.length} message(s) during flush`,
793 )
794 return
795 }
796
797 for (const msg of filtered) recentPostedUUIDs.add(msg.uuid)
798 const events = toSDKMessages(filtered).map(m => ({
799 ...m,
800 session_id: sessionId,
801 }))
802 // v2 does not derive worker_status from events server-side (unlike v1
803 // session-ingress session_status_updater.go). Push it from here so the
804 // CCR web session list shows Running instead of stuck on Idle. A user
805 // message in the batch marks turn start. CCRClient.reportState dedupes
806 // consecutive same-state pushes.
807 if (filtered.some(m => m.type === 'user')) {
808 transport.reportState('running')
809 }
810 logForDebugging(`[remote-bridge] Sending ${filtered.length} message(s)`)
811 void transport.writeBatch(events)
812 },
813 writeSdkMessages(messages: SDKMessage[]) {
814 const filtered = messages.filter(
815 m => !m.uuid || !recentPostedUUIDs.has(m.uuid),

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected