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:
2026-09-10 21:26:16 +02:00
parent fc45594d9a
commit 402a60f213
74 changed files with 2105 additions and 531 deletions

View File

@ -344,6 +344,7 @@ fn progress_entity_key(progress: &ReplyProgressDto) -> Option<String> {
fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
match chunk {
ReplyChunk::UserPrompt {
at_ms: _,
text,
attachments,
attachment_refs,
@ -360,8 +361,8 @@ fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
})
.sum::<usize>()
}
ReplyChunk::TextDelta { text } => text.len(),
ReplyChunk::ToolActivity { label } => label.len(),
ReplyChunk::TextDelta { text, .. } => text.len(),
ReplyChunk::ToolActivity { label, .. } => label.len(),
ReplyChunk::Progress { progress } => {
progress.label.len()
+ progress.text.as_ref().map_or(0, String::len)
@ -369,8 +370,8 @@ fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
+ progress.native_event.as_ref().map_or(0, String::len)
+ progress.tool_name.as_ref().map_or(0, String::len)
}
ReplyChunk::Final { content } => content.len(),
ReplyChunk::Error { message } => message.len(),
ReplyChunk::Final { content, .. } => content.len(),
ReplyChunk::Error { message, .. } => message.len(),
}
}
@ -386,40 +387,57 @@ fn reply_chunk_bytes(chunk: &ReplyChunk) -> usize {
/// too. Every content-bearing event still maps to exactly one chunk.
#[must_use]
pub fn chunk_from_event(event: ReplyEvent) -> Option<ReplyChunk> {
chunk_from_event_at(event, None)
}
/// Maps a domain reply event while preserving the backend acceptance time.
#[must_use]
pub fn chunk_from_event_at(event: ReplyEvent, at_ms: Option<u64>) -> Option<ReplyChunk> {
match event {
ReplyEvent::Progress { progress } => Some(ReplyChunk::Progress {
progress: progress.into(),
}),
ReplyEvent::TextDelta { text } => Some(ReplyChunk::TextDelta { text }),
ReplyEvent::Progress { progress } => {
let mut progress: ReplyProgressDto = progress.into();
progress.occurred_at_ms = at_ms;
Some(ReplyChunk::Progress { progress })
}
ReplyEvent::TextDelta { text } => Some(ReplyChunk::TextDelta { text, at_ms }),
ReplyEvent::ToolActivity { label } => Some(ReplyChunk::Progress {
progress: ReplyProgress::new(
ReplyProgressSource::ProviderNative,
ReplyProgressKind::Tool,
ReplyProgressStage::Info,
label.clone(),
)
.with_tool_name(label)
.into(),
progress: {
let mut progress: ReplyProgressDto = ReplyProgress::new(
ReplyProgressSource::ProviderNative,
ReplyProgressKind::Tool,
ReplyProgressStage::Info,
label.clone(),
)
.with_tool_name(label)
.into();
progress.occurred_at_ms = at_ms;
progress
},
}),
ReplyEvent::Error { message } => Some(ReplyChunk::Error { message }),
ReplyEvent::Error { message } => Some(ReplyChunk::Error { message, at_ms }),
ReplyEvent::Final { content } => {
if content.trim().is_empty() {
Some(ReplyChunk::Error {
message: "Réponse vide du modèle.".to_owned(),
at_ms,
})
} else {
Some(ReplyChunk::Final { content })
Some(ReplyChunk::Final { content, at_ms })
}
}
ReplyEvent::Announcement { text } => Some(ReplyChunk::Progress {
progress: ReplyProgress::new(
ReplyProgressSource::ProviderNative,
ReplyProgressKind::Message,
ReplyProgressStage::Delta,
"message intermédiaire",
)
.with_text(text)
.into(),
progress: {
let mut progress: ReplyProgressDto = ReplyProgress::new(
ReplyProgressSource::ProviderNative,
ReplyProgressKind::Message,
ReplyProgressStage::Delta,
"message intermédiaire",
)
.with_text(text)
.into();
progress.occurred_at_ms = at_ms;
progress
},
}),
ReplyEvent::Heartbeat => None,
ReplyEvent::RateLimited { .. } => None,
@ -432,5 +450,20 @@ pub fn chunk_from_event(event: ReplyEvent) -> Option<ReplyChunk> {
pub fn unfinished_turn_chunk() -> ReplyChunk {
ReplyChunk::Error {
message: MODEL_RESPONSE_NOT_FINALIZED_MESSAGE.to_owned(),
at_ms: None,
}
}
/// Assigns an acceptance timestamp to a transport-created chunk.
#[must_use]
pub fn with_chunk_timestamp(mut chunk: ReplyChunk, at_ms: Option<u64>) -> ReplyChunk {
match &mut chunk {
ReplyChunk::UserPrompt { at_ms: value, .. }
| ReplyChunk::TextDelta { at_ms: value, .. }
| ReplyChunk::ToolActivity { at_ms: value, .. }
| ReplyChunk::Final { at_ms: value, .. }
| ReplyChunk::Error { at_ms: value, .. } => *value = at_ms,
ReplyChunk::Progress { progress } => progress.occurred_at_ms = at_ms,
}
chunk
}

View File

@ -66,7 +66,7 @@ use crate::dto::{
MemoryIndexDto, MemoryLinksDto, MemoryListDto, ModelServerConfigDto, ModelServerConfigListDto,
OpenCodeProviderListDto, OpenProjectRestoreStateDto, OpenTerminalRequestDto,
PreviewModelServerCommandDto, ProfileDto, ProfileListDto, ProfileModelCatalogDto, ProjectDto,
ProjectListDto, ProjectMcpToolPermissionsDto, ProjectPermissionsDto,
ProjectListDto, ProjectMcpToolPermissionsDto, ProjectPermissionsDto, ProjectSettingsDto,
ProjectSystemPermissionsDto, ProjectWorkStateDto, ReadAgentContextResponseDto,
ReadChatDraftResponseDto, ReadConversationPageRequestDto, ReattachChatDto, ReattachResultDto,
RecallMemoryRequestDto, RemoveOpenProjectRestoreEntryRequestDto, RemoveProjectRequestDto,
@ -86,8 +86,8 @@ use crate::dto::{
UpdateAgentSystemPermissionsRequestDto, UpdateMemoryRequestDto, UpdateProjectContextRequestDto,
UpdateProjectMcpToolPermissionsRequestDto, UpdateProjectOrchestratorRequestDto,
UpdateProjectOrchestratorResponseDto, UpdateProjectPermissionsRequestDto,
UpdateProjectSystemPermissionsRequestDto, UpdateSkillRequestDto, UpdateTemplateRequestDto,
WriteTerminalRequestDto,
UpdateProjectSettingsRequestDto, UpdateProjectSystemPermissionsRequestDto,
UpdateSkillRequestDto, UpdateTemplateRequestDto, UserSettingsDto, WriteTerminalRequestDto,
};
use crate::embedded_server::{
EmbeddedServerStatusDto, ServerExposurePreviewDto, ServerExposureSettingsDto,
@ -815,6 +815,66 @@ pub async fn update_project_context(
.map_err(ErrorDto::from)
}
/// Reads global machine-local IdeA preferences.
#[tauri::command]
pub async fn read_user_settings(state: State<'_, AppState>) -> Result<UserSettingsDto, ErrorDto> {
state
.read_user_settings
.execute()
.await
.map(Into::into)
.map_err(Into::into)
}
/// Replaces global machine-local IdeA preferences.
#[tauri::command]
pub async fn update_user_settings(
request: UserSettingsDto,
state: State<'_, AppState>,
) -> Result<UserSettingsDto, ErrorDto> {
state
.update_user_settings
.execute(request.into())
.await
.map(Into::into)
.map_err(Into::into)
}
/// Reads project-owned settings without creating a legacy-missing file.
#[tauri::command]
pub async fn read_project_settings(
project_id: String,
state: State<'_, AppState>,
) -> Result<ProjectSettingsDto, ErrorDto> {
let project = resolve_project(&project_id, &state).await?;
state
.read_project_settings
.execute(&project)
.await
.map(Into::into)
.map_err(Into::into)
}
/// Validates and replaces project-owned settings.
#[tauri::command]
pub async fn update_project_settings(
request: UpdateProjectSettingsRequestDto,
state: State<'_, AppState>,
) -> Result<ProjectSettingsDto, ErrorDto> {
let project = resolve_project(&request.project_id, &state).await?;
let theme_color = request
.theme_color
.map(domain::ThemeColor::new)
.transpose()
.map_err(|message| ErrorDto::from(AppError::Invalid(message)))?;
state
.update_project_settings
.execute(&project, domain::ProjectSettings { theme_color })
.await
.map(Into::into)
.map_err(Into::into)
}
/// `get_project_permissions` — read `.ideai/permissions.json`.
///
/// # Errors
@ -2198,7 +2258,11 @@ pub async fn stop_live_agent(
}
state
.stop_live_agent
.execute(StopLiveAgentInput { project, agent_id })
.execute(StopLiveAgentInput {
project,
agent_id,
reason: request.reason,
})
.await
.map(StopLiveAgentResponseDto::from)
.map_err(ErrorDto::from)
@ -2372,6 +2436,10 @@ pub async fn launch_agent(
mcp_runtime,
allow_structured_alongside_pty: false,
require_structured: request.cell_kind == Some(CellKind::Chat),
terminal_interface: request.cell_kind.map(|kind| match kind {
CellKind::Pty => domain::DefaultAgentTerminalInterface::NativeTui,
CellKind::Chat => domain::DefaultAgentTerminalInterface::IdeaCli,
}),
fresh_start: request.fresh_start,
managed_temp_exposure: application::ManagedTempExposureRequest::default(),
})
@ -2781,6 +2849,7 @@ pub async fn agent_send(
let _ = state.chat_bridge.send_output(
&sid,
ReplyChunk::UserPrompt {
at_ms: u64::try_from(state.clock.now_millis()).ok(),
text: prompt.clone(),
attachments: attachment_labels,
attachment_refs,
@ -2793,6 +2862,7 @@ pub async fn agent_send(
// still running.
let (tap_tx, tap_rx) = std::sync::mpsc::channel();
let tap_bridge = std::sync::Arc::clone(&state.chat_bridge);
let tap_clock = std::sync::Arc::clone(&state.clock);
let tap_sid = sid;
let tap_turn_guard = turn_guard.as_ref().map(|guard| guard.liveness_handle());
let tap_pump = std::thread::spawn(move || {
@ -2803,7 +2873,9 @@ pub async fn agent_send(
guard.mark_alive();
}
}
let Some(chunk) = crate::chat::chunk_from_event(event) else {
let Some(chunk) =
crate::chat::chunk_from_event_at(event, u64::try_from(tap_clock.now_millis()).ok())
else {
continue;
};
if matches!(chunk, ReplyChunk::Final { .. } | ReplyChunk::Error { .. }) {
@ -2842,6 +2914,7 @@ pub async fn agent_send(
// `Final` event (or stream end / superseded channel), then detaches *only its
// own* generation so a concurrent re-attach is never torn down.
let bridge = std::sync::Arc::clone(&state.chat_bridge);
let clock = std::sync::Arc::clone(&state.clock);
// Level-1 session-limit tap (§21, niveau 1 — structuré). Resolve the agent, host
// cell and engine conversation once from the live registry; a `RateLimited` turn
// event then feeds the service (détecter→planifier). Without a conversation id the
@ -2879,7 +2952,10 @@ pub async fn agent_send(
let _ = bridge.send_output_settled(
&sid,
&mut settler,
ReplyChunk::Error { message },
ReplyChunk::Error {
message,
at_ms: u64::try_from(clock.now_millis()).ok(),
},
);
break 'logical_turn;
}
@ -2920,7 +2996,9 @@ pub async fn agent_send(
}
// Heartbeats carry no chat content (readiness/heartbeat lot 1) ⇒ no wire
// chunk; skip them while still draining so the turn runs to its `Final`.
let Some(chunk) = crate::chat::chunk_from_event(event) else {
let Some(chunk) =
crate::chat::chunk_from_event_at(event, u64::try_from(clock.now_millis()).ok())
else {
continue;
};
if matches!(chunk, ReplyChunk::Final { .. } | ReplyChunk::Error { .. }) {
@ -2946,7 +3024,10 @@ pub async fn agent_send(
let _ = bridge.send_output_settled(
&sid,
&mut settler,
ReplyChunk::Error { message },
ReplyChunk::Error {
message,
at_ms: u64::try_from(clock.now_millis()).ok(),
},
);
}
backend::StructuredHumanTurnTransition::Cancelled => {
@ -2971,6 +3052,7 @@ pub async fn agent_send(
ReplyChunk::Error {
message: "Le redémarrage n'a pas fourni de session de remplacement."
.to_owned(),
at_ms: u64::try_from(clock.now_millis()).ok(),
},
);
break;
@ -2991,6 +3073,7 @@ pub async fn agent_send(
&mut settler,
ReplyChunk::Error {
message: error.to_string(),
at_ms: u64::try_from(clock.now_millis()).ok(),
},
);
break;
@ -2998,7 +3081,10 @@ pub async fn agent_send(
}
}
if !terminal_visible {
let chunk = crate::chat::unfinished_turn_chunk();
let chunk = crate::chat::with_chunk_timestamp(
crate::chat::unfinished_turn_chunk(),
u64::try_from(clock.now_millis()).ok(),
);
let _ = bridge.send_output_settled(&sid, &mut settler, chunk);
}
if let Some(guard) = &turn_guard {
@ -3421,7 +3507,11 @@ pub async fn cancel_agent_chat(
}
state
.stop_live_agent
.execute(StopLiveAgentInput { project, agent_id })
.execute(StopLiveAgentInput {
project,
agent_id,
reason: Some("fermeture de la session chat".to_owned()),
})
.await
.map(|_| ())
.map_err(ErrorDto::from)

View File

@ -263,6 +263,10 @@ pub fn run() {
commands::list_projects,
commands::read_project_context,
commands::update_project_context,
commands::read_user_settings,
commands::update_user_settings,
commands::read_project_settings,
commands::update_project_settings,
commands::get_project_permissions,
commands::update_project_permissions,
commands::update_agent_permissions,