opencode
opencode copied to clipboard
fix: prevent app hanging when executing sudo commands
Summary
- Fixes app becoming unresponsive when executing commands requiring sudo password
- Adds proactive detection and clear error messaging for sudo commands
- Includes comprehensive test coverage
Problem
When opencode executes a command requiring sudo password, the bash tool spawns the process without stdin connected, causing it to hang indefinitely waiting for password input that can never be provided.
Solution
Added sudo command detection in the bash tool that:
- Checks if commands start with
sudo - Detects sudo after common command separators (
;,&&,||,|) - Throws a clear error message before execution
- Suggests alternative approaches without elevated privileges
Test Coverage
Added comprehensive tests in bash.test.ts:
- ✅ Rejects commands starting with sudo
- ✅ Rejects sudo in command chains
- ✅ Allows commands with "sudo" in non-command context
- ✅ Snapshot test for error message consistency
- ✅ Basic bash functionality tests
Related
Fixes #652
🤖 Generated with opencode