# Track Specification: Context Composition Decoupling ## Overview Decouple Files & Media from Context Composition, add directory grouping, file stats, and view mode selection per file. This is Phase 1 of the Context Composition Redesign per spec at `docs/superpowers/specs/2026-05-10-context-composition-redesign-design.md`. ## Current State Audit (as of 2026-05-10) ### Already Implemented - Files & Media panel lists project files with wildcards - Context Composition panel inherits files from Files & Media - View flags (agg/full/sig/def) sync visually between panels - `_render_context_composition_panel()` in gui_2.py:2794-2964 ### Gaps to Fill (This Track's Scope) - Files & Media populates Context Composition automatically (coupled) - No directory grouping in file listings - No file stats (line count, AST element count) - View mode selection is limited (no custom view presets) - Context Composition is NOT independent selection - it's derived from Files & Media ## Goals 1. Make Files & Media and Context Composition independent data sources 2. Add directory grouping to file listings for compact display 3. Add file stats per file and aggregate 4. Implement proper view mode selection (full/sig/def/custom) 5. User can add/remove files from Context Composition independently 6. "Add all" and bulk add/remove operations ## Functional Requirements - Context Composition starts empty or from saved preset on discussion switch - User manually adds files FROM project whitelist (not auto-inherited) - Each file entry has: path, view_mode, custom_slices - Directory grouping with collapsible headers (`📁 relative/path/`) - File stats displayed: line count, AST element count per file - Aggregate stats for selection: total files, lines, AST elements - View mode dropdown per file: full, sig, def, custom - Batch operations: add all from whitelist, remove selected, etc. ## Non-Functional Requirements - No horizontal scrolling in file lists (directory grouping enables this) - Stats computed asynchronously to not block UI - FileItem model may need extension for view_mode field ## Architecture Reference - `src/gui_2.py:_render_context_composition_panel()` - main panel - `src/models.py:FileItem` - needs view_mode field extension - `src/aggregate.py` - respects view modes when composing context - `docs/superpowers/specs/2026-05-10-context-composition-redesign-design.md` ## Out of Scope - Slice visualization and annotations (Phase 2) - Context preset save/load (Phase 3) - Context preview before send (Phase 3)