Codex App-Server V2 Implementation
December 13, 2025 · View on GitHub
A Tauri + React application integrating with Codex app-server using the v2 protocol.
Architecture
Backend (Rust + Tauri)
Core Components
-
CodexClient (
src-tauri/src/codex/client.rs)- Spawns
codex app-serverprocess via stdin/stdout - Manages JSON-RPC communication
- Handles event loop for notifications and server requests
- Emits events to frontend via Tauri event system
- Spawns
-
Tauri Commands (
src-tauri/src/commands.rs)codex_initialize()- Initialize and spawn app-serverthread_start(params)- Create new threadthread_resume(params)- Resume existing threadturn_start(params)- Send message and start turnturn_interrupt(params)- Stop ongoing turnrespond_to_approval(response)- Respond to approval requests
-
State Management (
src-tauri/src/state.rs)- Manages CodexClient instance in application state
-
Type Definitions (
src-tauri/src/codex/types.rs)- ApprovalRequest - Unified approval request type
- ApprovalRequestKind - CommandExecution | FileChange
Event Flow
Frontend → Tauri Command → CodexClient → app-server (stdin)
↓
Frontend ← Tauri Event ← CodexClient ← app-server (stdout)
Frontend (React + Zustand)
State Management
-
useCodexStore (
src/stores/useCodexStore.ts)- Manages threads, turns, and processing state
- Actions: initialize, threadStart, threadResume, turnStart, turnInterrupt
- Uses v2 protocol types from bindings
-
useApprovalStore (
src/stores/useApprovalStore.ts)- Manages pending approval requests
- Actions: addApproval, respondToApproval
Hooks
- useCodexEvents (
src/hooks/useCodexEvents.ts)- Listens to Tauri events from backend
- Handles approval requests and server notifications
- Auto-updates stores with incoming events
Components
-
ChatPage (
src/pages/chat-page.tsx)- Main layout container
- Initializes Codex on mount
- Integrates ThreadList, ChatInterface, and ApprovalDialog
-
ThreadList (
src/components/ThreadList.tsx)- Left sidebar showing all threads
- Create new thread button
- Thread selection and resume
-
ChatInterface (
src/components/ChatInterface.tsx)- Main chat area with event rendering
- Textarea for user input
- Send button (or Stop button when processing)
- Keyboard shortcuts: Enter to send, Shift+Enter for new line
-
ApprovalDialog (
src/components/ApprovalDialog.tsx)- Modal dialog for approval requests
- Shows command execution or file change details
- Actions: Approve Once, Approve for Session, Decline
Protocol V2 Features
Thread Management
- ThreadStart - Create new conversation thread
- ThreadResume - Resume existing thread
- ThreadList - List all threads
- ThreadArchive - Archive thread
Turn Management
- TurnStart - Send message and start agent turn
- TurnInterrupt - Stop ongoing turn
- Turn status tracking (inProgress, completed, failed, interrupted)
Approval System
-
Command Execution Approval
- Triggered when agent wants to execute commands
- Shows proposed command and reason
- Can approve with execpolicy amendment
-
File Change Approval
- Triggered when agent wants to modify files
- Shows grant root and reason
- Can approve for session
Event Streaming
- Real-time event notifications via Tauri events
- Event types:
- thread/started
- turn/started, turn/completed
- item/started, item/completed
- item/agentMessage/delta (streaming text)
- item/commandExecution/outputDelta
- item/fileChange/outputDelta
- error notifications
Type System
All types are generated from Rust and exported to TypeScript:
- V2 protocol types:
@/bindings/v2/* - V1 events:
@/bindings/EventMsg - Auto-generated, no manual type definitions needed
Usage
- Initialize: App auto-initializes Codex on startup
- Create Thread: Click "New Thread" button
- Send Message: Type message and press Enter or click Send
- Stop Processing: Click Stop button (square icon) to interrupt
- Approve Actions: When approval dialog appears, choose to approve or decline
- Resume Thread: Click on thread in sidebar to resume
Configuration
The backend uses codex command directly. To configure the path to Codex binary:
- Set PATH environment variable, or
- Modify backend to use specific path
Future Enhancements
- Thread history display
- Message editing and regeneration
- File diff viewer for file changes
- Command output syntax highlighting
- Thread search and filtering
- Export conversation history