Split monolithic commands.rs (1525 lines) into 7 domain-focused modules to improve maintainability and readability while preserving the external API. ## Changes ### Module Structure Created `commands/` directory with domain-based organization: - **provider.rs** (946 lines, 15 commands) - Provider CRUD operations (get, add, update, delete, switch) - Usage query integration - Endpoint speed testing and custom endpoint management - Sort order management - Largest file but highly cohesive (all provider-related) - **mcp.rs** (235 lines, 13 commands) - Claude MCP management (~/.claude.json) - SSOT MCP config management (config.json) - Sync operations (Claude ↔ Codex) - Import/export functionality - **config.rs** (153 lines, 8 commands) - Config path queries (Claude/Codex) - Directory operations (open, pick) - Config status checks - Parameter compatibility layer (app_type/app/appType) - **settings.rs** (40 lines, 5 commands) - App settings management - App restart functionality - app_config_dir override (Store integration) - **plugin.rs** (36 lines, 4 commands) - Claude plugin management (~/.claude/config.json) - Plugin status and config operations - **misc.rs** (45 lines, 3 commands) - External link handling - Update checks - Portable mode detection - **mod.rs** (15 lines) - Module exports via `pub use` - Preserves flat API structure ### API Preservation - Used `pub use` pattern to maintain external API - All commands still accessible as `commands::function_name` - Zero breaking changes for frontend code - lib.rs invoke_handler unchanged (48 commands registered) ## Statistics - Files: 1 → 7 (modular organization) - Lines: 1525 → 1470 (net -55 lines, -3.6%) - Commands: 48 → 48 (all preserved) - Average file size: 210 lines (excluding provider.rs) - Compilation: ✅ Success (6.92s, 0 warnings) - Tests: ✅ 4/4 passed ## Benefits - **Maintainability**: Easier to locate and modify domain-specific code - **Readability**: Smaller files (~200 lines) vs monolithic 1500+ lines - **Testability**: Can unit test individual modules in isolation - **Scalability**: Clear pattern for adding new command groups - **Zero Risk**: No API changes, all tests passing ## Design Decisions 1. **Domain-based split**: Organized by business domain (provider, mcp, config) rather than technical layers (crud, query, sync) 2. **Preserved provider.rs size**: Kept at 946 lines to maintain high cohesion (all provider-related operations together). Can be further split in Phase 2.1 if needed. 3. **Parameter compatibility**: Retained multiple parameter names (app_type, app, appType) for backward compatibility with different frontend call styles ## Phase 2 Status: ✅ 100% Complete Ready for Phase 3: Adding integration tests. Co-authored-by: Claude <noreply@anthropic.com>
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
#![allow(non_snake_case)]
|
||
|
||
use crate::config::ConfigStatus;
|
||
|
||
/// Claude 插件:获取 ~/.claude/config.json 状态
|
||
#[tauri::command]
|
||
pub async fn get_claude_plugin_status() -> Result<ConfigStatus, String> {
|
||
crate::claude_plugin::claude_config_status()
|
||
.map(|(exists, path)| ConfigStatus {
|
||
exists,
|
||
path: path.to_string_lossy().to_string(),
|
||
})
|
||
.map_err(|e| e.to_string())
|
||
}
|
||
|
||
/// Claude 插件:读取配置内容(若不存在返回 Ok(None))
|
||
#[tauri::command]
|
||
pub async fn read_claude_plugin_config() -> Result<Option<String>, String> {
|
||
crate::claude_plugin::read_claude_config().map_err(|e| e.to_string())
|
||
}
|
||
|
||
/// Claude 插件:写入/清除固定配置
|
||
#[tauri::command]
|
||
pub async fn apply_claude_plugin_config(official: bool) -> Result<bool, String> {
|
||
if official {
|
||
crate::claude_plugin::clear_claude_config().map_err(|e| e.to_string())
|
||
} else {
|
||
crate::claude_plugin::write_claude_config().map_err(|e| e.to_string())
|
||
}
|
||
}
|
||
|
||
/// Claude 插件:检测是否已写入目标配置
|
||
#[tauri::command]
|
||
pub async fn is_claude_plugin_applied() -> Result<bool, String> {
|
||
crate::claude_plugin::is_claude_config_applied().map_err(|e| e.to_string())
|
||
}
|