Commit Graph

239 Commits

Author SHA1 Message Date
Mohamed Boudra
315dbe20f3 fix: remove stale raw field expectation from test
The 'raw' field was removed from timeline entries in commit e80989e
(Nov 28) to reduce payload sizes by 64-85%. This test was never updated
and has been broken since then. Remove the stale expectation to align
with the current implementation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 01:06:01 +00:00
Mohamed Boudra
34f13d4439 docs: record managed agent snapshot cleanup 2025-11-30 00:32:27 +00:00
Mohamed Boudra
e2924f7523 refactor: derive session payloads from ManagedAgent 2025-11-30 00:14:00 +00:00
Mohamed Boudra
7aec973323 refactor: update registry persistence to use ManagedAgent
Remove AgentSnapshot from persistence layer. AgentRegistry now accepts
ManagedAgent and uses toStoredAgentRecord for atomic config + lifecycle
persistence. Deleted obsolete recordConfig method.

- Update applySnapshot to accept ManagedAgent and use toStoredAgentRecord
- Remove recordConfig method entirely (no longer needed)
- Remove sanitizeConfig helper (handled by projection)
- Update session to stop calling deleted recordConfig
- Add ManagedAgent test fixtures to registry and persistence-hook tests
- Test config persistence, title retention, and subscription forwarding

Registry and persistence-hooks now typecheck cleanly. Expected failures
in session/mcp-server/messages (still reference AgentSnapshot).

Task 4 of 8 in agent architecture refactor.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 00:03:00 +00:00
Mohamed Boudra
8a708aab8b refactor: convert ManagedAgent to discriminated unions and remove AgentSnapshot
Replace ManagedAgent with discriminated union keyed on lifecycle state
to make impossible states unrepresentable. Remove AgentSnapshot type
and toSnapshot method entirely - consumers now receive ManagedAgent
directly.

- Define ManagedAgent as discriminated union with 5 lifecycle states
- Add comprehensive immutability protection (deep clone + freeze)
- Update getAgent/listAgents to return immutable ManagedAgent views
- Remove AgentSnapshot type and toSnapshot method
- Update event emissions to use ManagedAgent

Breaking change: All consumers must now use ManagedAgent or projection
functions instead of AgentSnapshot.

Tasks 2 & 3 of 8 in agent architecture refactor.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 00:02:47 +00:00
Mohamed Boudra
2794a5b63c feat: add pure projection functions for ManagedAgent transformations
Introduce toStoredAgentRecord and toAgentPayload as deterministic
pure functions to project ManagedAgent state to persistence and
client payload formats. This eliminates the need for AgentSnapshot
as an intermediate representation.

- Add toStoredAgentRecord for persistence projection
- Add toAgentPayload for client communication projection
- Add comprehensive test suite covering all lifecycle states
- Handle optionality at boundaries with proper null/undefined semantics

Task 1 of 8 in agent architecture refactor.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 00:02:37 +00:00
Mohamed Boudra
0dfa2f04bd refactor: remove status from recordConfig, add design proposal
- recordConfig no longer writes lastStatus (handled by applySnapshot only)
- Add warning if recordConfig called before snapshot exists
- Update tests to reflect new separation of concerns
- Add AGENT_REFACTOR_PROPOSAL.md with comprehensive design plan

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 23:24:25 +00:00
Mohamed Boudra
898b8ce5a1 fix: lazy agent loading and type safety improvements
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>
2025-11-29 22:44:03 +00:00
Mohamed Boudra
5660935a4b perf: remove eager agent restoration blocking server startup
Remove blocking restorePersistedAgents() call that was resuming all 87
agents before opening the HTTP socket. The architecture already supports
lazy loading through handleInitializeAgentRequest() - agents are shown
in the UI from the registry and only initialized when clients request them.

This eliminates:
- Sequential thread resumes with network handshakes to Codex/Claude
- Synchronous history file reads from disk
- DNS lookups and model catalog fetches
- 87 awaited operations before socket binding

