Last updated: 2026-06-02
This document summarizes the implementation of a missing abstraction layer between the CLI and core components in the TeaAgent project.
The CLI handler (cli/_handlers/_agent.py) was directly instantiating core components like RunStore, GitBranchSandbox, UndoJournal, and calling run_chat_agent directly. This created tight coupling between the CLI and core, making the code harder to test and maintain.
Created a new abstraction layer in teaagent/cli/execution.py that provides:
- CommandExecutor Interface - Abstract base class for executing agent commands
- AgentExecutionFactory - Factory class for constructing all required components
- ExecutionContext - Dataclass to hold all execution context data
- DefaultCommandExecutor - Default implementation of the command executor
teaagent/cli/execution.py- New abstraction layer module (209 lines)tests/test_cli_execution.py- Unit tests for the new abstraction layer (144 lines)
teaagent/cli/_handlers/_agent.py- Refactored to use the new abstraction layer- Added import of execution module
- Replaced direct component instantiation with factory methods
- Replaced direct
run_chat_agentcall with executor pattern - Reduced coupling between CLI and core
store = RunStore(args.root)
audit = store.audit_logger()
undo_journal = UndoJournal(args.root)
git_sandbox = GitBranchSandbox(args.root, run_id='pending')
# ... more direct instantiation
result = run_chat_agent(task, adapter, config, ...)factory = AgentExecutionFactory(args.root)
store = factory.create_run_store()
audit = factory.create_audit_logger(store)
undo_journal = factory.create_undo_journal()
git_sandbox = factory.create_git_sandbox(run_id='pending')
# ... more factory methods
config = factory.create_chat_agent_config(...)
context = factory.create_execution_context(...)
executor = DefaultCommandExecutor()
result = executor.execute(context)- Separation of Concerns - CLI handlers now focus on argument parsing and user interaction, not component construction
- Testability - Components can be mocked more easily through the factory interface
- Maintainability - Component construction logic is centralized in one place
- Extensibility - New executor implementations can be added without modifying CLI handlers
- Type Safety - ExecutionContext provides a clear contract for what data is needed
All relevant tests pass:
tests/test_cli_ergonomics_handlers.py- 23 passedtests/test_ergonomics.py- 36 passedtests/test_cli_execution.py- 5 passed (new tests)tests/test_cli_chat.py- 41 passed (1 skipped, 1 deselected - unrelated to changes)
Total: 105 tests passed
CLI Handler (_agent.py)
↓ uses
AgentExecutionFactory
↓ creates
ExecutionContext + Components
↓ executes
CommandExecutor (DefaultCommandExecutor)
↓ calls
Core (run_chat_agent, etc.)
- Add more executor implementations for different execution strategies
- Consider adding a builder pattern for complex configurations
- Add integration tests for the full execution flow
- Consider extracting telemetry setup into the factory as well