Commit Graph

2531 Commits

Author SHA1 Message Date
Mohamed Boudra
545fad1b71 chore: update Claude Agent SDK to 0.1.75 for Opus 4.5
Updated @anthropic-ai/claude-agent-sdk from 0.1.74 to 0.1.75.
This version includes Opus 4.5 model (claude-opus-4-5-20251101).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 17:03:56 +00:00
Mohamed Boudra
20f94e48f7 plan: complete git diff loading investigation task
Root cause identified: Infinite loop in git-diff.tsx due to unstable
requestGitDiff function reference. The useEffect depends on this
function which changes on every store update, causing repeated
git_diff_request calls (250+ times in seconds).

Added findings section documenting:
- Data flow analysis showing the dependency chain
- The exact loop mechanism
- Console evidence (setGitDiffs/setSessionMethods called 250+ times)
- Required fix: remove requestGitDiff from useEffect dependencies

Added follow-up tasks:
- Fix task to remove unstable dependency
- Test task to verify git diff loads correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 17:00:55 +00:00
Mohamed Boudra
d5344af45d plan: complete model info re-audit task
Re-audit confirms all model info tracking tasks are complete:
- Claude SDK investigation found model in init message
- Implementation captures model in handleSystemMessage()
- Fixed refreshRuntimeInfo() to emit state on changes
- Both Claude and Codex agents show actual runtime models
- All tests passed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:56:35 +00:00
Mohamed Boudra
b605b53702 test: verify Claude agent model display behavior (PASSED)
Created Claude agent with "Automatic" model config. Agent correctly
self-reported running on claude-opus-4-1-20250805 (Opus 4.1), and
the agent info menu now displays the correct runtime model instead
of "Unknown". The fix for capturing model from SDK init message and
emitting state after runtimeInfo changes is working correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:55:42 +00:00
Mohamed Boudra
b1afa55778 test: verify Claude agent model display behavior (FAILED)
Created a new Claude agent with "Automatic" model config.
The agent responded correctly stating it runs on Claude Opus 4.1.
However, the model still shows "Unknown" in the agent info menu.

Root cause: The server wasn't restarted after the fix was implemented.
The dev server uses tsx with explicit restart messaging - it doesn't
auto-reload on file changes. The fix code exists in source but the
server is running stale code.

Added follow-up tasks:
- Restart server to apply model capture fix
- Re-test Claude model display after server restart

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:52:01 +00:00
Mohamed Boudra
1bf4a1d478 fix: emit state after refreshing runtime info so clients get model updates
The Claude agent model was not showing in the UI ("Model: Unknown") because
refreshRuntimeInfo() updated agent.runtimeInfo but never called emitState()
to notify connected clients of the change.

Fixed by:
1. Adding change detection in refreshRuntimeInfo() to check if model, sessionId,
   or modeId changed
2. Calling emitState(agent) when changes are detected
3. Added debug logging in handleSystemMessage() to confirm model capture

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:47:42 +00:00
Mohamed Boudra
071f83db86 test: verify Claude agent model display behavior (FAILED)
Created Claude agent with 'Automatic' model config. Agent self-reported
running on claude-opus-4-1-20250805 (Opus 4.1), but UI shows 'Model: Unknown'
in agent info menu.

The implementation to capture model from SDK init message is not working -
model is not being propagated to the UI.

Added fix task and re-test task to address the issue.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:43:10 +00:00
Mohamed Boudra
d46bf8c5ac test: verify Codex runtime model detection works
Tested Codex agent creation with "Automatic" model config.
After first turn completion, UI correctly displays `gpt-5.1-codex-max`
(actual runtime model from rollout file), confirming runtime model
detection is working correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:39:58 +00:00
Mohamed Boudra
e1631fcab6 feat: capture actual model from Claude SDK init message
Update handleSystemMessage() in claude-agent.ts to read the actual model
from the SDK's init message (message.model) instead of just echoing back
the configured model. This gives us the real runtime model that the SDK
selected.

Also invalidates cached runtime info when the model is updated to ensure
getRuntimeInfo() returns the new value.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:36:43 +00:00
Mohamed Boudra
845a2120ee docs: document Claude SDK model info investigation findings
Investigated @anthropic-ai/claude-agent-sdk types and found that actual
model info is exposed in two places:
1. SDKSystemMessage (init) has `model` field
2. SDKResultMessage has `modelUsage` with model names as keys

Current implementation ignores both, only using config.model.
Added implementation task to capture actual model from init message.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:34:48 +00:00
Mohamed Boudra
67fba8e96f docs: audit model info implementation and expand plan
Completed audit of current model info tracking implementation:

- Model config set via AgentSessionConfig.model
- Runtime info uses AgentRuntimeInfo type with model field
- UI correctly uses extractAgentModel() which reads runtimeInfo.model

Key findings:
- Codex agents: Correctly detect runtime model from rollout file ✓
- Claude agents: Currently echo configured model (not runtime detected)
- Gap: Claude SDK may expose actual model in response metadata

