feat(agent): UI hot-swap de profil (A2) — commande Tauri + sélecteur + dialog
- Tauri : commande change_agent_profile + ChangeAgentProfileRequestDto/Dto (camelCase, relaunchedSession omis si None), câblage state.rs par composition. - Front : gateway changeAgentProfile (adapters Tauri+mock), sélecteur de profil par agent, dialog de confirmation FR (« Changer le moteur abandonne l'historique de conversation… »), refresh sur event agentProfileChanged. Tests : app-tauri dto 5/5 ; vitest 314/314 (mapping, payload, dialog gating, libellé FR, refresh). 0 régression. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -9,8 +9,9 @@ use tauri::State;
|
||||
|
||||
use crate::dto::DismissEmbedderSuggestionRequestDto;
|
||||
use application::{
|
||||
AppError, AssignSkillToAgentInput, CloseProjectInput, CreateAgentInput, CreateLayoutInput,
|
||||
CreateMemoryInput, CreateSkillInput, DeleteAgentInput, DeleteEmbedderProfileInput,
|
||||
AppError, AssignSkillToAgentInput, ChangeAgentProfileInput, CloseProjectInput, CreateAgentInput,
|
||||
CreateLayoutInput, CreateMemoryInput, CreateSkillInput, DeleteAgentInput,
|
||||
DeleteEmbedderProfileInput,
|
||||
DeleteLayoutInput, DeleteMemoryInput, DeleteSkillInput, DeleteTemplateInput,
|
||||
DetectAgentDriftInput, GetMemoryInput, GitBranchesInput, GitCheckoutInput, GitCommitInput,
|
||||
GitGraphInput, GitInitInput, GitLogInput, GitStagePathInput, GitStatusInput,
|
||||
@ -27,7 +28,8 @@ use crate::dto::{
|
||||
parse_agent_id, parse_close_terminal, parse_delete_profile, parse_layout_id, parse_memory_slug,
|
||||
parse_node_id, parse_profile_id, parse_project_id, parse_session_id, parse_skill_id,
|
||||
parse_template_id, AgentDriftListDto, AgentDto, AgentListDto, AssignSkillRequestDto,
|
||||
AttachLiveAgentRequestDto, ConfigureProfilesRequestDto, ConversationDetailsDto,
|
||||
AttachLiveAgentRequestDto, ChangeAgentProfileDto, ChangeAgentProfileRequestDto,
|
||||
ConfigureProfilesRequestDto, ConversationDetailsDto,
|
||||
CreateAgentFromTemplateRequestDto, CreateAgentRequestDto, CreateLayoutRequestDto,
|
||||
CreateLayoutResultDto, CreateMemoryRequestDto, CreateProjectRequestDto, CreateSkillRequestDto,
|
||||
CreateTemplateRequestDto, DeleteLayoutRequestDto, DeleteLayoutResultDto,
|
||||
@ -1037,6 +1039,42 @@ pub async fn launch_agent(
|
||||
Ok(TerminalSessionDto::from(output))
|
||||
}
|
||||
|
||||
/// `change_agent_profile` — hot-swap an agent's runtime profile (§15.1).
|
||||
///
|
||||
/// Mutates the profile in the manifest, clears the now-foreign conversation id on
|
||||
/// every persisted layout cell hosting the agent, and — if the agent is live —
|
||||
/// kills its PTY and relaunches the session in the same cell with the new engine.
|
||||
/// Announces [`DomainEvent::AgentProfileChanged`].
|
||||
///
|
||||
/// Returns the mutated [`AgentDto`] and the relaunched [`TerminalSessionDto`] when
|
||||
/// a live session was hot-swapped (absent otherwise).
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns an [`ErrorDto`] (`INVALID` for malformed ids, `NOT_FOUND` if the
|
||||
/// project, agent or target profile is unknown, `STORE`/`FILESYSTEM`/`PROCESS` on
|
||||
/// the respective port failures).
|
||||
#[tauri::command]
|
||||
pub async fn change_agent_profile(
|
||||
request: ChangeAgentProfileRequestDto,
|
||||
state: State<'_, AppState>,
|
||||
) -> Result<ChangeAgentProfileDto, ErrorDto> {
|
||||
let project = resolve_project(&request.project_id, &state).await?;
|
||||
let agent_id = parse_agent_id(&request.agent_id)?;
|
||||
let profile_id = parse_profile_id(&request.profile_id)?;
|
||||
state
|
||||
.change_agent_profile
|
||||
.execute(ChangeAgentProfileInput {
|
||||
project,
|
||||
agent_id,
|
||||
profile_id,
|
||||
rows: request.rows,
|
||||
cols: request.cols,
|
||||
})
|
||||
.await
|
||||
.map(ChangeAgentProfileDto::from)
|
||||
.map_err(ErrorDto::from)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Templates & sync (L7)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@ -1032,10 +1032,10 @@ pub fn parse_profile_id(raw: &str) -> Result<ProfileId, ErrorDto> {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
use application::{
|
||||
CreateAgentOutput, InspectConversationOutput, LaunchAgentOutput, ListAgentsOutput,
|
||||
ReadAgentContextOutput,
|
||||
ChangeAgentProfileOutput, CreateAgentOutput, InspectConversationOutput, LaunchAgentOutput,
|
||||
ListAgentsOutput, ReadAgentContextOutput,
|
||||
};
|
||||
use domain::Agent;
|
||||
use domain::{Agent, TerminalSession};
|
||||
|
||||
/// An agent crossing the wire. [`Agent`] already serialises camelCase
|
||||
/// (`id`, `name`, `contextPath`, `profileId`, `origin` tagged, `synchronized`),
|
||||
@ -1154,6 +1154,56 @@ impl From<LaunchAgentOutput> for TerminalSessionDto {
|
||||
}
|
||||
}
|
||||
|
||||
/// Request DTO for `change_agent_profile` (§15.1): hot-swap an agent's runtime
|
||||
/// profile, optionally relaunching its live session in place.
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ChangeAgentProfileRequestDto {
|
||||
/// Id of the owning project.
|
||||
pub project_id: String,
|
||||
/// Id of the agent whose runtime profile to change.
|
||||
pub agent_id: String,
|
||||
/// Id of the new runtime profile.
|
||||
pub profile_id: String,
|
||||
/// Terminal height in rows for a possible hot relaunch.
|
||||
pub rows: u16,
|
||||
/// Terminal width in columns for a possible hot relaunch.
|
||||
pub cols: u16,
|
||||
}
|
||||
|
||||
/// Response DTO for `change_agent_profile`: the mutated agent plus the freshly
|
||||
/// relaunched session when a live session was hot-swapped (absent otherwise).
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ChangeAgentProfileDto {
|
||||
/// The agent now carrying the new profile.
|
||||
pub agent: AgentDto,
|
||||
/// The relaunched session, present only when a live session was swapped.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub relaunched_session: Option<TerminalSessionDto>,
|
||||
}
|
||||
|
||||
impl From<ChangeAgentProfileOutput> for ChangeAgentProfileDto {
|
||||
fn from(out: ChangeAgentProfileOutput) -> Self {
|
||||
Self {
|
||||
agent: AgentDto(out.agent),
|
||||
relaunched_session: out.relaunched.map(TerminalSessionDto::from),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TerminalSession> for TerminalSessionDto {
|
||||
fn from(s: TerminalSession) -> Self {
|
||||
Self {
|
||||
session_id: s.id.to_string(),
|
||||
cwd: s.cwd.as_str().to_owned(),
|
||||
rows: s.pty_size.rows,
|
||||
cols: s.pty_size.cols,
|
||||
assigned_conversation_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Request DTO for `inspect_conversation` (T7).
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
||||
@ -126,6 +126,7 @@ pub fn run() {
|
||||
commands::update_agent_context,
|
||||
commands::delete_agent,
|
||||
commands::launch_agent,
|
||||
commands::change_agent_profile,
|
||||
commands::inspect_conversation,
|
||||
commands::create_template,
|
||||
commands::update_template,
|
||||
|
||||
@ -10,7 +10,8 @@ use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use application::{
|
||||
AssignSkillToAgent, CheckEmbedderSuggestion, CloseProject, CloseTab, CloseTerminal,
|
||||
AssignSkillToAgent, ChangeAgentProfile, CheckEmbedderSuggestion, CloseProject, CloseTab,
|
||||
CloseTerminal,
|
||||
ConfigureProfiles, CreateAgentFromScratch, CreateAgentFromTemplate, CreateLayout, CreateMemory,
|
||||
CreateProject, CreateSkill, CreateTemplate, DeleteAgent, DeleteEmbedderProfile, DeleteLayout,
|
||||
DeleteMemory, DeleteProfile, DeleteSkill, DeleteTemplate, DescribeEmbedderEngines,
|
||||
@ -128,6 +129,8 @@ pub struct AppState {
|
||||
pub delete_agent: Arc<DeleteAgent>,
|
||||
/// Launch an agent (spawn PTY, apply injection strategy).
|
||||
pub launch_agent: Arc<LaunchAgent>,
|
||||
/// Hot-swap an agent's runtime profile, relaunching its live session in place (§15.1).
|
||||
pub change_agent_profile: Arc<ChangeAgentProfile>,
|
||||
/// Best-effort inspection of a conversation (last topic + token indicator)
|
||||
/// for the resume popup (T7). Optional/extensible: backed by a `Vec` of
|
||||
/// [`domain::ports::SessionInspector`]s; an empty/missing match yields empty
|
||||
@ -514,6 +517,20 @@ impl AppState {
|
||||
Some(Arc::clone(&check_embedder_suggestion)),
|
||||
));
|
||||
|
||||
// Hot-swap an agent's runtime profile (§15.1). Reuses the shared context/
|
||||
// profile/project/fs stores, the live-session registry and PTY port, and
|
||||
// *composes* the launcher above for the in-place relaunch (no duplication).
|
||||
let change_agent_profile = Arc::new(ChangeAgentProfile::new(
|
||||
Arc::clone(&contexts_port),
|
||||
Arc::clone(&profile_store_port),
|
||||
Arc::clone(&store_port),
|
||||
Arc::clone(&fs_port),
|
||||
Arc::clone(&terminal_sessions),
|
||||
Arc::clone(&pty_port),
|
||||
Arc::clone(&launch_agent),
|
||||
Arc::clone(&events_port),
|
||||
));
|
||||
|
||||
// --- Conversation inspection (T7) ---
|
||||
// Best-effort, optional, extensible: a `Vec` of SessionInspectors routed
|
||||
// by profile. Adding an inspectable CLI = pushing one more adapter here.
|
||||
@ -699,6 +716,7 @@ impl AppState {
|
||||
update_agent_context,
|
||||
delete_agent,
|
||||
launch_agent,
|
||||
change_agent_profile,
|
||||
inspect_conversation,
|
||||
project_store,
|
||||
create_template,
|
||||
|
||||
155
crates/app-tauri/tests/dto_change_agent_profile.rs
Normal file
155
crates/app-tauri/tests/dto_change_agent_profile.rs
Normal file
@ -0,0 +1,155 @@
|
||||
//! A2 tests for the `change_agent_profile` DTO contract (§15.1):
|
||||
//! - Request DTO round-trips camelCase JSON `{ projectId, agentId, profileId, rows, cols }`.
|
||||
//! - `From<ChangeAgentProfileOutput> for ChangeAgentProfileDto` maps the agent and
|
||||
//! surfaces `relaunchedSession` only when a live session was swapped (omitted via
|
||||
//! `skip_serializing_if` when `None`).
|
||||
//! - `From<TerminalSession> for TerminalSessionDto` carries id/cwd/size.
|
||||
|
||||
use app_tauri_lib::dto::{ChangeAgentProfileDto, ChangeAgentProfileRequestDto};
|
||||
use application::ChangeAgentProfileOutput;
|
||||
use domain::ids::{AgentId, NodeId, ProfileId, SessionId};
|
||||
use domain::terminal::{PtySize, SessionKind, SessionStatus, TerminalSession};
|
||||
use domain::{Agent, AgentOrigin, ProjectPath};
|
||||
use serde_json::json;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Helper: build a minimal validated [`Agent`].
|
||||
fn make_agent(agent_uuid: u128, profile_uuid: u128) -> Agent {
|
||||
Agent::new(
|
||||
AgentId::from_uuid(Uuid::from_u128(agent_uuid)),
|
||||
"My Agent",
|
||||
"agents/my-agent.md",
|
||||
ProfileId::from_uuid(Uuid::from_u128(profile_uuid)),
|
||||
AgentOrigin::Scratch,
|
||||
false,
|
||||
)
|
||||
.expect("valid agent")
|
||||
}
|
||||
|
||||
/// Helper: build a running [`TerminalSession`] for an agent cell.
|
||||
fn make_session(session_uuid: u128, node_uuid: u128, agent_uuid: u128) -> TerminalSession {
|
||||
let session_id = SessionId::from_uuid(Uuid::from_u128(session_uuid));
|
||||
let node_id = NodeId::from_uuid(Uuid::from_u128(node_uuid));
|
||||
let agent_id = AgentId::from_uuid(Uuid::from_u128(agent_uuid));
|
||||
let cwd = ProjectPath::new("/tmp/project".to_owned()).expect("valid path");
|
||||
let size = PtySize::new(30, 100).unwrap();
|
||||
let mut session = TerminalSession::starting(
|
||||
session_id,
|
||||
node_id,
|
||||
cwd,
|
||||
SessionKind::Agent { agent_id },
|
||||
size,
|
||||
);
|
||||
session.status = SessionStatus::Running;
|
||||
session
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Request DTO deserialisation (camelCase round-trip)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn change_agent_profile_request_deserialises_camelcase() {
|
||||
let project_id = Uuid::from_u128(1).to_string();
|
||||
let agent_id = Uuid::from_u128(2).to_string();
|
||||
let profile_id = Uuid::from_u128(3).to_string();
|
||||
let raw = json!({
|
||||
"projectId": project_id,
|
||||
"agentId": agent_id,
|
||||
"profileId": profile_id,
|
||||
"rows": 24,
|
||||
"cols": 80
|
||||
});
|
||||
let dto: ChangeAgentProfileRequestDto = serde_json::from_value(raw).unwrap();
|
||||
assert_eq!(dto.project_id, project_id);
|
||||
assert_eq!(dto.agent_id, agent_id);
|
||||
assert_eq!(dto.profile_id, profile_id);
|
||||
assert_eq!(dto.rows, 24);
|
||||
assert_eq!(dto.cols, 80);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn change_agent_profile_request_rejects_snake_case_keys() {
|
||||
// The wire contract is camelCase; snake_case keys must NOT satisfy the struct.
|
||||
let raw = json!({
|
||||
"project_id": Uuid::from_u128(1).to_string(),
|
||||
"agent_id": Uuid::from_u128(2).to_string(),
|
||||
"profile_id": Uuid::from_u128(3).to_string(),
|
||||
"rows": 24,
|
||||
"cols": 80
|
||||
});
|
||||
let res: Result<ChangeAgentProfileRequestDto, _> = serde_json::from_value(raw);
|
||||
assert!(res.is_err(), "snake_case keys must not deserialise");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// From<ChangeAgentProfileOutput> for ChangeAgentProfileDto
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn output_maps_agent_and_omits_session_when_no_relaunch() {
|
||||
let agent = make_agent(5, 6);
|
||||
let out = ChangeAgentProfileOutput {
|
||||
agent: agent.clone(),
|
||||
relaunched: None,
|
||||
};
|
||||
let dto = ChangeAgentProfileDto::from(out);
|
||||
assert_eq!(dto.agent.0.id, agent.id);
|
||||
assert!(dto.relaunched_session.is_none());
|
||||
|
||||
let v = serde_json::to_value(&dto).unwrap();
|
||||
// The agent is embedded with its camelCase shape.
|
||||
assert_eq!(v["agent"]["id"], agent.id.to_string());
|
||||
assert_eq!(v["agent"]["profileId"], agent.profile_id.to_string());
|
||||
// No relaunch ⇒ field must be OMITTED from the wire (absent, not null).
|
||||
assert!(
|
||||
v.get("relaunchedSession").is_none(),
|
||||
"no relaunch ⇒ relaunchedSession omitted, got: {v}"
|
||||
);
|
||||
// No snake_case leak.
|
||||
assert!(v.get("relaunched_session").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_maps_relaunched_session_camelcase_when_present() {
|
||||
let agent = make_agent(7, 8);
|
||||
let session = make_session(11, 12, 7);
|
||||
let out = ChangeAgentProfileOutput {
|
||||
agent: agent.clone(),
|
||||
relaunched: Some(session.clone()),
|
||||
};
|
||||
let dto = ChangeAgentProfileDto::from(out);
|
||||
assert!(dto.relaunched_session.is_some());
|
||||
|
||||
let v = serde_json::to_value(&dto).unwrap();
|
||||
let rs = v
|
||||
.get("relaunchedSession")
|
||||
.expect("relaunch present ⇒ relaunchedSession serialised");
|
||||
assert_eq!(rs["sessionId"], session.id.to_string());
|
||||
assert_eq!(rs["cwd"], "/tmp/project");
|
||||
assert_eq!(rs["rows"], 30);
|
||||
assert_eq!(rs["cols"], 100);
|
||||
// No snake_case leak on the nested DTO.
|
||||
assert!(rs.get("session_id").is_none(), "no snake_case leak");
|
||||
assert!(v.get("relaunched_session").is_none());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// From<TerminalSession> for TerminalSessionDto
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn terminal_session_maps_to_dto() {
|
||||
let session = make_session(21, 22, 23);
|
||||
// Exercise the From<TerminalSession> impl directly through the output mapping.
|
||||
let out = ChangeAgentProfileOutput {
|
||||
agent: make_agent(23, 24),
|
||||
relaunched: Some(session.clone()),
|
||||
};
|
||||
let dto = ChangeAgentProfileDto::from(out);
|
||||
let rs = dto.relaunched_session.expect("session present");
|
||||
assert_eq!(rs.session_id, session.id.to_string());
|
||||
assert_eq!(rs.cwd, "/tmp/project");
|
||||
assert_eq!(rs.rows, 30);
|
||||
assert_eq!(rs.cols, 100);
|
||||
}
|
||||
Reference in New Issue
Block a user