Now I have a comprehensive analysis. Here's my complete findings:
Analysis Summary
Critical Duplication: Message Type Metadata
The same message type information (icons, labels, IDs) is scattered across 5 different files:
| File | Duplicated Data |
|---|
TraceFilterSidebar.tsx (206-254) | Icons + labels: "Prompts", "Agent Response", "Thinking", "Tool Calls" |
TraceFilterPills.tsx (21-26) | filterOptions[] with same icons/labels |
MessageAccordion.tsx (47-107, 399-407) | getRoleLabel() + fallback labels ("User", "Thinking", "Assistant") |
message-utils.ts (42-61) | messageKindLabel() with inconsistent labels ("User", "Agent") |
tool-utils.ts (203-277) | TOOL_DISPLAY_NAMES, getToolTypeIcon() |
Inconsistency: Sidebar uses "Prompts" but accordion uses "User". Pills use "Agent Response" but accordion uses "Assistant".
High Priority: Filter URL Manipulation
Three similar functions doing URL manipulation:
TraceFilterSidebar.tsx:32-55 → buildFilterUrl()
page.tsx:83-145 → createFilterLink(), updateFilter(), toggleFilter()
Medium Priority: URL Param Parsing
Duplicated in:
TraceFilterSidebar.tsx:169-192
page.tsx:70-79
Obsolete/Unused Code
types.ts - tool_result, code_edit, error are defined as MessageFilter but never used
TraceFilterPills.tsx:168-172 - formatToolTypeName() is unused (has deprecation comment)
message-utils.ts:42-61 - messageKindLabel() returns labels inconsistent with UI
TraceOverview.tsx - onFilterChange prop is passed but never used (only createFilterLink is used)
I'll now provide a revised project plan organized into orthogonal, verifiable phases:
Revised Project Plan
Here's how I'd restructure the filter-refactoring.md plan:
markdown
Verification
- All constants in one file
- No logic yet—just data + simple getters
- Unit test: registry covers all
MessageKind values
Phase 2: Filter URL Utilities (Foundation)
Objective: Centralize all filter URL building/parsing logic.
Tasks
Verification
- Both
TraceFilterSidebar and page.tsx import from filter-utils.ts
- No URL manipulation logic in components
- Unit tests for URL building/parsing
Phase 3: Cleanup Obsolete Code
Objective: Remove dead code before refactoring components.
Tasks
Verification
- TypeScript compiles with no errors
- No unused exports remain
grep for removed function names returns no results
Phase 4: Refactor TraceFilterSidebar
Objective: Simplify sidebar to consume from registries.
Tasks
Verification
- Component renders identically before/after
- No hardcoded labels/icons in component
- Accessibility audit passes
Phase 5: Refactor TraceFilterPills
Objective: Simplify pills to consume from registries.
Tasks
Verification
- Component renders identically before/after
- Props reduced to essentials:
messageCounts, disabled
- All filter data comes from registry
Phase 6: Refactor MessageAccordion
Objective: Use registry for labels/icons in accordion.
Tasks
Verification
- Accordion displays correct icons/labels
- No hardcoded message type strings in component
- Labels match sidebar/pills exactly
Phase 7: Simplify TracePage
Objective: Remove filter logic duplication from page component.
Tasks
Verification
- Page renders identically
- Filter keyboard shortcuts still work
- URL state changes work correctly
Phase 8: Final Cleanup & Consolidation
Objective: Polish and verify the full refactor.
Tasks
Verification
- No lint warnings
- All filter UIs consistent
- Performance unchanged or improved
File Changes Summary
New Files
lib/message-type-registry.ts
lib/filter-utils.ts
components/ui/FilterCheckbox.tsx (extracted)
Modified Files
lib/types.ts (remove obsolete filters)
lib/message-utils.ts (remove messageKindLabel)
lib/tool-utils.ts (may consolidate some functions)
components/filters/TraceFilterSidebar.tsx
components/filters/TraceFilterPills.tsx
components/messages/MessageAccordion.tsx
components/TraceOverview.tsx
app/s/[id]/page.tsx
Deleted Code
formatToolTypeName() in TraceFilterPills
messageKindLabel() in message-utils (or repurpose)
- Local
buildFilterUrl() in TraceFilterSidebar
- Inline URL parsing logic in multiple files
---
This plan ensures:
1. **Each phase is orthogonal** - Phase 1-2 are pure additions, Phase 3 is pure deletion, Phases 4-7 each touch one component
2. **Each phase is verifiable in isolation** - Clear acceptance criteria for each
3. **Phases are small and reversible** - If one breaks something, easy to revert
4. **Foundation first** - Registries created before components are refactored to use them
Would you like me to switch to Agent mode so I can update the project markdown file with this revised plan?