Added follow-up tasks:
- Investigate if Claude SDK exposes actual model in responses
- Test Codex runtime model detection
- Test Claude agent model display behavior
- Re-audit plan after investigation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 16:33:00 +00:00
Mohamed Boudra
abe3a42478 feat: add agent runtime info tracking with model detection from rollout files 2025-12-21 23:16:49 +07:00
Mohamed Boudra
a70842d9ef feat: auto-detect and use system-installed codex binary from PATH
Implements automatic detection and usage of system-installed Codex binary
with transparent fallback to embedded binary.

Changes:
- Add detectSystemCodexPath() to check for codex in PATH using `which`
- Update CodexAgentClient constructor to auto-detect system binary
- Log which binary is being used (system vs embedded) for debugging
- Preserve ability to explicitly override via codexPathOverride option

Benefits:
- No manual configuration required
- Uses latest system codex when available
- Seamless fallback to embedded binary
- Transparent to rest of codebase

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-20 13:30:49 +07:00
Mohamed Boudra
f06170fcee feat: upgrade codex-sdk to 0.76.0 and claude-agent-sdk to 0.1.74
Upgrade packages to access latest model catalogs:
- @openai/codex-sdk: 0.58.0 → 0.76.0
- @anthropic-ai/claude-agent-sdk: 0.1.37 → 0.1.74

New models available after upgrade:
- Claude: Added Opus 4.5 and Haiku 4.5 to catalog
- Codex: Added gpt-5.2, gpt-5.2-codex, and gpt-5.1-codex variants

Updated patch file for new codex-sdk version.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-20 13:10:57 +07:00
Mohamed Boudra
b8de55f31b Merge branch 'main' of github.com:boudra/voice-dev 2025-12-20 12:58:17 +07:00
Mohamed Boudra
fb30160cda feat: add batch clear attention and orchestrator mode instructions 2025-12-20 05:57:54 +00:00
Mohamed Boudra
5466ea1967 Merge branch 'main' of github.com:boudra/voice-dev 2025-12-20 12:57:33 +07:00
Mohamed Boudra
a6d2ea3153 fix: add input field to tool call data and simplify CLAUDE.md orchestrator docs 2025-12-20 12:56:59 +07:00
Mohamed Boudra
0f1758709d feat: add "Requires Attention" agent grouping feature
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>
2025-12-04 11:27:08 +00:00
Mohamed Boudra
fd36c9b8e2 feat: add --isolated flag to Playwright MCP for Claude Code provider
Added the --isolated flag to the Playwright MCP configuration to ensure
browser instances run in isolated contexts, preventing state leakage
between different agent sessions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 23:03:45 +07:00
Mohamed Boudra
2a541d97c9 fix: capture input parameters for MCP and server tool calls
Previously, only standard tool_use blocks had their input parameters
captured in upsertToolUseEntry. MCP tools (mcp_tool_use) and server
tools (server_tool_use) were being handled for execution but their
inputs were never stored in the tool cache, resulting in missing input
data in the UI.

Now all three tool types have their inputs properly captured and
normalized, ensuring consistent tool call display across all tool types.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 22:55:14 +07:00
Mohamed Boudra
98c24f22a0 refactor: simplify footer architecture by removing global footer pattern
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>
2025-12-03 22:25:30 +07:00
Mohamed Boudra
5cbeb97391 refactor: simplify AgentManager by removing over-engineered freeze/clone logic
Remove ReadonlyPendingPermissionsMap class and related deep cloning/freezing
methods that were causing "ManagedAgent views returned by AgentManager are
read-only" errors. The bug occurred because Map constructor internally calls
.set() which was overridden to throw.

Replace with simple shallow clones - sufficient because all consumers either
read 1-2 fields or immediately serialize via toAgentPayload() which already
creates safe copies.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 21:54:55 +07:00
Mohamed Boudra
d3ad27e10a feat: improve Agent Control MCP activity endpoint with count headers
Enhance the get_agent_activity tool to provide better context about the activity list:
- Add activity count headers showing "X of Y activities"
- Remove raw format option, always use curated format for consistency
- Simplify implementation by removing unnecessary format branching
- Respect limit parameter to show most recent N activities

This makes it clearer to users when they're viewing a subset of activities versus the full list.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 21:03:48 +07:00
Mohamed Boudra
9aacc26eb6 feat: add 60-second timeout to Agent Control MCP wait operations
Implement hard-coded 60-second timeout for agent wait operations in three tools:
- create_agent (when background=false and initialPrompt provided)
- send_agent_prompt (when background=false)
- wait_for_agent (always)

When timeout occurs, returns gracefully with message "Awaiting the agent timed out, await again" instead of throwing an error. Agent continues running after timeout.

Added AGENT_WAIT_TIMEOUT_MS constant and waitForAgentWithTimeout helper function to handle timeout logic with proper cleanup and signal forwarding.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 20:53:01 +07:00
Mohamed Boudra
5f645d6b7a perf: use shallow selectors in useAggregatedAgents to reduce re-renders
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>
2025-12-03 20:47:10 +07:00
Mohamed Boudra
56e2af2308 refactor: move mode validation into AgentSession implementations
Move mode validation from AgentManager into the individual AgentSession
implementations (ClaudeAgentSession and CodexAgentSession) where it belongs.

