feat(agent): commandes Tauri + ChatBridge streaming (D4) — §17

Expose l'exécution structurée à l'UI (jumeau du chemin PTY) :
- ChatBridge (chat.rs) : pompe ReplyStream -> Channel<ReplyChunk>,
  generation-tracked (anti-double-pompe) ; scrollback de conversation
  côté transport (le port AgentSession est sans mémoire), purgé à la
  fermeture, préservé à la ré-attache.
- Commandes agent_send / reattach_agent_chat / close_agent_session.
- DTO : ReplyChunk (textDelta/toolActivity/final, camelCase tagué kind),
  ReattachChatDto, CellKind {pty,chat} + champ cellKind dérivé sur
  TerminalSessionDto (chat ssi LaunchAgentOutput.structured = Some).
- Wiring composition root : StructuredSessions + ChatBridge dans AppState,
  via la factory déjà injectée (aucun new d'adapter — règle D §17.8).
- From<AgentSessionError> for AppError (mappe sur PROCESS).

Tests (QA) : 35 unitaires verts — generation supersede validé par mutation
test, séquence deltas*+Final, reattach sans re-spawn, teardown shutdown+
unregister, DTO cellKind + round-trip ReplyChunk, non-régression PTY.
cargo test --workspace : 803 passed, 0 failed.

Reste D5 : AgentChatView (frontend) + routage cellKind dans LayoutGrid.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 23:15:08 +02:00
parent 050afa7d24
commit f4d5727a69
12 changed files with 1153 additions and 9 deletions

View File

@ -26,7 +26,8 @@ pub use lifecycle::{
ChangeAgentProfile, ChangeAgentProfileInput, ChangeAgentProfileOutput, CreateAgentFromScratch,
CreateAgentInput, CreateAgentOutput, DeleteAgent, DeleteAgentInput, LaunchAgent,
LaunchAgentInput, LaunchAgentOutput, ListAgents, ListAgentsInput, ListAgentsOutput,
ReadAgentContext, ReadAgentContextInput, ReadAgentContextOutput, UpdateAgentContext,
ReadAgentContext, ReadAgentContextInput, ReadAgentContextOutput, StructuredSessionDescriptor,
UpdateAgentContext,
UpdateAgentContextInput, AGENT_MEMORY_RECALL_BUDGET,
};
pub use usecases::{

View File

@ -6,8 +6,8 @@
//! with one error shape when building its `ErrorDTO`.
use domain::ports::{
EmbedderError, FsError, GitError, MemoryError, ProcessError, PtyError, RemoteError,
RuntimeError, StoreError,
AgentSessionError, EmbedderError, FsError, GitError, MemoryError, ProcessError, PtyError,
RemoteError, RuntimeError, StoreError,
};
use domain::{AgentId, NodeId};
@ -148,3 +148,15 @@ impl From<RemoteError> for AppError {
Self::Remote(e.to_string())
}
}
impl From<AgentSessionError> for AppError {
/// Maps a structured [`AgentSessionError`] (ARCHITECTURE §17.1) onto the single
/// application error shape. `Start`/`Io`/`Decode`/`Timeout` are all execution
/// failures of a live structured session (a process/SDK conversation), so they
/// fold into [`AppError::Process`] — coherent with [`PtyError`]/[`ProcessError`],
/// the byte-stream twins. The raw CLI JSON never travels through `Decode` (the
/// adapter already redacted it), so this is safe to surface.
fn from(e: AgentSessionError) -> Self {
Self::Process(e.to_string())
}
}

View File

@ -37,8 +37,8 @@ pub use agent::{
ListProfiles, ListProfilesOutput, ListResumableAgents, ListResumableAgentsInput,
ListResumableAgentsOutput, ProfileAvailability, ReadAgentContext, ReadAgentContextInput,
ReadAgentContextOutput, ReferenceProfiles, ReferenceProfilesOutput, ResumableAgent, SaveProfile,
SaveProfileInput, SaveProfileOutput, UpdateAgentContext, UpdateAgentContextInput,
send_blocking, AGENT_MEMORY_RECALL_BUDGET,
SaveProfileInput, SaveProfileOutput, StructuredSessionDescriptor, UpdateAgentContext,
UpdateAgentContextInput, send_blocking, AGENT_MEMORY_RECALL_BUDGET,
};
pub use embedder::{
CheckEmbedderSuggestion, CheckEmbedderSuggestionInput, CheckEmbedderSuggestionOutput,

View File

@ -3,7 +3,8 @@
use application::AppError;
use domain::ports::{
EmbedderError, FsError, GitError, MemoryError, ProcessError, PtyError, RemoteError, StoreError,
AgentSessionError, EmbedderError, FsError, GitError, MemoryError, ProcessError, PtyError,
RemoteError, StoreError,
};
#[test]
@ -52,6 +53,31 @@ fn process_pty_runtime_map_to_process() {
);
}
#[test]
fn agent_session_errors_all_map_to_process() {
// §17.1 / D4: a structured AgentSession is a live process/SDK conversation, so
// every failure variant folds into PROCESS (the byte-stream twin). Used by the
// agent_send / close_agent_session command error arms.
assert_eq!(
AppError::from(AgentSessionError::Start("no cli".into())).code(),
"PROCESS"
);
assert_eq!(
AppError::from(AgentSessionError::Io("broken pipe".into())).code(),
"PROCESS"
);
assert_eq!(
AppError::from(AgentSessionError::Decode("bad schema".into())).code(),
"PROCESS"
);
assert_eq!(AppError::from(AgentSessionError::Timeout).code(), "PROCESS");
// The message is carried through onto the single Process shape.
assert_eq!(
AppError::from(AgentSessionError::Io("broken pipe".into())),
AppError::Process(AgentSessionError::Io("broken pipe".into()).to_string())
);
}
#[test]
fn git_and_remote_map_through() {
assert_eq!(AppError::from(GitError::NotFound).code(), "GIT");