Skip to content

Validate markdown table separators before buffering in stream handler#91

Merged
nmaguiar merged 4 commits intousestreamfrom
copilot/sub-pr-89-again
Jan 26, 2026
Merged

Validate markdown table separators before buffering in stream handler#91
nmaguiar merged 4 commits intousestreamfrom
copilot/sub-pr-89-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 26, 2026

The stream handler buffered any line starting with | as table content, delaying output of non-table content and degrading UX during streaming.

Changes:

  • Table separator validation: Added regex pattern to verify markdown table separator lines (e.g., | --- | :---: | ---: |) before treating content as a table
  • Two-line lookahead: Buffer first |-prefixed line, verify second line is a valid separator, then continue buffering or flush as non-table content
  • State tracking: Introduced tableHeaderSeen flag to distinguish validated tables from false positives
// Before: any line starting with | was buffered
if (trimmedLine.indexOf("|") === 0) {
    tableBuffer += line + "\n"
    continue
}

// After: validate separator exists before buffering
var TABLE_SEPARATOR_REGEX = /^\s*\|(\s*:?-+:?\s*\|)+\s*$/
if (trimmedLine.indexOf("|") === 0) {
    var isSeparator = TABLE_SEPARATOR_REGEX.test(trimmedLine)
    if (!inTable) {
        // Buffer first line, wait for separator confirmation
        tableBuffer = line + "\n"
        tableHeaderSeen = false
        continue
    }
    if (!tableHeaderSeen && !isSeparator) {
        // Second line not a separator - flush as regular content
        flushContent(tableBuffer)
        flushContent(line + "\n")
        // ...reset state
    }
}

This prevents buffering of shell output, log lines, or other content that happens to start with | while preserving correct table rendering.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits January 26, 2026 00:35
Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
Co-authored-by: nmaguiar <11761746+nmaguiar@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP Address feedback on usestream functionality implementation Validate markdown table separators before buffering in stream handler Jan 26, 2026
Copilot AI requested a review from nmaguiar January 26, 2026 00:42
@nmaguiar nmaguiar marked this pull request as ready for review January 26, 2026 00:47
@nmaguiar nmaguiar merged commit 419edad into usestream Jan 26, 2026
@nmaguiar nmaguiar deleted the copilot/sub-pr-89-again branch January 26, 2026 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants