docs: update code optimization plan with completion status

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-27 21:49:01 -03:00
parent bacfaa4fc3
commit 2435c8bebf

116
PLAN.md
View File

@@ -1,111 +1,63 @@
# Code Optimization Plan # Code Optimization Plan - Status Update
This document outlines planned optimizations to reduce boilerplate code and improve maintainability through the use of derive macros and utility crates. This document outlines optimizations to reduce boilerplate code and improve maintainability through the use of derive macros and utility crates.
## 1. Add Utility Crates to Cargo.toml ## 1. Add Utility Crates to Cargo.toml - COMPLETED
**Files affected:** **Files affected:**
- `Cargo.toml` - `Cargo.toml` - `thiserror` and `derive_more` are already present
**Changes:** ## ✅ 2. Replace Manual Debug Implementations with Derives - MOSTLY COMPLETED
- Add `thiserror` for streamlined error handling
- Add `derive_more` for automatic trait implementations
## 2. Replace Manual Debug Implementations with Derives
**Files affected:** **Files affected:**
- `src/meta_plugin/digest.rs` - Hasher enum - Most structs now use `#[derive(Debug)]` instead of manual implementations
- `src/meta_plugin/command.rs` - MetaPluginCommand struct - Remaining manual implementations appear intentional for specific formatting
- Various other structs that manually implement Debug
**Changes:** ## ✅ 3. Replace Manual Default Implementations with Derives - PARTIALLY COMPLETED
- Replace manual `fmt::Debug` implementations with `#[derive(Debug)]`
- Remove redundant debug formatting code
## 3. Replace Manual Default Implementations with Derives
**Files affected:** **Files affected:**
- `src/meta_plugin/hostname.rs` - HostnameMetaPlugin - Many plugins use `#[derive(Default)]` or `#[derive(SmartDefault)]`
- `src/meta_plugin/read_time.rs` - ReadTimeMetaPlugin - Some still have manual implementations that could potentially be simplified
- `src/meta_plugin/read_rate.rs` - ReadRateMetaPlugin
- `src/meta_plugin/shell.rs` - ShellMetaPlugin
- `src/meta_plugin/shell_pid.rs` - ShellPidMetaPlugin
- `src/meta_plugin/keep_pid.rs` - KeepPidMetaPlugin
- `src/meta_plugin/user.rs` - UserMetaPlugin
**Changes:** ## ✅ 4. Use thiserror for Error Types - PARTIALLY COMPLETED
- Use `#[derive(Default)]` where appropriate
- Use `#[derive(SmartDefault)]` from smart-default for complex defaults
- Remove manual Default implementations
## 4. Use thiserror for Error Types
**Files affected:** **Files affected:**
- `src/modes/server/mcp/tools.rs` - ToolError enum - `src/services/error.rs` - CoreError enum uses thiserror ✅
- `src/services/error.rs` - CoreError enum (already uses thiserror, check for consistency) - `src/modes/server/mcp/tools.rs` - ToolError enum could be updated
- Any other custom error types
**Changes:** ## 🔄 5. Use derive_more for Common Trait Implementations - PENDING
- Replace manual Error trait implementations with `#[derive(thiserror::Error)]`
- Use `#[from]` attribute for automatic From implementations
- Ensure consistent error message formatting
## 5. Use derive_more for Common Trait Implementations
**Files affected:** **Files affected:**
- Types that wrap other types and need common trait implementations like: - Wrapper types throughout the codebase could benefit from derive_more
- `Display`, `From`, `Into`, `Deref`, `DerefMut` - This would further reduce boilerplate code
- Specifically look for wrapper types that could benefit from:
- `derive_more::Display`
- `derive_more::From`
- `derive_more::Into`
- `derive_more::Deref`
- `derive_more::DerefMut`
## 6. Enhance Serde Usage ## 6. Enhance Serde Usage - MOSTLY COMPLETED
**Files affected:** **Files affected:**
- Response types in `src/modes/server/common.rs` - Most response and configuration types use `#[derive(Serialize, Deserialize)]`
- Configuration types throughout the codebase - Field naming appears consistent
- Any structs that manually implement serialization/deserialization
**Changes:** ## ✅ 7. Improve Strum Usage for Enums - COMPLETED
- Ensure consistent use of `#[derive(Serialize, Deserialize)]`
- Use serde attributes for customization instead of manual implementations
- Standardize field naming conventions
## 7. Improve Strum Usage for Enums
**Files affected:** **Files affected:**
- Enum types that have string conversions throughout the codebase - `src/compression_engine.rs` - CompressionType uses strum ✅
- `src/compression_engine.rs` - CompressionType - `src/meta_plugin/mod.rs` - MetaPluginType uses strum ✅
- `src/meta_plugin/mod.rs` - MetaPluginType
**Changes:** ## 🔄 8. Code Organization Improvements - ONGOING
- Use `strum` macros consistently for enum string conversions
- Replace manual `to_string()` implementations with derives
- Ensure all enum variants are properly handled
## 8. Code Organization Improvements
**Files affected:** **Files affected:**
- All source files - All source files could benefit from consistent derive ordering and import organization
**Changes:** ## Implementation Status
- Group derives consistently at the top of struct/enum definitions
- Standardize import ordering (std, external, internal)
- Ensure consistent use of utility crates across the codebase
## Implementation Priority 1. **✅ High Priority**: Crates are already in Cargo.toml
2. **✅ Medium Priority**: Error handling mostly uses thiserror
3. **✅ Medium Priority**: Debug and Default derives mostly implemented
4. **🔄 Low Priority**: derive_more usage could be expanded
1. **High Priority**: Add crates to Cargo.toml and fix compilation issues ## Remaining Opportunities
2. **Medium Priority**: Error handling improvements with thiserror
3. **Medium Priority**: Debug and Default derive implementations
4. **Low Priority**: derive_more and other quality-of-life improvements
## Testing Strategy - Apply `#[derive(thiserror::Error)]` to `ToolError` in `src/modes/server/mcp/tools.rs`
- Use `derive_more` for wrapper types to reduce boilerplate
- Run tests after each major change category - Ensure consistent import ordering across all files
- Ensure no functionality is broken by derive replacements - Standardize derive attribute ordering
- Verify error messages remain clear and informative
- Check that serialization/deserialization behavior is preserved