-
Notifications
You must be signed in to change notification settings - Fork 437
Open
Description
Code Quality: Refactor Large Router File
Severity: MEDIUM (maintainability)
Location: src/main/lib/trpc/routers/claude.ts (1,800+ lines)
Description
The Claude router is 1,800+ lines and handles multiple concerns, making it hard to test, maintain, and debug.
Current Responsibilities
- Message streaming
- MCP server configuration
- Session management
- Tool approval/gating
- File path resolution
- Cache management
- Error handling
Recommendation
Split into focused modules:
lib/trpc/routers/claude/
├── index.ts # Main router (exports)
├── message-stream.ts # Streaming logic
├── mcp-config.ts # MCP server management
├── session-manager.ts # Session state & lifecycle
├── tool-approval.ts # Tool gating & permissions
├── path-resolver.ts # File path resolution
└── cache.ts # Caching strategies
Benefits:
- Easier to test individual components
- Better code organization
- Reduces merge conflicts
- Easier to onboard new contributors
- Simpler debugging
Example Structure
index.ts
import { createMessageStream } from './message-stream'
import { getMCPConfig } from './mcp-config'
import { SessionManager } from './session-manager'
export const claudeRouter = router({
onMessage: createMessageStream(sessionManager, mcpConfig),
// ... other procedures
})message-stream.ts
export function createMessageStream(
sessionManager: SessionManager,
mcpConfig: MCPConfig
) {
return publicProcedure
.input(messageSchema)
.subscription(async function* ({ input }) {
// Stream implementation
})
}Priority
Medium - Not urgent but would improve maintainability significantly.
Labels: refactor, code-quality
Metadata
Metadata
Assignees
Labels
No labels