Skip to content

fix(terminal): skip chat-panel terminals in workspace cd sync#263

Open
Raymond8196 wants to merge 1 commit into
yorgai:developfrom
Raymond8196:fix/terminal-repo-sync-skip-chatpanel
Open

fix(terminal): skip chat-panel terminals in workspace cd sync#263
Raymond8196 wants to merge 1 commit into
yorgai:developfrom
Raymond8196:fix/terminal-repo-sync-skip-chatpanel

Conversation

@Raymond8196

Copy link
Copy Markdown
Contributor

Problem

Switching sessions from the sidebar while a CLI agent TUI (codex/claude/gemini) was open in a chat-panel terminal injected cd '<path>' into the running TUI, corrupting it (e.g. codex echoed cd '/path' back as user input). The session switch itself succeeded, but the TUI was visually broken.

Root cause

useTerminalRepoSync broadcasts cd '<repoPath>' to every initialized terminal when the active workspace changes. Its guard only skipped readOnly and agent-pty- sessions, so chatpanel- terminals — which host interactive CLI agent TUIs — received the cd and got their TUI corrupted.

The session-list click → jumpToSessionAtomfollowSessionRepo updates activeWorkspaceRootPathAtom, which fired the broadcast into the chat-panel terminal running the codex TUI.

This is the only "iterate the terminal pool + inject a command" call site in the codebase; all other write_pty writers target a single active terminal and are unaffected.

Fix

  • Extract the guard into a pure selectRepoSyncTargets() so it is unit-testable without a React renderer (the host project ships neither @testing-library/react nor jsdom).
  • Add isChatPanelTerminalId to the exclusion list.
  • Add unit tests covering each excluded class (readOnly / agent-pty- / chatpanel- / uninitialized) plus a mixed case to lock the guard boundary.

Test plan

  • npx vitest run src/hooks/terminal/__tests__/repoSyncTargets.test.ts — 6/6 pass
  • Pre-commit hooks (lint-staged + eslint + prettier + scoped tsc) — clean
  • Manual: open a codex TUI in a new session, click a session in another repo from the sidebar — TUI must stay clean, no cd injected.

useTerminalRepoSync broadcasts `cd '<path>'` to every initialized terminal
when the active workspace changes. Its guard only skipped readOnly and
agent-pty- sessions, so chatpanel- terminals — which host interactive CLI
agent TUIs (codex/claude/gemini) — received the cd and got their TUI
corrupted (e.g. codex showed `cd '/path'` as user input).

Extract the guard into a pure selectRepoSyncTargets() and add unit tests
covering each excluded class (readOnly / agent-pty- / chatpanel- /
uninitialized) plus a mixed case, so the regression is caught without a
React renderer.

Pre-commit hook ran. Total eslint: 0, total circular: 0
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