TUI plugins cannot read the currently selected model/agent (only the last-sent server session value) · Issue #50315 · anomalyco/opencode · GitHub
Skip to content

TUI plugins cannot read the currently selected model/agent (only the last-sent server session value) #50315

Open

Description

@HaydarDK2024

Problem

A TUI plugin cannot display the model/agent currently selected in the prompt before the next message is sent.

  • TuiPluginApi.state exposes session, part, lsp, mcp, provider, config, path, vcs — no model/agent (packages/plugin/src/tui.ts, TuiState).
  • state.session.get(id).model is the server session value: it is updated only when a prompt is sent (the model is sent with session.prompt, and session.update is only used for title/archive).
  • The selected model/agent lives in the private Solid Local store in packages/tui/src/context/local.tsx. cycle() / set() only write that store; save() persists recent / favorite / variant to model.json but not the active model map.

Result: a status-line plugin that reads session.model (the only model value reachable from the plugin API) shows a stale value — it does not change on f2/tab model cycling, only after the next prompt is sent. The built-in prompt line does update live.

Reproduced on 1.18.31: cycling with f2 changes the built-in prompt line (· <model> <provider> · <variant>) but state.session.get(id).model stays on the previous value, and ~/.local/state/opencode/model.json never contains the active selection.

Ask

Expose the effective (pending) model / agent / variant through TuiState (or provide a change event on cycle/set), so TUI plugins can render an accurate status line without duplicating the built-in one inaccurately.

If a change event is preferred over a getter, something like tui.model.changed / tui.agent.changed would be enough.

Activity

  1. holny commented on Sep 23, 2026

    @holny
    Contributor

    I'll take this. The fix is to extend TuiPluginApi.state (packages/plugin/src/tui.ts) so a status-line plugin can read the live selected model/agent that the prompt input actually has on screen. The current gap is that state.session.get(id).model only mirrors the server-side value (set on the next session.prompt), and the in-memory selection lives in the private Solid store at packages/tui/src/context/local.tsx. The save() side already persists recent / favorite / variant to model.json — adding the active selection to that same payload keeps it consistent.

    Plan: thread the active selection through the Solid Local store, surface it as a reactive read on the plugin state, and persist it alongside the recent/favorite set so refreshes can rebuild it. Cover with a TUI test that flips the model via the prompt and asserts the plugin sees the new value before the next prompt is sent.

    Fixes #50315

  2. added a commit that references this issue on Sep 27, 2026
    988fbd8
  3. added a commit that references this issue on Oct 21, 2026
    77c0dab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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