Skip to content

fix(webui): persist Terminal/Chat/Program view selection per session#620

Merged
edwin-zvs merged 1 commit into
mainfrom
fix/webui-per-session-view-mode
Jun 29, 2026
Merged

fix(webui): persist Terminal/Chat/Program view selection per session#620
edwin-zvs merged 1 commit into
mainfrom
fix/webui-per-session-view-mode

Conversation

@edwin-zvs

Copy link
Copy Markdown
Contributor

Problem

In the web UI, the view-mode selector (Terminal / Chat / Program) didn't fully follow the focused session. Terminal and Chat were already per-session (stored in viewModeById), but Program was treated as a global mode — it lived only in the global state.mode and was never written to viewModeById (both the load and save filters dropped "program").

Two concrete symptoms:

  1. Program stuck globally. Switching sessions while viewing a Program carried Program onto the next session — selectSession keyed off state.mode === "program" (the outgoing session's mode) instead of the incoming session's own preference — so a terminal/chat session would render as Program just because the previous session was in Program.
  2. Program not restored. A session you deliberately left in Program reopened in Terminal/Chat, because its Program choice was never stored or restored.

Fix

Make Program a real per-session preference, peer to Terminal and Chat — which is exactly what spec 0059 already declares it to be ("a third per-session view mode, peer to Terminal and Chat"). The implementation simply wasn't honoring it.

  • Include "program" in the loadViewModePrefs / saveViewModePrefs filters for viewModeById.
  • Store "program" against the current session when entering Program mode; drop a stale "program" entry when a single-surface session leaves Program (so it reverts to its natural surface).
  • preferredViewModeForSession returns "program" when stored — it wins for any session, since every session owns a Program.
  • selectSession restores the incoming session's preferred view, not the outgoing session's global state.mode.
  • renderViewModeToggle highlights the per-session preference (not state.mode), so the toggle is correct during a switch, before the new surface is entered.

The session-deleted handler already cleaned up viewModeById, so removed sessions still drop their stored preference.

Behavior after

Each session independently remembers Terminal / Chat / Program and reopens in that view when you switch back to it. New sessions still default to their natural surface (Terminal for PTY-backed, otherwise Chat).

Spec

Adds specs/0062-webui-view-mode-is-per-session.md recording the per-session view-mode persistence/restore semantic so it isn't regressed back to a global toggle.

Testing

  • cargo build (debug) green in the worktree. index.html is include_str!'d into the daemon, so it ships in the construct binary (construct daemon run).
  • Inline-script parse check on index.html passes.

Only touches crates/daemon/assets/index.html (+ a new spec) → relevant binary is construct.

The web UI view-mode selector (Terminal / Chat / Program) treated Program
as a global mode: it lived only in the global `state.mode` and was never
recorded in the per-session `viewModeById` map. Terminal/Chat were already
per-session, but Program was not, so:

- switching sessions while in Program carried Program onto the next session
  (via `selectSession`'s `state.mode === "program"` check) regardless of
  what that session last showed, and
- a session you had left in Program reopened in Terminal/Chat, because its
  Program choice was never stored or restored.

Make Program a real per-session preference, peer to Terminal and Chat
(spec 0059):

- include "program" in the load/save filters for `viewModeById`;
- store "program" against the session when entering Program mode, and drop
  a stale "program" entry when a single-surface session leaves it;
- `preferredViewModeForSession` returns "program" when stored (it wins for
  any session, since every session owns a Program);
- `selectSession` restores the *incoming* session's preferred view instead
  of carrying the outgoing session's global `state.mode`;
- `renderViewModeToggle` highlights the per-session preference so the toggle
  is correct mid-switch, before the new surface is entered.

Add spec 0062 recording the per-session view-mode persistence semantic.
@edwin-zvs
edwin-zvs merged commit 68830c4 into main Jun 29, 2026
1 check 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.

1 participant