feat(sessions): workspace binding — capture git remote/branch, group + filter, restore cwd on resume (#48190)#48591
Open
professorpalmer wants to merge 1 commit into
Conversation
…+ filter, restore cwd on resume Implements session<->workspace binding (NousResearch#48190). Sessions already recorded cwd; this adds git_remote + git_branch (auto-migrated via declarative column reconciliation) and derives a workspace grouping key. - hermes_state: new git_remote/git_branch columns; best-effort capture at create_session() from the cwd callers already pass; skipped for child sessions (subagents/compression). workspace_key() groups by remote (cwd fallback) with branch as a per-session attribute, NOT part of the key, so switching branches doesn't fragment a workspace's history. SSH and HTTPS remotes normalize to one key. list_sessions_rich() gains a workspace= filter. - CLI: 'sessions list' shows a Workspace column + accepts --workspace; resume (chat -r/--continue) cd's back into the recorded cwd, with --no-restore-cwd to opt out and a graceful warn-and-stay fallback when the dir is gone. - Additive + backwards-compatible: pre-existing sessions render as unbound. - Tests: 7 E2E cases against a temp HERMES_HOME (migration, capture, ssh==https, non-git fallback, child-not-bound, filter, backwards-compat).
5 tasks
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
Implements session ↔ workspace binding (closes #48190). Sessions already
recorded
cwd; this addsgit_remote+git_branch, derives a workspacegrouping key, surfaces it in
sessions list, lets you filter by it, andrestores the recorded cwd on resume.
Incorporates the design refinement from the issue thread (@Ben-Home): grouping
is derived automatically from
(cwd, git_remote)rather than user-organized,and branch is a per-session attribute, not part of the grouping key — so
checking out a new branch doesn't fragment a workspace's session history.
What changed
hermes_state.pygit_remote/git_branchcolumns onsessions, added toSCHEMA_SQLso they auto-migrate via the existing declarative
_reconcile_columns—no version-gated migration block, no breaking change.
create_session()derived from thecwdcallersalready pass (every frontend gets it for free; no call-site changes). Never
fatal — any git failure yields
NULL. Skipped for child sessions(subagents/compression) so worktree byproduct doesn't get a workspace identity.
_normalize_git_remote()collapses SSH and HTTPS clones of the same repo toone key (
github.com/owner/repo), credentials stripped.workspace_key(row)— grouping derivation: git remote first,cwdfallback,branch deliberately excluded from the key.
list_sessions_rich(workspace=...)filter (matches remote exact/substring or cwd).hermes_cli/main.pysessions listshows a Workspace column (repo@branch,—when unbound)and accepts
--workspace <remote-or-dir>.chat -r/--continue)cds back into the session's recordedcwd;warns and stays put if the dir is gone (never fails the resume).
hermes_cli/_parser.py--no-restore-cwdflag on both chat parsers to opt out of cwd restore.tests/test_session_workspace_binding.pyHERMES_HOME(realSessionDB, real git repos,no mocks): column migration, git capture, SSH==HTTPS normalization, non-git
cwd fallback, child-not-bound,
--workspacefilter, backwards-compat unbound.Design constraints honored
never mutated mid-conversation — no system-prompt churn, no per-turn token cost.
NULLworkspace fields and render as unbound;
sessions listfalls back to theprior Preview column layout when nothing in the page is workspace-bound.
Test plan
CLI smoke:
hermes sessions list --helpshows--workspace;hermes chat --helpshows
--no-restore-cwd.Not included (noted as follow-ups in #48190)
workspace_key.Closes #48190