Each session validates modes in:
- Constructor (when config.modeId is provided)
- setMode() method (when mode is changed)

This follows the principle that the AgentManager is a coordinator while
the AgentSession is the authority on what modes it supports.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 20:17:25 +07:00
Mohamed Boudra
7b649eb77f feat: add centralized mode validation for agent providers
Prevents server crashes when invalid modes are passed to agents by
validating mode IDs before attempting to set them on the SDK.

- Export VALID_CLAUDE_MODES and VALID_CODEX_MODES from provider files
- Add validateMode() function in agent-manager.ts
- Apply validation in createAgent(), resumeAgent(), and setAgentMode()
- Throws clear error listing valid modes when validation fails

This fixes the crash when 'read-only' (Codex mode) was passed to
a Claude agent.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 20:03:38 +07:00
Mohamed Boudra
b7eed8409b fix: handle promise rejections in claude-agent fire-and-forget patterns
Fixed two fire-and-forget promise patterns that could cause unhandled rejections:
- interruptActiveTurn() in requestCancel closure - now catches errors and logs warning
- forwardPromptEvents() in stream method - now catches errors and logs to console

Both now properly handle promise rejections to prevent Node.js process crashes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 20:02:51 +07:00
Mohamed Boudra
2699e198d6 fix: always fetch agent timeline on screen open
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>
2025-12-03 19:14:37 +07:00
Mohamed Boudra
644c654274 perf: prevent HomeScreen rerenders during agent streaming
- 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>
2025-12-03 17:34:07 +07:00
Mohamed Boudra
4c1ba8f1b1 chore: remove investigation logging from performance work
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>
2025-12-03 17:33:23 +07:00
Mohamed Boudra
21d43bc249 perf: eliminate cascading rerenders with granular Zustand selectors
- 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>
2025-12-03 16:37:23 +07:00
Mohamed Boudra
74c82a312e perf: move drafts to top-level store to prevent session rerenders
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>
2025-12-03 15:46:45 +07:00
Mohamed Boudra
d5f8091d66 refactor: simplify modal mounting with lazy wrapper and add read-only git env 2025-12-03 14:09:56 +07:00
Mohamed Boudra
f4f7790d07 fix: improve terminal init error handling and websocket debug logging 2025-12-03 13:26:28 +07:00
Mohamed Boudra
43d2794e2d chore: remove plan.md 2025-12-03 12:43:41 +07:00
Mohamed Boudra
e346b4c026 Replace reconnecting badge with pull-to-refresh
UX improvements:
- Remove misleading "Reconnecting..." badge overlay
- Implement native pull-to-refresh gesture on agent list
- Add manual refresh capability via pull gesture

Technical changes:
- Add refreshSession() method to session context
- Add refreshAll() to useAggregatedAgents hook
- Integrate RefreshControl in AgentList component
- Use isRevalidating state for refresh indicator
- Apply theme colors to RefreshControl for consistency

Benefits:
- Familiar iOS/Android UX pattern
- No UI overlays blocking content
- Clear user action (pull) → clear feedback (refresh)
- Accurate state representation (syncing vs reconnecting)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 02:57:38 +00:00
Mohamed Boudra
348cb9d637 Fix loading state bugs and server crash
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>
2025-12-03 02:45:16 +00:00
Mohamed Boudra
5ddaea7352 Complete Zustand migration: fix component access to session APIs
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>
2025-12-02 17:42:49 +00:00
Mohamed Boudra
473e11d25f Fix stale closure bug in agent-input-area message handlers
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>
2025-12-02 17:17:54 +00:00
Mohamed Boudra
e8aa08159a Fix useDaemonSession to return combined state + APIs
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>
2025-12-02 14:27:57 +00:00
Mohamed Boudra
f5ec3bffb7 Update agent lastActivityAt on stream events
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>
2025-12-02 14:16:50 +00:00
Mohamed Boudra
8b87b0a4e2 Remove agent directory syncing, make it pure derived state
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>
2025-12-02 14:15:32 +00:00
Mohamed Boudra
f5c6bce54f Migrate SessionContext to pure Zustand, eliminate hybrid overhead
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>
2025-12-02 14:08:56 +00:00
Mohamed Boudra
32e111e1bf fix: remove unused focusedAgentId orchestrator logic and timestamp thrashing
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>
2025-12-02 13:14:49 +00:00
Mohamed Boudra
6615b23c8b fix: apply import.meta transform to ALL platforms (web + native)
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>
2025-12-02 11:25:18 +00:00
Mohamed Boudra
7896bdd42c revert: remove Phase 3 complexity - server handles persistence 2025-12-02 11:06:57 +00:00
Mohamed Boudra
3208624c5e perf: cap messages and optimize persistence (Phase 3) 2025-12-02 10:50:11 +00:00
Mohamed Boudra
0ba5e481f4 fix: Phase 2 review issues 2025-12-02 10:33:49 +00:00