Skip to content

fix/fill input#453

Merged
sudo-tee merged 2 commits into
sudo-tee:mainfrom
phanen:fix/fill-input
Jul 10, 2026
Merged

fix/fill input#453
sudo-tee merged 2 commits into
sudo-tee:mainfrom
phanen:fix/fill-input

Conversation

@phanen

@phanen phanen commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
  • feat(session): refill prompt input after /undo
  • refactor(history): derive prompt history from active session messages

Not sure why all prompt history is stored in ~/.local/share/nvim/opencode/history.txt.

Ideally different session should have separate prompt history.

Maybe history can be deprecated in favor of timeline picker?

@sudo-tee

sudo-tee commented Jul 8, 2026

Copy link
Copy Markdown
Owner

@phanen

The history file was a remnant from the original repo this one was forked from (goose.nvim)

But just scope it from the session would limit what you can do with it.

Sometimes I start new sessions but want to send a prompt I already sent in another.

But they should be scoped per project at least.

@phanen

phanen commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

But they should be scoped per project at least.

This pr currently make history picker per-session since it's just wrapper on timeline picker. Maybe we can have a action for history to toggle session/project/...

Also maybe each session should have persistent draft message if tui support this (i don't often use tui so i'm not sure)

@sudo-tee

sudo-tee commented Jul 9, 2026

Copy link
Copy Markdown
Owner

@phanen

Can we split the 2 things that this PR addresses ?

I really like the /undo fix.

But for the history I would need to play with it and think about what is the best solution.

Because opencode tui does the same history navigation as we do with arrows in the input. and it does not scope it per session either. The history picker in this plugin was just a view on the message history the user sent over time.

@phanen phanen mentioned this pull request Jul 9, 2026
@phanen phanen force-pushed the fix/fill-input branch 2 times, most recently from 6b6bb2b to 61afeec Compare July 9, 2026 16:29
@phanen

phanen commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Found another bug... /undo say "No user message to undo" but it actually have.

msg is often truncated from the end

if lazy_limit and #visible_messages > lazy_limit then
visible_messages = vim.list_slice(visible_messages, #visible_messages - lazy_limit + 1)
end

local function get_visible_session_messages(messages)
local real_messages = get_real_session_messages(messages)
local revert_index = get_revert_index(messages)
if revert_index then
real_messages = vim.list_slice(real_messages, 1, revert_index - 1)
end
local limit = get_max_rendered_messages()
if not limit or #real_messages <= limit then
return real_messages, 0
end
local start_index = #real_messages - limit + 1
return vim.list_slice(real_messages, start_index, #real_messages), start_index - 1
end

set_last_user_message is only called in on_message_updated (only on truncated messages)

if hidden_count > 0 then
local hidden_notice = build_hidden_messages_notice(hidden_count)
events.on_message_updated(hidden_notice)

and only when role is user
if msg.info.role == 'user' then
state.renderer.set_last_user_message(msg)

but a canceled user messages sequence can be:

user -> assistant (tool call 1) -> assistant (tool call 2) -> ...

so when there's many tool call, truncated msg won't contain user msg -> last_user_message will be never set.

so sometimes /undo cannot found last_user_message (usually reproduce on startup or when use max_messages, and haven't load_all_message/load_more_message).

@phanen

phanen commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

on_message_updated seems correct to call set_last_user_message when it's call from opencode event. But it have have side effect on render job... so _render_full_session_data lazily use it... but set_last_user_message is check/updated on every message.

Not sure if it's proper to add another set_last_user_message here... or make anther version of on_message_updated without side effect.. i'll think about it later.

EDIT: llm suggest a another option to remove set_last_user_message totally and get last userr msg from store.messages when require..

Problem: /undo sent the revert to the server but left the input
buffer empty, forcing the user to retype the prompt to tweak it.

Solution: capture the target message before reverting and refill the
input buffer from its parts once the server acknowledges.
…evert

Problem: state.last_user_message was a stored cursor that callers had
to keep in sync from multiple sites, drifting whenever a path forgot to
update it.

Solution: drop the stored cursor and compute the next /undo target
inline from state.messages + server.revert.
@phanen

phanen commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

EDIT: llm suggest a another option to remove set_last_user_message totally and get last userr msg from store.messages when require..

I finally choose this direction since it feels proper and easy to go...

@phanen phanen marked this pull request as ready for review July 10, 2026 11:31
@sudo-tee

Copy link
Copy Markdown
Owner

Since we can restore running sessions, and the output is sliced, it might be a good isea to reconstruct from the messages instead set_last_user_messsage. it's worth a try at least

@sudo-tee

Copy link
Copy Markdown
Owner

Looks good to me.

Thanks for the PR

@sudo-tee sudo-tee merged commit 3f1baf4 into sudo-tee:main Jul 10, 2026
5 checks passed
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