1jehuang / 1jehuang/jcode

Side-panel focus state diverges between the tool and TUI when hidden with Alt+M

Open
#986 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autonomous: no bug triage: needs-decision ux
Dominant language
Rust
Stars
19.9k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
30

Description

Summary

When the user hides the side panel with Alt+M, an agent can create or focus a different page through the side_panel tool with focus = true. The tool reports the new page as focused, but the TUI deliberately suppresses that focus while hidden. When the user presses Alt+M again, the TUI restores the previously visible page instead of the newly requested page.

Respecting the user's hidden-panel choice is desirable. The bug is that the server-side snapshot and tool output claim one page is focused while the TUI has retained a different page as the one it will display. The agent therefore reports that content was opened or focused even though the user cannot see it.

Environment
  • Jcode v0.77.1 (3d164135a)
  • Windows x86_64
  • Jcode TUI
  • Side panel containing more than one page
Steps to reproduce
  1. Open side-panel page A.
  2. Press Alt+M to hide the side panel.
  3. While it is hidden, have the agent create and focus page B:
side_panel action="write" page_id="page-b" title="Page B" focus=true
  1. Observe that the tool reports page B as focused:
Side panel: 2 pages
Focused: page-b
* page-b (markdown)
  page-a (markdown)
  1. The TUI correctly remains hidden because the user explicitly hid it.
  2. Press Alt+M to reopen the side panel.
  3. Observe that page A is displayed instead of page B.
  4. A subsequent side_panel action="status" can still report page B as focused, despite the TUI showing page A.
Actual behavior
  • focus = true updates the persisted/server-side focused_page_id.
  • The tool output says the requested page is focused.
  • The hidden TUI clears the incoming focused page locally.
  • The TUI retains the old last_side_panel_focus_id.
  • Reopening with Alt+M restores the old page.
  • Tool status and the user-visible TUI disagree about which page is focused.
Expected behavior

The user's Alt+M choice should continue to prevent agents from unexpectedly reopening the panel. However, focus and status should remain internally consistent.

One reasonable behavior would be:

  • keep the panel hidden
  • record page B as the page to display on the next manual reopen
  • report that the panel is hidden and page B is pending or selected
  • display page B when the user next presses Alt+M

Alternatively, if focus requests are intentionally ignored while hidden, the tool should report that fact rather than claiming the page is focused.

At minimum, side_panel status should distinguish persisted requested focus from actual client-visible focus.

Technical notes

The side_panel tool defaults focus to true, persists the resulting snapshot, publishes it, and returns status_output(&snapshot). The status is therefore based entirely on the server-side snapshot.

In crates/jcode-tui/src/tui/app/state_ui.rs, set_side_panel_snapshot deliberately clears incoming focus while the panel is user-hidden:

if self.side_panel_user_hidden && snapshot.focused_page_id.is_some() {
    snapshot.focused_page_id = None;
}

Because the snapshot still contains pages, apply_side_panel_snapshot does not clear or replace last_side_panel_focus_id when focus becomes None.

In crates/jcode-tui/src/tui/app/navigation.rs, toggle_side_panel later restores last_side_panel_focus_id, which is still page A.

There is an existing test confirming that a side panel hidden with Alt+M stays hidden across snapshot updates. That desired visibility behavior can remain unchanged. The missing case is a hidden update that explicitly focuses a different page and the resulting server/TUI focus divergence.

Impact

Agents can truthfully receive a successful tool response and then incorrectly tell users that a page was opened or focused. Users reopen the panel and see stale content, making new drafts or files appear missing. The mismatch is especially confusing because side_panel status can confirm a focus state that does not match the rendered TUI.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in crates/jcode-tui/src/tui/app/state_ui.rs, especially set_side_panel_snapshot and apply_side_panel_snapshot, then inspect toggle_side_panel in crates/jcode-tui/src/tui/app/navigation.rs. Run the existing test covering Alt+M hidden-panel behavior and add coverage for a hidden snapshot that focuses another page. Done means reopening displays the requested page and tool status no longer conflicts with the TUI's visible focus.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.