Related Code Files:
interactive_utils.py- The shared utility module- All Python tools listed below
Created: 2025-07-28
Status: Migration in Progress
This document tracks the migration status of all Python tools to use the unified interactive_utils.py module for consistent non-interactive mode support.
- No More EOF Errors: Clear messages instead of crashes
- Consistent Behavior: All tools work the same way
- Multiple Config Methods: Flags, env vars, .pytoolsrc
- CI/CD Ready: Automatic detection and handling
- Better User Experience: Helpful error messages
-
text_undo.py - Fully migrated with all features
- Basic confirmations ✓
- Numbered selections ✓
- Environment variables ✓
- .pytoolsrc support ✓
-
safe_file_manager.py - Fully migrated (2025-07-28)
- Risk-based confirmations ✓
- Typed phrases for high-risk operations ✓
- Numbered selections for restore ✓
- Environment variables (SFM_ASSUME_YES, SFM_FORCE_YES) ✓
- .pytoolsrc support through check_auto_yes_env ✓
- Backward compatibility maintained ✓
-
safegit.py - Fully migrated (2025-07-28)
- Multi-choice prompts (1/2/3 options) ✓
- Typed confirmations for high-risk operations ✓
- Yes/No confirmations with danger levels ✓
- Environment variables (SAFEGIT_ASSUME_YES, SAFEGIT_FORCE_YES) ✓
- .pytoolsrc support maintained ✓
- Complete fallback implementation ✓
-
replace_text_v9.py - Fully migrated (2025-07-28)
- Large change confirmations ✓
- Environment variables (REPLACE_TEXT_ASSUME_YES) ✓
- .pytoolsrc support through check_auto_yes_env ✓
- Complete fallback implementation ✓
-
replace_text_ast_v3.py - Fully migrated (2025-07-28)
- Multi-choice prompts (y/n/q) for batch operations ✓
- Basic confirmations for batch rename ✓
- Environment variables (REPLACE_TEXT_AST_ASSUME_YES) ✓
- .pytoolsrc support through check_auto_yes_env ✓
- Complete fallback implementation ✓
-
replace_text_v8.py
⚠️ - Status: Direct
input()with EOFError handling - Priority: HIGH - Still widely used
- Features needed: Basic confirmations
- Status: Direct
-
replace_text_ast_v2.py
⚠️ - Status: Direct
input()with EOFError handling - Priority: HIGH - AST refactoring (older version)
- Features needed: Multi-choice (y/N/q)
- Status: Direct
-
sync_tools_to_desktop.py
- Status: Direct
input()for sync confirmations - Features needed: Multi-choice (y/N/force)
- Status: Direct
-
safe_move.py
- Status: Direct
input()for undo selection - Features needed: Numbered selections
- Status: Direct
-
safegit_undo_stack.py
- Status: Direct
input()for confirmations - Features needed: Basic confirmations, numbered selections
- Status: Direct
-
refactor_rename.py / v2.py
- Status: Direct
input()with EOFError handling - Features needed: Basic confirmations
- Status: Direct
- api.py / api_prototype.py
- Status: REPL mode with special requirements
- Note: May need special handling for REPL
To migrate a tool:
- Import interactive_utils:
try:
from interactive_utils import (
safe_input, get_confirmation, get_multi_choice,
get_numbered_selection, check_auto_yes_env
)
except ImportError:
# Fallback for older installations
print("Warning: interactive_utils not found", file=sys.stderr)
# Provide basic fallbacks- Replace direct
input()calls:
# Before:
response = input("Confirm? [y/N]: ")
# After:
confirmed = get_confirmation(
"Confirm?",
tool_name="my_tool",
env_var="MY_TOOL_ASSUME_YES"
)- Add environment variable support:
# In argument parsing
check_auto_yes_env('my_tool', args)- Completed: ✅ safe_file_manager.py, safegit.py, replace_text_v9.py, replace_text_ast_v3.py (2025-07-28)
- Testing: Test all migrated tools for proper non-interactive behavior
- Future: Migrate remaining tools as time permits (replace_text_v8.py, replace_text_ast_v2.py, etc.)
For each migrated tool:
- [✓] Test interactive mode works normally
- [✓] Test non-interactive mode shows clear errors
- [✓] Test --yes flag works
- [✓] Test environment variable works
- [✓] Test .pytoolsrc configuration works
- [✓] Verify backward compatibility
Successfully migrated 5 critical tools to use the unified interactive_utils.py module:
- text_undo.py - First tool migrated as proof of concept
- safe_file_manager.py - Most critical file management tool
- safegit.py - Mandatory git safety wrapper
- replace_text_v9.py - Latest text replacement tool
- replace_text_ast_v3.py - Latest AST-based refactoring tool
- ✅ No More EOF Errors: All tools now show helpful error messages
- ✅ Consistent Behavior: Unified configuration and environment handling
- ✅ Multiple Config Methods: Flags > Env vars > .pytoolsrc > defaults
- ✅ Backward Compatible: All tools maintain fallback implementations
- ✅ CI/CD Ready: Automatic detection of non-interactive environments
- ✅ Better UX: Clear, actionable error messages with solution hints
❌ ERROR: Interactive confirmation required but running in non-interactive mode.
Use --yes flag to skip confirmation
Or set TEXT_UNDO_ASSUME_YES=1 environment variable
Or set 'assume_yes = true' in .pytoolsrc [text_undo] section
Remaining tools can be migrated as needed following the established pattern. The framework is proven and stable for production use.