feat(backend,frontend): lot utilisateur #310 #311 #312 #313 — horodatage conversation, stop agent robuste, préférence terminal par défaut, paramètres projet (QA verte)
- #310: horodatage de tous les messages et événements de conversation visibles — composant partagé EntryTimestamp, timestamps propagés dans le transcript chat, les annonces inter-agent et le viewer de conversation, normalisation côté domain/adapters (conversation_log, paginate). - #311: stop d'agent robuste pour PTY non monté, sessions headless et CLI custom — lifecycle/orchestrator durcis, ponts chat app-tauri/web-server alignés, arrêt fiable sans session orpheline. - #312: préférence globale d'interface terminal par défaut — nouveau store settings (domain/application/infrastructure + tests), DTO et commandes backend, adapter frontend userSettings, panneau TerminalSettings dans les paramètres globaux. - #313: Paramètres du projet — contexte de projet éditable et couleur de thème par projet (ProjectSettingsPanel + projectTheme), teinte des onglets projet, persistance via DTO projet. QA verte (GO QA sur feature/batch-310-311-312-313-chat-stop-prefs-theme) — vérifications Git: git diff --cached --check OK; staging borné à crates/ et frontend/ (74 fichiers, +2105/-531), commit unique de lot conforme à la convention des lots (précédents batch-151/158/159, batch-210/211/212) car les fichiers partagés (dto.rs, commands.rs, CustomAgentChatView) entrelacent les 4 tickets. fichiers .ideai/* (agents/test.md, chat-drafts.json, system-permissions.json, tickets/counter.json, tickets/index.json, tickets/308-313/), attachments/ et scripts/ hors périmètre et préservés en worktree ; aucun push. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -1501,6 +1501,7 @@ fn launch_input_with_project(agent_id: AgentId, project: Project) -> LaunchAgent
|
||||
mcp_runtime: None,
|
||||
allow_structured_alongside_pty: false,
|
||||
require_structured: false,
|
||||
terminal_interface: None,
|
||||
fresh_start: false,
|
||||
managed_temp_exposure: ManagedTempExposureRequest::default(),
|
||||
}
|
||||
|
||||
@ -4585,8 +4585,8 @@ async fn p6b_user_ask_records_prompt_then_response_pair() {
|
||||
"response is sourced from the target (architect)"
|
||||
);
|
||||
// Clock stamp came from the injected Clock.
|
||||
assert_eq!(prompt.at_ms, 123);
|
||||
assert_eq!(response.at_ms, 123);
|
||||
assert_eq!(prompt.at_ms, Some(123));
|
||||
assert_eq!(response.at_ms, Some(123));
|
||||
}
|
||||
|
||||
/// Round-trip with an **agent** requester (A) resolves the `A↔B` conversation and the
|
||||
|
||||
@ -40,13 +40,16 @@ use domain::ports::{
|
||||
ContextInjectionPlan, DirEntry, EventBus, EventStream, ExitStatus, FileSystem, FsError,
|
||||
IdGenerator, MemoryError, MemoryQuery, MemoryRecall, OutputStream, PreparedContext,
|
||||
ProfileStore, ProjectStore, PtyError, PtyHandle, PtyPort, RemotePath, ReplyEvent, ReplyStream,
|
||||
RuntimeError, SessionPlan, SkillStore, SpawnSpec, StoreError,
|
||||
RuntimeError, SessionPlan, SkillStore, SpawnSpec, StoreError, UserSettingsStore,
|
||||
};
|
||||
use domain::profile::{AgentProfile, ContextInjection, StructuredAdapter};
|
||||
use domain::project::{Project, ProjectPath};
|
||||
use domain::remote::RemoteRef;
|
||||
use domain::skill::{Skill, SkillScope};
|
||||
use domain::{MemoryIndexEntry, NodeId, PtySize, SessionId, SessionKind, SkillId};
|
||||
use domain::{
|
||||
DefaultAgentTerminalInterface, IdeaUserSettings, MemoryIndexEntry, NodeId, PtySize, SessionId,
|
||||
SessionKind, SkillId,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
use application::{
|
||||
@ -772,6 +775,7 @@ fn launch_input(agent_id: AgentId) -> LaunchAgentInput {
|
||||
mcp_runtime: None,
|
||||
allow_structured_alongside_pty: false,
|
||||
require_structured: false,
|
||||
terminal_interface: None,
|
||||
fresh_start: false,
|
||||
managed_temp_exposure: ManagedTempExposureRequest::default(),
|
||||
}
|
||||
@ -858,10 +862,103 @@ fn launch_fixture_with_mode(
|
||||
}
|
||||
}
|
||||
|
||||
struct FixedUserSettings(IdeaUserSettings);
|
||||
|
||||
#[async_trait]
|
||||
impl UserSettingsStore for FixedUserSettings {
|
||||
async fn load(&self) -> Result<IdeaUserSettings, StoreError> {
|
||||
Ok(self.0.clone())
|
||||
}
|
||||
async fn save(&self, _settings: &IdeaUserSettings) -> Result<(), StoreError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct MutableUserSettings(Arc<Mutex<IdeaUserSettings>>);
|
||||
|
||||
#[async_trait]
|
||||
impl UserSettingsStore for MutableUserSettings {
|
||||
async fn load(&self) -> Result<IdeaUserSettings, StoreError> {
|
||||
Ok(self.0.lock().unwrap().clone())
|
||||
}
|
||||
async fn save(&self, settings: &IdeaUserSettings) -> Result<(), StoreError> {
|
||||
*self.0.lock().unwrap() = settings.clone();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn launch_fixture_with_preference(interface: DefaultAgentTerminalInterface) -> LaunchFixture {
|
||||
let mut fixture = launch_fixture_with_mode(
|
||||
structured_profile(pid(9)),
|
||||
FakeFactory::new(500, Some("engine-conv")),
|
||||
StructuredRoutingMode::HumanPtyFallback,
|
||||
);
|
||||
let launch = Arc::try_unwrap(fixture.launch)
|
||||
.ok()
|
||||
.expect("fixture owns its launcher")
|
||||
.with_user_settings(Arc::new(FixedUserSettings(IdeaUserSettings {
|
||||
default_agent_terminal_interface: Some(interface),
|
||||
})));
|
||||
fixture.launch = Arc::new(launch);
|
||||
fixture
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// 1. Routage LaunchAgent : chemin structuré
|
||||
// ===========================================================================
|
||||
|
||||
#[tokio::test]
|
||||
async fn global_idea_cli_preference_applies_to_a_new_human_launch() {
|
||||
let f = launch_fixture_with_preference(DefaultAgentTerminalInterface::IdeaCli);
|
||||
let out = f.launch.execute(launch_input(f.agent.id)).await.unwrap();
|
||||
assert!(out.structured.is_some());
|
||||
assert_eq!(f.factory.start_count(), 1);
|
||||
assert_eq!(f.pty.spawn_count(), 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn explicit_native_tui_overrides_the_global_idea_cli_preference() {
|
||||
let f = launch_fixture_with_preference(DefaultAgentTerminalInterface::IdeaCli);
|
||||
let mut input = launch_input(f.agent.id);
|
||||
input.terminal_interface = Some(DefaultAgentTerminalInterface::NativeTui);
|
||||
let out = f.launch.execute(input).await.unwrap();
|
||||
assert!(out.structured.is_none());
|
||||
assert_eq!(f.factory.start_count(), 0);
|
||||
assert_eq!(f.pty.spawn_count(), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn changing_global_preference_does_not_replace_an_existing_terminal() {
|
||||
let mut fixture = launch_fixture_with_mode(
|
||||
structured_profile(pid(9)),
|
||||
FakeFactory::new(500, Some("engine-conv")),
|
||||
StructuredRoutingMode::HumanPtyFallback,
|
||||
);
|
||||
let settings = MutableUserSettings(Arc::new(Mutex::new(IdeaUserSettings::default())));
|
||||
let launch = Arc::try_unwrap(fixture.launch)
|
||||
.ok()
|
||||
.unwrap()
|
||||
.with_user_settings(Arc::new(settings.clone()));
|
||||
fixture.launch = Arc::new(launch);
|
||||
|
||||
let mut input = launch_input(fixture.agent.id);
|
||||
input.node_id = Some(nid(3));
|
||||
let first = fixture.launch.execute(input.clone()).await.unwrap();
|
||||
assert!(first.structured.is_none());
|
||||
settings
|
||||
.save(&IdeaUserSettings {
|
||||
default_agent_terminal_interface: Some(DefaultAgentTerminalInterface::IdeaCli),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let second = fixture.launch.execute(input).await.unwrap();
|
||||
assert_eq!(second.session.id, first.session.id);
|
||||
assert_eq!(fixture.pty.spawn_count(), 1);
|
||||
assert_eq!(fixture.factory.start_count(), 0);
|
||||
}
|
||||
|
||||
/// Profil structuré + factory câblée ⇒ `factory.start` appelé une fois, session
|
||||
/// enregistrée dans `StructuredSessions`, AUCUN `pty.spawn`, `AgentLaunched` publié,
|
||||
/// `output.structured = Some(descriptor)` avec les bons champs.
|
||||
|
||||
@ -330,15 +330,17 @@ async fn stop_pty_kills_and_removes_session() {
|
||||
.execute(StopLiveAgentInput {
|
||||
project: project(),
|
||||
agent_id: a,
|
||||
reason: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(out.agent_id, a);
|
||||
assert_eq!(out.session_id, sid(1));
|
||||
assert_eq!(out.node_id, nid(100));
|
||||
assert_eq!(out.kind, LiveSessionKind::Pty);
|
||||
assert_eq!(out.runtime_state, LiveRuntimeState::Stopped);
|
||||
assert!(!out.already_stopped);
|
||||
assert_eq!(out.stopped[0].session_id, sid(1));
|
||||
assert_eq!(out.stopped[0].node_id, nid(100));
|
||||
assert_eq!(out.stopped[0].kind, LiveSessionKind::Pty);
|
||||
assert_eq!(out.stopped[0].state, LiveRuntimeState::Stopped);
|
||||
// Delegated to the close primitive: process killed and registry emptied.
|
||||
assert_eq!(f.pty_port.kills(), vec![sid(1)]);
|
||||
assert!(f.pty.is_empty(), "live session removed from the registry");
|
||||
@ -346,7 +348,7 @@ async fn stop_pty_kills_and_removes_session() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stop_structured_cancels_turn_and_keeps_session() {
|
||||
async fn stop_structured_shuts_down_and_removes_session() {
|
||||
let f = fixture();
|
||||
let a = aid(10);
|
||||
let (shutdown_called, cancel_called) = insert_structured(&f.structured, sid(2), a, nid(100));
|
||||
@ -356,26 +358,24 @@ async fn stop_structured_cancels_turn_and_keeps_session() {
|
||||
.execute(StopLiveAgentInput {
|
||||
project: project(),
|
||||
agent_id: a,
|
||||
reason: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(out.session_id, sid(2));
|
||||
assert_eq!(out.kind, LiveSessionKind::Structured);
|
||||
assert_eq!(out.runtime_state, LiveRuntimeState::Stopped);
|
||||
assert_eq!(out.stopped[0].session_id, sid(2));
|
||||
assert_eq!(out.stopped[0].kind, LiveSessionKind::Structured);
|
||||
assert_eq!(out.stopped[0].state, LiveRuntimeState::Stopped);
|
||||
assert!(!cancel_called.load(Ordering::SeqCst));
|
||||
assert!(
|
||||
cancel_called.load(Ordering::SeqCst),
|
||||
"session.cancel_current_turn() was called"
|
||||
shutdown_called.load(Ordering::SeqCst),
|
||||
"session.shutdown() must be called"
|
||||
);
|
||||
assert!(
|
||||
!shutdown_called.load(Ordering::SeqCst),
|
||||
"session.shutdown() must not be called"
|
||||
);
|
||||
assert!(!f.structured.is_empty(), "live session is preserved");
|
||||
assert!(f.structured.is_empty(), "live session is removed");
|
||||
assert_eq!(
|
||||
f.structured
|
||||
.session_id_for_agent_in_project(project().id, &a),
|
||||
Some(sid(2))
|
||||
None
|
||||
);
|
||||
// No PTY was touched.
|
||||
assert!(f.pty_port.kills().is_empty());
|
||||
@ -395,21 +395,46 @@ async fn stop_structured_runs_execution_cascade_best_effort() {
|
||||
.execute(StopLiveAgentInput {
|
||||
project: project(),
|
||||
agent_id: a,
|
||||
reason: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(out.session_id, sid(2));
|
||||
assert_eq!(out.stopped[0].session_id, sid(2));
|
||||
assert_eq!(*cascade.calls.lock().unwrap(), vec![(project().id, a)]);
|
||||
assert!(
|
||||
cancel_called.load(Ordering::SeqCst),
|
||||
"session.cancel_current_turn() was called"
|
||||
!cancel_called.load(Ordering::SeqCst),
|
||||
"session.cancel_current_turn() is not the runtime stop primitive"
|
||||
);
|
||||
assert!(
|
||||
!shutdown_called.load(Ordering::SeqCst),
|
||||
"session.shutdown() must not be called"
|
||||
shutdown_called.load(Ordering::SeqCst),
|
||||
"session.shutdown() must be called"
|
||||
);
|
||||
assert!(!f.structured.is_empty(), "live session is preserved");
|
||||
assert!(f.structured.is_empty(), "live session is removed");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stop_removes_every_runtime_for_the_agent_across_registries() {
|
||||
let f = fixture();
|
||||
let agent = aid(10);
|
||||
insert_pty(&f.pty, sid(1), agent, nid(100));
|
||||
let (shutdown_called, _) = insert_structured(&f.structured, sid(2), agent, nid(200));
|
||||
|
||||
let out = f
|
||||
.stop
|
||||
.execute(StopLiveAgentInput {
|
||||
project: project(),
|
||||
agent_id: agent,
|
||||
reason: Some("user requested".to_owned()),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(out.stopped.len(), 2);
|
||||
assert!(f.pty.is_empty());
|
||||
assert!(f.structured.is_empty());
|
||||
assert_eq!(f.pty_port.kills(), vec![sid(1)]);
|
||||
assert!(shutdown_called.load(Ordering::SeqCst));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@ -423,6 +448,7 @@ async fn stop_pty_is_idempotent_after_success() {
|
||||
.execute(StopLiveAgentInput {
|
||||
project: project(),
|
||||
agent_id: a,
|
||||
reason: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@ -431,31 +457,31 @@ async fn stop_pty_is_idempotent_after_success() {
|
||||
.execute(StopLiveAgentInput {
|
||||
project: project(),
|
||||
agent_id: a,
|
||||
reason: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(first, second);
|
||||
assert_eq!(second.runtime_state, LiveRuntimeState::Stopped);
|
||||
assert!(!first.already_stopped);
|
||||
assert!(second.already_stopped);
|
||||
assert!(second.stopped.is_empty());
|
||||
assert_eq!(f.pty_port.kills(), vec![sid(1)], "kill is not repeated");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn stop_unknown_agent_is_not_found() {
|
||||
async fn stop_unknown_agent_is_idempotent_success() {
|
||||
let f = fixture();
|
||||
|
||||
let err = f
|
||||
let out = f
|
||||
.stop
|
||||
.execute(StopLiveAgentInput {
|
||||
project: project(),
|
||||
agent_id: aid(999),
|
||||
reason: None,
|
||||
})
|
||||
.await
|
||||
.expect_err("absent agent ⇒ NOT_FOUND");
|
||||
|
||||
assert!(
|
||||
matches!(err, application::AppError::NotFound(_)),
|
||||
"got {err:?}"
|
||||
);
|
||||
.expect("absent agent is an idempotent success");
|
||||
assert!(out.already_stopped);
|
||||
assert!(out.stopped.is_empty());
|
||||
assert!(f.pty_port.kills().is_empty(), "nothing killed");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user