Related Code Files:
interactive_utils.py- The unified solution for all interactive promptstext_undo.py- Example of migrated toolINTERACTIVE_MIGRATION_PLAN.md- Complete migration strategy
We've created a comprehensive solution for the EOF errors that occur when tools run in non-interactive environments (CI/CD, pipes, scripts). Instead of ugly stack traces, users now get clear, actionable error messages.
A shared module that ALL tools can use for consistent non-interactive handling:
from interactive_utils import (
get_confirmation, # Yes/no prompts
get_multi_choice, # y/n/force, y/n/q prompts
get_numbered_selection, # Select from list (1-10)
get_multi_confirmation, # Multiple confirmations
safe_input, # Safe input with defaults
check_auto_yes_env # Environment variable support
)The module handles ALL interaction patterns found in our tools:
| Pattern | Function | Example |
|---|---|---|
| Yes/No | get_confirmation() |
"Proceed? [y/N]" |
| Typed Phrase | get_confirmation(typed_confirmation="DELETE") |
"Type 'DELETE' to confirm" |
| Multi-Choice | get_multi_choice() |
"Action? [y/N/force]" |
| Numbered List | get_numbered_selection() |
"Select (1-10) or 0 to cancel" |
| Multi-Step | get_multi_confirmation() |
Multiple dangerous confirmations |
Every function gracefully handles non-interactive mode:
# EOF error before:
echo "" | python tool.py
# EOFError: EOF when reading a line
# Clear message after:
echo "" | python tool.py
# ERROR: Interactive confirmation required but running in non-interactive mode.
# Use --yes flag to skip confirmation
# Or set TOOL_ASSUME_YES=1 environment variableStandardized environment variable support:
{TOOL}_ASSUME_YES=1- Auto-confirm prompts{TOOL}_FORCE_YES=1- Force dangerous operations{TOOL}_NONINTERACTIVE=1- Strict non-interactive mode
text_undo.py has been migrated as an example:
# Before (crashes with EOF):
confirm = input(f"Proceed with undo? (y/N): ")
# After (handles non-interactive gracefully):
if not get_confirmation(
"Proceed with undo?",
tool_name='text_undo',
env_var='TEXT_UNDO_ASSUME_YES'
):
print("Cancelled.")
return- sync_tools_to_desktop.py - No env var support
- text_undo.py - Needs numbered selection support
- safegit_undo_stack.py - Limited non-interactive support
- safe_move.py - Not using common module
- refactor_rename.py/v2.py - For consistency
- safe_file_manager.py - Has full support
- safegit.py - Has full support
- replace_text_ast_v2/v3.py - Has full support
- No More EOF Errors - Clear messages instead of crashes
- CI/CD Ready - All tools work in automation
- Consistent UX - Same behavior across all tools
- User Friendly - Clear instructions on what to do
- Backward Compatible - Existing scripts continue to work
- Migrate remaining tools using the template
- Test in various non-interactive environments
- Update documentation
- Add to release notes as a major improvement
This solution ensures that all Code Intelligence Toolkit tools work seamlessly in both interactive terminals and automated environments!