Server now starts immediately by just loading the lightweight agents.json
registry. Agents resume on-demand when requested by clients.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 22:05:47 +00:00
Mohamed Boudra
36facf4bfd Fix MCP server: create separate McpServer instance per session
Previously shared one McpServer instance across all sessions/transports,
which caused Protocol._transport to be overwritten when new sessions
connected. This broke message routing for requests on previous transports
after long-running SSE streams.

Now creates a new McpServer instance per session, following the stateful
session pattern from the MCP SDK documentation. Each session gets its own
server+transport pair, preventing transport reference conflicts.

Fixes issue where get_agent_status would fail after wait_for_agent completed.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 21:39:46 +00:00
Mohamed Boudra
6b9fbb83c0 Fix MCP request hangs caused by agent interruption
This fixes two root causes of MCP tool calls hanging indefinitely:

1. Transform ensureValidJson from validator to transformer
   - Previously threw errors on undefined values, causing handlers to crash
   - Now converts undefined→null, Date→ISO string, bigint→string, etc.
   - Ensures all MCP handlers always return valid JSON responses

2. Cancel waitTracker when interrupting agents
   - Added waitTracker.cancel() in cancel_agent handler
   - Added waitTracker.cancel() in kill_agent handler
   - Resolves waiting wait_for_agent promises when agents are interrupted
   - Prevents indefinite hangs requiring server restart

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 11:41:11 +00:00
Mohamed Boudra
7c1517d830 feat(server): add Playwright MCP with headless mode to spawned Claude agents
Spawned agents now get Playwright browser automation capabilities by default.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 05:08:56 +00:00
Mohamed Boudra
53d91a319e fix(app): use pre-parsed props for Codex file edit diffs
ToolCall component had parsedEditEntries, parsedReadEntries, and
parsedCommandDetails props defined but never used them. Now prefers
these pre-parsed props when available, enabling Codex apply_patch
diffs to render correctly in the expanded view.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 01:04:33 +00:00
Mohamed Boudra
4311c3aebd feat(codex): add structured file edit output with diffs for restored sessions
Add structured output matching StructuredToolResult type for Codex
apply_patch operations when parsing rollout files. This enables the
frontend to render file edit diffs for restored Codex sessions, matching
the behavior of Claude agent file edits.

Note: For live streaming, the Codex SDK only provides file_change events
with {path, kind} without actual patch content. The structured diffs are
only available for restored sessions via rollout file parsing.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 19:57:46 +00:00
Mohamed Boudra
bf04b7d5df fix(codex): use aggregated_output for structured command results
Codex SDK uses aggregated_output and exit_code fields for command
execution results (not output). Build structured output matching
StructuredToolResult type so frontend renders Codex commands the
same way as Claude commands.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 19:46:55 +00:00
Mohamed Boudra
4001b7dc0a refactor: remove heuristic parsing, use pure type-based tool rendering
- Remove all heuristic parsing code from message.tsx (hasCommandDetails,
  commandSection, editSections, readSections, hasStructuredContent, etc.)
- Replace with simple raw JSON fallback for tools without structured results
- Fix server-side support for Claude SDK's old_string/new_string params
  (in addition to old_str/new_str)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 19:38:42 +00:00
Mohamed Boudra
38b08fec0c feat: add structured tool result types for better rendering
Server-side:
- Add StructuredToolResult discriminated union type with command, file_write,
  file_edit, file_read, and generic variants
- Implement buildStructuredToolResult in claude-agent.ts to detect tool types
  and emit properly structured results
- Update codex-agent.ts to emit structured command results

Client-side:
- Add type guard and extraction functions for structured results
- Render tool calls based on result.type when available:
  - command: show command, output, exit code
  - file_write/file_edit: show diff viewer with proper +/- format
  - file_read: show file content
  - generic: show raw JSON
- Fall back to heuristic parsing for backwards compatibility

