agentmux_srv\agents\translator/
mod.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Provider frame → unified `AgentEvent` translation.
5//!
6//! Each provider (Claude Code stream-json, ACP, future Aider /
7//! Codex / Gemini) implements `Translator` to produce a stream of
8//! `AgentEvent`s. The runner is provider-agnostic; only this layer
9//! knows the wire format.
10
11use serde_json::Value;
12
13use super::types::AgentEvent;
14
15pub mod claude;
16
17/// A streaming translator: feeds raw provider frames as parsed JSON
18/// values and emits zero-or-more `AgentEvent`s per frame.
19///
20/// Using a concrete `serde_json::Value` frame type (rather than an
21/// associated type) keeps the trait `dyn`-dispatchable so the
22/// runner can hold `Box<dyn Translator>` and switch providers at
23/// run time. All currently-planned providers (Claude Code
24/// stream-json, ACP, future Aider/Codex/Gemini) speak JSON over
25/// stdout, so the lowest-common-denominator frame fits them.
26/// Providers with binary framing would wrap their parser to emit
27/// `Value` envelopes before this layer.
28///
29/// PR 0 ships only the trait + Claude skeleton. PR 1 fills in the
30/// translation logic.
31pub trait Translator: Send {
32    /// Translate a single frame into zero-or-more events. Returning
33    /// `Vec` (not `Option`) because some provider frames produce
34    /// multiple events (e.g. a `message_start` with embedded
35    /// `tool_use` blocks).
36    fn translate(&mut self, frame: Value) -> Vec<AgentEvent>;
37}