opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: prevent app hanging when executing sudo commands

Open delorenj opened this issue 6 months ago • 0 comments

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:

  1. Checks if commands start with sudo
  2. Detects sudo after common command separators (;, &&, ||, |)
  3. Throws a clear error message before execution
  4. 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

delorenj avatar Jul 03 '25 18:07 delorenj