fix(file-tools): respect TERMINAL_CWD for path resolution in worktree mode#13080
Closed
bennytimz wants to merge 1 commit into
Closed
fix(file-tools): respect TERMINAL_CWD for path resolution in worktree mode#13080bennytimz wants to merge 1 commit into
bennytimz wants to merge 1 commit into
Conversation
… mode Fixes NousResearch#12689. All four bare Path.resolve()/os.path.realpath calls in _check_sensitive_path, read_file_tool, _update_read_timestamp, and _check_file_staleness now route through a _resolve_path helper that anchors relative paths to TERMINAL_CWD when set (worktree root), falling back to os.getcwd() otherwise.
Contributor
|
Merged via PR #13161 (#13161) using @aniruddhaadak80's implementation from PR #12695 (submitted first). Your fix was identical — thanks for the contribution, and apologies for closing as duplicate. |
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.
Fixes #12689.
In CLI
-w(worktree) mode,cli.pycorrectly setsTERMINAL_CWDto the isolated worktree path. However,file_tools.pyresolves all paths usingPath(path).resolve()andos.path.realpath(), which anchor to the process CWD (main repo root) instead ofTERMINAL_CWD. This meansread_file,write_file,patch, andsearchcan silently escape the worktree and corrupt files in the main repository.Root cause
Four path resolution call sites in
_check_sensitive_path,read_file_tool,_update_read_timestamp, and_check_file_stalenessall ignoreTERMINAL_CWD.Fix
Adds a
_resolve_path()helper that readsTERMINAL_CWDand uses it as the base for relative path resolution. Absolute paths are left unchanged. Falls back toos.getcwd()whenTERMINAL_CWDis not set — no behaviour change in non-worktree mode.Test plan
hermes -wand verifyread_file/write_file/patchresolve paths inside the worktree, not the main repoTERMINAL_CWDset → falls back toos.getcwd())