This fixes file writes showing as "Command: success message" - they now
properly show as diffs with +line additions.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 19:24:52 +00:00
Mohamed Boudra
a7df671144 fix(app): deduplicate tool call expansion sections
Command output was being shown three times: as "Command", as "Read Result",
and as raw JSON "Result". Now:
- Skip "Read Result" when command output is already shown
- Skip raw JSON "Result" when we have structured content to display

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 19:05:41 +00:00
Mohamed Boudra
7278a9515f fix(server): resolve agent cwd to absolute path at creation time
Relative paths like "." resolve differently depending on where the
server is started, causing agent history files to be stored under
different directories. This fixes the empty state issue when loading
agents created with relative paths.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 19:01:00 +00:00
Mohamed Boudra
eea28d59c9 fix(server): extract tool result content from SDK blocks
The Claude SDK returns tool_result blocks with `content` as a string
containing the actual command output. Previously, handleToolResult only
set output when there were file changes (entry?.files), missing all
other tool outputs like shell command results.

Now buildToolOutput extracts block.content and wraps it as
{ result: { output: content } } which the frontend parsers expect.
This fixes "No additional details available" when expanding tool calls.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:52:13 +00:00
Mohamed Boudra
e80989ea78 perf: remove raw field from timeline items to reduce payload size
Remove the `raw` field that was duplicating provider data in timeline
items, reducing WebSocket payload sizes by 64-85%:
- session_state: ~320KB → ~48KB
- agent_stream_snapshot: ~320KB → ~114KB

Changes:
- Remove raw from AgentTimelineItem, AgentStreamEvent, AgentPermissionRequest
- Remove raw assignments from claude-agent.ts and codex-agent.ts
- Remove provider_event handling from stream.ts (only used for Codex raw)
- Update tests to reflect new behavior

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:20:33 +00:00
Mohamed Boudra
ae4678bca8 fix: eliminate duplicate WebSocket messages during agent history priming
- Skip dispatching individual agent_stream events when replaying history
  (the snapshot is sent after priming anyway, so individual events were wasted)
- Add WebSocket message logging on client (type, size, id) for debugging
- Change default daemon URL from dev to localhost
- Clean up unused imports in session.ts

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 17:44:07 +00:00
Mohamed Boudra
3dc517366d fix: record user messages for MCP-triggered agent prompts
Ensures MCP-originated prompts emit timeline events in real-time by calling recordUserMessage before starting agent runs. Fixes issue where messages sent via MCP tools only appeared after page refresh.

- Add recordUserMessage call in send_agent_prompt tool
- Add recordUserMessage call in create_coding_agent with initialPrompt
- Both paths now mirror UI-sent message behavior

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 12:48:21 +00:00
Mohamed Boudra
1b019c4688 chore: update android scripts and add dev runner with IPC restart support 2025-11-28 11:39:31 +01:00
Mohamed Boudra
2c84447ec2 fix(app): resolve create agent dictation confirm handler timing issue
Fixed a state management bug where clicking the checkmark in create agent dictation mode would not trigger processing. The issue was that setIsDictationProcessing(true) was called after stopping the recorder, causing a race condition where the UI never showed the processing state.

Changes:
- Move setIsDictationProcessing(true) to execute immediately at the start of the confirm handler
- Add proper cleanup when audioData is null
- Ensure UI shows loading spinner when checkmark is clicked

This aligns the create agent dictation behavior with the working agent chat dictation implementation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 10:10:31 +00:00
Mohamed Boudra
b97ae99b2b feat(app): add Android product flavors and env-based daemon config 2025-11-28 08:19:41 +01:00
Mohamed Boudra
08dc2ed937 feat(app): add zustand store for session state management 2025-11-27 21:36:03 +01:00
Mohamed Boudra
bf58e81ce8 refactor(app): simplify session directory with direct snapshots and add sessionReady state
Replace subscription-based session accessor pattern with direct snapshot updates in daemon connections context. Add sessionReady flag to connection state to track when initial agent list has been received. Auto-select first ready host in create agent modal. Migrate from app.json to app.config.js. Add android:release script and Playwright testing docs.
2025-11-27 21:06:48 +01:00
Mohamed Boudra
a01c3f9b73 Flatten home screen agent list and sort by activity
The agent list on the home screen now displays all agents in a single flat
list rather than grouped by host. Each row shows a host badge next to the
agent title so users can still identify which host an agent belongs to.
Agents are sorted globally by status (running first) then by most recent
activity, providing a unified view across all hosts.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 20:18:49 +01:00
Mohamed Boudra
135bcf13a8 Fix create agent modal incorrectly showing hosts as offline
The availability check was failing for online hosts due to a timing
issue: connectionStates would show "online" before SessionProvider
registered its session accessor, causing session to be null.

Changed selectedDaemonIsUnavailable to selectedDaemonIsOffline which
only checks connectionStates status (the single source of truth for
connection state), removing the redundant session and ws.isConnected
checks. isTargetDaemonReady still requires session for actual operations.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 20:12:11 +01:00
Mohamed Boudra
0c571f6f43 Add loading indicator to home screen while agents are fetching
useAggregatedAgents now returns { groups, isLoading } where isLoading is true
while the daemon registry loads or while hosts are connecting without a session.
HomeScreen shows an ActivityIndicator during loading, then either the agent
list or empty state. Offline hosts don't block loading—only connecting hosts do.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 20:07:33 +01:00
Mohamed Boudra
69881d3862 Remove connection status banners from home screen
Host health now only displays in Settings. The home screen no longer
shows offline/connecting/error banners for hosts, following the
principle that a stopped host is not an error.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 20:03:22 +01:00
Mohamed Boudra
c88bbd3ee8 Rename "Server" to "Host" in Settings add-host form and restart alert
- Change placeholder text from "My Server" to "My Host"
- Change restart success alert title from "Server reachable" to "Host reachable"

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 19:58:31 +01:00
Mohamed Boudra
e98952bf4c Remove manual connect prompts 2025-11-26 19:47:55 +01:00
Mohamed Boudra
0db0e1ad23 Clarify automatic host reconnection 2025-11-26 19:33:43 +01:00
Mohamed Boudra
393aa44e68 feat: auto reconnect hosts when app resumes 2025-11-26 19:26:27 +01:00
Mohamed Boudra
99b055d2f9 Remove global settings test form 2025-11-26 19:09:19 +01:00
Mohamed Boudra
4f00e07284 Eliminate hidden host defaults 2025-11-26 19:02:47 +01:00
Mohamed Boudra
670c38ab8c Remove legacy host auto-connect state 2025-11-26 18:53:53 +01:00
Mohamed Boudra
737e8904be Remove auto-connect toggle from host settings 2025-11-26 18:42:36 +01:00
Mohamed Boudra
db87f331fb Remove primary host plumbing 2025-11-26 18:30:04 +01:00
Mohamed Boudra
5807f62f1a Remove active host dependency from UI actions 2025-11-26 18:04:40 +01:00
Mohamed Boudra
e6d2998904 Remove primary host concept 2025-11-26 17:51:25 +01:00
Mohamed Boudra
3524b0facb Remove active host notion from UI 2025-11-26 17:39:07 +01:00
Mohamed Boudra
04d51fbe10 Rename daemon UI copy to host 2025-11-26 17:26:25 +01:00
Mohamed Boudra
59967aad87 chore: land multi-daemon rollout 2025-11-26 08:47:49 +00:00
Mohamed Boudra
4ab79b1a50 feat: add multi-daemon support with session routing and connection management
Introduce DaemonRegistry and DaemonConnections contexts for managing multiple server connections. Add session directory for aggregating agents across daemons, with automatic routing based on agent/server context.

Key changes:
- Add daemon profile management (add/edit/remove/set default)
- Implement connection state tracking with reconnection and exponential backoff
- Create useAggregatedAgents hook for unified agent list across daemons
- Add useDaemonSession and useDaemonRequest hooks for daemon-scoped operations
- Update agent routes to include serverId for proper session routing
- Add connection health indicators on home screen and settings
- Persist session snapshots per daemon for faster hydration on reconnect
- Guard screens gracefully when target daemon is offline
- Add React Query for consistent loading/error state management

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 08:25:02 +01:00
Mohamed Boudra
7d8979e125 chore: declare encryption usage 2025-11-24 23:16:31 +01:00
Mohamed Boudra
cc4a210ebe chore: align expo slug for eas 2025-11-24 22:33:49 +01:00
Mohamed Boudra
30d1b63b2b chore: typecheck and build readiness 2025-11-24 22:31:41 +01:00