Wrapped AgentStreamView content with ToolCallSheetProvider to enable
tool call details to open in a bottom sheet on tap instead of expanding
inline. This improves mobile UX for viewing tool call information.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Import useToolCallSheet hook from new tool-call-sheet component
- Replace inline expansion with openToolCall() to show details in bottom sheet
- Remove ~300 lines of unused code (toolCallStylesheet, formatFullValue,
buildLineDiffFromStrings, isStructuredToolResult, and inline rendering)
- Clean up unused imports (ScrollView, DiffViewer, DiffLine)
- Badge display unchanged - still shows icon, label, loading/error state
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create a new component for displaying tool call details in a bottom sheet
on mobile devices. Includes:
- ToolCallSheetProvider and useToolCallSheet hook for state management
- BottomSheetModal with snap points at 50% and 90%
- Header with tool icon, name, and status badge
- Content sections for args, commands, file diffs, file reads, and errors
- Reuses rendering logic from existing ToolCall component
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The useShallow wrapper was not preventing infinite loops because the
selector created new object references on every store update. Fixed by:
1. Selecting the agents Map directly (stable reference)
2. Deriving childAgents array in useMemo with proper dependencies
The Map only changes when agents are added/removed, preventing
unnecessary re-renders that were causing the infinite loop.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The childAgents selector in the agent screen was creating a new array
on every render, causing an infinite loop when combined with zustand's
store subscription. Added useShallow wrapper to perform shallow
comparison and prevent unnecessary re-renders.
Also updated plan.md with test results:
- PARTIAL PASS: Fixed infinite loop, agent screen loads correctly
- Sub-Agents menu section displays properly
- Parent/child MCP creation works but parentAgentId not auto-injected
- Added fix task for auto-injecting parentAgentId in MCP server
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added a "Sub-Agents" section to the agent info menu dropdown that:
- Queries session store for agents where parentAgentId matches current agent
- Displays child agents as clickable menu items with chevron icons
- Shows "No sub-agents" when the agent has no children
- Navigates to child agent screen when tapped
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Skip agents with parentAgentId when building the aggregated agents list
for the homepage. This ensures only top-level (root) agents are displayed,
while child agents are only accessible through their parent agent's menu.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add parentAgentId field to:
- Agent interface in session-store.ts
- AgentDirectoryEntry in agent-directory.ts
- getAgentDirectory() includes parentAgentId
- normalizeAgentSnapshot() maps from server payload
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Added hasRequestedRef to track if a git diff request was already made
for the current agentId. This prevents duplicate requests when the
requestGitDiff function reference changes due to store updates.
The issue was that requestGitDiff in the useEffect dependency array
caused an infinite loop: request → store update → new function ref →
effect re-runs → request again.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implement a new UI section that surfaces agents requiring user attention at the top of the agent list. This includes agents that are running, have pending permissions, or have errors.
**Backend changes:**
- Add `requiresAttention` field to agent projections and SDK types
- Implement logic in AgentManager to detect attention states (running, pending permissions, errors)
- Add WebSocket message handler to notify clients of attention state changes
- Update session state to include attention tracking
**Frontend changes:**
- Add "REQUIRES ATTENTION" section in agent-list component with visual prominence
- Update useAggregatedAgents hook to expose `requiresAttention` agents
- Enhance session store to track and update attention states
- Add real-time updates via WebSocket for attention state changes
- Update type definitions across agent directory and stream types
Verified working via Playwright MCP testing on localhost:8081.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace portal/registry pattern with direct rendering where each screen
owns its footer. This eliminates FooterControlsContext indirection and
makes the code follow standard React composition patterns.
- Remove GlobalFooter and FooterControlsProvider from _layout.tsx
- Add HomeFooter component rendered directly in home screen
- Render AgentInputArea directly in agent screen (not via registration)
- Add keyboard animation and safe area handling to AgentInputArea
- Move FOOTER_HEIGHT constant to shared constants/layout.ts
- Delete footer-controls-context.tsx and global-footer.tsx
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace greedy sessions selector with granular useShallow selectors
that only extract agent Maps and methods. This prevents HomeScreen
from re-rendering on every agent stream update.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Previously, opening an agent screen would skip fetching timeline history
if stream state already existed in the cache. This caused issues when:
- Opening a running agent after reconnection
- Returning to an agent with stale/incomplete cache
Now we always fetch fresh timeline on open, ensuring:
- Complete history is shown regardless of client state
- Reconnection scenarios work correctly
- Agent state is always up-to-date
Uses a ref to track initialization per mount to prevent infinite loops.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add top-level agentLastActivity Map to store (prevents cascade rerenders)
- Remove lastActivityAt updates from agent_stream handler (only status changes update timestamps)
- useAggregatedAgents now uses agent.lastActivityAt directly
- Remove investigation logging from previous debug session
The root cause was that every stream event updated agent.lastActivityAt,
causing useAggregatedAgents to recalculate, which caused HomeScreen to
rerender even when not visible. Now timestamps only update on meaningful
events (agent status changes), not individual stream tokens.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Remove debug logging and render counters added during performance investigation.
All performance issues have been resolved by:
- Moving drafts to top-level store
- Moving agentLastActivity to top-level store
- Using granular Zustand selectors throughout
- Eliminating useDaemonSession hook
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Delete useDaemonSession hook that selected entire session object
- Move drafts to top-level store (not nested in sessions)
- Refactor all components to use granular useSessionStore selectors
- Fix infinite loop bugs from selector fallbacks (use stable constants)
Before: 15-20 component rerenders per keystroke
After: ~1-2 rerenders per keystroke
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Previously, drafts were nested inside each session object, which caused
the entire session to be recreated on every keystroke. This triggered
rerenders in all components subscribed to the session.
Now drafts are stored at the top level of the Zustand store, keyed by
agentId (not serverId:agentId since agent IDs are globally unique).
This means draft updates only trigger rerenders in components that
subscribe to drafts specifically.
Changes:
- Move drafts from SessionState to SessionStoreState (top-level)
- Add createModalDraft for future use by the create agent modal
- Update getDraftInput/saveDraftInput to work with agentId only
- Update session-context to clear drafts using new API
- Remove investigation console.log statements
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Backend fixes:
- Fix server crash when logging large session_state messages (186 agents)
- Use safe logging that extracts only message/stack properties
- Prevents TypeError in util.inspect on circular refs or deep objects
Frontend loading state fixes:
- Add reactive WebSocket update to prevent stale session.ws references
- Add timeout/retry wrapper for session_state loading (3 retries × 15s)
- Add hasEverReceivedSessionState flag to track cached data across reconnects
- Implement data-aware loading (isInitialLoad vs isRevalidating)
- Show reconnecting badge instead of hiding agents on reconnect
Debug improvements:
- Add detailed connection state logging in useAggregatedAgents
- Add connection status logging in AgentInputArea
- Track connecting reasons for easier debugging
Fixes:
- Agent screen no longer shows false "Offline" toast on reconnect
- Home screen shows loading immediately (no empty state flash)
- Home screen keeps agents visible during reconnect with badge
- Stuck loading has timeout protection with graceful degradation
- Server no longer crashes when sending session_state with many agents
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Finalizes the pure Zustand refactor by ensuring all components properly access both session state and imperative methods through useDaemonSession. Moves CLAUDE.md to root and ignores local overrides.
Changes:
- Fix useDaemonSession to return stable combined state + methods object
- Update components to use useDaemonSession instead of direct context
- Fix realtime context to work with session state only
- Move CLAUDE.md to root, ignore CLAUDE.local.md for local config
- Add proper null checks and type safety throughout
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace direct `agentId` prop usage with `agentIdRef.current` to prevent
messages from being sent to the wrong agent during navigation.
Fixed 3 instances:
- handleSendMessage: Line 383
- handleSendQueuedNow: Line 869
- handleCancelAgent: Line 834
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Problem: After migrating to pure Zustand, useDaemonSession returned only
SessionState from the store, but components need both state AND imperative
APIs (like sendAgentMessage, createAgent, etc.).
Solution: Create DaemonSession type that combines:
- SessionState (from Zustand store)
- Imperative APIs (from SessionContext)
- Wrapped store actions (getDraftInput, setFocusedAgentId, etc.)
Changes:
- Added DaemonSession type to use-daemon-session.ts
- useDaemonSession now merges sessionState + context + store actions
- Wraps store actions to bind serverId automatically
- Updated prop types in components to use DaemonSession
- Fixed use-session-directory.ts to use SessionState
This restores component compatibility while keeping pure Zustand architecture.
Still TODO: Fix remaining components that use SessionContext directly
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Problem: lastActivityAt was only updated when agent_state messages arrived
(which only happens on agent lifecycle changes), not when the agent was
actively streaming output. This meant the agent directory showed stale
"last activity" times.
Solution: Update agent.lastActivityAt whenever agent_stream events arrive,
using the event's timestamp. Now lastActivityAt tracks real-time activity.
Updates happen on:
1. agent_state message → lastActivityAt = updatedAt (from server)
2. agent_stream message → lastActivityAt = event.timestamp (real-time!)
This ensures the agent directory always shows fresh activity times.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Problem: Agent directory was still being synced from SessionProvider to
Zustand store, violating the "SessionProvider is just a message handler"
principle and creating unnecessary state duplication.
Solution: Make agent directory pure derived state:
- Removed agentDirectory from SessionStoreState
- Removed setAgentDirectory/clearAgentDirectory actions
- Changed getAgentDirectory to compute on-demand from session.agents
- Removed buildAgentDirectoryEntries and syncing from SessionProvider
- Updated useAggregatedAgents to derive from sessions directly
How it works now:
- Agent directory is computed on-demand from session.agents Map
- lastActivityAt automatically updates when agents update via WebSocket
- No syncing, no stale state, no overhead
- Single source of truth: session.agents
Benefits:
- Eliminated redundant state (agentDirectory was duplicate of agents)
- No sync overhead or complexity
- Always fresh data (derived on read)
- Simpler mental model (agents is the only source)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Problem: SessionContext used useSyncedSessionState which synced every state
update from React useState to Zustand, creating double overhead and complexity.
Solution: Complete migration to pure Zustand architecture:
- session-store.ts is now the single source of truth
- Moved ALL state directly into Zustand (no React useState)
- Added per-session state: messages, agents, commands, permissions, etc.
- Added Zustand actions for all state updates (setMessages, setAgents, etc.)
- Exported all types (MessageEntry, Agent, Command, etc.)
- session-context.tsx is now a pure WebSocket message handler
- Removed useSyncedSessionState hook entirely
- Removed all useState calls for session state
- Removed sync machinery (syncSessionField, syncSessionPartial)
- WebSocket handlers now call Zustand setters directly
- Context only provides imperative APIs (ws, audioPlayer, actions)
- No state values in context
Architecture change:
Before: WebSocket → React useState → sync → Zustand (double overhead)
After: WebSocket → Zustand directly (single source of truth)
Benefits:
- Eliminated double overhead from React → Zustand syncing
- Single state update per WebSocket message
- Better re-render optimization via Zustand selectors
- Cleaner separation: SessionProvider = message handler, SessionStore = state
- Reduced complexity: removed 400+ lines of hybrid sync code
Backward compatibility:
- useDaemonSession() already reads from Zustand, no changes needed
- Type exports re-exported from session-store for compatibility
- Components work exactly the same
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit implements a critical performance optimization by removing
unused orchestrator logic that was causing thousands of unnecessary
store updates per minute:
1. Removed orchestratorFocusedAgentId state and auto-selection logic
- The orchestrator auto-selected "most recently active agent"
- Nothing in the codebase actually reads focusedAgentId
- Simplified focusedAgentId to just focusedAgentOverride (user selection only)
2. Stopped updating timestamps on every stream event
- Previously updated lastActivityAt/updatedAt on every agent_stream event
- These events occur 15+ times per second during streaming
- Created 2700+ store updates per minute from a single agent
3. Removed focusedAgentId from store sync
- No longer syncs focusedAgentId changes to the store
- Reduces cascading updates throughout the app
Expected impact:
- 95%+ reduction in store updates during agent streaming
- Home screen no longer re-renders during agent activity
- Improved UI responsiveness and reduced battery usage
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
The previous fix only applied unstable_transformImportMeta to the native
platform, but Zustand 5's import.meta.env usage also breaks on web.
Moving the transform to the top level ensures it applies to both web and
native platforms, fixing the "Cannot use 'import.meta' outside a module"
error across all platforms.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- use recorderState.isRecording instead of recorderRef.current.isRecording
- avoid touching native shared object after it's been released
- fixes production crash: 'cannot cast to AudioRecorder (received Integer)'
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- add shared useDictation hook to prevent double-stop races
- refactor modal + agent chat to consume shared API
- improve web recorder errors with secure-context messaging
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
1. Lazy agent loading - fix race condition where prompts sent before initialization completes:
- Add ensureAgentLoaded() helper that deduplicates initialization requests
- Update handleSendAgentMessage/Audio to await agent initialization before streaming
- Fix status updates being sent to client after initialization
2. Type safety - remove unsafe 'as any' casts for agent status:
- Create AGENT_LIFECYCLE_STATUSES constant as single source of truth
- Export AgentStatusSchema from messages.ts for reuse
- Update registry schema to validate lastStatus against AgentStatusSchema
- Add .default("closed") to handle missing status values from legacy files
- Remove (record.lastStatus as any) cast in buildStoredAgentPayload
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>