|
| 1 | +# Implementation Plan |
| 2 | + |
| 3 | +- [ ] 1. Set up package structure and base interfaces |
| 4 | + - [ ] 1.1 Create `src/core/cli/` package directory structure |
| 5 | + - Create `src/core/cli/__init__.py` with public API exports |
| 6 | + - Create `src/core/cli/applicators/__init__.py` for domain applicators |
| 7 | + - _Requirements: 10.1, 10.2, 10.3_ |
| 8 | + - [ ] 1.2 Define `DomainApplicator` protocol and base types |
| 9 | + - Create `src/core/cli/protocols.py` with `DomainApplicator` protocol |
| 10 | + - Define common type aliases and constants |
| 11 | + - _Requirements: 6.1, 8.1, 8.2_ |
| 12 | + - [ ] 1.3 Write property test for domain applicator isolation |
| 13 | + - **Property 3: Domain Applicator Isolation** |
| 14 | + - **Validates: Requirements 6.2** |
| 15 | + |
| 16 | +- [ ] 2. Extract ArgumentParserBuilder |
| 17 | + - [ ] 2.1 Create `ArgumentParserBuilder` class |
| 18 | + - Create `src/core/cli/argument_parser_builder.py` |
| 19 | + - Extract `build_cli_parser()` logic into builder methods organized by domain |
| 20 | + - Implement `_add_server_arguments`, `_add_backend_arguments`, `_add_logging_arguments`, etc. |
| 21 | + - _Requirements: 1.1, 1.5_ |
| 22 | + - [ ] 2.2 Update `cli.py` to use `ArgumentParserBuilder` |
| 23 | + - Replace `build_cli_parser()` with delegation to `ArgumentParserBuilder().build()` |
| 24 | + - Maintain backward compatibility of `build_cli_parser()` function signature |
| 25 | + - _Requirements: 7.1, 7.5_ |
| 26 | + - [ ] 2.3 Write unit tests for ArgumentParserBuilder |
| 27 | + - Test that all expected arguments are present |
| 28 | + - Test argument groups are correctly organized |
| 29 | + - _Requirements: 9.1_ |
| 30 | + |
| 31 | +- [ ] 3. Extract domain applicators |
| 32 | + - [ ] 3.1 Create ServerApplicator |
| 33 | + - Create `src/core/cli/applicators/server_applicator.py` |
| 34 | + - Extract host, port, timeout, command_prefix, context_window logic |
| 35 | + - _Requirements: 6.1, 6.2_ |
| 36 | + - [ ] 3.2 Create LoggingApplicator |
| 37 | + - Create `src/core/cli/applicators/logging_applicator.py` |
| 38 | + - Extract log_file, log_level, capture settings, CBOR capture logic |
| 39 | + - _Requirements: 6.1, 6.2_ |
| 40 | + - [ ] 3.3 Create BackendApplicator |
| 41 | + - Create `src/core/cli/applicators/backend_applicator.py` |
| 42 | + - Extract default_backend, API keys, static_route, hybrid settings, debugging overrides |
| 43 | + - _Requirements: 6.1, 6.2_ |
| 44 | + - [ ] 3.4 Create SessionApplicator |
| 45 | + - Create `src/core/cli/applicators/session_applicator.py` |
| 46 | + - Extract session flags, planning phase, tool access, pytest settings |
| 47 | + - _Requirements: 6.1, 6.2_ |
| 48 | + - [ ] 3.5 Create AuthApplicator |
| 49 | + - Create `src/core/cli/applicators/auth_applicator.py` |
| 50 | + - Extract auth flags, SSO settings, brute force protection |
| 51 | + - _Requirements: 6.1, 6.2_ |
| 52 | + - [ ] 3.6 Create AssessmentApplicator |
| 53 | + - Create `src/core/cli/applicators/assessment_applicator.py` |
| 54 | + - Extract LLM assessment configuration |
| 55 | + - _Requirements: 6.1, 6.2_ |
| 56 | + - [ ] 3.7 Create MemoryApplicator |
| 57 | + - Create `src/core/cli/applicators/memory_applicator.py` |
| 58 | + - Extract ProxyMem configuration |
| 59 | + - _Requirements: 6.1, 6.2_ |
| 60 | + - [ ] 3.8 Create FailureHandlingApplicator |
| 61 | + - Create `src/core/cli/applicators/failure_handling_applicator.py` |
| 62 | + - Extract failure handling configuration |
| 63 | + - _Requirements: 6.1, 6.2_ |
| 64 | + - [ ] 3.9 Create additional applicators for remaining domains |
| 65 | + - Create `EditPrecisionApplicator`, `IdentityApplicator`, `RoutingApplicator`, `CompactionApplicator` |
| 66 | + - _Requirements: 6.1, 6.2_ |
| 67 | + - [ ] 3.10 Write unit tests for domain applicators |
| 68 | + - Test each applicator modifies only its domain |
| 69 | + - Test environment variable handling |
| 70 | + - _Requirements: 6.5, 9.1_ |
| 71 | + |
| 72 | +- [ ] 4. Checkpoint - Ensure all tests pass |
| 73 | + - Ensure all tests pass, ask the user if questions arise. |
| 74 | + |
| 75 | +- [ ] 5. Extract ConfigurationApplicator |
| 76 | + - [ ] 5.1 Create `ConfigurationApplicator` class |
| 77 | + - Create `src/core/cli/configuration_applicator.py` |
| 78 | + - Implement coordination of domain applicators |
| 79 | + - Handle ParameterResolution recording |
| 80 | + - _Requirements: 1.2, 1.3, 6.1_ |
| 81 | + - [ ] 5.2 Update `cli.py` to use `ConfigurationApplicator` |
| 82 | + - Replace `apply_cli_args()` internals with delegation to `ConfigurationApplicator` |
| 83 | + - Maintain backward compatibility of `apply_cli_args()` signature |
| 84 | + - _Requirements: 7.1, 7.5_ |
| 85 | + - [ ] 5.3 Write property test for argument parsing round-trip |
| 86 | + - **Property 1: Argument Parsing Round-Trip Consistency** |
| 87 | + - **Validates: Requirements 1.1, 1.2, 7.1** |
| 88 | + - [ ] 5.4 Write property test for parameter source recording |
| 89 | + - **Property 2: Parameter Source Recording Completeness** |
| 90 | + - **Validates: Requirements 1.3** |
| 91 | + |
| 92 | +- [ ] 6. Extract ErrorHandler |
| 93 | + - [ ] 6.1 Create `ErrorHandler` class |
| 94 | + - Create `src/core/cli/error_handler.py` |
| 95 | + - Extract `_handle_application_build_error()` logic |
| 96 | + - Implement `ErrorType` enum and `classify_error()` method |
| 97 | + - Implement specialized message formatters |
| 98 | + - _Requirements: 5.1, 5.2, 5.3, 5.4, 5.5_ |
| 99 | + - [ ] 6.2 Update `cli.py` to use `ErrorHandler` |
| 100 | + - Replace `_handle_application_build_error()` with delegation to `ErrorHandler` |
| 101 | + - _Requirements: 5.1_ |
| 102 | + - [ ] 6.3 Write property test for error classification |
| 103 | + - **Property 4: Error Classification Consistency** |
| 104 | + - **Validates: Requirements 5.1, 5.2, 5.3, 5.4** |
| 105 | + |
| 106 | +- [ ] 7. Extract LoggingConfigurator |
| 107 | + - [ ] 7.1 Create `LoggingConfigurator` class |
| 108 | + - Create `src/core/cli/logging_configurator.py` |
| 109 | + - Extract `_configure_logging()`, `_with_timestamp_suffix()`, `_apply_pid_suffixes()` logic |
| 110 | + - _Requirements: 4.1, 4.2, 4.3_ |
| 111 | + - [ ] 7.2 Update `cli.py` to use `LoggingConfigurator` |
| 112 | + - Replace logging configuration functions with delegation to `LoggingConfigurator` |
| 113 | + - _Requirements: 4.1_ |
| 114 | + - [ ] 7.3 Write property test for timestamp suffix format |
| 115 | + - **Property 5: Timestamp Suffix Format Validity** |
| 116 | + - **Validates: Requirements 4.2** |
| 117 | + |
| 118 | +- [ ] 8. Extract PrivilegeChecker |
| 119 | + - [ ] 8.1 Create `PrivilegeChecker` class with injectable platform detector |
| 120 | + - Create `src/core/cli/privilege_checker.py` |
| 121 | + - Extract `_is_admin()`, `_has_privilege_functionality()`, `_check_privileges()` logic |
| 122 | + - Define `PlatformDetector` protocol for testability |
| 123 | + - _Requirements: 3.1, 3.2, 3.3, 3.4_ |
| 124 | + - [ ] 8.2 Update `cli.py` to use `PrivilegeChecker` |
| 125 | + - Replace privilege checking functions with delegation to `PrivilegeChecker` |
| 126 | + - _Requirements: 3.1_ |
| 127 | + - [ ] 8.3 Write property test for privilege enforcement |
| 128 | + - **Property 6: Privilege Check Enforcement** |
| 129 | + - **Validates: Requirements 3.2** |
| 130 | + |
| 131 | +- [ ] 9. Checkpoint - Ensure all tests pass |
| 132 | + - Ensure all tests pass, ask the user if questions arise. |
| 133 | + |
| 134 | +- [ ] 10. Extract ServerLifecycleManager |
| 135 | + - [ ] 10.1 Create `ServerLifecycleManager` class |
| 136 | + - Create `src/core/cli/server_lifecycle_manager.py` |
| 137 | + - Extract `is_port_in_use()`, `_daemonize()`, `_maybe_run_as_daemon()` logic |
| 138 | + - Implement server startup coordination |
| 139 | + - _Requirements: 2.1, 2.2, 2.3, 2.4, 2.5_ |
| 140 | + - [ ] 10.2 Update `cli.py` to use `ServerLifecycleManager` |
| 141 | + - Replace server lifecycle logic in `main()` with delegation to `ServerLifecycleManager` |
| 142 | + - _Requirements: 2.1_ |
| 143 | + - [ ] 10.3 Write unit tests for ServerLifecycleManager |
| 144 | + - Test port availability checking |
| 145 | + - Test daemon mode handling |
| 146 | + - Test server coordination |
| 147 | + - _Requirements: 9.1_ |
| 148 | + |
| 149 | +- [ ] 11. Refactor main() to thin facade |
| 150 | + - [ ] 11.1 Simplify `main()` function |
| 151 | + - Reduce `main()` to orchestration of extracted services |
| 152 | + - Ensure all business logic is delegated to services |
| 153 | + - _Requirements: 10.4_ |
| 154 | + - [ ] 11.2 Update `src/core/cli/__init__.py` with public API |
| 155 | + - Export `parse_cli_args`, `apply_cli_args`, `main`, `build_cli_parser` |
| 156 | + - Export `ArgumentParserBuilder`, `ConfigurationApplicator` for advanced usage |
| 157 | + - _Requirements: 10.2, 7.4, 7.5_ |
| 158 | + - [ ] 11.3 Write property test for public API signature preservation |
| 159 | + - **Property 7: Public API Signature Preservation** |
| 160 | + - **Validates: Requirements 7.4, 7.5** |
| 161 | + |
| 162 | +- [ ] 12. Checkpoint - Ensure all tests pass |
| 163 | + - Ensure all tests pass, ask the user if questions arise. |
| 164 | + |
| 165 | +- [ ] 13. Backward compatibility verification |
| 166 | + - [ ] 13.1 Run existing CLI tests |
| 167 | + - Execute all tests in `tests/` related to CLI functionality |
| 168 | + - Verify zero test modifications required |
| 169 | + - _Requirements: 7.3, 9.2_ |
| 170 | + - [ ] 13.2 Run full test suite |
| 171 | + - Execute `./.venv/Scripts/python.exe -m pytest -m "integration or unit"` |
| 172 | + - Verify zero regressions |
| 173 | + - _Requirements: 9.2_ |
| 174 | + - [ ] 13.3 Write integration tests for end-to-end CLI behavior |
| 175 | + - Test full CLI invocation with various argument combinations |
| 176 | + - Verify output matches original implementation |
| 177 | + - _Requirements: 7.2, 9.4_ |
| 178 | + |
| 179 | +- [ ] 14. Final Checkpoint - Ensure all tests pass |
| 180 | + - Ensure all tests pass, ask the user if questions arise. |
0 commit comments