Maestro icon indicating copy to clipboard operation
Maestro copied to clipboard

feat: Unified Inbox with Focus Mode (Encore Feature)

Open felipeggv opened this issue 9 months ago • 6 comments

Summary

Adds a fully gated Unified Inbox feature behind the encoreFeatures.unifiedInbox flag (disabled by default). The inbox aggregates the latest messages from all active agents into a single, keyboard-navigable overlay with focus mode for deep-dive reading and inline replies.

Key changes:

  • 6 new source files: AgentInbox/index.tsx, InboxListView.tsx, FocusModeView.tsx, useAgentInbox.ts, agent-inbox.ts types, tabDisplayName.ts utility
  • App.tsx integration: lazy import, 5 handler functions, ref binding, conditional rendering
  • Keyboard shortcut: Alt+I opens inbox (triple-gated: shortcut match + feature flag + setter exists)
  • Command palette: Unified Inbox wired into Cmd+K quick actions with encore gating
  • Settings UI: Toggle added to SettingsModal Encore section with ARIA attributes
  • Modal system: agentInbox registered in modalStore with AgentInboxModalData type

Fixes applied from review branches:

  • Race condition: Resize observer cleanup prevents stale layout after unmount
  • Resize leak: Observer properly disconnected on component teardown
  • Group keys: Sort-by-agent uses sessionId (stable) not sessionName (mutable)
  • Duplicate logs: Deduplication guard prevents repeated console entries
  • AI mode forcing: Focus mode no longer forces terminal mode switch
  • ARIA compliance: Proper roles, labels, and keyboard navigation attributes
  • Performance: useMemo/useCallback on filters, sorts, and derived data; double-rAF focus instead of setTimeout hack

Test coverage:

  • useAgentInbox.test.ts: 26 tests (filters, sorts, truncation, timestamp fallback)
  • AgentInbox.test.tsx: 18 tests (render, filter pills, keyboard nav, escape, focus mode, reply)
  • modalStore.test.ts: Updated 1 test to reflect new updateModalData behavior (stores data on unopened modals)

Test plan

  • [ ] Enable unifiedInbox in Settings > Encore and verify Alt+I opens the inbox
  • [ ] Verify inbox shows latest messages from all active agents
  • [ ] Test filter pills: all, unread, read, starred
  • [ ] Test sort modes: newest, oldest, grouped, by agent
  • [ ] Enter focus mode (Enter/double-click) and verify message thread display
  • [ ] Test reply input sends to correct agent tab
  • [ ] Verify Escape closes inbox and returns focus to previous element
  • [ ] Verify Cmd+K shows "Open Unified Inbox" when feature is enabled
  • [ ] Verify inbox is completely invisible when feature flag is disabled
  • [ ] Run npm run test — all non-baseline failures should pass

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Unified Inbox feature with dual list and focus modes for managing conversations
    • Filtering options: All, Unread, Read, Starred
    • Sorting options: Newest, Oldest, Grouped, By Agent
    • Focus mode for detailed conversation view with reply composer
    • Keyboard shortcut (Alt+I) and quick action access for unified inbox
    • Context usage indicators and thinking mode toggle
    • Settings toggle to enable/disable unified inbox
  • Tests

    • Comprehensive test coverage for inbox components, hooks, and modal state management

felipeggv avatar Feb 27 '26 14:02 felipeggv

@coderabbitai review

felipeggv avatar Feb 27 '26 14:02 felipeggv

📝 Walkthrough

Walkthrough

Adds a new "Unified Inbox" feature providing a two-view modal interface (list and focus modes) for browsing and interacting with agent sessions, including filtering, sorting, keyboard navigation, and persistent state management integration.

Changes

Cohort / File(s) Summary
Test Suites
src/__tests__/renderer/components/AgentInbox/AgentInbox.test.tsx, src/__tests__/renderer/hooks/useAgentInbox.test.ts, src/__tests__/renderer/stores/modalStore.test.ts
Added comprehensive test coverage for new AgentInbox component and useAgentInbox hook with mocked dependencies; updated modalStore test to verify data persistence for unopened modals.
Agent Inbox Components
src/renderer/components/AgentInbox/index.tsx, src/renderer/components/AgentInbox/InboxListView.tsx, src/renderer/components/AgentInbox/FocusModeView.tsx
Introduced new two-mode inbox UI: main AgentInbox orchestrator with mode switching, virtualized InboxListView with sorting/filtering/grouping controls and keyboard navigation, and FocusModeView with resizable sidebar and markdown-rich conversation display.
Types and Constants
src/renderer/types/agent-inbox.ts, src/renderer/types/index.ts, src/renderer/constants/modalPriorities.ts, src/renderer/constants/shortcuts.ts
Added InboxItem interface, filter/sort/view mode types, status labels and colors; extended EncoreFeatureFlags with unifiedInbox; added AGENT_INBOX modal priority and agentInbox keyboard shortcut.
Hooks and Utilities
src/renderer/hooks/useAgentInbox.ts, src/renderer/utils/tabDisplayName.ts
Implemented useAgentInbox hook with filtering (all/unread/read/starred), sorting (newest/oldest/grouped/byAgent), and message truncation; added getTabDisplayName utility to derive session display names from various ID formats.
Modal and Store Integration
src/renderer/stores/modalStore.ts, src/renderer/stores/settingsStore.ts
Extended modalStore with agentInbox modal support and AgentInboxModalData type; added unifiedInbox feature flag to DEFAULT_ENCORE_FEATURES; updated getModalActions and useModalActions to expose agentInbox state handlers.
App and Modal Props Wiring
src/renderer/App.tsx, src/renderer/components/AppModals.tsx, src/renderer/components/AppUtilityModals.tsx, src/renderer/components/QuickActionsModal.tsx, src/renderer/components/SettingsModal.tsx
Integrated AgentInbox into main App with lazy loading, session navigation, and quick-reply flow; extended AppModals and QuickActionsModal props to wire onOpenAgentInbox; added UI toggle for unifiedInbox feature in SettingsModal; wired keyboard shortcut handler in useMainKeyboardHandler.

Sequence Diagram

sequenceDiagram
    actor User
    participant KeyboardHandler as Keyboard Handler
    participant App as App Component
    participant ModalStore as Modal Store
    participant AgentInbox as AgentInbox Modal
    participant ListView as InboxListView
    participant FocusView as FocusModeView
    participant SessionMgr as Session Manager

    User->>KeyboardHandler: Alt+I (agentInbox shortcut)
    activate KeyboardHandler
    KeyboardHandler->>ModalStore: setAgentInboxOpen(true)
    deactivate KeyboardHandler
    activate ModalStore
    ModalStore->>ModalStore: openModal('agentInbox')
    ModalStore-->>App: agentInboxOpen=true
    deactivate ModalStore

    App->>AgentInbox: render with sessions/groups
    activate AgentInbox
    AgentInbox->>ListView: render list mode (default)
    activate ListView
    ListView->>ListView: useAgentInbox hook
    ListView->>ListView: filter/sort items
    ListView-->>User: display filtered inbox items

    User->>ListView: ArrowDown/Up navigation
    ListView->>ListView: update selected row
    ListView-->>User: highlight next/prev item

    User->>ListView: Enter key
    ListView->>AgentInbox: onNavigateToSession(sessionId, tabId)
    deactivate ListView
    AgentInbox->>SessionMgr: navigate to session/tab
    SessionMgr-->>User: activate target session

    User->>ListView: F key or double-click
    activate ListView
    ListView->>AgentInbox: switch to focus mode
    deactivate ListView
    AgentInbox->>FocusView: render focus mode
    activate FocusView
    FocusView->>FocusView: render sidebar + conversation
    FocusView-->>User: show logs and reply composer

    User->>FocusView: type reply + Enter
    FocusView->>AgentInbox: onQuickReply(sessionId, message)
    AgentInbox->>SessionMgr: process reply in target session
    SessionMgr-->>User: update session with reply

    User->>FocusView: Escape key
    FocusView->>AgentInbox: switch back to list mode
    deactivate FocusView
    AgentInbox->>ListView: render list mode
    activate ListView
    ListView-->>User: return to inbox list
    deactivate ListView

    User->>AgentInbox: click close / Escape
    deactivate AgentInbox
    AgentInbox->>ModalStore: setAgentInboxOpen(false)
    activate ModalStore
    ModalStore-->>App: agentInboxOpen=false
    deactivate ModalStore
    App->>User: close modal, restore focus

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • RunMaestro/Maestro#440: Modifies AppModals.tsx prop propagation and useMainKeyboardHandler.ts keyboard handler logic that overlap with agent inbox integration.
  • RunMaestro/Maestro#452: Touches same modal/App wiring layers (modalStore, App.tsx, useMainKeyboardHandler) affected by agent inbox feature additions.
  • RunMaestro/Maestro#444: Extends AppModals props interface (similar to onOpenAgentInbox addition in this PR), indicating related modal system modifications.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: introducing a Unified Inbox feature with Focus Mode as an Encore-gated feature.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Feb 27 '26 14:02 coderabbitai[bot]

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Feb 27 '26 14:02 coderabbitai[bot]

Greptile Summary

Adds a fully-gated Unified Inbox feature (disabled by default) that aggregates latest messages from all active agents into a keyboard-navigable overlay with focus mode for deep reading and inline replies.

Key architectural decisions:

  • Triple-gated activation: feature flag + keyboard shortcut + setter existence check prevents accidental exposure
  • Frozen snapshot pattern: focus mode freezes item order on entry while resolving against live data for real-time updates
  • Capture/bubble phase keyboard handling: Cmd+[/] navigation fires before textarea consumes events
  • Quick reply deterministic flush: uses effect + pending state instead of RAF timing chains
  • Modal data persistence: updateModalData now stores filter/sort/expand state even when modal is closed

Integration points:

  • 6 new source files (types, hooks, 3 view components, utility)
  • App.tsx: 5 handler functions, ref binding for processInput, conditional rendering
  • Settings UI: toggle in Encore section with Beta badge and ARIA attributes
  • Command palette: wired into Cmd+K with encore gating
  • Modal system: registered at priority 555 with AgentInboxModalData type

Test coverage:

  • useAgentInbox.test.ts: 26 tests (filters, sorts, truncation, timestamp fallback)
  • AgentInbox.test.tsx: 18 tests (render, keyboard nav, focus mode, reply)
  • modalStore.test.ts: 1 updated test for new updateModalData behavior

Bug fixes applied from review branches:

  • Race condition: resize observer cleanup
  • Resize leak: proper observer disconnection
  • Group keys: sort-by-agent uses stable sessionId not mutable sessionName
  • Duplicate logs: deduplication guard
  • Performance: useMemo/useCallback on filters, sorts, derived data

Confidence Score: 5/5

  • Safe to merge with high confidence - well-architected feature with comprehensive testing and proper gating
  • Score reflects excellent implementation quality: comprehensive test coverage (44 tests), proper feature gating prevents accidental exposure, follows all CLAUDE.md patterns (tabs not spaces, error handling, performance optimization), clean integration with existing modal/keyboard systems, and multiple bug fixes already applied from review branches. The modalStore behavioral change is intentional and properly tested.
  • No files require special attention - all changes are well-tested and follow project conventions

Important Files Changed

