botserver/docs/CLEANUP_WARNINGS.md

220 lines
6.1 KiB
Markdown
Raw Normal View History

2025-11-21 23:23:53 -03:00
# Code Cleanup: Removing Unused Code Warnings
This document tracks unused code warnings and the proper way to fix them.
## Strategy: NO `#[allow(dead_code)]` Bandaids
Instead, we either:
1. **USE IT** - Create API endpoints or connect to existing flows
2. **REMOVE IT** - Delete truly unused code
---
## 1. Channel Adapters (src/channels/mod.rs)
### Status: KEEP - Used via trait dispatch
**Issue**: Trait methods marked as unused but they ARE used polymorphically.
**Solution**: These are false positives. The trait methods are called through `dyn ChannelAdapter`, so the compiler doesn't detect usage. Keep as-is.
- `ChannelAdapter::send_message()` - Used by channel implementations
- `ChannelAdapter::receive_message()` - Used by channel implementations
- `ChannelAdapter::get_channel_name()` - Used by channel implementations
- `VoiceAdapter` methods - Used in voice processing flow
**Action**: Document that these are used via trait dispatch. No changes needed.
---
## 2. Meet Service (src/meet/service.rs)
### Status: NEEDS API ENDPOINTS
**Unused Methods**:
- `MeetingService::join_room()`
- `MeetingService::start_transcription()`
- `MeetingService::get_room()`
- `MeetingService::list_rooms()`
**Solution**: Add REST API endpoints in `src/main.rs`:
```rust
// Add to api_router:
.route("/api/meet/rooms", get(crate::meet::list_rooms_handler))
.route("/api/meet/room/:room_id", get(crate::meet::get_room_handler))
.route("/api/meet/room/:room_id/join", post(crate::meet::join_room_handler))
.route("/api/meet/room/:room_id/transcription", post(crate::meet::toggle_transcription_handler))
```
Then create handlers in `src/meet/mod.rs` that call the service methods.
---
## 3. Multimedia Service (src/bot/multimedia.rs)
### Status: NEEDS API ENDPOINTS
**Unused Methods**:
- `MultimediaHandler::upload_media()`
- `MultimediaHandler::download_media()`
- `MultimediaHandler::generate_thumbnail()`
**Solution**: Add REST API endpoints:
```rust
// Add to api_router:
.route("/api/media/upload", post(crate::bot::multimedia::upload_handler))
.route("/api/media/download/:media_id", get(crate::bot::multimedia::download_handler))
.route("/api/media/thumbnail/:media_id", get(crate::bot::multimedia::thumbnail_handler))
```
Create handlers that use the `DefaultMultimediaHandler` implementation.
---
## 4. Drive Monitor (src/drive_monitor/mod.rs)
### Status: KEEP - Used internally
**Issue**: Fields and methods marked as unused but ARE used.
**Reality Check**:
- `DriveMonitor` is constructed in `src/bot/mod.rs` (line 48)
- It's stored in `BotOrchestrator::mounted_bots`
- The `spawn()` method is called to start the monitoring task
- Internal fields are used within the monitoring loop
**Action**: This is a false positive. The struct is actively used. No changes needed.
---
## 5. Basic Compiler (src/basic/compiler/mod.rs)
### Status: KEEP - Used by DriveMonitor
**Issue**: Structures marked as unused.
**Reality Check**:
- `BasicCompiler` is constructed in `src/drive_monitor/mod.rs` (line 276)
- `ToolDefinition`, `MCPTool`, etc. are returned by compilation
- Used for `.bas` file compilation in gbdialog folders
**Action**: These are actively used. False positives from compiler analysis. No changes needed.
---
## 6. Zitadel Auth (src/auth/zitadel.rs)
### Status: PARTIAL USE - Some methods need endpoints, some can be removed
**Currently Unused**:
- `verify_token()` - Should be used in auth middleware
- `refresh_token()` - Should be exposed via `/api/auth/refresh` endpoint
- `get_user_workspace()` - Called in `initialize_user_workspace()` which IS used
- `UserWorkspace` struct - Created and used in workspace initialization
**Action Items**:
1. **Add auth middleware** that uses `verify_token()`:
```rust
// src/auth/middleware.rs (new file)
pub async fn require_auth(
State(state): State<Arc<AppState>>,
headers: HeaderMap,
request: Request,
next: Next,
) -> Result<Response, StatusCode> {
// Extract and verify JWT using zitadel.verify_token()
}
```
2. **Add refresh endpoint**:
```rust
// In src/auth/mod.rs
pub async fn refresh_token_handler(...) -> impl IntoResponse {
// Call zitadel.refresh_token()
}
```
3. **Add to routes**:
```rust
.route("/api/auth/refresh", post(refresh_token_handler))
```
**Methods to Remove**:
- `extract_user_id_from_token()` - Can be replaced with proper JWT parsing in `verify_token()`
---
## 7. Email Setup (src/package_manager/setup/email_setup.rs)
### Status: KEEP - Used in bootstrap process
**Issue**: Methods marked as unused.
**Reality Check**:
- `EmailSetup` is used in bootstrap/setup flows
- Methods are called when setting up email server
- This is infrastructure code, not API code
**Action**: These are legitimately used during setup. False positives. No changes needed.
---
## 8. Config Structures (src/config/mod.rs)
### Status: INVESTIGATE - May have unused fields
**Unused Fields**:
- `AppConfig::email` - Check if email config is actually read
- Various `EmailConfig` fields
**Action**:
1. Check if `AppConfig::from_database()` actually reads these fields from DB
2. If yes, keep them
3. If no, remove unused fields from the struct
---
## 9. Session/LLM Minor Warnings
These are small warnings in various files. After fixing the major items above, recheck diagnostics and clean up minor issues.
---
## Priority Order
1. **Fix multimedia.rs field name bugs** (blocking compilation)
2. **Add meet service API endpoints** (most complete feature waiting for APIs)
3. **Add multimedia API endpoints**
4. **Add auth middleware + refresh endpoint**
5. **Document false positives** (channels, drive_monitor, compiler)
6. **Clean up config** unused fields
7. **Minor cleanup** pass on remaining warnings
---
## Rules
-**NEVER** use `#[allow(dead_code)]` as a quick fix
-**CREATE** API endpoints for unused service methods
-**DOCUMENT** false positives from trait dispatch or internal usage
-**REMOVE** truly unused code that serves no purpose
-**VERIFY** usage before removing - use `grep` and `find` to check references
---
## Testing After Changes
After each cleanup:
```bash
cargo check
cargo test
cargo clippy
```
Ensure:
- All tests pass
- No new warnings introduced
- Functionality still works