feat(terminals): reprise de conversation par cellule + fix ordre d'écriture
Permet de recharger la conversation CLI précédente de chaque cellule à la
réouverture du projet, de façon universelle (indépendant du modèle/CLI).
- profil AgentRuntime: bloc déclaratif optionnel `session { assignFlag, resumeFlag }`
- LeafCell: `conversationId` (persistant, distinct du SessionId PTY) + `agentWasRunning`
- runtime: SessionPlan (None/Assign/Resume) + composition pure des args
- LaunchAgent: décide Assign vs Resume, génère l'UUID, remonte l'id assigné
(persistance par l'appelant via setCellConversation — découplage SRP)
- close: SnapshotRunningAgents fige `agentWasRunning` avant le kill-all
(statut clot/en cours universel, sans parsing CLI)
- SessionInspector: port optionnel best-effort + adapter ClaudeTranscriptInspector
- popup de reprise par cellule (statut + sujet/tokens si dispo), intercalée
avant le Resume auto, jamais sur le chemin reattach
fix(terminals): sérialise les écritures PTY (file FIFO par handle) — corrige
les caractères mélangés/accents dus au réordonnancement des invoke Tauri concurrents
fix(layout): l'opération `move` préservait mal les champs du leaf (perdait `agent`)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -223,6 +223,8 @@ fn layout_dto_serialises_camelcase_tagged_tree() {
|
||||
id: nid(1),
|
||||
session: None,
|
||||
agent: None,
|
||||
conversation_id: None,
|
||||
agent_was_running: false,
|
||||
});
|
||||
let dto = LayoutDto::from(LoadLayoutOutput {
|
||||
layout_id: domain::LayoutId::new_random(),
|
||||
@ -322,8 +324,10 @@ fn layout_dto_round_trips_a_split_tree_shape() {
|
||||
id: nid(1),
|
||||
session: None,
|
||||
agent: None,
|
||||
conversation_id: None,
|
||||
agent_was_running: false,
|
||||
})
|
||||
.split(nid(1), Direction::Column, LeafCell { id: nid(2), session: None, agent: None }, nid(9))
|
||||
.split(nid(1), Direction::Column, LeafCell { id: nid(2), session: None, agent: None, conversation_id: None, agent_was_running: false }, nid(9))
|
||||
.unwrap();
|
||||
let dto = LayoutDto::from(LoadLayoutOutput {
|
||||
layout_id: domain::LayoutId::new_random(),
|
||||
|
||||
@ -3,10 +3,14 @@
|
||||
//! and `From<LaunchAgentOutput>` for [`TerminalSessionDto`].
|
||||
|
||||
use app_tauri_lib::dto::{
|
||||
parse_agent_id, AgentDto, AgentListDto, CreateAgentRequestDto, LaunchAgentRequestDto,
|
||||
TerminalSessionDto, UpdateAgentContextRequestDto,
|
||||
parse_agent_id, AgentDto, AgentListDto, ConversationDetailsDto, CreateAgentRequestDto,
|
||||
InspectConversationRequestDto, LaunchAgentRequestDto, TerminalSessionDto,
|
||||
UpdateAgentContextRequestDto,
|
||||
};
|
||||
use application::{CreateAgentOutput, LaunchAgentOutput, ListAgentsOutput};
|
||||
use application::{
|
||||
CreateAgentOutput, InspectConversationOutput, LaunchAgentOutput, ListAgentsOutput,
|
||||
};
|
||||
use domain::ports::ConversationDetails;
|
||||
use domain::ids::{AgentId, NodeId, ProfileId, SessionId};
|
||||
use domain::terminal::{PtySize, SessionKind, SessionStatus, TerminalSession};
|
||||
use domain::{Agent, AgentOrigin, ProjectPath};
|
||||
@ -126,6 +130,72 @@ fn launch_agent_request_deserialises_camelcase() {
|
||||
assert_eq!(dto.cols, 80);
|
||||
assert_eq!(dto.project_id, project_id);
|
||||
assert_eq!(dto.agent_id, agent_id);
|
||||
// Omitting the resume id defaults to None (a fresh cell).
|
||||
assert_eq!(dto.conversation_id, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn launch_agent_request_carries_conversation_id_for_resume() {
|
||||
let raw = json!({
|
||||
"projectId": Uuid::from_u128(1).to_string(),
|
||||
"agentId": Uuid::from_u128(2).to_string(),
|
||||
"rows": 24,
|
||||
"cols": 80,
|
||||
"conversationId": "resume-me"
|
||||
});
|
||||
let dto: LaunchAgentRequestDto = serde_json::from_value(raw).unwrap();
|
||||
// The leaf's persisted id reaches the backend so the launch resumes (T4b).
|
||||
assert_eq!(dto.conversation_id.as_deref(), Some("resume-me"));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// InspectConversation DTOs (T7)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn inspect_conversation_request_deserialises_camelcase() {
|
||||
let raw = json!({
|
||||
"projectId": Uuid::from_u128(1).to_string(),
|
||||
"agentId": Uuid::from_u128(2).to_string(),
|
||||
"conversationId": "conv-7"
|
||||
});
|
||||
let dto: InspectConversationRequestDto = serde_json::from_value(raw).unwrap();
|
||||
assert_eq!(dto.project_id, Uuid::from_u128(1).to_string());
|
||||
assert_eq!(dto.agent_id, Uuid::from_u128(2).to_string());
|
||||
assert_eq!(dto.conversation_id, "conv-7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conversation_details_dto_serialises_camelcase_when_present() {
|
||||
let out = InspectConversationOutput {
|
||||
details: ConversationDetails {
|
||||
last_topic: Some("refactor parser".to_owned()),
|
||||
token_count: Some(1234),
|
||||
},
|
||||
};
|
||||
let dto = ConversationDetailsDto::from(out);
|
||||
let v = serde_json::to_value(&dto).unwrap();
|
||||
assert_eq!(v["lastTopic"], "refactor parser");
|
||||
assert_eq!(v["tokenCount"], 1234);
|
||||
// No snake_case leak.
|
||||
assert!(v.get("last_topic").is_none());
|
||||
assert!(v.get("token_count").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conversation_details_dto_omits_fields_when_none() {
|
||||
let out = InspectConversationOutput {
|
||||
details: ConversationDetails {
|
||||
last_topic: None,
|
||||
token_count: None,
|
||||
},
|
||||
};
|
||||
let dto = ConversationDetailsDto::from(out);
|
||||
let v = serde_json::to_value(&dto).unwrap();
|
||||
// Both optional fields are omitted from the wire (absent, not null).
|
||||
assert!(v.get("lastTopic").is_none(), "absent topic ⇒ field omitted");
|
||||
assert!(v.get("tokenCount").is_none(), "absent tokens ⇒ field omitted");
|
||||
assert_eq!(v, json!({}), "fully degraded ⇒ empty object");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@ -168,7 +238,10 @@ fn launch_agent_output_maps_to_terminal_session_dto() {
|
||||
);
|
||||
session.status = SessionStatus::Running;
|
||||
|
||||
let out = LaunchAgentOutput { session };
|
||||
let out = LaunchAgentOutput {
|
||||
session,
|
||||
assigned_conversation_id: None,
|
||||
};
|
||||
let dto = TerminalSessionDto::from(out);
|
||||
|
||||
assert_eq!(dto.session_id, session_id.to_string());
|
||||
@ -176,9 +249,51 @@ fn launch_agent_output_maps_to_terminal_session_dto() {
|
||||
assert_eq!(dto.rows, 24);
|
||||
assert_eq!(dto.cols, 80);
|
||||
|
||||
// Nothing assigned ⇒ no conversation id surfaced.
|
||||
assert_eq!(dto.assigned_conversation_id, None);
|
||||
|
||||
// Also verify camelCase serialisation.
|
||||
let v = serde_json::to_value(&dto).unwrap();
|
||||
assert_eq!(v["sessionId"], session_id.to_string());
|
||||
assert_eq!(v["cwd"], "/tmp/project");
|
||||
assert!(v.get("session_id").is_none(), "no snake_case leak");
|
||||
// Absent assignment must be omitted from the wire payload entirely.
|
||||
assert!(
|
||||
v.get("assignedConversationId").is_none(),
|
||||
"no assignment ⇒ field omitted"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn launch_agent_output_propagates_assigned_conversation_id() {
|
||||
let session_id = SessionId::from_uuid(Uuid::from_u128(70));
|
||||
let node_id = NodeId::from_uuid(Uuid::from_u128(80));
|
||||
let agent_id = AgentId::from_uuid(Uuid::from_u128(90));
|
||||
let cwd = ProjectPath::new("/tmp/project".to_owned()).expect("valid path");
|
||||
let size = PtySize::new(24, 80).unwrap();
|
||||
|
||||
let mut session = TerminalSession::starting(
|
||||
session_id,
|
||||
node_id,
|
||||
cwd,
|
||||
SessionKind::Agent { agent_id },
|
||||
size,
|
||||
);
|
||||
session.status = SessionStatus::Running;
|
||||
|
||||
let out = LaunchAgentOutput {
|
||||
session,
|
||||
assigned_conversation_id: Some("conv-xyz".to_owned()),
|
||||
};
|
||||
let dto = TerminalSessionDto::from(out);
|
||||
|
||||
// The id minted by the launch is carried through to the DTO …
|
||||
assert_eq!(dto.assigned_conversation_id.as_deref(), Some("conv-xyz"));
|
||||
// … and serialised in camelCase for the front to persist on the leaf.
|
||||
let v = serde_json::to_value(&dto).unwrap();
|
||||
assert_eq!(v["assignedConversationId"], "conv-xyz");
|
||||
assert!(
|
||||
v.get("assigned_conversation_id").is_none(),
|
||||
"no snake_case leak"
|
||||
);
|
||||
}
|
||||
|
||||
@ -245,3 +245,66 @@ fn set_cell_agent_op_deserialises_with_absent_agent_defaults_to_none() {
|
||||
_ => panic!("expected SetCellAgent with None agent"),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// setCellConversation operation deserialisation (T4b)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn set_cell_conversation_op_deserialises_with_id() {
|
||||
let target = nid(1);
|
||||
let raw = json!({
|
||||
"type": "setCellConversation",
|
||||
"target": target.to_string(),
|
||||
"conversationId": "conv-42"
|
||||
});
|
||||
let dto: LayoutOperationDto = serde_json::from_value(raw).unwrap();
|
||||
let op = dto.into_operation().unwrap();
|
||||
match op {
|
||||
application::LayoutOperation::SetCellConversation {
|
||||
target: t,
|
||||
conversation_id: Some(id),
|
||||
} => {
|
||||
assert_eq!(t, target);
|
||||
assert_eq!(id, "conv-42");
|
||||
}
|
||||
_ => panic!("expected SetCellConversation with id"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_cell_conversation_op_deserialises_with_null_id() {
|
||||
let target = nid(2);
|
||||
let raw = json!({
|
||||
"type": "setCellConversation",
|
||||
"target": target.to_string(),
|
||||
"conversationId": null
|
||||
});
|
||||
let dto: LayoutOperationDto = serde_json::from_value(raw).unwrap();
|
||||
let op = dto.into_operation().unwrap();
|
||||
match op {
|
||||
application::LayoutOperation::SetCellConversation {
|
||||
target: t,
|
||||
conversation_id: None,
|
||||
} => assert_eq!(t, target),
|
||||
_ => panic!("expected SetCellConversation with None id"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_cell_conversation_op_deserialises_with_absent_id_defaults_to_none() {
|
||||
let target = nid(3);
|
||||
let raw = json!({
|
||||
"type": "setCellConversation",
|
||||
"target": target.to_string()
|
||||
});
|
||||
let dto: LayoutOperationDto = serde_json::from_value(raw).unwrap();
|
||||
let op = dto.into_operation().unwrap();
|
||||
match op {
|
||||
application::LayoutOperation::SetCellConversation {
|
||||
conversation_id: None,
|
||||
..
|
||||
} => {}
|
||||
_ => panic!("expected SetCellConversation with None id"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ fn profile(id: u128, name: &str, command: &str) -> AgentProfile {
|
||||
ContextInjection::convention_file("CLAUDE.md").unwrap(),
|
||||
Some(format!("{command} --version")),
|
||||
"{projectRoot}",
|
||||
None,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user