ID8Composer Codebase Cleanup Plan
Timeline: 2-4 weeks Priority: KB/Knowledge consolidation first, then structured cleanup Risk Level: Medium (incremental approach)
Agent & Tool Assignments
| Role | Assignment |
|---|---|
| Orchestrator/Code Reviewer | Claude (main) - reviews all work, fixes issues |
| Code Architecture | feature-dev:code-architect - designs refactoring approach |
| Code Implementation | fullstack-developer - executes file moves/edits |
| Code Review | pr-review-toolkit:code-reviewer - validates changes |
| Security Audit | security-pro:security-auditor - checks for regressions |
| Testing | testing-suite:generate-tests - ensures coverage |
| Git Workflow | git-workflow:feature + /commit skill - branch management |
| Database | supabase-toolkit MCP - migration verification |
Executive Summary
This plan addresses the technical debt identified in the codebase audit:
- KB/Knowledge naming duplication - consolidate to single namespace
- Oversized files - extract quick wins from monster files
- Console.log cleanup - adopt structured logger
- Migration adapter - investigate status, plan removal
Week 1: KB/Knowledge Consolidation (Priority 1)
Goal
Eliminate confusing duplicate naming between /kb/ and /knowledge/ across components and API routes.
Decision: Consolidate to /knowledge/
- More descriptive than "kb" acronym
/api/knowledge/already has 20+ comprehensive routes/api/kb/only has 1 route (operations/execute)
Agents for Week 1
1. /git-workflow:feature kb-knowledge-consolidation → Create branch
2. fullstack-developer → Execute file moves
3. pr-review-toolkit:code-reviewer → Validate each step
4. Claude (main) → Review & fix issues
5. /commit → Commit after each day
6. testing-suite:generate-tests → Verify no regressions
Day 1-2: Component Consolidation
Files to modify:
src/components/kb/ → DELETE (after migration)
src/components/knowledge/ → KEEP (primary)
Migration steps:
- Move
ActiveKBPanel.tsx→src/components/knowledge/ActiveKnowledgePanel.tsx - Move
KBFileVersionPanel.tsx→src/components/knowledge/FileVersionPanel.tsx - Move
KBContentViewer.tsx→src/components/knowledge/ContentViewer.tsx - Consolidate
KnowledgeFileCard.tsx+FileCard.tsx→ singleFileCard.tsx - Keep
KnowledgeManager.tsxas-is in/knowledge/
Update imports (5 files):
src/components/composer/UnifiedInterface.tsxsrc/components/layout/claude-unified-interface.tsxsrc/components/layout/left-sidebar-panel.tsxsrc/app/kb-demo/page.tsxsrc/components/layout/left-sidebar-panel-simple.tsx
Day 3: API Route Consolidation
Files to modify:
src/app/api/kb/operations/execute/route.ts → MOVE to /api/knowledge/operations/execute/
src/app/api/kb/ → DELETE
Update fetch calls referencing /api/kb/
Day 4-5: Testing & Cleanup
- Run full E2E test suite
- Verify all KB operations work
- Delete empty
/components/kb/directory - Delete
/app/api/kb/directory - Update any documentation referencing "kb"
Week 2: Quick Wins - File Extraction
Goal
Reduce oversized files by extracting low-risk, self-contained modules.
Agents for Week 2
1. /git-workflow:feature file-extraction-quick-wins → Create branch
2. feature-dev:code-architect → Design module boundaries
3. fullstack-developer → Execute extractions
4. pr-review-toolkit:code-reviewer → Validate each extraction
5. pr-review-toolkit:code-simplifier → Ensure clean code
6. Claude (main) → Review & fix issues
7. /commit → Commit after each extraction
Day 1-2: Extract document-utils.ts (300 lines)
Source: src/stores/document-store.ts
Target: src/lib/document/document-utils.ts
Extract these pure functions:
ensureString()- content type conversionplainTextToHtml()/htmlToPlainText()- format conversioncaptureKBContext()- KB snapshot helpercalculateWordCount()/calculateReadingTime()- Export utility helpers
Risk: Very low - pure functions with no state dependencies
Day 3-4: Extract event-sourcing-store.ts (300 lines)
Source: src/stores/document-store.ts
Target: src/stores/event-sourcing-store.ts
Extract:
- Event log management
- Undo/redo stack operations
- History queries
- Event filtering
Risk: Low - clear boundaries, limited coupling
Day 5: Complete dual-panel-store.ts
Source: src/stores/document-store.ts
Target: src/stores/dual-panel-store.ts (already exists, needs completion)
Move remaining:
- Canvas state management
- Source state management
- Transport/transfer logic
- Story tree (branching) system
Risk: Medium - used by editor components, needs testing
Week 3: Console.log Cleanup
Goal
Remove debug noise, adopt structured logger for production-appropriate logging.
Agents for Week 3
1. /git-workflow:feature console-log-cleanup → Create branch
2. fullstack-developer → Execute replacements
3. pr-review-toolkit:silent-failure-hunter → Ensure error handling preserved
4. security-pro:security-auditor → Verify no sensitive data in logs
5. Claude (main) → Review & fix issues
6. /commit → Commit in batches
Existing Logger
src/lib/logging/structured-logger.ts - already exists but underutilized
Day 1: Safe Removals (~300 logs)
Remove entirely:
- UI event logs ("Document clicked", "Button clicked")
- State mutation debug logs ("Setting state to...")
- Intermediate step logs in hooks
- JSON parameter dumps
Target files (highest log counts):
src/components/editor/paradigm-shift/DualPanelEditor.tsx(~110 logs)src/stores/document-store.ts(~120 logs after extraction)src/stores/arc-generator-store.ts(~95 logs)
Day 2-3: Migrate Error Logging (~380 logs)
Replace:
// Before
console.error('Failed to save:', error);
// After
import { structuredLogger } from '@/lib/logging/structured-logger';
structuredLogger.error('Failed to save', { error, context: 'document-save' });
Priority files:
- API routes (
src/app/api/**) - Database operations (
src/lib/database/**) - Authentication (
src/lib/services/authentication.ts)
Day 4-5: Environment-Gated Logging
Keep but gate behind NODE_ENV:
if (process.env.NODE_ENV === 'development') {
console.log('[DEBUG]', ...);
}
Apply to:
- Feature flag logs
- Demo mode logs
- Migration adapter warnings
Week 4: Migration Adapter Investigation & Cleanup
Goal
Determine if use-migration-adapter.ts can be simplified or removed.
Agents for Week 4
1. feature-dev:code-explorer → Investigate migration status
2. /git-workflow:feature migration-adapter-cleanup → Create branch
3. feature-dev:code-architect → Design simplification approach
4. fullstack-developer → Execute refactoring
5. pr-review-toolkit:code-reviewer → Validate changes
6. pr-review-toolkit:type-design-analyzer → Review type changes
7. testing-suite:generate-tests → Ensure coverage
8. Claude (main) → Review & fix issues
Day 1: Investigation
Check feature flag status:
// Find in codebase
const useUnifiedStore = ... // What controls this?
Questions to answer:
- Is unified store enabled in production?
- Are there any components still using legacy path?
- What breaks if we remove the adapter?
Day 2-3: Based on Investigation
If unified store is active:
- Remove legacy adapter code (~1,300 lines)
- Simplify to direct unified store usage
- Update all consuming components
If migration still in progress:
- Extract to separate files:
legacy-adapter.ts(600 lines)unified-adapter.ts(800 lines)store-conversion.ts(300 lines)
- Add deprecation warnings to legacy path
Day 4-5: ARC Store Quick Wins
Extract from arc-generator-store.ts:
arc-settings-store.ts(200 lines) - format/personality configarc-ui-state.ts(150 lines) - visibility/animation state
Leave for later:
- Phase management (core logic)
- Conversation handling (core logic)
- Scene management (already extracted)
Critical Files Reference
To Modify
src/components/kb/ # DELETE after migration
src/components/knowledge/ # ADD migrated components
src/app/api/kb/ # DELETE after migration
src/app/api/knowledge/operations/ # ADD moved route
src/stores/document-store.ts # EXTRACT utilities
src/stores/dual-panel-store.ts # COMPLETE extraction
src/hooks/use-migration-adapter.ts # INVESTIGATE & simplify
src/stores/arc-generator-store.ts # EXTRACT settings/UI
To Create
src/lib/document/document-utils.ts # Pure utility functions
src/stores/event-sourcing-store.ts # History/undo management
src/components/knowledge/ActiveKnowledgePanel.tsx # Renamed from KB
src/components/knowledge/FileVersionPanel.tsx # Renamed from KB
Success Metrics
| Metric | Before | After |
|---|---|---|
| Duplicate naming schemes | 2 (kb + knowledge) | 1 (knowledge) |
| document-store.ts lines | 2,936 | ~2,000 |
| Console.logs in production | ~400 | <100 |
| use-migration-adapter.ts | 2,699 | TBD based on investigation |
Orchestration Workflow
Claude (Main) Responsibilities - Code Reviewer & Fixer
For each task:
1. DELEGATE → Launch appropriate agent for the task
2. MONITOR → Watch agent progress, read outputs
3. REVIEW → Use pr-review-toolkit:code-reviewer to validate
4. FIX → Correct any issues found
5. VERIFY → Run type-check, build, tests
6. COMMIT → Use /commit skill when verified
7. REPEAT → Move to next task
Quality Gates (After Each Major Step)
npm run type-check # Must pass
npm run build # Must pass
npm run test:unit # Must pass
PR Workflow (End of Each Week)
1. /git-workflow:finish → Complete feature branch
2. pr-review-toolkit:code-reviewer → Full code review
3. pr-review-toolkit:pr-test-analyzer → Verify test coverage
4. gh pr create → Create PR for review
5. gh pr merge → Merge after approval
Risk Mitigation
- Run tests after each extraction - don't batch changes
- Keep compatibility layers during migration
- Feature flag new code paths where possible
- Commit frequently with descriptive messages
- Create rollback points before major changes
Out of Scope (Future Work)
- Breaking down remaining 71 oversized components
- Full barrel export implementation
- Complete type standardization
- Test coverage improvements