Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
684 changes: 247 additions & 437 deletions bun.lock

Large diffs are not rendered by default.

471 changes: 471 additions & 0 deletions plans/ux-recommendation-spec.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parking_lot = "0.12"
# is NOT used — it depends on acp 0.11, which would pull a second, incompatible
# copy of the protocol crate into the tree. See Spec Change Log in
# spec-adr-003-p0-rust-acp-core.md.
agent-client-protocol = "0.12"
agent-client-protocol = { version = "0.12", features = ["unstable_session_model"] }

# Regex and parsing
regex = "1"
Expand Down
19 changes: 16 additions & 3 deletions src-tauri/src/acp/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use agent_client_protocol::schema::{
use tauri::State;

use crate::acp::config::{AgentConfig, AgentId, SessionId};
use crate::acp::manager::{AcpManager, NewSessionOutcome};
use crate::acp::manager::{AcpManager, NewSessionOutcome, SessionStateOutcome};

/// Spawn an ACP agent subprocess and complete the `initialize` handshake.
#[tauri::command]
Expand Down Expand Up @@ -59,7 +59,7 @@ pub async fn acp_load_session(
agent_id: AgentId,
session_id: SessionId,
cwd: String,
) -> Result<(), String> {
) -> Result<SessionStateOutcome, String> {
manager.load_session(&agent_id, session_id, cwd).await
}

Expand All @@ -70,7 +70,7 @@ pub async fn acp_resume_session(
agent_id: AgentId,
session_id: SessionId,
cwd: String,
) -> Result<(), String> {
) -> Result<SessionStateOutcome, String> {
manager.resume_session(&agent_id, session_id, cwd).await
}

Expand Down Expand Up @@ -148,6 +148,19 @@ pub async fn acp_set_mode(
manager.set_mode(&agent_id, session_id, mode_id).await
}

/// Set the active session model (unstable ACP `session/set_model`).
#[tauri::command]
pub async fn acp_set_session_model(
manager: State<'_, Arc<AcpManager>>,
agent_id: AgentId,
session_id: SessionId,
model_id: String,
) -> Result<(), String> {
manager
.set_session_model(&agent_id, session_id, model_id)
.await
}

/// Run the ACP `authenticate` method for an agent. `methodId` must be one of
/// the ids surfaced in the `acp:auth_required` event.
#[tauri::command]
Expand Down
6 changes: 5 additions & 1 deletion src-tauri/src/acp/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use crate::acp::config::{AgentId, SessionId};
use agent_client_protocol::schema::{
AgentCapabilities, AvailableCommand, ContentBlock, PermissionOption, Plan, SessionConfigOption,
SessionMode, SessionModeId, StopReason, ToolCall, ToolCallUpdate,
SessionMode, SessionModeId, SessionModelState, StopReason, ToolCall, ToolCallUpdate,
};
use serde::Serialize;
use tauri::{AppHandle, Emitter};
Expand Down Expand Up @@ -102,6 +102,8 @@ pub struct SessionCreatedEvent {
#[serde(skip_serializing_if = "Option::is_none")]
pub modes: Option<agent_client_protocol::schema::SessionModeState>,
#[serde(skip_serializing_if = "Option::is_none")]
pub models: Option<SessionModelState>,
#[serde(skip_serializing_if = "Option::is_none")]
pub config_options: Option<Vec<SessionConfigOption>>,
}

Expand Down Expand Up @@ -253,12 +255,14 @@ mod tests {
agent_id: AgentId("agent-1".to_string()),
session_id: SessionId::new("sess-1"),
modes: None,
models: None,
config_options: None,
};
let value = serde_json::to_value(&event).unwrap();
assert_eq!(value["agentId"], "agent-1");
assert_eq!(value["sessionId"], "sess-1");
assert!(value.get("modes").is_none());
assert!(value.get("models").is_none());
assert!(value.get("configOptions").is_none());
}

Expand Down
119 changes: 94 additions & 25 deletions src-tauri/src/acp/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ use agent_client_protocol::schema::{
ContentBlock, InitializeRequest, ListSessionsResponse, LoadSessionRequest, McpServer,
NewSessionRequest, PromptRequest, ProtocolVersion, RequestPermissionOutcome,
RequestPermissionResponse, ResumeSessionRequest, SelectedPermissionOutcome, SessionConfigOption,
SetSessionConfigOptionRequest, SetSessionModeRequest, StopReason,
SessionModelState, SetSessionConfigOptionRequest, SetSessionModeRequest,
SetSessionModelRequest, StopReason,
};
use agent_client_protocol::{Agent, Client, ConnectionTo, LineDirection};
use parking_lot::Mutex;
Expand All @@ -60,17 +61,27 @@ const CANCEL_GRACE: Duration = Duration::from_secs(5);
/// can never hang on a wedged agent.
const JOIN_TIMEOUT: Duration = Duration::from_secs(5);

/// Outcome of creating a new session, returned to the command caller.
/// Modes, models, and config options returned when a session is created or reattached.
#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NewSessionOutcome {
pub session_id: SessionId,
pub struct SessionStateOutcome {
#[serde(skip_serializing_if = "Option::is_none")]
pub modes: Option<agent_client_protocol::schema::SessionModeState>,
#[serde(skip_serializing_if = "Option::is_none")]
pub models: Option<SessionModelState>,
#[serde(skip_serializing_if = "Option::is_none")]
pub config_options: Option<Vec<SessionConfigOption>>,
}

/// Outcome of creating a new session, returned to the command caller.
#[derive(Debug, Clone, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NewSessionOutcome {
pub session_id: SessionId,
#[serde(flatten)]
pub state: SessionStateOutcome,
}

/// Commands sent from Tauri command handlers to an agent's driver thread.
///
/// Every variant that expects a result carries a `oneshot::Sender`; the driver
Expand All @@ -85,12 +96,12 @@ enum AcpCommand {
LoadSession {
session_id: SessionId,
cwd: String,
reply: oneshot::Sender<Result<(), String>>,
reply: oneshot::Sender<Result<SessionStateOutcome, String>>,
},
ResumeSession {
session_id: SessionId,
cwd: String,
reply: oneshot::Sender<Result<(), String>>,
reply: oneshot::Sender<Result<SessionStateOutcome, String>>,
},
CloseSession {
session_id: SessionId,
Expand All @@ -113,6 +124,11 @@ enum AcpCommand {
mode_id: String,
reply: oneshot::Sender<Result<(), String>>,
},
SetSessionModel {
session_id: SessionId,
model_id: String,
reply: oneshot::Sender<Result<(), String>>,
},
SetConfigOption {
session_id: SessionId,
config_id: String,
Expand Down Expand Up @@ -347,7 +363,7 @@ impl AcpManager {
agent_id: &AgentId,
session_id: SessionId,
cwd: String,
) -> Result<(), String> {
) -> Result<SessionStateOutcome, String> {
let caps = self.capabilities(agent_id)?;
gate_load_session(&caps)?;
let tx = self.command_tx(agent_id)?;
Expand All @@ -365,7 +381,7 @@ impl AcpManager {
agent_id: &AgentId,
session_id: SessionId,
cwd: String,
) -> Result<(), String> {
) -> Result<SessionStateOutcome, String> {
let caps = self.capabilities(agent_id)?;
gate_resume_session(&caps)?;
let tx = self.command_tx(agent_id)?;
Expand Down Expand Up @@ -445,6 +461,22 @@ impl AcpManager {
.await
}

/// Set the session's active model (unstable ACP `session/set_model`).
pub async fn set_session_model(
&self,
agent_id: &AgentId,
session_id: SessionId,
model_id: String,
) -> Result<(), String> {
let tx = self.command_tx(agent_id)?;
send_command(&tx, |reply| AcpCommand::SetSessionModel {
session_id,
model_id,
reply,
})
.await
}

/// Set a session configuration option, returning the updated option set.
pub async fn set_config_option(
&self,
Expand Down Expand Up @@ -1180,23 +1212,25 @@ async fn run_command_loop(
req_state
.lock()
.set_session_root(session_id.0.clone(), PathBuf::from(&cwd));
let state = SessionStateOutcome {
modes: response.modes.clone(),
models: response.models.clone(),
config_options: response.config_options.clone(),
};
events::emit(
&req_app,
events::EVENT_SESSION_CREATED,
SessionCreatedEvent {
agent_id: req_agent_id,
session_id: session_id.clone(),
modes: response.modes.clone(),
config_options: response.config_options.clone(),
modes: state.modes.clone(),
models: state.models.clone(),
config_options: state.config_options.clone(),
},
);
send_reply(
&task_slot,
Ok(NewSessionOutcome {
session_id,
modes: response.modes,
config_options: response.config_options,
}),
Ok(NewSessionOutcome { session_id, state }),
);
}
Err(e) => send_reply(&task_slot, Err(e.to_string())),
Expand All @@ -1216,12 +1250,22 @@ async fn run_command_loop(
spawn_request(&cx, slot, async move {
let request = LoadSessionRequest::new(&session_id, cwd.clone());
let result = req_cx.send_request(request).block_task().await;
if result.is_ok() {
req_state
.lock()
.set_session_root(session_id.0.clone(), PathBuf::from(&cwd));
match result {
Ok(response) => {
req_state
.lock()
.set_session_root(session_id.0.clone(), PathBuf::from(&cwd));
send_reply(
&task_slot,
Ok(SessionStateOutcome {
modes: response.modes,
models: response.models,
config_options: response.config_options,
}),
);
}
Err(e) => send_reply(&task_slot, Err(e.to_string())),
}
send_reply(&task_slot, result.map(|_| ()).map_err(|e| e.to_string()));
});
}

Expand All @@ -1237,12 +1281,22 @@ async fn run_command_loop(
spawn_request(&cx, slot, async move {
let request = ResumeSessionRequest::new(&session_id, cwd.clone());
let result = req_cx.send_request(request).block_task().await;
if result.is_ok() {
req_state
.lock()
.set_session_root(session_id.0.clone(), PathBuf::from(&cwd));
match result {
Ok(response) => {
req_state
.lock()
.set_session_root(session_id.0.clone(), PathBuf::from(&cwd));
send_reply(
&task_slot,
Ok(SessionStateOutcome {
modes: response.modes,
models: response.models,
config_options: response.config_options,
}),
);
}
Err(e) => send_reply(&task_slot, Err(e.to_string())),
}
send_reply(&task_slot, result.map(|_| ()).map_err(|e| e.to_string()));
});
}

Expand Down Expand Up @@ -1422,6 +1476,21 @@ async fn run_command_loop(
});
}

AcpCommand::SetSessionModel {
session_id,
model_id,
reply,
} => {
let slot = reply_slot(reply);
let task_slot = slot.clone();
let req_cx = cx.clone();
spawn_request(&cx, slot, async move {
let request = SetSessionModelRequest::new(&session_id, model_id);
let result = req_cx.send_request(request).block_task().await;
send_reply(&task_slot, result.map(|_| ()).map_err(|e| e.to_string()));
});
}

AcpCommand::SetConfigOption {
session_id,
config_id,
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,7 @@ pub fn run() {
acp::commands::acp_cancel_prompt,
acp::commands::acp_set_config_option,
acp::commands::acp_set_mode,
acp::commands::acp_set_session_model,
acp::commands::acp_respond_permission,
acp::commands::acp_authenticate,
acp_binary_install::acp_install_registry_binary,
Expand Down
22 changes: 21 additions & 1 deletion src/renderer/components/chat/AgentChatPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCallback, useMemo } from 'react'
import { toast } from 'sonner'
import { useShallow } from 'zustand/shallow'
import type { AvailableCommand, PlanEntry, SessionId, ToolCall } from '@/lib/acp-api'
import { isThinkingVisible } from '@/lib/acp-thinking'
import { useAcpMessages, useAcpSession, useAcpStore } from '@/stores/acp-store'
import { AgentHeader } from './AgentHeader'
import { ChatInputBar } from './ChatInputBar'
Expand Down Expand Up @@ -41,6 +42,7 @@ export function AgentChatPanel({ sessionId }: AgentChatPanelProps): React.JSX.El
const cancelPrompt = useAcpStore((s) => s.cancelPrompt)
const setConfigOption = useAcpStore((s) => s.setConfigOption)
const setMode = useAcpStore((s) => s.setMode)
const setSessionModel = useAcpStore((s) => s.setSessionModel)

const handleSend = useCallback(
(text: string) => {
Expand Down Expand Up @@ -75,7 +77,24 @@ export function AgentChatPanel({ sessionId }: AgentChatPanelProps): React.JSX.El
[setMode, sessionId]
)

const timeline = useMemo(() => buildTimeline(messages, toolCalls), [messages, toolCalls])
const handleSetSessionModel = useCallback(
(modelId: string) => {
void setSessionModel(sessionId, modelId).catch((err) => {
toast.error(`Failed to set model: ${String(err)}`)
})
},
[setSessionModel, sessionId]
)

const showThoughts = useMemo(
() =>
isThinkingVisible(session?.modes ?? null, session?.models ?? null, session?.configOptions),
[session?.modes, session?.models, session?.configOptions]
)
const timeline = useMemo(
() => buildTimeline(messages, toolCalls, { showThoughts }),
[messages, toolCalls, showThoughts]
)
// Show the typing indicator while a turn is active but no agent text has
// streamed yet (a trailing agent message means text is already rendering).
const lastMessage = messages[messages.length - 1]
Expand Down Expand Up @@ -133,6 +152,7 @@ export function AgentChatPanel({ sessionId }: AgentChatPanelProps): React.JSX.El
modes={session.modes}
onSetConfig={handleSetConfig}
onSetMode={handleSetMode}
onSetSessionModel={handleSetSessionModel}
/>
{pendingPermission && !isClosed && <PermissionDialog permission={pendingPermission} />}
</div>
Expand Down
Loading
Loading