Related Code Files:
interactive_utils_v2.py- Enhanced shared utility module- All Python tools with interactive prompts
We need to update 10+ tools to use the common interactive_utils_v2.py module for consistent non-interactive mode handling. This will eliminate EOF errors and provide clear, actionable error messages across all tools.
The new version now supports ALL interaction patterns found in our tools:
- ✅ Basic yes/no confirmations -
get_confirmation() - ✅ Typed phrase confirmations -
get_confirmation(typed_confirmation="DELETE") - ✅ Multi-choice prompts -
get_multi_choice()for y/n/force, y/n/q - ✅ Numbered selection menus -
get_numbered_selection()for restore/undo - ✅ Multi-step confirmations -
get_multi_confirmation()for dangerous ops - ✅ Environment variable support - Standardized checking
- ✅ Force flags - Support for --force in addition to --yes
Current State: Limited non-interactive support (only --force) Interactive Patterns:
- Three-way prompt: "y/N/force"
- Basic y/N confirmations
Migration Tasks:
# Replace
response = input("Proceed with sync? (y/N/force): ").strip().lower()
# With
choice = get_multi_choice(
"Proceed with sync?",
[('y', PromptChoice.YES), ('n', PromptChoice.NO), ('force', PromptChoice.FORCE)],
default=PromptChoice.NO,
tool_name='sync_tools_to_desktop',
env_var='SYNC_TOOLS_ASSUME_YES'
)Current State: Partial migration (confirmations done, selections missing) Interactive Patterns:
- ✅ Y/n confirmations (already migrated)
- ❌ Numbered selection for interactive undo
Migration Tasks:
# Add support for numbered selection
if args.interactive:
selection = get_numbered_selection(
"Select operation to undo",
[str(op) for op in operations],
tool_name='text_undo',
env_var='TEXT_UNDO',
flag_hint='--operation ID'
)Current State: Good support but not using common module Interactive Patterns:
- Y/n confirmations
- Numbered selection for undo
Migration Tasks:
- Import interactive_utils_v2
- Replace custom input handling with common functions
Current State: Limited non-interactive support Interactive Patterns:
- Y/n confirmations
- Numbered selection: "Select operation to undo (1-10)"
Migration Tasks:
- Add proper argument parsing for --yes flag
- Use get_numbered_selection() for interactive mode
- Add environment variable support
Current State: Full non-interactive support Interactive Patterns:
- File-by-file confirmations with quit option (y/N/q)
- Batch confirmations
Migration Tasks:
- Could benefit from using get_multi_choice() for consistency
- Already handles non-interactive well
Current State: Good support Migration Tasks:
- Minor: Use common module for consistency
Current State: Interactive REPL by design Migration Tasks:
- These are meant to be interactive
- Could add batch mode support using common module
# Create test script
cat > test_interactive_utils.py << 'EOF'
#!/usr/bin/env python3
from interactive_utils_v2 import *
# Test all functions
print("Testing confirmations...")
result = get_confirmation("Test confirm?", tool_name="test", env_var="TEST_ASSUME_YES")
print(f"Result: {result}")
print("\nTesting multi-choice...")
choice = get_multi_choice(
"Choose action",
[('y', PromptChoice.YES), ('n', PromptChoice.NO), ('f', PromptChoice.FORCE)],
tool_name="test"
)
print(f"Choice: {choice}")
print("\nTesting numbered selection...")
selection = get_numbered_selection(
"Select item",
["Option 1", "Option 2", "Option 3"],
tool_name="test"
)
print(f"Selected: {selection}")
EOF
# Test in different modes
python test_interactive_utils.py # Interactive
echo "" | python test_interactive_utils.py # Non-interactive
TEST_ASSUME_YES=1 python test_interactive_utils.py # With env var# Standard migration template for each tool
# 1. Add imports
try:
from interactive_utils_v2 import (
safe_input, get_confirmation, get_multi_choice,
get_numbered_selection, check_auto_yes_env,
get_tool_env_var, Colors, PromptChoice
)
HAS_INTERACTIVE_UTILS = True
except ImportError:
HAS_INTERACTIVE_UTILS = False
# Provide fallbacks
# 2. Update argument parsing
parser.add_argument('--yes', '-y', action='store_true',
help='Auto-confirm prompts')
parser.add_argument('--non-interactive', action='store_true',
help='Fail instead of prompting')
# 3. Check environment
check_auto_yes_env('tool_name', args)
# 4. Replace input() calls
# See specific patterns above- Apply migration template
- Test interactive mode
- Test non-interactive mode
- Test with environment variables
- Update tool documentation
# Test suite for all migrated tools
for tool in text_undo.py sync_tools_to_desktop.py safe_move.py; do
echo "Testing $tool"
# Test non-interactive detection
echo "" | python $tool --help
# Test with flags
python $tool --yes --dry-run
# Test with env vars
TOOL_ASSUME_YES=1 python $tool --dry-run
done- No EOF Errors: All tools handle non-interactive gracefully
- Clear Messages: Users know exactly what flags/env vars to use
- Consistent Behavior: All tools use same patterns
- Backward Compatible: Existing scripts continue to work
- CI/CD Ready: All tools work in automated environments
- Phase 1: 1 hour (high-impact tools)
- Phase 2: 1 hour (complex interactions)
- Phase 3: 30 minutes (verification)
- Phase 4: 30 minutes (special cases)
- Testing: 1 hour
Total: ~4 hours for complete migration
- Update CLAUDE.md with new non-interactive guidelines
- Create NON_INTERACTIVE_GUIDE.md with examples
- Add to release notes
- Consider making interactive_utils_v2.py the standard