fix(cli): scope -c/--resume to the current workspace - #72507
Merged
Conversation
`hermes -c`/`--resume` (continue last session) resolved the globally most-recently-used session, then cd'd into *its* recorded cwd. So running `hermes -c` from repo A could land you in repo B's session — the session you last touched anywhere, not the last one *here*. Now `_resolve_last_session` scopes to the current workspace first: the git repo root when CWD is inside a repo (so all sessions across its subdirs/worktrees group together), else the CWD itself — matching the `workspace_key` identity `hermes sessions list --workspace` already groups on. It falls back to the unscoped global MRU when no session matches the current workspace, preserving the old behaviour for fresh directories. Adds `workspace_key` param to `SessionDB.search_sessions` and a `_workspace_key_clause` SQL helper that mirrors `workspace_key()`: a row matches when its `git_repo_root` equals the key, or (legacy rows without git metadata) when its `cwd` is at or under it.
OutThisLife
enabled auto-merge
July 27, 2026 06:29
Contributor
૮ >ﻌ< ა ci reviewran on 28a87d6 all good! |
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 2026
…-cwd-scoped fix(cli): scope -c/--resume to the current workspace
prmartinow
pushed a commit
to prmartinow/hermes-agent
that referenced
this pull request
Aug 26, 2026
…-cwd-scoped fix(cli): scope -c/--resume to the current workspace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hermes -c/--resume(continue last session) resolved the globally most-recently-used session, then cd'd into its recorded cwd. Sohermes -cfrom repo A could drop you into repo B's session — the last session you touched anywhere, not the last one here.Now
_resolve_last_sessionscopes to the current workspace first:workspace_keyidentityhermes sessions list --workspacealready groups onFalls back to the unscoped global MRU when no session matches the current workspace, preserving the old behaviour for fresh directories.
What changed
SessionDB.search_sessionsgains aworkspace_keyparam +_workspace_key_clauseSQL helper that mirrorsworkspace_key(): a row matches when itsgit_repo_rootequals the key, or (legacy rows without git metadata) when itscwdis at or under it._resolve_last_sessioncomputes the current workspace key (_resolve_workspace_key) and queries workspace-scoped first, falling back to global MRU.Verification
tests/hermes_cli/test_resolve_last_session.py— 12 pass (6 existing + 6 new: workspace preference, global fallback, cwd-subdir legacy match, source filtering within workspace, real-DB SQL filter, real-DB end-to-end)tests/cli/test_cli_resume_command.py,tests/cli/test_cwd_env_respect.py,tests/cli/test_resume_display.py,tests/test_session_workspace_binding.py,tests/hermes_cli/test_session_filters.py— 107 passtests/test_hermes_state.py— 464 pass, 1 skiprepo_bglobal-MRU returned instead ofrepo_a) and pass with this change.Closes #38562 (the cwd-scoped-resume half that #67287's interactive
/resumeleft out — the-c/--resumestartup path).