Skip to content

fix(bash): track cwd across ; chains, bare cd, quoted paths, subshells - #28

Open
Franky100-pig wants to merge 3 commits into
he-yufeng:mainfrom
Franky100-pig:fix/bash-cwd-tracking
Open

Franky100-pig wants to merge 3 commits into
he-yufeng:mainfrom
Franky100-pig:fix/bash-cwd-tracking

Conversation

@Franky100-pig

Copy link
Copy Markdown

What

_update_cwd previously only split commands on &&, so a cd inside a
;-chained command, a quoted path with spaces, or a subshell was never
reflected in the working directory reported to the model.

How

Rewrote it with shlex(punctuation_chars=";&") plus a small
_split_statements helper, so separators inside quotes are not mistaken
for statement breaks. Now handled:

  • 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

Tests

Added 7 tests to tests/test_tools.py (a bash_mod fixture 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.py tree count (131→164).

_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.
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.

1 participant