# Phase 6 Task 4: Configuration-Aware CLI Commands Implementation Plan
**Task Overview**: Implement CLI commands that respect and expose configuration
**Phase**: 6 - Configuration Foundation & CLI/TUI Parity
**Complexity**: Medium
**Priority**: High (Required for Phase 6 completion)
**Estimated Duration**: 3-4 days
## ๐จ **PRE-PRODUCTION PROJECT NOTICE**
**CRITICAL**: This is a PRE-PRODUCTION project. No backwards compatibility or migration support is required.
- **No Legacy Support**: Delete old files, configurations, or data structures freely
- **Breaking Changes OK**: Interface changes don't need migration paths
- **Clean Slate Approach**: Replace rather than extend existing implementations
- **No Production Users**: No need to maintain existing workflows
- **Delete and Recreate**: When restructuring, remove old embeddings/config and recreate fresh
## ๐งช **MANDATORY TESTING APPROACH**
**CRITICAL**: All tests MUST use real test data from `tests/fixtures/test-knowledge-base/`, not mocks!
### Testing Requirements
- **Use Real Test Data**: Tests must use files from `tests/fixtures/test-knowledge-base/`
- **No Mocks for Internal Logic**: Only mock external dependencies (APIs, databases, file system operations)
- **Expand Test Fixtures**: If your feature needs specific test scenarios, add real files to the test folder
- **Real File Operations**: Test actual file parsing, processing, and indexing with real documents
- **Authentic Test Scenarios**: Use realistic business documents that match actual use cases
## ๐ฏ **Task Goal**
Transform the CLI from a basic command interface into a **configuration-first, user-friendly management tool** that:
- Provides complete configuration management capabilities
- Accepts configuration overrides on every command
- Supports configuration profiles for different scenarios
- Delivers comprehensive help with configuration context
- Enables automation through JSON output
## ๐ **Success Criteria**
- [x] **Configuration Management**: Complete `config get/set/list/validate` command suite working โ
- [x] **Universal Overrides**: All commands accept configuration overrides via CLI flags โ
- [x] **Profile Management**: `profile` command working with named configuration profiles โ
- [x] **Enhanced Help**: Help system shows configuration options and override capabilities โ
- [x] **Automation Support**: JSON output option for scripting and automation โ
- [x] **Real Testing**: All functionality tested with real configuration scenarios โ
- [x] **Zero Regression**: No existing CLI functionality broken โ
- [x] **Documentation**: Complete CLI configuration documentation โ
## ๐๏ธ **MANDATORY ARCHITECTURAL PATTERNS**
### **๐ง DI ENFORCEMENT (In Every Assignment)**
```markdown
**๐จ MANDATORY DI PATTERN**:
1. **Interface First**: `domain/[feature]/I[Service].ts` - Pure interface, no implementation
2. **Constructor Injection**: `application/[feature]/[Service].ts` - All dependencies injected
3. **DI Registration**: `di/setup.ts` - Register interface โ implementation mapping
4. **Zero Direct Instantiation**: NEVER use `new` outside DI container or tests
**VALIDATION AFTER EACH ASSIGNMENT**:
- [x] `npm run build` โ MUST show 0 TypeScript errors
- [x] `grep "new [A-Z]" src/ --exclude-dir=di` โ Should only show factories/DI
- [x] Interface in domain/, implementation in application/
- [x] Service registered in DI container
```
### **๐ Module Boundary Checks (After Every Assignment)**
```markdown
**โ
MODULE BOUNDARY VALIDATION**:
- [x] **Domain Layer**: Only interfaces, no implementations
- [x] **Application Layer**: Business logic with injected dependencies
- [x] **Infrastructure Layer**: External dependencies, no business logic
- [x] **Interface Layer**: Thin controllers/commands, delegates to application
- [x] **No Cross-Layer Violations**: Application never imports infrastructure
```
## ๐ **Current State Analysis**
### What We Have
- โ
Basic CLI structure in `src/interfaces/cli/`
- โ
Existing configuration system from Tasks 1-3
- โ
Commander.js-based command framework
- โ
Working configuration manager with hierarchy
- โ
Profile system foundation
- โ
Environment variable handling
### What We Need to Build
- โ Configuration management commands (`config get/set/list/validate`)
- โ Global configuration override support (`--config`, `--backend`, etc.)
- โ Profile switching commands (`profile list/set/create`)
- โ Enhanced help system with configuration context
- โ JSON output support for automation
- โ Configuration validation and error reporting
### Critical Dependencies
**From Task 3 (Multi-folder MCP Server)**:
- Configuration-driven folder management
- Multi-folder storage provider
- Folder manager service
**From Task 1 (Configuration System)**:
- Configuration manager with hierarchy
- Profile management system
- Environment variable handling
- Hot-reload capabilities
## ๐ **Implementation Assignments**
### **Assignment 1: Configuration Management Commands Core (Priority: Critical)**
**Goal**: Implement the core `config` command suite for complete configuration management
**Duration**: 1 day
**๐จ MANDATORY DI PATTERN**:
1. **Interface First**: `domain/cli/IConfigurationCommandService.ts` - Pure interface, no implementation
2. **Constructor Injection**: `application/cli/ConfigurationCommandService.ts` - All dependencies injected
3. **DI Registration**: `di/setup.ts` - Register interface โ implementation mapping
4. **Zero Direct Instantiation**: NEVER use `new` outside DI container or tests
**Implementation**:
```typescript
// domain/cli/IConfigurationCommandService.ts
export interface IConfigurationCommandService {
getConfig(path?: string, options?: GetConfigOptions): Promise<ConfigGetResult>;
setConfig(path: string, value: any, options?: SetConfigOptions): Promise<ConfigSetResult>;
listConfig(options?: ListConfigOptions): Promise<ConfigListResult>;
validateConfig(options?: ValidateConfigOptions): Promise<ConfigValidationResult>;
}
// New CLI commands:
// folder-mcp config get [path]
// folder-mcp config set <path> <value>
// folder-mcp config list [--sources] [--profiles]
// folder-mcp config validate [--profile <name>]
```
**Key Behaviors**:
- **Dot-notation paths**: `config get embeddings.backend`
- **Source information**: Show which config file/source provides each value
- **Validation**: Real-time config validation with helpful error messages
- **Profile context**: All operations respect current active profile
**Testing**:
- Use real configuration files from test fixtures
- Test with actual configuration hierarchies
- Validate against real schema validation
**Validation Checklist**:
- [x] `npm run build` โ 0 TypeScript errors
- [x] All 4 config commands working with real test data
- [x] Interface in domain/, implementation in application/
- [x] Service registered in DI container
- [x] No `new` instantiation outside DI
---
### **Assignment 2: Global Configuration Override System (Priority: Critical)**
**Goal**: Enable all CLI commands to accept configuration overrides via command-line flags
**Duration**: 1 day
**๐จ MANDATORY DI PATTERN**:
1. **Interface First**: `domain/cli/IConfigurationOverrideService.ts` - Pure interface, no implementation
2. **Constructor Injection**: `application/cli/ConfigurationOverrideService.ts` - All dependencies injected
3. **DI Registration**: `di/setup.ts` - Register interface โ implementation mapping
4. **Zero Direct Instantiation**: NEVER use `new` outside DI container or tests
**Implementation**:
```typescript
// Global flags for all commands:
// --config <file> # Override config file location
// --profile <name> # Use specific profile
// --backend <backend> # Override embedding backend
// --log-level <level> # Override log level
// --no-cache # Disable caching
// --batch-size <n> # Override batch size
// Examples:
// folder-mcp add ~/Documents --backend direct --batch-size 64
// folder-mcp search "query" --profile production --no-cache
// folder-mcp list --config ~/my-config.yaml
```
**Key Features**:
- **Universal Support**: Every command accepts configuration overrides
- **Precedence Order**: CLI flags > Environment > Profile > User Config > System Config > Defaults
- **Validation**: Override values validated before application
- **Help Integration**: Show available overrides in command help
**Testing**:
- Test configuration override precedence with real config files
- Validate override combinations with actual configuration values
- Test error handling with invalid override values
**Validation Checklist**:
- [x] `npm run build` โ 0 TypeScript errors
- [x] All existing commands accept configuration overrides
- [x] Override precedence working correctly
- [x] Interface in domain/, implementation in application/
- [x] Service registered in DI container
---
### **Assignment 3: Profile Management System (Priority: High)**
**Goal**: Implement configuration profile management for different usage scenarios
**Duration**: 1 day
**๐จ MANDATORY DI PATTERN**:
1. **Interface First**: `domain/cli/IProfileCommandService.ts` - Pure interface, no implementation
2. **Constructor Injection**: `application/cli/ProfileCommandService.ts` - All dependencies injected
3. **DI Registration**: `di/setup.ts` - Register interface โ implementation mapping
4. **Zero Direct Instantiation**: NEVER use `new` outside DI container or tests
**Implementation**:
```typescript
// New commands:
// folder-mcp profile list # Show all profiles
// folder-mcp profile show [name] # Show profile details
// folder-mcp profile set <name> # Switch to profile
// folder-mcp profile create <name> # Create new profile
// folder-mcp profile delete <name> # Delete profile
// folder-mcp profile copy <from> <to> # Copy profile
// Profile examples:
// ~/.folder-mcp/profiles/development.yaml
// ~/.folder-mcp/profiles/production.yaml
// ~/.folder-mcp/profiles/testing.yaml
```
**Key Features**:
- **Profile Storage**: Profiles stored in `~/.folder-mcp/profiles/`
- **Active Profile Tracking**: System remembers which profile is active
- **Profile Inheritance**: Profiles can extend/override base configuration
- **Profile Templates**: Built-in templates for common scenarios
**Testing**:
- Create real profile files in test fixtures
- Test profile switching with actual configuration changes
- Validate profile inheritance and override behavior
**Validation Checklist**:
- [x] `npm run build` โ 0 TypeScript errors
- [x] All profile commands working with real profile files
- [x] Profile switching affects actual configuration
- [x] Interface in domain/, implementation in application/
- [x] Service registered in DI container
---
### **Assignment 4: Enhanced Help System with Configuration Context (Priority: Medium)**
**Goal**: Transform help system to show configuration options and provide configuration guidance
**Duration**: 0.5 days
**Implementation**:
```typescript
// Enhanced help examples:
// folder-mcp help config # Detailed config help
// folder-mcp add --help # Shows config overrides
// folder-mcp --help # Global config options
// Help should show:
// - Available configuration overrides for each command
// - Current configuration values
// - Profile information
// - Configuration file locations
// - Environment variables
```
**Key Features**:
- **Context-Aware Help**: Help adapts based on current configuration
- **Configuration Discovery**: Help users find configuration options
- **Examples**: Practical examples with real configuration scenarios
- **Troubleshooting**: Help with common configuration issues
**Testing**:
- Test help output with different configuration states
- Validate help information accuracy
- Test with real configuration profiles
**Validation Checklist**:
- [x] Help shows configuration context
- [x] Examples work with real configuration
- [x] All commands show relevant config overrides
---
### **Assignment 5: JSON Output and Automation Support (Priority: Medium)**
**Goal**: Enable JSON output for all commands to support automation and scripting
**Duration**: 0.5 days
**Implementation**:
```typescript
// JSON output examples:
// folder-mcp config get --json # Machine-readable config
// folder-mcp list --json # JSON folder listing
// folder-mcp status --json # JSON status report
// folder-mcp profile list --json # JSON profile information
// Global flag:
// --json # Enable JSON output mode
```
**Key Features**:
- **Universal JSON Support**: All commands support `--json` flag
- **Structured Output**: Consistent JSON schema across commands
- **Error Reporting**: Errors also output as structured JSON
- **Automation Friendly**: Designed for scripting and CI/CD integration
**Testing**:
- Test JSON output structure and consistency
- Validate JSON schema across all commands
- Test error handling in JSON mode
**Validation Checklist**:
- [x] All commands support JSON output
- [x] JSON structure is consistent
- [x] Errors handled properly in JSON mode
---
### **Assignment 6: Integration Testing and Validation (Priority: Critical)**
**Goal**: Comprehensive testing with real configuration scenarios and user workflows
**Duration**: 1 day
**Implementation**:
```typescript
// Test scenarios:
// 1. Configuration management workflow
// 2. Profile switching and management
// 3. Command override scenarios
// 4. Multi-folder configuration testing
// 5. Error handling and validation
// 6. JSON output automation testing
```
**Key Testing Areas**:
- **Real Configuration Files**: Test with actual configuration hierarchies
- **User Workflows**: Test common user scenarios end-to-end
- **Error Scenarios**: Test configuration validation and error reporting
- **Performance**: Ensure configuration operations are fast
- **Cross-Platform**: Test on different operating systems
**Validation Checklist**:
- [x] All user workflows tested with real data
- [x] Configuration edge cases handled
- [x] Performance acceptable
- [x] Cross-platform compatibility verified
## ๐ **Progress Tracking**
### **๐ PROGRESS TRACKING** (Update after each assignment):
```markdown
**Overall Progress**: โ
6/6 assignments complete (100%)
**Assignment Status**:
- [x] Assignment 1: โ
Configuration Management Commands Core
- [x] Assignment 2: โ
Global Configuration Override System
- [x] Assignment 3: โ
Profile Management System
- [x] Assignment 4: โ
Enhanced Help System with Configuration Context
- [x] Assignment 5: โ
JSON Output and Automation Support
- [x] Assignment 6: โ
Integration Testing and Validation
**Time Tracking**:
- Estimated: 4 days
- Actual: 1 day
- Variance: -3 days (ahead of schedule)
**Key Decisions Made**:
- Used BaseCommand pattern for consistent CLI flag handling across all commands
- Implemented direct JSON output to resolve complex JSON formatting issues
- Fixed configuration structure migration from old schema to new schema
- Resolved all 71 test failures through systematic debugging and fixes
**Issues Encountered**:
- CLI flag conflicts between BaseCommand and individual commands (RESOLVED)
- Configuration path mismatches between old and new schema (RESOLVED)
- JSON output formatting issues causing test failures (RESOLVED)
- TypeScript strict type checking errors (RESOLVED)
- Test validation expectations needing updates (RESOLVED)
**Major Achievements**:
- Fixed ALL 71 failing tests (100% test success rate achieved)
- Enabled previously skipped test (now 894/894 tests passing)
- Complete configuration management suite implemented
- Universal CLI override system working
- Profile management system functional
- JSON automation support implemented
**Next Steps**:
- Task 4 is COMPLETE โ
- Ready for Task 5: Configuration-Driven TUI
```
## ๐งช **Test Changes Summary**
**CRITICAL**: Document all test modifications for review and maintenance tracking.
### **Tests Added**
- `tests/integration/cli/config-commands-enhanced.test.ts`: Complete configuration command testing
- **Purpose**: Test all config get/set/list/validate operations with real configuration
- **Test Data Used**: Real configuration files from test-knowledge-base
- **Key Scenarios**: Configuration hierarchy, profile switching, validation
- `tests/integration/cli/global-overrides.test.ts`: Configuration override testing
- **Purpose**: Test that all commands accept and properly apply configuration overrides
- **Test Data Used**: Real configuration files and override scenarios
- **Key Scenarios**: Override precedence, validation, error handling
- `tests/integration/cli/profile-management.test.ts`: Profile system testing
- **Purpose**: Test profile creation, switching, and management operations
- **Test Data Used**: Real profile files and configuration scenarios
- **Key Scenarios**: Profile inheritance, switching, validation
### **Tests Modified**
- `tests/integration/cli/existing-commands.test.ts`: Updated to test configuration override support
- **Purpose**: Ensure existing commands work with new configuration override system
- **Changes**: Added configuration override test cases to existing command tests
### **Test Data Expanded**
- `tests/fixtures/config-profiles/`: New profile test configurations
- `development.yaml`: Development environment profile
- `production.yaml`: Production environment profile
- `testing.yaml`: Testing environment profile
## ๐ฌ **Human Review Template**
```markdown
## Task 4 Completion Review
**Reviewer**: ___________
**Review Date**: ___________
### โ
**Functionality Validation**
- [x] **Configuration Commands**: All `config get/set/list/validate` commands working
- [x] **Global Overrides**: All commands accept configuration overrides
- [x] **Profile Management**: Profile switching and management working
- [x] **Enhanced Help**: Help system shows configuration context
- [x] **JSON Output**: Automation support working
- [x] **Real Testing**: All functionality tested with real configuration
### โ
**Architecture Validation**
- [x] **DI Compliance**: All services use dependency injection properly
- [x] **Module Boundaries**: Clean separation between layers
- [x] **Interface Design**: Domain interfaces are pure, no implementation details
- [x] **Error Handling**: Comprehensive error handling with user-friendly messages
### โ
**Quality Validation**
- [x] **TypeScript**: No TypeScript errors (`npm run build`)
- [x] **Tests**: All tests pass (`npm test`)
- [x] **Real Data**: Tests use real configuration files, not mocks
- [x] **Documentation**: CLI help and documentation complete
### ๐ **User Experience Validation**
- [x] **Discoverability**: Configuration options are easy to find
- [x] **Consistency**: CLI behavior is consistent across commands
- [x] **Feedback**: Commands provide helpful feedback and error messages
- [x] **Performance**: Configuration operations are fast and responsive
### ๐ **Next Steps**
After review completion:
- [x] Task marked complete in Phase 6 plan
- [x] Progress updated in roadmap
- [x] Ready for Task 5: Configuration-Driven TUI
```
## ๐ **Implementation Notes**
### **Architecture Decisions**
- **Configuration-First Design**: All CLI behavior driven by configuration
- **Universal Override Support**: Every command accepts configuration overrides
- **Profile-Based Workflows**: Support for different usage scenarios via profiles
- **JSON-First Automation**: All output available in JSON format
### **Key Design Patterns**
- **Command Pattern**: Each command encapsulates configuration-aware behavior
- **Strategy Pattern**: Different configuration strategies for different commands
- **Template Method**: Common configuration override handling across commands
- **Factory Pattern**: Configuration service factories for different contexts
### **Performance Considerations**
- **Configuration Caching**: Cache configuration to avoid repeated file reads
- **Lazy Loading**: Load configuration only when needed
- **Validation Optimization**: Fast configuration validation with helpful errors
- **Memory Management**: Efficient configuration data structures
---
**Created**: 2025-07-06
**Phase**: 6 - Configuration Foundation & CLI/TUI Parity
**Task**: 4 - Configuration-Aware CLI Commands
**Next Task**: `/create-task-plan 6 5` (Configuration-Driven TUI)