Skip to content

feat(cli): resume relaunches in the session's original working directory - #38562

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-dd547edd
Jun 4, 2026
Merged

feat(cli): resume relaunches in the session's original working directory#38562
teknium1 merged 1 commit into
mainfrom
hermes/hermes-dd547edd

Conversation

@teknium1

@teknium1 teknium1 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

hermes -c / hermes --resume <id> now reopen a session in the directory it was originally launched from, instead of wherever you happen to be standing.

The sessions table already had a cwd column (and the TUI gateway used it) — the classic CLI just never wrote or read it. This wires up both halves.

Changes

  • run_agent._ensure_db_session: stamps cwd on the session row. New _launch_cwd_for_session(source) gates it to local CLI sessions only — gateway/cron sessions and non-local terminal backends (docker/ssh/modal) have no stable host cwd to restore, so they record nothing.
  • cli._restore_session_cwd(session_meta): on resume, os.chdir()s the process and retargets TERMINAL_CWD so the terminal tool, code-exec tool, and relative-path resolution all land in the restored dir (the local terminal backend snapshots cwd on first use, which happens after this runs). Wired into both resume paths — interactive run() and the -q single-query path.
  • Robust degradation: no-op when no cwd was recorded (older/gateway sessions), when already in that dir, or when the dir is gone (single dim warning, stays put — no crash).

Validation

End-to-end, real CLI, isolated HERMES_HOME:

Step Result
Launch -q from /tmp/dirA session row records cwd=/tmp/dirA
--resume <id> from /tmp/dirB, agent runs cat marker.txt returns I-AM-DIR-A + prints ↻ Working directory: /tmp/dirA

Plus 15 unit-level E2E assertions covering write-side gating (cli/local records, gateway/docker skip), DB round-trip, chdir + TERMINAL_CWD retarget, already-there no-op, missing-dir degradation, ~ expansion, and quiet-mode stderr routing — all pass.

Infographic

resume-relaunches-cwd

… from

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-dd547edd vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9746 on HEAD, 9746 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5048 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Jun 4, 2026
@teknium1
teknium1 merged commit e7bc618 into main Jun 4, 2026
23 checks passed
@teknium1
teknium1 deleted the hermes/hermes-dd547edd branch June 4, 2026 00:37
Yuki-14544869 pushed a commit to Yuki-14544869/hermes-agent that referenced this pull request Jun 4, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
davidgut1982 pushed a commit to davidgut1982/hermes-agent that referenced this pull request Jun 5, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
changman pushed a commit to changman/hermes-agent that referenced this pull request Jun 10, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
alt-glitch pushed a commit that referenced this pull request Jun 14, 2026
… from (#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
kossteg pushed a commit to kossteg/hermes-agent that referenced this pull request Jun 16, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
xyshanren pushed a commit to xyshanren/hermes-agent-cn that referenced this pull request Jun 25, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
donbowman pushed a commit to donbowman/hermes-agent that referenced this pull request Jul 13, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
… from (NousResearch#38562)

hermes -c / --resume now reopen a session in its original working
directory. The sessions table already had a cwd column; the classic CLI
just never wrote or read it.

- run_agent._ensure_db_session stamps cwd for local CLI sessions only
  (new _launch_cwd_for_session gates out gateway/cron and non-local
  terminal backends, where a host cwd is meaningless to restore).
- cli._restore_session_cwd chdir's the process AND retargets TERMINAL_CWD
  so the terminal tool, code-exec tool, and relative-path resolution all
  land in the restored dir. Called from both resume paths (interactive
  run() and the -q single-query path).
- Robust degradation: no-op when no cwd recorded, when already there, or
  when the dir is gone (single dim warning, stays put — no crash).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants