Skip to content

fix(bwopencode2): persist TUI plugin state across sessions - #29

Merged
Dan Allan (danielballan) merged 1 commit into
NSLS2:mainfrom
stuwilkins:fix/bwopencode2-persist-tui-state
Oct 24, 2026
Merged

Dan Allan (danielballan) merged 1 commit into
NSLS2:mainfrom
stuwilkins:fix/bwopencode2-persist-tui-state

Conversation

@stuwilkins

Copy link
Copy Markdown
Contributor

What

Persist OpenCode 2's TUI plugin storage (~/.local/state/opencode/latest/tui)
across bwopencode2 launches by binding it from the host
(~/.local/state/opencode2/opencode/latest/tui, the location the ansible
opencode2 wrapper uses). The rest of the state directory stays ephemeral.

Why

$HOME in the sandbox is a tmpfs, so everything under
~/.local/state/opencode was discarded on exit. That includes the TUI's
plugin storage, so:

  • the sidebar "Getting started" box reappears on every launch even after it is
    dismissed (users whose providers come from config rather than /connect
    always see it), and
  • the tab layout (tabs.json) is forgotten.

How

  • resolve_opencode2_paths: add OC2_TUI_STATE_SRC / OC2_TUI_STATE_DIR,
    with a _check_dir_safe check on the host path.
  • ensure_host_dirs: create the host directory (skipped on --dry-run).
  • build_opencode2_state_dir: keep --dir for the state dir, add
    --bind for latest/tui only.
  • docs/bw-wrappers.md: mount table and text updated.

Why only latest/tui

  • locks/ and latest/locks/ stay on tmpfs. This keeps the original reason
    for an ephemeral state dir: avoiding lock clashes on NFS homes.
  • Background-service files stay on tmpfs, so they are not shared with a
    host opencode2.
  • Root-level files (model.json, kv.json, prompt-history.jsonl) are not
    bound one by one. OpenCode saves by writing a temp file and renaming it over
    the target, which fails (EBUSY) on a bind-mounted single file. A directory
    bind does not have this problem.
  • latest is the release-channel directory name. Another channel would not
    be persisted; this is noted in a code comment.

Testing

  • bash -n, and the repo's pre-commit hooks (shfmt, shellcheck,
    markdownlint, codespell, gitleaks) pass on the changed files.
  • bwopencode2 --dry-run shows
    --bind ~/.local/state/opencode2/opencode/latest/tui ~/.local/state/opencode/latest/tui.
  • Manual: dismiss "Getting started", exit, relaunch, and confirm it stays
    hidden and the tabs are restored.

AI disclosure

Written with OpenCode (claude-sonnet-5-5), reviewed by a human.
AI_DISCLOSURE.md updated.

The sandbox state directory is a tmpfs, so a dismissed Getting started box and the tab layout were lost on every launch. Bind only latest/tui from the host opencode2 state directory; locks and service files stay ephemeral. A directory is bound because OpenCode saves by rename, which fails on a bind-mounted file.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings October 24, 2026 13:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new writable mount’s source validation can allow symlinks to expose protected host configuration.

No open issues 🎉

What changed in this PR

This PR updates bwopencode2 to preserve OpenCode 2’s TUI plugin state across sandbox sessions while keeping other state ephemeral.

Changes:

  • Creates and binds the host latest/tui directory to preserve dismissed onboarding boxes and tab layouts.
  • Documents the persistence boundary, leaving locks and background-service files ephemeral.
  • Updates the AI disclosure metadata.
File Description
docs/​bw-wrappers.md Documents the persistent TUI mount and remaining ephemeral state.
bin/​bwopencode2 Adds TUI state path validation, directory creation, and a writable bind.
AI_DISCLOSURE.md Updates the model list and disclosure date.

Review effort: Balanced

@danielballan
Dan Allan (danielballan) merged commit 28209d6 into NSLS2:main Oct 24, 2026
1 check passed
@stuwilkins
Stuart B. Wilkins (stuwilkins) deleted the fix/bwopencode2-persist-tui-state branch October 25, 2026 23:53
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.

3 participants