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;
16pub mod codex;
17pub mod gemini;
18
19/// A streaming translator: feeds raw provider frames as parsed JSON
20/// values and emits zero-or-more `AgentEvent`s per frame.
21///
22/// Using a concrete `serde_json::Value` frame type (rather than an
23/// associated type) keeps the trait `dyn`-dispatchable so the
24/// runner can hold `Box<dyn Translator>` and switch providers at
25/// run time. All currently-planned providers (Claude Code
26/// stream-json, ACP, future Aider/Codex/Gemini) speak JSON over
27/// stdout, so the lowest-common-denominator frame fits them.
28/// Providers with binary framing would wrap their parser to emit
29/// `Value` envelopes before this layer.
30///
31/// PR 0 ships only the trait + Claude skeleton. PR 1 fills in the
32/// translation logic.
33pub trait Translator: Send {
34 /// Translate a single frame into zero-or-more events. Returning
35 /// `Vec` (not `Option`) because some provider frames produce
36 /// multiple events (e.g. a `message_start` with embedded
37 /// `tool_use` blocks).
38 fn translate(&mut self, frame: Value) -> Vec<AgentEvent>;
39}