Skip to content

fix(file_tools): resolve relative paths against TERMINAL_CWD for worktree isolation#13161

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-975c386c
Apr 20, 2026
Merged

fix(file_tools): resolve relative paths against TERMINAL_CWD for worktree isolation#13161
teknium1 merged 2 commits into
mainfrom
hermes/hermes-975c386c

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Resolves relative paths in file_tools.py against TERMINAL_CWD instead of process CWD, so pre-check guards (binary detection, dedup, staleness, sensitive path) resolve the same file the actual I/O targets.

Fixes #12689. Salvaged from PR #12695 (@aniruddhaadak80, first submitter). Supersedes PR #13080 (@bennytimz, same fix submitted later).

Changes

  • tools/file_tools.py: new _resolve_path() helper, applied to 4 call sites
  • tests/tools/test_resolve_path.py: 5 tests covering relative, absolute, tilde, fallback, and traversal normalization
  • scripts/release.py: AUTHOR_MAP entry for contributor

Validation

Before After
Relative path in -w mode Resolves against process CWD (main repo) Resolves against TERMINAL_CWD (worktree)
Absolute path Unchanged Unchanged
No TERMINAL_CWD set os.getcwd() os.getcwd() (no behavior change)

Tests: 21/21 file_tools + 5/5 new resolve_path tests passing.

aniruddhaadak80 and others added 2 commits April 20, 2026 12:23
…tree isolation

Adds a _resolve_path() helper that reads TERMINAL_CWD and uses it as
the base for relative path resolution. Applied to _check_sensitive_path,
read_file_tool, _update_read_timestamp, and _check_file_staleness.

Absolute paths and non-worktree sessions (no TERMINAL_CWD) are
unaffected — falls back to os.getcwd().

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: file_tools.py ignores TERMINAL_CWD — file operations leak out of worktree isolation in CLI -w mode

2 participants