Skip to content

feat: filter session history by workspace directory#11813

Open
mvanhorn wants to merge 2 commits intocontinuedev:mainfrom
mvanhorn:osc/9936-workspace-session-filter
Open

feat: filter session history by workspace directory#11813
mvanhorn wants to merge 2 commits intocontinuedev:mainfrom
mvanhorn:osc/9936-workspace-session-filter

Conversation

@mvanhorn
Copy link
Contributor

@mvanhorn mvanhorn commented Mar 25, 2026

Summary

Add optional workspaceDirectory field to ListHistoryOptions so callers can scope session lists to a specific workspace. Sessions are stored with workspace info already (BaseSessionMetadata.workspaceDirectory) but HistoryManager.list() had no way to filter by it.

Why this matters

Opening a project currently shows the last active session from any project, and session history shows all projects interleaved. Multi-window usage is confusing because sessions from different workspaces appear mixed together.

  • #9936 - original feature request
  • core/util/history.ts:25 - list() returned all sessions without workspace filtering
  • core/protocol/core.ts:63 - ListHistoryOptions only had offset and limit

Changes

  • core/protocol/core.ts - Added workspaceDirectory?: string to ListHistoryOptions
  • core/util/history.ts - Added workspace filter in list(), applied before pagination. Case-insensitive comparison. Omitting the field returns all sessions (backward compatible).
  • core/util/history.test.ts - 5 new tests: exact match, case-insensitive, empty returns all, non-matching returns empty, works with limit/offset

Testing

All 17 tests pass (12 existing + 5 new workspace filtering tests).

This contribution was developed with AI assistance (Claude Code).

Fixes #9936


Summary by cubic

Adds an optional workspace filter to session history so UIs can list sessions per workspace and avoid mixing projects. Improves multi-window behavior by scoping sessions to the active workspace. Fixes #9936.

  • New Features

    • Added workspaceDirectory?: string to ListHistoryOptions.
    • Case-insensitive filtering in HistoryManager.list() before pagination; omit the field to return all.
  • Bug Fixes

    • Safer filtering using a typeof guard on workspaceDirectory to handle malformed metadata.
    • Expanded tests: match, case-insensitive, no filter, non-match, limit-only, and limit+offset with filter.

Written for commit d919e1d. Summary will update on new commits.

Add optional workspaceDirectory field to ListHistoryOptions so callers
can scope session lists to a specific workspace. Filtering is
case-insensitive and applied before pagination. Omitting the field
preserves the existing behavior of returning all sessions.

Fixes continuedev#9936

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mvanhorn mvanhorn requested a review from a team as a code owner March 25, 2026 05:04
@mvanhorn mvanhorn requested review from sestinj and removed request for a team March 25, 2026 05:04
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 25, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="core/util/history.ts">

<violation number="1" location="core/util/history.ts:42">
P2: Workspace filter calls `.toLowerCase()` on unvalidated runtime values, which can throw and break `list()` for malformed session metadata.</violation>
</file>

<file name="core/util/history.test.ts">

<violation number="1" location="core/util/history.test.ts:139">
P2: Test claims to validate workspace filtering with both limit and offset, but offset is never passed, so the combined pagination behavior is untested.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

- Use typeof check instead of truthiness for workspaceDirectory to
  handle malformed session metadata safely
- Rename test to match actual coverage (limit only)
- Add separate test for combined limit+offset with workspace filter
Copy link
Collaborator

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

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

@mvanhorn this seems like a good change that would move towards solving a long running issue, but where is the workspaceDirectory option actually passed around? Is there missing UI? Seems maybe in current state this will not change any functionality?

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Mar 25, 2026
@mvanhorn
Copy link
Contributor Author

You're right that nothing passes workspaceDirectory yet - this is the core plumbing only. The filter works when called directly (tests cover that), but the UI history panel and IDE protocol handler both need a follow-up to wire it through.

My plan was to keep this PR small and land the filtering logic first, then add the IDE-side wiring (reading the current workspace from the IDE context and passing it to history/list) as a separate PR. Happy to combine them if you'd prefer the full end-to-end in one shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

feat: isolate chat sessions by workspace directory

2 participants