Attachments are not rendered correctly when cycling through prev prompts #2151

Closed
opened 2026-02-16 17:34:25 -05:00 by yindo · 2 comments
Owner

Originally created by @geril07 on GitHub (Oct 17, 2025).

[[message_history]]
  text = "xxx\n@README.md"

  [[message_history.attachments]]
    id = "0b652571-982a-4fe9-a526-267141f2ed38"
    type = "file"
    display = "@README.md"
    url = "file:///home/geril/code/oss/opencode/README.md"
    filename = "README.md"
    media_type = "text/plain"
    start_index = 4
    end_index = 14
    [message_history.attachments.source]
      path = "/home/geril/code/oss/opencode/README.md"
      mime = "text/plain"

What was typed as a prompt:

xxx
@README.md

Attachment from toml is correct there, but note, start_index and end_index are ABSOLUTE indexes.

Let's look at this piece of code of RestoreFromPrompt which is called when cycling through previous prompts

https://github.com/sst/opencode/blob/335d83365521728181248b13a55386a10ae41ef0/packages/tui/internal/components/chat/editor.go#L801-L805

It calls ReplaceRange with the absolute ranges

However, what we see in ReplaceRange function:

https://github.com/sst/opencode/blob/335d83365521728181248b13a55386a10ae41ef0/packages/tui/internal/components/textarea/textarea.go#L695-L723

It works with the current row, but the indexes passed into it are absolute ones(at least from RestoreFromPrompt fn)

And this is how it looks like when cycling previous prompts:

Image

Seems logical, absolute start_index 4 was used as a "col index", and therefore @REA is there

And also something affects a session message, but it's not related to the explained thing ig:

Image

should we wait until opentui?)

Originally created by @geril07 on GitHub (Oct 17, 2025). ```toml [[message_history]] text = "xxx\n@README.md" [[message_history.attachments]] id = "0b652571-982a-4fe9-a526-267141f2ed38" type = "file" display = "@README.md" url = "file:///home/geril/code/oss/opencode/README.md" filename = "README.md" media_type = "text/plain" start_index = 4 end_index = 14 [message_history.attachments.source] path = "/home/geril/code/oss/opencode/README.md" mime = "text/plain" ``` What was typed as a prompt: ``` xxx @README.md ``` Attachment from toml is correct there, but note, `start_index` and `end_index` are ABSOLUTE indexes. Let's look at this piece of code of `RestoreFromPrompt` which is called when cycling through previous prompts https://github.com/sst/opencode/blob/335d83365521728181248b13a55386a10ae41ef0/packages/tui/internal/components/chat/editor.go#L801-L805 It calls `ReplaceRange` with the absolute ranges However, what we see in `ReplaceRange` function: https://github.com/sst/opencode/blob/335d83365521728181248b13a55386a10ae41ef0/packages/tui/internal/components/textarea/textarea.go#L695-L723 It works with the current row, but the indexes passed into it are absolute ones(at least from `RestoreFromPrompt` fn) And this is how it looks like when cycling previous prompts: <img width="1010" height="240" alt="Image" src="https://github.com/user-attachments/assets/2b9d75fc-ed51-4cf7-8b15-7bb6fda43313" /> Seems logical, absolute `start_index` 4 was used as a "col index", and therefore `@REA` is there And also something affects a session message, but it's not related to the explained thing ig: <img width="1876" height="230" alt="Image" src="https://github.com/user-attachments/assets/999baaa2-f76e-4a88-8a4b-5c0a63c02ade" /> should we wait until opentui?)
yindo closed this issue 2026-02-16 17:34:25 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 17, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #1266: Both issues describe attachment corruption when cycling through prompt history, caused by the same RestoreFromHistory/RestoreFromPrompt functions using absolute indices incorrectly with ReplaceRange

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 17, 2025): This issue might be a duplicate of existing issues. Please check: - #1266: Both issues describe attachment corruption when cycling through prompt history, caused by the same RestoreFromHistory/RestoreFromPrompt functions using absolute indices incorrectly with ReplaceRange Feel free to ignore if none of these address your specific case.
Author
Owner

@geril07 commented on GitHub (Oct 17, 2025):

This issue might be a duplicate of existing issues.

This issue is not a duplicate, it's a DUPLICATE DUPLICATE
sorry about that 😄

@geril07 commented on GitHub (Oct 17, 2025): > This issue might be a duplicate of existing issues. This issue is not a duplicate, it's a DUPLICATE DUPLICATE sorry about that :smile:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2151