fix(session): scope session list to current directory#14443
fix(session): scope session list to current directory#14443Aegis-commits wants to merge 1 commit intoanomalyco:devfrom
Conversation
Pass the existing `directory` parameter to all session list call sites that were missing it, so sessions are filtered to the current working directory instead of showing all sessions globally. Fixes four entry points: - CLI `session list` command - TUI bootstrap session fetch - TUI /sessions dialog search - TUI SSE session.updated event handler (new session inserts) Uses the existing Session.list() directory filter and GET /session?directory= API parameter — no server or API contract changes required. Fixes anomalyco#8836
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Related PRs FoundNote: PR #14443 is the current PR being checked, so it's excluded from the duplicate list below. Highly Related PRs:
Why These Are Related:
|
|
Closing — fix is incomplete, sessions still cross directories in the TUI. Will investigate further before resubmitting. |
Summary
opencode session listand the TUI/sessionsdialog show sessions from all directories instead of only the current working directory. This is because four call sites don't pass the existingdirectoryfilter parameter toSession.list().This PR wires the
directoryparameter through all four missing call sites. No server, API, or schema changes required — the filtering infrastructure already exists and is already used by the web app.Fixes #8836
Problem
Session.list()accepts an optionaldirectoryparameter that filters sessions by working directory. The server route (GET /session?directory=) and the web app'ssession-load.tsalready use this parameter correctly. However, four TUI/CLI entry points callSession.list()without it:session listcommand — fetches all sessions globally/sessionsdialog — searches all sessions when user opens session pickersession.updatedevents regardless of directoryFor git repositories, this is partially masked because
project_idis derived from the repo root. But for non-git directories,project_idis"global"— so sessions from every non-git directory get mixed together.Changes
packages/opencode/src/cli/cmd/session.tsdirectory: Instance.directorytoSession.list()packages/opencode/src/cli/cmd/tui/context/sync.tsxdirectory: sdk.directoryin bootstrap fetch (line ~353)packages/opencode/src/cli/cmd/tui/context/sync.tsxsession.updatedhandler — only insert sessions matching current directory (lines ~208-220)packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsxdirectoryto search callpackages/opencode/src/cli/cmd/tui/context/sdk.tsxdirectoryproperty on SDK context return object (plumbing for the above)+7 lines, -4 lines across 4 files.
Approach
This follows the same pattern the web app already uses in
packages/app/src/context/global-sync/session-load.ts. Each caller explicitly passes the directory it cares about — no server-side default changes, no new CLI flags, no API contract modifications.The SSE handler fix deserves a note: without it, a session created in directory B would still appear in the TUI running in directory A via the real-time event stream, even though the initial fetch was correctly filtered.
Testing
tsgo --noEmitpasses for bothpackages/opencodeandpackages/app(full monorepo typecheck via turborepo: 12/12 packages pass)tmpdir())Instance.directorystores the literal CWD, confirming exact-match filtering works correctlyRelated