feat: Add shell input/output/kill tools for background process interaction#2556
feat: Add shell input/output/kill tools for background process interaction#2556qwen-code-ci-bot wants to merge 4 commits intomainfrom
Conversation
- Add exited state check in writeToPty, resizePty, and scrollPty methods - Handle EBADF error in addition to ESRCH to fix race condition when PTY file descriptor is closed but process still exists as zombie - Fixes #2555 where long-running tasks would crash with EBADF error after approximately 10 minutes when terminal resize was triggered
📋 Review SummaryThis PR fixes a critical bug where long-running shell tasks crash with 🔍 General Feedback
🎯 Specific Feedback🔴 Critical
🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
- Import ShellKillTool from tools/shell-kill.js - Register ShellKillTool after ShellTool in the core tools registry - This enables the shell_kill tool for terminating background shell processes Test plan: - npm run build: passes - npm test -- shell-kill: 16 tests pass
- Import ShellSendInputTool from tools/shell-send-input.js - Import ShellReadOutputTool from tools/shell-read-output.js - Register both tools after ShellKillTool in the core tools registry These tools enable full interaction with background shell processes: - shell_send_input: Send input to interactive programs (e.g., REPLs, prompts) - shell_read_output: Read output from running background processes Test plan: - npm run build: passes - npm test -- shell-*: 40 tests pass (16 kill + 12 send-input + 12 read-output) - Manual testing: verified echo, bc calculator, and sleep process workflows
- Add comprehensive test review document (SHELL_KILL_TEST_REVIEW.md) - Add manual testing guide (test-shell-kill-manual.md) - Include test cases for shell_kill, shell_send_input, shell_read_output - Document all 40 unit tests and manual test procedures
Summary
This PR adds three new shell tools to enable full interaction with background processes in qwen-code.
Changes
New Tools Registered
shell_kill- Terminate background processesshell_send_input- Send input to interactive background processesshell_read_output- Read output from background processesFiles Modified
packages/core/src/config/config.ts- Register the three new toolsSHELL_KILL_TEST_REVIEW.md- Comprehensive test review documenttest-shell-kill-manual.md- Manual testing guideTesting
Unit Tests
All 40 tests pass:
Integration Tests
Verified in interactive mode with the following scenarios:
Test 1: Start background process and read output
node dist/cli.js --yolo --sandbox=false -p "启动后台进程,运行 echo 'HELLO_TEST',然后读取输出"Result: ✅ Successfully read "HELLO_TEST"
Test 2: Send input to interactive process (bc calculator)
node dist/cli.js --yolo --sandbox=false -p "启动后台进程 bc,发送输入 10+20\\n,读取输出"Result: ✅ Got result "30"
Test 3: Python REPL interaction
node dist/cli.js --yolo --sandbox=false -p "启动后台进程 python3,发送输入 print('PYTHON_OK')\\n,读取输出"Result: ✅ Got output "PYTHON_OK"
Test 4: Query process status
node dist/cli.js --yolo --sandbox=false -p "启动后台进程 sleep 10,然后检查进程状态"Result: ✅ Showed sleep process status
Test 5: Combined workflow
node dist/cli.js --yolo --sandbox=false -p "启动后台进程 bc,发送输入 5*5\\n,读取输出确认结果"Result: ✅ Got result "25"
Test Results Summary
shell_read_outputshell_send_inputshell_send_inputshell_process_statusAll 5 integration tests passed!
Use Cases
These tools enable:
Related
Addresses the need for background process interaction capabilities beyond basic
run_shell_commandwithis_background: true.