Files
kit/cmd
Ed Zynda ddd7856f9b Refactor: Extract shared code between normal and script modes (#94)
This commit addresses issue #92 by extracting duplicated code between
normal mode (cmd/root.go) and script mode (cmd/script.go) into reusable
factory functions and utilities.

## Changes Made

### New Factory Files
- **internal/agent/factory.go**: Agent creation factory with spinner support
  - `CreateAgent()` function with configurable options
  - `ParseModelName()` utility for model string parsing
  - Spinner function injection to avoid import cycles

- **internal/ui/factory.go**: CLI setup factory with standard configuration
  - `SetupCLI()` function for consistent CLI initialization
  - Usage tracking setup for supported providers
  - Model info and tool count display

- **internal/config/merger.go**: Config loading and merging utilities
  - `LoadAndValidateConfig()` for standard config loading
  - `MergeConfigs()` for script frontmatter merging

### Updated Command Files
- **cmd/root.go**: Refactored to use new factories
  - Replaced ~50 lines of agent creation logic
  - Replaced ~30 lines of CLI setup logic
  - Replaced ~20 lines of config loading logic
  - Added agentUIAdapter to handle interface compatibility

- **cmd/script.go**: Refactored to use new factories
  - Same factory usage as normal mode for consistency
  - Maintained script-specific behavior (no spinners)
  - Improved config merging with frontmatter

## Benefits
- **Reduced code duplication**: ~33 lines of duplicated code eliminated
- **Single source of truth**: Agent creation and CLI setup logic centralized
- **Consistent behavior**: Both modes now use identical underlying logic
- **Easier maintenance**: Changes apply to both modes automatically
- **Better testability**: Factory functions can be unit tested independently
- **Cleaner command files**: Focus on mode-specific logic only

## Testing
- All existing tests pass
- Build verification successful
- Both normal and script modes tested for basic functionality
- Code formatting and linting checks passed

🤖 Generated with [opencode](https://opencode.ai)

Co-authored-by: opencode <noreply@opencode.ai>
2025-06-27 17:41:18 +03:00
..
2025-06-25 14:27:19 +03:00