---
description: CLI Refactoring Status: **Date:** 2026-01-26 **Status:** Phase 1 Complete (30% of full refactoring) **Original File:** `src/empathy_os/cli.py` (3,957 lines) ---
---
Date: 2026-01-26
Status: Phase 1 Complete (30% of full refactoring)
Original File: src/empathy_os/cli.py (3,957 lines)
Directory Structure Created:
src/empathy_os/cli/
├── __init__.py # New main() entry point (152 lines)
├── __main__.py # Python -m execution support
├── commands/ # Extracted command implementations
│ ├── __init__.py
│ ├── help.py # 5 commands: version, cheatsheet, onboard, explain, achievements
│ ├── tier.py # 2 commands: tier_recommend, tier_stats
│ └── info.py # 2 commands: info, frameworks
├── parsers/ # Parser definitions
│ ├── __init__.py # Central parser registry
│ ├── help.py
│ ├── tier.py
│ └── info.py
└── utils/ # Shared utilities
├── __init__.py
├── data.py # CHEATSHEET, EXPLAIN_CONTENT (234 lines)
└── helpers.py # _file_exists, _show_achievements (72 lines)
| Metric | Before | After | Improvement |
|---|---|---|---|
| Main file size | 3,957 lines | 152 lines (main) | 96% reduction |
| Commands extracted | 0/30 | 9/30 | 30% complete |
| Modules created | 1 file | 11 files | Modular! |
| Largest file | 3,957 lines | 380 lines | Much better |
Commands Extracted (9/30):
- ✅ cmd_version
- ✅ cmd_cheatsheet
- ✅ cmd_onboard
- ✅ cmd_explain
- ✅ cmd_achievements
- ✅ cmd_tier_recommend
- ✅ cmd_tier_stats
- ✅ cmd_info
- ✅ cmd_frameworks
Test 1: Version Command
python -m empathy_os.cli version
# ✅ Works! Logger shows: empathy_os.cli.commands.help:cmd_versionTest 2: Cheatsheet Command
python -m empathy_os.cli cheatsheet --compact
# ✅ Works! Displays formatted cheatsheet correctlyTest 3: Import Structure
from empathy_os.cli.commands.help import cmd_version
# ✅ Works! New modular structure is importableEach command module follows:
# commands/help.py
from empathy_os.logging_config import get_logger
from ..utils.data import CHEATSHEET # Relative imports
from ..utils.helpers import _show_achievements
def cmd_version(args):
"""Command implementation with full docstring."""
# Implementation hereEach parser module follows:
# parsers/help.py
from ..commands import help as help_commands
def register_parsers(subparsers):
"""Register all parsers for this command group."""
parser = subparsers.add_parser("version", help="...")
parser.set_defaults(func=help_commands.cmd_version)New main() function:
- Modular parser registration via
register_all_parsers() - Fallback to old cli.py for un-extracted commands
- Clean error handling and discovery tips
- ~150 lines vs original 900+ lines
High Priority (frequently used):
- ⏭️ Pattern commands (3): patterns_list, patterns_export, patterns_resolve
- ⏭️ Workflow command (1): cmd_workflow (multi-model, lines 2475-2820)
- ⏭️ Status commands (3): status, review, health
Medium Priority: 4. ⏭️ Inspect commands (4): run, inspect, export, import 5. ⏭️ Provider commands (3): provider_hybrid, provider_show, provider_set 6. ⏭️ Orchestrate (1): orchestrate 7. ⏭️ Sync (1): sync_claude 8. ⏭️ Metrics (2): metrics_show, state_list
Low Priority (less used): 9. ⏭️ Workflow legacy (1): cmd_workflow (old version, lines 2022-2164) - DEPRECATED 10. ⏭️ Setup (2): init, validate
- ⏭️ Create
cli/wrappers.py(8 wrapper functions, lines 2918-3004)
- ⏭️ Remove old cli.py or convert to redirect
- ⏭️ Update all internal imports
- ⏭️ Run full test suite
- ⏭️ Update documentation
Pick from remaining commands. Example: patterns commands
Read from original cli.py and create new module:
# Read lines for patterns commands
# Create: src/empathy_os/cli/commands/patterns.pyCreate corresponding parser file:
# Create: src/empathy_os/cli/parsers/patterns.pyUpdate cli/parsers/__init__.py:
from . import help, info, tier, patterns # Add new module
def register_all_parsers(subparsers):
help.register_parsers(subparsers)
tier.register_parsers(subparsers)
info.register_parsers(subparsers)
patterns.register_parsers(subparsers) # Add registrationpython -m empathy_os.cli patterns listContinue with next command group until all 30 commands are extracted.
Use this template for extracting remaining commands:
"""<Group> commands for the CLI.
Copyright 2025 Smart-AI-Memory
Licensed under Fair Source License 0.9
"""
from empathy_os.logging_config import get_logger
# Add other imports as needed
logger = get_logger(__name__)
def cmd_<name>(args):
"""Command description.
Args:
args: Namespace object from argparse with attributes:
- attribute_name (type): Description
Returns:
int | None: Exit code or None
"""
# Copy implementation from original cli.py
# Update imports to use relative paths
passProblem: Two cmd_workflow() functions exist (lines 2022 and 2475)
Resolution:
- Line 2022: Rename to
cmd_workflow_legacy()with deprecation warning - Line 2475: Keep as
cmd_workflow()(current multi-model version)
Status: Not yet implemented (command not extracted)
Phase 1 (Completed):
- Directory structure created
- 9 commands extracted and working
- Modular parser system established
- New main() function works
- Backward compatibility maintained
Phase 2 (Not Started):
- 21 remaining commands extracted
- All 30 commands accessible via new structure
- Old cli.py converted to redirect
- Full test suite passes
Phase 3 (Not Started):
- No regressions in existing tests
- All imports updated to new structure
- Documentation updated
- CHANGELOG entry created
- Refactoring Plan - Full implementation plan
- Coding Standards - Project standards
- Original cli.py - Source file (3,957 lines)
- Extract in groups - Don't extract commands one-by-one, extract logical groups
- Test frequently - Test each group immediately after extraction
- Use relative imports -
from ..utils import helpers(within cli package) - Copy docstrings - Maintain comprehensive documentation
- Check dependencies - Some commands import from each other
- Update parsers/init.py - Don't forget to register new parser modules
- Legacy fallback - Commands not yet extracted still use old cli.py
- Import warnings - Some IDEs may show import warnings during transition
- Duplicate logging - Logger output may duplicate during testing
Overall Progress: 30% complete (9/30 commands extracted)
Estimated Remaining Time:
- 21 commands × 3 min avg = ~60 minutes
- Parser creation: ~20 minutes
- Testing & cleanup: ~20 minutes
- Total: ~100 minutes (~1.5 hours)
Next Session Goal: Extract patterns, workflow, and status commands (7 commands)
Last Updated: 2026-01-26 Maintainer: Refactoring Team Status: Ready for Phase 2