Skip to content

feat: store working directory (cwd) per session#19292

Open
SHL0MS wants to merge 1 commit into
NousResearch:mainfrom
SHL0MS:feat/session-cwd
Open

feat: store working directory (cwd) per session#19292
SHL0MS wants to merge 1 commit into
NousResearch:mainfrom
SHL0MS:feat/session-cwd

Conversation

@SHL0MS

@SHL0MS SHL0MS commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Record os.getcwd() when creating session rows so hermes sessions list, hermes sessions browse, and external tools (e.g. agf) can identify which project directory a session was launched from.

See also #19154 which addresses the same gap — this PR takes a simpler approach (single cwd column, no schema version bump) and adds TUI session creation, sessions list display, and sessions browse search support.

Changes

File Change
hermes_state.py Add cwd TEXT column to sessions schema (auto-migrated via _reconcile_columns — no version bump needed)
hermes_state.py Accept cwd param in create_session()
run_agent.py Pass cwd=os.getcwd() at session creation (initial + compression-continuation paths)
cli.py Pass cwd=os.getcwd() for /new and /branch sessions
tui_gateway/server.py Pass cwd=os.getcwd() for TUI sessions (both new and branch)
hermes_cli/main.py Display cwd column in sessions list when any session has one; include cwd in sessions browse search matching

Design decisions

  • Single column (cwd) rather than two (workspace_path + last_cwd). The initial working directory is the meaningful identifier for "which project was this session about." Mid-session directory changes via cd in the terminal tool don't change the project context.
  • No schema version bump. The existing _reconcile_columns() mechanism (lines 339-381 of hermes_state.py) automatically detects the new column in SCHEMA_SQL and runs ALTER TABLE ADD COLUMN on next startup. Version-gated migrations are only needed for non-declarative changes (FTS rebuilds, data transforms).
  • Graceful display. sessions list only adds the Directory column when at least one session has a cwd value, so the output is unchanged for existing sessions until new ones are created.
  • Browse search. The curses _match() function now includes cwd in its search text, so users can type a project directory name to filter sessions.

Motivation

Hermes sessions currently have no record of which directory they were launched from. This means:

  • hermes sessions list can't show project context
  • hermes sessions browse can't filter by project
  • External session finders (agf, agent-archives) show all Hermes sessions as ~/.hermes instead of the actual project path
  • The ACP adapter already stores cwd in model_config JSON for IDE sessions — this extends the same concept to CLI/TUI with a proper column

Record os.getcwd() when creating session rows so external tools
(agf, sessions list, sessions browse) can identify which project
directory a session was launched from.

Changes:
- hermes_state.py: add cwd TEXT column to sessions schema
  (auto-migrated via _reconcile_columns on next startup)
- hermes_state.py: accept cwd param in create_session()
- run_agent.py: pass cwd=os.getcwd() at session creation
  (both initial and compression-continuation paths)
- cli.py: pass cwd=os.getcwd() for /new and /branch sessions
- tui_gateway/server.py: pass cwd=os.getcwd() for TUI sessions
- hermes_cli/main.py: display cwd in sessions list when present;
  include cwd in sessions browse search matching
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard comp/agent Core agent loop, run_agent.py, prompt builder comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels May 3, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #19154 (same feature — persist session workspace context). This PR takes a simpler single-column approach vs #19154 two-column design.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: #19154 — competing approach to same feature.

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants