Repository navigation
Closed
Description
Overview
Create all Tauri command functions that bridge the Svelte frontend to the Rust agent backend services. This is the glue layer that connects the UI components (#1003) to the local agent (#1006, #1007), model manager (#1000), ACP client (#1004), and context assembly (#1005).
Also handles service initialization in Tauri managed state and event emission for all agent-related channels.
Acceptance Criteria
- All local agent commands registered and callable from frontend
- All model management commands registered and callable
- All ACP commands registered and callable
- Event emission works for all event channels (streaming, tools, status, download, ACP)
-
LocalAgentServiceandAcpClientServiceregistered as independent Tauri managed state (OUTSIDE AppServices) - Services survive database hot-swap (verified by test)
- Agent services obtain NodeService/NodeEmbeddingService per-operation from AppServices
- GPU lifecycle integration: chat model unloaded during
release_gpu_resources() - Error mapping: Rust errors converted to frontend-friendly strings
- Commands handle concurrent calls safely
- Frontend mock backends replaced with real Tauri invoke calls
- Integration test: invoke command, verify event emission
- Code passes
bun run quality:fix
Technical Specifications
New Modules
packages/desktop-app/src-tauri/src/commands/local_agent.rspackages/desktop-app/src-tauri/src/commands/acp.rs
Local Agent Commands
#[command] async fn local_agent_status() -> Result<LocalAgentStatus, String>
#[command] async fn local_agent_new_session(model_id: String) -> Result<String, String> // returns session_id
#[command] async fn local_agent_send(session_id: String, message: String) -> Result<StopReason, String>
#[command] async fn local_agent_cancel(session_id: String) -> Result<(), String>
#[command] async fn local_agent_end_session(session_id: String) -> Result<(), String>
#[command] async fn local_agent_get_sessions() -> Result<Vec<AgentSession>, String>Model Management Commands
#[command] async fn model_list() -> Result<Vec<(ModelInfo, ModelStatus)>, String>
#[command] async fn model_recommended() -> Result<ModelInfo, String> // RAM-based recommendation
#[command] async fn model_download(model_id: String) -> Result<(), String>
#[command] async fn model_cancel_download(model_id: String) -> Result<(), String>
#[command] async fn model_delete(model_id: String) -> Result<(), String>
#[command] async fn model_load(model_id: String) -> Result<(), String>
#[command] async fn model_unload() -> Result<(), String>ACP Commands
#[command] async fn acp_list_agents() -> Result<Vec<AcpAgentInfo>, String>
#[command] async fn acp_start_session(agent_id: String, context_node_ids: Vec<String>) -> Result<String, String>
#[command] async fn acp_send_message(session_id: String, message: String) -> Result<(), String>
#[command] async fn acp_end_session(session_id: String) -> Result<(), String>
#[command] async fn acp_refresh_agents() -> Result<Vec<AcpAgentInfo>, String>Event Emission
- Forward streaming chunks ->
local-agent://chunk - Forward tool calls ->
local-agent://tool - Forward status changes ->
local-agent://status - Forward errors ->
local-agent://error - Forward download progress ->
model://download-progress - Forward ACP session state ->
acp://session-state - Forward ACP agent messages ->
acp://agent-message
Service Initialization (in lib.rs)
// Agent services are OUTSIDE AppServices — survive database hot-swaps
app.manage(LocalAgentService::new(models_dir));
app.manage(AcpClientService::new());
// Initialize model manager on startup (scan for existing models)
// Start agent registry background health checksKey pattern: Agent services obtain NodeService and NodeEmbeddingService references on each operation via AppServices accessor methods — they never store these long-term.
GPU Lifecycle Integration
- Chat model must be unloaded during
release_gpu_resources() - Follow same drain-then-release ordering as embedding processor shutdown
- Re-load chat model after database switch completes (if model was previously loaded)
Reference Files
packages/desktop-app/src-tauri/src/commands/— existing command patternspackages/desktop-app/src-tauri/src/lib.rs— app initialization and service registrationpackages/desktop-app/src-tauri/src/app_services.rs— AppServices pattern and hot-swap lifecyclepackages/desktop-app/src-tauri/src/mcp_integration.rs— similar independent service pattern
Dependencies
- Shared types, traits, and interface contracts for agent subsystems #998 (types/traits)
- NLP Engine: Chat inference with streaming and tool-call parsing #999 (chat inference)
- GGUF Model Manager with download, verification, and lifecycle #1000 (model manager)
- Frontend: Chat UI, agent panel, model settings, and AI onboarding #1003 (frontend)
- ACP session state machine and orchestration #1004 (ACP session)
- Context assembly: build rich prompts from knowledge graph #1005 (context assembly)
- Local agent ReAct loop with history management and context budgeting #1006 (local agent loop)
- Agent tool executor: graph operation tools for local agent #1007 (agent tools)
Related Issues
- ACP Integration and Local LLM Capability #997 (parent epic)
Activity
malibio commentedon Apr 3, 2026
Implementation Guide
Start Here
Read
packages/desktop-app/src-tauri/src/commands/embeddings.rs— the most complete command example:#[tauri::command]attribute on async functionState<'_, AppServices>+ typed paramsResult<T, CommandError>services.embedding_state().await?for service accessRead
packages/desktop-app/src-tauri/src/commands/nodes.rs— node CRUD pattern:CreateNodeInputstruct (line 22) — input types for frontend serializationCommandError(line 42) — machine-readable codes + user messageFrom<NodeServiceError>impl (line 53) — maps business errors to command errorsRead
packages/desktop-app/src-tauri/src/lib.rslines 380-429 —tauri::generate_handler![]macro where all commands are registered. Your new commands go here.Command Registration
All existing command files are in
packages/desktop-app/src-tauri/src/commands/:db.rs,nodes.rs,embeddings.rs,collections.rs,schemas.rs,settings.rs,diagnostics.rs,import.rs,models.rsmod.rs— module declarations (add your new modules here)You'll create two new files:
commands/local_agent.rs— local agent commandscommands/acp.rs— ACP agent commandsService Initialization Sequence
In
lib.rssetup, services initialize in this order:ShutdownTokenregistered as managed state (line 237)AppServicesregistered as managed state (line 329)initialize_databasecommand → createsServiceBundle→ populatesAppServicesYour agent services initialize in step 2 (before database):
They obtain
NodeServiceper-operation fromAppServices(which may not be initialized yet — commands must handle theNOT_INITIALIZEDerror gracefully).Event Forwarding Pattern
For streaming events from Rust to frontend, follow the pattern in
initialize_domain_event_forwarder()(lib.rs line 48):GPU Lifecycle Integration
During
AppServices::switch_database()(app_services.rs line 174), the chat model must be unloaded. The drain protocol:Your
LocalAgentServiceshould listen for the shutdown signal and unload the chat model. The model reloads on the next agent operation after the new database is initialized.malibio commentedon Apr 4, 2026
Baseline: 124 test files passed, 3850 tests passed (worktree agent-a2329807)
feat: Tauri command layer wiring frontend to agent backend services (c…
feat: Tauri command layer wiring frontend to agent backend services (c…