-
-
Notifications
You must be signed in to change notification settings - Fork 73
feat(sessions): select session #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(sessions): select session #139
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds functionality to select and switch between existing OpenCode sessions through the UI.
Changes:
- Adds a new
select_sessionUI component that fetches and displays sessions - Integrates session selection into the command menu
- Adds API client methods for retrieving and selecting sessions
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lua/opencode/ui/select_session.lua | New module implementing session selection UI with sorting and formatting |
| lua/opencode/ui/select.lua | Adds special handling for the "session.select" command |
| lua/opencode/config.lua | Registers "session.select" in the commands configuration |
| lua/opencode/cli/client.lua | Adds get_sessions and select_session API methods |
| lua/opencode.lua | Exports the select_session function in the main module |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey @NickvanDyke! What do you think about this? Any suggestions? |
|
Sorry just been busy! LGTM, thanks for slotting it in so nicely to the surrounding code + patterns! I'm generally trying to avoid re-implementing TUI features to keep the plugin simple and reliable for both me and users. I'll accept this because the implementation is good and simple, and hopefully |
lua/opencode/ui/select_session.lua
Outdated
| for _, session in ipairs(session_data.sessions) do | ||
| ---@type opencode.cli.client.Session | ||
| local item = { | ||
| id = session.id, | ||
| title = session.title, | ||
| time = { | ||
| created_ms = math.floor(session.time.created), | ||
| updated_ms = math.floor(session.time.updated), | ||
| }, | ||
| } | ||
| table.insert(sessions, item) | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this mapping happen in client#get_sessions? I could be misunderstanding but its return type seems a bit misleading right now. It claims to return session.time.created_ms/updated_ms, but I see here - outside it - that we're mapping its session.time.created/updated to those fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept client#get_sessions in the same spirit as the other functions in that file, ie thin wrappers over the curl call. Here session.time.created and session.time.updated are data from opencode, so in milliseconds. We assign them to our _ms versions which are more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, but the callback passes opencode's data, but is typed as though it passes the _ms versions.
I'm okay to just use the opencode data directly too. We can remove the _ms suffix and just add it as a docstring comment on the field instead. Then no mapping necessary. Unless the math.floor is important?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a change, is that what you're thinking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember correctly I used math.floor to convert them to int so not to depend on coercion. But can do that at location of division as well if it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's in the right direction! I guess I don't understand what this loop is doing? session_data.sessions is already opencode.cli.client.Session[]. So I don't understand the need for the loop that maps each element to a opencode.cli.client.Session and adds it to sessions. It seems to me we could just use session_data.sessions directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it doesn't make sense now. It stayed as part of my previous thinking of mapping to a local type. Fixed, but doing some manual testing.
|
The plugin's first priority is enabling functionality that's not possible in the TUI. Supplementing your editor workflow with AI, rather than replace it. Like injecting editor context. Neovim implementations of TUI features are nice, but it's impossible for me to keep up with Maintenance aside, I also want to keep things simple for users. Sometimes less is more. Maybe this is just me, but I found it overwhelming to try so many new AI tools. They all have their own way to do things. With Obviously there are exceptions. Like This is my experience in open source thus far, at least 🙂 I would love to create the best editor experience possible (in Neovim and others), but it's only realistic as a paid member of the |
Yeah, totally makes sense. How's your current workflow when something like the above happens? Do you ctrl-w to the opencode split and make the selection then go back to editing? |
I don't think I'm on the |
I'm also curious about the opencode devs' workflow since they use vim. |
|
Interesting, I didn't know that! While they've nicely supported the APIs this plugin needs, they haven't interacted with it much otherwise. So I guess they prefer to use |
|
Code looks and functions well! Tyvm for the discussion and iteration 🙂 ❤️ |

Re: #123. One way to check this out is to open the main select dialogue and pick the select session command.