fix(bash): track cwd across ; chains, bare cd, quoted paths, subshells - #28
Closed
Franky100-pig wants to merge 3 commits into
Closed
Franky100-pig wants to merge 3 commits into
Franky100-pig wants to merge 3 commits into
Conversation
_update_cwd previously only split commands on '&&', so a 'cd' inside a
';'-chained command, a quoted path with spaces, or a subshell was not
reflected in the working directory reported to the model.
Rewrite using shlex (punctuation_chars=';&') so separators inside quotes
are not mistaken for statement breaks, and handle:
- 'cd a; cd b' and 'ls x; cd a' (semicolon chains)
- bare 'cd' -> home, 'cd' to a missing dir -> ignored
- quoted targets with spaces ('cd "my dir"')
- separators inside quotes are not treated as cd ('echo "x; cd a"')
- 'cd' inside a subshell '(cd a)' is not tracked
Adds 7 tests. Syncs README LoC numbers (engine 1161->1191, physical
2384->2417, net 1931->1961) and the bash.py tree count (131->164).
The suite actually has 160 tests (153 baseline + 7 added for the bash cwd tracking fix), but the prose still said 146. Update both README and README_CN to match the real number.
# Conflicts: # README.md # README_CN.md
he-yufeng
added a commit
that referenced
this pull request
Sep 18, 2026
_update_cwd split statements on && and ; with a plain regex, so a separator inside quotes was misread as a statement break (echo "x; cd a" moved the tracked cwd) and a bare cd never went home. Split with shlex (punctuation_chars=";&") so quoted separators hold and quoted targets with spaces arrive as one token; bare cd resolves to ~. README line counts resynced (engine 1192->1209, package 2,430->2,449 physical / 1,966->1,983 net). Reference: the shape of the fix follows PR #28's diagnosis (statement splitting must be quote-aware); implemented fresh here with tests for the quoted-separator false positive, bare cd, and quoted paths. 166/166 tests, ruff clean.
Owner
|
Thanks for this — the diagnosis was right and it held up when I ran it down on current main. The regex split misread separators inside quotes ( I implemented the fix fresh in 2c49e74 rather than merging this branch: same idea as yours (split on Closing this since the fix is in. Appreciate the careful writeup. |
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.
What
_update_cwdpreviously only split commands on&&, so acdinside a;-chained command, a quoted path with spaces, or a subshell was neverreflected in the working directory reported to the model.
How
Rewrote it with
shlex(punctuation_chars=";&")plus a small_split_statementshelper, so separators inside quotes are not mistakenfor statement breaks. Now handled:
cd a; cd bandls x; cd a(semicolon chains)cd→ home,cdto a missing dir → ignoredcd "my dir")echo "x; cd a")cdinside a subshell(cd a)is not trackedTests
Added 7 tests to
tests/test_tools.py(abash_modfixture clears_local.cwd). Full suite: 160 passed, including the README LoC guard.Docs
Synced README/README_CN headline numbers (engine 1161→1191, physical
2384→2417, net 1931→1961) and the
bash.pytree count (131→164).