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:**
- `Cargo.toml`
- `Cargo.toml` - `thiserror` and `derive_more` are already present
**Changes:**
- Add `thiserror` for streamlined error handling
- Add `derive_more` for automatic trait implementations
## 2. Replace Manual Debug Implementations with Derives
## ✅ 2. Replace Manual Debug Implementations with Derives - MOSTLY COMPLETED
**Files affected:**
- `src/meta_plugin/digest.rs` - Hasher enum
- `src/meta_plugin/command.rs` - MetaPluginCommand struct
- Various other structs that manually implement Debug
- Most structs now use `#[derive(Debug)]` instead of manual implementations
- Remaining manual implementations appear intentional for specific formatting
**Changes:**
- Replace manual `fmt::Debug` implementations with `#[derive(Debug)]`
- Remove redundant debug formatting code
## 3. Replace Manual Default Implementations with Derives
## ✅ 3. Replace Manual Default Implementations with Derives - PARTIALLY COMPLETED
**Files affected:**
- `src/meta_plugin/hostname.rs` - HostnameMetaPlugin
- `src/meta_plugin/read_time.rs` - ReadTimeMetaPlugin
- `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
- Many plugins use `#[derive(Default)]` or `#[derive(SmartDefault)]`
- Some still have manual implementations that could potentially be simplified
**Changes:**
- Use `#[derive(Default)]` where appropriate
- Use `#[derive(SmartDefault)]` from smart-default for complex defaults
- Remove manual Default implementations
## 4. Use thiserror for Error Types
## ✅ 4. Use thiserror for Error Types - PARTIALLY COMPLETED
**Files affected:**
- `src/modes/server/mcp/tools.rs` - ToolError enum
- `src/services/error.rs` - CoreError enum (already uses thiserror, check for consistency)
- Any other custom error types
- `src/services/error.rs` - CoreError enum uses thiserror ✅
- `src/modes/server/mcp/tools.rs` - ToolError enum could be updated
**Changes:**
- 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
## 🔄 5. Use derive_more for Common Trait Implementations - PENDING
**Files affected:**
- Types that wrap other types and need common trait implementations like:
- `Display`, `From`, `Into`, `Deref`, `DerefMut`
- Specifically look for wrapper types that could benefit from:
- `derive_more::Display`
- `derive_more::From`
- `derive_more::Into`
- `derive_more::Deref`
- `derive_more::DerefMut`
- Wrapper types throughout the codebase could benefit from derive_more
- This would further reduce boilerplate code
## 6. Enhance Serde Usage
## 6. Enhance Serde Usage - MOSTLY COMPLETED
**Files affected:**
- Response types in `src/modes/server/common.rs`
- Configuration types throughout the codebase
- Any structs that manually implement serialization/deserialization
- Most response and configuration types use `#[derive(Serialize, Deserialize)]`
- Field naming appears consistent
**Changes:**
- 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
## ✅ 7. Improve Strum Usage for Enums - COMPLETED
**Files affected:**
- Enum types that have string conversions throughout the codebase
- `src/compression_engine.rs` - CompressionType
- `src/meta_plugin/mod.rs` - MetaPluginType
- `src/compression_engine.rs` - CompressionType uses strum ✅
- `src/meta_plugin/mod.rs` - MetaPluginType uses strum ✅
**Changes:**
- 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
## 🔄 8. Code Organization Improvements - ONGOING
**Files affected:**
- All source files
- All source files could benefit from consistent derive ordering and import organization
**Changes:**
- 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 Status
## 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
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
## Remaining Opportunities
## Testing Strategy
- Run tests after each major change category
- Ensure no functionality is broken by derive replacements
- Verify error messages remain clear and informative
- Check that serialization/deserialization behavior is preserved
- Apply `#[derive(thiserror::Error)]` to `ToolError` in `src/modes/server/mcp/tools.rs`
- Use `derive_more` for wrapper types to reduce boilerplate
- Ensure consistent import ordering across all files
- Standardize derive attribute ordering