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.
screenDiff(formerlyFindNewMessage) incorrectly includes header lines and old content in the diff when used withAgentTypeOpencode.Observed behavior:
When extracting new messages from Opencode agents, the diff includes:
┃ /share ... 15.3K/8% ($0.07) ┃)Expected behavior:
Should return only the new message content, excluding header metadata and previously-seen lines.
Example:
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
screenDifftests useAgentTypeCustom, which doesn't setdynamicHeaderEnd, so the bug path is untested.