Skip to content

fix(cli): scope -c/--resume to the current workspace - #72507

Merged
OutThisLife merged 1 commit into
mainfrom
bb/cli-resume-cwd-scoped
Jul 27, 2026
Merged

fix(cli): scope -c/--resume to the current workspace#72507
OutThisLife merged 1 commit into
mainfrom
bb/cli-resume-cwd-scoped

Conversation

@OutThisLife

Copy link
Copy Markdown
Collaborator

Summary

hermes -c / --resume (continue last session) resolved the globally most-recently-used session, then cd'd into its recorded cwd. So hermes -c from repo A could drop you into repo B's session — the last session you touched anywhere, not the last one here.

Now _resolve_last_session scopes to the current workspace first:

  • git repo root when CWD is inside a repo (so sessions across its subdirs/worktrees group together), matching the workspace_key identity hermes sessions list --workspace already groups on
  • else the CWD itself

Falls back to the unscoped global MRU when no session matches the current workspace, preserving the old behaviour for fresh directories.

What changed

  • SessionDB.search_sessions gains a workspace_key param + _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.
  • _resolve_last_session computes 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 pass
  • tests/test_hermes_state.py — 464 pass, 1 skip
  • Premise verified: the new workspace-preference tests fail on origin/main (repo_b global-MRU returned instead of repo_a) and pass with this change.

Closes #38562 (the cwd-scoped-resume half that #67287's interactive /resume left out — the -c/--resume startup path).

`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
OutThisLife enabled auto-merge July 27, 2026 06:29
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 27, 2026
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 28a87d6

all good!

@OutThisLife
OutThisLife merged commit 21dd2d4 into main Jul 27, 2026
38 checks passed
@OutThisLife
OutThisLife deleted the bb/cli-resume-cwd-scoped branch July 27, 2026 06:32
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants