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

Function extractUserMessageText

source code/bridge/sessionRunner.ts:209–236  ·  view source on GitHub ↗

* Extract plain text from a replayed SDKUserMessage NDJSON line. Returns the * trimmed text if this looks like a real human-authored message, otherwise * undefined so the caller keeps waiting for the first real message.

(
  msg: Record<string, unknown>,
)

Source from the content-addressed store, hash-verified

207 * undefined so the caller keeps waiting for the first real message.
208 */
209function extractUserMessageText(
210 msg: Record<string, unknown>,
211): string | undefined {
212 // Skip tool-result user messages (wrapped subagent results) and synthetic
213 // caveat messages — neither is human-authored.
214 if (msg.parent_tool_use_id != null || msg.isSynthetic || msg.isReplay)
215 return undefined
216
217 const message = msg.message as Record<string, unknown> | undefined
218 const content = message?.content
219 let text: string | undefined
220 if (typeof content === 'string') {
221 text = content
222 } else if (Array.isArray(content)) {
223 for (const block of content) {
224 if (
225 block &&
226 typeof block === 'object' &&
227 (block as Record<string, unknown>).type === 'text'
228 ) {
229 text = (block as Record<string, unknown>).text as string | undefined
230 break
231 }
232 }
233 }
234 text = text?.trim()
235 return text ? text : undefined
236}
237
238/** Build a short preview of tool input for debug logging. */
239function inputPreview(input: Record<string, unknown>): string {

Callers 1

spawnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected