Skip to content

screenDiff returns wrong content for AgentTypeOpencode #174

@mafredri

Description

@mafredri

screenDiff (formerly FindNewMessage) incorrectly includes header lines and old content in the diff when used with AgentTypeOpencode.

Observed behavior:
When extracting new messages from Opencode agents, the diff includes:

  • Dynamic header lines with token counts/costs (┃ /share ... 15.3K/8% ($0.07) ┃)
  • Old content that appeared in the previous screen
  • Only partial new content

Expected behavior:
Should return only the new message content, excluding header metadata and previously-seen lines.

Example:

oldScreen := `┃ Header 12.6K/6% ($0.05) ┃
old line A
old line B`

newScreen := `┃ Header 15.3K/8% ($0.07) ┃
old line A
old line B
new message`

// Currently returns: "┃ Header 15.3K/8% ($0.07) ┃\nold line A\nold line B\nnew message"
// Should return: "new message"

Impact:
Opencode users see garbled responses with header metadata mixed into agent messages.

Probable cause:
The logic that skips the first two header lines (when dynamicHeaderEnd=2) uses a sliced array in the loop. The index variable is relative to the slice, not the original array, causing an off-by-one error.

Test coverage gap:
All existing screenDiff tests use AgentTypeCustom, which doesn't set dynamicHeaderEnd, so the bug path is untested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions