-
Notifications
You must be signed in to change notification settings - Fork 73
terminal/tmux: disable bash history expansion to avoid ! mangling #1277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: openhands <openhands@all-hands.dev>
…ng during init handshake\n\nCo-authored-by: openhands <openhands@all-hands.dev>
openhands-tools/openhands/tools/terminal/terminal/subprocess_terminal.py
Show resolved
Hide resolved
xingyaoww
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Can we add a few tests for it?
|
@OpenHands Let’s add unit tests for this PR. Make sure to find the right place for these tests, probably in the same test file(s) where other functions in these files are tested. |
|
I'm on it! enyst can track my progress at all-hands.dev |
…isabled in tmux and subprocess backends - Mock tmux to assert initialize sends 'set +H;' in TmuxTerminal - E2E check in SubprocessTerminal that '!' is preserved (no history expansion) Co-authored-by: openhands <openhands@all-hands.dev>
|
Summary of changes made
Validation steps performed
Checklist
|
| with patch( | ||
| "openhands.tools.terminal.terminal.tmux_terminal.libtmux.Server", FakeServer | ||
| ): | ||
| # Avoid isinstance check in clear_screen during initialize since we stub Pane |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 i think we do have some unit tests that are actually running a real libtmux Server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
Coverage Report •
|
|||||||||||||||||||||||||
… subprocess backends - In test_terminal_session.py, add test_history_expansion_disabled to assert '!' is preserved and no history expansion occurs across both backends Co-authored-by: openhands <openhands@all-hands.dev>
…eal parametrized test - Delete tests/tools/terminal/test_disable_history_expansion.py as redundant - test_history_expansion_disabled in test_terminal_session.py now covers both tmux and subprocess Co-authored-by: openhands <openhands@all-hands.dev>
- Add @parametrize_terminal_types to ensure the test runs for both tmux and subprocess and fixture exists Co-authored-by: openhands <openhands@all-hands.dev>
I had the agent do this for itself in an overnight experiment where it created itself a TUI to use it for E2E testing of switching LLM Profiles
The TUI it made is here (it's not pretty but it worked without humans 😅):
I'm not sure when it needed disabling history expansion, but it seems like a good idea to me?
(Agent write-up)
This PR disables bash history expansion in the tmux-based terminal backend to prevent unintended "!" expansion that can mangle commands.
Change:
set +H;to the initialization command when configuring the shell inTmuxTerminal.initializeso that!characters are not interpreted by history expansion.Rationale:
!(e.g., URLs, JSON, or other content), bash history expansion can alter the input unexpectedly. Disabling it leads to more predictable behavior for programmatic terminal execution.Implementation details:
openhands-tools/openhands/tools/terminal/terminal/tmux_terminal.pyself.pane.send_keys(...)line to includeset +H;before settingPROMPT_COMMANDandPS2.This is a minimal, backwards-compatible change that only affects the initialization of the interactive shell used by the tmux terminal backend.
@enyst can click here to continue refining the PR
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.12-nodejs22golang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:2a61f33-pythonRun
All tags pushed for this build
About Multi-Architecture Support
2a61f33-python) is a multi-arch manifest supporting both amd64 and arm642a61f33-python-amd64) are also available if needed