Filename Overview
src/renderer/components/AgentInbox/index.tsx Main inbox container with view mode orchestration, frozen snapshot pattern for focus mode, proper keyboard handling with capture/bubble phases
src/renderer/components/AgentInbox/InboxListView.tsx Virtualized list view with filter pills, sort modes, grouped headers, and keyboard navigation
src/renderer/components/AgentInbox/FocusModeView.tsx Deep-dive view for individual agent conversations with log rendering, inline reply, thinking mode toggle, and markdown support
src/renderer/hooks/useAgentInbox.ts Data aggregation hook with filtering, sorting (newest/oldest/grouped/by-agent), smart summary generation, and proper memoization
src/renderer/App.tsx Adds 5 inbox handler functions (navigate, quick reply, open & reply, mark as read, toggle thinking), ref binding for processInput, and conditional rendering with encore gating
src/renderer/stores/modalStore.ts Adds agentInbox modal registration and updates updateModalData to allow storing data on unopened modals (behavioral change with test update)
src/tests/renderer/hooks/useAgentInbox.test.ts 26 tests covering truncation, smart summary generation, filtering, sorting, timestamp derivation, and group handling
src/tests/renderer/components/AgentInbox/AgentInbox.test.tsx 18 tests covering rendering, filter pills, keyboard navigation (arrows/enter/escape), focus mode entry/exit, and reply functionality

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    Start([User presses Alt+I]) --> CheckGate{Feature enabled?}
    CheckGate -->|No| End1([Nothing happens])
    CheckGate -->|Yes| OpenModal[Open AgentInbox Modal]
    
    OpenModal --> LoadData[useAgentInbox hook aggregates data]
    LoadData --> FilterSort[Filter + Sort items]
    FilterSort --> ListView[InboxListView renders]
    
    ListView --> UserAction{User Action}
    
    UserAction -->|Arrow Keys| Navigate[Navigate items]
    Navigate --> ListView
    
    UserAction -->|F or Enter| EnterFocus[Enter Focus Mode]
    EnterFocus --> FreezeOrder[Freeze item order in ref]
    FreezeOrder --> FocusView[FocusModeView renders]
    
    FocusView --> FocusAction{User Action in Focus}
    
    FocusAction -->|Cmd+Bracket Keys| PrevNext[Navigate prev/next]
    PrevNext --> FocusView
    
    FocusAction -->|Type reply| QuickReply[Quick Reply handler]
    QuickReply --> SwitchSession[Switch to target session]
    SwitchSession --> ProcessInput[processInput sends text]
    ProcessInput --> RestoreSession[Restore previous session]
    
    FocusAction -->|Escape or B| ExitFocus[Exit to List View]
    ExitFocus --> ClearFreeze[Clear frozen order]
    ClearFreeze --> ListView
    
    UserAction -->|Escape| CloseModal[Close Modal]
    FocusAction -->|Click Navigate| CloseAndNav[Navigate to session]
    
    CloseModal --> RestoreFocus[Restore focus to trigger element]
    CloseAndNav --> RestoreFocus
    RestoreFocus --> End2([Complete])

Last reviewed commit: ee926c2

greptile-apps avatar Feb 27 '26 15:02 greptile-apps

@felipeggv please run the following on your machine for this PR so it can move toward acceptance.

Here is the prompt you should run:

You are responsible for getting this PR in RunMaestro/Maestro to an accept-ready state.

PR: https://github.com/RunMaestro/Maestro/pull/474
Branch/Head: inspect the PR branch locally before making changes.

Goal:
Drive this PR to zero unresolved CodeRabbit and Greptile review threads.

Process:
1. Fetch the PR locally and work from a clean git worktree on the PR branch.
2. List all unresolved CodeRabbit and Greptile review threads for this PR.
3. For each unresolved bot thread:
   - verify whether the issue is still real on the current PR head
   - if it is already fixed or the thread is outdated, resolve the GitHub review thread immediately
   - if it is real, implement the smallest correct fix on the PR branch
4. After each fix batch:
   - run the relevant validation commands locally
   - push the branch
   - re-poll the PR’s unresolved CodeRabbit/Greptile threads
   - resolve any newly stale/fixed bot threads
5. Repeat until this PR has zero unresolved CodeRabbit and Greptile threads.

Rules:
- Resolve bot threads only when the current branch state actually fixes them.
- Do not resolve human review threads unless explicitly asked.
- Be surgical. Do not broaden scope beyond the review findings.
- If local validation differs from CI because of environment issues, state the exact failing test/check and the exact missing dependency/file/path.
- If a bot comment is a design tradeoff rather than a bug, explain why and leave it unresolved only if it truly still applies.

Definition of done:
- zero unresolved CodeRabbit threads
- zero unresolved Greptile threads
- branch pushed
- latest validation/check status re-polled
- concise summary written with:
  - PR URL
  - commits pushed
  - threads resolved
  - any remaining blockers

Keep looping until the PR is clean.

jeffscottward avatar Mar 14 '26 17:03 jeffscottward

Thanks for the great contribution, @felipeggv! This is a substantial and well-structured feature — the encore flag gating, comprehensive test coverage (44+ tests across the hook and component), and attention to accessibility and performance all look solid.

Unfortunately, this branch currently has merge conflicts with main and is in a DIRTY merge state. Could you kindly rebase onto the latest main and resolve the conflicts so we can get a clean merge? Once that's done and CI is green, I'll take another pass.

A couple of CodeRabbit nits worth addressing while you're at it:

  • src/renderer/types/agent-inbox.ts: narrow toolType: string to Session['toolType'] for better type safety.
  • FocusModeView.tsx (~L434-457): keyboard-focusable group headers could use focus handlers for full a11y parity.

Appreciate the care put into this — excited to land it once the rebase is sorted.

pedramamini avatar Apr 21 '26 21:04 pedramamini