Skip to content

Plugin transcript parser drops every line after the first in multi-line messages #1184

Description

@abhay-codes07

Summary

parseTranscriptMessages in apps/web/lib/plugin-document.ts builds its message-splitting regex with the m flag, and the terminating lookahead ends with |$:

const regex = new RegExp(
	`^\\s*(\\d+)\\.\\s+\\[(${TRANSCRIPT_ROLE_PATTERN})\\]\\s*([\\s\\S]*?)(?=^\\s*\\d+\\.\\s+\\[(?:${TRANSCRIPT_ROLE_PATTERN})\\]\\s*|$)`,
	"gm",
)

With m, $ matches at every line end, not just end of input, so the lazy ([\s\S]*?) body — clearly written to span lines — stops at the first newline. Every line of a message after the first is silently dropped.

Reproduction

const content = [
	"1. [user] Hello there",
	"Here is more context on line two",
	"memory id: mem_123",
	"2. [assistant] Sure!",
	"Second line of the reply",
].join("\n")

Actual parsed messages: "Hello there" and "Sure!". The continuation lines appear in no message.

Impact

  • Codex session and Amp thread documents (parseSessionTranscript) render truncated conversations in the document modal — only the first line of each turn survives.
  • memory id: ... lines inside a message body are dropped instead of being surfaced as artifacts by extractArtifacts, so the Memory ID chip never shows for multi-line turns.
  • Session previews and user/assistant message counts are computed from truncated text.

This is amplified by normalizeContent, which converts literal \n escapes into real newlines before parsing — so multi-line bodies are the norm for these payloads, not the edge case.

Expected behavior

Message bodies should span lines until the next N. [role] header or the true end of input. The last message in a transcript should keep all of its lines.

Suggested fix

Replace the |$ alternative in the lookahead with a real end-of-input assertion that isn't affected by the m flag: |(?![\s\S]). One-line change; the adjacent parseClaudeCodeTurns regex is unaffected (it uses $ without the m flag, where it already means end of input).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions